goodteditor-ui 1.0.66 → 1.0.68

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": "goodteditor-ui",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "main": "index.js",
5
5
  "homepage": "https://goodt-ui.netlify.app/",
6
6
  "scripts": {
@@ -278,18 +278,26 @@ export default {
278
278
  * Defines the 'value' field of the option Object
279
279
  */
280
280
  valueField: {
281
- type: String,
281
+ type: [String, Symbol],
282
282
  default: 'value'
283
283
  },
284
284
  /**
285
285
  * Defines the 'label' field of the option Object
286
286
  */
287
287
  labelField: {
288
- type: String,
288
+ type: [String, Symbol],
289
289
  default: 'label'
290
290
  },
291
291
  autoWidth: {
292
292
  default: true
293
+ },
294
+ /**
295
+ * Alternative function to detect if option Object selected
296
+ * by compare model value with option Object valueField value
297
+ */
298
+ valueOfOptionChecker: {
299
+ type: Function,
300
+ default: null
293
301
  }
294
302
  },
295
303
  data() {
@@ -319,32 +327,38 @@ export default {
319
327
  }
320
328
  },
321
329
  methods: {
330
+ isValueOfOptionDefault(option, modelItem) {
331
+ const modelValue = this.valueObjects ? this.getOptionValue(modelItem) : modelItem;
332
+ const optionValue = this.getOptionValue(option);
333
+ return modelValue === optionValue;
334
+ },
335
+ /**
336
+ * @param option
337
+ * @param modelItem
338
+ * @return {boolean}
339
+ */
340
+ isValueOfOption(option, modelItem) {
341
+ const { valueOfOptionChecker, isValueOfOptionDefault } = this;
342
+ const isTrue = valueOfOptionChecker ?? isValueOfOptionDefault;
343
+ return isTrue(option, modelItem);
344
+ },
345
+ /**
346
+ * @param model
347
+ */
322
348
  importModel(model) {
323
- let ci = -1;
324
- let tmp = [];
325
- model = this.multiple ? (Array.isArray(model) ? model : [model]) : [model];
326
- model.forEach((modelItem) => {
327
- let modelItemValue = this.valueObjects ? this.getOptionValue(modelItem) : modelItem;
328
- let optionIndex = this.options.findIndex((optionItem) => {
329
- let optionItemValue = this.getOptionValue(optionItem);
330
- return optionItemValue === modelItemValue;
331
- });
332
- if (optionIndex >= 0) {
333
- ci = ci < 0 ? optionIndex : ci;
334
- tmp.push(this.options[optionIndex]);
335
- }
336
- });
337
- this.dataListCursorIndex = ci;
338
- this.optionsSelected = tmp;
349
+ const { options, isValueOfOption } = this;
350
+ const models = [model].flat();
351
+ const optionsSelected = options.filter((option) => models.some((modelItem) => isValueOfOption(option, modelItem)));
352
+ if (optionsSelected.length > 0) {
353
+ this.dataListCursorIndex = this.getOptionIndex(optionsSelected[0]);
354
+ this.optionsSelected = this.multiple ? optionsSelected : optionsSelected[0];
355
+ }
339
356
  },
340
357
  exportModel() {
341
- let model = this.optionsSelected.map((option) =>
358
+ const model = this.optionsSelected.map((option) =>
342
359
  this.valueObjects ? option : this.getOptionValue(option)
343
360
  );
344
- if (this.multiple) {
345
- return model;
346
- }
347
- return model && model.length ? model[0] : null;
361
+ return this.multiple ? model : model[0] ?? null;
348
362
  },
349
363
  /**
350
364
  *
@@ -374,14 +388,11 @@ export default {
374
388
  return value === undefined ? option : value;
375
389
  },
376
390
  getOptionIndex(option) {
377
- return this.options.findIndex((o) => this.getOptionValue(o) === this.getOptionValue(option));
391
+ return this.options.indexOf(option);
378
392
  },
379
393
  isOptionSelected(option) {
380
- return !!this.optionsSelected.find((o) => this.getOptionValue(o) === this.getOptionValue(option));
394
+ return this.optionsSelected.includes(option);
381
395
  },
382
- /**
383
- * @return {function(): void} rollback
384
- */
385
396
  createOptionRollback() {
386
397
  const optionsSelected = [...this.optionsSelected];
387
398
  return () => this.optionsSelected = optionsSelected;
@@ -390,6 +401,7 @@ export default {
390
401
  if (this.isOptionSelected(option)) {
391
402
  return;
392
403
  }
404
+
393
405
  const rollback = this.createOptionRollback();
394
406
  if (this.multiple) {
395
407
  this.optionsSelected.push(option);
@@ -406,9 +418,7 @@ export default {
406
418
  return;
407
419
  }
408
420
  const rollback = this.createOptionRollback();
409
- this.optionsSelected = this.optionsSelected.filter(
410
- (o) => this.getOptionValue(o) !== this.getOptionValue(option)
411
- );
421
+ this.optionsSelected.splice(this.getOptionIndex(option), 1);
412
422
  this.triggerModelChange(rollback);
413
423
  },
414
424
  toggleOption(option) {