@naptics/vue-collection 0.0.3 → 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 (47) hide show
  1. package/README.md +5 -1
  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.js +46 -0
  18. package/components/NInputSelect.js +114 -0
  19. package/components/NInputSuggestion.js +63 -0
  20. package/components/NLink.js +59 -0
  21. package/components/NList.js +24 -0
  22. package/components/NLoadingIndicator.js +53 -0
  23. package/components/NModal.js +210 -0
  24. package/components/NPagination.js +108 -0
  25. package/components/NSearchbar.js +66 -0
  26. package/components/NSearchbarList.js +36 -0
  27. package/components/NSelect.js +84 -0
  28. package/components/NSuggestionList.js +156 -0
  29. package/components/NTable.js +126 -0
  30. package/components/NTableAction.js +49 -0
  31. package/components/NTextArea.js +128 -0
  32. package/components/NTooltip.js +178 -0
  33. package/components/NValInput.js +104 -0
  34. package/components/ValidatedForm.js +18 -18
  35. package/i18n/index.js +4 -8
  36. package/index.js +1 -1
  37. package/package.json +9 -2
  38. package/utils/breakpoints.js +21 -21
  39. package/utils/component.js +17 -9
  40. package/utils/deferred.js +12 -12
  41. package/utils/identifiable.js +27 -29
  42. package/utils/stringMaxLength.js +8 -13
  43. package/utils/tailwind.js +1 -1
  44. package/utils/utils.js +5 -5
  45. package/utils/vModel.js +82 -73
  46. package/utils/validation.js +55 -81
  47. package/utils/vue.js +7 -5
package/utils/utils.js CHANGED
@@ -1,12 +1,12 @@
1
1
  export function markReadonly(object) {
2
- return object;
2
+ return object;
3
3
  }
4
4
  let currentId = 1;
5
5
  /**
6
6
  * Generates and returns a non random but unique id.
7
7
  */
8
8
  export function uniqueId() {
9
- return currentId++;
9
+ return currentId++;
10
10
  }
11
11
  /**
12
12
  * Determines if a value is not null or undefined.
@@ -14,7 +14,7 @@ export function uniqueId() {
14
14
  * @returns `true` if the value is anything but `null` or `undefined`.
15
15
  */
16
16
  export function notNullish(value) {
17
- return value !== null && value !== undefined;
17
+ return value !== null && value !== undefined;
18
18
  }
19
19
  /**
20
20
  * Determines if a value is null or undefined.
@@ -22,5 +22,5 @@ export function notNullish(value) {
22
22
  * @returns `true` if the value is `null` or `undefined`.
23
23
  */
24
24
  export function isNullish(value) {
25
- return value === null || value === undefined;
26
- }
25
+ return value === null || value === undefined;
26
+ }
package/utils/vModel.js CHANGED
@@ -8,54 +8,54 @@
8
8
  * @returns An object containing the value-property and the update-function.
9
9
  */
10
10
  export function vModelProps(propType) {
11
- return {
12
- /**
13
- * The value of the component.
14
- */
15
- value: propType,
16
- /**
17
- * This will be called, when the value of the component has changed.
18
- */
19
- onUpdateValue: Function,
20
- };
11
+ return {
12
+ /**
13
+ * The value of the component.
14
+ */
15
+ value: propType,
16
+ /**
17
+ * This will be called, when the value of the component has changed.
18
+ */
19
+ onUpdateValue: Function
20
+ };
21
21
  }
22
22
  /**
23
23
  * Creates props for a required `v-model` of the given type.
24
24
  * @see {@link vModelProps}
25
25
  */
26
26
  export function vModelRequiredProps(propType) {
27
- return {
28
- /**
29
- * The value of the component.
30
- */
31
- value: {
32
- type: propType,
33
- required: true,
34
- },
35
- /**
36
- * This will be called, when the value of the component has changed.
37
- */
38
- onUpdateValue: Function,
39
- };
27
+ return {
28
+ /**
29
+ * The value of the component.
30
+ */
31
+ value: {
32
+ type: propType,
33
+ required: true
34
+ },
35
+ /**
36
+ * This will be called, when the value of the component has changed.
37
+ */
38
+ onUpdateValue: Function
39
+ };
40
40
  }
