goodteditor-ui 1.0.65 → 1.0.67
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
|
@@ -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,36 @@ 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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
+
this.dataListCursorIndex = this.getOptionIndex(optionsSelected[0]);
|
|
353
|
+
this.optionsSelected = this.multiple ? optionsSelected : [optionsSelected[0]];
|
|
339
354
|
},
|
|
340
355
|
exportModel() {
|
|
341
|
-
|
|
356
|
+
const model = this.optionsSelected.map((option) =>
|
|
342
357
|
this.valueObjects ? option : this.getOptionValue(option)
|
|
343
358
|
);
|
|
344
|
-
|
|
345
|
-
return model;
|
|
346
|
-
}
|
|
347
|
-
return model && model.length ? model[0] : null;
|
|
359
|
+
return this.multiple ? model : model[0] ?? null;
|
|
348
360
|
},
|
|
349
361
|
/**
|
|
350
362
|
*
|
|
@@ -374,14 +386,11 @@ export default {
|
|
|
374
386
|
return value === undefined ? option : value;
|
|
375
387
|
},
|
|
376
388
|
getOptionIndex(option) {
|
|
377
|
-
return this.options.
|
|
389
|
+
return this.options.indexOf(option);
|
|
378
390
|
},
|
|
379
391
|
isOptionSelected(option) {
|
|
380
|
-
return
|
|
392
|
+
return this.optionsSelected.includes(option);
|
|
381
393
|
},
|
|
382
|
-
/**
|
|
383
|
-
* @return {function(): void} rollback
|
|
384
|
-
*/
|
|
385
394
|
createOptionRollback() {
|
|
386
395
|
const optionsSelected = [...this.optionsSelected];
|
|
387
396
|
return () => this.optionsSelected = optionsSelected;
|
|
@@ -390,6 +399,7 @@ export default {
|
|
|
390
399
|
if (this.isOptionSelected(option)) {
|
|
391
400
|
return;
|
|
392
401
|
}
|
|
402
|
+
|
|
393
403
|
const rollback = this.createOptionRollback();
|
|
394
404
|
if (this.multiple) {
|
|
395
405
|
this.optionsSelected.push(option);
|
|
@@ -406,9 +416,7 @@ export default {
|
|
|
406
416
|
return;
|
|
407
417
|
}
|
|
408
418
|
const rollback = this.createOptionRollback();
|
|
409
|
-
this.optionsSelected
|
|
410
|
-
(o) => this.getOptionValue(o) !== this.getOptionValue(option)
|
|
411
|
-
);
|
|
419
|
+
this.optionsSelected.splice(this.getOptionIndex(option), 1);
|
|
412
420
|
this.triggerModelChange(rollback);
|
|
413
421
|
},
|
|
414
422
|
toggleOption(option) {
|