@v1nt1248/3nclient-lib 0.2.99 → 0.3.2

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@v1nt1248/3nclient-lib",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "author": "v1nt1248",
5
- "version": "0.2.99",
5
+ "version": "0.3.2",
6
6
  "description": "Library for 3NWeb clients",
7
7
  "type": "module",
8
8
  "files": [
@@ -8,6 +8,7 @@ export interface Ui3nInputProps {
8
8
  icon?: string;
9
9
  iconColor?: string;
10
10
  rules?: Array<(v: unknown) => boolean | string>;
11
+ validateAtStartup?: boolean;
11
12
  hideBottomSpace?: boolean;
12
13
  displayStateMode?: 'error' | 'success';
13
14
  displayStateWithIcon?: boolean;
@@ -1,6 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { computed, onMounted, ref, watch, useCssModule } from 'vue';
3
- import isEmpty from 'lodash/isEmpty';
2
+ import { computed, onMounted, ref, watch } from 'vue';
4
3
  import Ui3nIcon from '../ui3n-icon/ui3n-icon.vue';
5
4
  import Ui3nButton from '../ui3n-button/ui3n-button.vue';
6
5
  import type { Ui3nInputEmits, Ui3nInputProps } from './types';
@@ -8,8 +7,6 @@
8
7
  const props = defineProps<Ui3nInputProps>();
9
8
  const emits = defineEmits<Ui3nInputEmits>();
10
9
 
11
- const css = useCssModule();
12
-
13
10
  const inputElement = ref<HTMLInputElement | null>(null);
14
11
  const text = ref<string>('');
15
12
  const isDirty = ref(false);
@@ -24,43 +21,6 @@
24
21
  return props.iconColor || 'var(--color-icon-control-primary-default)';
25
22
  });
26
23
 
27
- const isValid = computed(() => {
28
- if (!isDirty.value) {
29
- return true;
30
- }
31
-
32
- return !errorMessage.value;
33
- });
34
-
35
- const mainCssClasses = computed(() => {
36
- const val = [css.ui3nInput];
37
- props.label && val.push(css.withLabel);
38
- props.hideBottomSpace && val.push(css.withoutBottomSpace);
39
- props.icon && val.push(css.withIcon);
40
- props.clearable && text.value && val.push(css.clearable);
41
- props.disabled && val.push(css.disabled);
42
- ((!!errorMessage.value && !isValid.value) || props.displayStateMode === 'error') && val.push(css.error);
43
- props.displayStateMode === 'success' && val.push(css.success);
44
-
45
- return val;
46
- });
47
-
48
- const iconCssClasses = computed(() => {
49
- const val = [css.ui3nInputIcon];
50
- props.disabled && val.push(css.ui3nInputIconDisabled);
51
-
52
- return val;
53
- });
54
-
55
- const messageCssClasses = computed(() => {
56
- const val = [css.ui3nInputFieldMessage];
57
- (errorMessage.value || (props.displayStateMode === 'error' && !!props.displayStateMessage)) &&
58
- val.push(css.ui3nInputErrorMessage);
59
- props.displayStateMode === 'success' && props.displayStateMessage && val.push(css.ui3nInputSuccessMessage);
60
-
61
- return val;
62
- });
63
-
64
24
  function onFocus(event: Event) {
65
25
  isFocused.value = true;
66
26
  emits('focus', event);
@@ -76,6 +36,7 @@
76
36
  function onChange(event: Event) {
77
37
  const value = (event.target as HTMLInputElement).value;
78
38
  validate(value);
39
+ console.log('[Ui3nInput] ON_CHANGE');
79
40
  emits('change', value);
80
41
  }
81
42
 
@@ -84,6 +45,7 @@
84
45
  text.value = value;
85
46
  isDirty.value = true;
86
47
  validate(value);
48
+ console.log('[Ui3nInput] ON_INPUT');
87
49
  emits('update:modelValue', value);
88
50
  emits('input', value);
89
51
  }
@@ -93,6 +55,7 @@
93
55
  const value = (target as HTMLInputElement).value;
94
56
  isDirty.value = true;
95
57
  validate(value);
58
+ console.log('[Ui3nInput] ON_ENTER_KEYDOWN');
96
59
  emits('update:modelValue', value);
97
60
  emits('enter', { value, altKey, ctrlKey, metaKey, shiftKey });
98
61
  }
@@ -101,6 +64,7 @@
101
64
  const value = (event.target as HTMLInputElement).value;
102
65
  isDirty.value = true;
103
66
  validate(value);
67
+ console.log('[Ui3nInput] ON_ESCAPE_KEYDOWN');
104
68
  emits('update:modelValue', value);
105
69
  emits('escape', event);
106
70
  }
@@ -113,6 +77,7 @@
113
77
  text.value = '';
114
78
  isDirty.value = false;
115
79
  validate('');
80
+ console.log('[Ui3nInput] CLEAR_VALUE');
116
81
  emits('update:modelValue', '');
117
82
  emits('input', '');
