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