@sd-angular/core 1.0.78 → 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.
Files changed (52) hide show
  1. package/bundles/sd-angular-core-chip.umd.js +325 -108
  2. package/bundles/sd-angular-core-chip.umd.js.map +1 -1
  3. package/bundles/sd-angular-core-chip.umd.min.js +2 -2
  4. package/bundles/sd-angular-core-chip.umd.min.js.map +1 -1
  5. package/bundles/sd-angular-core-grid-material.umd.js +1 -1
  6. package/bundles/sd-angular-core-grid-material.umd.js.map +1 -1
  7. package/bundles/sd-angular-core-grid-material.umd.min.js +1 -1
  8. package/bundles/sd-angular-core-grid-material.umd.min.js.map +1 -1
  9. package/bundles/sd-angular-core-input.umd.js +1 -1
  10. package/bundles/sd-angular-core-input.umd.js.map +1 -1
  11. package/bundles/sd-angular-core-input.umd.min.js +1 -1
  12. package/bundles/sd-angular-core-input.umd.min.js.map +1 -1
  13. package/bundles/sd-angular-core-loading.umd.js +367 -22
  14. package/bundles/sd-angular-core-loading.umd.js.map +1 -1
  15. package/bundles/sd-angular-core-loading.umd.min.js +15 -1
  16. package/bundles/sd-angular-core-loading.umd.min.js.map +1 -1
  17. package/bundles/sd-angular-core-radio.umd.js +39 -25
  18. package/bundles/sd-angular-core-radio.umd.js.map +1 -1
  19. package/bundles/sd-angular-core-radio.umd.min.js +2 -2
  20. package/bundles/sd-angular-core-radio.umd.min.js.map +1 -1
  21. package/bundles/sd-angular-core-select.umd.js +1 -1
  22. package/bundles/sd-angular-core-select.umd.js.map +1 -1
  23. package/bundles/sd-angular-core-select.umd.min.js +2 -2
  24. package/bundles/sd-angular-core-select.umd.min.js.map +1 -1
  25. package/chip/sd-angular-core-chip.metadata.json +1 -1
  26. package/chip/src/lib/chip.component.d.ts +8 -13
  27. package/esm2015/chip/src/lib/chip.component.js +279 -96
  28. package/esm2015/grid-material/src/lib/components/desktop-cell-view/desktop-cell-view.component.js +2 -2
  29. package/esm2015/input/src/lib/input.component.js +2 -2
  30. package/esm2015/loading/src/lib/loading.service.js +49 -14
  31. package/esm2015/radio/src/lib/radio.component.js +39 -25
  32. package/esm2015/select/src/lib/select.component.js +2 -2
  33. package/fesm2015/sd-angular-core-chip.js +278 -95
  34. package/fesm2015/sd-angular-core-chip.js.map +1 -1
  35. package/fesm2015/sd-angular-core-grid-material.js +1 -1
  36. package/fesm2015/sd-angular-core-grid-material.js.map +1 -1
  37. package/fesm2015/sd-angular-core-input.js +1 -1
  38. package/fesm2015/sd-angular-core-input.js.map +1 -1
  39. package/fesm2015/sd-angular-core-loading.js +48 -13
  40. package/fesm2015/sd-angular-core-loading.js.map +1 -1
  41. package/fesm2015/sd-angular-core-radio.js +38 -25
  42. package/fesm2015/sd-angular-core-radio.js.map +1 -1
  43. package/fesm2015/sd-angular-core-select.js +1 -1
  44. package/fesm2015/sd-angular-core-select.js.map +1 -1
  45. package/grid-material/sd-angular-core-grid-material.metadata.json +1 -1
  46. package/input/sd-angular-core-input.metadata.json +1 -1
  47. package/loading/sd-angular-core-loading.metadata.json +1 -1
  48. package/loading/src/lib/loading.service.d.ts +5 -2
  49. package/package.json +1 -1
  50. package/radio/sd-angular-core-radio.metadata.json +1 -1
  51. package/radio/src/lib/radio.component.d.ts +5 -5
  52. package/{sd-angular-core-1.0.78.tgz → sd-angular-core-1.0.81.tgz} +0 -0
