@webitel/ui-sdk 25.6.38 → 25.8.1

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 (24) hide show
  1. package/dist/types/components/wt-input/wt-input.vue.d.ts +100 -41
  2. package/dist/types/components/wt-search-bar/wt-search-bar.vue.d.ts +3 -3
  3. package/dist/types/components/wt-select/wt-select.vue.d.ts +23 -1
  4. package/dist/types/components/wt-slider/wt-slider.vue.d.ts +1 -1
  5. package/dist/types/mixins/validationMixin/regle/useRegleValidation.d.ts +10 -0
  6. package/dist/types/mixins/validationMixin/useValidation.d.ts +11 -0
  7. package/dist/types/mixins/validationMixin/vuelidate/useVuelidateValidation.d.ts +16 -0
  8. package/dist/ui-sdk.css +1 -1
  9. package/dist/ui-sdk.js +2658 -2667
  10. package/dist/ui-sdk.umd.cjs +43 -43
  11. package/package.json +2 -1
  12. package/src/api/clients/caseSources/caseSources.ts +2 -2
  13. package/src/components/wt-datepicker/wt-datepicker.vue +1 -1
  14. package/src/components/wt-input/wt-input.vue +44 -101
  15. package/src/components/wt-search-bar/__tests__/WtSearchBar.spec.js +1 -1
  16. package/src/components/wt-search-bar/wt-search-bar.vue +1 -1
  17. package/src/components/wt-select/mixins/multiselectMixin.js +1 -1
  18. package/src/components/wt-select/wt-select.vue +29 -0
  19. package/src/components/wt-tags-input/wt-tags-input.vue +2 -0
  20. package/src/locale/en/en.js +8 -1
  21. package/src/mixins/validationMixin/regle/useRegleValidation.ts +29 -0
  22. package/src/mixins/validationMixin/useValidation.ts +59 -0
  23. package/src/mixins/validationMixin/{useValidation.js → vuelidate/useVuelidateValidation.ts} +13 -5
  24. package/src/modules/DeleteConfirmationPopup/__tests__/delete-confirmation-popup.spec.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-sdk",
3
- "version": "25.6.38",
3
+ "version": "25.8.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "npm run docs:dev",
@@ -129,6 +129,7 @@
129
129
  "@vue/test-utils": "^2.4.6",
130
130
  "@vue/tsconfig": "^0.7.0",
131
131
  "eslint": "^9.22.0",
132
+ "@regle/core": "^1.3.0",
132
133
  "eslint-config-prettier": "^10.1.1",
133
134
  "eslint-plugin-simple-import-sort": "^12.1.1",
134
135
  "eslint-plugin-vue": "^10.0.0",
