@haiilo/catalyst 1.0.2 → 1.1.1
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/dist/catalyst/catalyst.css +1 -1
- package/dist/catalyst/catalyst.esm.js +1 -1
- package/dist/catalyst/catalyst.esm.js.map +1 -1
- package/dist/catalyst/p-a4d0b054.entry.js +10 -0
- package/dist/catalyst/p-a4d0b054.entry.js.map +1 -0
- package/dist/catalyst/scss/utils/_sizing.mixins.scss +1 -1
- package/dist/cjs/cat-alert_23.cjs.entry.js +320 -129
- package/dist/cjs/cat-alert_23.cjs.entry.js.map +1 -1
- package/dist/cjs/catalyst.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/cat-alert/cat-alert.css +13 -19
- package/dist/collection/components/cat-alert/cat-alert.js +19 -20
- package/dist/collection/components/cat-alert/cat-alert.js.map +1 -1
- package/dist/collection/components/cat-avatar/cat-avatar.css +8 -8
- package/dist/collection/components/cat-badge/cat-badge.css +20 -26
- package/dist/collection/components/cat-badge/cat-badge.js +9 -12
- package/dist/collection/components/cat-badge/cat-badge.js.map +1 -1
- package/dist/collection/components/cat-card/cat-card.js +2 -3
- package/dist/collection/components/cat-card/cat-card.js.map +1 -1
- package/dist/collection/components/cat-checkbox/cat-checkbox.css +1 -1
- package/dist/collection/components/cat-select/cat-select.css +6 -1
- package/dist/collection/components/cat-select/cat-select.js +290 -89
- package/dist/collection/components/cat-select/cat-select.js.map +1 -1
- package/dist/collection/components/cat-select-demo/cat-select-demo.js +43 -30
- package/dist/collection/components/cat-select-demo/cat-select-demo.js.map +1 -1
- package/dist/collection/components/cat-tooltip/cat-tooltip.css +26 -2
- package/dist/collection/components/cat-tooltip/cat-tooltip.js +51 -3
- package/dist/collection/components/cat-tooltip/cat-tooltip.js.map +1 -1
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/scss/utils/_sizing.mixins.scss +1 -1
- package/dist/collection/utils/setDefault.js +9 -0
- package/dist/collection/utils/setDefault.js.map +1 -0
- package/dist/components/cat-alert.js +16 -14
- package/dist/components/cat-alert.js.map +1 -1
- package/dist/components/cat-avatar2.js +1 -1
- package/dist/components/cat-avatar2.js.map +1 -1
- package/dist/components/cat-badge.js +9 -9
- package/dist/components/cat-badge.js.map +1 -1
- package/dist/components/cat-card.js +2 -2
- package/dist/components/cat-card.js.map +1 -1
- package/dist/components/cat-checkbox2.js +1 -1
- package/dist/components/cat-checkbox2.js.map +1 -1
- package/dist/components/cat-select-demo.js +33 -22
- package/dist/components/cat-select-demo.js.map +1 -1
- package/dist/components/cat-select2.js +238 -77
- package/dist/components/cat-select2.js.map +1 -1
- package/dist/components/cat-tooltip.js +17 -3
- package/dist/components/cat-tooltip.js.map +1 -1
- package/dist/components/setDefault.js +12 -0
- package/dist/components/setDefault.js.map +1 -0
- package/dist/esm/cat-alert_23.entry.js +321 -130
- package/dist/esm/cat-alert_23.entry.js.map +1 -1
- package/dist/esm/catalyst.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/types/components/cat-alert/cat-alert.d.ts +3 -3
- package/dist/types/components/cat-badge/cat-badge.d.ts +2 -2
- package/dist/types/components/cat-select/cat-select.d.ts +34 -1
- package/dist/types/components/cat-select-demo/cat-select-demo.d.ts +3 -0
- package/dist/types/components/cat-tooltip/cat-tooltip.d.ts +8 -0
- package/dist/types/components.d.ts +37 -5
- package/dist/types/index.d.ts +1 -1
- package/dist/types/utils/setDefault.d.ts +6 -0
- package/package.json +2 -2
- package/dist/catalyst/p-a2ddc7fa.entry.js +0 -10
- package/dist/catalyst/p-a2ddc7fa.entry.js.map +0 -1
|
@@ -69,6 +69,10 @@ export class CatSelect {
|
|
|
69
69
|
* Whether the select should show a clear button.
|
|
70
70
|
*/
|
|
71
71
|
this.clearable = false;
|
|
72
|
+
/**
|
|
73
|
+
* Whether the select should add new items.
|
|
74
|
+
*/
|
|
75
|
+
this.tags = false;
|
|
72
76
|
}
|
|
73
77
|
onConnectorChange(connector) {
|
|
74
78
|
this.reset(connector);
|
|
@@ -88,11 +92,25 @@ export class CatSelect {
|
|
|
88
92
|
this.hide();
|
|
89
93
|
}
|
|
90
94
|
const idsSelected = this.state.selection.map(item => item.item.id);
|
|
91
|
-
if (this.
|
|
92
|
-
this.
|
|
95
|
+
if (!this.tags) {
|
|
96
|
+
if (this.multiple) {
|
|
97
|
+
this.value = idsSelected;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
this.value = idsSelected.length ? idsSelected[0] : '';
|
|
101
|
+
}
|
|
93
102
|
}
|
|
94
103
|
else {
|
|
95
|
-
|
|
104
|
+
const ids = idsSelected.filter(id => !id.startsWith(`select-${this.id}-tag`));
|
|
105
|
+
const tags = this.state.selection
|
|
106
|
+
.filter(item => item.item.id.startsWith(`select-${this.id}-tag`))
|
|
107
|
+
.map(item => item.render.label);
|
|
108
|
+
if (this.multiple) {
|
|
109
|
+
this.value = { ids, tags };
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.value = { id: ids.length ? ids[0] : '', tag: tags.length ? tags[0] : '' };
|
|
113
|
+
}
|
|
96
114
|
}
|
|
97
115
|
this.catChange.emit();
|
|
98
116
|
}
|
|
@@ -113,7 +131,12 @@ export class CatSelect {
|
|
|
113
131
|
}
|
|
114
132
|
onBlur(event) {
|
|
115
133
|
if (!this.multiple && this.state.activeOptionIndex >= 0) {
|
|
116
|
-
this.
|
|
134
|
+
if (this.tags && this.state.options[this.state.activeOptionIndex].item.id === `select-${this.id}-option-tag`) {
|
|
135
|
+
this.createTag(this.state.term);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
this.select(this.state.options[this.state.activeOptionIndex]);
|
|
139
|
+
}
|
|
117
140
|
}
|
|
118
141
|
this.hide();
|
|
119
142
|
this.patchState({ activeSelectionIndex: -1 });
|
|
@@ -125,8 +148,19 @@ export class CatSelect {
|
|
|
125
148
|
if (['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
|
|
126
149
|
this.onArrowKeyDown(event);
|
|
127
150
|
}
|
|
128
|
-
else if (['Enter', ' '].includes(event.key)) {
|
|
129
|
-
if (
|
|
151
|
+
else if (['Enter', ' '].includes(event.key) && isInputFocused) {
|
|
152
|
+
if (this.tags &&
|
|
153
|
+
this.state.activeOptionIndex === 0 &&
|
|
154
|
+
this.state.options[0].item.id === `select-${this.id}-option-tag`) {
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
if (this.multiple) {
|
|
157
|
+
this.toggleTag(this.state.options[0]);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
this.createTag(this.state.options[0].render.label);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (this.state.activeOptionIndex >= 0) {
|
|
130
164
|
event.preventDefault();
|
|
131
165
|
if (this.multiple) {
|
|
132
166
|
this.toggle(this.state.options[this.state.activeOptionIndex]);
|
|
@@ -135,6 +169,9 @@ export class CatSelect {
|
|
|
135
169
|
this.select(this.state.options[this.state.activeOptionIndex]);
|
|
136
170
|
}
|
|
137
171
|
}
|
|
172
|
+
else if (this.tags && event.key === 'Enter' && this.state.activeOptionIndex < 0) {
|
|
173
|
+
this.createTag(this.state.term);
|
|
174
|
+
}
|
|
138
175
|
}
|
|
139
176
|
else if (event.key === 'Escape') {
|
|
140
177
|
this.hide();
|
|
@@ -158,7 +195,12 @@ export class CatSelect {
|
|
|
158
195
|
this.patchState({ activeSelectionIndex: -1, activeOptionIndex: -1 });
|
|
159
196
|
}
|
|
160
197
|
else if (this.state.activeOptionIndex >= 0) {
|
|
161
|
-
this.
|
|
198
|
+
if (this.tags && this.state.options[this.state.activeOptionIndex].item.id === `select-${this.id}-option-tag`) {
|
|
199
|
+
this.createTag(this.state.term);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
this.select(this.state.options[this.state.activeOptionIndex]);
|
|
203
|
+
}
|
|
162
204
|
}
|
|
163
205
|
}
|
|
164
206
|
else if (event.key.length === 1) {
|
|
@@ -196,12 +238,28 @@ export class CatSelect {
|
|
|
196
238
|
this.subscription = this.term$
|
|
197
239
|
.asObservable()
|
|
198
240
|
.pipe(debounce(term => (term ? timer(this.debounce) : of(0))), distinctUntilChanged(), tap(() => (number$ = this.more$.pipe(filter(() => !this.state.isLoading), scan(n => n + 1, 0), startWith(0)))), tap(() => this.patchState({ options: [] })), switchMap(term => number$.pipe(tap(() => this.patchState({ isLoading: true })), switchMap(number => this.connectorSafe.retrieve(term, number)), tap(page => this.patchState({ isLoading: false, totalElements: page.totalElements })), takeWhile(page => !page.last, true), scan((items, page) => [...items, ...page.content], []))))
|
|
199
|
-
.subscribe(items =>
|
|
200
|
-
|
|
201
|
-
|
|
241
|
+
.subscribe(items => {
|
|
242
|
+
var _a;
|
|
243
|
+
const options = items === null || items === void 0 ? void 0 : items.map(item => ({
|
|
244
|
+
item: Object.assign(Object.assign({}, item), { id: this.connectorSafe.customId ? this.connectorSafe.customId(item) : item.id }),
|
|
202
245
|
render: this.connectorSafe.render(item)
|
|
203
|
-
}))
|
|
204
|
-
|
|
246
|
+
}));
|
|
247
|
+
if (this.tags &&
|
|
248
|
+
this.state.term.trim().length &&
|
|
249
|
+
!options.find(value1 => value1.render.label.toLowerCase() === this.state.term.toLowerCase())) {
|
|
250
|
+
let label;
|
|
251
|
+
if (this.isAlreadyCreated(this.state.term)) {
|
|
252
|
+
label = (_a = this.state.selection.find(item => item.render.label.toLowerCase() === this.state.term.toLowerCase())) === null || _a === void 0 ? void 0 : _a.render.label;
|
|
253
|
+
}
|
|
254
|
+
options.unshift({
|
|
255
|
+
item: { id: `select-${this.id}-option-tag` },
|
|
256
|
+
render: { label: label ? label : this.state.term }
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
this.patchState({
|
|
260
|
+
options
|
|
261
|
+
});
|
|
262
|
+
});
|
|
205
263
|
}
|
|
206
264
|
render() {
|
|
207
265
|
return (h(Host, null,
|
|
@@ -232,28 +290,47 @@ export class CatSelect {
|
|
|
232
290
|
this.hintSection,
|
|
233
291
|
h("div", { class: "select-dropdown", ref: el => (this.dropdown = el), style: { display: this.state.isOpen ? 'block' : undefined } }, this.state.isOpen && (h("cat-scrollable", { class: "select-options-wrapper", scrolledBuffer: 56, noOverflowX: true, noOverscroll: true, noScrolledInit: true, onScrolledBottom: () => this.more$.next() },
|
|
234
292
|
h("ul", { class: "select-options", role: "listbox", "aria-multiselectable": this.multiple, "aria-setsize": this.state.totalElements, id: `select-listbox-${this.id}` },
|
|
235
|
-
this.
|
|
236
|
-
this.toggle(item);
|
|
237
|
-
e.stopPropagation();
|
|
238
|
-
} },
|
|
239
|
-
h("span", { slot: "label", class: "select-option-inner" },
|
|
240
|
-
item.render.avatar ? (h("cat-avatar", { label: item.render.label, round: item.render.avatar.round, src: item.render.avatar.src, initials: '' })) : null,
|
|
241
|
-
h("span", { class: "select-option-text" },
|
|
242
|
-
h("span", { class: "select-option-label" }, item.render.label),
|
|
243
|
-
h("span", { class: "select-option-description" }, item.render.description))))) : (h("div", { class: {
|
|
244
|
-
'select-option-inner': true,
|
|
245
|
-
'select-option-single': true,
|
|
246
|
-
'select-option-active': this.state.activeOptionIndex === i
|
|
247
|
-
}, onFocus: () => { var _a; return (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus(); }, onClick: () => this.select(item), tabIndex: -1 },
|
|
248
|
-
item.render.avatar ? (h("cat-avatar", { label: item.render.label, round: item.render.avatar.round, src: item.render.avatar.src, initials: '' })) : null,
|
|
249
|
-
h("span", { class: "select-option-text" },
|
|
250
|
-
h("span", { class: "select-option-label" }, item.render.label),
|
|
251
|
-
h("span", { class: "select-option-description" }, item.render.description))))))),
|
|
293
|
+
this.optionsList,
|
|
252
294
|
this.state.isLoading
|
|
253
295
|
? Array.from(Array(CatSelect.SKELETON_COUNT)).map(() => (h("li", { class: "select-option-loading" },
|
|
254
296
|
h("cat-skeleton", { variant: "body", lines: 1 }),
|
|
255
297
|
h("cat-skeleton", { variant: "body", lines: 1 }))))
|
|
256
|
-
: !this.state.options.length &&
|
|
298
|
+
: !this.state.options.length &&
|
|
299
|
+
!this.tags && h("li", { class: "select-option-empty" }, this.i18n.t('select.empty'))))))));
|
|
300
|
+
}
|
|
301
|
+
get optionsList() {
|
|
302
|
+
return this.state.options.map((item, i) => {
|
|
303
|
+
const isTagOption = this.tags && item.item.id === `select-${this.id}-option-tag`;
|
|
304
|
+
const getAriaSelected = () => {
|
|
305
|
+
if (isTagOption) {
|
|
306
|
+
return this.isAlreadyCreated(item.render.label) ? 'true' : 'false';
|
|
307
|
+
}
|
|
308
|
+
return this.isSelected(item.item.id) ? 'true' : 'false';
|
|
309
|
+
};
|
|
310
|
+
const getLabel = () => {
|
|
311
|
+
if (isTagOption) {
|
|
312
|
+
return item.render.label + this.tagTextHelp;
|
|
313
|
+
}
|
|
314
|
+
return item.render.label;
|
|
315
|
+
};
|
|
316
|
+
return (h("li", { role: "option", class: "select-option", id: `select-${this.id}-option-${i}`, "aria-selected": getAriaSelected() }, this.multiple ? (h("cat-checkbox", { class: { 'select-option-active': this.state.activeOptionIndex === i }, checked: !isTagOption ? this.isSelected(item.item.id) : this.isAlreadyCreated(item.render.label), tabIndex: -1, labelLeft: true, onFocus: () => { var _a; return (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus(); }, onCatChange: e => {
|
|
317
|
+
!isTagOption ? this.toggle(item) : this.toggleTag(item);
|
|
318
|
+
e.stopPropagation();
|
|
319
|
+
} },
|
|
320
|
+
h("span", { slot: "label", class: "select-option-inner" },
|
|
321
|
+
item.render.avatar ? (h("cat-avatar", { label: item.render.label, round: item.render.avatar.round, src: item.render.avatar.src, initials: '' })) : null,
|
|
322
|
+
h("span", { class: "select-option-text" },
|
|
323
|
+
h("span", { class: "select-option-label" }, getLabel()),
|
|
324
|
+
h("span", { class: "select-option-description" }, item.render.description))))) : (h("div", { class: {
|
|
325
|
+
'select-option-inner': true,
|
|
326
|
+
'select-option-single': true,
|
|
327
|
+
'select-option-active': this.state.activeOptionIndex === i
|
|
328
|
+
}, onFocus: () => { var _a; return (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus(); }, onClick: () => (isTagOption ? this.createTag(item.render.label) : this.select(item)), tabIndex: -1 },
|
|
329
|
+
item.render.avatar ? (h("cat-avatar", { label: item.render.label, round: item.render.avatar.round, src: item.render.avatar.src, initials: '' })) : null,
|
|
330
|
+
h("span", { class: "select-option-text" },
|
|
331
|
+
h("span", { class: "select-option-label" }, getLabel()),
|
|
332
|
+
h("span", { class: "select-option-description" }, item.render.description))))));
|
|
333
|
+
});
|
|
257
334
|
}
|
|
258
335
|
get hintSection() {
|
|
259
336
|
const hasSlottedHint = !!this.hostElement.querySelector('[slot="hint"]');
|
|
@@ -266,21 +343,27 @@ export class CatSelect {
|
|
|
266
343
|
throw new Error('CatSelectConnector not set');
|
|
267
344
|
}
|
|
268
345
|
resolve() {
|
|
269
|
-
var _a;
|
|
270
346
|
this.patchState({ isResolving: true });
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
else {
|
|
276
|
-
ids = [this.value];
|
|
347
|
+
const ids = this.initIds();
|
|
348
|
+
let tags;
|
|
349
|
+
if (this.tags) {
|
|
350
|
+
tags = this.initTags();
|
|
277
351
|
}
|
|
278
|
-
const data$ =
|
|
279
|
-
data$.pipe(catchError(() => of([]))).subscribe(items =>
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
352
|
+
const data$ = ids.length ? this.connectorSafe.resolve(ids).pipe(first()) : of([]);
|
|
353
|
+
data$.pipe(catchError(() => of([]))).subscribe(items => {
|
|
354
|
+
const selection = items.length ? items === null || items === void 0 ? void 0 : items.map(item => ({ item, render: this.connectorSafe.render(item) })) : [];
|
|
355
|
+
if (this.tags) {
|
|
356
|
+
tags === null || tags === void 0 ? void 0 : tags.forEach((tag, index) => {
|
|
357
|
+
const item = { id: `select-${this.id}-tag-${index}`, name: tag };
|
|
358
|
+
selection.push({ item, render: { label: item.name } });
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
this.patchState({
|
|
362
|
+
isResolving: false,
|
|
363
|
+
selection,
|
|
364
|
+
term: !this.multiple && selection.length ? selection[0].render.label : ''
|
|
365
|
+
});
|
|
366
|
+
});
|
|
284
367
|
}
|
|
285
368
|
show() {
|
|
286
369
|
var _a;
|
|
@@ -305,7 +388,6 @@ export class CatSelect {
|
|
|
305
388
|
return this.state.selection.findIndex(s => s.item.id === id) >= 0;
|
|
306
389
|
}
|
|
307
390
|
select(item) {
|
|
308
|
-
var _a;
|
|
309
391
|
if (!this.isSelected(item.item.id)) {
|
|
310
392
|
let newSelection;
|
|
311
393
|
if (this.multiple) {
|
|
@@ -316,11 +398,13 @@ export class CatSelect {
|
|
|
316
398
|
this.search(item.render.label);
|
|
317
399
|
}
|
|
318
400
|
this.patchState({ selection: newSelection });
|
|
401
|
+
if (this.multiple && this.state.term.trim() && this.input) {
|
|
402
|
+
this.patchState({ term: '', activeOptionIndex: -1 });
|
|
403
|
+
this.term$.next('');
|
|
404
|
+
this.input.value = '';
|
|
405
|
+
}
|
|
319
406
|
}
|
|
320
|
-
|
|
321
|
-
this.hide();
|
|
322
|
-
(_a = this.input) === null || _a === void 0 ? void 0 : _a.classList.add('select-input-transparent-caret');
|
|
323
|
-
}
|
|
407
|
+
this.setTransparentCaret();
|
|
324
408
|
}
|
|
325
409
|
deselect(id) {
|
|
326
410
|
if (this.isSelected(id)) {
|
|
@@ -367,7 +451,12 @@ export class CatSelect {
|
|
|
367
451
|
}
|
|
368
452
|
onInput() {
|
|
369
453
|
var _a;
|
|
370
|
-
this.search(((_a = this.input) === null || _a === void 0 ? void 0 : _a.value) || '');
|
|
454
|
+
this.search(((_a = this.input) === null || _a === void 0 ? void 0 : _a.value.trim()) || '');
|
|
455
|
+
if (!this.multiple && this.state.selection.length) {
|
|
456
|
+
const selectionClone = [...this.state.selection];
|
|
457
|
+
selectionClone.pop();
|
|
458
|
+
this.patchState({ selection: selectionClone });
|
|
459
|
+
}
|
|
371
460
|
this.show();
|
|
372
461
|
}
|
|
373
462
|
update() {
|
|
@@ -405,52 +494,122 @@ export class CatSelect {
|
|
|
405
494
|
var _a, _b;
|
|
406
495
|
let preventDefault = false;
|
|
407
496
|
(_a = this.input) === null || _a === void 0 ? void 0 : _a.focus();
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
this.state.isOpen
|
|
411
|
-
? this.patchState({
|
|
412
|
-
activeOptionIndex: Math.min(this.state.activeOptionIndex + 1, this.state.options.length - 1),
|
|
413
|
-
activeSelectionIndex: -1
|
|
414
|
-
})
|
|
415
|
-
: this.show();
|
|
416
|
-
}
|
|
417
|
-
else if (event.key === 'ArrowUp') {
|
|
418
|
-
preventDefault = true;
|
|
419
|
-
this.state.activeOptionIndex >= 0
|
|
420
|
-
? this.patchState({
|
|
421
|
-
activeOptionIndex: Math.max(this.state.activeOptionIndex - 1, -1),
|
|
422
|
-
activeSelectionIndex: -1
|
|
423
|
-
})
|
|
424
|
-
: this.hide();
|
|
425
|
-
}
|
|
426
|
-
else if (event.key === 'ArrowLeft') {
|
|
427
|
-
if (((_b = this.input) === null || _b === void 0 ? void 0 : _b.selectionStart) === 0) {
|
|
497
|
+
switch (event.key) {
|
|
498
|
+
case 'ArrowDown':
|
|
428
499
|
preventDefault = true;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
if (this.state.activeSelectionIndex >= 0) {
|
|
500
|
+
this.state.isOpen
|
|
501
|
+
? this.patchState({
|
|
502
|
+
activeOptionIndex: Math.min(this.state.activeOptionIndex + 1, this.state.options.length - 1),
|
|
503
|
+
activeSelectionIndex: -1
|
|
504
|
+
})
|
|
505
|
+
: this.show();
|
|
506
|
+
break;
|
|
507
|
+
case 'ArrowUp':
|
|
438
508
|
preventDefault = true;
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
509
|
+
this.state.activeOptionIndex >= 0
|
|
510
|
+
? this.patchState({
|
|
511
|
+
activeOptionIndex: Math.max(this.state.activeOptionIndex - 1, -1),
|
|
512
|
+
activeSelectionIndex: -1
|
|
513
|
+
})
|
|
514
|
+
: this.hide();
|
|
515
|
+
break;
|
|
516
|
+
case 'ArrowLeft':
|
|
517
|
+
if (((_b = this.input) === null || _b === void 0 ? void 0 : _b.selectionStart) === 0) {
|
|
518
|
+
preventDefault = true;
|
|
519
|
+
let index;
|
|
520
|
+
this.state.activeSelectionIndex > 0
|
|
521
|
+
? (index = Math.max(this.state.activeSelectionIndex - 1, -1))
|
|
522
|
+
: (index = this.state.selection.length - 1);
|
|
523
|
+
this.patchState({ activeSelectionIndex: index, activeOptionIndex: -1 });
|
|
442
524
|
}
|
|
443
|
-
|
|
444
|
-
|
|
525
|
+
break;
|
|
526
|
+
case 'ArrowRight':
|
|
527
|
+
if (this.state.activeSelectionIndex >= 0) {
|
|
528
|
+
preventDefault = true;
|
|
529
|
+
let index = -1;
|
|
530
|
+
if (this.state.activeSelectionIndex < this.state.selection.length - 1) {
|
|
531
|
+
index = Math.min(this.state.activeSelectionIndex + 1, this.state.selection.length - 1);
|
|
532
|
+
}
|
|
533
|
+
else if (!this.state.term) {
|
|
534
|
+
index = 0;
|
|
535
|
+
}
|
|
536
|
+
this.patchState({ activeSelectionIndex: index, activeOptionIndex: -1 });
|
|
445
537
|
}
|
|
446
|
-
this.patchState({ activeSelectionIndex: index, activeOptionIndex: -1 });
|
|
447
|
-
}
|
|
448
538
|
}
|
|
449
539
|
if (preventDefault) {
|
|
450
540
|
event.preventDefault();
|
|
451
541
|
event.stopPropagation();
|
|
452
542
|
}
|
|
453
543
|
}
|
|
544
|
+
get tagTextHelp() {
|
|
545
|
+
return this.tagHint && !this.isAlreadyCreated(this.state.term) ? ' (' + this.tagHint + ')' : '';
|
|
546
|
+
}
|
|
547
|
+
isAlreadyCreated(term) {
|
|
548
|
+
return this.state.selection.findIndex(item => item.render.label.toLowerCase() === term.toLowerCase()) >= 0;
|
|
549
|
+
}
|
|
550
|
+
createTag(term) {
|
|
551
|
+
if (term.trim().length && !this.isAlreadyCreated(term)) {
|
|
552
|
+
const value = this.value;
|
|
553
|
+
const tags = value === null || value === void 0 ? void 0 : value.tags;
|
|
554
|
+
const tag = { id: `select-${this.id}-tag-${tags ? tags.length : 0}`, name: term };
|
|
555
|
+
this.select({ item: tag, render: { label: tag.name } });
|
|
556
|
+
}
|
|
557
|
+
this.setTransparentCaret();
|
|
558
|
+
}
|
|
559
|
+
initIds() {
|
|
560
|
+
let ids = [];
|
|
561
|
+
if (this.value) {
|
|
562
|
+
if (!this.tags) {
|
|
563
|
+
if (this.multiple) {
|
|
564
|
+
ids = this.value;
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
ids = [this.value];
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
if (this.multiple) {
|
|
572
|
+
const value = this.value;
|
|
573
|
+
ids = value.ids ? value.ids : [];
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
const value = this.value;
|
|
577
|
+
ids = value.id ? [value.id] : [];
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return ids;
|
|
582
|
+
}
|
|
583
|
+
initTags() {
|
|
584
|
+
let tags = [];
|
|
585
|
+
if (this.value) {
|
|
586
|
+
if (this.multiple) {
|
|
587
|
+
const value = this.value;
|
|
588
|
+
tags = value.tags ? value.tags : [];
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
const value = this.value;
|
|
592
|
+
tags = value.tag ? [value.tag] : [];
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return tags;
|
|
596
|
+
}
|
|
597
|
+
toggleTag(item) {
|
|
598
|
+
this.isAlreadyCreated(item.render.label) ? this.removeTag(item.render.label) : this.createTag(item.render.label);
|
|
599
|
+
}
|
|
600
|
+
removeTag(label) {
|
|
601
|
+
if (this.isAlreadyCreated(label)) {
|
|
602
|
+
const item = this.state.selection.find(item => item.render.label.toLowerCase() === label.toLowerCase());
|
|
603
|
+
item && this.deselect(item.item.id);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
setTransparentCaret() {
|
|
607
|
+
var _a;
|
|
608
|
+
if (!this.multiple) {
|
|
609
|
+
this.hide();
|
|
610
|
+
(_a = this.input) === null || _a === void 0 ? void 0 : _a.classList.add('select-input-transparent-caret');
|
|
611
|
+
}
|
|
612
|
+
}
|
|
454
613
|
static get is() { return "cat-select"; }
|
|
455
614
|
static get encapsulation() { return "shadow"; }
|
|
456
615
|
static get originalStyleUrls() { return {
|
|
@@ -523,15 +682,22 @@ export class CatSelect {
|
|
|
523
682
|
"type": "string",
|
|
524
683
|
"mutable": true,
|
|
525
684
|
"complexType": {
|
|
526
|
-
"original": "string | string[]",
|
|
527
|
-
"resolved": "string | string[] | undefined",
|
|
528
|
-
"references": {
|
|
685
|
+
"original": "string | string[] | CatSelectTaggingValue | CatSelectMultipleTaggingValue",
|
|
686
|
+
"resolved": "CatSelectMultipleTaggingValue | CatSelectTaggingValue | string | string[] | undefined",
|
|
687
|
+
"references": {
|
|
688
|
+
"CatSelectTaggingValue": {
|
|
689
|
+
"location": "local"
|
|
690
|
+
},
|
|
691
|
+
"CatSelectMultipleTaggingValue": {
|
|
692
|
+
"location": "local"
|
|
693
|
+
}
|
|
694
|
+
}
|
|
529
695
|
},
|
|
530
696
|
"required": false,
|
|
531
697
|
"optional": true,
|
|
532
698
|
"docs": {
|
|
533
699
|
"tags": [],
|
|
534
|
-
"text": "The value of the select
|
|
700
|
+
"text": "The value of the select.\n\nThe value of the select depends on whether it is allowed to choose a single item or several items.\nWhen only one item can be selected, the value is the id of the item, in case several items can be selected, the value is an array of ids of the selected items.\n\nIn case the user can add new items to the select (tags activated), the value in the single select is an object (CatSelectTaggingValue) with the id of the item or the name of the created item,\nin the case of multiple select, it is an object (CatSelectMultipleTaggingValue) with the array of the ids of the items selected and the array of the names of the items created"
|
|
535
701
|
},
|
|
536
702
|
"attribute": "value",
|
|
537
703
|
"reflect": false
|
|
@@ -677,6 +843,41 @@ export class CatSelect {
|
|
|
677
843
|
"attribute": "clearable",
|
|
678
844
|
"reflect": false,
|
|
679
845
|
"defaultValue": "false"
|
|
846
|
+
},
|
|
847
|
+
"tags": {
|
|
848
|
+
"type": "boolean",
|
|
849
|
+
"mutable": false,
|
|
850
|
+
"complexType": {
|
|
851
|
+
"original": "boolean",
|
|
852
|
+
"resolved": "boolean",
|
|
853
|
+
"references": {}
|
|
854
|
+
},
|
|
855
|
+
"required": false,
|
|
856
|
+
"optional": false,
|
|
857
|
+
"docs": {
|
|
858
|
+
"tags": [],
|
|
859
|
+
"text": "Whether the select should add new items."
|
|
860
|
+
},
|
|
861
|
+
"attribute": "tags",
|
|
862
|
+
"reflect": false,
|
|
863
|
+
"defaultValue": "false"
|
|
864
|
+
},
|
|
865
|
+
"tagHint": {
|
|
866
|
+
"type": "string",
|
|
867
|
+
"mutable": false,
|
|
868
|
+
"complexType": {
|
|
869
|
+
"original": "string",
|
|
870
|
+
"resolved": "string | undefined",
|
|
871
|
+
"references": {}
|
|
872
|
+
},
|
|
873
|
+
"required": false,
|
|
874
|
+
"optional": true,
|
|
875
|
+
"docs": {
|
|
876
|
+
"tags": [],
|
|
877
|
+
"text": "Optional hint text to be displayed on the new item to be added."
|
|
878
|
+
},
|
|
879
|
+
"attribute": "tag-hint",
|
|
880
|
+
"reflect": false
|
|
680
881
|
}
|
|
681
882
|
}; }
|
|
682
883
|
static get states() { return {
|