@@ -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, _subscription, _updateValidator;
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,19 +350,35 @@
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, []);
362
+ // @Input() set items(items: undefined | any[]) {
363
+ // if (!items) {
364
+ // this.#items = [];
365
+ // } else if (Array.isArray(items)) {
366
+ // this.#items = items.filter(e => (e ?? '').toString().trim() !== '');
367
+ // } else {
368
+ // this.#items = items;
369
+ // }
370
+ // this.inputControl.updateValueAndValidity();
371
+ // this.#itemChanges.next(this.items);
372
+ // }
373
+ // Server search
374
+ this.loading = false;
375
+ _allItems.set(this, void 0);
376
+ _allItem.set(this, {});
377
+ _cache.set(this, {});
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
379
+ _itemsChanges.set(this, new rxjs.BehaviorSubject([]));
364
380
  this.limit = 50;
365
- this.selectedItems = [];
381
+ _filteredItems.set(this, void 0);
366
382
  // Validator
367
383
  this.isRequired = false;
368
384
  this.modelChange = new core.EventEmitter();
@@ -371,7 +387,7 @@
371
387
  this.chipSelected = new core.EventEmitter();
372
388
  this.isFocused = false;
373
389
  this.inputControl = new forms.FormControl();
374
- this.formControl = new forms.FormControl();
390
+ this.formControl = new common.SdFormControl();
375
391
  this.matcher = new SdChipErrotStateMatcher(this.formControl);
376
392
  _subscription.set(this, new rxjs.Subscription());
377
393
  _updateValidator.set(this, function () {
@@ -392,40 +408,136 @@
392
408
  _this.formControl.setAsyncValidators(asyncValidators);
393
409
  _this.formControl.updateValueAndValidity();
394
410
  });