@@ -69,7 +69,7 @@ const getSource = async ({ itemId: id }) => {
69
69
 
70
70
  const addSource = async ({ itemInstance }) => {
71
71
  const item = applyTransform(itemInstance, [
72
- sanitize(getFieldsToSendFromZodSchema(createSourceBody)),
72
+ sanitize(getShallowFieldsToSendFromZodSchema(createSourceBody)),
73
73
  camelToSnake(),
74
74
  ]);
75
75
  try {
@@ -83,7 +83,7 @@ const addSource = async ({ itemInstance }) => {
83
83
  const updateSource = async ({ itemInstance, itemId: id }) => {
84
84
  const item = applyTransform(itemInstance, [
85
85
  camelToSnake(),
86
- sanitize(updateSourceBody),
86
+ sanitize(getShallowFieldsToSendFromZodSchema(updateSourceBody)),
87
87
  ]);
88
88
 
89
89
  try {
@@ -89,7 +89,7 @@ import '@vuepic/vue-datepicker/dist/main.css';
89
89
  import VueDatepicker from '@vuepic/vue-datepicker';
90
90
  import { computed, ref, toRefs } from 'vue';
91
91
 
92
- import { useValidation } from '../../mixins/validationMixin/useValidation.js';
92
+ import { useValidation } from '../../mixins/validationMixin/useValidation';
93
93
  import WtInputInfo from '../wt-input-info/wt-input-info.vue';
94
94
 
95
95
  const props = defineProps({
@@ -43,7 +43,7 @@
43
43
  ref="AfterWrapper"
44
44
  class="wt-input__after-wrapper"
45
45
  >
46
- <slot name="after-input" />
46
+ <slot name="after-input"/>
47
47
  <slot
48
48
  v-if="isPassword"
49
49
  name="show-password"
@@ -69,121 +69,64 @@
69
69
  </div>
70
70
  </template>
71
71
 
72
- <script setup>
73
- import { computed, onMounted, ref, toRefs, useSlots } from 'vue';
72
+ <script lang="ts" setup>
73
+ import type {RegleFieldStatus} from '@regle/core';
74
+ import {computed, onMounted, ref, toRefs, useSlots} from 'vue';
74
75
 
75
- import { useValidation } from '../../mixins/validationMixin/useValidation.js';
76
+ import {
77
+ useValidation
78
+ } from '../../mixins/validationMixin/useValidation';
76
79
 
77
80
  /*
78
81
  * IMPORTANT: WT-INPUT SHOULD SUPPORT VUE 3 AND VUE 2 V-MODEL INTERFACES SO THAT THERE'S
79
82
  * TWO PROPS: VALUE AND MODELVALUE, AND 2 EVENTS: @UPDATE:MODELVALUE AND @INPUT
80
83
  * */
81
- const props = defineProps({
82
- value: {
83
- type: [String, Number],
84
- },
85
- /**
86
- * Current input modelValue (`v-model`)
87
- */
88
- modelValue: {
89
- type: [String, Number],
90
- },
91
- /**
92
- * Form input label
93
- */
94
- label: {
95
- type: String,
96
- default: '',
97
- },
98
- /**
99
- * Form input placeholder
100
- */
101
- placeholder: {
102
- type: String,
103
- },
104
- /**
105
- * Form input name
106
- */
107
- name: {
108
- type: String,
109
- default: '',
110
- },
111
- /**
112
- * Form input type
113
- */
114
- type: {
115
- type: String,
116
- default: 'text',
117
- },
118
- /**
119
- * Native input required attribute
120
- */
121
- required: {
122
- type: Boolean,
123
- default: false,
124
- description: 'Native input required attribute',
125
- },
126
- /**
127
- * Native input disabled attribute
128
- */
129
- disabled: {
130
- type: Boolean,
131
- default: false,
132
- description: 'Native input disabled attribute',
133
- },
134
- /**
135
- * Status of show password icon display
136
- */
137
- hasShowPassword: {
138
- type: Boolean,
139
- default: false,
140
- },
141
-
142
- /**
143
- * Native number input restrictions
144
- */
145
- numberMin: {
146
- type: Number,
147
- default: 0,
148
- },
149
-
150
- /**
151
- * Native number input restrictions
152
- */
153
- numberMax: {
154
- type: Number,
155
- },
156
-
157
- labelProps: {
158
- type: Object,
159
- description: 'Object with props, passed down to wt-label as props',
160
- },
161
-
162
- preventTrim: {
163
- type: Boolean,
164
- default: false,
165
- },
166
-
167
- // validation rules
168
- // TODO: move to separate file to make it reusable
169
- v: {
170
- type: Object,
171
- },
172
- customValidators: {
173
- type: Array,
174
- default: () => [],
175
- },
84
+ const props = withDefaults(defineProps<{
85
+ value?: string | number;
86
+ modelValue?: string | number;
87
+ label?: string;
88
+ placeholder?: string;
89
+ name?: string;
90
+ type?: string;
91
+ required?: boolean;
92
+ disabled?: boolean;
93
+ hasShowPassword?: boolean;
94
+ numberMin?: number;
95
+ numberMax?: number;
96
+ labelProps?: Record<string, unknown>;
97
+ preventTrim?: boolean;
98
+ v?: Record<string, unknown>;
99
+ regleValidation?: RegleFieldStatus<string>;
100
+ customValidators?: unknown[];
101
+ }>(), {
102
+ label: '',
103
+ name: '',
104
+ type: 'text',
105
+ required: false,
106
+ disabled: false,
107
+ hasShowPassword: false,
108
+ numberMin: 0,
109
+ preventTrim: false,
110
+ v: null,
111
+ regleValidation: null,
112
+ customValidators: () => [],
176
113
  });
114
+
177
115
  const emit = defineEmits(['update:modelValue', 'input', 'keyup']);
178
116
 
179
117
  const slots = useSlots();
180
118
 
181
119
  // https://stackoverflow.com/questions/72408463/use-props-in-composables-vue3
182
- const { v, customValidators } = toRefs(props);
120
+ const {v, customValidators, regleValidation } = toRefs(props);
183
121
 
184
- const { isValidation, invalid, validationText } = useValidation({
122
+ const {
123
+ isValidation,
124
+ invalid,
125
+ validationText,
126
+ } = useValidation({
185
127
  v,
186
128
  customValidators,
129
+ regleValidation,
187
130
  });
188
131
 
189
132
  // toggles password <-> text at showPassword
@@ -1,7 +1,7 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
2
  import { ref } from 'vue';
3
3
 
4
- import { useValidation } from '../../../mixins/validationMixin/useValidation.js';
4
+ import { useValidation } from '../../../mixins/validationMixin/useValidation';
5
5
  import WtSearchBar from '../wt-search-bar.vue';
6
6
 
7
7
  vi.mock('../../../mixins/validationMixin/useValidation');
@@ -81,7 +81,7 @@
81
81
  <script lang="ts" setup>
82
82
  import { computed, toRefs } from 'vue';
83
83
 
84
- import { useValidation } from '../../mixins/validationMixin/useValidation.js';
84
+ import { useValidation } from '../../mixins/validationMixin/useValidation';
85
85
  import debounce from '../../scripts/debounce.js';
86
86
 
87
87
  const props = defineProps({
@@ -7,7 +7,7 @@ import isEmpty from '../../../scripts/isEmpty.js';
7
7
  import labelUsageMixin from '../../wt-label/mixins/labelUsageMixin.js';
8
8
 
9
9
  export default {
10
- mixins: [validationMixin, labelUsageMixin],
10
+ mixins: [labelUsageMixin],
11
11
  directives: { ObserveVisibility },
12
12
  components: {
13
13
  VueMultiselect,
@@ -167,6 +167,8 @@
167
167
  </template>
168
168
 
169
169
  <script>
170
+ import { toRefs } from 'vue';
171
+ import { useValidation } from '../../mixins/validationMixin/useValidation';
170
172
  import isEmpty from '../../scripts/isEmpty.js';
171
173
  import taggableMixin from '../wt-tags-input/mixin/taggableMixin.js';
172
174
  import multiselectMixin from './mixins/multiselectMixin.js';
@@ -213,6 +215,14 @@ export default {
213
215
  default: false,
214
216
  description: 'See wt-tags-input "manualTagging" prop.',
215
217
  },
218
+ v: {
219
+ type: Object,
220
+ default: null,
221
+ },
222
+ regleValidation: {
223
+ type: Object,
224
+ default: null,
225
+ },
216
226
  },
217
227
  emits: [
218
228
  'reset',
@@ -222,6 +232,25 @@ export default {
222
232
  'closed',
223
233
  'custom-value', // fires when allowCustomValues and new customValue is added
224
234
  ],
235
+ setup: (props/*, ctx*/) => {
236
+ // https://stackoverflow.com/questions/72408463/use-props-in-composables-vue3
237
+ const {v, customValidators, regleValidation } = toRefs(props);
238
+ const {
239
+ isValidation,
240
+ invalid,
241
+ validationText,
242
+ } = useValidation({
243
+ v,
244
+ customValidators,
245
+ regleValidation,
246
+ });
247
+
248
+ return {
249
+ isValidation,
250
+ invalid,
251
+ validationText,
252
+ };
253
+ },
225
254
  data: () => ({
226
255
  isOpened: false,
227
256
  items: [],
@@ -103,6 +103,7 @@
103
103
 
104
104
  <script>
105
105
  import deepEqual from 'deep-equal';
106
+ import validationMixin from '../../mixins/validationMixin/validationMixin';
106
107
 
107
108
  import multiselectMixin from '../wt-select/mixins/multiselectMixin.js';
108
109
  import taggableMixin from './mixin/taggableMixin.js';
@@ -110,6 +111,7 @@ import taggableMixin from './mixin/taggableMixin.js';
110
111
  export default {
111
112
  name: 'WtTagsInput',
112
113
  mixins: [
114
+ validationMixin,
113
115
  multiselectMixin,
114
116
  // taggableMixin is used to add custom select values, see [https://my.webitel.com/browse/WTEL-3181
115
117
  taggableMixin,
@@ -353,7 +353,14 @@ export default {
353
353
  maxLength: 'The length should not be greater than',
354
354
  sameAs: 'Incorrect password',
355
355
  requiredArrayValue: 'Array should not be empty',
356
- minLength: 'Quantity of characters should not be less than',
356
+ minLength: ({ named }) => {
357
+ let text = 'The length should not be less than';
358
+ if (named('min')) {
359
+ text += ` ${named('min')}`;
360
+ }
361
+
362
+ return text;
363
+ },
357
364
  url: 'Should look like URL',
358
365
  websocketValidator: 'Should look like WebSocket url',
359
366
  isRegExpMatched: 'Password must match the regular expression:',
@@ -0,0 +1,29 @@
1
+ import type { RegleFieldStatus } from '@regle/core';
2
+ import { computed, ComputedRef, Ref } from 'vue';
3
+
4
+ export type UseFieldValidationParams = {
5
+ field: Ref<RegleFieldStatus<string>>;
6
+ };
7
+
8
+ export type UseFieldValidationReturn = {
9
+ invalid: ComputedRef<boolean | null>; // null if is not validated
10
+ validationText?: ComputedRef<string>;
11
+ };
12
+
13
+ export const useFieldValidation = ({
14
+ field: fieldRef,
15
+ }: UseFieldValidationParams): UseFieldValidationReturn => {
16
+
17
+ const invalid = computed(() => {
18
+ return fieldRef.value.$error;
19
+ });
20
+
21
+ const validationText = computed(() => {
22
+ return fieldRef.value?.$errors?.at(0);
23
+ });
24
+
25
+ return {
26
+ invalid,
27
+ validationText,
28
+ };
29
+ };
@@ -0,0 +1,59 @@
1
+ import { computed } from 'vue';
2
+
3
+ import {
4
+ useFieldValidation as useRegleFieldValidation,
5
+ UseFieldValidationParams as UseRegleFieldValidationParams,
6
+ } from "./regle/useRegleValidation";
7
+ import {
8
+ useFieldValidation as useVuelidateValidation,
9
+ UseFieldValidationParams as UseVuelidateFieldValidationParams,
10
+ } from "./vuelidate/useVuelidateValidation";
11
+
12
+ type CompatVuelidateParams = {
13
+ v: UseVuelidateFieldValidationParams['field'];
14
+ };
15
+
16
+ export const useValidation = ({
17
+ v: vuelidateValidation,
18
+ customValidators: inputCustomValidators, // vuelidate custom validations, compat
19
+ regleValidation,
20
+ }: UseRegleFieldValidationParams | CompatVuelidateParams) => {
21
+
22
+ const {
23
+ isValidation: isVuelidateValidation,
24
+ invalid: vuelidateInvalid,
25
+ validationText: vuelidateValidationText,
26
+ } = useVuelidateValidation({
27
+ field: vuelidateValidation,
28
+ customValidators: inputCustomValidators,
29
+ });
30
+
31
+ const {
32
+ invalid: regleInvalid,
33
+ validationText: regleValidationText,
34
+ } = useRegleFieldValidation({
35
+ field: regleValidation,
36
+ });
37
+
38
+ const isRegleValidation = computed(() => {
39
+ return !!regleValidation?.value;
40
+ });
41
+
42
+ const isValidation = computed(() => {
43
+ return isRegleValidation.value || isVuelidateValidation.value;
44
+ });
45
+
46
+ const invalid = computed(() => {
47
+ return isRegleValidation.value ? regleInvalid.value : vuelidateInvalid.value;
48
+ });
49
+
50
+ const validationText = computed(() => {
51
+ return isRegleValidation.value ? regleValidationText.value : vuelidateValidationText.value;
52
+ });
53
+
54
+ return {
55
+ isValidation,
56
+ invalid,
57
+ validationText,
58
+ };
59
+ };
@@ -1,10 +1,16 @@
1
- import { computed, isReactive } from 'vue';
1
+ import {computed, isReactive, Ref} from 'vue';
2
2
  import { useI18n } from 'vue-i18n';
3
+ import type { Validation } from '@vuelidate/core';
3
4
 
4
- export function useValidation({
5
- v: inputV,
5
+ export type UseFieldValidationParams = {
6
+ field: Ref<Validation>;
7
+ customValidators?: Array<object>;
8
+ };
9
+
10
+ export const useFieldValidation = ({
11
+ field: inputV,
6
12
  customValidators: inputCustomValidators,
7
- }) {
13
+ }: UseFieldValidationParams) => {
8
14
  const { t } = useI18n();
9
15
 
10
16
  // support vue options api, where v is a reactive, not ref
@@ -82,4 +88,6 @@ export function useValidation({
82
88
  invalid,
83
89
  validationText,
84
90
  };
85
- }
91
+ };
92
+
93
+ export const useVuelidateFieldValidation = useFieldValidation;
@@ -1,7 +1,7 @@
1
1
  import { mount, shallowMount } from '@vue/test-utils';
2
2
  import { ref } from 'vue';
3
3
 
4
- import { useValidation } from '../../../mixins/validationMixin/useValidation.js';
4
+ import { useValidation } from '../../../mixins/validationMixin/useValidation';
5
5
  import DeleteConfirmationPopup from '../components/delete-confirmation-popup.vue';
6
6
 
7
7
  vi.mock('../../../mixins/validationMixin/useValidation.js');