@webitel/ui-sdk 24.12.59 → 24.12.61

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-sdk",
3
- "version": "24.12.59",
3
+ "version": "24.12.61",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -126,7 +126,7 @@
126
126
  "lodash": "^4.17.21",
127
127
  "mitt": "3.0.1",
128
128
  "path-browserify": "^1.0.1",
129
- "plyr": "3.7.8",
129
+ "plyr": "^3.7.8",
130
130
  "query-string": "^9.1.1",
131
131
  "sortablejs": "^1.15.3",
132
132
  "vue-i18n": "^11.0.1",
@@ -1,5 +1,6 @@
1
1
  import VueMultiselect from 'vue-multiselect';
2
2
  import { ObserveVisibility } from 'vue-observe-visibility';
3
+
3
4
  import validationMixin from '../../../mixins/validationMixin/validationMixin.js';
4
5
  import debounce from '../../../scripts/debounce.js';
5
6
  import isEmpty from '../../../scripts/isEmpty.js';
@@ -82,16 +83,34 @@ export default {
82
83
  showIntersectionObserver() {
83
84
  return this.isApiMode && !this.isLoading && this.apiOptions.length;
84
85
  },
85
- // vue-multiselect doesn't show placeholder if value is empty object
86
86
  selectValue() {
87
+ /* vue-multiselect doesn't show placeholder if value is empty object */
87
88
  if (!this.isValue) return '';
88
89
 
90
+ let returnedValue = this.value;
91
+
92
+ /*
93
+ coerce single value to array, if it was passed with `multiple` prop
94
+ by dev mistake or internal error
95
+ */
96
+ if (this.multiple && !Array.isArray(returnedValue)) {
97
+ console.warn(
98
+ 'wt-select: value prop should be an array when using multiple mode',
99
+ );
100
+ returnedValue = [returnedValue];
101
+ }
102
+
89
103
  if (this.useValueFromOptionsByProp) {
90
- const valueFromOptions = this.cachedOptionsMap[this.value];
91
- if (valueFromOptions) return valueFromOptions;
104
+ if (this.multiple) {
105
+ returnedValue = returnedValue.map(
106
+ (item) => this.cachedOptionsMap[item] || item,
107
+ );
108
+ } else {
109
+ returnedValue = this.cachedOptionsMap[returnedValue] || returnedValue;
110
+ }
92
111
  }
93
112
 
94
- return this.value;
113
+ return returnedValue;
95
114
  },
96
115
 
97
116
  selectOptions() {
@@ -155,9 +174,16 @@ export default {
155
174
  },
156
175
 
157
176
  input(value) {
158
- const emittedValue = this.useValueFromOptionsByProp
159
- ? value[this.useValueFromOptionsByProp]
160
- : value;
177
+ let emittedValue = value;
178
+ if (this.useValueFromOptionsByProp) {
179
+ if (this.multiple) {
180
+ emittedValue = value.map(
181
+ (item) => item[this.useValueFromOptionsByProp],
182
+ );
183
+ } else {
184
+ emittedValue = value[this.useValueFromOptionsByProp];
185
+ }
186
+ }
161
187
  this.$emit('input', emittedValue); // vue 2
162
188
  this.$emit('update:model-value', emittedValue); // vue 3
163
189
  },
@@ -174,12 +200,46 @@ export default {
174
200
  // load options if becomes enabled
175
201
  if (!this.disabled) this.fetchOptions();
176
202
  },
177
- options: {
203
+ selectOptions: {
178
204
  handler() {
179
205
  if (this.trackBy === null) return; // then, options are primitives
180
206
 
181
- for (const opt of this.options) {
182
- this.cachedOptionsMap[opt[this.useValueFromOptionsByProp || this.trackBy]] = opt;
207
+ for (const opt of this.selectOptions) {
208
+ this.cachedOptionsMap[
209
+ opt[this.useValueFromOptionsByProp || this.trackBy]
210
+ ] = opt;
211
+ }
212
+ },
213
+ immediate: true,
214
+ },
215
+ value: {
216
+ async handler() {
217
+ /*
218
+ use case: select api option while using `useValueFromOptionsByProp` prop,
219
+ then, refresh page and restore selected id. but it may not be in options list,
220
+
221
+ when using api-fetched options, selected value, tracked by id,
222
+ may be not in returned options list,
223
+ so its necessary to fetch those values separately
224
+ */
225
+ if (this.useValueFromOptionsByProp && this.isApiMode) {
226
+ const valuesArr = Array.isArray(this.value)
227
+ ? this.value
228
+ : [this.value];
229
+ const uncachedValues = valuesArr.filter(() => {
230
+ return !this.cachedOptionsMap[this.value];
231
+ });
232
+
233
+ if (uncachedValues.length) {
234
+ const { items } = await this.searchMethod({
235
+ id: uncachedValues,
236
+ size: uncachedValues.length,
237
+ });
238
+ items.forEach((item) => {
239
+ this.cachedOptionsMap[item[this.useValueFromOptionsByProp]] =
240
+ item;
241
+ });
242
+ }
183
243
  }
184
244
  },
185
245
  immediate: true,
@@ -27,6 +27,10 @@
27
27
  <vue-multiselect
28
28
  ref="vue-multiselect"
29
29
  :allow-empty="allowEmpty"
30
+ :close-on-select="
31
+ $attrs.closeOnSelect ||
32
+ !multiple /* override default vue-multiselect value */
33
+ "
30
34
  :disabled="disabled"
31
35
  :internal-search="!searchMethod"
32
36
  :label="selectOptionLabel"
package/src/install.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import 'vue-multiselect/dist/vue-multiselect.css';
2
2
  import '@webitel/styleguide/fonts';
3
+ import 'plyr/src/sass/plyr.scss';
3
4
  import './css/main.scss';
4
5
  import './assets/icons/sprite/index.js';
5
6