@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.
Files changed (61) hide show
  1. package/README.md +123 -15
  2. package/components/NAlert.js +81 -0
  3. package/components/NBadge.js +57 -0
  4. package/components/NBreadcrub.js +66 -0
  5. package/components/NButton.js +65 -0
  6. package/components/NCheckbox.js +42 -0
  7. package/components/NCheckboxLabel.js +39 -0
  8. package/components/NCrudModal.js +105 -0
  9. package/components/NDialog.js +160 -0
  10. package/components/NDropdown.js +108 -0
  11. package/components/NDropzone.js +210 -0
  12. package/components/NForm.js +28 -0
  13. package/components/NFormModal.js +54 -0
  14. package/components/NIconButton.js +81 -0
  15. package/components/NIconCircle.js +66 -0
  16. package/components/NInput.js +105 -0
  17. package/components/NInputPhone.d.ts +1 -1
  18. package/components/NInputPhone.js +46 -0
  19. package/components/NInputPhone.jsx +2 -1
  20. package/components/NInputSelect.js +114 -0
  21. package/components/NInputSuggestion.d.ts +1 -1
  22. package/components/NInputSuggestion.js +63 -0
  23. package/components/NLink.js +59 -0
  24. package/components/NList.js +24 -0
  25. package/components/NLoadingIndicator.js +53 -0
  26. package/components/NModal.js +210 -0
  27. package/components/NPagination.js +108 -0
  28. package/components/NSearchbar.js +66 -0
  29. package/components/NSearchbarList.js +36 -0
  30. package/components/NSelect.js +84 -0
  31. package/components/NSuggestionList.js +156 -0
  32. package/components/NTable.js +126 -0
  33. package/components/NTableAction.js +49 -0
  34. package/components/NTextArea.d.ts +1 -1
  35. package/components/NTextArea.js +128 -0
  36. package/components/NTooltip.js +178 -0
  37. package/components/NValInput.d.ts +1 -1
  38. package/components/NValInput.js +104 -0
  39. package/components/ValidatedForm.js +18 -18
  40. package/i18n/index.d.ts +24 -1
  41. package/i18n/index.js +13 -16
  42. package/index.d.ts +2 -0
  43. package/index.js +2 -0
  44. package/package.json +11 -4
  45. package/utils/breakpoints.js +21 -21
  46. package/utils/component.js +17 -9
  47. package/utils/deferred.js +12 -12
  48. package/utils/identifiable.js +27 -29
  49. package/utils/stringMaxLength.js +8 -13
  50. package/utils/tailwind.js +1 -1
  51. package/utils/utils.js +5 -5
  52. package/utils/vModel.js +82 -73
  53. package/utils/validation.d.ts +9 -3
  54. package/utils/validation.js +67 -83
  55. package/utils/vue.js +7 -5
  56. package/i18n/de/template.json +0 -10
  57. package/i18n/de.d.ts +0 -61
  58. package/i18n/de.js +0 -5
  59. package/i18n/en/template.json +0 -10
  60. package/i18n/en.d.ts +0 -61
  61. package/i18n/en.js +0 -5
@@ -1,9 +1,24 @@
1
1
  import { trsl } from '../i18n';
2
+ /**
3
+ * Creates a valid result.
4
+ */
2
5
  export function validResult() {
3
- return { isValid: true };
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
- export function invalidResult(ruleKey, params) {
6
- return { isValid: false, errorMessage: trsl(`vue-collection.validation.rules.${ruleKey}`, params) };
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
- for (const rule of rules) {
19
- const validationResult = rule(input);
20
- if (!validationResult.isValid)
21
- return validationResult;
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
- const trimmed = input?.trim();
33
- if (trimmed)
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
- if (!input || Number.isInteger(+input))
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
- return input => {
55
- if (!input)
56
- return validResult();
57
- if (min !== undefined && max !== undefined && !(min <= input.length && input.length <= max))
58
- return invalidResult('length.min-max', { min, max });
59
- else if (min !== undefined && !(min <= input.length))
60
- return invalidResult('length.min', { min });
61
- else if (max !== undefined && !(input.length <= max))
62
- return invalidResult('length.max', { max });
63
- return validResult();
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
- return input => {
73
- if (!input)
74
- return validResult();
75
- const parsed = Number.parseFloat(input);
76
- if (Number.isNaN(parsed))
77
- return invalidResult('number-range.nan');
78
- if (min !== undefined && max !== undefined && !(min <= parsed && parsed <= max))
79
- return invalidResult('number-range.min-max', { min, max });
80
- else if (min !== undefined && !(min <= parsed))
81
- return invalidResult('number-range.min', { min });
82
- else if (max !== undefined && !(parsed <= max))
83
- return invalidResult('number-range.max', { max });
84
- return validResult();
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
- if (!input || VALIDATION_FORMAT_EMAIL.test(input))
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
- if (!input || VALIDATION_FORMAT_PASSWORD.test(input))
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
- return input => {
125
- if (input === other)
126
- return validResult();
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
- return input => {
137
- if (!input || options.includes(input || ''))
138
- return validResult();
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
- return input => {
149
- if (!input || pattern.test(input || ''))
150
- return validResult();
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 somwhere else.
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, errorKey) {
162
- return input => (!input || isValid ? validResult() : invalidResult(errorKey));
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
- watch(updater, newValue => {
9
- ref.value = newValue;
10
- }, { immediate: true });
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
- watch(() => ref.value, onChange);
19
- }
20
+ watch(() => ref.value, onChange);
21
+ }
@@ -1,10 +0,0 @@
1
- {
2
- "title": {},
3
- "subtitle": {},
4
- "text": {},
5
- "property": {},
6
- "term": {},
7
- "action": {},
8
- "enum": {},
9
- "error": {}
10
- }
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
@@ -1,5 +0,0 @@
1
- import vueCollection from './de/vue-collection.json';
2
- const de = {
3
- ['vue-collection']: vueCollection,
4
- };
5
- export default de;
@@ -1,10 +0,0 @@
1
- {
2
- "title": {},
3
- "subtitle": {},
4
- "text": {},
5
- "property": {},
6
- "term": {},
7
- "action": {},
8
- "enum": {},
9
- "error": {}
10
- }
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;
package/i18n/en.js DELETED
@@ -1,5 +0,0 @@
1
- import vueCollection from './en/vue-collection.json';
2
- const en = {
3
- ['vue-collection']: vueCollection,
4
- };
5
- export default en;