@sd-angular/core 1.0.80 → 1.0.83
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/bundles/sd-angular-core-chip.umd.js +228 -133
- package/bundles/sd-angular-core-chip.umd.js.map +1 -1
- package/bundles/sd-angular-core-chip.umd.min.js +2 -2
- package/bundles/sd-angular-core-chip.umd.min.js.map +1 -1
- package/bundles/sd-angular-core-input.umd.js +1 -1
- package/bundles/sd-angular-core-input.umd.js.map +1 -1
- package/bundles/sd-angular-core-input.umd.min.js +1 -1
- package/bundles/sd-angular-core-input.umd.min.js.map +1 -1
- package/bundles/sd-angular-core-select.umd.js +1 -0
- package/bundles/sd-angular-core-select.umd.js.map +1 -1
- package/bundles/sd-angular-core-select.umd.min.js +1 -1
- package/bundles/sd-angular-core-select.umd.min.js.map +1 -1
- package/chip/sd-angular-core-chip.metadata.json +1 -1
- package/chip/src/lib/chip.component.d.ts +5 -9
- package/esm2015/chip/src/lib/chip.component.js +188 -104
- package/esm2015/input/src/lib/input.component.js +2 -2
- package/esm2015/select/src/lib/select.component.js +2 -1
- package/fesm2015/sd-angular-core-chip.js +188 -104
- package/fesm2015/sd-angular-core-chip.js.map +1 -1
- package/fesm2015/sd-angular-core-input.js +1 -1
- package/fesm2015/sd-angular-core-input.js.map +1 -1
- package/fesm2015/sd-angular-core-select.js +1 -0
- package/fesm2015/sd-angular-core-select.js.map +1 -1
- package/input/sd-angular-core-input.metadata.json +1 -1
- package/package.json +1 -1
- package/{sd-angular-core-1.0.80.tgz → sd-angular-core-1.0.83.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('@
|
|
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', '@
|
|
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
|
|
5
|
-
}(this, (function (exports, core, common$1, icon, tooltip, progressSpinner, keycodes, operators, uuid, forms, rxjs,
|
|
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,
|
|
340
|
+
var _name, _form, _addable, _allItems, _allItem, _cache, _delay, _itemsChanges, _selectedItems, _filteredItems, _subscription, _updateValidator, _loadItems, _loadSelectedItems;
|
|
341
341
|
var SdChipErrotStateMatcher = /** @class */ (function () {
|
|
342
342
|
function SdChipErrotStateMatcher(formControl) {
|
|
343
343
|
this.formControl = formControl;
|
|
@@ -350,17 +350,16 @@
|
|
|
350
350
|
return SdChipErrotStateMatcher;
|
|
351
351
|
}());
|
|
352
352
|
var SdChip = /** @class */ (function () {
|
|
353
|
-
function SdChip(ref
|
|
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
|
-
|
|
363
|
-
_items.set(this, []);
|
|
362
|
+
this.disableErrorMessage = false;
|
|
364
363
|
// @Input() set items(items: undefined | any[]) {
|
|
365
364
|
// if (!items) {
|
|
366
365
|
// this.#items = [];
|
|
@@ -380,6 +379,8 @@
|
|
|
380
379
|
_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
380
|
_itemsChanges.set(this, new rxjs.BehaviorSubject([]));
|
|
382
381
|
this.limit = 50;
|
|
382
|
+
_selectedItems.set(this, []);
|
|
383
|
+
_filteredItems.set(this, void 0);
|
|
383
384
|
// Validator
|
|
384
385
|
this.isRequired = false;
|
|
385
386
|
this.modelChange = new core.EventEmitter();
|
|
@@ -412,22 +413,22 @@
|
|
|
412
413
|
_loadItems.set(this, function (searchText, items) { return __awaiter(_this, void 0, void 0, function () {
|
|
413
414
|
var results, objItem, selectedItems;
|
|
414
415
|
var _this = this;
|
|
415
|
-
return __generator(this, function (
|
|
416
|
-
switch (
|
|
416
|
+
return __generator(this, function (_f) {
|
|
417
|
+
switch (_f.label) {
|
|
417
418
|
case 0:
|
|
418
419
|
searchText = (searchText === null || searchText === void 0 ? void 0 : searchText.toString()) || '';
|
|
419
420
|
if (!(__classPrivateFieldGet(this, _cache)[searchText] === undefined)) return [3 /*break*/, 2];
|
|
420
421
|
this.loading = true;
|
|
421
422
|
return [4 /*yield*/, items(searchText).catch(function () { return []; }).finally(function () { return _this.loading = false; })];
|
|
422
423
|
case 1:
|
|
423
|
-
results =
|
|
424
|
+
results = _f.sent();
|
|
424
425
|
objItem = Array.toObject(results, this.valueField);
|
|
425
426
|
__classPrivateFieldSet(this, _allItem, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _allItem)), objItem));
|
|
426
427
|
__classPrivateFieldGet(this, _cache)[searchText] = results.union(this.valueField);
|
|
427
|
-
|
|
428
|
+
_f.label = 2;
|
|
428
429
|
case 2: return [4 /*yield*/, __classPrivateFieldGet(this, _loadSelectedItems).call(this, this.formControl.value, items)];
|
|
429
430
|
case 3:
|
|
430
|
-
selectedItems =
|
|
431
|
+
selectedItems = _f.sent();
|
|
431
432
|
// Đưa những selectedItems lên đầu nếu không mat-select-trigger sẽ không work
|
|
432
433
|
return [2 /*return*/, __spread(selectedItems, __classPrivateFieldGet(this, _cache)[searchText]).union(this.valueField)];
|
|
433
434
|
}
|
|
@@ -436,8 +437,8 @@
|
|
|
436
437
|
_loadSelectedItems.set(this, function (value, items) { return __awaiter(_this, void 0, void 0, function () {
|
|
437
438
|
var values, results, objItem, objValue;
|
|
438
439
|
var _this = this;
|
|
439
|
-
return __generator(this, function (
|
|
440
|
-
switch (
|
|
440
|
+
return __generator(this, function (_f) {
|
|
441
|
+
switch (_f.label) {
|
|
441
442
|
case 0:
|
|
442
443
|
if (!(value === null || value === void 0 ? void 0 : value.toString())) {
|
|
443
444
|
return [2 /*return*/, []];
|
|
@@ -450,56 +451,103 @@
|
|
|
450
451
|
if (!values.some(function (val) { return __classPrivateFieldGet(_this, _allItem)[val] === undefined; })) return [3 /*break*/, 2];
|
|
451
452
|
return [4 /*yield*/, items(value, true).catch(function () { return []; }).finally(function () { return _this.loading = false; })];
|
|
452
453
|
case 1:
|
|
453
|
-
results =
|
|
454
|
+
results = _f.sent();
|
|
454
455
|
objItem = Array.toObject(results, this.valueField);
|
|
455
456
|
objValue = Array.toObject(values.map(function (val) {
|
|
456
|
-
var
|
|
457
|
-
return (
|
|
457
|
+
var _f, _g;
|
|
458
|
+
return (_f = {}, _f[val === null || val === void 0 ? void 0 : val.toString()] = (_g = {}, _g[_this.valueField] = val, _g[_this.displayField] = val, _g), _f);
|
|
458
459
|
}), this.valueField);
|
|
459
460
|
__classPrivateFieldSet(this, _allItem, Object.assign(Object.assign(Object.assign({}, objValue), __classPrivateFieldGet(this, _allItem)), objItem));
|
|
460
|
-
|
|
461
|
+
_f.label = 2;
|
|
461
462
|
case 2: return [2 /*return*/, values.map(function (val) {
|
|
462
|
-
var
|
|
463
|
+
var _f;
|
|
463
464
|
var _a;
|
|
464
|
-
return (_a = __classPrivateFieldGet(_this, _allItem)[val === null || val === void 0 ? void 0 : val.toString()]) !== null && _a !== void 0 ? _a : (
|
|
465
|
+
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
466
|
})];
|
|
466
467
|
}
|
|
467
468
|
});
|
|
468
469
|
}); });
|
|
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
470
|
this.onAdd = function (event) {
|
|
480
|
-
var _a, _b;
|
|
471
|
+
var _a, _b, _c, _d, _e;
|
|
481
472
|
// Add item only when MatAutocomplete is not open
|
|
482
473
|
// To make sure this does not conflict with OptionSelected Event
|
|
483
|
-
if (!
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
474
|
+
// if (!this.matAutocomplete.isOpen) {
|
|
475
|
+
// const value = (event.value ?? '').toString().trim();
|
|
476
|
+
// if (value) {
|
|
477
|
+
// if (this.valueField && this.displayField) {
|
|
478
|
+
// const item = this.#filteredItems.find(e => e[this.displayField] === value);
|
|
479
|
+
// if (item) {
|
|
480
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
481
|
+
// values.push(item[this.valueField]);
|
|
482
|
+
// this.formControl.setValue(values);
|
|
483
|
+
// } else if (this.#addable) {
|
|
484
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
485
|
+
// values.push(value);
|
|
486
|
+
// this.formControl.setValue(values);
|
|
487
|
+
// }
|
|
488
|
+
// } else {
|
|
489
|
+
// console.log(value);
|
|
490
|
+
// console.log(this.#filteredItems);
|
|
491
|
+
// const item = this.#filteredItems.find(item => item === value);
|
|
492
|
+
// if (item) {
|
|
493
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
494
|
+
// values.push(item);
|
|
495
|
+
// this.formControl.setValue(values);
|
|
496
|
+
// } else if (this.#addable) {
|
|
497
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
498
|
+
// values.push(value);
|
|
499
|
+
// this.formControl.setValue(values);
|
|
500
|
+
// }
|
|
501
|
+
// }
|
|
502
|
+
// }
|
|
503
|
+
// this.inputControl.setValue('');
|
|
504
|
+
// }
|
|
505
|
+
var value = ((_a = event.value) !== null && _a !== void 0 ? _a : '').toString().trim();
|
|
506
|
+
if (value) {
|
|
507
|
+
if (_this.valueField && _this.displayField) {
|
|
508
|
+
var item = __classPrivateFieldGet(_this, _filteredItems).find(function (e) { return e[_this.displayField] === value; });
|
|
488
509
|
if (item) {
|
|
489
510
|
var values = (_b = _this.formControl.value) !== null && _b !== void 0 ? _b : [];
|
|
490
511
|
values.push(item[_this.valueField]);
|
|
491
512
|
_this.formControl.setValue(values);
|
|
513
|
+
_this.modelChange.emit(_this.formControl.value);
|
|
514
|
+
_this.sdChange.emit(_this.formControl.value);
|
|
515
|
+
}
|
|
516
|
+
else if (__classPrivateFieldGet(_this, _addable)) {
|
|
517
|
+
var values = (_c = _this.formControl.value) !== null && _c !== void 0 ? _c : [];
|
|
518
|
+
values.push(value);
|
|
519
|
+
_this.formControl.setValue(values);
|
|
520
|
+
_this.modelChange.emit(_this.formControl.value);
|
|
521
|
+
_this.sdChange.emit(_this.formControl.value);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
var item = __classPrivateFieldGet(_this, _filteredItems).find(function (item) { return item === value; });
|
|
526
|
+
if (item) {
|
|
527
|
+
var values = (_d = _this.formControl.value) !== null && _d !== void 0 ? _d : [];
|
|
528
|
+
values.push(item);
|
|
529
|
+
_this.formControl.setValue(values);
|
|
530
|
+
_this.modelChange.emit(_this.formControl.value);
|
|
531
|
+
_this.sdChange.emit(_this.formControl.value);
|
|
532
|
+
}
|
|
533
|
+
else if (__classPrivateFieldGet(_this, _addable)) {
|
|
534
|
+
var values = (_e = _this.formControl.value) !== null && _e !== void 0 ? _e : [];
|
|
535
|
+
values.push(value);
|
|
536
|
+
_this.formControl.setValue(values);
|
|
537
|
+
_this.modelChange.emit(_this.formControl.value);
|
|
538
|
+
_this.sdChange.emit(_this.formControl.value);
|
|
492
539
|
}
|
|
493
540
|
}
|
|
494
|
-
_this.inputControl.setValue('');
|
|
495
541
|
}
|
|
542
|
+
_this.input.nativeElement.value = '';
|
|
543
|
+
_this.inputControl.setValue('');
|
|
496
544
|
};
|
|
497
545
|
// andn1 viết để xử lý tạm us B2B1D-18289 ở S69
|
|
498
546
|
this.onAdd2 = function (event) {
|
|
499
547
|
var _a, _b;
|
|
500
548
|
var value = ((_a = event.value) !== null && _a !== void 0 ? _a : '').toString().toLowerCase().trim();
|
|
501
549
|
if (value) {
|
|
502
|
-
var item = __classPrivateFieldGet(_this,
|
|
550
|
+
var item = __classPrivateFieldGet(_this, _filteredItems).find(function (e) { return e[_this.valueField]
|
|
503
551
|
&& e[_this.valueField].toString().toLowerCase().trim() === value; });
|
|
504
552
|
if (item) {
|
|
505
553
|
var values = (_b = _this.formControl.value) !== null && _b !== void 0 ? _b : [];
|
|
@@ -510,56 +558,96 @@
|
|
|
510
558
|
}
|
|
511
559
|
}
|
|
512
560
|
_this.inputControl.setValue('');
|
|
513
|
-
_this.ref.detectChanges();
|
|
514
561
|
};
|
|
515
562
|
this.onRemove = function (item) {
|
|
516
563
|
var _a;
|
|
517
564
|
var values = (_a = _this.formControl.value) !== null && _a !== void 0 ? _a : [];
|
|
518
|
-
|
|
565
|
+
if (typeof (item) === 'string' || typeof (item) === 'number') {
|
|
566
|
+
_this.formControl.setValue(values.filter(function (value) { return item !== value; }));
|
|
567
|
+
_this.modelChange.emit(_this.formControl.value);
|
|
568
|
+
_this.sdChange.emit(_this.formControl.value);
|
|
569
|
+
}
|
|
570
|
+
else if (_this.valueField) {
|
|
571
|
+
_this.formControl.setValue(values.filter(function (value) { return (item === null || item === void 0 ? void 0 : item[_this.valueField]) !== value; }));
|
|
572
|
+
_this.modelChange.emit(_this.formControl.value);
|
|
573
|
+
_this.sdChange.emit(_this.formControl.value);
|
|
574
|
+
}
|
|
519
575
|
_this.inputControl.setValue('');
|
|
520
576
|
};
|
|
521
577
|
this.select = function (item) {
|
|
522
578
|
_this.chipSelected.emit(item);
|
|
523
579
|
};
|
|
580
|
+
// onSelect = (event: MatAutocompleteSelectedEvent) => {
|
|
581
|
+
// const value = (event.option.value?.[this.valueField] ?? '').toString().trim();
|
|
582
|
+
// if (value) {
|
|
583
|
+
// const item = this.#items.find(e => e[this.valueField]
|
|
584
|
+
// && e[this.valueField].toString().trim() === value);
|
|
585
|
+
// if (item) {
|
|
586
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
587
|
+
// values.push(item[this.valueField]);
|
|
588
|
+
// this.formControl.setValue(values);
|
|
589
|
+
// this.input.nativeElement.value = '';
|
|
590
|
+
// this.inputControl.setValue('');
|
|
591
|
+
// setTimeout(() => {
|
|
592
|
+
// this.autocompleteTrigger?.openPanel();
|
|
593
|
+
// }, 0);
|
|
594
|
+
// }
|
|
595
|
+
// }
|
|
596
|
+
// }
|
|
524
597
|
this.onSelect = function (event) {
|
|
525
|
-
var _a
|
|
526
|
-
var
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}
|
|
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;
|
|
598
|
+
var _a;
|
|
599
|
+
var item = event.option.value;
|
|
600
|
+
var values = (_a = _this.formControl.value) !== null && _a !== void 0 ? _a : [];
|
|
601
|
+
if (item) {
|
|
602
|
+
if (typeof (item) === 'string' || typeof (item) === 'number') {
|
|
603
|
+
if (!values.includes(item)) {
|
|
604
|
+
values.push(item);
|
|
605
|
+
_this.formControl.setValue(values);
|
|
606
|
+
_this.modelChange.emit(_this.formControl.value);
|
|
607
|
+
_this.sdChange.emit(_this.formControl.value);
|
|
608
|
+
setTimeout(function () {
|
|
609
|
+
var _a;
|
|
610
|
+
(_a = _this.autocompleteTrigger) === null || _a === void 0 ? void 0 : _a.openPanel();
|
|
611
|
+
}, 0);
|
|
612
|
+
}
|
|
554
613
|
}
|
|
555
|
-
else {
|
|
556
|
-
|
|
614
|
+
else if (_this.valueField) {
|
|
615
|
+
var val = (item === null || item === void 0 ? void 0 : item[_this.valueField]) || null;
|
|
616
|
+
if (!values.includes(val)) {
|
|
617
|
+
values.push(val);
|
|
618
|
+
_this.formControl.setValue(values);
|
|
619
|
+
_this.modelChange.emit(_this.formControl.value);
|
|
620
|
+
_this.sdChange.emit(_this.formControl.value);
|
|
621
|
+
setTimeout(function () {
|
|
622
|
+
var _a;
|
|
623
|
+
(_a = _this.autocompleteTrigger) === null || _a === void 0 ? void 0 : _a.openPanel();
|
|
624
|
+
}, 0);
|
|
625
|
+
}
|
|
557
626
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
627
|
+
_this.input.nativeElement.value = '';
|
|
628
|
+
_this.inputControl.setValue('', {
|
|
629
|
+
emitEvent: false
|
|
630
|
+
});
|
|
561
631
|
}
|
|
562
632
|
};
|
|
633
|
+
// displayFn = (value: string | { [key: string]: string }): string | undefined => {
|
|
634
|
+
// if (typeof value === 'string') {
|
|
635
|
+
// if (!this.#items) {
|
|
636
|
+
// return undefined;
|
|
637
|
+
// }
|
|
638
|
+
// const selectedItem = this.#items.find(item => item[this.valueField] === value);
|
|
639
|
+
// if (selectedItem) {
|
|
640
|
+
// return selectedItem[this.displayField];
|
|
641
|
+
// }
|
|
642
|
+
// if (this.#items.some(item => item[this.displayField].toLowerCase().indexOf(value.toLowerCase()) !== -1)) {
|
|
643
|
+
// return value;
|
|
644
|
+
// } else {
|
|
645
|
+
// return undefined;
|
|
646
|
+
// }
|
|
647
|
+
// } else {
|
|
648
|
+
// return value ? value[this.displayField] : undefined;
|
|
649
|
+
// }
|
|
650
|
+
// }
|
|
563
651
|
this.onFocus = function () {
|
|
564
652
|
_this.isFocused = true;
|
|
565
653
|
_this.inputControl.setValue('');
|
|
@@ -592,9 +680,12 @@
|
|
|
592
680
|
$event === null || $event === void 0 ? void 0 : $event.stopPropagation();
|
|
593
681
|
_this.inputControl.setValue('');
|
|
594
682
|
_this.formControl.setValue([]);
|
|
683
|
+
_this.modelChange.emit(_this.formControl.value);
|
|
684
|
+
_this.sdChange.emit(_this.formControl.value);
|
|
595
685
|
(_a = _this.autocompleteTrigger) === null || _a === void 0 ? void 0 : _a.openPanel();
|
|
596
686
|
_this.ref.detectChanges();
|
|
597
687
|
};
|
|
688
|
+
this.getSelectedItems = function () { return __classPrivateFieldGet(_this, _selectedItems); };
|
|
598
689
|
}
|
|
599
690
|
Object.defineProperty(SdChip.prototype, "name", {
|
|
600
691
|
set: function (val) {
|
|
@@ -619,6 +710,13 @@
|
|
|
619
710
|
enumerable: false,
|
|
620
711
|
configurable: true
|
|
621
712
|
});
|
|
713
|
+
Object.defineProperty(SdChip.prototype, "addable", {
|
|
714
|
+
set: function (val) {
|
|
715
|
+
__classPrivateFieldSet(this, _addable, (val === '') || val);
|
|
716
|
+
},
|
|
717
|
+
enumerable: false,
|
|
718
|
+
configurable: true
|
|
719
|
+
});
|
|
622
720
|
Object.defineProperty(SdChip.prototype, "_removable", {
|
|
623
721
|
set: function (val) {
|
|
624
722
|
this.removable = (val === '') || val;
|
|
@@ -626,6 +724,13 @@
|
|
|
626
724
|
enumerable: false,
|
|
627
725
|
configurable: true
|
|
628
726
|
});
|
|
727
|
+
Object.defineProperty(SdChip.prototype, "_disableErrorMessage", {
|
|
728
|
+
set: function (val) {
|
|
729
|
+
this.disableErrorMessage = (val === '') || val;
|
|
730
|
+
},
|
|
731
|
+
enumerable: false,
|
|
732
|
+
configurable: true
|
|
733
|
+
});
|
|
629
734
|
Object.defineProperty(SdChip.prototype, "items", {
|
|
630
735
|
set: function (items) {
|
|
631
736
|
__classPrivateFieldSet(this, _delay, 0);
|
|
@@ -696,8 +801,6 @@
|
|
|
696
801
|
configurable: true
|
|
697
802
|
});
|
|
698
803
|
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
804
|
};
|
|
702
805
|
SdChip.prototype.ngAfterViewInit = function () {
|
|
703
806
|
var _this = this;
|
|
@@ -709,50 +812,31 @@
|
|
|
709
812
|
__classPrivateFieldGet(this, _itemsChanges).asObservable(),
|
|
710
813
|
this.inputControl.valueChanges.pipe(operators.startWith(''), operators.debounceTime(__classPrivateFieldGet(this, _delay))),
|
|
711
814
|
this.formControl.valueChanges.pipe(operators.startWith(this.formControl.value))
|
|
712
|
-
]).pipe(operators.switchMap(function (
|
|
713
|
-
var
|
|
815
|
+
]).pipe(operators.switchMap(function (_f) {
|
|
816
|
+
var _g = __read(_f, 1), items = _g[0];
|
|
714
817
|
return __awaiter(_this, void 0, void 0, function () {
|
|
715
|
-
var
|
|
818
|
+
var val, values, hasFields;
|
|
716
819
|
var _this = this;
|
|
717
|
-
return __generator(this, function (
|
|
718
|
-
switch (
|
|
820
|
+
return __generator(this, function (_f) {
|
|
821
|
+
switch (_f.label) {
|
|
719
822
|
case 0:
|
|
823
|
+
val = this.inputControl.value;
|
|
824
|
+
values = this.formControl.value || [];
|
|
720
825
|
if (!(typeof (items) === 'function')) return [3 /*break*/, 2];
|
|
721
826
|
return [4 /*yield*/, __classPrivateFieldGet(this, _loadItems).call(this, val, items)];
|
|
722
|
-
case 1: return [2 /*return*/,
|
|
827
|
+
case 1: return [2 /*return*/, _f.sent()];
|
|
723
828
|
case 2:
|
|
724
829
|
__classPrivateFieldSet(this, _allItem, items.toObject(this.valueField));
|
|
725
|
-
isArray = Array.isArray(formValue);
|
|
726
830
|
hasFields = !!this.valueField && !!this.displayField;
|
|
727
|
-
|
|
831
|
+
__classPrivateFieldSet(this, _filteredItems, items.filter(function (item) {
|
|
728
832
|
var value = hasFields ? item[_this.valueField] : item;
|
|
729
833
|
var display = hasFields ? item[_this.displayField] : item;
|
|
730
834
|
if (String.aliasIncludes(value, val) || String.aliasIncludes(display, val)) {
|
|
731
835
|
return true;
|
|
732
836
|
}
|
|
733
|
-
|
|
734
|
-
|
|
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
|
-
})];
|
|
837
|
+
return values.some(function (e) { return e === value; });
|
|
838
|
+
}));
|
|
839
|
+
return [2 /*return*/, __classPrivateFieldGet(this, _filteredItems)];
|
|
756
840
|
}
|
|
757
841
|
});
|
|
758
842
|
});
|
|
@@ -761,39 +845,48 @@
|
|
|
761
845
|
__classPrivateFieldGet(this, _itemsChanges).asObservable(),
|
|
762
846
|
this.formControl.valueChanges.pipe(operators.startWith(this.formControl.value))
|
|
763
847
|
])
|
|
764
|
-
.pipe(operators.switchMap(function (
|
|
765
|
-
var
|
|
848
|
+
.pipe(operators.switchMap(function (_f) {
|
|
849
|
+
var _g = __read(_f, 2), items = _g[0], val = _g[1];
|
|
766
850
|
return __awaiter(_this, void 0, void 0, function () {
|
|
767
|
-
var
|
|
851
|
+
var _b, _f, _g;
|
|
768
852
|
var _this = this;
|
|
769
|
-
return __generator(this, function (
|
|
770
|
-
switch (
|
|
853
|
+
return __generator(this, function (_h) {
|
|
854
|
+
switch (_h.label) {
|
|
771
855
|
case 0:
|
|
772
856
|
// 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
857
|
// Nhưng formControl.value vẫn có giá trị đúng nên thực hiện gán val = this.formControl.value;
|
|
774
858
|
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
859
|
if (!this.valueField) {
|
|
780
|
-
|
|
860
|
+
__classPrivateFieldSet(this, _selectedItems, this.formControl.value);
|
|
861
|
+
return [2 /*return*/, __classPrivateFieldGet(this, _selectedItems)];
|
|
781
862
|
}
|
|
782
863
|
if (!(typeof (items) === 'function')) return [3 /*break*/, 2];
|
|
864
|
+
_f = __classPrivateFieldSet;
|
|
865
|
+
_g = [this, _selectedItems];
|
|
783
866
|
return [4 /*yield*/, __classPrivateFieldGet(this, _loadSelectedItems).call(this, val, items)];
|
|
784
|
-
case 1:
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
867
|
+
case 1:
|
|
868
|
+
_f.apply(void 0, _g.concat([_h.sent()]));
|
|
869
|
+
return [2 /*return*/, __classPrivateFieldGet(this, _selectedItems)];
|
|
870
|
+
case 2:
|
|
871
|
+
__classPrivateFieldSet(this, _selectedItems, (_b = (this.formControl.value || [])) === null || _b === void 0 ? void 0 : _b.map(function (value) {
|
|
872
|
+
var _f;
|
|
873
|
+
return (items === null || items === void 0 ? void 0 : items.find(function (item) { return item[_this.valueField] === value; })) || (_f = {},
|
|
874
|
+
_f[_this.valueField] = value,
|
|
875
|
+
_f[_this.displayField] = value,
|
|
876
|
+
_f);
|
|
877
|
+
}));
|
|
878
|
+
return [2 /*return*/, __classPrivateFieldGet(this, _selectedItems)];
|
|
792
879
|
}
|
|
793
880
|
});
|
|
794
881
|
});
|
|
795
882
|
}));
|
|
796
|
-
this.filteredItems = __classPrivateFieldGet(this, _allItems).pipe(operators.map(function (allItems) { return allItems.
|
|
883
|
+
this.filteredItems = __classPrivateFieldGet(this, _allItems).pipe(operators.map(function (allItems) { return allItems.filter(function (item) {
|
|
884
|
+
var values = _this.formControl.value || [];
|
|
885
|
+
if (_this.valueField) {
|
|
886
|
+
return !values.includes(item === null || item === void 0 ? void 0 : item[_this.valueField]);
|
|
887
|
+
}
|
|
888
|
+
return !values.includes(item);
|
|
889
|
+
}).paging(_this.limit); }));
|
|
797
890
|
// this.display = this.selectedItems.pipe(
|
|
798
891
|
// map(selectedItems => selectedItems?.map(item => this.displayField ? item[this.displayField] : item)?.join(', ')));
|
|
799
892
|
// this.#subscription.add(this.formControl.valueChanges.subscribe(() => {
|
|
@@ -825,27 +918,29 @@
|
|
|
825
918
|
};
|
|
826
919
|
return SdChip;
|
|
827
920
|
}());
|
|
828
|
-
_name = new WeakMap(), _form = new WeakMap(),
|
|
921
|
+
_name = new WeakMap(), _form = new WeakMap(), _addable = new WeakMap(), _allItems = new WeakMap(), _allItem = new WeakMap(), _cache = new WeakMap(), _delay = new WeakMap(), _itemsChanges = new WeakMap(), _selectedItems = new WeakMap(), _filteredItems = new WeakMap(), _subscription = new WeakMap(), _updateValidator = new WeakMap(), _loadItems = new WeakMap(), _loadSelectedItems = new WeakMap();
|
|
829
922
|
SdChip.decorators = [
|
|
830
923
|
{ type: core.Component, args: [{
|
|
831
924
|
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]=\"
|
|
833
|
-
|
|
925
|
+
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', 'no-padding-wrapper': disableErrorMessage}\" 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]=\"removable\" (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-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>",
|
|
926
|
+
changeDetection: core.ChangeDetectionStrategy.OnPush,
|
|
927
|
+
styles: [":host{display:block;padding-top:5px}:host ::ng-deep .mat-form-field.no-padding-wrapper .mat-form-field-wrapper{padding-bottom:0}: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
928
|
},] }
|
|
835
929
|
];
|
|
836
930
|
SdChip.ctorParameters = function () { return [
|
|
837
|
-
{ type: core.ChangeDetectorRef }
|
|
838
|
-
{ type: utility.SdUtilityService }
|
|
931
|
+
{ type: core.ChangeDetectorRef }
|
|
839
932
|
]; };
|
|
840
933
|
SdChip.propDecorators = {
|
|
841
934
|
name: [{ type: core.Input }],
|
|
842
935
|
size: [{ type: core.Input }],
|
|
843
936
|
form: [{ type: core.Input }],
|
|
937
|
+
addable: [{ type: core.Input }],
|
|
844
938
|
label: [{ type: core.Input }],
|
|
845
939
|
valueField: [{ type: core.Input }],
|
|
846
940
|
displayField: [{ type: core.Input }],
|
|
847
941
|
placeholder: [{ type: core.Input }],
|
|
848
942
|
_removable: [{ type: core.Input, args: ['removable',] }],
|
|
943
|
+
_disableErrorMessage: [{ type: core.Input, args: ['disableErrorMessage',] }],
|
|
849
944
|
items: [{ type: core.Input }],
|
|
850
945
|
limit: [{ type: core.Input }],
|
|
851
946
|
model: [{ type: core.Input }],
|