41
41
  /**
42
42
  * Creates props for a `v-model` of the given type with a default value.
43
43
  * @see {@link vModelProps}
44
44
  */
45
45
  export function vModelDefaultProps(propType, defaultValue) {
46
- return {
47
- /**
48
- * The value of the component.
49
- */
50
- value: {
51
- type: propType,
52
- default: defaultValue,
53
- },
54
- /**
55
- * This will be called, when the value of the component has changed.
56
- */
57
- onUpdateValue: Function,
58
- };
46
+ return {
47
+ /**
48
+ * The value of the component.
49
+ */
50
+ value: {
51
+ type: propType,
52
+ default: defaultValue
53
+ },
54
+ /**
55
+ * This will be called, when the value of the component has changed.
56
+ */
57
+ onUpdateValue: Function
58
+ };
59
59
  }
60
60
  /**
61
61
  * Uses the given `ref` as a `v-model`, to create a two-way binding with the `ref`.
@@ -63,12 +63,12 @@ export function vModelDefaultProps(propType, defaultValue) {
63
63
  * @returns An object of type {@link VModel}, which connects the `ref` to the `v-model`.
64
64
  */
65
65
  export function vModelForRef(ref) {
66
- return {
67
- value: ref.value,
68
- onUpdateValue: (newValue) => {
69
- ref.value = newValue;
70
- },
71
- };
66
+ return {
67
+ value: ref.value,
68
+ onUpdateValue: newValue => {
69
+ ref.value = newValue;
70
+ }
71
+ };
72
72
  }
73
73
  /**
74
74
  * This creates a `v-model` for a property of an object. The property of the object is taken as the
@@ -93,12 +93,15 @@ export function vModelForRef(ref) {
93
93
  * ```
94
94
  */
95
95
  export function vModelForObjectProperty(object, key, onUpdate) {
96
- return {
97
- value: object[key],
98
- onUpdateValue: (newValue) => {
99
- onUpdate?.({ ...object, [key]: newValue });
100
- },
101
- };
96
+ return {
97
+ value: object[key],
98
+ onUpdateValue: newValue => {
99
+ onUpdate?.({
100
+ ...object,
101
+ [key]: newValue
102
+ });
103
+ }
104
+ };
102
105
  }
103
106
  /**
104
107
  * This creates a `v-model` which operates on one property of a parent `v-model`. It takes the value of
@@ -130,12 +133,15 @@ export function vModelForObjectProperty(object, key, onUpdate) {
130
133
  * ```
131
134
  */
132
135
  export function vModelForVModelProperty(vModel, key) {
133
- return {
134
- value: vModel.value[key],
135
- onUpdateValue: (newValue) => {
136
- vModel.onUpdateValue?.({ ...vModel.value, [key]: newValue });
137
- },
138
- };
136
+ return {
137
+ value: vModel.value[key],
138
+ onUpdateValue: newValue => {
139
+ vModel.onUpdateValue?.({
140
+ ...vModel.value,
141
+ [key]: newValue
142
+ });
143
+ }
144
+ };
139
145
  }
140
146
  /**
141
147
  * This function does the same thing as {@link vModelForVModelProperty},
@@ -168,12 +174,15 @@ export function vModelForVModelProperty(vModel, key) {
168
174
  * ```
169
175
  */
170
176
  export function vModelForVModelPropertyMapType(vModel, key, mapType) {
171
- return {
172
- value: vModel.value[key],
173
- onUpdateValue: (newValue) => {
174
- vModel.onUpdateValue?.({ ...vModel.value, [key]: mapType(newValue) });
175
- },
176
- };
177
+ return {
178
+ value: vModel.value[key],
179
+ onUpdateValue: newValue => {
180
+ vModel.onUpdateValue?.({
181
+ ...vModel.value,
182
+ [key]: mapType(newValue)
183
+ });
184
+ }
185
+ };
177
186
  }
178
187
  /**
179
188
  * Creates an array of `v-models`, one for every element of an array. All changes in
@@ -200,16 +209,16 @@ export function vModelForVModelPropertyMapType(vModel, key, mapType) {
200
209
  * ```
201
210
  */
