@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.
- package/bundles/sd-angular-core-chip.umd.js +325 -108
- 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-grid-material.umd.js +1 -1
- package/bundles/sd-angular-core-grid-material.umd.js.map +1 -1
- package/bundles/sd-angular-core-grid-material.umd.min.js +1 -1
- package/bundles/sd-angular-core-grid-material.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-loading.umd.js +367 -22
- package/bundles/sd-angular-core-loading.umd.js.map +1 -1
- package/bundles/sd-angular-core-loading.umd.min.js +15 -1
- package/bundles/sd-angular-core-loading.umd.min.js.map +1 -1
- package/bundles/sd-angular-core-radio.umd.js +39 -25
- package/bundles/sd-angular-core-radio.umd.js.map +1 -1
- package/bundles/sd-angular-core-radio.umd.min.js +2 -2
- package/bundles/sd-angular-core-radio.umd.min.js.map +1 -1
- package/bundles/sd-angular-core-select.umd.js +1 -1
- package/bundles/sd-angular-core-select.umd.js.map +1 -1
- package/bundles/sd-angular-core-select.umd.min.js +2 -2
- 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 +8 -13
- package/esm2015/chip/src/lib/chip.component.js +279 -96
- package/esm2015/grid-material/src/lib/components/desktop-cell-view/desktop-cell-view.component.js +2 -2
- package/esm2015/input/src/lib/input.component.js +2 -2
- package/esm2015/loading/src/lib/loading.service.js +49 -14
- package/esm2015/radio/src/lib/radio.component.js +39 -25
- package/esm2015/select/src/lib/select.component.js +2 -2
- package/fesm2015/sd-angular-core-chip.js +278 -95
- package/fesm2015/sd-angular-core-chip.js.map +1 -1
- package/fesm2015/sd-angular-core-grid-material.js +1 -1
- package/fesm2015/sd-angular-core-grid-material.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-loading.js +48 -13
- package/fesm2015/sd-angular-core-loading.js.map +1 -1
- package/fesm2015/sd-angular-core-radio.js +38 -25
- package/fesm2015/sd-angular-core-radio.js.map +1 -1
- package/fesm2015/sd-angular-core-select.js +1 -1
- package/fesm2015/sd-angular-core-select.js.map +1 -1
- package/grid-material/sd-angular-core-grid-material.metadata.json +1 -1
- package/input/sd-angular-core-input.metadata.json +1 -1
- package/loading/sd-angular-core-loading.metadata.json +1 -1
- package/loading/src/lib/loading.service.d.ts +5 -2
- package/package.json +1 -1
- package/radio/sd-angular-core-radio.metadata.json +1 -1
- package/radio/src/lib/radio.component.d.ts +5 -5
- package/{sd-angular-core-1.0.78.tgz → sd-angular-core-1.0.81.tgz} +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { Directive, TemplateRef, EventEmitter, Component, ChangeDetectorRef, Input, Output, ViewChild, ContentChild, Pipe, NgModule } from '@angular/core';
|
|
1
|
+
import { Directive, TemplateRef, EventEmitter, Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, Output, ViewChild, ContentChild, Pipe, NgModule } from '@angular/core';
|
|
2
2
|
import { CommonModule } from '@angular/common';
|
|
3
3
|
import { MatIconModule } from '@angular/material/icon';
|
|
4
4
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
5
5
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
6
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
|
|
6
|
+
import { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
|
|
7
7
|
import { ENTER, COMMA } from '@angular/cdk/keycodes';
|
|
8
|
-
import { startWith, map } from 'rxjs/operators';
|
|
8
|
+
import { startWith, debounceTime, switchMap, map } from 'rxjs/operators';
|
|
9
9
|
import { v4 } from 'uuid';
|
|
10
10
|
import { FormControl, Validators, NgForm, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
11
|
-
import {
|
|
12
|
-
import { SdUtilityService } from '@sd-angular/core/utility';
|
|
11
|
+
import { BehaviorSubject, Subscription, combineLatest } from 'rxjs';
|
|
13
12
|
import { MatAutocompleteTrigger, MatAutocompleteModule } from '@angular/material/autocomplete';
|
|
14
|
-
import { SdViewDefDirective, SdCommonModule } from '@sd-angular/core/common';
|
|
13
|
+
import { SdFormControl, SdViewDefDirective, SdCommonModule } from '@sd-angular/core/common';
|
|
15
14
|
import { MatInputModule } from '@angular/material/input';
|
|
16
15
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
17
16
|
import { SdTranslateModule } from '@sd-angular/core/translate';
|
|
@@ -31,7 +30,7 @@ SdChipDisplayDef.ctorParameters = () => [
|
|
|
31
30
|
{ type: TemplateRef }
|
|
32
31
|
];
|
|
33
32
|
|
|
34
|
-
var _name, _form,
|
|
33
|
+
var _name, _form, _addable, _allItems, _allItem, _cache, _delay, _itemsChanges, _filteredItems, _subscription, _updateValidator, _loadItems, _loadSelectedItems;
|
|
35
34
|
class SdChipErrotStateMatcher {
|
|
36
35
|
constructor(formControl) {
|
|
37
36
|
this.formControl = formControl;
|
|
@@ -43,18 +42,34 @@ class SdChipErrotStateMatcher {
|
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
class SdChip {
|
|
46
|
-
constructor(ref
|
|
45
|
+
constructor(ref) {
|
|
47
46
|
this.ref = ref;
|
|
48
|
-
this.utilityService = utilityService;
|
|
49
47
|
_name.set(this, v4());
|
|
50
48
|
this.separatorKeysCodes = [ENTER, COMMA];
|
|
51
49
|
this.selectable = true;
|
|
52
50
|
_form.set(this, void 0);
|
|
51
|
+
_addable.set(this, void 0);
|
|
53
52
|
this.removable = true;
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
// @Input() set items(items: undefined | any[]) {
|
|
54
|
+
// if (!items) {
|
|
55
|
+
// this.#items = [];
|
|
56
|
+
// } else if (Array.isArray(items)) {
|
|
57
|
+
// this.#items = items.filter(e => (e ?? '').toString().trim() !== '');
|
|
58
|
+
// } else {
|
|
59
|
+
// this.#items = items;
|
|
60
|
+
// }
|
|
61
|
+
// this.inputControl.updateValueAndValidity();
|
|
62
|
+
// this.#itemChanges.next(this.items);
|
|
63
|
+
// }
|
|
64
|
+
// Server search
|
|
65
|
+
this.loading = false;
|
|
66
|
+
_allItems.set(this, void 0);
|
|
67
|
+
_allItem.set(this, {});
|
|
68
|
+
_cache.set(this, {});
|
|
69
|
+
_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
|
|
70
|
+
_itemsChanges.set(this, new BehaviorSubject([]));
|
|
56
71
|
this.limit = 50;
|
|
57
|
-
this
|
|
72
|
+
_filteredItems.set(this, void 0);
|
|
58
73
|
// Validator
|
|
59
74
|
this.isRequired = false;
|
|
60
75
|
this.modelChange = new EventEmitter();
|
|
@@ -63,7 +78,7 @@ class SdChip {
|
|
|
63
78
|
this.chipSelected = new EventEmitter();
|
|
64
79
|
this.isFocused = false;
|
|
65
80
|
this.inputControl = new FormControl();
|
|
66
|
-
this.formControl = new
|
|
81
|
+
this.formControl = new SdFormControl();
|
|
67
82
|
this.matcher = new SdChipErrotStateMatcher(this.formControl);
|
|
68
83
|
_subscription.set(this, new Subscription());
|
|
69
84
|
_updateValidator.set(this, () => {
|
|
@@ -84,40 +99,112 @@ class SdChip {
|
|
|
84
99
|
this.formControl.setAsyncValidators(asyncValidators);
|
|
85
100
|
this.formControl.updateValueAndValidity();
|
|
86
101
|
});
|
|
87
|
-
this
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
102
|
+
_loadItems.set(this, (searchText, items) => __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
searchText = (searchText === null || searchText === void 0 ? void 0 : searchText.toString()) || '';
|
|
104
|
+
if (__classPrivateFieldGet(this, _cache)[searchText] === undefined) {
|
|
105
|
+
this.loading = true;
|
|
106
|
+
const results = yield items(searchText).catch(() => []).finally(() => this.loading = false);
|
|
107
|
+
const objItem = Array.toObject(results, this.valueField);
|
|
108
|
+
__classPrivateFieldSet(this, _allItem, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _allItem)), objItem));
|
|
109
|
+
__classPrivateFieldGet(this, _cache)[searchText] = results.union(this.valueField);
|
|
110
|
+
}
|
|
111
|
+
// if (!this.multiple) {
|
|
112
|
+
// return this.#cache[searchText];
|
|
113
|
+
// }
|
|
114
|
+
const selectedItems = yield __classPrivateFieldGet(this, _loadSelectedItems).call(this, this.formControl.value, items);
|
|
115
|
+
// Đưa những selectedItems lên đầu nếu không mat-select-trigger sẽ không work
|
|
116
|
+
return [...selectedItems, ...__classPrivateFieldGet(this, _cache)[searchText]].union(this.valueField);
|
|
117
|
+
}));
|
|
118
|
+
_loadSelectedItems.set(this, (value, items) => __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
if (!(value === null || value === void 0 ? void 0 : value.toString())) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const values = Array.isArray(value) ? value : [value];
|
|
123
|
+
if (!this.valueField && !this.displayField) {
|
|
124
|
+
return values;
|
|
125
|
+
}
|
|
126
|
+
this.loading = true;
|
|
127
|
+
if (values.some(val => __classPrivateFieldGet(this, _allItem)[val] === undefined)) {
|
|
128
|
+
const results = yield items(value, true).catch(() => []).finally(() => this.loading = false);
|
|
129
|
+
const objItem = Array.toObject(results, this.valueField);
|
|
130
|
+
const objValue = Array.toObject(values.map(val => ({ [val === null || val === void 0 ? void 0 : val.toString()]: { [this.valueField]: val, [this.displayField]: val } })), this.valueField);
|
|
131
|
+
__classPrivateFieldSet(this, _allItem, Object.assign(Object.assign(Object.assign({}, objValue), __classPrivateFieldGet(this, _allItem)), objItem));
|
|
132
|
+
}
|
|
133
|
+
return values.map(val => { var _a; return (_a = __classPrivateFieldGet(this, _allItem)[val === null || val === void 0 ? void 0 : val.toString()]) !== null && _a !== void 0 ? _a : { [this.valueField]: val, [this.displayField]: val }; });
|
|
134
|
+
}));
|
|
97
135
|
this.onAdd = (event) => {
|
|
98
|
-
var _a, _b;
|
|
136
|
+
var _a, _b, _c, _d, _e;
|
|
99
137
|
// Add item only when MatAutocomplete is not open
|
|
100
138
|
// To make sure this does not conflict with OptionSelected Event
|
|
101
|
-
if (!this.matAutocomplete.isOpen) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
139
|
+
// if (!this.matAutocomplete.isOpen) {
|
|
140
|
+
// const value = (event.value ?? '').toString().trim();
|
|
141
|
+
// if (value) {
|
|
142
|
+
// if (this.valueField && this.displayField) {
|
|
143
|
+
// const item = this.#filteredItems.find(e => e[this.displayField] === value);
|
|
144
|
+
// if (item) {
|
|
145
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
146
|
+
// values.push(item[this.valueField]);
|
|
147
|
+
// this.formControl.setValue(values);
|
|
148
|
+
// } else if (this.#addable) {
|
|
149
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
150
|
+
// values.push(value);
|
|
151
|
+
// this.formControl.setValue(values);
|
|
152
|
+
// }
|
|
153
|
+
// } else {
|
|
154
|
+
// console.log(value);
|
|
155
|
+
// console.log(this.#filteredItems);
|
|
156
|
+
// const item = this.#filteredItems.find(item => item === value);
|
|
157
|
+
// if (item) {
|
|
158
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
159
|
+
// values.push(item);
|
|
160
|
+
// this.formControl.setValue(values);
|
|
161
|
+
// } else if (this.#addable) {
|
|
162
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
163
|
+
// values.push(value);
|
|
164
|
+
// this.formControl.setValue(values);
|
|
165
|
+
// }
|
|
166
|
+
// }
|
|
167
|
+
// }
|
|
168
|
+
// this.inputControl.setValue('');
|
|
169
|
+
// }
|
|
170
|
+
const value = ((_a = event.value) !== null && _a !== void 0 ? _a : '').toString().trim();
|
|
171
|
+
if (value) {
|
|
172
|
+
if (this.valueField && this.displayField) {
|
|
173
|
+
const item = __classPrivateFieldGet(this, _filteredItems).find(e => e[this.displayField] === value);
|
|
106
174
|
if (item) {
|
|
107
175
|
const values = (_b = this.formControl.value) !== null && _b !== void 0 ? _b : [];
|
|
108
176
|
values.push(item[this.valueField]);
|
|
109
177
|
this.formControl.setValue(values);
|
|
110
178
|
}
|
|
179
|
+
else if (__classPrivateFieldGet(this, _addable)) {
|
|
180
|
+
const values = (_c = this.formControl.value) !== null && _c !== void 0 ? _c : [];
|
|
181
|
+
values.push(value);
|
|
182
|
+
this.formControl.setValue(values);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const item = __classPrivateFieldGet(this, _filteredItems).find(item => item === value);
|
|
187
|
+
if (item) {
|
|
188
|
+
const values = (_d = this.formControl.value) !== null && _d !== void 0 ? _d : [];
|
|
189
|
+
values.push(item);
|
|
190
|
+
this.formControl.setValue(values);
|
|
191
|
+
}
|
|
192
|
+
else if (__classPrivateFieldGet(this, _addable)) {
|
|
193
|
+
const values = (_e = this.formControl.value) !== null && _e !== void 0 ? _e : [];
|
|
194
|
+
values.push(value);
|
|
195
|
+
this.formControl.setValue(values);
|
|
196
|
+
}
|
|
111
197
|
}
|
|
112
|
-
this.inputControl.setValue('');
|
|
113
198
|
}
|
|
199
|
+
this.input.nativeElement.value = '';
|
|
200
|
+
this.inputControl.setValue('');
|
|
114
201
|
};
|
|
115
202
|
// andn1 viết để xử lý tạm us B2B1D-18289 ở S69
|
|
116
203
|
this.onAdd2 = (event) => {
|
|
117
204
|
var _a, _b;
|
|
118
205
|
const value = ((_a = event.value) !== null && _a !== void 0 ? _a : '').toString().toLowerCase().trim();
|
|
119
206
|
if (value) {
|
|
120
|
-
const item = __classPrivateFieldGet(this,
|
|
207
|
+
const item = __classPrivateFieldGet(this, _filteredItems).find(e => e[this.valueField]
|
|
121
208
|
&& e[this.valueField].toString().toLowerCase().trim() === value);
|
|
122
209
|
if (item) {
|
|
123
210
|
const values = (_b = this.formControl.value) !== null && _b !== void 0 ? _b : [];
|
|
@@ -128,56 +215,92 @@ class SdChip {
|
|
|
128
215
|
}
|
|
129
216
|
}
|
|
130
217
|
this.inputControl.setValue('');
|
|
131
|
-
this.ref.detectChanges();
|
|
132
218
|
};
|
|
133
219
|
this.onRemove = (item) => {
|
|
134
220
|
var _a;
|
|
135
221
|
const values = (_a = this.formControl.value) !== null && _a !== void 0 ? _a : [];
|
|
136
|
-
|
|
222
|
+
if (typeof (item) === 'string' || typeof (item) === 'number') {
|
|
223
|
+
this.formControl.setValue(values.filter(value => item !== value));
|
|
224
|
+
}
|
|
225
|
+
else if (this.valueField) {
|
|
226
|
+
this.formControl.setValue(values.filter(value => (item === null || item === void 0 ? void 0 : item[this.valueField]) !== value));
|
|
227
|
+
}
|
|
137
228
|
this.inputControl.setValue('');
|
|
138
229
|
};
|
|
139
230
|
this.select = (item) => {
|
|
140
231
|
this.chipSelected.emit(item);
|
|
141
232
|
};
|
|
233
|
+
// onSelect = (event: MatAutocompleteSelectedEvent) => {
|
|
234
|
+
// const value = (event.option.value?.[this.valueField] ?? '').toString().trim();
|
|
235
|
+
// if (value) {
|
|
236
|
+
// const item = this.#items.find(e => e[this.valueField]
|
|
237
|
+
// && e[this.valueField].toString().trim() === value);
|
|
238
|
+
// if (item) {
|
|
239
|
+
// const values: (string | number)[] = this.formControl.value ?? [];
|
|
240
|
+
// values.push(item[this.valueField]);
|
|
241
|
+
// this.formControl.setValue(values);
|
|
242
|
+
// this.input.nativeElement.value = '';
|
|
243
|
+
// this.inputControl.setValue('');
|
|
244
|
+
// setTimeout(() => {
|
|
245
|
+
// this.autocompleteTrigger?.openPanel();
|
|
246
|
+
// }, 0);
|
|
247
|
+
// }
|
|
248
|
+
// }
|
|
249
|
+
// }
|
|
142
250
|
this.onSelect = (event) => {
|
|
143
|
-
var _a
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
this.displayFn = (value) => {
|
|
162
|
-
if (typeof value === 'string') {
|
|
163
|
-
if (!__classPrivateFieldGet(this, _items)) {
|
|
164
|
-
return undefined;
|
|
165
|
-
}
|
|
166
|
-
const selectedItem = __classPrivateFieldGet(this, _items).find(item => item[this.valueField] === value);
|
|
167
|
-
if (selectedItem) {
|
|
168
|
-
return selectedItem[this.displayField];
|
|
169
|
-
}
|
|
170
|
-
if (__classPrivateFieldGet(this, _items).some(item => item[this.displayField].toLowerCase().indexOf(value.toLowerCase()) !== -1)) {
|
|
171
|
-
return value;
|
|
251
|
+
var _a;
|
|
252
|
+
const item = event.option.value;
|
|
253
|
+
const values = (_a = this.formControl.value) !== null && _a !== void 0 ? _a : [];
|
|
254
|
+
if (item) {
|
|
255
|
+
if (typeof (item) === 'string' || typeof (item) === 'number') {
|
|
256
|
+
if (!values.includes(item)) {
|
|
257
|
+
values.push(item);
|
|
258
|
+
this.formControl.setValue(values);
|
|
259
|
+
this.modelChange.emit(values);
|
|
260
|
+
this.sdChange.emit(values);
|
|
261
|
+
setTimeout(() => {
|
|
262
|
+
var _a;
|
|
263
|
+
(_a = this.autocompleteTrigger) === null || _a === void 0 ? void 0 : _a.openPanel();
|
|
264
|
+
}, 0);
|
|
265
|
+
}
|
|
172
266
|
}
|
|
173
|
-
else {
|
|
174
|
-
|
|
267
|
+
else if (this.valueField) {
|
|
268
|
+
const val = (item === null || item === void 0 ? void 0 : item[this.valueField]) || null;
|
|
269
|
+
if (!values.includes(val)) {
|
|
270
|
+
values.push(val);
|
|
271
|
+
this.formControl.setValue(values);
|
|
272
|
+
this.modelChange.emit(values);
|
|
273
|
+
this.sdChange.emit(values);
|
|
274
|
+
setTimeout(() => {
|
|
275
|
+
var _a;
|
|
276
|
+
(_a = this.autocompleteTrigger) === null || _a === void 0 ? void 0 : _a.openPanel();
|
|
277
|
+
}, 0);
|
|
278
|
+
}
|
|
175
279
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
280
|
+
this.input.nativeElement.value = '';
|
|
281
|
+
this.inputControl.setValue('', {
|
|
282
|
+
emitEvent: false
|
|
283
|
+
});
|
|
179
284
|
}
|
|
180
285
|
};
|
|
286
|
+
// displayFn = (value: string | { [key: string]: string }): string | undefined => {
|
|
287
|
+
// if (typeof value === 'string') {
|
|
288
|
+
// if (!this.#items) {
|
|
289
|
+
// return undefined;
|
|
290
|
+
// }
|
|
291
|
+
// const selectedItem = this.#items.find(item => item[this.valueField] === value);
|
|
292
|
+
// if (selectedItem) {
|
|
293
|
+
// return selectedItem[this.displayField];
|
|
294
|
+
// }
|
|
295
|
+
// if (this.#items.some(item => item[this.displayField].toLowerCase().indexOf(value.toLowerCase()) !== -1)) {
|
|
296
|
+
// return value;
|
|
297
|
+
// } else {
|
|
298
|
+
// return undefined;
|
|
299
|
+
// }
|
|
300
|
+
// } else {
|
|
301
|
+
// return value ? value[this.displayField] : undefined;
|
|
302
|
+
// }
|
|
303
|
+
// }
|
|
181
304
|
this.onFocus = () => {
|
|
182
305
|
this.isFocused = true;
|
|
183
306
|
this.inputControl.setValue('');
|
|
@@ -229,30 +352,32 @@ class SdChip {
|
|
|
229
352
|
}
|
|
230
353
|
}
|
|
231
354
|
}
|
|
355
|
+
set addable(val) {
|
|
356
|
+
__classPrivateFieldSet(this, _addable, (val === '') || val);
|
|
357
|
+
}
|
|
232
358
|
set _removable(val) {
|
|
233
359
|
this.removable = (val === '') || val;
|
|
234
360
|
}
|
|
235
361
|
set items(items) {
|
|
362
|
+
__classPrivateFieldSet(this, _delay, 0);
|
|
236
363
|
if (!items) {
|
|
237
|
-
|
|
364
|
+
__classPrivateFieldGet(this, _itemsChanges).next([]);
|
|
238
365
|
}
|
|
239
366
|
else if (Array.isArray(items)) {
|
|
240
|
-
|
|
367
|
+
__classPrivateFieldGet(this, _itemsChanges).next(items.filter(e => e !== null && e !== undefined));
|
|
241
368
|
}
|
|
242
369
|
else {
|
|
243
|
-
__classPrivateFieldSet(this,
|
|
370
|
+
__classPrivateFieldSet(this, _delay, 500);
|
|
371
|
+
__classPrivateFieldGet(this, _itemsChanges).next(items);
|
|
244
372
|
}
|
|
245
|
-
this.
|
|
246
|
-
__classPrivateFieldGet(this, _itemChanges).next(this.items);
|
|
373
|
+
this.formControl.updateValueAndValidity();
|
|
247
374
|
}
|
|
248
375
|
// model
|
|
249
376
|
set model(values) {
|
|
250
377
|
if (!Array.isArray(values)) {
|
|
251
378
|
values = [];
|
|
252
379
|
}
|
|
253
|
-
this.formControl.setValue(values
|
|
254
|
-
emitEvent: false
|
|
255
|
-
});
|
|
380
|
+
this.formControl.setValue(values);
|
|
256
381
|
}
|
|
257
382
|
set required(val) {
|
|
258
383
|
this.isRequired = (val === '') || val;
|
|
@@ -279,28 +404,85 @@ class SdChip {
|
|
|
279
404
|
}
|
|
280
405
|
}
|
|
281
406
|
ngOnInit() {
|
|
282
|
-
this.filteredItems = this.inputControl.valueChanges.pipe(startWith(''), map(item => { var _a; return typeof item === 'string' ? item : ((_a = item === null || item === void 0 ? void 0 : item[this.displayField]) !== null && _a !== void 0 ? _a : ''); }), map(name => this.filter(name)));
|
|
283
407
|
}
|
|
284
408
|
ngAfterViewInit() {
|
|
285
409
|
var _a;
|
|
286
|
-
__classPrivateFieldGet(this, _subscription).add(this.formControl.
|
|
287
|
-
|
|
288
|
-
this.selectedItems = __classPrivateFieldGet(this, _items).filter(item => values.findIndex(value => value === (item === null || item === void 0 ? void 0 : item[this.valueField])) !== -1);
|
|
289
|
-
this.modelChange.emit(values);
|
|
290
|
-
this.sdChange.emit(values);
|
|
291
|
-
setTimeout(() => {
|
|
292
|
-
var _a;
|
|
293
|
-
(_a = __classPrivateFieldGet(this, _form)) === null || _a === void 0 ? void 0 : _a.markAsDirty();
|
|
294
|
-
}, 0);
|
|
410
|
+
__classPrivateFieldGet(this, _subscription).add(this.formControl.sdChanges.subscribe(() => {
|
|
411
|
+
this.ref.markForCheck();
|
|
295
412
|
}));
|
|
296
|
-
|
|
413
|
+
__classPrivateFieldSet(this, _allItems, combineLatest([
|
|
414
|
+
__classPrivateFieldGet(this, _itemsChanges).asObservable(),
|
|
415
|
+
this.inputControl.valueChanges.pipe(startWith(''), debounceTime(__classPrivateFieldGet(this, _delay))),
|
|
416
|
+
this.formControl.valueChanges.pipe(startWith(this.formControl.value))
|
|
417
|
+
]).pipe(switchMap(([items]) => __awaiter(this, void 0, void 0, function* () {
|
|
418
|
+
const val = this.inputControl.value;
|
|
297
419
|
const values = this.formControl.value || [];
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const item = __classPrivateFieldGet(this, _items).find(e => (e === null || e === void 0 ? void 0 : e[this.valueField]) === value) || {};
|
|
301
|
-
this.selectedItems.push(Object.assign(Object.assign({}, item), { [this.valueField]: value }));
|
|
420
|
+
if (typeof (items) === 'function') {
|
|
421
|
+
return yield __classPrivateFieldGet(this, _loadItems).call(this, val, items);
|
|
302
422
|
}
|
|
303
|
-
|
|
423
|
+
__classPrivateFieldSet(this, _allItem, items.toObject(this.valueField));
|
|
424
|
+
const hasFields = !!this.valueField && !!this.displayField;
|
|
425
|
+
__classPrivateFieldSet(this, _filteredItems, items.filter(item => {
|
|
426
|
+
const value = hasFields ? item[this.valueField] : item;
|
|
427
|
+
const display = hasFields ? item[this.displayField] : item;
|
|
428
|
+
if (String.aliasIncludes(value, val) || String.aliasIncludes(display, val)) {
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
return values.some(e => e === value);
|
|
432
|
+
}));
|
|
433
|
+
return __classPrivateFieldGet(this, _filteredItems);
|
|
434
|
+
}))));
|
|
435
|
+
this.selectedItems = combineLatest([
|
|
436
|
+
__classPrivateFieldGet(this, _itemsChanges).asObservable(),
|
|
437
|
+
this.formControl.valueChanges.pipe(startWith(this.formControl.value))
|
|
438
|
+
])
|
|
439
|
+
.pipe(switchMap(([items, val]) => __awaiter(this, void 0, void 0, function* () {
|
|
440
|
+
var _b;
|
|
441
|
+
// 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
|
|
442
|
+
// Nhưng formControl.value vẫn có giá trị đúng nên thực hiện gán val = this.formControl.value;
|
|
443
|
+
val = this.formControl.value;
|
|
444
|
+
if (!this.valueField) {
|
|
445
|
+
return this.formControl.value;
|
|
446
|
+
}
|
|
447
|
+
if (typeof (items) === 'function') {
|
|
448
|
+
return yield __classPrivateFieldGet(this, _loadSelectedItems).call(this, val, items);
|
|
449
|
+
}
|
|
450
|
+
return (_b = (this.formControl.value || [])) === null || _b === void 0 ? void 0 : _b.map(value => {
|
|
451
|
+
return (items === null || items === void 0 ? void 0 : items.find(item => item[this.valueField] === value)) || {
|
|
452
|
+
[this.valueField]: value,
|
|
453
|
+
[this.displayField]: value
|
|
454
|
+
};
|
|
455
|
+
});
|
|
456
|
+
})));
|
|
457
|
+
this.filteredItems = __classPrivateFieldGet(this, _allItems).pipe(map(allItems => allItems.filter(item => {
|
|
458
|
+
const values = this.formControl.value || [];
|
|
459
|
+
if (this.valueField) {
|
|
460
|
+
return !values.includes(item === null || item === void 0 ? void 0 : item[this.valueField]);
|
|
461
|
+
}
|
|
462
|
+
return !values.includes(item);
|
|
463
|
+
}).paging(this.limit)));
|
|
464
|
+
// this.display = this.selectedItems.pipe(
|
|
465
|
+
// map(selectedItems => selectedItems?.map(item => this.displayField ? item[this.displayField] : item)?.join(', ')));
|
|
466
|
+
// this.#subscription.add(this.formControl.valueChanges.subscribe(() => {
|
|
467
|
+
// const values: (string | number)[] = this.formControl.value || [];
|
|
468
|
+
// this.selectedItems = this.#items.filter(item => values.findIndex(value => value === item?.[this.valueField]) !== -1);
|
|
469
|
+
// this.modelChange.emit(values);
|
|
470
|
+
// this.sdChange.emit(values);
|
|
471
|
+
// setTimeout(() => {
|
|
472
|
+
// this.#form?.markAsDirty();
|
|
473
|
+
// }, 0);
|
|
474
|
+
// }));
|
|
475
|
+
// this.#subscription.add(this.#itemChanges.pipe(startWith(this.#items)).subscribe(() => {
|
|
476
|
+
// const values: (string | number)[] = this.formControl.value || [];
|
|
477
|
+
// this.selectedItems = [];
|
|
478
|
+
// for (const value of values) {
|
|
479
|
+
// const item = this.#items.find(e => e?.[this.valueField] === value) || {};
|
|
480
|
+
// this.selectedItems.push({
|
|
481
|
+
// ...item,
|
|
482
|
+
// [this.valueField]: value
|
|
483
|
+
// });
|
|
484
|
+
// }
|
|
485
|
+
// }));
|
|
304
486
|
(_a = __classPrivateFieldGet(this, _form)) === null || _a === void 0 ? void 0 : _a.addControl(__classPrivateFieldGet(this, _name), this.formControl);
|
|
305
487
|
}
|
|
306
488
|
ngOnDestroy() {
|
|
@@ -309,22 +491,23 @@ class SdChip {
|
|
|
309
491
|
__classPrivateFieldGet(this, _subscription).unsubscribe();
|
|
310
492
|
}
|
|
311
493
|
}
|
|
312
|
-
_name = new WeakMap(), _form = new WeakMap(),
|
|
494
|
+
_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();
|
|
313
495
|
SdChip.decorators = [
|
|
314
496
|
{ type: Component, args: [{
|
|
315
497
|
selector: 'sd-chip',
|
|
316
|
-
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\"
|
|
498
|
+
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>",
|
|
499
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
317
500
|
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}"]
|
|
318
501
|
},] }
|
|
319
502
|
];
|
|
320
503
|
SdChip.ctorParameters = () => [
|
|
321
|
-
{ type: ChangeDetectorRef }
|
|
322
|
-
{ type: SdUtilityService }
|
|
504
|
+
{ type: ChangeDetectorRef }
|
|
323
505
|
];
|
|
324
506
|
SdChip.propDecorators = {
|
|
325
507
|
name: [{ type: Input }],
|
|
326
508
|
size: [{ type: Input }],
|
|
327
509
|
form: [{ type: Input }],
|
|
510
|
+
addable: [{ type: Input }],
|
|
328
511
|
label: [{ type: Input }],
|
|
329
512
|
valueField: [{ type: Input }],
|
|
330
513
|
displayField: [{ type: Input }],
|