@abgov/ui-components-common 1.0.0 → 1.1.0
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.d.ts +2 -0
- package/index.js +332 -1
- package/lib/common.d.ts +2 -2
- package/lib/public-form-controller.d.ts +50 -0
- package/lib/validators.d.ts +48 -0
- package/package.json +3 -2
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";var A=Object.defineProperty;var p=r=>{throw TypeError(r)};var M=(r,t,e)=>t in r?A(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),v=(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)=>(v(r,t,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class S{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 s=n.map(i=>i(t[a])).find(i=>!!i);s&&(e[a]=s)}),e}}function E(){return[f("Day is required"),h({min:1,max:31,minMsg:"Day must be between 1 and 31",maxMsg:"Day must be between 1 and 31"})]}function N(){return[f("Month is required"),h({min:0,max:11,minMsg:"Month must be between Jan and Dec",maxMsg:"Month must be between Jan and Dec"})]}function _(){const r=new Date().getFullYear();return[f("Year is required"),h({min:1900,max:r,minMsg:"Year must be greater than 1900",maxMsg:`Year must be less than ${r}`})]}function f(r){return t=>(r=r||"Required",typeof t=="number"&&!isNaN(t)||t?"":r)}function R(r){const t=new RegExp(/^\+?[\d-() ]{10,18}$/);return c(t,r||"Invalid phone number")}function D(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 c(t,r||"Invalid email address")}function w(){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,s)=>{const i=n*t[s];return i<10?i:`${i}`.split("").map(o=>parseInt(o)).reduce((o,m)=>o+m,0)}).reduce((n,s)=>n+s,0)%10===0?"":"Invalid SIN"}}function I(){return c(/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,"Invalid postal code")}function c(r,t){return e=>!e||e.match(r)?"":t}function x({invalidMsg:r,minMsg:t,maxMsg:e,min:a,max:n}){return s=>{let i=new Date(0);return typeof s=="string"&&(i=new Date(s)),s.toDateString&&(i=s),i.toString()==="Invalid Date"||i.getTime()===0?r||"Invalid date":i&&a&&i<a?t||`Must be after ${a}`:i&&n&&i>n?e||`Must be before ${n}`:""}}function h({invalidTypeMsg:r,minMsg:t,maxMsg:e,min:a=-Number.MAX_VALUE,max:n=Number.MAX_VALUE}){return s=>{let i=Number.MAX_VALUE;return typeof s=="string"&&(i=parseFloat(s)),typeof s=="number"&&(i=s),isNaN(i)?r||"Must be a numeric value":i>n?e||`Must be less than or equal to ${n}`:i<a?t||`Must be greater than or equal to ${a}`:""}}function $({invalidTypeMsg:r,minMsg:t,maxMsg:e,min:a=-Number.MAX_VALUE,max:n=Number.MAX_VALUE,optional:s}){return i=>s&&`${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,L,V;class C{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),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,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,s]of Object.entries(a))e[n]=s.value;return e},{})):(console.warn("Utils:getStateList: unable to update the state of a non-multi form type",this.state),[]):[]}continueTo(t){if(!t){console.error("continueTo [name] is undefined");return}console.log("continueTo: TYPE",{type:this.type,state:this.state,formRef:this._formRef,next:t}),l(this._formRef,"external::continue",{next:t})}validate(t,e,a){var o;const{el:n,state:s}=e.detail,i=(o=s==null?void 0:s[t])==null?void 0:o.value;for(const m of a){const b=m(i);if(g(this,d,V).call(this,n,t,b),b)return[!1,""]}return[!0,i]}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(){var e;if(Array.isArray(this.state))return;const t=this.state;return(e=this.state)==null?void 0:e.history.reduce((a,n)=>(a[n]=t==null?void 0:t.form[n],a),{})}}d=new WeakSet,L=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=S;exports.PublicFormController=C;exports.SINValidator=w;exports.birthDayValidator=E;exports.birthMonthValidator=N;exports.birthYearValidator=_;exports.dateValidator=x;exports.dispatch=T;exports.emailValidator=D;exports.lengthValidator=$;exports.numericValidator=h;exports.phoneNumberValidator=R;exports.postalCodeValidator=I;exports.regexValidator=c;exports.relay=l;exports.requiredValidator=f;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1 +1,332 @@
|
|
|
1
|
-
|
|
1
|
+
var M = Object.defineProperty;
|
|
2
|
+
var p = (r) => {
|
|
3
|
+
throw TypeError(r);
|
|
4
|
+
};
|
|
5
|
+
var v = (r, t, e) => t in r ? M(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
6
|
+
var u = (r, t, e) => v(r, typeof t != "symbol" ? t + "" : t, e), V = (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) => (V(r, t, "access private method"), e);
|
|
9
|
+
class _ {
|
|
10
|
+
constructor(t) {
|
|
11
|
+
u(this, "validators");
|
|
12
|
+
this.validators = t || {};
|
|
13
|
+
}
|
|
14
|
+
add(t, ...e) {
|
|
15
|
+
this.validators[t] = e;
|
|
16
|
+
}
|
|
17
|
+
validate(t) {
|
|
18
|
+
const e = {};
|
|
19
|
+
return Object.entries(this.validators).forEach(([a, i]) => {
|
|
20
|
+
const s = i.map((n) => n(t[a])).find((n) => !!n);
|
|
21
|
+
s && (e[a] = s);
|
|
22
|
+
}), e;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function N() {
|
|
26
|
+
return [
|
|
27
|
+
c("Day is required"),
|
|
28
|
+
m({
|
|
29
|
+
min: 1,
|
|
30
|
+
max: 31,
|
|
31
|
+
minMsg: "Day must be between 1 and 31",
|
|
32
|
+
maxMsg: "Day must be between 1 and 31"
|
|
33
|
+
})
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
function R() {
|
|
37
|
+
return [
|
|
38
|
+
c("Month is required"),
|
|
39
|
+
m({
|
|
40
|
+
min: 0,
|
|
41
|
+
max: 11,
|
|
42
|
+
minMsg: "Month must be between Jan and Dec",
|
|
43
|
+
maxMsg: "Month must be between Jan and Dec"
|
|
44
|
+
})
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
function w() {
|
|
48
|
+
const r = (/* @__PURE__ */ new Date()).getFullYear();
|
|
49
|
+
return [
|
|
50
|
+
c("Year is required"),
|
|
51
|
+
m({
|
|
52
|
+
min: 1900,
|
|
53
|
+
max: r,
|
|
54
|
+
minMsg: "Year must be greater than 1900",
|
|
55
|
+
maxMsg: `Year must be less than ${r}`
|
|
56
|
+
})
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
function c(r) {
|
|
60
|
+
return (t) => (r = r || "Required", typeof t == "number" && !isNaN(t) || t ? "" : r);
|
|
61
|
+
}
|
|
62
|
+
function D(r) {
|
|
63
|
+
const t = new RegExp(/^\+?[\d-() ]{10,18}$/);
|
|
64
|
+
return h(t, r || "Invalid phone number");
|
|
65
|
+
}
|
|
66
|
+
function I(r) {
|
|
67
|
+
const t = new RegExp(
|
|
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
|
+
);
|
|
70
|
+
return h(t, r || "Invalid email address");
|
|
71
|
+
}
|
|
72
|
+
function x() {
|
|
73
|
+
return (r) => {
|
|
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, s) => {
|
|
77
|
+
const n = i * t[s];
|
|
78
|
+
return n < 10 ? n : `${n}`.split("").map((o) => parseInt(o)).reduce((o, d) => o + d, 0);
|
|
79
|
+
}).reduce((i, s) => i + s, 0) % 10 === 0 ? "" : "Invalid SIN";
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function $() {
|
|
83
|
+
return h(
|
|
84
|
+
/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
|
|
85
|
+
"Invalid postal code"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
function h(r, t) {
|
|
89
|
+
return (e) => !e || e.match(r) ? "" : t;
|
|
90
|
+
}
|
|
91
|
+
function L({
|
|
92
|
+
invalidMsg: r,
|
|
93
|
+
minMsg: t,
|
|
94
|
+
maxMsg: e,
|
|
95
|
+
min: a,
|
|
96
|
+
max: i
|
|
97
|
+
}) {
|
|
98
|
+
return (s) => {
|
|
99
|
+
let n = /* @__PURE__ */ new Date(0);
|
|
100
|
+
return typeof s == "string" && (n = new Date(s)), s.toDateString && (n = s), n.toString() === "Invalid Date" || n.getTime() === 0 ? r || "Invalid date" : n && a && n < a ? t || `Must be after ${a}` : n && i && n > i ? e || `Must be before ${i}` : "";
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function m({
|
|
104
|
+
invalidTypeMsg: r,
|
|
105
|
+
minMsg: t,
|
|
106
|
+
maxMsg: e,
|
|
107
|
+
min: a = -Number.MAX_VALUE,
|
|
108
|
+
max: i = Number.MAX_VALUE
|
|
109
|
+
}) {
|
|
110
|
+
return (s) => {
|
|
111
|
+
let n = Number.MAX_VALUE;
|
|
112
|
+
return typeof s == "string" && (n = parseFloat(s)), typeof s == "number" && (n = s), isNaN(n) ? r || "Must be a numeric value" : n > i ? e || `Must be less than or equal to ${i}` : n < a ? t || `Must be greater than or equal to ${a}` : "";
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function T({
|
|
116
|
+
invalidTypeMsg: r,
|
|
117
|
+
minMsg: t,
|
|
118
|
+
maxMsg: e,
|
|
119
|
+
min: a = -Number.MAX_VALUE,
|
|
120
|
+
max: i = Number.MAX_VALUE,
|
|
121
|
+
optional: s
|
|
122
|
+
}) {
|
|
123
|
+
return (n) => s && `${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` : "";
|
|
124
|
+
}
|
|
125
|
+
var f, E, A;
|
|
126
|
+
class C {
|
|
127
|
+
constructor(t) {
|
|
128
|
+
y(this, f);
|
|
129
|
+
u(this, "state");
|
|
130
|
+
u(this, "_formData");
|
|
131
|
+
u(this, "_formRef");
|
|
132
|
+
this.type = t;
|
|
133
|
+
}
|
|
134
|
+
// Obtain reference to the form element
|
|
135
|
+
init(t) {
|
|
136
|
+
if (this._formRef) {
|
|
137
|
+
console.warn("init: form element has already been set");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this._formRef = t.detail.el, this.state = {
|
|
141
|
+
uuid: crypto.randomUUID(),
|
|
142
|
+
form: {},
|
|
143
|
+
history: [],
|
|
144
|
+
editting: "",
|
|
145
|
+
status: "not-started"
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
initList(t) {
|
|
149
|
+
this._formRef = t.detail.el, this.state = [];
|
|
150
|
+
}
|
|
151
|
+
// Public method to allow for the initialization of the state
|
|
152
|
+
initState(t, e) {
|
|
153
|
+
l(this._formRef, "external::init:state", t), e && setTimeout(e, 200);
|
|
154
|
+
}
|
|
155
|
+
updateListState(t) {
|
|
156
|
+
const e = t.detail;
|
|
157
|
+
Array.isArray(e.data) && (this.state = e.data);
|
|
158
|
+
}
|
|
159
|
+
updateObjectState(t) {
|
|
160
|
+
var a, i;
|
|
161
|
+
if (Array.isArray(this.state))
|
|
162
|
+
return;
|
|
163
|
+
const e = t.detail;
|
|
164
|
+
e.type === "list" ? this.state = {
|
|
165
|
+
...this.state,
|
|
166
|
+
form: { ...((a = this.state) == null ? void 0 : a.form) || {}, [e.id]: e.data }
|
|
167
|
+
// currentFieldset: newState.currentFieldset,
|
|
168
|
+
// history: detail.data.,
|
|
169
|
+
} : this.state = {
|
|
170
|
+
...this.state,
|
|
171
|
+
form: { ...((i = this.state) == null ? void 0 : i.form) || {}, ...e.data.form },
|
|
172
|
+
// currentFieldset: newState.currentFieldset,
|
|
173
|
+
history: e.data.history
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
getStateList() {
|
|
177
|
+
return this.state ? Array.isArray(this.state) ? this.state.length === 0 ? [] : this.state.map((t) => Object.values(t.form).filter((e) => {
|
|
178
|
+
var a;
|
|
179
|
+
return ((a = e == null ? void 0 : e.data) == null ? void 0 : a.type) === "details";
|
|
180
|
+
}).map((e) => {
|
|
181
|
+
var a;
|
|
182
|
+
return e.data.type === "details" && ((a = e.data) == null ? void 0 : a.fieldsets) || {};
|
|
183
|
+
}).reduce(
|
|
184
|
+
(e, a) => {
|
|
185
|
+
for (const [i, s] of Object.entries(a))
|
|
186
|
+
e[i] = s.value;
|
|
187
|
+
return e;
|
|
188
|
+
},
|
|
189
|
+
{}
|
|
190
|
+
)) : (console.warn(
|
|
191
|
+
"Utils:getStateList: unable to update the state of a non-multi form type",
|
|
192
|
+
this.state
|
|
193
|
+
), []) : [];
|
|
194
|
+
}
|
|
195
|
+
// getStateItems(group: string): Record<string, FieldsetItemState>[] {
|
|
196
|
+
// if (Array.isArray(this.state)) {
|
|
197
|
+
// console.error(
|
|
198
|
+
// "Utils:getStateItems: unable to update the state of a multi form type",
|
|
199
|
+
// );
|
|
200
|
+
// return [];
|
|
201
|
+
// }
|
|
202
|
+
// if (!this.state) {
|
|
203
|
+
// console.error("Utils:getStateItems: state has not yet been set");
|
|
204
|
+
// return [];
|
|
205
|
+
// }
|
|
206
|
+
// console.debug("Utils:getStateItems", this.state, { group });
|
|
207
|
+
// return (this.state.form[group]?.data ?? []) as Record<string, FieldsetItemState>[];
|
|
208
|
+
// }
|
|
209
|
+
// Public method to allow for the retrieval of the state value
|
|
210
|
+
// getStateValue(group: string, key: string): string {
|
|
211
|
+
// if (Array.isArray(this.state)) {
|
|
212
|
+
// console.error("getStateValue: unable to update the state of a multi form type");
|
|
213
|
+
// return "";
|
|
214
|
+
// }
|
|
215
|
+
// if (!this.state) {
|
|
216
|
+
// console.error("getStateValue: state has not yet been set");
|
|
217
|
+
// return "";
|
|
218
|
+
// }
|
|
219
|
+
// const data = this.state.form[group].data as Record<string, FieldsetItemState>[];
|
|
220
|
+
// // @ts-expect-error "ignore"
|
|
221
|
+
// return (data as Record<string, string>)[key]?.value ?? "";
|
|
222
|
+
// }
|
|
223
|
+
// Public method to allow for the continuing to the next page
|
|
224
|
+
continueTo(t) {
|
|
225
|
+
if (!t) {
|
|
226
|
+
console.error("continueTo [name] is undefined");
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
console.log("continueTo: TYPE", {
|
|
230
|
+
type: this.type,
|
|
231
|
+
state: this.state,
|
|
232
|
+
formRef: this._formRef,
|
|
233
|
+
next: t
|
|
234
|
+
}), l(this._formRef, "external::continue", { next: t });
|
|
235
|
+
}
|
|
236
|
+
// Public method to perform validation and send the appropriate messages to the form elements
|
|
237
|
+
validate(t, e, a) {
|
|
238
|
+
var o;
|
|
239
|
+
const { el: i, state: s } = e.detail, n = (o = s == null ? void 0 : s[t]) == null ? void 0 : o.value;
|
|
240
|
+
for (const d of a) {
|
|
241
|
+
const b = d(n);
|
|
242
|
+
if (g(this, f, A).call(this, i, t, b), b)
|
|
243
|
+
return [!1, ""];
|
|
244
|
+
}
|
|
245
|
+
return [!0, n];
|
|
246
|
+
}
|
|
247
|
+
edit(t) {
|
|
248
|
+
l(this._formRef, "external::alter:state", { index: t, operation: "edit" });
|
|
249
|
+
}
|
|
250
|
+
remove(t) {
|
|
251
|
+
l(this._formRef, "external::alter:state", { index: t, operation: "remove" });
|
|
252
|
+
}
|
|
253
|
+
// removes any data collected that doesn't correspond with the final history path
|
|
254
|
+
clean() {
|
|
255
|
+
var e;
|
|
256
|
+
if (Array.isArray(this.state))
|
|
257
|
+
return;
|
|
258
|
+
const t = this.state;
|
|
259
|
+
return (e = this.state) == null ? void 0 : e.history.reduce((a, i) => (a[i] = t == null ? void 0 : t.form[i], a), {});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
f = new WeakSet(), E = function(t) {
|
|
263
|
+
var e;
|
|
264
|
+
Array.isArray(t.data) && (Array.isArray(this.state) || (this.state = {
|
|
265
|
+
...this.state,
|
|
266
|
+
form: {
|
|
267
|
+
...((e = this.state) == null ? void 0 : e.form) || {},
|
|
268
|
+
[t.id]: t.data
|
|
269
|
+
}
|
|
270
|
+
}));
|
|
271
|
+
}, // Private method to dispatch the error message to the form element
|
|
272
|
+
A = function(t, e, a) {
|
|
273
|
+
t.dispatchEvent(
|
|
274
|
+
new CustomEvent("msg", {
|
|
275
|
+
composed: !0,
|
|
276
|
+
detail: {
|
|
277
|
+
action: "external::set:error",
|
|
278
|
+
data: {
|
|
279
|
+
name: e,
|
|
280
|
+
msg: a
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
})
|
|
284
|
+
);
|
|
285
|
+
};
|
|
286
|
+
function U(r, t, e, a) {
|
|
287
|
+
if (!r) {
|
|
288
|
+
console.error("dispatch element is null");
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
r.dispatchEvent(
|
|
292
|
+
new CustomEvent(t, {
|
|
293
|
+
composed: !0,
|
|
294
|
+
bubbles: a == null ? void 0 : a.bubbles,
|
|
295
|
+
detail: e
|
|
296
|
+
})
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
function l(r, t, e, a) {
|
|
300
|
+
if (!r) {
|
|
301
|
+
console.error("dispatch element is null");
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
r.dispatchEvent(
|
|
305
|
+
new CustomEvent("msg", {
|
|
306
|
+
composed: !0,
|
|
307
|
+
bubbles: a == null ? void 0 : a.bubbles,
|
|
308
|
+
detail: {
|
|
309
|
+
action: t,
|
|
310
|
+
data: e
|
|
311
|
+
}
|
|
312
|
+
})
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
export {
|
|
316
|
+
_ as FormValidator,
|
|
317
|
+
C as PublicFormController,
|
|
318
|
+
x as SINValidator,
|
|
319
|
+
N as birthDayValidator,
|
|
320
|
+
R as birthMonthValidator,
|
|
321
|
+
w as birthYearValidator,
|
|
322
|
+
L as dateValidator,
|
|
323
|
+
U as dispatch,
|
|
324
|
+
I as emailValidator,
|
|
325
|
+
T as lengthValidator,
|
|
326
|
+
m as numericValidator,
|
|
327
|
+
D as phoneNumberValidator,
|
|
328
|
+
$ as postalCodeValidator,
|
|
329
|
+
h as regexValidator,
|
|
330
|
+
l as relay,
|
|
331
|
+
c as requiredValidator
|
|
332
|
+
};
|
package/lib/common.d.ts
CHANGED
|
@@ -123,7 +123,7 @@ export interface GoabSkeletonProps extends Margins {
|
|
|
123
123
|
export type GoabSkeletonType = "image" | "text" | "title" | "text-small" | "avatar" | "header" | "paragraph" | "thumbnail" | "card" | "profile" | "article";
|
|
124
124
|
export type GoabSkeletonSize = "1" | "2" | "3" | "4";
|
|
125
125
|
export type GoabRadioGroupOrientation = "horizontal" | "vertical";
|
|
126
|
-
export interface
|
|
126
|
+
export interface GoabRadioGroupProps extends Margins {
|
|
127
127
|
name: string;
|
|
128
128
|
value?: string;
|
|
129
129
|
disabled?: boolean;
|
|
@@ -132,7 +132,7 @@ export interface GoabRadioGroup extends Margins {
|
|
|
132
132
|
error?: boolean;
|
|
133
133
|
ariaLabel?: string;
|
|
134
134
|
}
|
|
135
|
-
export interface
|
|
135
|
+
export interface GoabRadioItemProps {
|
|
136
136
|
value?: string;
|
|
137
137
|
label?: string;
|
|
138
138
|
name?: string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { FieldsetItemState, FieldValidator } from './validators';
|
|
2
|
+
|
|
3
|
+
export type FormStatus = "not-started" | "incomplete" | "complete";
|
|
4
|
+
export type AppState<T> = {
|
|
5
|
+
uuid: string;
|
|
6
|
+
form: Record<string, Fieldset<T>>;
|
|
7
|
+
history: string[];
|
|
8
|
+
editting: string;
|
|
9
|
+
lastModified?: Date;
|
|
10
|
+
status: FormStatus;
|
|
11
|
+
currentFieldset?: {
|
|
12
|
+
id: T;
|
|
13
|
+
dispatchType: "change" | "continue";
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type Fieldset<T> = {
|
|
17
|
+
heading: string;
|
|
18
|
+
data: {
|
|
19
|
+
type: "details";
|
|
20
|
+
fieldsets: Record<string, FieldsetItemState>;
|
|
21
|
+
} | {
|
|
22
|
+
type: "list";
|
|
23
|
+
items: AppState<T>[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export declare class PublicFormController<T> {
|
|
27
|
+
#private;
|
|
28
|
+
private type;
|
|
29
|
+
state?: AppState<T> | AppState<T>[];
|
|
30
|
+
_formData?: Record<string, string>;
|
|
31
|
+
_formRef?: HTMLElement;
|
|
32
|
+
constructor(type: "details" | "list");
|
|
33
|
+
init(e: Event): void;
|
|
34
|
+
initList(e: Event): void;
|
|
35
|
+
initState(state?: string | AppState<T> | AppState<T>[], callback?: () => void): void;
|
|
36
|
+
updateListState(e: Event): void;
|
|
37
|
+
updateObjectState(e: Event): void;
|
|
38
|
+
getStateList(): Record<string, string>[];
|
|
39
|
+
continueTo(next: T | undefined): void;
|
|
40
|
+
validate(field: string, e: Event, validators: FieldValidator[]): [boolean, string];
|
|
41
|
+
edit(index: number): void;
|
|
42
|
+
remove(index: number): void;
|
|
43
|
+
clean(): Record<string, unknown> | undefined;
|
|
44
|
+
}
|
|
45
|
+
export declare function dispatch<T>(el: HTMLElement | Element | null | undefined, eventName: string, detail?: T, opts?: {
|
|
46
|
+
bubbles?: boolean;
|
|
47
|
+
}): void;
|
|
48
|
+
export declare function relay<T>(el: HTMLElement | Element | null | undefined, eventName: string, data?: T, opts?: {
|
|
49
|
+
bubbles?: boolean;
|
|
50
|
+
}): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type FieldsetItemState = {
|
|
2
|
+
name: string;
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
export type FieldValidator = (value: unknown) => string;
|
|
7
|
+
export type FieldsetState = Record<string, FieldsetItemState>;
|
|
8
|
+
export declare class FormValidator {
|
|
9
|
+
private readonly validators;
|
|
10
|
+
constructor(validators?: Record<string, FieldValidator[]>);
|
|
11
|
+
add(fieldName: string, ...validators: FieldValidator[]): void;
|
|
12
|
+
validate(data: Record<string, string>): Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export declare function birthDayValidator(): FieldValidator[];
|
|
15
|
+
export declare function birthMonthValidator(): FieldValidator[];
|
|
16
|
+
export declare function birthYearValidator(): FieldValidator[];
|
|
17
|
+
export declare function requiredValidator(msg?: string): FieldValidator;
|
|
18
|
+
export declare function phoneNumberValidator(msg?: string): FieldValidator;
|
|
19
|
+
export declare function emailValidator(msg?: string): FieldValidator;
|
|
20
|
+
export declare function SINValidator(): FieldValidator;
|
|
21
|
+
export declare function postalCodeValidator(): FieldValidator;
|
|
22
|
+
export declare function regexValidator(regex: RegExp, msg: string): FieldValidator;
|
|
23
|
+
interface DateValidatorOptions {
|
|
24
|
+
invalidMsg?: string;
|
|
25
|
+
minMsg?: string;
|
|
26
|
+
maxMsg?: string;
|
|
27
|
+
min?: Date;
|
|
28
|
+
max?: Date;
|
|
29
|
+
}
|
|
30
|
+
export declare function dateValidator({ invalidMsg, minMsg, maxMsg, min, max, }: DateValidatorOptions): FieldValidator;
|
|
31
|
+
interface NumericValidatorOptions {
|
|
32
|
+
invalidTypeMsg?: string;
|
|
33
|
+
minMsg?: string;
|
|
34
|
+
maxMsg?: string;
|
|
35
|
+
min?: number;
|
|
36
|
+
max?: number;
|
|
37
|
+
}
|
|
38
|
+
export declare function numericValidator({ invalidTypeMsg, minMsg, maxMsg, min, max, }: NumericValidatorOptions): FieldValidator;
|
|
39
|
+
interface LengthValidatorOptions {
|
|
40
|
+
invalidTypeMsg?: string;
|
|
41
|
+
minMsg?: string;
|
|
42
|
+
maxMsg?: string;
|
|
43
|
+
max?: number;
|
|
44
|
+
min?: number;
|
|
45
|
+
optional?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare function lengthValidator({ invalidTypeMsg, minMsg, maxMsg, min, max, optional, }: LengthValidatorOptions): FieldValidator;
|
|
48
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/ui-components-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/GovAlta/ui-components/issues"
|
|
6
6
|
},
|
|
@@ -21,5 +21,6 @@
|
|
|
21
21
|
"module": "./index.js",
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"semantic-release": "semantic-release"
|
|
25
26
|
}
|