@sd-angular/core 1.0.80 → 1.0.81

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/material/icon'), require('@angular/material/tooltip'), require('@angular/material/progress-spinner'), require('@angular/cdk/keycodes'), require('rxjs/operators'), require('uuid'), require('@angular/forms'), require('rxjs'), require('@sd-angular/core/utility'), require('@angular/material/autocomplete'), require('@sd-angular/core/common'), require('@angular/material/input'), require('@angular/material/form-field'), require('@sd-angular/core/translate'), require('@angular/material/chips')) :
3
- typeof define === 'function' && define.amd ? define('@sd-angular/core/chip', ['exports', '@angular/core', '@angular/common', '@angular/material/icon', '@angular/material/tooltip', '@angular/material/progress-spinner', '@angular/cdk/keycodes', 'rxjs/operators', 'uuid', '@angular/forms', 'rxjs', '@sd-angular/core/utility', '@angular/material/autocomplete', '@sd-angular/core/common', '@angular/material/input', '@angular/material/form-field', '@sd-angular/core/translate', '@angular/material/chips'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['sd-angular'] = global['sd-angular'] || {}, global['sd-angular'].core = global['sd-angular'].core || {}, global['sd-angular'].core.chip = {}), global.ng.core, global.ng.common, global.ng.material.icon, global.ng.material.tooltip, global.ng.material.progressSpinner, global.ng.cdk.keycodes, global.rxjs.operators, global.uuid, global.ng.forms, global.rxjs, global['sd-angular'].core.utility, global.ng.material.autocomplete, global['sd-angular'].core.common, global.ng.material.input, global.ng.material.formField, global['sd-angular'].core.translate, global.ng.material.chips));
5
- }(this, (function (exports, core, common$1, icon, tooltip, progressSpinner, keycodes, operators, uuid, forms, rxjs, utility, autocomplete, common, input, formField, translate, chips) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/material/icon'), require('@angular/material/tooltip'), require('@angular/material/progress-spinner'), require('@angular/cdk/keycodes'), require('rxjs/operators'), require('uuid'), require('@angular/forms'), require('rxjs'), require('@angular/material/autocomplete'), require('@sd-angular/core/common'), require('@angular/material/input'), require('@angular/material/form-field'), require('@sd-angular/core/translate'), require('@angular/material/chips')) :
3
+ typeof define === 'function' && define.amd ? define('@sd-angular/core/chip', ['exports', '@angular/core', '@angular/common', '@angular/material/icon', '@angular/material/tooltip', '@angular/material/progress-spinner', '@angular/cdk/keycodes', 'rxjs/operators', 'uuid', '@angular/forms', 'rxjs', '@angular/material/autocomplete', '@sd-angular/core/common', '@angular/material/input', '@angular/material/form-field', '@sd-angular/core/translate', '@angular/material/chips'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['sd-angular'] = global['sd-angular'] || {}, global['sd-angular'].core = global['sd-angular'].core || {}, global['sd-angular'].core.chip = {}), global.ng.core, global.ng.common, global.ng.material.icon, global.ng.material.tooltip, global.ng.material.progressSpinner, global.ng.cdk.keycodes, global.rxjs.operators, global.uuid, global.ng.forms, global.rxjs, global.ng.material.autocomplete, global['sd-angular'].core.common, global.ng.material.input, global.ng.material.formField, global['sd-angular'].core.translate, global.ng.material.chips));
5
+ }(this, (function (exports, core, common$1, icon, tooltip, progressSpinner, keycodes, operators, uuid, forms, rxjs, autocomplete, common, input, formField, translate, chips) { 'use strict';
6
6
 
7
7
  /*! *****************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -337,7 +337,7 @@
337
337
  { type: core.TemplateRef }
338
338
  ]; };
339
339
 
340
- var _name, _form, _itemChanges, _items, _allItems, _allItem, _cache, _delay, _itemsChanges, _subscription, _updateValidator, _loadItems, _loadSelectedItems;
340
+ var _name, _form, _addable, _allItems, _allItem, _cache, _delay, _itemsChanges, _filteredItems, _subscription, _updateValidator, _loadItems, _loadSelectedItems;
341
341
  var SdChipErrotStateMatcher = /** @class */ (function () {
342
342
  function SdChipErrotStateMatcher(formControl) {
343
343
  this.formControl = formControl;
@@ -350,17 +350,15 @@
350
350
  return SdChipErrotStateMatcher;
351
351
  }());
352
352
  var SdChip = /** @class */ (function () {
353
- function SdChip(ref, utilityService) {
353
+ function SdChip(ref) {
354
354
  var _this = this;
355
355
  this.ref = ref;
356
- this.utilityService = utilityService;
357
356
  _name.set(this, uuid.v4());
358
357
  this.separatorKeysCodes = [keycodes.ENTER, keycodes.COMMA];
359
358
  this.selectable = true;
360
359
  _form.set(this, void 0);
360
+ _addable.set(this, void 0);
361
361
  this.removable = true;
362
- _itemChanges.set(this, new rxjs.Subject());
363
- _items.set(this, []);
364
362
  // @Input() set items(items: undefined | any[]) {
365
363
  // if (!items) {
366
364
  // this.#items = [];
@@ -380,6 +378,7 @@
380
378
  _delay.set(this, 200); // Sau khoảng thời gian delay nếu không có thay đổi thì thì mới bắt đầu thực hiện gọi hàm
381
379
  _itemsChanges.set(this, new rxjs.BehaviorSubject([]));
382
380
  this.limit = 50;
381
+ _filteredItems.set(this, void 0);
383
382
  // Validator
384
383
  this.isRequired = false;
385
384
  this.modelChange = new core.EventEmitter();
@@ -412,22 +411,22 @@
412
411
  _loadItems.set(this, function (searchText, items) { return __awaiter(_this, void 0, void 0, function () {
413
412
  var results, objItem, selectedItems;
414
413
  var _this = this;
415
- return __generator(this, function (_d) {
416
- switch (_d.label) {
414
+ return __generator(this, function (_f) {
415
+ switch (_f.label) {
417
416
  case 0:
418
417
  searchText = (searchText === null || searchText === void 0 ? void 0 : searchText.toString()) || '';
419
418
  if (!(__classPrivateFieldGet(this, _cache)[searchText] === undefined)) return [3 /*break*/, 2];
420
419
  this.loading = true;
421
420
  return [4 /*yield*/, items(searchText).catch(function () { return []; }).finally(function () { return _this.loading = false; })];
422
421
  case 1:
423
- results = _d.sent();
422
+ results = _f.sent();
424
423
  objItem = Array.toObject(results, this.valueField);
425
424
  __classPrivateFieldSet(this, _allItem, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _allItem)), objItem));
426
425
  __classPrivateFieldGet(this, _cache)[searchText] = results.union(this.valueField);
427
- _d.label = 2;
426
+ _f.label = 2;
428
427
  case 2: return [4 /*yield*/, __classPrivateFieldGet(this, _loadSelectedItems).call(this, this.formControl.value, items)];
429
428
  case 3:
430
- selectedItems = _d.sent();
429
+ selectedItems = _f.sent();
431
430
  // Đưa những selectedItems lên đầu nếu không mat-select-trigger sẽ không work
432
431
  return [2 /*return*/, __spread(selectedItems, __classPrivateFieldGet(this, _cache)[searchText]).union(this.valueField)];
433
432
  }
@@ -436,8 +435,8 @@
436
435
  _loadSelectedItems.set(this, function (value, items) { return __awaiter(_this, void 0, void 0, function () {
437
436
  var values, results, objItem, objValue;
438
437
  var _this = this;
439
- return __generator(this, function (_d) {
440
- switch (_d.label) {
438
+ return __generator(this, function (_f) {
439
+ switch (_f.label) {
441
440
  case 0:
442
441
  if (!(value === null || value === void 0 ? void 0 : value.toString())) {
443
442
  return [2 /*return*/, []];
@@ -450,56 +449,95 @@
450
449
  if (!values.some(function (val) { return __classPrivateFieldGet(_this, _allItem)[val] === undefined; })) return [3 /*break*/, 2];
451
450
  return [4 /*yield*/, items(value, true).catch(function () { return []; }).finally(function () { return _this.loading = false; })];
452
451
  case 1:
453
- results = _d.sent();
452
+ results = _f.sent();
454
453
  objItem = Array.toObject(results, this.valueField);
455
454
  objValue = Array.toObject(values.map(function (val) {
456
- var _d, _e;
457
- return (_d = {}, _d[val === null || val === void 0 ? void 0 : val.toString()] = (_e = {}, _e[_this.valueField] = val, _e[_this.displayField] = val, _e), _d);
455
+ var _f, _g;
456
+ return (_f = {}, _f[val === null || val === void 0 ? void 0 : val.toString()] = (_g = {}, _g[_this.valueField] = val, _g[_this.displayField] = val, _g), _f);
458
457
  }), this.valueField);
459
458
  __classPrivateFieldSet(this, _allItem, Object.assign(Object.assign(Object.assign({}, objValue), __classPrivateFieldGet(this, _allItem)), objItem));
460
- _d.label = 2;
459
+ _f.label = 2;
461
460
  case 2: return [2 /*return*/, values.map(function (val) {
462
- var _d;
461
+ var _f;
463
462
  var _a;
464
- return (_a = __classPrivateFieldGet(_this, _allItem)[val === null || val === void 0 ? void 0 : val.toString()]) !== null && _a !== void 0 ? _a : (_d = {}, _d[_this.valueField] = val, _d[_this.displayField] = val, _d);
463
+ return (_a = __classPrivateFieldGet(_this, _allItem)[val === null || val === void 0 ? void 0 : val.toString()]) !== null && _a !== void 0 ? _a : (_f = {}, _f[_this.valueField] = val, _f[_this.displayField] = val, _f);
465
464
  })];
466
465
  }
467
466
  });
468
467
  }); });
469
- this.filter = function (value) {
470
- return __classPrivateFieldGet(_this, _items).filter(function (item) {
471
- var _a;
472
- if ((_a = _this.formControl.value) === null || _a === void 0 ? void 0 : _a.some(function (val) { return val === item[_this.valueField]; })) {
473
- return false;
474
- }
475
- return !value || _this.utilityService.changeAliasLowerCase(item[_this.displayField])
476
- .indexOf(_this.utilityService.changeAliasLowerCase(value)) !== -1;
477
- }).filter(function (item, index) { return index < _this.limit; });
478
- };
479
468
  this.onAdd = function (event) {
480
- var _a, _b;
469
+ var _a, _b, _c, _d, _e;
481
470
  // Add item only when MatAutocomplete is not open
482
471
  // To make sure this does not conflict with OptionSelected Event
483
- if (!_this.matAutocomplete.isOpen) {
484
- var value_1 = ((_a = event.value) !== null && _a !== void 0 ? _a : '').toString().toLowerCase().trim();
485
- if (value_1) {
486
- var item = __classPrivateFieldGet(_this, _items).find(function (e) { return e[_this.displayField]
487
- && e[_this.displayField].toString().toLowerCase().trim() === value_1; });
472
+ // if (!this.matAutocomplete.isOpen) {
473
+ // const value = (event.value ?? '').toString().trim();
474
+ // if (value) {
475
+ // if (this.valueField && this.displayField) {
476
+ // const item = this.#filteredItems.find(e => e[this.displayField] === value);
477
+ // if (item) {
478
+ // const values: (string | number)[] = this.formControl.value ?? [];
479
+ // values.push(item[this.valueField]);
480
+ // this.formControl.setValue(values);
481
+ // } else if (this.#addable) {
482
+ // const values: (string | number)[] = this.formControl.value ?? [];
483
+ // values.push(value);
484
+ // this.formControl.setValue(values);
485
+ // }
486
+ // } else {
487
+ // console.log(value);
488
+ // console.log(this.#filteredItems);
489
+ // const item = this.#filteredItems.find(item => item === value);
490
+ // if (item) {
491
+ // const values: (string | number)[] = this.formControl.value ?? [];
492
+ // values.push(item);
493
+ // this.formControl.setValue(values);
494
+ // } else if (this.#addable) {
495
+ // const values: (string | number)[] = this.formControl.value ?? [];
496
+ // values.push(value);
497
+ // this.formControl.setValue(values);
498
+ // }
499
+ // }
500
+ // }
501
+ // this.inputControl.setValue('');
502
+ // }
503
+ var value = ((_a = event.value) !== null && _a !== void 0 ? _a : '').toString().trim();
504
+ if (value) {
505
+ if (_this.valueField && _this.displayField) {
506
+ var item = __classPrivateFieldGet(_this, _filteredItems).find(function (e) { return e[_this.displayField] === value; });
488
507
  if (item) {
489
508
  var values = (_b = _this.formControl.value) !== null && _b !== void 0 ? _b : [];
490
509
  values.push(item[_this.valueField]);
491
510
  _this.formControl.setValue(values);
492
511
  }
512
+ else if (__classPrivateFieldGet(_this, _addable)) {
513
+ var values = (_c = _this.formControl.value) !== null && _c !== void 0 ? _c : [];
514
+ values.push(value);
515
+ _this.formControl.setValue(values);
516
+ }
517
+ }
518
+ else {
519
+ var item = __classPrivateFieldGet(_this, _filteredItems).find(function (item) { return item === value; });
520
+ if (item) {
521
+ var values = (_d = _this.formControl.value) !== null && _d !== void 0 ? _d : [];
522
+ values.push(item);
523
+ _this.formControl.setValue(values);
524
+ }
525
+ else if (__classPrivateFieldGet(_this, _addable)) {
526
+ var values = (_e = _this.formControl.value) !== null && _e !== void 0 ? _e : [];
527
+ values.push(value);
528
+ _this.formControl.setValue(values);
529
+ }
493
530
  }
494
- _this.inputControl.setValue('');
495
531
  }
532
+ _this.input.nativeElement.value = '';
533
+ _this.inputControl.setValue('');
496
534
  };
497
535
  // andn1 viết để xử lý tạm us B2B1D-18289 ở S69
498
536
  this.onAdd2 = function (event) {
499
537
  var _a, _b;
500
538
  var value = ((_a = event.value) !== null && _a !== void 0 ? _a : '').toString().toLowerCase().trim();
501
539
  if (value) {
502
- var item = __classPrivateFieldGet(_this, _items).find(function (e) { return e[_this.valueField]
540
+ var item = __classPrivateFieldGet(_this, _filteredItems).find(function (e) { return e[_this.valueField]
503
541
  && e[_this.valueField].toString().toLowerCase().trim() === value; });
504
542
  if (item) {
505
543
  var values = (_b = _this.formControl.value) !== null && _b !== void 0 ? _b : [];
@@ -510,56 +548,92 @@
510
548
  }
511
549
  }
512
550
  _this.inputControl.setValue('');
513
- _this.ref.detectChanges();
514
551
  };
515
552
  this.onRemove = function (item) {
516
553
  var _a;
517
554
  var values = (_a = _this.formControl.value) !== null && _a !== void 0 ? _a : [];
518
- _this.formControl.setValue(values.filter(function (value) { return (item === null || item === void 0 ? void 0 : item[_this.valueField]) !== value; }));
555
+ if (typeof (item) === 'string' || typeof (item) === 'number') {
556
+ _this.formControl.setValue(values.filter(function (value) { return item !== value; }));
557
+ }
558
+ else if (_this.valueField) {
559
+ _this.formControl.setValue(values.filter(function (value) { return (item === null || item === void 0 ? void 0 : item[_this.valueField]) !== value; }));
560
+ }
519
561
  _this.inputControl.setValue('');
520
562
  };
521
563
  this.select = function (item) {
522
564
  _this.chipSelected.emit(item);
523
565
  };
566
+ // onSelect = (event: MatAutocompleteSelectedEvent) => {
567
+ // const value = (event.option.value?.[this.valueField] ?? '').toString().trim();
568
+ // if (value) {
569
+ // const item = this.#items.find(e => e[this.valueField]
570
+ // && e[this.valueField].toString().trim() === value);
571
+ // if (item) {
572
+ // const values: (string | number)[] = this.formControl.value ?? [];
573
+ // values.push(item[this.valueField]);
574
+ // this.formControl.setValue(values);
575
+ // this.input.nativeElement.value = '';
576
+ // this.inputControl.setValue('');
577
+ // setTimeout(() => {
578
+ // this.autocompleteTrigger?.openPanel();
579
+ // }, 0);
580
+ // }
581
+ // }
582
+ // }
524
583
  this.onSelect = function (event) {
525
- var _a, _b, _c;
526
- var value = ((_b = (_a = event.option.value) === null || _a === void 0 ? void 0 : _a[_this.valueField]) !== null && _b !== void 0 ? _b : '').toString().trim();
527
- if (value) {
528
- var item = __classPrivateFieldGet(_this, _items).find(function (e) { return e[_this.valueField]
529
- && e[_this.valueField].toString().trim() === value; });
530
- if (item) {
531
- var values = (_c = _this.formControl.value) !== null && _c !== void 0 ? _c : [];
532
- values.push(item[_this.valueField]);
533
- _this.formControl.setValue(values);
534
- _this.input.nativeElement.value = '';
535
- _this.inputControl.setValue('');
536
- setTimeout(function () {
537
- var _a;
538
- (_a = _this.autocompleteTrigger) === null || _a === void 0 ? void 0 : _a.openPanel();
539
- }, 0);
540
- }
541
- }
542
- };
543
- this.displayFn = function (value) {
544
- if (typeof value === 'string') {
545
- if (!__classPrivateFieldGet(_this, _items)) {
546
- return undefined;
547
- }
548
- var selectedItem = __classPrivateFieldGet(_this, _items).find(function (item) { return item[_this.valueField] === value; });
549
- if (selectedItem) {
550
- return selectedItem[_this.displayField];
551
- }
552
- if (__classPrivateFieldGet(_this, _items).some(function (item) { return item[_this.displayField].toLowerCase().indexOf(value.toLowerCase()) !== -1; })) {
553
- return value;
584
+ var _a;
585
+ var item = event.option.value;
586
+ var values = (_a = _this.formControl.value) !== null && _a !== void 0 ? _a : [];
587
+ if (item) {
588
+ if (typeof (item) === 'string' || typeof (item) === 'number') {
589
+ if (!values.includes(item)) {
590
+ values.push(item);
591
+ _this.formControl.setValue(values);
592
+ _this.modelChange.emit(values);
593
+ _this.sdChange.emit(values);
594
+ setTimeout(function () {
595
+ var _a;
596
+ (_a = _this.autocompleteTrigger) === null || _a === void 0 ? void 0 : _a.openPanel();
597
+ }, 0);
598
+ }
554
599
  }
555
- else {
556
- return undefined;
600
+ else if (_this.valueField) {
601
+ var val = (item === null || item === void 0 ? void 0 : item[_this.valueField]) || null;
602
+ if (!values.includes(val)) {
603
+ values.push(val);
604
+ _this.formControl.setValue(values);
605
+ _this.modelChange.emit(values);
606
+ _this.sdChange.emit(values);
607
+ setTimeout(function () {
608
+ var _a;
609
+ (_a = _this.autocompleteTrigger) === null || _a === void 0 ? void 0 : _a.openPanel();
610
+ }, 0);
611
+ }
557
612
  }
558
- }
559
- else {
560
- return value ? value[_this.displayField] : undefined;
613
+ _this.input.nativeElement.value = '';
614
+ _this.inputControl.setValue('', {
615
+ emitEvent: false
616
+ });
561
617
  }
562
618
  };
619
+ // displayFn = (value: string | { [key: string]: string }): string | undefined => {
620
+ // if (typeof value === 'string') {
621
+ // if (!this.#items) {
622
+ // return undefined;
623
+ // }
624
+ // const selectedItem = this.#items.find(item => item[this.valueField] === value);
625
+ // if (selectedItem) {
626
+ // return selectedItem[this.displayField];
627
+ // }
628
+ // if (this.#items.some(item => item[this.displayField].toLowerCase().indexOf(value.toLowerCase()) !== -1)) {
629
+ // return value;
630
+ // } else {
631
+ // return undefined;
632
+ // }
633
+ // } else {
634
+ // return value ? value[this.displayField] : undefined;
635
+ // }
636
+ // }
563
637
  this.onFocus = function () {
564
638
  _this.isFocused = true;
565
639
  _this.inputControl.setValue('');
@@ -619,6 +693,13 @@
619
693
  enumerable: false,
620
694
  configurable: true
621
695
  });
696
+ Object.defineProperty(SdChip.prototype, "addable", {
697
+ set: function (val) {
698
+ __classPrivateFieldSet(this, _addable, (val === '') || val);
699
+ },
700
+ enumerable: false,
701
+ configurable: true
702
+ });
622
703
  Object.defineProperty(SdChip.prototype, "_removable", {
623
704
  set: function (val) {
624
705
  this.removable = (val === '') || val;
@@ -696,8 +777,6 @@
696
777
  configurable: true
697
778
  });
698
779
  SdChip.prototype.ngOnInit = function () {
699
- var _this = this;
700
- this.filteredItems = this.inputControl.valueChanges.pipe(operators.startWith(''), operators.map(function (item) { var _a; return typeof item === 'string' ? item : ((_a = item === null || item === void 0 ? void 0 : item[_this.displayField]) !== null && _a !== void 0 ? _a : ''); }), operators.map(function (name) { return _this.filter(name); }));
701
780
  };
702
781
  SdChip.prototype.ngAfterViewInit = function () {
703
782
  var _this = this;
@@ -709,50 +788,31 @@
709
788
  __classPrivateFieldGet(this, _itemsChanges).asObservable(),
710
789
  this.inputControl.valueChanges.pipe(operators.startWith(''), operators.debounceTime(__classPrivateFieldGet(this, _delay))),
711
790
  this.formControl.valueChanges.pipe(operators.startWith(this.formControl.value))
712
- ]).pipe(operators.switchMap(function (_d) {
713
- var _e = __read(_d, 3), items = _e[0], val = _e[1], formValue = _e[2];
791
+ ]).pipe(operators.switchMap(function (_f) {
792
+ var _g = __read(_f, 1), items = _g[0];
714
793
  return __awaiter(_this, void 0, void 0, function () {
715
- var isArray, hasFields, filteredItems;
794
+ var val, values, hasFields;
716
795
  var _this = this;
717
- return __generator(this, function (_d) {
718
- switch (_d.label) {
796
+ return __generator(this, function (_f) {
797
+ switch (_f.label) {
719
798
  case 0:
799
+ val = this.inputControl.value;
800
+ values = this.formControl.value || [];
720
801
  if (!(typeof (items) === 'function')) return [3 /*break*/, 2];
721
802
  return [4 /*yield*/, __classPrivateFieldGet(this, _loadItems).call(this, val, items)];
722
- case 1: return [2 /*return*/, _d.sent()];
803
+ case 1: return [2 /*return*/, _f.sent()];
723
804
  case 2:
724
805
  __classPrivateFieldSet(this, _allItem, items.toObject(this.valueField));
725
- isArray = Array.isArray(formValue);
726
806
  hasFields = !!this.valueField && !!this.displayField;
727
- filteredItems = items.filter(function (item) {
807
+ __classPrivateFieldSet(this, _filteredItems, items.filter(function (item) {
728
808
  var value = hasFields ? item[_this.valueField] : item;
729
809
  var display = hasFields ? item[_this.displayField] : item;
730
810
  if (String.aliasIncludes(value, val) || String.aliasIncludes(display, val)) {
731
811
  return true;
732
812
  }
733
- if (isArray) {
734
- return formValue.some(function (e) { return e === value; });
735
- }
736
- return formValue === value;
737
- });
738
- if (items.length <= this.limit) {
739
- return [2 /*return*/, filteredItems];
740
- }
741
- // Đưa những selectedItems lên đầu nếu không mat-select-trigger sẽ không work
742
- return [2 /*return*/, filteredItems.sort(function (current, next) {
743
- var value1 = hasFields ? current[_this.valueField] : current;
744
- var value2 = hasFields ? next[_this.valueField] : next;
745
- var flag1 = 0;
746
- var flag2 = 0;
747
- if (isArray) {
748
- flag1 = formValue.some(function (e) { return e === value1; }) ? 1 : 0;
749
- flag2 = formValue.some(function (e) { return e === value2; }) ? 1 : 0;
750
- return flag2 - flag1;
751
- }
752
- flag1 = formValue === value1 ? 1 : 0;
753
- flag2 = formValue === value2 ? 1 : 0;
754
- return flag2 - flag1;
755
- })];
813
+ return values.some(function (e) { return e === value; });
814
+ }));
815
+ return [2 /*return*/, __classPrivateFieldGet(this, _filteredItems)];
756
816
  }
757
817
  });
758
818
  });
@@ -761,39 +821,41 @@
761
821
  __classPrivateFieldGet(this, _itemsChanges).asObservable(),
762
822
  this.formControl.valueChanges.pipe(operators.startWith(this.formControl.value))
763
823
  ])
764
- .pipe(operators.switchMap(function (_d) {
765
- var _e = __read(_d, 2), items = _e[0], val = _e[1];
824
+ .pipe(operators.switchMap(function (_f) {
825
+ var _g = __read(_f, 2), items = _g[0], val = _g[1];
766
826
  return __awaiter(_this, void 0, void 0, function () {
767
- var values;
827
+ var _b;
768
828
  var _this = this;
769
- return __generator(this, function (_d) {
770
- switch (_d.label) {
829
+ return __generator(this, function (_f) {
830
+ switch (_f.label) {
771
831
  case 0:
772
832
  // Vì một số lý do chưa xác định mà khi sử dụng sdViewDef thì khi chuyển sang dạng view sẽ trigger val = null
773
833
  // Nhưng formControl.value vẫn có giá trị đúng nên thực hiện gán val = this.formControl.value;
774
834
  val = this.formControl.value;
775
- if (!(val === null || val === void 0 ? void 0 : val.toString())) {
776
- return [2 /*return*/, []];
777
- }
778
- values = Array.isArray(val) ? val : [val];
779
835
  if (!this.valueField) {
780
- return [2 /*return*/, values];
836
+ return [2 /*return*/, this.formControl.value];
781
837
  }
782
838
  if (!(typeof (items) === 'function')) return [3 /*break*/, 2];
783
839
  return [4 /*yield*/, __classPrivateFieldGet(this, _loadSelectedItems).call(this, val, items)];
784
- case 1: return [2 /*return*/, _d.sent()];
785
- case 2: return [2 /*return*/, values.map(function (value) {
786
- var _d;
787
- return (items === null || items === void 0 ? void 0 : items.find(function (item) { return item[_this.valueField] === value; })) || (_d = {},
788
- _d[_this.valueField] = value,
789
- _d[_this.displayField] = value,
790
- _d);
840
+ case 1: return [2 /*return*/, _f.sent()];
841
+ case 2: return [2 /*return*/, (_b = (this.formControl.value || [])) === null || _b === void 0 ? void 0 : _b.map(function (value) {
842
+ var _f;
843
+ return (items === null || items === void 0 ? void 0 : items.find(function (item) { return item[_this.valueField] === value; })) || (_f = {},
844
+ _f[_this.valueField] = value,
845
+ _f[_this.displayField] = value,
846
+ _f);
791
847
  })];
792
848
  }
793
849
  });
794
850
  });
795
851
  }));
796
- this.filteredItems = __classPrivateFieldGet(this, _allItems).pipe(operators.map(function (allItems) { return allItems.paging(_this.limit); }));
852
+ this.filteredItems = __classPrivateFieldGet(this, _allItems).pipe(operators.map(function (allItems) { return allItems.filter(function (item) {
853
+ var values = _this.formControl.value || [];
854
+ if (_this.valueField) {
855
+ return !values.includes(item === null || item === void 0 ? void 0 : item[_this.valueField]);
856
+ }
857
+ return !values.includes(item);
858
+ }).paging(_this.limit); }));
797
859
  // this.display = this.selectedItems.pipe(
798
860
  // map(selectedItems => selectedItems?.map(item => this.displayField ? item[this.displayField] : item)?.join(', ')));
799
861
  // this.#subscription.add(this.formControl.valueChanges.subscribe(() => {
@@ -825,22 +887,23 @@
825
887
  };
826
888
  return SdChip;
827
889
  }());
828
- _name = new WeakMap(), _form = new WeakMap(), _itemChanges = new WeakMap(), _items = new WeakMap(), _allItems = new WeakMap(), _allItem = new WeakMap(), _cache = new WeakMap(), _delay = new WeakMap(), _itemsChanges = new WeakMap(), _subscription = new WeakMap(), _updateValidator = new WeakMap(), _loadItems = new WeakMap(), _loadSelectedItems = new WeakMap();
890
+ _name = new WeakMap(), _form = new WeakMap(), _addable = new WeakMap(), _allItems = new WeakMap(), _allItem = new WeakMap(), _cache = new WeakMap(), _delay = new WeakMap(), _itemsChanges = new WeakMap(), _filteredItems = new WeakMap(), _subscription = new WeakMap(), _updateValidator = new WeakMap(), _loadItems = new WeakMap(), _loadSelectedItems = new WeakMap();
829
891
  SdChip.decorators = [
830
892
  { type: core.Component, args: [{
831
893
  selector: 'sd-chip',
832
- template: "<div class=\"d-flex align-items-center\" [class.sd-view]=\"sdView?.templateRef\" [class.c-focused]=\"isFocused\"\r\n [class.c-disabled]=\"formControl.disabled\" (click)=\"onClick()\">\r\n <ng-container *ngIf=\"sdView?.templateRef && !autocompleteTrigger?.panelOpen && !isFocused; else default\">\r\n <ng-container *ngTemplateOutlet=\"sdView.templateRef;context: { value: formControl.value}\">\r\n </ng-container>\r\n </ng-container>\r\n <ng-template #default>\r\n <mat-form-field class=\"c-md\" [ngClass]=\"{'c-sm': size === 'sm'}\" appearance=\"outline\">\r\n <mat-label *ngIf=\"label\">{{label}}</mat-label>\r\n <mat-chip-list [formControl]=\"formControl\" #chipList>\r\n <ng-container *ngFor=\"let item of selectedItems\">\r\n <mat-chip *ngIf=\"item\" [selectable]=\"selectable\" [removable]=\"true\" (removed)=\"onRemove(item)\"\r\n [selected]=\"item.isSelected\" (selectionChange)=\"select(item)\" [disabled]=\"inputControl.disabled\"\r\n (click)=\"item.isSelected = !item.isSelected\">\r\n <ng-container *ngIf=\"sdChipDisplay?.templateRef\">\r\n <ng-container *ngTemplateOutlet=\"sdChipDisplay.templateRef;context:{item: item}\">\r\n </ng-container>\r\n </ng-container>\r\n <span *ngIf=\"!sdChipDisplay?.templateRef\">{{item[displayField] || item[valueField]}}</span>\r\n <mat-icon *ngIf=\"!inputControl.disabled && item | sdRemovableChip:removable\" matChipRemove>cancel</mat-icon>\r\n </mat-chip>\r\n </ng-container>\r\n <input #autocompleteTrigger [formControl]=\"inputControl\" [placeholder]=\"placeholder || label\"\r\n [matAutocomplete]=\"auto\" [matChipInputFor]=\"chipList\" [matChipInputSeparatorKeyCodes]=\"separatorKeysCodes\"\r\n (matChipInputTokenEnd)=\"onAdd($event)\" autocomplete=\"off\" [errorStateMatcher]=\"matcher\" (focus)=\"onFocus()\"\r\n (blur)=\"onBlur()\" matInput #input>\r\n </mat-chip-list>\r\n <mat-error *ngIf=\"formControl?.errors?.minItem\">\r\n {{formControl?.errors?.minItem}}\r\n </mat-error>\r\n <mat-autocomplete #auto=\"matAutocomplete\" [displayWith]=\"displayFn\" (optionSelected)=\"onSelect($event)\">\r\n <mat-option *ngFor=\"let item of filteredItems | async\" [value]=\"item\">\r\n {{item[displayField]}}\r\n </mat-option>\r\n </mat-autocomplete>\r\n </mat-form-field>\r\n </ng-template>\r\n</div>",
894
+ template: "<div class=\"d-flex align-items-center\" [class.sd-view]=\"sdView?.templateRef\" [class.c-focused]=\"isFocused\"\r\n [class.c-disabled]=\"formControl.disabled\" (click)=\"onClick()\">\r\n <ng-container *ngIf=\"sdView?.templateRef && !autocompleteTrigger?.panelOpen && !isFocused; else default\">\r\n <ng-container *ngTemplateOutlet=\"sdView.templateRef;context: { value: formControl.value}\">\r\n </ng-container>\r\n </ng-container>\r\n <ng-template #default>\r\n <mat-form-field class=\"c-md\" [ngClass]=\"{'c-sm': size === 'sm'}\" appearance=\"outline\">\r\n <mat-label *ngIf=\"label\">{{label}}</mat-label>\r\n <mat-chip-list [formControl]=\"formControl\" #chipList>\r\n <ng-container *ngFor=\"let item of selectedItems | async\">\r\n <mat-chip *ngIf=\"item\" [selectable]=\"selectable\" [removable]=\"true\" (removed)=\"onRemove(item)\"\r\n [selected]=\"item.isSelected\" (selectionChange)=\"select(item)\" [disabled]=\"inputControl.disabled\"\r\n (click)=\"item.isSelected = !item.isSelected\">\r\n <ng-container *ngIf=\"sdChipDisplay?.templateRef\">\r\n <ng-container *ngTemplateOutlet=\"sdChipDisplay.templateRef;context:{item: item}\">\r\n </ng-container>\r\n </ng-container>\r\n <span *ngIf=\"!sdChipDisplay?.templateRef\">{{item[displayField] || item[valueField] || item}}</span>\r\n <mat-icon *ngIf=\"!inputControl.disabled && item | sdRemovableChip:removable\" matChipRemove>cancel</mat-icon>\r\n </mat-chip>\r\n </ng-container>\r\n <input #autocompleteTrigger [formControl]=\"inputControl\" [placeholder]=\"placeholder || label\"\r\n [matAutocomplete]=\"auto\" [matChipInputFor]=\"chipList\" [matChipInputSeparatorKeyCodes]=\"separatorKeysCodes\"\r\n (matChipInputTokenEnd)=\"onAdd($event)\" autocomplete=\"off\" [errorStateMatcher]=\"matcher\" (focus)=\"onFocus()\"\r\n (blur)=\"onBlur()\" matInput #input>\r\n </mat-chip-list>\r\n <mat-error *ngIf=\"formControl?.errors?.minItem\">\r\n {{formControl?.errors?.minItem}}\r\n </mat-error>\r\n <mat-autocomplete #auto=\"matAutocomplete\" (optionSelected)=\"onSelect($event)\">\r\n <mat-option *ngFor=\"let item of filteredItems | async\" [value]=\"item\" matTooltipPosition=\"above\"\r\n [matTooltip]=\"displayField ? item[displayField] : item\">\r\n {{ displayField ? item[displayField] : item }}\r\n </mat-option>\r\n </mat-autocomplete>\r\n </mat-form-field>\r\n </ng-template>\r\n</div>",
895
+ changeDetection: core.ChangeDetectionStrategy.OnPush,
833
896
  styles: [":host{display:block;padding-top:5px}:host ::ng-deep mat-form-field.c-md .mat-form-field-infix{min-height:43.5px;padding:2px 0}:host ::ng-deep mat-form-field.c-md .mat-standard-chip{min-height:26px;padding:7px 10px}:host ::ng-deep mat-form-field.c-md .mat-standard-chip.mat-chip-with-trailing-icon{padding:7px 7px 7px 10px}.sd-view:not(.c-focused):not(.c-disabled):hover{background-color:#ebecf0}"]
834
897
  },] }
835
898
  ];
836
899
  SdChip.ctorParameters = function () { return [
837
- { type: core.ChangeDetectorRef },
838
- { type: utility.SdUtilityService }
900
+ { type: core.ChangeDetectorRef }
839
901
  ]; };
840
902
  SdChip.propDecorators = {
841
903
  name: [{ type: core.Input }],
842
904
  size: [{ type: core.Input }],
843
905
  form: [{ type: core.Input }],
906
+ addable: [{ type: core.Input }],
844
907
  label: [{ type: core.Input }],
845
908
  valueField: [{ type: core.Input }],
846
909
  displayField: [{ type: core.Input }],