@abgov/angular-components 4.0.0 → 4.0.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/esm2022/index.mjs +2 -3
- package/fesm2022/abgov-angular-components.mjs +2 -240
- package/fesm2022/abgov-angular-components.mjs.map +1 -1
- package/index.d.ts +1 -2
- package/package.json +2 -1
- package/esm2022/lib/public-form-utils.mjs +0 -34
- package/esm2022/lib/validation.mjs +0 -205
- package/lib/public-form-utils.d.ts +0 -18
- package/lib/validation.d.ts +0 -44
package/esm2022/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from "./lib/angular-components.module";
|
|
2
2
|
export * from "./lib/components";
|
|
3
|
-
export * from "
|
|
4
|
-
|
|
5
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9saWJzL2FuZ3VsYXItY29tcG9uZW50cy9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxpQ0FBaUMsQ0FBQztBQUNoRCxjQUFjLGtCQUFrQixDQUFDO0FBQ2pDLGNBQWMsa0JBQWtCLENBQUM7QUFDakMsY0FBYyx5QkFBeUIsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gXCIuL2xpYi9hbmd1bGFyLWNvbXBvbmVudHMubW9kdWxlXCI7XG5leHBvcnQgKiBmcm9tIFwiLi9saWIvY29tcG9uZW50c1wiO1xuZXhwb3J0ICogZnJvbSBcIi4vbGliL3ZhbGlkYXRpb25cIjtcbmV4cG9ydCAqIGZyb20gXCIuL2xpYi9wdWJsaWMtZm9ybS11dGlsc1wiO1xuIl19
|
|
3
|
+
export * from "@abgov/ui-components-common";
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9saWJzL2FuZ3VsYXItY29tcG9uZW50cy9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxpQ0FBaUMsQ0FBQztBQUNoRCxjQUFjLGtCQUFrQixDQUFDO0FBQ2pDLGNBQWMsNkJBQTZCLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgKiBmcm9tIFwiLi9saWIvYW5ndWxhci1jb21wb25lbnRzLm1vZHVsZVwiO1xuZXhwb3J0ICogZnJvbSBcIi4vbGliL2NvbXBvbmVudHNcIjtcbmV4cG9ydCAqIGZyb20gXCJAYWJnb3YvdWktY29tcG9uZW50cy1jb21tb25cIjtcbiJdfQ==
|
|
@@ -2,6 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { forwardRef, Directive, HostListener, NgModule, CUSTOM_ELEMENTS_SCHEMA, EventEmitter, Component, Input, Output, TemplateRef } from '@angular/core';
|
|
3
3
|
import { NG_VALUE_ACCESSOR, CheckboxControlValueAccessor } from '@angular/forms';
|
|
4
4
|
import { NgTemplateOutlet } from '@angular/common';
|
|
5
|
+
export * from '@abgov/ui-components-common';
|
|
5
6
|
|
|
6
7
|
// @deprecated: Use the new <goab-input .. /> component
|
|
7
8
|
class ValueDirective {
|
|
@@ -3746,248 +3747,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.3", ngImpor
|
|
|
3746
3747
|
type: Input
|
|
3747
3748
|
}] } });
|
|
3748
3749
|
|
|
3749
|
-
// TODO: move this into the form-utils file, since it is specific to the public form component
|
|
3750
|
-
function validate(field, fieldsetEl, fieldsetState, validators) {
|
|
3751
|
-
const value = fieldsetState?.[field]?.value;
|
|
3752
|
-
for (const validator of validators) {
|
|
3753
|
-
const msg = validator(value);
|
|
3754
|
-
if (msg) {
|
|
3755
|
-
dispatchError(fieldsetEl, field, msg);
|
|
3756
|
-
return [false, ""];
|
|
3757
|
-
}
|
|
3758
|
-
}
|
|
3759
|
-
return [true, value];
|
|
3760
|
-
}
|
|
3761
|
-
// TODO: move this into the form-utils file, since it is specific to the public form component
|
|
3762
|
-
function dispatchError(el, name, msg) {
|
|
3763
|
-
el.dispatchEvent(new CustomEvent("msg", {
|
|
3764
|
-
composed: true,
|
|
3765
|
-
detail: {
|
|
3766
|
-
action: "external::set:error",
|
|
3767
|
-
data: {
|
|
3768
|
-
name,
|
|
3769
|
-
msg,
|
|
3770
|
-
},
|
|
3771
|
-
},
|
|
3772
|
-
}));
|
|
3773
|
-
}
|
|
3774
|
-
class FormValidator {
|
|
3775
|
-
constructor(validators) {
|
|
3776
|
-
this.validators = validators || {};
|
|
3777
|
-
}
|
|
3778
|
-
add(fieldName, ...validators) {
|
|
3779
|
-
this.validators[fieldName] = validators;
|
|
3780
|
-
}
|
|
3781
|
-
validate(data) {
|
|
3782
|
-
const errors = {};
|
|
3783
|
-
Object.entries(this.validators).forEach(([name, validators]) => {
|
|
3784
|
-
const err = validators
|
|
3785
|
-
.map((validatorFn) => {
|
|
3786
|
-
const errMsg = validatorFn(data[name]);
|
|
3787
|
-
return errMsg;
|
|
3788
|
-
})
|
|
3789
|
-
.find((msg) => !!msg);
|
|
3790
|
-
if (err) {
|
|
3791
|
-
errors[name] = err;
|
|
3792
|
-
}
|
|
3793
|
-
});
|
|
3794
|
-
return errors;
|
|
3795
|
-
}
|
|
3796
|
-
}
|
|
3797
|
-
// **********
|
|
3798
|
-
// Validators
|
|
3799
|
-
// **********
|
|
3800
|
-
function birthDayValidator() {
|
|
3801
|
-
return [
|
|
3802
|
-
requiredValidator("Day is required"),
|
|
3803
|
-
numericValidator({
|
|
3804
|
-
min: 1,
|
|
3805
|
-
max: 31,
|
|
3806
|
-
minMsg: "Day must be between 1 and 31",
|
|
3807
|
-
maxMsg: "Day must be between 1 and 31",
|
|
3808
|
-
}),
|
|
3809
|
-
];
|
|
3810
|
-
}
|
|
3811
|
-
function birthMonthValidator() {
|
|
3812
|
-
return [
|
|
3813
|
-
requiredValidator("Month is required"),
|
|
3814
|
-
numericValidator({
|
|
3815
|
-
min: 0,
|
|
3816
|
-
max: 11,
|
|
3817
|
-
minMsg: "Month must be between Jan and Dec",
|
|
3818
|
-
maxMsg: "Month must be between Jan and Dec",
|
|
3819
|
-
}),
|
|
3820
|
-
];
|
|
3821
|
-
}
|
|
3822
|
-
function birthYearValidator() {
|
|
3823
|
-
const maxYear = new Date().getFullYear();
|
|
3824
|
-
return [
|
|
3825
|
-
requiredValidator("Year is required"),
|
|
3826
|
-
numericValidator({
|
|
3827
|
-
min: 1900,
|
|
3828
|
-
max: maxYear,
|
|
3829
|
-
minMsg: "Year must be greater than 1900",
|
|
3830
|
-
maxMsg: `Year must be less than ${maxYear}`,
|
|
3831
|
-
}),
|
|
3832
|
-
];
|
|
3833
|
-
}
|
|
3834
|
-
function requiredValidator(msg) {
|
|
3835
|
-
return (value) => {
|
|
3836
|
-
msg = msg || "Required";
|
|
3837
|
-
if (typeof value === "number" && !isNaN(value)) {
|
|
3838
|
-
return "";
|
|
3839
|
-
}
|
|
3840
|
-
if (value) {
|
|
3841
|
-
return "";
|
|
3842
|
-
}
|
|
3843
|
-
return msg;
|
|
3844
|
-
};
|
|
3845
|
-
}
|
|
3846
|
-
function phoneNumberValidator(msg) {
|
|
3847
|
-
const regex = new RegExp(/^\+?[\d-() ]{10,18}$/);
|
|
3848
|
-
return regexValidator(regex, msg || "Invalid phone number");
|
|
3849
|
-
}
|
|
3850
|
-
function emailValidator(msg) {
|
|
3851
|
-
// emailregex.com
|
|
3852
|
-
const regex = 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,}))$/);
|
|
3853
|
-
return regexValidator(regex, msg || "Invalid email address");
|
|
3854
|
-
}
|
|
3855
|
-
function SINValidator() {
|
|
3856
|
-
return (value) => {
|
|
3857
|
-
if (!value)
|
|
3858
|
-
return "";
|
|
3859
|
-
const checkValue = "121121121".split("").map((c) => parseInt(c));
|
|
3860
|
-
const valueStr = value.replace(/\D/g, "");
|
|
3861
|
-
if (valueStr.length !== 9)
|
|
3862
|
-
return "SIN must contain 9 numbers";
|
|
3863
|
-
const checkSum = valueStr
|
|
3864
|
-
.split("")
|
|
3865
|
-
.map((c) => parseInt(c))
|
|
3866
|
-
.map((num, index) => {
|
|
3867
|
-
const val = num * checkValue[index];
|
|
3868
|
-
if (val < 10) {
|
|
3869
|
-
return val;
|
|
3870
|
-
}
|
|
3871
|
-
return `${val}`
|
|
3872
|
-
.split("")
|
|
3873
|
-
.map((c) => parseInt(c))
|
|
3874
|
-
.reduce((acc, val) => acc * val, 1);
|
|
3875
|
-
})
|
|
3876
|
-
.reduce((acc, val) => acc + val, 0);
|
|
3877
|
-
if (checkSum % 10 === 0) {
|
|
3878
|
-
return "";
|
|
3879
|
-
}
|
|
3880
|
-
return "Invalid SIN";
|
|
3881
|
-
};
|
|
3882
|
-
}
|
|
3883
|
-
function postalCodeValidator() {
|
|
3884
|
-
return regexValidator(/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i, "Invalid postal code");
|
|
3885
|
-
}
|
|
3886
|
-
function regexValidator(regex, msg) {
|
|
3887
|
-
return (value) => {
|
|
3888
|
-
if (!value) {
|
|
3889
|
-
return "";
|
|
3890
|
-
}
|
|
3891
|
-
if (value.match(regex)) {
|
|
3892
|
-
return "";
|
|
3893
|
-
}
|
|
3894
|
-
return msg;
|
|
3895
|
-
};
|
|
3896
|
-
}
|
|
3897
|
-
function dateValidator({ invalidMsg, startMsg, endMsg, start, end, }) {
|
|
3898
|
-
return (date) => {
|
|
3899
|
-
let _date = new Date(0);
|
|
3900
|
-
if (typeof date === "string") {
|
|
3901
|
-
_date = new Date(date);
|
|
3902
|
-
}
|
|
3903
|
-
if (date.toDateString) {
|
|
3904
|
-
_date = date;
|
|
3905
|
-
}
|
|
3906
|
-
if (_date.toString() === "Invalid Date" || _date.getTime() === 0) {
|
|
3907
|
-
return invalidMsg || "Invalid date";
|
|
3908
|
-
}
|
|
3909
|
-
if (_date && start && _date < start) {
|
|
3910
|
-
return startMsg || `Must be after ${start}`;
|
|
3911
|
-
}
|
|
3912
|
-
if (_date && end && _date > end) {
|
|
3913
|
-
return endMsg || `Must be before ${end}`;
|
|
3914
|
-
}
|
|
3915
|
-
return "";
|
|
3916
|
-
};
|
|
3917
|
-
}
|
|
3918
|
-
function numericValidator({ invalidTypeMsg, minMsg, maxMsg, min = -Number.MAX_VALUE, max = Number.MAX_VALUE, }) {
|
|
3919
|
-
return (value) => {
|
|
3920
|
-
let _value = Number.MAX_VALUE;
|
|
3921
|
-
if (typeof value === "string") {
|
|
3922
|
-
_value = parseFloat(value);
|
|
3923
|
-
}
|
|
3924
|
-
if (typeof value === "number") {
|
|
3925
|
-
_value = value;
|
|
3926
|
-
}
|
|
3927
|
-
if (isNaN(_value)) {
|
|
3928
|
-
return invalidTypeMsg || "Must be a numeric value";
|
|
3929
|
-
}
|
|
3930
|
-
if (_value > max) {
|
|
3931
|
-
return maxMsg || `Must be less than or equal to ${max}`;
|
|
3932
|
-
}
|
|
3933
|
-
if (_value < min) {
|
|
3934
|
-
return minMsg || `Must be greater than or equal to ${min}`;
|
|
3935
|
-
}
|
|
3936
|
-
return "";
|
|
3937
|
-
};
|
|
3938
|
-
}
|
|
3939
|
-
function lengthValidator({ invalidTypeMsg, minMsg, maxMsg, min = -Number.MAX_VALUE, max = Number.MAX_VALUE, }) {
|
|
3940
|
-
return (value) => {
|
|
3941
|
-
if (typeof value !== "string") {
|
|
3942
|
-
return invalidTypeMsg || "Invalid type";
|
|
3943
|
-
}
|
|
3944
|
-
if (value.length > max) {
|
|
3945
|
-
return maxMsg || `Must be less than ${max} characters`;
|
|
3946
|
-
}
|
|
3947
|
-
if (value.length < min) {
|
|
3948
|
-
return minMsg || `Must be greater than ${min} characters`;
|
|
3949
|
-
}
|
|
3950
|
-
return "";
|
|
3951
|
-
};
|
|
3952
|
-
}
|
|
3953
|
-
|
|
3954
|
-
function dispatch(el, eventName, detail, opts) {
|
|
3955
|
-
if (!el) {
|
|
3956
|
-
console.error("dispatch element is null");
|
|
3957
|
-
return;
|
|
3958
|
-
}
|
|
3959
|
-
el.dispatchEvent(new CustomEvent(eventName, {
|
|
3960
|
-
composed: true,
|
|
3961
|
-
bubbles: opts?.bubbles,
|
|
3962
|
-
detail: detail,
|
|
3963
|
-
}));
|
|
3964
|
-
}
|
|
3965
|
-
function relay(el, eventName, data, opts) {
|
|
3966
|
-
if (!el) {
|
|
3967
|
-
console.error("dispatch element is null");
|
|
3968
|
-
return;
|
|
3969
|
-
}
|
|
3970
|
-
// console.log(`RELAY(${eventName}):`, data, el);
|
|
3971
|
-
el.dispatchEvent(new CustomEvent("msg", {
|
|
3972
|
-
composed: true,
|
|
3973
|
-
bubbles: opts?.bubbles,
|
|
3974
|
-
detail: {
|
|
3975
|
-
action: eventName,
|
|
3976
|
-
data,
|
|
3977
|
-
},
|
|
3978
|
-
}));
|
|
3979
|
-
}
|
|
3980
|
-
// TODO: Logic similar to this needs to be done on the React side as well i.e. an initial onMount
|
|
3981
|
-
// event that passes a ref to the form,
|
|
3982
|
-
function continueTo(el, name) {
|
|
3983
|
-
relay(el, "external::continue", {
|
|
3984
|
-
next: name,
|
|
3985
|
-
});
|
|
3986
|
-
}
|
|
3987
|
-
|
|
3988
3750
|
/**
|
|
3989
3751
|
* Generated bundle index. Do not edit.
|
|
3990
3752
|
*/
|
|
3991
3753
|
|
|
3992
|
-
export { AngularComponentsModule, CheckedDirective,
|
|
3754
|
+
export { AngularComponentsModule, CheckedDirective, GoabAccordion, GoabAppFooter, GoabAppFooterMetaSection, GoabAppFooterNavSection, GoabAppHeader, GoabAppHeaderMenu, GoabBadge, GoabBlock, GoabButton, GoabButtonGroup, GoabCallout, GoabCard, GoabCardActions, GoabCardContent, GoabCardImage, GoabCheckbox, GoabChip, GoabCircularProgress, GoabColumnLayout, GoabContainer, GoabDatePicker, GoabDetails, GoabDivider, GoabDropdown, GoabDropdownItem, GoabFileUploadCard, GoabFileUploadInput, GoabFormItem, GoabFormItemSlot, GoabFormStep, GoabFormStepper, GoabGrid, GoabHeroBanner, GoabIcon, GoabIconButton, GoabInput, GoabMicrositeHeader, GoabModal, GoabNotificationBanner, GoabPages, GoabPagination, GoabPopover, GoabRadioGroup, GoabRadioItem, GoabSideMenu, GoabSideMenuGroup, GoabSideMenuHeading, GoabSkeleton, GoabSpacer, GoabTab, GoabTable, GoabTableSortHeader, GoabTabs, GoabTextArea, GoabTooltip, ValueDirective, ValueListDirective };
|
|
3993
3755
|
//# sourceMappingURL=abgov-angular-components.mjs.map
|