@digigov/form 1.1.5-496927f3 → 1.2.0-01ea6f24
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/Questions/__snapshots__/index.spec.tsx.snap +30 -30
- package/cjs/Questions/__snapshots__/index.spec.tsx.snap +30 -30
- package/cjs/inputs/ImageInput/index.js +2 -2
- package/cjs/inputs/Input/Input.stories/index.js +12 -0
- package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +36 -0
- package/cjs/inputs/Input/__stories__/MobilePhone/index.js +4 -0
- package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +4 -1
- package/cjs/lazy/index.js +517 -0
- package/cjs/validators/utils/phone/index.js +94 -70
- package/index.js +1 -1
- package/inputs/ImageInput/index.js +2 -2
- package/inputs/Input/Input.stories/index.js +1 -0
- package/inputs/Input/Input.stories.d.ts +1 -0
- package/inputs/Input/__stories__/LandlineNumber/index.js +26 -0
- package/inputs/Input/__stories__/LandlineNumber/package.json +6 -0
- package/inputs/Input/__stories__/LandlineNumber.d.ts +3 -0
- package/inputs/Input/__stories__/MobilePhone/index.js +4 -0
- package/inputs/Input/__stories__/PhoneNumber/index.js +4 -1
- package/lazy/index.js +395 -0
- package/lazy/package.json +6 -0
- package/lazy.d.ts +69 -0
- package/package.json +4 -5
- package/src/Questions/__snapshots__/index.spec.tsx.snap +30 -30
- package/src/inputs/ImageInput/index.tsx +2 -2
- package/src/inputs/Input/Input.stories.js +1 -0
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +27 -0
- package/src/inputs/Input/__stories__/MobilePhone.tsx +4 -0
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +4 -1
- package/src/lazy.js +60 -0
- package/src/validators/utils/phone.ts +152 -72
- package/validators/utils/phone/index.js +92 -66
- package/validators/utils/phone.d.ts +2 -2
|
@@ -1,87 +1,111 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.PHONE_NUMBER_VALIDATOR = exports.MOBILE_PHONE_VALIDATOR = void 0;
|
|
8
|
-
exports.
|
|
8
|
+
exports.discoverPhoneType = discoverPhoneType;
|
|
9
9
|
exports.validatePhoneNumber = validatePhoneNumber;
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
// add more countries from here libphonenumber-js/metadata.full.json
|
|
12
|
+
var countryPhoneData = {
|
|
13
|
+
"GR": ["30", "00", "5005000\\d{3}|8\\d{9,11}|(?:[269]\\d|70)\\d{8}", [10, 11, 12], [["(\\d{2})(\\d{4})(\\d{4})", "$1 $2 $3", ["21|7"]], ["(\\d{4})(\\d{6})", "$1 $2", ["2(?:2|3[2-57-9]|4[2-469]|5[2-59]|6[2-9]|7[2-69]|8[2-49])|5"]], ["(\\d{3})(\\d{3})(\\d{4})", "$1 $2 $3", ["[2689]"]], ["(\\d{3})(\\d{3,4})(\\d{5})", "$1 $2 $3", ["8"]]], 0, 0, 0, 0, 0, 0, [["2(?:1\\d\\d|2(?:2[1-46-9]|[36][1-8]|4[1-7]|5[1-4]|7[1-5]|[89][1-9])|3(?:1\\d|2[1-57]|[35][1-3]|4[13]|7[1-7]|8[124-6]|9[1-79])|4(?:1\\d|2[1-8]|3[1-4]|4[13-5]|6[1-578]|9[1-5])|5(?:1\\d|[29][1-4]|3[1-5]|4[124]|5[1-6])|6(?:1\\d|[269][1-6]|3[1245]|4[1-7]|5[13-9]|7[14]|8[1-5])|7(?:1\\d|2[1-5]|3[1-6]|4[1-7]|5[1-57]|6[135]|9[125-7])|8(?:1\\d|2[1-5]|[34][1-4]|9[1-57]))\\d{6}", [10]], ["68[57-9]\\d{7}|(?:69|94)\\d{8}", [10]], ["800\\d{7,9}"], ["90[19]\\d{7}", [10]], ["70\\d{8}", [10]], 0, ["5005000\\d{3}", [10]], 0, 0, ["8(?:0[16]|12|[27]5|50)\\d{7}", [10]]]]
|
|
14
|
+
};
|
|
15
|
+
function expandPhoneNumberStructure(compressed) {
|
|
16
|
+
var countries = Object.keys(compressed);
|
|
17
|
+
var expanded = {};
|
|
18
|
+
for (var _i = 0, _countries = countries; _i < _countries.length; _i++) {
|
|
19
|
+
var country = _countries[_i];
|
|
20
|
+
expanded[country] = {
|
|
21
|
+
fixedLine: {
|
|
22
|
+
possibleLengths: {
|
|
23
|
+
_national: compressed[country][3].map(String)
|
|
24
|
+
},
|
|
25
|
+
nationalNumberPattern: compressed[country][11][0][0]
|
|
26
|
+
},
|
|
27
|
+
mobile: {
|
|
28
|
+
nationalNumberPattern: compressed[country][11][1][0]
|
|
29
|
+
},
|
|
30
|
+
tollFree: {
|
|
31
|
+
nationalNumberPattern: compressed[country][11][2][0]
|
|
32
|
+
},
|
|
33
|
+
premiumRate: {
|
|
34
|
+
nationalNumberPattern: compressed[country][11][3][0]
|
|
35
|
+
},
|
|
36
|
+
sharedCost: {
|
|
37
|
+
nationalNumberPattern: compressed[country][11][9][0]
|
|
38
|
+
},
|
|
39
|
+
personalNumber: {
|
|
40
|
+
nationalNumberPattern: compressed[country][11][4][0]
|
|
41
|
+
},
|
|
42
|
+
uan: {
|
|
43
|
+
nationalNumberPattern: compressed[country][11][6][0]
|
|
44
|
+
},
|
|
45
|
+
id: country,
|
|
46
|
+
countryCode: compressed[country][0],
|
|
47
|
+
internationalPrefix: compressed[country][1]
|
|
48
|
+
};
|
|
19
49
|
}
|
|
20
|
-
return
|
|
21
|
-
try {
|
|
22
|
-
var phone = phoneUtil.parse(phoneNumber, country.toUpperCase());
|
|
23
|
-
if (phoneUtil.isValidNumber(phone)) {
|
|
24
|
-
if (typeOfPhoneNumber) {
|
|
25
|
-
if (matchTypeOfPhoneNumber(phone, typeOfPhoneNumber, phoneUtil)) {
|
|
26
|
-
return true;
|
|
27
|
-
} else {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.error(error);
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
50
|
+
return expanded;
|
|
40
51
|
}
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
var PHONENUMBER_SPEC = expandPhoneNumberStructure(countryPhoneData);
|
|
53
|
+
function discoverPhoneType(phoneNumber, config) {
|
|
54
|
+
var cleanNumber = phoneNumber.replace(/\D/g, "").replace(/\s/g, "").replace(/^\+/, "").replace(new RegExp("^" + config.internationalPrefix, ""), "").replace(new RegExp("^" + config.countryCode, ""), "");
|
|
55
|
+
var categories = {
|
|
56
|
+
"landline": config.fixedLine,
|
|
57
|
+
mobile: config.mobile,
|
|
58
|
+
"toll-free": config.tollFree,
|
|
59
|
+
"premium-rate": config.premiumRate
|
|
60
|
+
};
|
|
61
|
+
for (var _i2 = 0, _Object$entries = Object.entries(categories); _i2 < _Object$entries.length; _i2++) {
|
|
62
|
+
var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i2], 2),
|
|
63
|
+
categoryName = _Object$entries$_i[0],
|
|
64
|
+
categoryDetails = _Object$entries$_i[1];
|
|
65
|
+
var pattern = new RegExp("^(" + categoryDetails.nationalNumberPattern.replace(/\s/g, "") + ")$", "");
|
|
66
|
+
if (cleanNumber.match(pattern)) {
|
|
67
|
+
return categoryName; // Returns the category name if the number matches the pattern
|
|
54
68
|
}
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error(error);
|
|
57
|
-
return false;
|
|
58
69
|
}
|
|
70
|
+
|
|
71
|
+
// If no category matches, return 'Unknown'
|
|
72
|
+
return "unknown";
|
|
59
73
|
}
|
|
60
|
-
function
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!value.match(/^((\+|00){0,1}\d{1,3}[- ]?)?\d{10}$/)) {
|
|
65
|
-
return false;
|
|
74
|
+
function getNumberType(phoneNumber, country) {
|
|
75
|
+
var spec = PHONENUMBER_SPEC[country.toUpperCase()];
|
|
76
|
+
if (!spec) {
|
|
77
|
+
throw new Error("Country ".concat(country, " is not supported"));
|
|
66
78
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
value = '+30' + origValue;
|
|
77
|
-
phone = phoneUtil.parse(value);
|
|
78
|
-
}
|
|
79
|
+
var type = discoverPhoneType(phoneNumber, spec);
|
|
80
|
+
return type;
|
|
81
|
+
}
|
|
82
|
+
function isPhoneNumberValid(phoneNumber, countries) {
|
|
83
|
+
var types = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['mobile', 'landline'];
|
|
84
|
+
return countries.some(function (country) {
|
|
85
|
+
var numberType = getNumberType(phoneNumber, country);
|
|
86
|
+
if (numberType && types.includes(numberType)) {
|
|
87
|
+
return true;
|
|
79
88
|
}
|
|
80
|
-
return phoneUtil.isValidNumber(phone);
|
|
81
|
-
} catch (err) {
|
|
82
|
-
console.error(err);
|
|
83
89
|
return false;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function isNumberOfType(phoneNumber, country, type) {
|
|
93
|
+
var numberType = getNumberType(phoneNumber, country);
|
|
94
|
+
if (numberType === type) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
function validatePhoneNumber(phoneNumber) {
|
|
100
|
+
var countries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['gr'];
|
|
101
|
+
var typeOfPhoneNumber = arguments.length > 2 ? arguments[2] : undefined;
|
|
102
|
+
if (!countries || countries.length === 0) {
|
|
103
|
+
return true;
|
|
84
104
|
}
|
|
105
|
+
return isPhoneNumberValid(phoneNumber, countries, typeOfPhoneNumber ? [typeOfPhoneNumber] : undefined);
|
|
106
|
+
}
|
|
107
|
+
function validateMobile(value) {
|
|
108
|
+
return isNumberOfType(value, 'gr', 'mobile');
|
|
85
109
|
}
|
|
86
110
|
var MOBILE_PHONE_VALIDATOR = exports.MOBILE_PHONE_VALIDATOR = {
|
|
87
111
|
name: 'mobile-phone-validator',
|
|
@@ -95,7 +119,7 @@ var MOBILE_PHONE_VALIDATOR = exports.MOBILE_PHONE_VALIDATOR = {
|
|
|
95
119
|
};
|
|
96
120
|
var PHONE_NUMBER_VALIDATOR = exports.PHONE_NUMBER_VALIDATOR = function PHONE_NUMBER_VALIDATOR(field) {
|
|
97
121
|
var _field$extra, _field$extra2;
|
|
98
|
-
var
|
|
122
|
+
var countryCodes = field === null || field === void 0 ? void 0 : (_field$extra = field.extra) === null || _field$extra === void 0 ? void 0 : _field$extra.countries;
|
|
99
123
|
var typeOfPhone = field === null || field === void 0 ? void 0 : (_field$extra2 = field.extra) === null || _field$extra2 === void 0 ? void 0 : _field$extra2.phoneType;
|
|
100
124
|
return {
|
|
101
125
|
name: 'phone-number-validator',
|
|
@@ -113,7 +137,7 @@ var PHONE_NUMBER_VALIDATOR = exports.PHONE_NUMBER_VALIDATOR = function PHONE_NUM
|
|
|
113
137
|
if (!value) {
|
|
114
138
|
return true;
|
|
115
139
|
}
|
|
116
|
-
return validatePhoneNumber(value,
|
|
140
|
+
return validatePhoneNumber(value, countryCodes, typeOfPhone);
|
|
117
141
|
}
|
|
118
142
|
};
|
|
119
143
|
};
|
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export var Image = /*#__PURE__*/React.memo(function Image(_ref) {
|
|
|
14
14
|
var src = _ref.src;
|
|
15
15
|
return /*#__PURE__*/React.createElement("img", {
|
|
16
16
|
src: src,
|
|
17
|
-
className: "
|
|
17
|
+
className: "ds-image--ratio"
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
export var ImageInput = /*#__PURE__*/React.forwardRef(function ImageInput(_ref2, ref) {
|
|
@@ -53,7 +53,7 @@ export var ImageInput = /*#__PURE__*/React.forwardRef(function ImageInput(_ref2,
|
|
|
53
53
|
setImageUrl('');
|
|
54
54
|
}, [selectedImage]);
|
|
55
55
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FileUploadContainer, null, selectedImage !== null ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Paragraph, null, /*#__PURE__*/React.createElement("b", null, t('upload.image'), ":"), " ", "".concat(selectedImage === null || selectedImage === void 0 ? void 0 : selectedImage.name))) : /*#__PURE__*/React.createElement(CoreHint, {
|
|
56
|
-
className: "
|
|
56
|
+
className: "ds-dashed--border"
|
|
57
57
|
}, t('upload.no_image')), /*#__PURE__*/React.createElement(React.Fragment, null, selectedImage !== null && /*#__PURE__*/React.createElement(Image, {
|
|
58
58
|
src: imageUrl
|
|
59
59
|
}), /*#__PURE__*/React.createElement(ButtonGroup, {
|
|
@@ -8,6 +8,7 @@ export * from '@digigov/form/inputs/Input/__stories__/Default';
|
|
|
8
8
|
export * from '@digigov/form/inputs/Input/__stories__/Integer';
|
|
9
9
|
export * from '@digigov/form/inputs/Input/__stories__/Boolean';
|
|
10
10
|
export * from '@digigov/form/inputs/Input/__stories__/PhoneNumber';
|
|
11
|
+
export * from '@digigov/form/inputs/Input/__stories__/LandlineNumber';
|
|
11
12
|
export * from '@digigov/form/inputs/Input/__stories__/MobilePhone';
|
|
12
13
|
export * from '@digigov/form/inputs/Input/__stories__/AFM';
|
|
13
14
|
export * from '@digigov/form/inputs/Input/__stories__/IBAN';
|
|
@@ -8,6 +8,7 @@ export * from "@digigov/form/inputs/Input/__stories__/Default";
|
|
|
8
8
|
export * from "@digigov/form/inputs/Input/__stories__/Integer";
|
|
9
9
|
export * from "@digigov/form/inputs/Input/__stories__/Boolean";
|
|
10
10
|
export * from "@digigov/form/inputs/Input/__stories__/PhoneNumber";
|
|
11
|
+
export * from "@digigov/form/inputs/Input/__stories__/LandlineNumber";
|
|
11
12
|
export * from "@digigov/form/inputs/Input/__stories__/MobilePhone";
|
|
12
13
|
export * from "@digigov/form/inputs/Input/__stories__/AFM";
|
|
13
14
|
export * from "@digigov/form/inputs/Input/__stories__/IBAN";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import FormBuilder, { Field } from '@digigov/form';
|
|
3
|
+
import { Button } from '@digigov/ui/form/Button';
|
|
4
|
+
var _ref = /*#__PURE__*/React.createElement(Button, {
|
|
5
|
+
type: "submit"
|
|
6
|
+
}, "\u03A3\u03C5\u03BD\u03AD\u03C7\u03B5\u03B9\u03B1");
|
|
7
|
+
export var LandlineNumber = function LandlineNumber() {
|
|
8
|
+
return /*#__PURE__*/React.createElement(FormBuilder, {
|
|
9
|
+
onSubmit: function onSubmit(data) {
|
|
10
|
+
console.log(data);
|
|
11
|
+
}
|
|
12
|
+
}, /*#__PURE__*/React.createElement(Field, {
|
|
13
|
+
key: "phone-number",
|
|
14
|
+
name: "phone-number",
|
|
15
|
+
type: "phone_number",
|
|
16
|
+
label: {
|
|
17
|
+
primary: 'Σταθερό τηλέφωνο'
|
|
18
|
+
},
|
|
19
|
+
extra: {
|
|
20
|
+
countries: ['gr'],
|
|
21
|
+
phoneType: 'landline'
|
|
22
|
+
},
|
|
23
|
+
required: true
|
|
24
|
+
}), _ref);
|
|
25
|
+
};
|
|
26
|
+
export default LandlineNumber;
|