@naptics/vue-collection 0.0.2 → 0.0.4
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/README.md +123 -15
- package/components/NAlert.js +81 -0
- package/components/NBadge.js +57 -0
- package/components/NBreadcrub.js +66 -0
- package/components/NButton.js +65 -0
- package/components/NCheckbox.js +42 -0
- package/components/NCheckboxLabel.js +39 -0
- package/components/NCrudModal.js +105 -0
- package/components/NDialog.js +160 -0
- package/components/NDropdown.js +108 -0
- package/components/NDropzone.js +210 -0
- package/components/NForm.js +28 -0
- package/components/NFormModal.js +54 -0
- package/components/NIconButton.js +81 -0
- package/components/NIconCircle.js +66 -0
- package/components/NInput.js +105 -0
- package/components/NInputPhone.d.ts +1 -1
- package/components/NInputPhone.js +46 -0
- package/components/NInputPhone.jsx +2 -1
- package/components/NInputSelect.js +114 -0
- package/components/NInputSuggestion.d.ts +1 -1
- package/components/NInputSuggestion.js +63 -0
- package/components/NLink.js +59 -0
- package/components/NList.js +24 -0
- package/components/NLoadingIndicator.js +53 -0
- package/components/NModal.js +210 -0
- package/components/NPagination.js +108 -0
- package/components/NSearchbar.js +66 -0
- package/components/NSearchbarList.js +36 -0
- package/components/NSelect.js +84 -0
- package/components/NSuggestionList.js +156 -0
- package/components/NTable.js +126 -0
- package/components/NTableAction.js +49 -0
- package/components/NTextArea.d.ts +1 -1
- package/components/NTextArea.js +128 -0
- package/components/NTooltip.js +178 -0
- package/components/NValInput.d.ts +1 -1
- package/components/NValInput.js +104 -0
- package/components/ValidatedForm.js +18 -18
- package/i18n/index.d.ts +24 -1
- package/i18n/index.js +13 -16
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +11 -4
- package/utils/breakpoints.js +21 -21
- package/utils/component.js +17 -9
- package/utils/deferred.js +12 -12
- package/utils/identifiable.js +27 -29
- package/utils/stringMaxLength.js +8 -13
- package/utils/tailwind.js +1 -1
- package/utils/utils.js +5 -5
- package/utils/vModel.js +82 -73
- package/utils/validation.d.ts +9 -3
- package/utils/validation.js +67 -83
- package/utils/vue.js +7 -5
- package/i18n/de/template.json +0 -10
- package/i18n/de.d.ts +0 -61
- package/i18n/de.js +0 -5
- package/i18n/en/template.json +0 -10
- package/i18n/en.d.ts +0 -61
- package/i18n/en.js +0 -5
package/utils/validation.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { trsl } from '../i18n';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a valid result.
|
|
4
|
+
*/
|
|
2
5
|
export function validResult() {
|
|
3
|
-
|
|
6
|
+
return {
|
|
7
|
+
isValid: true
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates an invalid result with the provided error message.
|
|
12
|
+
*/
|
|
13
|
+
export function invalidResult(errorMessage) {
|
|
14
|
+
return {
|
|
15
|
+
isValid: false,
|
|
16
|
+
errorMessage
|
|
17
|
+
};
|
|
4
18
|
}
|
|
5
|
-
|
|
6
|
-
|
|
19
|
+
const TRANSLATION_KEY_BASE = 'vue-collection.validation.rules';
|
|
20
|
+
function invalidResultInternal(key, params) {
|
|
21
|
+
return invalidResult(trsl(`${TRANSLATION_KEY_BASE}.${key}`, params));
|
|
7
22
|
}
|
|
8
23
|
/**
|
|
9
24
|
* Validates a given input with the specified rules.
|
|
@@ -15,12 +30,11 @@ export function invalidResult(ruleKey, params) {
|
|
|
15
30
|
* @returns an object containing the result of the validation.
|
|
16
31
|
*/
|
|
17
32
|
export function validate(input, rules) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return validResult();
|
|
33
|
+
for (const rule of rules) {
|
|
34
|
+
const validationResult = rule(input);
|
|
35
|
+
if (!validationResult.isValid) return validationResult;
|
|
36
|
+
}
|
|
37
|
+
return validResult();
|
|
24
38
|
}
|
|
25
39
|
/*
|
|
26
40
|
* ---------- Validation Rules ----------
|
|
@@ -29,20 +43,14 @@ export function validate(input, rules) {
|
|
|
29
43
|
* This rule expects the trimmed input-value to be truthy.
|
|
30
44
|
*/
|
|
31
45
|
export const required = input => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return validResult();
|
|
35
|
-
else
|
|
36
|
-
return invalidResult('required');
|
|
46
|
+
const trimmed = input?.trim();
|
|
47
|
+
if (trimmed) return validResult();else return invalidResultInternal('required');
|
|
37
48
|
};
|
|
38
49
|
/**
|
|
39
50
|
* This rule expects the input to be an integer.
|
|
40
51
|
*/
|
|
41
52
|
export const integer = input => {
|
|
42
|
-
|
|
43
|
-
return validResult();
|
|
44
|
-
else
|
|
45
|
-
return invalidResult('integer');
|
|
53
|
+
if (!input || Number.isInteger(+input)) return validResult();else return invalidResultInternal('integer');
|
|
46
54
|
};
|
|
47
55
|
/**
|
|
48
56
|
* This rule expects the input to be in the specified length range. An empty input
|
|
@@ -51,17 +59,18 @@ export const integer = input => {
|
|
|
51
59
|
* @param max The maximum length of the string.
|
|
52
60
|
*/
|
|
53
61
|
export function length(min, max) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
return input => {
|
|
63
|
+
if (!input) return validResult();
|
|
64
|
+
if (min !== undefined && max !== undefined && !(min <= input.length && input.length <= max)) return invalidResultInternal('length.min-max', {
|
|
65
|
+
min,
|
|
66
|
+
max
|
|
67
|
+
});else if (min !== undefined && !(min <= input.length)) return invalidResultInternal('length.min', {
|
|
68
|
+
min
|
|
69
|
+
});else if (max !== undefined && !(input.length <= max)) return invalidResultInternal('length.max', {
|
|
70
|
+
max
|
|
71
|
+
});
|
|
72
|
+
return validResult();
|
|
73
|
+
};
|
|
65
74
|
}
|
|
66
75
|
/**
|
|
67
76
|
* This rule expects the input to be a number in the specified range.
|
|
@@ -69,50 +78,34 @@ export function length(min, max) {
|
|
|
69
78
|
* @param max the upper bound, if `undefined` there is no upper bound.
|
|
70
79
|
*/
|
|
71
80
|
export function numberRange(min, max) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
return input => {
|
|
82
|
+
if (!input) return validResult();
|
|
83
|
+
const parsed = Number.parseFloat(input);
|
|
84
|
+
if (Number.isNaN(parsed)) return invalidResultInternal('number-range.nan');
|
|
85
|
+
if (min !== undefined && max !== undefined && !(min <= parsed && parsed <= max)) return invalidResultInternal('number-range.min-max', {
|
|
86
|
+
min,
|
|
87
|
+
max
|
|
88
|
+
});else if (min !== undefined && !(min <= parsed)) return invalidResultInternal('number-range.min', {
|
|
89
|
+
min
|
|
90
|
+
});else if (max !== undefined && !(parsed <= max)) return invalidResultInternal('number-range.max', {
|
|
91
|
+
max
|
|
92
|
+
});
|
|
93
|
+
return validResult();
|
|
94
|
+
};
|
|
86
95
|
}
|
|
87
96
|
export const VALIDATION_FORMAT_EMAIL = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/;
|
|
88
97
|
/**
|
|
89
98
|
* This rule expects the input-value to be a valid email adress matching {@link VALIDATION_FORMAT_EMAIL}.
|
|
90
99
|
*/
|
|
91
100
|
export const email = input => {
|
|
92
|
-
|
|
93
|
-
return validResult();
|
|
94
|
-
else
|
|
95
|
-
return invalidResult('email');
|
|
101
|
+
if (!input || VALIDATION_FORMAT_EMAIL.test(input)) return validResult();else return invalidResultInternal('email');
|
|
96
102
|
};
|
|
97
103
|
export const VALIDATION_FORMAT_PASSWORD = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+\-=!*()@%&?]).{8,}$/;
|
|
98
104
|
/**
|
|
99
105
|
* This rule expects the input-value to be a password matching {@link VALIDATION_FORMAT_PASSWORD}.
|
|
100
106
|
*/
|
|
101
107
|
export const password = input => {
|
|
102
|
-
|
|
103
|
-
return validResult();
|
|
104
|
-
else if (input.length < 8)
|
|
105
|
-
return invalidResult('password.to-short');
|
|
106
|
-
else if (!/[a-z]+/.test(input))
|
|
107
|
-
return invalidResult('password.no-lowercase');
|
|
108
|
-
else if (!/[A-Z]+/.test(input))
|
|
109
|
-
return invalidResult('password.no-uppercase');
|
|
110
|
-
else if (!/\d+/.test(input))
|
|
111
|
-
return invalidResult('password.no-digits');
|
|
112
|
-
else if (!/[#$^+\-=!*()@%&?]+/.test(input))
|
|
113
|
-
return invalidResult('password.no-special-chars');
|
|
114
|
-
else
|
|
115
|
-
return invalidResult('password.unknown');
|
|
108
|
+
if (!input || VALIDATION_FORMAT_PASSWORD.test(input)) return validResult();else if (input.length < 8) return invalidResultInternal('password.to-short');else if (!/[a-z]+/.test(input)) return invalidResultInternal('password.no-lowercase');else if (!/[A-Z]+/.test(input)) return invalidResultInternal('password.no-uppercase');else if (!/\d+/.test(input)) return invalidResultInternal('password.no-digits');else if (!/[#$^+\-=!*()@%&?]+/.test(input)) return invalidResultInternal('password.no-special-chars');else return invalidResultInternal('password.unknown');
|
|
116
109
|
};
|
|
117
110
|
/**
|
|
118
111
|
* This rule expects the input-value to match another (input-) value.
|
|
@@ -121,43 +114,34 @@ export const password = input => {
|
|
|
121
114
|
* @param other the other value to match
|
|
122
115
|
*/
|
|
123
116
|
export function matches(other) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
else
|
|
128
|
-
return invalidResult('matches');
|
|
129
|
-
};
|
|
117
|
+
return input => {
|
|
118
|
+
if (input === other) return validResult();else return invalidResultInternal('matches');
|
|
119
|
+
};
|
|
130
120
|
}
|
|
131
121
|
/**
|
|
132
122
|
* This rule expects the input-value to match one option in an array.
|
|
133
123
|
* @param options the options which the input can match
|
|
134
124
|
*/
|
|
135
125
|
export function option(options) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
else
|
|
140
|
-
return invalidResult('option');
|
|
141
|
-
};
|
|
126
|
+
return input => {
|
|
127
|
+
if (!input || options.includes(input || '')) return validResult();else return invalidResultInternal('option');
|
|
128
|
+
};
|
|
142
129
|
}
|
|
143
130
|
/**
|
|
144
131
|
* This rule expects the input-value to match the regex pattern
|
|
145
132
|
* @param pattern the pattern the input should match.
|
|
146
133
|
*/
|
|
147
134
|
export function regex(pattern) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
else
|
|
152
|
-
return invalidResult('regex');
|
|
153
|
-
};
|
|
135
|
+
return input => {
|
|
136
|
+
if (!input || pattern.test(input || '')) return validResult();else return invalidResultInternal('regex');
|
|
137
|
+
};
|
|
154
138
|
}
|
|
155
139
|
/**
|
|
156
|
-
* This rule can be used if the validation logic happens
|
|
140
|
+
* This rule can be used if the validation logic happens somewhere else.
|
|
157
141
|
* When `isValid = true` is passed, the function will return a valid result,
|
|
158
142
|
* otherwise it will return the invalid result with the passed `errorKey`.
|
|
159
143
|
* Like always, a falsy input is always valid to not interefere with the {@link required} rule.
|
|
160
144
|
*/
|
|
161
|
-
export function external(isValid,
|
|
162
|
-
|
|
163
|
-
}
|
|
145
|
+
export function external(isValid, errorMessage) {
|
|
146
|
+
return input => !input || isValid ? validResult() : invalidResult(errorMessage);
|
|
147
|
+
}
|
package/utils/vue.js
CHANGED
|
@@ -5,9 +5,11 @@ import { watch } from 'vue';
|
|
|
5
5
|
* @param updater the updater funtion which provides the updates
|
|
6
6
|
*/
|
|
7
7
|
export function updateWith(ref, updater) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
watch(updater, newValue => {
|
|
9
|
+
ref.value = newValue;
|
|
10
|
+
}, {
|
|
11
|
+
immediate: true
|
|
12
|
+
});
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Conveience function to create a watcher for a ref
|
|
@@ -15,5 +17,5 @@ export function updateWith(ref, updater) {
|
|
|
15
17
|
* @param onChange the function, which is executed on change of a value
|
|
16
18
|
*/
|
|
17
19
|
export function watchRef(ref, onChange) {
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
+
watch(() => ref.value, onChange);
|
|
21
|
+
}
|
package/i18n/de/template.json
DELETED
package/i18n/de.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
declare const de: {
|
|
2
|
-
"vue-collection": {
|
|
3
|
-
title: {};
|
|
4
|
-
subtitle: {};
|
|
5
|
-
text: {
|
|
6
|
-
"loading-search-results": string;
|
|
7
|
-
"no-search-results": string;
|
|
8
|
-
"drag-n-drop-files": string;
|
|
9
|
-
"files-selected": string;
|
|
10
|
-
};
|
|
11
|
-
property: {};
|
|
12
|
-
term: {};
|
|
13
|
-
action: {
|
|
14
|
-
search: string;
|
|
15
|
-
select: string;
|
|
16
|
-
remove: string;
|
|
17
|
-
cancel: string;
|
|
18
|
-
"all-right": string;
|
|
19
|
-
proceed: string;
|
|
20
|
-
save: string;
|
|
21
|
-
"clear-files": string;
|
|
22
|
-
};
|
|
23
|
-
enum: {};
|
|
24
|
-
error: {
|
|
25
|
-
"file-type": string;
|
|
26
|
-
"file-size": string;
|
|
27
|
-
"too-many-files": string;
|
|
28
|
-
};
|
|
29
|
-
validation: {
|
|
30
|
-
rules: {
|
|
31
|
-
email: string;
|
|
32
|
-
integer: string;
|
|
33
|
-
length: {
|
|
34
|
-
min: string;
|
|
35
|
-
max: string;
|
|
36
|
-
"min-max": string;
|
|
37
|
-
};
|
|
38
|
-
matches: string;
|
|
39
|
-
"number-range": {
|
|
40
|
-
nan: string;
|
|
41
|
-
min: string;
|
|
42
|
-
max: string;
|
|
43
|
-
"min-max": string;
|
|
44
|
-
};
|
|
45
|
-
option: string;
|
|
46
|
-
password: {
|
|
47
|
-
"to-short": string;
|
|
48
|
-
"no-lowercase": string;
|
|
49
|
-
"no-uppercase": string;
|
|
50
|
-
"no-digits": string;
|
|
51
|
-
"no-special-chars": string;
|
|
52
|
-
unknown: string;
|
|
53
|
-
};
|
|
54
|
-
phone: string;
|
|
55
|
-
required: string;
|
|
56
|
-
regex: string;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export default de;
|
package/i18n/de.js
DELETED
package/i18n/en/template.json
DELETED
package/i18n/en.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
declare const en: {
|
|
2
|
-
"vue-collection": {
|
|
3
|
-
title: {};
|
|
4
|
-
subtitle: {};
|
|
5
|
-
text: {
|
|
6
|
-
"loading-search-results": string;
|
|
7
|
-
"no-search-results": string;
|
|
8
|
-
"drag-n-drop-files": string;
|
|
9
|
-
"files-selected": string;
|
|
10
|
-
};
|
|
11
|
-
property: {};
|
|
12
|
-
term: {};
|
|
13
|
-
action: {
|
|
14
|
-
search: string;
|
|
15
|
-
select: string;
|
|
16
|
-
remove: string;
|
|
17
|
-
cancel: string;
|
|
18
|
-
"all-right": string;
|
|
19
|
-
proceed: string;
|
|
20
|
-
save: string;
|
|
21
|
-
"clear-files": string;
|
|
22
|
-
};
|
|
23
|
-
enum: {};
|
|
24
|
-
error: {
|
|
25
|
-
"file-type": string;
|
|
26
|
-
"file-size": string;
|
|
27
|
-
"too-many-files": string;
|
|
28
|
-
};
|
|
29
|
-
validation: {
|
|
30
|
-
rules: {
|
|
31
|
-
email: string;
|
|
32
|
-
integer: string;
|
|
33
|
-
length: {
|
|
34
|
-
min: string;
|
|
35
|
-
max: string;
|
|
36
|
-
"min-max": string;
|
|
37
|
-
};
|
|
38
|
-
matches: string;
|
|
39
|
-
"number-range": {
|
|
40
|
-
nan: string;
|
|
41
|
-
min: string;
|
|
42
|
-
max: string;
|
|
43
|
-
"min-max": string;
|
|
44
|
-
};
|
|
45
|
-
option: string;
|
|
46
|
-
password: {
|
|
47
|
-
"to-short": string;
|
|
48
|
-
"no-lowercase": string;
|
|
49
|
-
"no-uppercase": string;
|
|
50
|
-
"no-digits": string;
|
|
51
|
-
"no-special-chars": string;
|
|
52
|
-
unknown: string;
|
|
53
|
-
};
|
|
54
|
-
phone: string;
|
|
55
|
-
required: string;
|
|
56
|
-
regex: string;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export default en;
|