@nethserver/ns8-ui-lib 0.1.27 → 0.1.28
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/README.md +1 -22
- package/dist/ns8-ui-lib.esm.js +119 -81
- package/dist/ns8-ui-lib.min.js +1 -1
- package/dist/ns8-ui-lib.ssr.js +133 -99
- package/package.json +1 -1
- package/src/lib-components/NsMultiSelect.vue +119 -76
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
ref="list"
|
|
158
158
|
>
|
|
159
159
|
<div
|
|
160
|
-
v-for="(item, index) in
|
|
160
|
+
v-for="(item, index) in filteredOptions"
|
|
161
161
|
:key="`multi-select-${index}`"
|
|
162
162
|
:class="[
|
|
163
163
|
`${carbonPrefix}--list-box__menu-item`,
|
|
@@ -262,10 +262,10 @@ export default {
|
|
|
262
262
|
default: "Choose",
|
|
263
263
|
},
|
|
264
264
|
highlight: String,
|
|
265
|
-
value: { type: Array, default: () => [] },
|
|
266
265
|
// initial value of the multi-select,
|
|
267
266
|
// options in the form
|
|
268
267
|
// [{ label: '', value: '', name: ''}]
|
|
268
|
+
value: { type: Array, default: () => [] },
|
|
269
269
|
options: {
|
|
270
270
|
type: Array,
|
|
271
271
|
required: true,
|
|
@@ -326,7 +326,7 @@ export default {
|
|
|
326
326
|
data() {
|
|
327
327
|
return {
|
|
328
328
|
open: false,
|
|
329
|
-
dataOptions: null,
|
|
329
|
+
// dataOptions: null, ////
|
|
330
330
|
// includes user input items
|
|
331
331
|
internalOptions: [],
|
|
332
332
|
dataValue: "",
|
|
@@ -350,16 +350,16 @@ export default {
|
|
|
350
350
|
this.dataValue = this.value;
|
|
351
351
|
} else {
|
|
352
352
|
this.dataValue = this.value.filter((item) =>
|
|
353
|
-
this.
|
|
353
|
+
this.internalOptions.some((opt) => opt.value === item.trim())
|
|
354
354
|
);
|
|
355
355
|
}
|
|
356
356
|
},
|
|
357
357
|
options() {
|
|
358
358
|
this.internalOptions = _cloneDeep(this.options);
|
|
359
|
-
this.updateOptions();
|
|
359
|
+
// this.updateOptions(); ////
|
|
360
360
|
},
|
|
361
361
|
selectionFeedback() {
|
|
362
|
-
this.updateOptions();
|
|
362
|
+
// this.updateOptions(); ////
|
|
363
363
|
},
|
|
364
364
|
open() {
|
|
365
365
|
if (this.marginBottomOnOpen) {
|
|
@@ -376,13 +376,17 @@ export default {
|
|
|
376
376
|
},
|
|
377
377
|
},
|
|
378
378
|
created() {
|
|
379
|
+
console.log("ns-multi-select created"); ////
|
|
380
|
+
|
|
379
381
|
this.internalOptions = _cloneDeep(this.options);
|
|
380
|
-
this.updateOptions();
|
|
382
|
+
// this.updateOptions(); ////
|
|
381
383
|
this.dataValue = this.value.filter((item) =>
|
|
382
|
-
this.
|
|
384
|
+
this.internalOptions.some((opt) => opt.value === item.trim())
|
|
383
385
|
);
|
|
384
386
|
},
|
|
385
387
|
mounted() {
|
|
388
|
+
console.log("ns-multi-select mounted"); ////
|
|
389
|
+
|
|
386
390
|
this.highlighted = this.value ? this.value : this.highlight; // override highlight with value if provided
|
|
387
391
|
this.checkSlots();
|
|
388
392
|
},
|
|
@@ -395,13 +399,13 @@ export default {
|
|
|
395
399
|
return this.dataHighlighted;
|
|
396
400
|
},
|
|
397
401
|
set(val) {
|
|
398
|
-
let firstMatchIndex = this.
|
|
402
|
+
let firstMatchIndex = this.internalOptions.findIndex(
|
|
399
403
|
(item) => item.value === val
|
|
400
404
|
);
|
|
401
405
|
if (firstMatchIndex < 0) {
|
|
402
|
-
firstMatchIndex = this.
|
|
406
|
+
firstMatchIndex = this.internalOptions.length ? 0 : -1;
|
|
403
407
|
this.dataHighlighted =
|
|
404
|
-
firstMatchIndex >= 0 ? this.
|
|
408
|
+
firstMatchIndex >= 0 ? this.internalOptions[0].value : "";
|
|
405
409
|
} else {
|
|
406
410
|
this.dataHighlighted = val;
|
|
407
411
|
}
|
|
@@ -427,7 +431,7 @@ export default {
|
|
|
427
431
|
return this.filterable ? { marginTop: 0, marginBottom: 0 } : {};
|
|
428
432
|
},
|
|
429
433
|
limitedDataOptions() {
|
|
430
|
-
return this.
|
|
434
|
+
return this.internalOptions.slice(0, this.maxDisplayOptions);
|
|
431
435
|
},
|
|
432
436
|
selectedItems() {
|
|
433
437
|
return this.dataValue.map((val) =>
|
|
@@ -437,6 +441,42 @@ export default {
|
|
|
437
441
|
hasTooltipSlot() {
|
|
438
442
|
return !!this.$slots.tooltip;
|
|
439
443
|
},
|
|
444
|
+
filteredOptions() {
|
|
445
|
+
//// use this.dataFilter?
|
|
446
|
+
if (!this.filter) {
|
|
447
|
+
return this.limitedDataOptions;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
let results = this.internalOptions.filter((option) => {
|
|
451
|
+
return option.label
|
|
452
|
+
.trim()
|
|
453
|
+
.toLowerCase()
|
|
454
|
+
.includes(this.filter.trim().toLowerCase());
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
// user input
|
|
458
|
+
|
|
459
|
+
if (this.acceptUserInput && this.filter.trim()) {
|
|
460
|
+
// suggest user input if not already present among options
|
|
461
|
+
const trimmedFilter = this.filter.trim();
|
|
462
|
+
const optionFound = results.find(
|
|
463
|
+
(option) => option.label === trimmedFilter
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
if (!optionFound) {
|
|
467
|
+
results.push({
|
|
468
|
+
name: trimmedFilter,
|
|
469
|
+
label: trimmedFilter,
|
|
470
|
+
value: trimmedFilter,
|
|
471
|
+
type: this.userInputLabel,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// limit results
|
|
477
|
+
results = results.slice(0, this.maxDisplayOptions);
|
|
478
|
+
return results;
|
|
479
|
+
},
|
|
440
480
|
},
|
|
441
481
|
methods: {
|
|
442
482
|
checkSlots() {
|
|
@@ -454,7 +494,7 @@ export default {
|
|
|
454
494
|
this.filter = "";
|
|
455
495
|
this.$refs.input.focus();
|
|
456
496
|
this.doOpen(true);
|
|
457
|
-
this.updateOptions();
|
|
497
|
+
// this.updateOptions(); ////
|
|
458
498
|
},
|
|
459
499
|
checkHighlightPosition(newHiglight) {
|
|
460
500
|
if (
|
|
@@ -479,105 +519,108 @@ export default {
|
|
|
479
519
|
}
|
|
480
520
|
},
|
|
481
521
|
doMove(up) {
|
|
482
|
-
if (this.
|
|
522
|
+
if (this.internalOptions.length > 0) {
|
|
483
523
|
// requery could have changed
|
|
484
|
-
const currentHighlight = this.
|
|
524
|
+
const currentHighlight = this.internalOptions.findIndex(
|
|
485
525
|
(item) => item.value === this.highlighted
|
|
486
526
|
);
|
|
487
527
|
let newHiglight;
|
|
488
528
|
|
|
489
529
|
if (up) {
|
|
490
530
|
if (currentHighlight <= 0) {
|
|
491
|
-
newHiglight = this.
|
|
531
|
+
newHiglight = this.internalOptions.length - 1;
|
|
492
532
|
} else {
|
|
493
533
|
newHiglight = currentHighlight - 1;
|
|
494
534
|
}
|
|
495
535
|
} else {
|
|
496
|
-
if (currentHighlight >= this.
|
|
536
|
+
if (currentHighlight >= this.internalOptions.length - 1) {
|
|
497
537
|
newHiglight = 0;
|
|
498
538
|
} else {
|
|
499
539
|
newHiglight = currentHighlight + 1;
|
|
500
540
|
}
|
|
501
541
|
}
|
|
502
|
-
this.highlighted = this.
|
|
542
|
+
this.highlighted = this.internalOptions[newHiglight].value;
|
|
503
543
|
// this.checkHighlightPosition(newHiglight);
|
|
504
544
|
}
|
|
505
545
|
},
|
|
506
|
-
updateOptions() {
|
|
507
|
-
|
|
508
|
-
const escFilter = this.filter.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
509
|
-
const pat = new RegExp(escFilter, "iu");
|
|
510
|
-
this.dataOptions = this.internalOptions
|
|
511
|
-
.filter((opt) => pat.test(opt.label))
|
|
512
|
-
.slice(0);
|
|
513
|
-
} else {
|
|
514
|
-
this.dataOptions = this.internalOptions.slice(0);
|
|
515
|
-
}
|
|
516
|
-
if (this.highlight !== this.highlighted) {
|
|
517
|
-
this.highlighted = this.highlight;
|
|
518
|
-
}
|
|
546
|
+
// updateOptions() { ////
|
|
547
|
+
// console.log("ns-multi-select updateOptions"); ////
|
|
519
548
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
549
|
+
// if (this.autoFilter) {
|
|
550
|
+
// const escFilter = this.filter.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
551
|
+
// const pat = new RegExp(escFilter, "iu");
|
|
552
|
+
// this.dataOptions = this.internalOptions
|
|
553
|
+
// .filter((opt) => pat.test(opt.label))
|
|
554
|
+
// .slice(0);
|
|
555
|
+
// } else {
|
|
556
|
+
// this.dataOptions = this.internalOptions.slice(0);
|
|
557
|
+
// }
|
|
558
|
+
// if (this.highlight !== this.highlighted) {
|
|
559
|
+
// this.highlighted = this.highlight;
|
|
560
|
+
// }
|
|
532
561
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
562
|
+
// // multi select unique part
|
|
563
|
+
// if (
|
|
564
|
+
// !this.sorting &&
|
|
565
|
+
// this.selectionFeedback !== selectionFeedbackOptions[FIXED]
|
|
566
|
+
// ) {
|
|
567
|
+
// // if included in data value move to top
|
|
568
|
+
// this.dataOptions.sort(
|
|
569
|
+
// (a, b) =>
|
|
570
|
+
// (this.dataValue.includes(a.value) ? -1 : 1) -
|
|
571
|
+
// (this.dataValue.includes(b.value) ? -1 : 1)
|
|
572
|
+
// );
|
|
573
|
+
// }
|
|
536
574
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
575
|
+
// // added for ns-multi-select
|
|
576
|
+
// if (this.acceptUserInput && this.filter.trim()) {
|
|
577
|
+
// //// remove block?
|
|
578
|
+
// // suggest user input
|
|
541
579
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
580
|
+
// const trimmedFilter = this.filter.trim();
|
|
581
|
+
// const itemFound = this.internalOptions.find(
|
|
582
|
+
// (o) => o.value.trim() === trimmedFilter
|
|
583
|
+
// );
|
|
584
|
+
|
|
585
|
+
// if (!itemFound) {
|
|
586
|
+
// this.dataOptions.push({
|
|
587
|
+
// name: trimmedFilter,
|
|
588
|
+
// label: trimmedFilter,
|
|
589
|
+
// value: trimmedFilter,
|
|
590
|
+
// type: this.userInputLabel,
|
|
591
|
+
// });
|
|
592
|
+
// }
|
|
593
|
+
// }
|
|
594
|
+
// },
|
|
552
595
|
updateHighlight() {
|
|
553
596
|
let firstMatchIndex;
|
|
554
|
-
if (this.autoHighlight && this.
|
|
597
|
+
if (this.autoHighlight && this.internalOptions.length > 0) {
|
|
555
598
|
// then highlight first match
|
|
556
599
|
const filterRegex = new RegExp(this.filter, "iu");
|
|
557
|
-
firstMatchIndex = this.
|
|
600
|
+
firstMatchIndex = this.internalOptions.findIndex((item) =>
|
|
558
601
|
filterRegex.test(item.label)
|
|
559
602
|
);
|
|
560
603
|
if (firstMatchIndex < 0) {
|
|
561
604
|
firstMatchIndex = 0;
|
|
562
605
|
}
|
|
563
|
-
this.highlighted = this.
|
|
606
|
+
this.highlighted = this.internalOptions[firstMatchIndex].value;
|
|
564
607
|
// this.checkHighlightPosition(firstMatchIndex);
|
|
565
608
|
}
|
|
566
609
|
},
|
|
567
610
|
onInput() {
|
|
568
611
|
this.doOpen(true);
|
|
569
612
|
|
|
570
|
-
this.updateOptions();
|
|
613
|
+
// this.updateOptions(); ////
|
|
571
614
|
this.updateHighlight();
|
|
572
615
|
},
|
|
573
616
|
doOpen(newVal) {
|
|
574
|
-
if (
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
) {
|
|
579
|
-
|
|
580
|
-
}
|
|
617
|
+
// if ( ////
|
|
618
|
+
// newVal &&
|
|
619
|
+
// !this.open &&
|
|
620
|
+
// this.selectionFeedback === selectionFeedbackOptions[TOP_AFTER_REOPEN]
|
|
621
|
+
// ) {
|
|
622
|
+
// this.updateOptions();
|
|
623
|
+
// }
|
|
581
624
|
this.open = newVal;
|
|
582
625
|
},
|
|
583
626
|
onDown() {
|
|
@@ -610,7 +653,7 @@ export default {
|
|
|
610
653
|
this.filter = "";
|
|
611
654
|
|
|
612
655
|
this.doOpen(false);
|
|
613
|
-
this.updateOptions();
|
|
656
|
+
// this.updateOptions(); ////
|
|
614
657
|
} else {
|
|
615
658
|
this.doOpen(true);
|
|
616
659
|
}
|
|
@@ -675,9 +718,9 @@ export default {
|
|
|
675
718
|
}
|
|
676
719
|
}
|
|
677
720
|
|
|
678
|
-
if (this.selectionFeedback === selectionFeedbackOptions[TOP]) {
|
|
679
|
-
|
|
680
|
-
}
|
|
721
|
+
// if (this.selectionFeedback === selectionFeedbackOptions[TOP]) {
|
|
722
|
+
// this.updateOptions(); ////
|
|
723
|
+
// }
|
|
681
724
|
this.$refs.button.focus();
|
|
682
725
|
this.$emit("change", this.dataValue);
|
|
683
726
|
},
|
|
@@ -732,4 +775,4 @@ export default {
|
|
|
732
775
|
.ns-multi-select .bx--tooltip__label .bx--tooltip__trigger {
|
|
733
776
|
margin-left: 0.25rem;
|
|
734
777
|
}
|
|
735
|
-
</style>
|
|
778
|
+
</style>
|