395
- this.filter = function (value) {
396
- return __classPrivateFieldGet(_this, _items).filter(function (item) {
397
- var _a;
398
- if ((_a = _this.formControl.value) === null || _a === void 0 ? void 0 : _a.some(function (val) { return val === item[_this.valueField]; })) {
399
- return false;
411
+ _loadItems.set(this, function (searchText, items) { return __awaiter(_this, void 0, void 0, function () {
412
+ var results, objItem, selectedItems;
413
+ var _this = this;
414
+ return __generator(this, function (_f) {
415
+ switch (_f.label) {
416
+ case 0:
417
+ searchText = (searchText === null || searchText === void 0 ? void 0 : searchText.toString()) || '';
418
+ if (!(__classPrivateFieldGet(this, _cache)[searchText] === undefined)) return [3 /*break*/, 2];
419
+ this.loading = true;
420
+ return [4 /*yield*/, items(searchText).catch(function () { return []; }).finally(function () { return _this.loading = false; })];
421
+ case 1:
422
+ results = _f.sent();
423
+ objItem = Array.toObject(results, this.valueField);
424
+ __classPrivateFieldSet(this, _allItem, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _allItem)), objItem));
425
+ __classPrivateFieldGet(this, _cache)[searchText] = results.union(this.valueField);
426
+ _f.label = 2;
427
+ case 2: return [4 /*yield*/, __classPrivateFieldGet(this, _loadSelectedItems).call(this, this.formControl.value, items)];
428
+ case 3:
429
+ selectedItems = _f.sent();
430
+ // Đưa những selectedItems lên đầu nếu không mat-select-trigger sẽ không work
431
+ return [2 /*return*/, __spread(selectedItems, __classPrivateFieldGet(this, _cache)[searchText]).union(this.valueField)];
400
432
  }
401
- return !value || _this.utilityService.changeAliasLowerCase(item[_this.displayField])
402
- .indexOf(_this.utilityService.changeAliasLowerCase(value)) !== -1;
403
- }).filter(function (item, index) { return index < _this.limit; });
404
- };
433
+ });
434
+ }); });
435
+ _loadSelectedItems.set(this, function (value, items) { return __awaiter(_this, void 0, void 0, function () {
436
+ var values, results, objItem, objValue;
437
+ var _this = this;
438
+ return __generator(this, function (_f) {
439
+ switch (_f.label) {
440
+ case 0:
441
+ if (!(value === null || value === void 0 ? void 0 : value.toString())) {
442
+ return [2 /*return*/, []];
443
+ }
444
+ values = Array.isArray(value) ? value : [value];
445
+ if (!this.valueField && !this.displayField) {
446
+ return [2 /*return*/, values];
447
+ }
448
+ this.loading = true;
449
+ if (!values.some(function (val) { return __classPrivateFieldGet(_this, _allItem)[val] === undefined; })) return [3 /*break*/, 2];
450
+ return [4 /*yield*/, items(value, true).catch(function () { return []; }).finally(function () { return _this.loading = false; })];
451
+ case 1:
452
+ results = _f.sent();
453
+ objItem = Array.toObject(results, this.valueField);
454
+ objValue = Array.toObject(values.map(function (val) {
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);
457
+ }), this.valueField);
458
+ __classPrivateFieldSet(this, _allItem, Object.assign(Object.assign(Object.assign({}, objValue), __classPrivateFieldGet(this, _allItem)), objItem));
459
+ _f.label = 2;
460
+ case 2: return [2 /*return*/, values.map(function (val) {
461
+ var _f;
462
+ var _a;
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);
464
+ })];
465
+ }
466
+ });
467
+ }); });
405
468
  this.onAdd = function (event) {
406
- var _a, _b;
469
+ var _a, _b, _c, _d, _e;
407
470
  // Add item only when MatAutocomplete is not open
408
471
  // To make sure this does not conflict with OptionSelected Event
409
- if (!_this.matAutocomplete.isOpen) {
410
- var value_1 = ((_a = event.value) !== null && _a !== void 0 ? _a : '').toString().toLowerCase().trim();
411
- if (value_1) {
412
- var item = __classPrivateFieldGet(_this, _items).find(function (e) { return e[_this.displayField]
413
- && 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; });
414
507
  if (item) {
415
508
  var values = (_b = _this.formControl.value) !== null && _b !== void 0 ? _b : [];
416
509
  values.push(item[_this.valueField]);
417
510
  _this.formControl.setValue(values);
418
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
+ }
419
530
  }
420
- _this.inputControl.setValue('');
421
531
  }
532
+ _this.input.nativeElement.value = '';
533
+ _this.inputControl.setValue('');
422
534
  };
423
535
  // andn1 viết để xử lý tạm us B2B1D-18289 ở S69
424
536
  this.onAdd2 = function (event) {
425
537
  var _a, _b;
426
538
  var value = ((_a = event.value) !== null && _a !== void 0 ? _a : '').toString().toLowerCase().trim();
427
539
  if (value) {
428
- 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]
429
541
  && e[_this.valueField].toString().toLowerCase().trim() === value; });
430
542
  if (item) {
431
543
  var values = (_b = _this.formControl.value) !== null && _b !== void 0 ? _b : [];
@@ -436,56 +548,92 @@
436
548
  }
437
549
  }
438
550
  _this.inputControl.setValue('');
439
- _this.ref.detectChanges();
440
551
  };
441
552
  this.onRemove = function (item) {
442
553
  var _a;
443
554
  var values = (_a = _this.formControl.value) !== null && _a !== void 0 ? _a : [];
444
- _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
+ }
445
561
  _this.inputControl.setValue('');
446
562
  };