118
83
  emits('change', '');
@@ -131,6 +96,11 @@
131
96
  }
132
97
  }
133
98
  }
99
+
100
+ if (isDirty.value) {
101
+ console.log('[Ui3nInput] UPDATE:VALID => ', !errorMessage.value, ' | ', errorMessage.value);
102
+ emits('update:valid', !errorMessage.value);
103
+ }
134
104
  }
135
105
 
136
106
  defineExpose({
@@ -145,21 +115,20 @@
145
115
  }
146
116
 
147
117
  emits('init', inputElement.value!);
118
+ if (props.validateAtStartup) {
119
+ console.log('[Ui3nInput] ON_MOUNTED');
120
+ validate(text.value);
121
+ }
148
122
  });
149
123
 
150
124
  watch(
151
125
  () => props.modelValue,
152
- val => {
153
- text.value = val;
154
- validate(text.value);
155
- },
156
- { immediate: true },
157
- );
158
-
159
- watch(
160
- () => isValid.value,
161
- val => {
162
- emits('update:valid', val);
126
+ (val, oldVal) => {
127
+ if ((val ?? '') !== (oldVal ?? '')) {
128
+ text.value = val ?? '';
129
+ console.log('[Ui3nInput] WATCH => ', oldVal, ' => ', val);
130
+ validate(text.value);
131
+ }
163
132
  },
164
133
  { immediate: true },
165
134
  );
@@ -167,8 +136,16 @@
167
136
 
168
137
  <template>
169
138
  <div
170
- ref="wrapperElement"
171
- :class="mainCssClasses"
139
+ :class="[
140
+ $style.ui3nInput,
141
+ label && $style.withLabel,
142
+ hideBottomSpace && $style.withoutBottomSpace,
143
+ icon && $style.withIcon,
144
+ clearable && text && $style.clearable,
145
+ disabled && $style.disabled,
146
+ (!!errorMessage || displayStateMode === 'error') && $style.error,
147
+ displayStateMode === 'success' && $style.success,
148
+ ]"
172
149
  >
173
150
  <label
174
151
  v-if="label"
@@ -199,7 +176,7 @@
199
176
  :icon="icon"
200
177
  :width="16"
201
178
  :height="16"
202
- :class="iconCssClasses"
179
+ :class="[$style.ui3nInputIcon, disabled && $style.ui3nInputIconDisabled]"
203
180
  />
204
181
 
205
182
  <ui3n-icon
@@ -225,7 +202,11 @@
225
202
 
226
203
  <div
227
204
  v-if="(isDirty && errorMessage) || (displayStateMode && displayStateMessage)"
228
- :class="messageCssClasses"
205
+ :class="[
206
+ $style.ui3nInputFieldMessage,
207
+ (errorMessage || (displayStateMode === 'error' && displayStateMessage)) && $style.ui3nInputErrorMessage,
208
+ displayStateMode === 'success' && displayStateMessage && $style.ui3nInputSuccessMessage,
209
+ ]"
229
210
  >
230
211
  {{ errorMessage || displayStateMessage }}
231
212
  </div>
@@ -35,7 +35,6 @@
35
35
  label: '',
36
36
  items: () => [] as T[],
37
37
  itemValue: 'id',
38
- itemDisplay: 'id' as keyof T,
39
38
  clearable: false,
40
39
  withSearch: false,
41
40
  returnObject: false,
@@ -95,23 +94,24 @@
95
94
  });
96
95
 
97
96
  function getItemTitle(value: T | T[keyof T], withProcessing?: boolean): string {
98
- if (props.returnObject || typeof value === 'object') {
99
- const isItemDisplayFunction = typeof props.itemDisplay === 'function';
100
- const val = isItemDisplayFunction
101
- ? (props.itemDisplay as Ui3nSelectorItemDisplayingFunction<T>)(value as T)
102
- : value
103
- ? ((value as T)[props.itemDisplay as keyof T] as string)
104
- : '';
97
+ if (!value) {
98
+ return '';
99
+ }
100
+
101
+ if (typeof value !== 'object') {
102
+ const val = (value as T[keyof T]).toString();
105
103
  return withProcessing ? val.toLowerCase() : val;
106
104
  }
107
105
 
108
- return withProcessing
109
- ? value
110
- ? (value as T[keyof T] as string).toLowerCase()
111
- : ''
112
- : value
113
- ? (value as T[keyof T] as string)
114
- : '';
106
+ const isItemDisplayFunction = props.itemDisplay && typeof props.itemDisplay === 'function';
107
+ const preVal = isItemDisplayFunction
108
+ ? (props.itemDisplay as Ui3nSelectorItemDisplayingFunction<T>)(value as T)
109
+ : props.itemDisplay
110
+ ? (value as T)[props.itemDisplay as keyof T]
111
+ : (value as T).id;
112
+ // @ts-expect-error
113
+ const val = preVal.toString();
114
+ return withProcessing ? val.toLowerCase() : val;
115
115
  }
116
116
 
117
117
  function onFocus() {