202
211
  export function vModelsForArray(array, onUpdate) {
203
- return array.map((entry, index) => ({
204
- value: entry,
205
- onUpdateValue: (entry) => {
206
- const newArray = [...array];
207
- newArray[index] = entry;
208
- onUpdate?.(newArray);
209
- },
210
- remove: () => {
211
- const newArray = [...array.slice(0, index), ...array.slice(index + 1)];
212
- onUpdate?.(newArray);
213
- },
214
- }));
215
- }
212
+ return array.map((entry, index) => ({
213
+ value: entry,
214
+ onUpdateValue: entry => {
215
+ const newArray = [...array];
216
+ newArray[index] = entry;
217
+ onUpdate?.(newArray);
218
+ },
219
+ remove: () => {
220
+ const newArray = [...array.slice(0, index), ...array.slice(index + 1)];
221
+ onUpdate?.(newArray);
222
+ }
223
+ }));
224
+ }
@@ -3,17 +3,22 @@ import { trsl } from '../i18n';
3
3
  * Creates a valid result.
4
4
  */
5
5
  export function validResult() {
6
- return { isValid: true };
6
+ return {
7
+ isValid: true
8
+ };
7
9
  }
8
10
  /**
9
11
  * Creates an invalid result with the provided error message.
10
12
  */
11
13
  export function invalidResult(errorMessage) {
12
- return { isValid: false, errorMessage };
14
+ return {
15
+ isValid: false,
16
+ errorMessage
17
+ };
13
18
  }
14
19
  const TRANSLATION_KEY_BASE = 'vue-collection.validation.rules';
15
20
  function invalidResultInternal(key, params) {
16
- return invalidResult(trsl(`${TRANSLATION_KEY_BASE}.${key}`, params));
21
+ return invalidResult(trsl(`${TRANSLATION_KEY_BASE}.${key}`, params));
17
22
  }
18
23
  /**
19
24
  * Validates a given input with the specified rules.
@@ -25,12 +30,11 @@ function invalidResultInternal(key, params) {
25
30
  * @returns an object containing the result of the validation.
26
31
  */
27
32
  export function validate(input, rules) {
28
- for (const rule of rules) {
29
- const validationResult = rule(input);
30
- if (!validationResult.isValid)
31
- return validationResult;
32
- }
33
- return validResult();
33
+ for (const rule of rules) {
34
+ const validationResult = rule(input);
35
+ if (!validationResult.isValid) return validationResult;
36
+ }
37
+ return validResult();
34
38
  }
35
39
  /*
36
40
  * ---------- Validation Rules ----------
@@ -39,20 +43,14 @@ export function validate(input, rules) {
39
43
  * This rule expects the trimmed input-value to be truthy.
40
44
  */
41
45
  export const required = input => {
42
- const trimmed = input?.trim();
43
- if (trimmed)
44
- return validResult();
45
- else
46
- return invalidResultInternal('required');
46
+ const trimmed = input?.trim();
47
+ if (trimmed) return validResult();else return invalidResultInternal('required');
47
48
  };
48
49
  /**
49
50
  * This rule expects the input to be an integer.
50
51
  */
51
52
  export const integer = input => {
52
- if (!input || Number.isInteger(+input))
53
- return validResult();
54
- else
55
- return invalidResultInternal('integer');
53
+ if (!input || Number.isInteger(+input)) return validResult();else return invalidResultInternal('integer');
56
54
  };
57
55
  /**
58
56
  * This rule expects the input to be in the specified length range. An empty input
@@ -61,17 +59,18 @@ export const integer = input => {
61
59
  * @param max The maximum length of the string.
62
60
  */
63
61
  export function length(min, max) {
64
- return input => {
65
- if (!input)
66
- return validResult();
67
- if (min !== undefined && max !== undefined && !(min <= input.length && input.length <= max))
68
- return invalidResultInternal('length.min-max', { min, max });
69
- else if (min !== undefined && !(min <= input.length))
70
- return invalidResultInternal('length.min', { min });
71
- else if (max !== undefined && !(input.length <= max))
72
- return invalidResultInternal('length.max', { max });
73
- return validResult();
74
- };
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
+ };
75
74
  }
76
75
  /**
77
76
  * This rule expects the input to be a number in the specified range.
@@ -79,50 +78,34 @@ export function length(min, max) {
79
78
  * @param max the upper bound, if `undefined` there is no upper bound.
80
79
  */