447
563
  this.select = function (item) {
448
564
  _this.chipSelected.emit(item);
449
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
+ // }
450
583
  this.onSelect = function (event) {
451
- var _a, _b, _c;
452
- var value = ((_b = (_a = event.option.value) === null || _a === void 0 ? void 0 : _a[_this.valueField]) !== null && _b !== void 0 ? _b : '').toString().trim();
453
- if (value) {
454
- var item = __classPrivateFieldGet(_this, _items).find(function (e) { return e[_this.valueField]
455
- && e[_this.valueField].toString().trim() === value; });
456
- if (item) {
457
- var values = (_c = _this.formControl.value) !== null && _c !== void 0 ? _c : [];
458
- values.push(item[_this.valueField]);
459
- _this.formControl.setValue(values);
460
- _this.input.nativeElement.value = '';
461
- _this.inputControl.setValue('');
462
- setTimeout(function () {
463
- var _a;
464
- (_a = _this.autocompleteTrigger) === null || _a === void 0 ? void 0 : _a.openPanel();
465
- }, 0);
466
- }
467
- }
468
- };
469
- this.displayFn = function (value) {
470
- if (typeof value === 'string') {
471
- if (!__classPrivateFieldGet(_this, _items)) {
472
- return undefined;
473
- }
474
- var selectedItem = __classPrivateFieldGet(_this, _items).find(function (item) { return item[_this.valueField] === value; });
475
- if (selectedItem) {
476
- return selectedItem[_this.displayField];
477
- }
478
- if (__classPrivateFieldGet(_this, _items).some(function (item) { return item[_this.displayField].toLowerCase().indexOf(value.toLowerCase()) !== -1; })) {
479
- 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
+ }
480
599
  }
481
- else {
482
- 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
+ }
483
612
  }
484
- }
485
- else {
486
- return value ? value[_this.displayField] : undefined;
613
+ _this.input.nativeElement.value = '';
614
+ _this.inputControl.setValue('', {
615
+ emitEvent: false
616
+ });
487
617
  }
488
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
+ // }
489
637
  this.onFocus = function () {
490
638
  _this.isFocused = true;
491
639
  _this.inputControl.setValue('');
@@ -545,6 +693,13 @@
545
693
  enumerable: false,
546
694
  configurable: true
547
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
+ });
548
703
  Object.defineProperty(SdChip.prototype, "_removable", {
549
704
  set: function (val) {
550
705
  this.removable = (val === '') || val;
@@ -554,17 +709,18 @@
554
709
  });
555
710
  Object.defineProperty(SdChip.prototype, "items", {
556
711
  set: function (items) {
712
+ __classPrivateFieldSet(this, _delay, 0);
557
713
  if (!items) {
558
- __classPrivateFieldSet(this, _items, []);
714
+ __classPrivateFieldGet(this, _itemsChanges).next([]);
559
715
  }
560
716
  else if (Array.isArray(items)) {
561
- __classPrivateFieldSet(this, _items, items.filter(function (e) { return (e !== null && e !== void 0 ? e : '').toString().trim() !== ''; }));
717
+ __classPrivateFieldGet(this, _itemsChanges).next(items.filter(function (e) { return e !== null && e !== undefined; }));
562
718
  }
563
719
  else {
564
- __classPrivateFieldSet(this, _items, items);
720
+ __classPrivateFieldSet(this, _delay, 500);
721
+ __classPrivateFieldGet(this, _itemsChanges).next(items);
565
722
  }
566
- this.inputControl.updateValueAndValidity();
567
- __classPrivateFieldGet(this, _itemChanges).next(this.items);
723
+ this.formControl.updateValueAndValidity();
568
724
  },
569
725
  enumerable: false,
570
726
  configurable: true
@@ -575,9 +731,7 @@
575
731
  if (!Array.isArray(values)) {
576
732
  values = [];
577
733
  }
578
- this.formControl.setValue(values, {
579
- emitEvent: false
580
- });
734
+ this.formControl.setValue(values);
581
735
  },
582
736
  enumerable: false,
583
737
  configurable: true
@@ -623,45 +777,107 @@
623
777
  configurable: true
624
778
  });
625
779
  SdChip.prototype.ngOnInit = function () {
626
- var _this = this;
627
- 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); }));
628
780
  };
