@haiilo/catalyst 1.0.2 → 1.1.0
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-78b3fc17.entry.js +10 -0
- package/dist/catalyst/p-78b3fc17.entry.js.map +1 -0
- package/dist/catalyst/scss/utils/_sizing.mixins.scss +1 -1
- package/dist/cjs/cat-alert_23.cjs.entry.js +299 -120
- 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 +17 -18
- package/dist/collection/components/cat-alert/cat-alert.js.map +1 -1
- package/dist/collection/components/cat-checkbox/cat-checkbox.css +1 -1
- package/dist/collection/components/cat-select/cat-select.css +1 -1
- package/dist/collection/components/cat-select/cat-select.js +290 -94
- 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/components/cat-alert.js +14 -12
- package/dist/components/cat-alert.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 +237 -81
- 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/esm/cat-alert_23.entry.js +300 -121
- 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 -2
- package/dist/types/components/cat-select/cat-select.d.ts +32 -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/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();
|
|
@@ -145,11 +182,6 @@ export class CatSelect {
|
|
|
145
182
|
if (this.state.activeSelectionIndex >= 0) {
|
|
146
183
|
this.deselect(this.state.selection[this.state.activeSelectionIndex].item.id);
|
|
147
184
|
}
|
|
148
|
-
else if (this.state.selection.length) {
|
|
149
|
-
const selectionClone = [...this.state.selection];
|
|
150
|
-
selectionClone.pop();
|
|
151
|
-
this.patchState({ selection: selectionClone });
|
|
152
|
-
}
|
|
153
185
|
}
|
|
154
186
|
}
|
|
155
187
|
else if (event.key === 'Tab') {
|
|
@@ -158,7 +190,12 @@ export class CatSelect {
|
|
|
158
190
|
this.patchState({ activeSelectionIndex: -1, activeOptionIndex: -1 });
|
|
159
191
|
}
|
|
160
192
|
else if (this.state.activeOptionIndex >= 0) {
|
|
161
|
-
this.
|
|
193
|
+
if (this.tags && this.state.options[this.state.activeOptionIndex].item.id === `select-${this.id}-option-tag`) {
|
|
194
|
+
this.createTag(this.state.term);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
this.select(this.state.options[this.state.activeOptionIndex]);
|
|
198
|
+
}
|
|
162
199
|
}
|
|
163
200
|
}
|
|
164
201
|
else if (event.key.length === 1) {
|
|
@@ -196,12 +233,28 @@ export class CatSelect {
|
|
|
196
233
|
this.subscription = this.term$
|
|
197
234
|
.asObservable()
|
|
198
235
|
.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
|
-
|
|
236
|
+
.subscribe(items => {
|
|
237
|
+
var _a;
|
|
238
|
+
const options = items === null || items === void 0 ? void 0 : items.map(item => ({
|
|
201
239
|
item,
|
|
202
240
|
render: this.connectorSafe.render(item)
|
|
203
|
-
}))
|
|
204
|
-
|
|
241
|
+
}));
|
|
242
|
+
if (this.tags &&
|
|
243
|
+
this.state.term.trim().length &&
|
|
244
|
+
!options.find(value1 => value1.render.label.toLowerCase() === this.state.term.toLowerCase())) {
|
|
245
|
+
let label;
|
|
246
|
+
if (this.isAlreadyCreated(this.state.term)) {
|
|
247
|
+
label = (_a = this.state.selection.find(item => item.render.label.toLowerCase() === this.state.term.toLowerCase())) === null || _a === void 0 ? void 0 : _a.render.label;
|
|
248
|
+
}
|
|
249
|
+
options.unshift({
|
|
250
|
+
item: { id: `select-${this.id}-option-tag` },
|
|
251
|
+
render: { label: label ? label : this.state.term }
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
this.patchState({
|
|
255
|
+
options
|
|
256
|
+
});
|
|
257
|
+
});
|
|
205
258
|
}
|
|
206
259
|
render() {
|
|
207
260
|
return (h(Host, null,
|
|
@@ -232,28 +285,47 @@ export class CatSelect {
|
|
|
232
285
|
this.hintSection,
|
|
233
286
|
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
287
|
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))))))),
|
|
288
|
+
this.optionsList,
|
|
252
289
|
this.state.isLoading
|
|
253
290
|
? Array.from(Array(CatSelect.SKELETON_COUNT)).map(() => (h("li", { class: "select-option-loading" },
|
|
254
291
|
h("cat-skeleton", { variant: "body", lines: 1 }),
|
|
255
292
|
h("cat-skeleton", { variant: "body", lines: 1 }))))
|
|
256
|
-
: !this.state.options.length &&
|
|
293
|
+
: !this.state.options.length &&
|
|
294
|
+
!this.tags && h("li", { class: "select-option-empty" }, this.i18n.t('select.empty'))))))));
|
|
295
|
+
}
|
|
296
|
+
get optionsList() {
|
|
297
|
+
return this.state.options.map((item, i) => {
|
|
298
|
+
const isTagOption = this.tags && item.item.id === `select-${this.id}-option-tag`;
|
|
299
|
+
const getAriaSelected = () => {
|
|
300
|
+
if (isTagOption) {
|
|
301
|
+
return this.isAlreadyCreated(item.render.label) ? 'true' : 'false';
|
|
302
|
+
}
|
|
303
|
+
return this.isSelected(item.item.id) ? 'true' : 'false';
|
|
304
|
+
};
|
|
305
|
+
const getLabel = () => {
|
|
306
|
+
if (isTagOption) {
|
|
307
|
+
return item.render.label + this.tagTextHelp;
|
|
308
|
+
}
|
|
309
|
+
return item.render.label;
|
|
310
|
+
};
|
|
311
|
+
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 => {
|
|
312
|
+
!isTagOption ? this.toggle(item) : this.toggleTag(item);
|
|
313
|
+
e.stopPropagation();
|
|
314
|
+
} },
|
|
315
|
+
h("span", { slot: "label", class: "select-option-inner" },
|
|
316
|
+
item.render.avatar ? (h("cat-avatar", { label: item.render.label, round: item.render.avatar.round, src: item.render.avatar.src, initials: '' })) : null,
|
|
317
|
+
h("span", { class: "select-option-text" },
|
|
318
|
+
h("span", { class: "select-option-label" }, getLabel()),
|
|
319
|
+
h("span", { class: "select-option-description" }, item.render.description))))) : (h("div", { class: {
|
|
320
|
+
'select-option-inner': true,
|
|
321
|
+
'select-option-single': true,
|
|
322
|
+
'select-option-active': this.state.activeOptionIndex === i
|
|
323
|
+
}, 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 },
|
|
324
|
+
item.render.avatar ? (h("cat-avatar", { label: item.render.label, round: item.render.avatar.round, src: item.render.avatar.src, initials: '' })) : null,
|
|
325
|
+
h("span", { class: "select-option-text" },
|
|
326
|
+
h("span", { class: "select-option-label" }, getLabel()),
|
|
327
|
+
h("span", { class: "select-option-description" }, item.render.description))))));
|
|
328
|
+
});
|
|
257
329
|
}
|
|
258
330
|
get hintSection() {
|
|
259
331
|
const hasSlottedHint = !!this.hostElement.querySelector('[slot="hint"]');
|
|
@@ -266,21 +338,27 @@ export class CatSelect {
|
|
|
266
338
|
throw new Error('CatSelectConnector not set');
|
|
267
339
|
}
|
|
268
340
|
resolve() {
|
|
269
|
-
var _a;
|
|
270
341
|
this.patchState({ isResolving: true });
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
342
|
+
const ids = this.initIds();
|
|
343
|
+
let tags;
|
|
344
|
+
if (this.tags) {
|
|
345
|
+
tags = this.initTags();
|
|
346
|
+
}
|
|
347
|
+
const data$ = ids.length ? this.connectorSafe.resolve(ids).pipe(first()) : of([]);
|
|
348
|
+
data$.pipe(catchError(() => of([]))).subscribe(items => {
|
|
349
|
+
const selection = items.length ? items === null || items === void 0 ? void 0 : items.map(item => ({ item, render: this.connectorSafe.render(item) })) : [];
|
|
350
|
+
if (this.tags) {
|
|
351
|
+
tags === null || tags === void 0 ? void 0 : tags.forEach((tag, index) => {
|
|
352
|
+
const item = { id: `select-${this.id}-tag-${index}`, name: tag };
|
|
353
|
+
selection.push({ item, render: { label: item.name } });
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
this.patchState({
|
|
357
|
+
isResolving: false,
|
|
358
|
+
selection,
|
|
359
|
+
term: !this.multiple && selection.length ? selection[0].render.label : ''
|
|
360
|
+
});
|
|
361
|
+
});
|
|
284
362
|
}
|
|
285
363
|
show() {
|
|
286
364
|
var _a;
|
|
@@ -305,7 +383,6 @@ export class CatSelect {
|
|
|
305
383
|
return this.state.selection.findIndex(s => s.item.id === id) >= 0;
|
|
306
384
|
}
|
|
307
385
|
select(item) {
|
|
308
|
-
var _a;
|
|
309
386
|
if (!this.isSelected(item.item.id)) {
|
|
310
387
|
let newSelection;
|
|
311
388
|
if (this.multiple) {
|
|
@@ -316,11 +393,13 @@ export class CatSelect {
|
|
|
316
393
|
this.search(item.render.label);
|
|
317
394
|
}
|
|
318
395
|
this.patchState({ selection: newSelection });
|
|
396
|
+
if (this.multiple && this.state.term.trim() && this.input) {
|
|
397
|
+
this.patchState({ term: '', activeOptionIndex: -1 });
|
|
398
|
+
this.term$.next('');
|
|
399
|
+
this.input.value = '';
|
|
400
|
+
}
|
|
319
401
|
}
|
|
320
|
-
|
|
321
|
-
this.hide();
|
|
322
|
-
(_a = this.input) === null || _a === void 0 ? void 0 : _a.classList.add('select-input-transparent-caret');
|
|
323
|
-
}
|
|
402
|
+
this.setTransparentCaret();
|
|
324
403
|
}
|
|
325
404
|
deselect(id) {
|
|
326
405
|
if (this.isSelected(id)) {
|
|
@@ -367,7 +446,12 @@ export class CatSelect {
|
|
|
367
446
|
}
|
|
368
447
|
onInput() {
|
|
369
448
|
var _a;
|
|
370
|
-
this.search(((_a = this.input) === null || _a === void 0 ? void 0 : _a.value) || '');
|
|
449
|
+
this.search(((_a = this.input) === null || _a === void 0 ? void 0 : _a.value.trim()) || '');
|
|
450
|
+
if (!this.multiple && this.state.selection.length) {
|
|
451
|
+
const selectionClone = [...this.state.selection];
|
|
452
|
+
selectionClone.pop();
|
|
453
|
+
this.patchState({ selection: selectionClone });
|
|
454
|
+
}
|
|
371
455
|
this.show();
|
|
372
456
|
}
|
|
373
457
|
update() {
|
|
@@ -405,52 +489,122 @@ export class CatSelect {
|
|
|
405
489
|
var _a, _b;
|
|
406
490
|
let preventDefault = false;
|
|
407
491
|
(_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) {
|
|
492
|
+
switch (event.key) {
|
|
493
|
+
case 'ArrowDown':
|
|
428
494
|
preventDefault = true;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
if (this.state.activeSelectionIndex >= 0) {
|
|
495
|
+
this.state.isOpen
|
|
496
|
+
? this.patchState({
|
|
497
|
+
activeOptionIndex: Math.min(this.state.activeOptionIndex + 1, this.state.options.length - 1),
|
|
498
|
+
activeSelectionIndex: -1
|
|
499
|
+
})
|
|
500
|
+
: this.show();
|
|
501
|
+
break;
|
|
502
|
+
case 'ArrowUp':
|
|
438
503
|
preventDefault = true;
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
504
|
+
this.state.activeOptionIndex >= 0
|
|
505
|
+
? this.patchState({
|
|
506
|
+
activeOptionIndex: Math.max(this.state.activeOptionIndex - 1, -1),
|
|
507
|
+
activeSelectionIndex: -1
|
|
508
|
+
})
|
|
509
|
+
: this.hide();
|
|
510
|
+
break;
|
|
511
|
+
case 'ArrowLeft':
|
|
512
|
+
if (((_b = this.input) === null || _b === void 0 ? void 0 : _b.selectionStart) === 0) {
|
|
513
|
+
preventDefault = true;
|
|
514
|
+
let index;
|
|
515
|
+
this.state.activeSelectionIndex > 0
|
|
516
|
+
? (index = Math.max(this.state.activeSelectionIndex - 1, -1))
|
|
517
|
+
: (index = this.state.selection.length - 1);
|
|
518
|
+
this.patchState({ activeSelectionIndex: index, activeOptionIndex: -1 });
|
|
442
519
|
}
|
|
443
|
-
|
|
444
|
-
|
|
520
|
+
break;
|
|
521
|
+
case 'ArrowRight':
|
|
522
|
+
if (this.state.activeSelectionIndex >= 0) {
|
|
523
|
+
preventDefault = true;
|
|
524
|
+
let index = -1;
|
|
525
|
+
if (this.state.activeSelectionIndex < this.state.selection.length - 1) {
|
|
526
|
+
index = Math.min(this.state.activeSelectionIndex + 1, this.state.selection.length - 1);
|
|
527
|
+
}
|
|
528
|
+
else if (!this.state.term) {
|
|
529
|
+
index = 0;
|
|
530
|
+
}
|
|
531
|
+
this.patchState({ activeSelectionIndex: index, activeOptionIndex: -1 });
|
|
445
532
|
}
|
|
446
|
-
this.patchState({ activeSelectionIndex: index, activeOptionIndex: -1 });
|
|
447
|
-
}
|
|
448
533
|
}
|
|
449
534
|
if (preventDefault) {
|
|
450
535
|
event.preventDefault();
|
|
451
536
|
event.stopPropagation();
|
|
452
537
|
}
|
|
453
538
|
}
|
|
539
|
+
get tagTextHelp() {
|
|
540
|
+
return this.tagHint && !this.isAlreadyCreated(this.state.term) ? ' (' + this.tagHint + ')' : '';
|
|
541
|
+
}
|
|
542
|
+
isAlreadyCreated(term) {
|
|
543
|
+
return this.state.selection.findIndex(item => item.render.label.toLowerCase() === term.toLowerCase()) >= 0;
|
|
544
|
+
}
|
|
545
|
+
createTag(term) {
|
|
546
|
+
if (term.trim().length && !this.isAlreadyCreated(term)) {
|
|
547
|
+
const value = this.value;
|
|
548
|
+
const tags = value === null || value === void 0 ? void 0 : value.tags;
|
|
549
|
+
const tag = { id: `select-${this.id}-tag-${tags ? tags.length : 0}`, name: term };
|
|
550
|
+
this.select({ item: tag, render: { label: tag.name } });
|
|
551
|
+
}
|
|
552
|
+
this.setTransparentCaret();
|
|
553
|
+
}
|
|
554
|
+
initIds() {
|
|
555
|
+
let ids = [];
|
|
556
|
+
if (this.value) {
|
|
557
|
+
if (!this.tags) {
|
|
558
|
+
if (this.multiple) {
|
|
559
|
+
ids = this.value;
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
ids = [this.value];
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
if (this.multiple) {
|
|
567
|
+
const value = this.value;
|
|
568
|
+
ids = value.ids ? value.ids : [];
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
const value = this.value;
|
|
572
|
+
ids = value.id ? [value.id] : [];
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return ids;
|
|
577
|
+
}
|
|
578
|
+
initTags() {
|
|
579
|
+
let tags = [];
|
|
580
|
+
if (this.value) {
|
|
581
|
+
if (this.multiple) {
|
|
582
|
+
const value = this.value;
|
|
583
|
+
tags = value.tags ? value.tags : [];
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
const value = this.value;
|
|
587
|
+
tags = value.tag ? [value.tag] : [];
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return tags;
|
|
591
|
+
}
|
|
592
|
+
toggleTag(item) {
|
|
593
|
+
this.isAlreadyCreated(item.render.label) ? this.removeTag(item.render.label) : this.createTag(item.render.label);
|
|
594
|
+
}
|
|
595
|
+
removeTag(label) {
|
|
596
|
+
if (this.isAlreadyCreated(label)) {
|
|
597
|
+
const item = this.state.selection.find(item => item.render.label.toLowerCase() === label.toLowerCase());
|
|
598
|
+
item && this.deselect(item.item.id);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
setTransparentCaret() {
|
|
602
|
+
var _a;
|
|
603
|
+
if (!this.multiple) {
|
|
604
|
+
this.hide();
|
|
605
|
+
(_a = this.input) === null || _a === void 0 ? void 0 : _a.classList.add('select-input-transparent-caret');
|
|
606
|
+
}
|
|
607
|
+
}
|
|
454
608
|
static get is() { return "cat-select"; }
|
|
455
609
|
static get encapsulation() { return "shadow"; }
|
|
456
610
|
static get originalStyleUrls() { return {
|
|
@@ -523,15 +677,22 @@ export class CatSelect {
|
|
|
523
677
|
"type": "string",
|
|
524
678
|
"mutable": true,
|
|
525
679
|
"complexType": {
|
|
526
|
-
"original": "string | string[]",
|
|
527
|
-
"resolved": "string | string[] | undefined",
|
|
528
|
-
"references": {
|
|
680
|
+
"original": "string | string[] | CatSelectTaggingValue | CatSelectMultipleTaggingValue",
|
|
681
|
+
"resolved": "CatSelectMultipleTaggingValue | CatSelectTaggingValue | string | string[] | undefined",
|
|
682
|
+
"references": {
|
|
683
|
+
"CatSelectTaggingValue": {
|
|
684
|
+
"location": "local"
|
|
685
|
+
},
|
|
686
|
+
"CatSelectMultipleTaggingValue": {
|
|
687
|
+
"location": "local"
|
|
688
|
+
}
|
|
689
|
+
}
|
|
529
690
|
},
|
|
530
691
|
"required": false,
|
|
531
692
|
"optional": true,
|
|
532
693
|
"docs": {
|
|
533
694
|
"tags": [],
|
|
534
|
-
"text": "The value of the select
|
|
695
|
+
"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
696
|
},
|
|
536
697
|
"attribute": "value",
|
|
537
698
|
"reflect": false
|
|
@@ -677,6 +838,41 @@ export class CatSelect {
|
|
|
677
838
|
"attribute": "clearable",
|
|
678
839
|
"reflect": false,
|
|
679
840
|
"defaultValue": "false"
|
|
841
|
+
},
|
|
842
|
+
"tags": {
|
|
843
|
+
"type": "boolean",
|
|
844
|
+
"mutable": false,
|
|
845
|
+
"complexType": {
|
|
846
|
+
"original": "boolean",
|
|
847
|
+
"resolved": "boolean",
|
|
848
|
+
"references": {}
|
|
849
|
+
},
|
|
850
|
+
"required": false,
|
|
851
|
+
"optional": false,
|
|
852
|
+
"docs": {
|
|
853
|
+
"tags": [],
|
|
854
|
+
"text": "Whether the select should add new items."
|
|
855
|
+
},
|
|
856
|
+
"attribute": "tags",
|
|
857
|
+
"reflect": false,
|
|
858
|
+
"defaultValue": "false"
|
|
859
|
+
},
|
|
860
|
+
"tagHint": {
|
|
861
|
+
"type": "string",
|
|
862
|
+
"mutable": false,
|
|
863
|
+
"complexType": {
|
|
864
|
+
"original": "string",
|
|
865
|
+
"resolved": "string | undefined",
|
|
866
|
+
"references": {}
|
|
867
|
+
},
|
|
868
|
+
"required": false,
|
|
869
|
+
"optional": true,
|
|
870
|
+
"docs": {
|
|
871
|
+
"tags": [],
|
|
872
|
+
"text": "Optional hint text to be displayed on the new item to be added."
|
|
873
|
+
},
|
|
874
|
+
"attribute": "tag-hint",
|
|
875
|
+
"reflect": false
|
|
680
876
|
}
|
|
681
877
|
}; }
|
|
682
878
|
static get states() { return {
|