81
80
  export function numberRange(min, max) {
82
- return input => {
83
- if (!input)
84
- return validResult();
85
- const parsed = Number.parseFloat(input);
86
- if (Number.isNaN(parsed))
87
- return invalidResultInternal('number-range.nan');
88
- if (min !== undefined && max !== undefined && !(min <= parsed && parsed <= max))
89
- return invalidResultInternal('number-range.min-max', { min, max });
90
- else if (min !== undefined && !(min <= parsed))
91
- return invalidResultInternal('number-range.min', { min });
92
- else if (max !== undefined && !(parsed <= max))
93
- return invalidResultInternal('number-range.max', { max });
94
- return validResult();
95
- };
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
+ };
96
95
  }
97
96
  export const VALIDATION_FORMAT_EMAIL = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/;
98
97
  /**
99
98
  * This rule expects the input-value to be a valid email adress matching {@link VALIDATION_FORMAT_EMAIL}.
100
99
  */
101
100
  export const email = input => {
102
- if (!input || VALIDATION_FORMAT_EMAIL.test(input))
103
- return validResult();
104
- else
105
- return invalidResultInternal('email');
101
+ if (!input || VALIDATION_FORMAT_EMAIL.test(input)) return validResult();else return invalidResultInternal('email');
106
102
  };
107
103
  export const VALIDATION_FORMAT_PASSWORD = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+\-=!*()@%&?]).{8,}$/;
108
104
  /**
109
105
  * This rule expects the input-value to be a password matching {@link VALIDATION_FORMAT_PASSWORD}.
110
106
  */
111
107
  export const password = input => {
112
- if (!input || VALIDATION_FORMAT_PASSWORD.test(input))
113
- return validResult();
114
- else if (input.length < 8)
115
- return invalidResultInternal('password.to-short');
116
- else if (!/[a-z]+/.test(input))
117
- return invalidResultInternal('password.no-lowercase');
118
- else if (!/[A-Z]+/.test(input))
119
- return invalidResultInternal('password.no-uppercase');
120
- else if (!/\d+/.test(input))
121
- return invalidResultInternal('password.no-digits');
122
- else if (!/[#$^+\-=!*()@%&?]+/.test(input))
123
- return invalidResultInternal('password.no-special-chars');
124
- else
125
- return invalidResultInternal('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');
126
109
  };
127
110
  /**
128
111
  * This rule expects the input-value to match another (input-) value.
@@ -131,36 +114,27 @@ export const password = input => {
131
114
  * @param other the other value to match
132
115
  */
133
116
  export function matches(other) {
134
- return input => {
135
- if (input === other)
136
- return validResult();
137
- else
138
- return invalidResultInternal('matches');
139
- };
117
+ return input => {
118
+ if (input === other) return validResult();else return invalidResultInternal('matches');
119
+ };
140
120
  }
141
121
  /**
142
122
  * This rule expects the input-value to match one option in an array.
143
123
  * @param options the options which the input can match
144
124
  */
145
125
  export function option(options) {
146
- return input => {
147
- if (!input || options.includes(input || ''))
148
- return validResult();
149
- else
150
- return invalidResultInternal('option');
151
- };
126
+ return input => {
127
+ if (!input || options.includes(input || '')) return validResult();else return invalidResultInternal('option');
128
+ };
152
129
  }
153
130
  /**
154
131
  * This rule expects the input-value to match the regex pattern
155
132
  * @param pattern the pattern the input should match.
156
133
  */
157
134
  export function regex(pattern) {
158
- return input => {
159
- if (!input || pattern.test(input || ''))
160
- return validResult();
161
- else
162
- return invalidResultInternal('regex');
163
- };
135
+ return input => {
136
+ if (!input || pattern.test(input || '')) return validResult();else return invalidResultInternal('regex');
137
+ };
164
138
  }
165
139
  /**
166
140
  * This rule can be used if the validation logic happens somewhere else.
@@ -169,5 +143,5 @@ export function regex(pattern) {
169
143
  * Like always, a falsy input is always valid to not interefere with the {@link required} rule.
170
144
  */
171
145
  export function external(isValid, errorMessage) {
172
- return input => (!input || isValid ? validResult() : invalidResult(errorMessage));
173
- }
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
+ }