629
781
  SdChip.prototype.ngAfterViewInit = function () {
630
782
  var _this = this;
631
783
  var _a;
632
- __classPrivateFieldGet(this, _subscription).add(this.formControl.valueChanges.subscribe(function () {
633
- var values = _this.formControl.value || [];
634
- _this.selectedItems = __classPrivateFieldGet(_this, _items).filter(function (item) { return values.findIndex(function (value) { return value === (item === null || item === void 0 ? void 0 : item[_this.valueField]); }) !== -1; });
635
- _this.modelChange.emit(values);
636
- _this.sdChange.emit(values);
637
- setTimeout(function () {
638
- var _a;
639
- (_a = __classPrivateFieldGet(_this, _form)) === null || _a === void 0 ? void 0 : _a.markAsDirty();
640
- }, 0);
784
+ __classPrivateFieldGet(this, _subscription).add(this.formControl.sdChanges.subscribe(function () {
785
+ _this.ref.markForCheck();
641
786
  }));
642
- __classPrivateFieldGet(this, _subscription).add(__classPrivateFieldGet(this, _itemChanges).pipe(operators.startWith(__classPrivateFieldGet(this, _items))).subscribe(function () {
643
- var e_1, _d;
787
+ __classPrivateFieldSet(this, _allItems, rxjs.combineLatest([
788
+ __classPrivateFieldGet(this, _itemsChanges).asObservable(),
789
+ this.inputControl.valueChanges.pipe(operators.startWith(''), operators.debounceTime(__classPrivateFieldGet(this, _delay))),
790
+ this.formControl.valueChanges.pipe(operators.startWith(this.formControl.value))
791
+ ]).pipe(operators.switchMap(function (_f) {
792
+ var _g = __read(_f, 1), items = _g[0];
793
+ return __awaiter(_this, void 0, void 0, function () {
794
+ var val, values, hasFields;
795
+ var _this = this;
796
+ return __generator(this, function (_f) {
797
+ switch (_f.label) {
798
+ case 0:
799
+ val = this.inputControl.value;
800
+ values = this.formControl.value || [];
801
+ if (!(typeof (items) === 'function')) return [3 /*break*/, 2];
802
+ return [4 /*yield*/, __classPrivateFieldGet(this, _loadItems).call(this, val, items)];
803
+ case 1: return [2 /*return*/, _f.sent()];
804
+ case 2:
805
+ __classPrivateFieldSet(this, _allItem, items.toObject(this.valueField));
806
+ hasFields = !!this.valueField && !!this.displayField;
807
+ __classPrivateFieldSet(this, _filteredItems, items.filter(function (item) {
808
+ var value = hasFields ? item[_this.valueField] : item;
809
+ var display = hasFields ? item[_this.displayField] : item;
810
+ if (String.aliasIncludes(value, val) || String.aliasIncludes(display, val)) {
811
+ return true;
812
+ }
813
+ return values.some(function (e) { return e === value; });
814
+ }));
815
+ return [2 /*return*/, __classPrivateFieldGet(this, _filteredItems)];
816
+ }
817
+ });
818
+ });
819
+ })));
820
+ this.selectedItems = rxjs.combineLatest([
821
+ __classPrivateFieldGet(this, _itemsChanges).asObservable(),
822
+ this.formControl.valueChanges.pipe(operators.startWith(this.formControl.value))
823
+ ])
824
+ .pipe(operators.switchMap(function (_f) {
825
+ var _g = __read(_f, 2), items = _g[0], val = _g[1];
826
+ return __awaiter(_this, void 0, void 0, function () {
827
+ var _b;
828
+ var _this = this;
829
+ return __generator(this, function (_f) {
830
+ switch (_f.label) {
831
+ case 0:
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
833
+ // Nhưng formControl.value vẫn có giá trị đúng nên thực hiện gán val = this.formControl.value;
834
+ val = this.formControl.value;
835
+ if (!this.valueField) {
836
+ return [2 /*return*/, this.formControl.value];
837
+ }
838
+ if (!(typeof (items) === 'function')) return [3 /*break*/, 2];
839
+ return [4 /*yield*/, __classPrivateFieldGet(this, _loadSelectedItems).call(this, val, items)];
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);
847
+ })];
848
+ }
849
+ });
850
+ });
851
+ }));
852
+ this.filteredItems = __classPrivateFieldGet(this, _allItems).pipe(operators.map(function (allItems) { return allItems.filter(function (item) {
644
853
  var values = _this.formControl.value || [];
645
- _this.selectedItems = [];
646
- var _loop_1 = function (value) {
647
- var _d;
648
- var item = __classPrivateFieldGet(_this, _items).find(function (e) { return (e === null || e === void 0 ? void 0 : e[_this.valueField]) === value; }) || {};
649
- _this.selectedItems.push(Object.assign(Object.assign({}, item), (_d = {}, _d[_this.valueField] = value, _d)));
650
- };
651
- try {
652
- for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
653
- var value = values_1_1.value;
654
- _loop_1(value);
655
- }
854
+ if (_this.valueField) {
855
+ return !values.includes(item === null || item === void 0 ? void 0 : item[_this.valueField]);
656
856
  }
657
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
658
- finally {
659
- try {
660
- if (values_1_1 && !values_1_1.done && (_d = values_1.return)) _d.call(values_1);
661
- }
662
- finally { if (e_1) throw e_1.error; }
663
- }
664
- }));
857
+ return !values.includes(item);
858
+ }).paging(_this.limit); }));
859
+ // this.display = this.selectedItems.pipe(
860
+ // map(selectedItems => selectedItems?.map(item => this.displayField ? item[this.displayField] : item)?.join(', ')));
861
+ // this.#subscription.add(this.formControl.valueChanges.subscribe(() => {
862
+ // const values: (string | number)[] = this.formControl.value || [];
863
+ // this.selectedItems = this.#items.filter(item => values.findIndex(value => value === item?.[this.valueField]) !== -1);
864
+ // this.modelChange.emit(values);
865
+ // this.sdChange.emit(values);
866
+ // setTimeout(() => {
867
+ // this.#form?.markAsDirty();
868
+ // }, 0);
869
+ // }));
870
+ // this.#subscription.add(this.#itemChanges.pipe(startWith(this.#items)).subscribe(() => {
871
+ // const values: (string | number)[] = this.formControl.value || [];
872
+ // this.selectedItems = [];
873
+ // for (const value of values) {
874
+ // const item = this.#items.find(e => e?.[this.valueField] === value) || {};
875
+ // this.selectedItems.push({
876
+ // ...item,
877
+ // [this.valueField]: value
878
+ // });
879
+ // }
880
+ // }));
665
881
  (_a = __classPrivateFieldGet(this, _form)) === null || _a === void 0 ? void 0 : _a.addControl(__classPrivateFieldGet(this, _name), this.formControl);
666
882
  };
667
883
  SdChip.prototype.ngOnDestroy = function () {
@@ -671,22 +887,23 @@
671
887
  };
672
888
  return SdChip;
673
889
  }());
674
- _name = new WeakMap(), _form = new WeakMap(), _itemChanges = new WeakMap(), _items = new WeakMap(), _subscription = new WeakMap(), _updateValidator = 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();
675
891
  SdChip.decorators = [
676
892
  { type: core.Component, args: [{
677
893
  selector: 'sd-chip',
678
- 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,
679
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}"]
680
897
  },] }
681
898
  ];
682
899
  SdChip.ctorParameters = function () { return [
683
- { type: core.ChangeDetectorRef },
684
- { type: utility.SdUtilityService }
900
+ { type: core.ChangeDetectorRef }
685
901
  ]; };
686
902
  SdChip.propDecorators = {
687
903
  name: [{ type: core.Input }],
688
904
  size: [{ type: core.Input }],
689
905
  form: [{ type: core.Input }],
906
+ addable: [{ type: core.Input }],
690
907
  label: [{ type: core.Input }],
691
908
  valueField: [{ type: core.Input }],
692
909
  displayField: [{ type: core.Input }],