@neovici/cosmoz-form 3.0.0-beta.1 → 3.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/dist/form-dialog/form-dialog.d.ts.map +1 -1
- package/dist/form-dialog/form-dialog.js +3 -3
- package/dist/inputs/date-range.js +5 -5
- package/dist/inputs/inline-file.js +3 -3
- package/dist/test/use-validated-form.test.js +6 -0
- package/dist/validation/rules.d.ts +10 -10
- package/dist/validation/rules.d.ts.map +1 -1
- package/dist/validation/rules.js +19 -17
- package/package.json +4 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-dialog.d.ts","sourceRoot":"","sources":["../../src/form-dialog/form-dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"form-dialog.d.ts","sourceRoot":"","sources":["../../src/form-dialog/form-dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,gCAAgC,CAAC;AACxC,OAAO,yBAAyB,CAAC;AAWjC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAqB,MAAM,wBAAwB,CAAC;AAG9E,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;IACjE,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAiDD,MAAM,WAAW,MAAM,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,MAAM,CAAC,CAAC,CAAC,KAAG,UAkBhE,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;;;;EAIzE,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { dialog } from '@neovici/cosmoz-dialog';
|
|
2
2
|
import '@neovici/cosmoz-dialog/loading';
|
|
3
|
-
import { _ } from '@neovici/cosmoz-i18next';
|
|
4
3
|
import '@neovici/cosmoz-spinner';
|
|
5
4
|
import { invoke } from '@neovici/cosmoz-utils/function';
|
|
6
5
|
import { useEffect } from '@pionjs/pion';
|
|
6
|
+
import { t } from 'i18next';
|
|
7
7
|
import { html, nothing } from 'lit-html';
|
|
8
8
|
import { ifDefined } from 'lit-html/directives/if-defined.js';
|
|
9
9
|
import { until } from 'lit-html/directives/until.js';
|
|
@@ -14,7 +14,7 @@ import buttonStyles from '../styles/button';
|
|
|
14
14
|
import { useValidatedForm$ } from '../use-validated-form$';
|
|
15
15
|
import styles from './style.css';
|
|
16
16
|
const FormDialog = (host) => {
|
|
17
|
-
const { description, auto, uncancelable, hideCancelButton, saveText =
|
|
17
|
+
const { description, auto, uncancelable, hideCancelButton, saveText = t('OK'), } = host, { onSave, disabled, save$, progress, ...form } = useValidatedForm$(host);
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
if (!auto) {
|
|
20
20
|
return;
|
|
@@ -30,7 +30,7 @@ const FormDialog = (host) => {
|
|
|
30
30
|
${renderFailure$(save$)}
|
|
31
31
|
${renderButton$({ save$, onSave, disabled, title: saveText, progress })}
|
|
32
32
|
${when(!hideCancelButton, () => html `<button class="button" value="cancel" ?disabled=${uncancelable}>
|
|
33
|
-
${
|
|
33
|
+
${t('Cancel')}
|
|
34
34
|
</button>`)}
|
|
35
35
|
</div>`;
|
|
36
36
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t } from 'i18next';
|
|
2
2
|
import { html } from 'lit-html';
|
|
3
3
|
import { ifDefined } from 'lit-html/directives/if-defined.js';
|
|
4
4
|
import { live } from 'lit-html/directives/live.js';
|
|
@@ -17,7 +17,7 @@ const _dateRange = (type) => input(({ id, label, error, warning, disabled, onCha
|
|
|
17
17
|
?disabled=${disabled}
|
|
18
18
|
?invalid=${!!error?.from}
|
|
19
19
|
.errorMessage=${error?.from}
|
|
20
|
-
.label=${
|
|
20
|
+
.label=${t('From ({0})', { 0: label })}
|
|
21
21
|
.value=${live(value?.from)}
|
|
22
22
|
.max=${ifDefined(value?.to)}
|
|
23
23
|
@change=${({ target }) => onChange({ ...value, from: target.value })}
|
|
@@ -30,7 +30,7 @@ const _dateRange = (type) => input(({ id, label, error, warning, disabled, onCha
|
|
|
30
30
|
?disabled=${disabled}
|
|
31
31
|
?invalid=${!!error?.to}
|
|
32
32
|
.errorMessage=${error?.to}
|
|
33
|
-
.label=${
|
|
33
|
+
.label=${t('To ({0})', { 0: label })}
|
|
34
34
|
.value=${live(value?.to)}
|
|
35
35
|
.min=${ifDefined(value?.from)}
|
|
36
36
|
@change=${({ target }) => onChange({ ...value, to: target.value })}
|
|
@@ -41,6 +41,6 @@ export const dateRange = _dateRange('date'), dateTimeRange = _dateRange('datetim
|
|
|
41
41
|
// error is typed as string | false, but here we have an object with errors per field
|
|
42
42
|
// TODO: review how the error is handled
|
|
43
43
|
missingRange = (value) => (missing(value?.from) || missing(value?.to)) && {
|
|
44
|
-
from: missing(value?.from) &&
|
|
45
|
-
to: missing(value?.to) &&
|
|
44
|
+
from: missing(value?.from) && t('Required'),
|
|
45
|
+
to: missing(value?.to) && t('Required'),
|
|
46
46
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ } from '@neovici/cosmoz-i18next';
|
|
2
1
|
import { tagged as css } from '@neovici/cosmoz-utils';
|
|
3
2
|
import { invoke, noop } from '@neovici/cosmoz-utils/function';
|
|
3
|
+
import { t } from 'i18next';
|
|
4
4
|
import { html } from 'lit-html';
|
|
5
5
|
import { ifDefined } from 'lit-html/directives/if-defined.js';
|
|
6
6
|
import { until } from 'lit-html/directives/until.js';
|
|
@@ -46,11 +46,11 @@ const icon = html `<svg
|
|
|
46
46
|
</svg>`;
|
|
47
47
|
const humanLabel = (value) => {
|
|
48
48
|
if (!value)
|
|
49
|
-
return
|
|
49
|
+
return t('Choose file');
|
|
50
50
|
if (Array.isArray(value)) {
|
|
51
51
|
if (value.length === 1)
|
|
52
52
|
return value[0].name;
|
|
53
|
-
return
|
|
53
|
+
return t('{0} files', { 0: value.length });
|
|
54
54
|
}
|
|
55
55
|
return value.name;
|
|
56
56
|
};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/* eslint-disable mocha/max-top-level-suites */
|
|
2
2
|
import { renderHook } from '@neovici/testing';
|
|
3
3
|
import { assert, waitUntil } from '@open-wc/testing';
|
|
4
|
+
import i18next from 'i18next';
|
|
4
5
|
import { useValidatedForm } from '../use-validated-form';
|
|
5
6
|
import { required, tooLong, tooShort } from '../validation';
|
|
7
|
+
i18next.init({
|
|
8
|
+
lng: 'en',
|
|
9
|
+
resources: { en: { translation: {} } },
|
|
10
|
+
fallbackLng: false,
|
|
11
|
+
});
|
|
6
12
|
suite('useValidatedForm', () => {
|
|
7
13
|
let result;
|
|
8
14
|
let nextUpdate;
|
|
@@ -6,16 +6,16 @@ export declare const required: <T>(value: T) => string | false;
|
|
|
6
6
|
export declare const requiredWhen: <T extends object, K extends keyof T, V extends T[K]>(condition: (value: V, values: T) => boolean) => Rule<T, K, V>;
|
|
7
7
|
export declare const requireEither: <T extends object, K extends keyof T, V extends T[K], P extends keyof T>(otherField: P) => Rule<T, K, V>;
|
|
8
8
|
export declare function notAnOption<T extends object, K extends keyof T, V extends T[K], O, OK extends keyof O>(options: O[], key?: OK): Rule<T, K, V>;
|
|
9
|
-
export declare const tooShort: (length: number) => <V extends string | undefined>(value: V) => string | false;
|
|
10
|
-
export declare const tooLong: (length: number) => <V extends string | undefined>(value: V) => string | false;
|
|
11
|
-
export declare const exactLength: (length: number) => <V extends string | undefined>(value: V) => string | false;
|
|
12
|
-
export declare const tooSmall: (min: number) => <V extends number | undefined>(value: V) => string | false;
|
|
13
|
-
export declare const tooSmallStrict: (min: number) => <V extends number | undefined>(value: V) => string | false;
|
|
14
|
-
export declare const tooBig: (max: number) => <V extends number | undefined>(value: V) => string | false;
|
|
15
|
-
export declare const doesNotMatchFormat: (regexp: RegExp, message?: string) => <V extends string | undefined>(value: V) => string | false;
|
|
16
|
-
export declare const luhn: <V extends string | undefined>(value: V) => string | false;
|
|
17
|
-
export declare const gln: <V extends string | undefined>(value: V) => string | false;
|
|
18
|
-
export declare const onlyDigits: <V extends string | undefined>(value: V) => string | false;
|
|
9
|
+
export declare const tooShort: (length: number) => <V extends string | null | undefined>(value: V) => string | false;
|
|
10
|
+
export declare const tooLong: (length: number) => <V extends string | null | undefined>(value: V) => string | false;
|
|
11
|
+
export declare const exactLength: (length: number) => <V extends string | null | undefined>(value: V) => string | false;
|
|
12
|
+
export declare const tooSmall: (min: number) => <V extends number | null | undefined>(value: V) => string | false;
|
|
13
|
+
export declare const tooSmallStrict: (min: number) => <V extends number | null | undefined>(value: V) => string | false;
|
|
14
|
+
export declare const tooBig: (max: number) => <V extends number | null | undefined>(value: V) => string | false;
|
|
15
|
+
export declare const doesNotMatchFormat: (regexp: RegExp, message?: string) => <V extends string | null | undefined>(value: V) => string | false;
|
|
16
|
+
export declare const luhn: <V extends string | null | undefined>(value: V) => string | false;
|
|
17
|
+
export declare const gln: <V extends string | null | undefined>(value: V) => string | false;
|
|
18
|
+
export declare const onlyDigits: <V extends string | null | undefined>(value: V) => string | false;
|
|
19
19
|
export declare const hint: <K extends PropertyKey>(field: K) => {
|
|
20
20
|
value: (<V, O_1 extends Record<K, any>>(value: V, values: O_1) => NonNullable<V> | {
|
|
21
21
|
label: NonNullable<O_1[K]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/validation/rules.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAIhC,eAAO,MAAM,WAAW,MAAM,EAC7B,WAAW,KAAK,EAChB,YAAY,KAAK,CAAC;AAEnB,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,OAAO,CAAC,YAIQ,CAAC;AAE5C,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,IAAI,WAAW,CAAC,CAAC,CAAoB,CAAC;AAEhF,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,OAAO,CAAC,mBAAoC,CAAC;AAEzE,eAAO,MAAM,YAAY,GACvB,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EACnD,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,KACzC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAEsD,CAAC;AAEvE,eAAO,MAAM,aAAa,GACxB,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EACtE,YAAY,CAAC,KACX,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAKD,CAAC;AAEhB,wBAAgB,WAAW,CAC1B,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAC,EACjB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EACd,CAAC,EACD,EAAE,SAAS,MAAM,CAA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AAK7B,eAAO,MAAM,UAAU,GACrB,WAAW,MAAM,EAAE,gBAAgD,MACnE,CAAC,EAAE,OAAO,CAAC,mBAIX,CAAC"}
|
package/dist/validation/rules.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { _ } from '@neovici/cosmoz-i18next';
|
|
2
1
|
import { ensureDate } from '@neovici/cosmoz-utils/date';
|
|
3
2
|
import { format } from 'date-fns/format';
|
|
4
3
|
import { addDays } from 'date-fns/fp/addDays';
|
|
4
|
+
import { t } from 'i18next';
|
|
5
5
|
import { gln as isGln } from '../util/gln';
|
|
6
6
|
import { luhn as isLuhn } from '../util/luhn';
|
|
7
7
|
export const STRING_TEXT = 200, STRING_LONG = 50, STRING_SHORT = 20;
|
|
@@ -10,39 +10,41 @@ export const missing = (value) => value == null ||
|
|
|
10
10
|
Number.isNaN(value) ||
|
|
11
11
|
(Array.isArray(value) && value.length < 1);
|
|
12
12
|
export const exists = (value) => !missing(value);
|
|
13
|
-
export const required = (value) => missing(value) &&
|
|
13
|
+
export const required = (value) => missing(value) && t('Required');
|
|
14
14
|
export const requiredWhen = (condition) => (value, values) => values != null && condition(value, values) ? required(value) : false;
|
|
15
15
|
export const requireEither = (otherField) => (value, values) => missing(value) &&
|
|
16
16
|
values != null &&
|
|
17
17
|
missing(values[otherField]) &&
|
|
18
|
-
|
|
18
|
+
t('Required');
|
|
19
19
|
export function notAnOption(options, key) {
|
|
20
20
|
return (value) => !missing(value) &&
|
|
21
21
|
options != null &&
|
|
22
22
|
!options.some((option) => option[(key ?? 'value')] === value) &&
|
|
23
|
-
|
|
23
|
+
t('Option not among possible values');
|
|
24
24
|
}
|
|
25
25
|
export const tooShort = (length) => (value) => exists(value) &&
|
|
26
26
|
value.length < length &&
|
|
27
|
-
|
|
27
|
+
t('Must have at least {0} characters', { 0: length });
|
|
28
28
|
export const tooLong = (length) => (value) => exists(value) &&
|
|
29
29
|
value.length > length &&
|
|
30
|
-
|
|
30
|
+
t('Must have maximum {0} characters', { 0: length });
|
|
31
31
|
export const exactLength = (length) => (value) => exists(value) &&
|
|
32
32
|
value.length !== length &&
|
|
33
|
-
|
|
33
|
+
t('Must have exactly {0} characters', { 0: length });
|
|
34
34
|
export const tooSmall = (min) => (value) => exists(value) &&
|
|
35
35
|
value < min &&
|
|
36
|
-
|
|
37
|
-
export const tooSmallStrict = (min) => (value) => exists(value) &&
|
|
36
|
+
t('Value must be greater or equal to {0}', { 0: min });
|
|
37
|
+
export const tooSmallStrict = (min) => (value) => exists(value) &&
|
|
38
|
+
value <= min &&
|
|
39
|
+
t('Value must be greater than {0}', { 0: min });
|
|
38
40
|
export const tooBig = (max) => (value) => exists(value) &&
|
|
39
41
|
exists(max) &&
|
|
40
42
|
value > max &&
|
|
41
|
-
|
|
43
|
+
t('Value must be less or equal to {0}', { 0: max });
|
|
42
44
|
export const doesNotMatchFormat = (regexp, message = 'Does not match format: ' + regexp) => (value) => exists(value) && !value.match(regexp) && message;
|
|
43
|
-
export const luhn = (value) => exists(value) && !isLuhn(value) &&
|
|
44
|
-
export const gln = (value) => exists(value) && !isGln(value) &&
|
|
45
|
-
export const onlyDigits = (value) => exists(value) && !/^[0-9]+$/u.test(value) &&
|
|
45
|
+
export const luhn = (value) => exists(value) && !isLuhn(value) && t('Not a valid identification number');
|
|
46
|
+
export const gln = (value) => exists(value) && !isGln(value) && t('Not a valid identification number');
|
|
47
|
+
export const onlyDigits = (value) => exists(value) && !/^[0-9]+$/u.test(value) && t('Only digits allowed');
|
|
46
48
|
export const hint = (field) => ({
|
|
47
49
|
value: [
|
|
48
50
|
(value, values) => {
|
|
@@ -63,7 +65,7 @@ export const hint = (field) => ({
|
|
|
63
65
|
return false;
|
|
64
66
|
}
|
|
65
67
|
const hintValue = values[field];
|
|
66
|
-
return hintValue == null ? req :
|
|
68
|
+
return hintValue == null ? req : t('Option not among possible values');
|
|
67
69
|
},
|
|
68
70
|
});
|
|
69
71
|
export const afterStartDate = (startDateField, eq) => (value, values) => {
|
|
@@ -74,7 +76,7 @@ export const afterStartDate = (startDateField, eq) => (value, values) => {
|
|
|
74
76
|
const endTime = end.getTime();
|
|
75
77
|
const startTime = start.getTime();
|
|
76
78
|
const invalid = eq ? endTime < startTime : endTime <= startTime;
|
|
77
|
-
return invalid &&
|
|
79
|
+
return invalid && t('End date must be after start date');
|
|
78
80
|
};
|
|
79
81
|
export const minDate = (date) => (value) => {
|
|
80
82
|
const dateValue = ensureDate(value), minDateValue = ensureDate(date);
|
|
@@ -83,14 +85,14 @@ export const minDate = (date) => (value) => {
|
|
|
83
85
|
return (dateValue &&
|
|
84
86
|
minDateValue &&
|
|
85
87
|
dateValue.getTime() <= minDateValue.getTime() &&
|
|
86
|
-
|
|
88
|
+
t('Date must be bigger than {0}', { 0: date }));
|
|
87
89
|
};
|
|
88
90
|
export const maxDate = (date) => (value) => {
|
|
89
91
|
const dateValue = ensureDate(value), maxDateValue = ensureDate(date);
|
|
90
92
|
if (!dateValue || !maxDateValue)
|
|
91
93
|
return false;
|
|
92
94
|
return (maxDateValue.getTime() <= dateValue.getTime() &&
|
|
93
|
-
|
|
95
|
+
t('Date must be lower than {0}', { 0: date }));
|
|
94
96
|
};
|
|
95
97
|
export const maxDays = (days) => maxDate(format(addDays(days, new Date()), 'yyyy-MM-dd'));
|
|
96
98
|
export const xor = (otherField) => (value, values) => values[otherField] != null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-form",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "A pionjs component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@lit-labs/virtualizer": "^2.1.1",
|
|
71
71
|
"@neovici/cosmoz-autocomplete": "^10.10.4 || ^11.0.0 || ^12.0.0 || ^13.0.0",
|
|
72
72
|
"@neovici/cosmoz-dialog": "^4.0.0 || ^5.0.0",
|
|
73
|
-
"
|
|
73
|
+
"i18next": ">=23.0.0 <27.0.0",
|
|
74
74
|
"@neovici/cosmoz-icons": "^1.3.0",
|
|
75
75
|
"@neovici/cosmoz-input": "^5.5.0",
|
|
76
76
|
"@neovici/cosmoz-spinner": "^1.0.2",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@commitlint/cli": "^20.0.0",
|
|
84
84
|
"@commitlint/config-conventional": "^20.0.0",
|
|
85
|
-
"@neovici/cfg": "^2.
|
|
85
|
+
"@neovici/cfg": "^2.11.0",
|
|
86
86
|
"@neovici/testing": "^2.0.0",
|
|
87
87
|
"@open-wc/testing": "^4.0.0",
|
|
88
88
|
"@open-wc/testing-helpers": "^3.0.1",
|
|
@@ -103,7 +103,6 @@
|
|
|
103
103
|
"storybook": "^10.0.0"
|
|
104
104
|
},
|
|
105
105
|
"overrides": {
|
|
106
|
-
"conventional-changelog-conventionalcommits": ">= 8.0.0"
|
|
107
|
-
"@polymer/polymer": "^3.5.2"
|
|
106
|
+
"conventional-changelog-conventionalcommits": ">= 8.0.0"
|
|
108
107
|
}
|
|
109
108
|
}
|