@haiilo/catalyst 0.14.2 → 0.15.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.
Files changed (65) hide show
  1. package/dist/catalyst/catalyst.esm.js +1 -1
  2. package/dist/catalyst/catalyst.esm.js.map +1 -1
  3. package/dist/catalyst/index.cdn.js +42 -15
  4. package/dist/catalyst/p-311d10a7.entry.js +12 -0
  5. package/dist/catalyst/p-311d10a7.entry.js.map +1 -0
  6. package/dist/cjs/{cat-alert_22.cjs.entry.js → cat-alert_24.cjs.entry.js} +2229 -19
  7. package/dist/cjs/cat-alert_24.cjs.entry.js.map +1 -0
  8. package/dist/cjs/catalyst.cjs.js +1 -1
  9. package/dist/cjs/loader.cjs.js +1 -1
  10. package/dist/collection/collection-manifest.json +2 -0
  11. package/dist/collection/components/cat-badge/cat-badge.css +5 -5
  12. package/dist/collection/components/cat-button/cat-button.css +4 -0
  13. package/dist/collection/components/cat-checkbox/cat-checkbox.css +1 -0
  14. package/dist/collection/components/cat-input/cat-input.css +1 -0
  15. package/dist/collection/components/cat-scrollable/cat-scrollable.css +0 -1
  16. package/dist/collection/components/cat-select-remote/cat-select-remote.css +209 -0
  17. package/dist/collection/components/cat-select-remote/cat-select-remote.js +798 -0
  18. package/dist/collection/components/cat-select-remote/cat-select-remote.js.map +1 -0
  19. package/dist/collection/components/cat-select-remote-test/cat-select-remote-test.js +1288 -0
  20. package/dist/collection/components/cat-select-remote-test/cat-select-remote-test.js.map +1 -0
  21. package/dist/collection/index.cdn.js +42 -15
  22. package/dist/collection/index.js.map +1 -1
  23. package/dist/components/cat-badge.js +1 -1
  24. package/dist/components/cat-badge.js.map +1 -1
  25. package/dist/components/cat-button2.js +1 -1
  26. package/dist/components/cat-button2.js.map +1 -1
  27. package/dist/components/cat-checkbox.js +1 -115
  28. package/dist/components/cat-checkbox.js.map +1 -1
  29. package/dist/components/cat-checkbox2.js +119 -0
  30. package/dist/components/cat-checkbox2.js.map +1 -0
  31. package/dist/components/cat-input.js +1 -1
  32. package/dist/components/cat-input.js.map +1 -1
  33. package/dist/components/cat-scrollable.js +1 -1355
  34. package/dist/components/cat-scrollable.js.map +1 -1
  35. package/dist/components/cat-scrollable2.js +1359 -0
  36. package/dist/components/cat-scrollable2.js.map +1 -0
  37. package/dist/components/cat-select-remote-test.d.ts +11 -0
  38. package/dist/components/cat-select-remote-test.js +1368 -0
  39. package/dist/components/cat-select-remote-test.js.map +1 -0
  40. package/dist/components/cat-select-remote.d.ts +11 -0
  41. package/dist/components/cat-select-remote.js +8 -0
  42. package/dist/components/cat-select-remote.js.map +1 -0
  43. package/dist/components/cat-select-remote2.js +982 -0
  44. package/dist/components/cat-select-remote2.js.map +1 -0
  45. package/dist/components/cat-skeleton.js +1 -71
  46. package/dist/components/cat-skeleton.js.map +1 -1
  47. package/dist/components/cat-skeleton2.js +75 -0
  48. package/dist/components/cat-skeleton2.js.map +1 -0
  49. package/dist/components/index.d.ts +2 -0
  50. package/dist/components/index.js +2 -0
  51. package/dist/components/index.js.map +1 -1
  52. package/dist/esm/{cat-alert_22.entry.js → cat-alert_24.entry.js} +2228 -20
  53. package/dist/esm/cat-alert_24.entry.js.map +1 -0
  54. package/dist/esm/catalyst.js +1 -1
  55. package/dist/esm/loader.js +1 -1
  56. package/dist/types/components/cat-select-remote/autosize.d.ts +1 -0
  57. package/dist/types/components/cat-select-remote/cat-select-remote.d.ts +145 -0
  58. package/dist/types/components/cat-select-remote-test/cat-select-remote-test.d.ts +6 -0
  59. package/dist/types/components.d.ts +145 -0
  60. package/dist/types/index.d.ts +3 -0
  61. package/package.json +5 -4
  62. package/dist/catalyst/p-45547af1.entry.js +0 -12
  63. package/dist/catalyst/p-45547af1.entry.js.map +0 -1
  64. package/dist/cjs/cat-alert_22.cjs.entry.js.map +0 -1
  65. package/dist/esm/cat-alert_22.entry.js.map +0 -1
@@ -0,0 +1,798 @@
1
+ import { autoUpdate, computePosition, offset } from '@floating-ui/dom';
2
+ import { Component, Element, Event, h, Host, Listen, Method, Prop, State, Watch } from '@stencil/core';
3
+ import autosizeInput from 'autosize-input';
4
+ import { catchError, debounce, distinctUntilChanged, filter, first, of, scan, startWith, Subject, switchMap, takeWhile, tap, timer } from 'rxjs';
5
+ import { CatI18nRegistry } from '../cat-i18n/cat-i18n-registry';
6
+ import log from 'loglevel';
7
+ import { CatFormHint } from '../cat-form-hint/cat-form-hint';
8
+ const INIT_STATE = {
9
+ term: '',
10
+ isOpen: false,
11
+ isLoading: false,
12
+ isResolving: false,
13
+ options: [],
14
+ selection: [],
15
+ activeOptionIndex: -1,
16
+ activeSelectionIndex: -1
17
+ };
18
+ let nextUniqueId = 0;
19
+ export class CatSelectRemote {
20
+ constructor() {
21
+ this.i18n = CatI18nRegistry.getInstance();
22
+ this.id = `cat-input-${nextUniqueId++}`;
23
+ this.term$ = new Subject();
24
+ this.more$ = new Subject();
25
+ this.state = INIT_STATE;
26
+ this.hasSlottedLabel = false;
27
+ /**
28
+ * Enable multiple selection.
29
+ */
30
+ this.multiple = false;
31
+ /**
32
+ * The debounce time for the search.
33
+ */
34
+ this.debounce = 250;
35
+ /**
36
+ * The placement of the select.
37
+ */
38
+ this.placement = 'bottom-start';
39
+ /**
40
+ * Whether the select is disabled.
41
+ */
42
+ this.disabled = false;
43
+ /**
44
+ * The label for the select.
45
+ */
46
+ this.label = '';
47
+ /**
48
+ * The name of the form control. Submitted with the form as part of a name/value pair.
49
+ */
50
+ this.name = '';
51
+ /**
52
+ * Visually hide the label, but still show it to assistive technologies like screen readers.
53
+ */
54
+ this.labelHidden = false;
55
+ /**
56
+ * A value is required or must be check for the form to be submittable.
57
+ */
58
+ this.required = false;
59
+ /**
60
+ * Whether the select should show a clear button.
61
+ */
62
+ this.clearable = false;
63
+ }
64
+ onConnectorChange(connector) {
65
+ this.reset(connector);
66
+ this.resolve();
67
+ }
68
+ onStateChange(newState, oldState) {
69
+ var _a;
70
+ const changed = (key) => newState[key] !== oldState[key];
71
+ if (changed('activeOptionIndex')) {
72
+ if (this.state.activeOptionIndex >= 0) {
73
+ const option = (_a = this.dropdown) === null || _a === void 0 ? void 0 : _a.querySelector(`#select-${this.id}-option-${this.state.activeOptionIndex}`);
74
+ option === null || option === void 0 ? void 0 : option.scrollIntoView({ block: 'nearest' });
75
+ }
76
+ }
77
+ if (changed('selection')) {
78
+ if (!this.multiple && this.state.selection.length) {
79
+ this.hide();
80
+ }
81
+ const idsSelected = this.state.selection.map(item => item.item.id);
82
+ if (this.multiple) {
83
+ this.value = idsSelected;
84
+ }
85
+ else {
86
+ this.value = idsSelected.length ? idsSelected[0] : '';
87
+ }
88
+ this.catChange.emit();
89
+ }
90
+ }
91
+ componentDidLoad() {
92
+ if (this.input) {
93
+ autosizeInput(this.input);
94
+ }
95
+ if (this.trigger && this.dropdown) {
96
+ autoUpdate(this.trigger, this.dropdown, () => this.update());
97
+ }
98
+ }
99
+ componentWillRender() {
100
+ this.hasSlottedLabel = !!this.hostElement.querySelector('[slot="label"]');
101
+ if (!this.label && !this.hasSlottedLabel) {
102
+ log.error('[A11y] Missing ARIA label on select', this);
103
+ }
104
+ }
105
+ onBlur(event) {
106
+ if (!this.multiple && this.state.activeOptionIndex >= 0) {
107
+ this.select(this.state.options[this.state.activeOptionIndex]);
108
+ }
109
+ this.hide();
110
+ this.patchState({ activeSelectionIndex: -1 });
111
+ this.catBlur.emit(event);
112
+ }
113
+ onKeyDown(event) {
114
+ var _a, _b, _c, _d, _e;
115
+ const isInputFocused = ((_a = this.hostElement.shadowRoot) === null || _a === void 0 ? void 0 : _a.activeElement) === this.input;
116
+ if (['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
117
+ this.onArrowKeyDown(event);
118
+ }
119
+ else if (['Enter', ' '].includes(event.key)) {
120
+ if (isInputFocused && this.state.activeOptionIndex >= 0) {
121
+ event.preventDefault();
122
+ if (this.multiple) {
123
+ this.toggle(this.state.options[this.state.activeOptionIndex]);
124
+ }
125
+ else {
126
+ this.select(this.state.options[this.state.activeOptionIndex]);
127
+ }
128
+ }
129
+ }
130
+ else if (event.key === 'Escape') {
131
+ this.hide();
132
+ }
133
+ else if (event.key === 'Backspace' || event.key === 'Delete') {
134
+ (_b = this.input) === null || _b === void 0 ? void 0 : _b.focus();
135
+ if (!this.multiple || !this.state.term || (((_c = this.input) === null || _c === void 0 ? void 0 : _c.selectionStart) === 0 && event.key === 'Backspace')) {
136
+ if (this.state.activeSelectionIndex >= 0) {
137
+ this.deselect(this.state.selection[this.state.activeSelectionIndex].item.id);
138
+ }
139
+ else if (this.state.selection.length) {
140
+ const selectionClone = [...this.state.selection];
141
+ selectionClone.pop();
142
+ this.patchState({ selection: selectionClone });
143
+ }
144
+ }
145
+ }
146
+ else if (event.key === 'Tab') {
147
+ (_d = this.trigger) === null || _d === void 0 ? void 0 : _d.setAttribute('tabindex', '-1');
148
+ if (this.multiple) {
149
+ this.patchState({ activeSelectionIndex: -1, activeOptionIndex: -1 });
150
+ }
151
+ else if (this.state.activeOptionIndex >= 0) {
152
+ this.select(this.state.options[this.state.activeOptionIndex]);
153
+ }
154
+ }
155
+ else if (event.key.length === 1) {
156
+ (_e = this.input) === null || _e === void 0 ? void 0 : _e.focus();
157
+ }
158
+ }
159
+ onKeyUp(event) {
160
+ var _a, _b, _c, _d, _e;
161
+ if (event.key === 'Tab' && !event.shiftKey) {
162
+ ((_a = this.hostElement.shadowRoot) === null || _a === void 0 ? void 0 : _a.activeElement) === this.trigger && ((_b = this.input) === null || _b === void 0 ? void 0 : _b.focus());
163
+ if (((_c = this.hostElement.shadowRoot) === null || _c === void 0 ? void 0 : _c.activeElement) === this.input) {
164
+ this.show();
165
+ }
166
+ }
167
+ else if (event.key === 'Tab' && event.shiftKey) {
168
+ const clearButton = (_d = this.trigger) === null || _d === void 0 ? void 0 : _d.querySelector(`#select-clear-btn-${this.id}`);
169
+ if (clearButton) {
170
+ ((_e = this.hostElement.shadowRoot) === null || _e === void 0 ? void 0 : _e.activeElement) === clearButton && this.show();
171
+ }
172
+ else {
173
+ this.show();
174
+ }
175
+ }
176
+ }
177
+ async connect(connector) {
178
+ var _a;
179
+ this.connector = connector;
180
+ let number$;
181
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
182
+ this.subscription = this.term$
183
+ .asObservable()
184
+ .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], []))))
185
+ .subscribe(items => this.patchState({
186
+ options: items === null || items === void 0 ? void 0 : items.map(item => ({
187
+ item,
188
+ render: this.connectorSafe.render(item)
189
+ }))
190
+ }));
191
+ }
192
+ render() {
193
+ return (h(Host, null,
194
+ (this.hasSlottedLabel || this.label) && (h("label", { htmlFor: this.id, class: { hidden: this.labelHidden } },
195
+ h("span", { part: "label" },
196
+ (this.hasSlottedLabel && h("slot", { name: "label" })) || this.label,
197
+ !this.required && (h("span", { class: "input-optional", "aria-hidden": "true" },
198
+ "(",
199
+ this.i18n.t('input.optional'),
200
+ ")"))))),
201
+ h("div", { class: { 'select-wrapper': true, 'select-disabled': this.disabled }, ref: el => (this.trigger = el), id: this.id, role: "combobox", "aria-expanded": this.state.isOpen || this.isPillboxActive(), "aria-controls": this.isPillboxActive() ? `select-pillbox-${this.id}` : `select-listbox-${this.id}`, "aria-required": this.required, "aria-activedescendant": this.activeDescendant, onClick: e => this.onClick(e) },
202
+ h("div", { class: "select-wrapper-inner" },
203
+ this.multiple && this.state.selection.length ? (h("div", { id: `select-pillbox-${this.id}`, role: "listbox", "aria-orientation": "horizontal", class: "select-pills" }, this.state.selection.map((item, i) => (h("span", { class: {
204
+ pill: true,
205
+ 'select-no-open': true,
206
+ 'select-option-active': this.state.activeSelectionIndex === i
207
+ }, role: "option", "aria-selected": "true", id: `select-${this.id}-selection-${i}` },
208
+ h("span", null, item.render.label),
209
+ !this.disabled && (h("cat-button", { size: "xs", variant: "text", icon: "16-cross", iconOnly: true, a11yLabel: this.i18n.t('select.deselect'), onClick: () => this.deselect(item.item.id), tabIndex: -1 }))))))) : null,
210
+ h("input", { class: "select-input", ref: el => (this.input = el), "aria-controls": this.isPillboxActive() ? `select-pillbox-${this.id}` : `select-listbox-${this.id}`, "aria-activedescendant": this.activeDescendant, onInput: () => this.onInput(), value: !this.multiple ? this.state.term : undefined, placeholder: this.placeholder, disabled: this.disabled || this.state.isResolving })),
211
+ this.state.isResolving && h("cat-spinner", null),
212
+ (this.state.selection.length || this.state.term.length) &&
213
+ !this.disabled &&
214
+ !this.state.isResolving &&
215
+ this.clearable ? (h("cat-button", { id: `select-clear-btn-${this.id}`, iconOnly: true, icon: "cross-circle-outlined", variant: "text", size: "s", a11yLabel: this.i18n.t('select.clear'), onClick: () => this.clear() })) : null,
216
+ !this.state.isResolving && (h("cat-button", { iconOnly: true, icon: "chevron-down-outlined", class: { 'select-btn': true, 'select-btn-open': this.state.isOpen }, variant: "text", size: "s", a11yLabel: this.state.isOpen ? this.i18n.t('select.close') : this.i18n.t('select.open'), "aria-controls": `select-listbox-${this.id}`, "aria-expanded": this.state.isOpen, tabIndex: -1, disabled: this.disabled || this.state.isResolving }))),
217
+ this.hintSection,
218
+ 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() },
219
+ h("ul", { class: "select-options", role: "listbox", "aria-multiselectable": this.multiple, "aria-setsize": this.state.totalElements, id: `select-listbox-${this.id}` },
220
+ this.state.options.map((item, i) => (h("li", { role: "option", class: "select-option", id: `select-${this.id}-option-${i}`, "aria-selected": this.isSelected(item.item.id) ? 'true' : 'false' }, this.multiple ? (h("cat-checkbox", { class: { 'select-option-active': this.state.activeOptionIndex === i }, checked: this.isSelected(item.item.id), tabIndex: -1, labelLeft: true, onFocus: () => { var _a; return (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus(); }, onCatChange: e => {
221
+ this.toggle(item);
222
+ e.stopPropagation();
223
+ } },
224
+ h("span", { slot: "label", class: "select-option" },
225
+ h("span", { class: "select-option-label" }, item.render.label),
226
+ h("span", { class: "select-option-description" }, item.render.description)))) : (h("div", { class: {
227
+ 'select-option-single': true,
228
+ 'select-option-active': this.state.activeOptionIndex === i
229
+ }, onFocus: () => { var _a; return (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus(); }, onClick: () => this.select(item), tabIndex: -1 },
230
+ h("span", { class: "select-option-label" }, item.render.label),
231
+ h("span", { class: "select-option-description" }, item.render.description)))))),
232
+ this.state.isLoading
233
+ ? Array.from(Array(CatSelectRemote.SKELETON_COUNT)).map(() => (h("li", { class: "select-option-loading" },
234
+ h("cat-skeleton", { variant: "body", lines: 1 }),
235
+ h("cat-skeleton", { variant: "body", lines: 1 }))))
236
+ : !this.state.options.length && h("li", { class: "select-option-empty" }, this.i18n.t('select.empty'))))))));
237
+ }
238
+ get hintSection() {
239
+ const hasSlottedHint = !!this.hostElement.querySelector('[slot="hint"]');
240
+ return ((this.hint || hasSlottedHint) && (h(CatFormHint, { hint: this.hint, slottedHint: hasSlottedHint && h("slot", { name: "hint" }) })));
241
+ }
242
+ get connectorSafe() {
243
+ if (this.connector) {
244
+ return this.connector;
245
+ }
246
+ throw new Error('CatSelectRemoteConnector not set');
247
+ }
248
+ resolve() {
249
+ var _a;
250
+ this.patchState({ isResolving: true });
251
+ let ids;
252
+ if (this.multiple) {
253
+ ids = this.value;
254
+ }
255
+ else {
256
+ ids = [this.value];
257
+ }
258
+ const data$ = ((_a = this.value) === null || _a === void 0 ? void 0 : _a.length) ? this.connectorSafe.resolve(ids).pipe(first()) : of([]);
259
+ data$.pipe(catchError(() => of([]))).subscribe(items => this.patchState({
260
+ isResolving: false,
261
+ selection: items === null || items === void 0 ? void 0 : items.map(item => ({ item, render: this.connectorSafe.render(item) })),
262
+ term: !this.multiple && items.length ? this.connectorSafe.render(items[0]).label : ''
263
+ }));
264
+ }
265
+ show() {
266
+ var _a;
267
+ if (!this.state.isOpen) {
268
+ this.patchState({ isOpen: true });
269
+ this.catOpen.emit();
270
+ this.term$.next(this.state.term);
271
+ (_a = this.input) === null || _a === void 0 ? void 0 : _a.classList.remove('select-input-transparent-caret');
272
+ }
273
+ }
274
+ hide() {
275
+ if (this.state.isOpen) {
276
+ this.patchState({ isOpen: false, activeOptionIndex: -1 });
277
+ this.catClose.emit();
278
+ }
279
+ }
280
+ search(term) {
281
+ this.patchState({ term, activeOptionIndex: -1, activeSelectionIndex: -1 });
282
+ this.term$.next(term);
283
+ }
284
+ isSelected(id) {
285
+ return this.state.selection.findIndex(s => s.item.id === id) >= 0;
286
+ }
287
+ select(item) {
288
+ var _a;
289
+ if (!this.isSelected(item.item.id)) {
290
+ let newSelection;
291
+ if (this.multiple) {
292
+ newSelection = [...this.state.selection, item];
293
+ }
294
+ else {
295
+ newSelection = [item];
296
+ this.search(item.render.label);
297
+ }
298
+ this.patchState({ selection: newSelection });
299
+ }
300
+ if (!this.multiple) {
301
+ this.hide();
302
+ (_a = this.input) === null || _a === void 0 ? void 0 : _a.classList.add('select-input-transparent-caret');
303
+ }
304
+ }
305
+ deselect(id) {
306
+ if (this.isSelected(id)) {
307
+ this.patchState({
308
+ selection: this.state.selection.filter(item => item.item.id !== id),
309
+ activeSelectionIndex: -1
310
+ });
311
+ }
312
+ }
313
+ toggle(item) {
314
+ this.isSelected(item.item.id) ? this.deselect(item.item.id) : this.select(item);
315
+ }
316
+ clear() {
317
+ if (this.input && this.state.term) {
318
+ this.patchState({ selection: [], options: [], term: '', activeOptionIndex: -1 });
319
+ this.term$.next('');
320
+ this.input.value = '';
321
+ }
322
+ else {
323
+ this.patchState({ selection: [] });
324
+ }
325
+ }
326
+ reset(connector) {
327
+ var _a;
328
+ this.connector = connector !== null && connector !== void 0 ? connector : this.connector;
329
+ (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
330
+ this.subscription = undefined;
331
+ this.state = INIT_STATE;
332
+ }
333
+ onClick(event) {
334
+ var _a, _b;
335
+ const elem = event.target;
336
+ (_a = this.trigger) === null || _a === void 0 ? void 0 : _a.setAttribute('tabindex', '0');
337
+ (_b = this.input) === null || _b === void 0 ? void 0 : _b.focus();
338
+ if (elem === this.trigger ||
339
+ elem === this.input ||
340
+ elem.classList.contains('select-btn') ||
341
+ elem.nodeName === 'SPAN') {
342
+ this.state.isOpen ? this.hide() : this.show();
343
+ }
344
+ }
345
+ onInput() {
346
+ var _a;
347
+ this.search(((_a = this.input) === null || _a === void 0 ? void 0 : _a.value) || '');
348
+ this.show();
349
+ }
350
+ update() {
351
+ if (this.trigger && this.dropdown) {
352
+ computePosition(this.trigger, this.dropdown, {
353
+ placement: this.placement,
354
+ middleware: [offset(CatSelectRemote.DROPDOWN_OFFSET)]
355
+ }).then(({ x, y }) => {
356
+ if (this.dropdown) {
357
+ Object.assign(this.dropdown.style, {
358
+ left: `${x}px`,
359
+ top: `${y}px`
360
+ });
361
+ }
362
+ });
363
+ }
364
+ }
365
+ patchState(update) {
366
+ this.state = Object.assign(Object.assign({}, this.state), update);
367
+ }
368
+ isPillboxActive() {
369
+ return this.state.activeSelectionIndex >= 0;
370
+ }
371
+ get activeDescendant() {
372
+ let activeDescendant = undefined;
373
+ if (this.state.activeOptionIndex >= 0) {
374
+ activeDescendant = `select-${this.id}-option-${this.state.activeOptionIndex}`;
375
+ }
376
+ else if (this.state.activeSelectionIndex >= 0) {
377
+ activeDescendant = `select-${this.id}-selection-${this.state.activeSelectionIndex}`;
378
+ }
379
+ return activeDescendant;
380
+ }
381
+ onArrowKeyDown(event) {
382
+ var _a, _b;
383
+ let preventDefault = false;
384
+ (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus();
385
+ if (event.key === 'ArrowDown') {
386
+ preventDefault = true;
387
+ this.state.isOpen
388
+ ? this.patchState({
389
+ activeOptionIndex: Math.min(this.state.activeOptionIndex + 1, this.state.options.length - 1),
390
+ activeSelectionIndex: -1
391
+ })
392
+ : this.show();
393
+ }
394
+ else if (event.key === 'ArrowUp') {
395
+ preventDefault = true;
396
+ this.state.activeOptionIndex >= 0
397
+ ? this.patchState({
398
+ activeOptionIndex: Math.max(this.state.activeOptionIndex - 1, -1),
399
+ activeSelectionIndex: -1
400
+ })
401
+ : this.hide();
402
+ }
403
+ else if (event.key === 'ArrowLeft') {
404
+ if (((_b = this.input) === null || _b === void 0 ? void 0 : _b.selectionStart) === 0) {
405
+ preventDefault = true;
406
+ let index;
407
+ this.state.activeSelectionIndex > 0
408
+ ? (index = Math.max(this.state.activeSelectionIndex - 1, -1))
409
+ : (index = this.state.selection.length - 1);
410
+ this.patchState({ activeSelectionIndex: index, activeOptionIndex: -1 });
411
+ }
412
+ }
413
+ else if (event.key === 'ArrowRight') {
414
+ if (this.state.activeSelectionIndex >= 0) {
415
+ preventDefault = true;
416
+ let index = -1;
417
+ if (this.state.activeSelectionIndex < this.state.selection.length - 1) {
418
+ index = Math.min(this.state.activeSelectionIndex + 1, this.state.selection.length - 1);
419
+ }
420
+ else if (!this.state.term) {
421
+ index = 0;
422
+ }
423
+ this.patchState({ activeSelectionIndex: index, activeOptionIndex: -1 });
424
+ }
425
+ }
426
+ if (preventDefault) {
427
+ event.preventDefault();
428
+ event.stopPropagation();
429
+ }
430
+ }
431
+ static get is() { return "cat-select-remote"; }
432
+ static get encapsulation() { return "shadow"; }
433
+ static get originalStyleUrls() { return {
434
+ "$": ["cat-select-remote.scss"]
435
+ }; }
436
+ static get styleUrls() { return {
437
+ "$": ["cat-select-remote.css"]
438
+ }; }
439
+ static get properties() { return {
440
+ "multiple": {
441
+ "type": "boolean",
442
+ "mutable": false,
443
+ "complexType": {
444
+ "original": "boolean",
445
+ "resolved": "boolean",
446
+ "references": {}
447
+ },
448
+ "required": false,
449
+ "optional": false,
450
+ "docs": {
451
+ "tags": [],
452
+ "text": "Enable multiple selection."
453
+ },
454
+ "attribute": "multiple",
455
+ "reflect": false,
456
+ "defaultValue": "false"
457
+ },
458
+ "debounce": {
459
+ "type": "number",
460
+ "mutable": false,
461
+ "complexType": {
462
+ "original": "number",
463
+ "resolved": "number",
464
+ "references": {}
465
+ },
466
+ "required": false,
467
+ "optional": false,
468
+ "docs": {
469
+ "tags": [],
470
+ "text": "The debounce time for the search."
471
+ },
472
+ "attribute": "debounce",
473
+ "reflect": false,
474
+ "defaultValue": "250"
475
+ },
476
+ "placement": {
477
+ "type": "string",
478
+ "mutable": false,
479
+ "complexType": {
480
+ "original": "Placement",
481
+ "resolved": "\"bottom\" | \"bottom-end\" | \"bottom-start\" | \"left\" | \"left-end\" | \"left-start\" | \"right\" | \"right-end\" | \"right-start\" | \"top\" | \"top-end\" | \"top-start\"",
482
+ "references": {
483
+ "Placement": {
484
+ "location": "import",
485
+ "path": "@floating-ui/dom"
486
+ }
487
+ }
488
+ },
489
+ "required": false,
490
+ "optional": false,
491
+ "docs": {
492
+ "tags": [],
493
+ "text": "The placement of the select."
494
+ },
495
+ "attribute": "placement",
496
+ "reflect": false,
497
+ "defaultValue": "'bottom-start'"
498
+ },
499
+ "value": {
500
+ "type": "string",
501
+ "mutable": true,
502
+ "complexType": {
503
+ "original": "string | string[]",
504
+ "resolved": "string | string[] | undefined",
505
+ "references": {}
506
+ },
507
+ "required": false,
508
+ "optional": true,
509
+ "docs": {
510
+ "tags": [],
511
+ "text": "The value of the select."
512
+ },
513
+ "attribute": "value",
514
+ "reflect": false
515
+ },
516
+ "disabled": {
517
+ "type": "boolean",
518
+ "mutable": false,
519
+ "complexType": {
520
+ "original": "boolean",
521
+ "resolved": "boolean",
522
+ "references": {}
523
+ },
524
+ "required": false,
525
+ "optional": false,
526
+ "docs": {
527
+ "tags": [],
528
+ "text": "Whether the select is disabled."
529
+ },
530
+ "attribute": "disabled",
531
+ "reflect": false,
532
+ "defaultValue": "false"
533
+ },
534
+ "placeholder": {
535
+ "type": "string",
536
+ "mutable": false,
537
+ "complexType": {
538
+ "original": "string",
539
+ "resolved": "string | undefined",
540
+ "references": {}
541
+ },
542
+ "required": false,
543
+ "optional": true,
544
+ "docs": {
545
+ "tags": [],
546
+ "text": "The placeholder text to display within the select."
547
+ },
548
+ "attribute": "placeholder",
549
+ "reflect": false
550
+ },
551
+ "hint": {
552
+ "type": "string",
553
+ "mutable": false,
554
+ "complexType": {
555
+ "original": "string | string[]",
556
+ "resolved": "string | string[] | undefined",
557
+ "references": {}
558
+ },
559
+ "required": false,
560
+ "optional": true,
561
+ "docs": {
562
+ "tags": [],
563
+ "text": "Optional hint text(s) to be displayed with the select."
564
+ },
565
+ "attribute": "hint",
566
+ "reflect": false
567
+ },
568
+ "label": {
569
+ "type": "string",
570
+ "mutable": false,
571
+ "complexType": {
572
+ "original": "string",
573
+ "resolved": "string",
574
+ "references": {}
575
+ },
576
+ "required": false,
577
+ "optional": false,
578
+ "docs": {
579
+ "tags": [],
580
+ "text": "The label for the select."
581
+ },
582
+ "attribute": "label",
583
+ "reflect": false,
584
+ "defaultValue": "''"
585
+ },
586
+ "name": {
587
+ "type": "string",
588
+ "mutable": false,
589
+ "complexType": {
590
+ "original": "string",
591
+ "resolved": "string",
592
+ "references": {}
593
+ },
594
+ "required": false,
595
+ "optional": false,
596
+ "docs": {
597
+ "tags": [],
598
+ "text": "The name of the form control. Submitted with the form as part of a name/value pair."
599
+ },
600
+ "attribute": "name",
601
+ "reflect": false,
602
+ "defaultValue": "''"
603
+ },
604
+ "labelHidden": {
605
+ "type": "boolean",
606
+ "mutable": false,
607
+ "complexType": {
608
+ "original": "boolean",
609
+ "resolved": "boolean",
610
+ "references": {}
611
+ },
612
+ "required": false,
613
+ "optional": false,
614
+ "docs": {
615
+ "tags": [],
616
+ "text": "Visually hide the label, but still show it to assistive technologies like screen readers."
617
+ },
618
+ "attribute": "label-hidden",
619
+ "reflect": false,
620
+ "defaultValue": "false"
621
+ },
622
+ "required": {
623
+ "type": "boolean",
624
+ "mutable": false,
625
+ "complexType": {
626
+ "original": "boolean",
627
+ "resolved": "boolean",
628
+ "references": {}
629
+ },
630
+ "required": false,
631
+ "optional": false,
632
+ "docs": {
633
+ "tags": [],
634
+ "text": "A value is required or must be check for the form to be submittable."
635
+ },
636
+ "attribute": "required",
637
+ "reflect": false,
638
+ "defaultValue": "false"
639
+ },
640
+ "clearable": {
641
+ "type": "boolean",
642
+ "mutable": false,
643
+ "complexType": {
644
+ "original": "boolean",
645
+ "resolved": "boolean",
646
+ "references": {}
647
+ },
648
+ "required": false,
649
+ "optional": false,
650
+ "docs": {
651
+ "tags": [],
652
+ "text": "Whether the select should show a clear button."
653
+ },
654
+ "attribute": "clearable",
655
+ "reflect": false,
656
+ "defaultValue": "false"
657
+ }
658
+ }; }
659
+ static get states() { return {
660
+ "connector": {},
661
+ "state": {},
662
+ "hasSlottedLabel": {}
663
+ }; }
664
+ static get events() { return [{
665
+ "method": "catOpen",
666
+ "name": "catOpen",
667
+ "bubbles": true,
668
+ "cancelable": true,
669
+ "composed": true,
670
+ "docs": {
671
+ "tags": [],
672
+ "text": "Emitted when the select dropdown is opened."
673
+ },
674
+ "complexType": {
675
+ "original": "FocusEvent",
676
+ "resolved": "FocusEvent",
677
+ "references": {
678
+ "FocusEvent": {
679
+ "location": "global"
680
+ }
681
+ }
682
+ }
683
+ }, {
684
+ "method": "catClose",
685
+ "name": "catClose",
686
+ "bubbles": true,
687
+ "cancelable": true,
688
+ "composed": true,
689
+ "docs": {
690
+ "tags": [],
691
+ "text": "Emitted when the select dropdown is closed."
692
+ },
693
+ "complexType": {
694
+ "original": "FocusEvent",
695
+ "resolved": "FocusEvent",
696
+ "references": {
697
+ "FocusEvent": {
698
+ "location": "global"
699
+ }
700
+ }
701
+ }
702
+ }, {
703
+ "method": "catChange",
704
+ "name": "catChange",
705
+ "bubbles": true,
706
+ "cancelable": true,
707
+ "composed": true,
708
+ "docs": {
709
+ "tags": [],
710
+ "text": "Emitted when the value is changed."
711
+ },
712
+ "complexType": {
713
+ "original": "any",
714
+ "resolved": "any",
715
+ "references": {}
716
+ }
717
+ }, {
718
+ "method": "catBlur",
719
+ "name": "catBlur",
720
+ "bubbles": true,
721
+ "cancelable": true,
722
+ "composed": true,
723
+ "docs": {
724
+ "tags": [],
725
+ "text": "Emitted when the select loses the focus."
726
+ },
727
+ "complexType": {
728
+ "original": "FocusEvent",
729
+ "resolved": "FocusEvent",
730
+ "references": {
731
+ "FocusEvent": {
732
+ "location": "global"
733
+ }
734
+ }
735
+ }
736
+ }]; }
737
+ static get methods() { return {
738
+ "connect": {
739
+ "complexType": {
740
+ "signature": "(connector: CatSelectRemoteConnector) => Promise<void>",
741
+ "parameters": [{
742
+ "tags": [],
743
+ "text": ""
744
+ }],
745
+ "references": {
746
+ "Promise": {
747
+ "location": "global"
748
+ },
749
+ "CatSelectRemoteConnector": {
750
+ "location": "local"
751
+ },
752
+ "Observable": {
753
+ "location": "import",
754
+ "path": "rxjs"
755
+ },
756
+ "Item": {
757
+ "location": "local"
758
+ }
759
+ },
760
+ "return": "Promise<void>"
761
+ },
762
+ "docs": {
763
+ "text": "",
764
+ "tags": []
765
+ }
766
+ }
767
+ }; }
768
+ static get elementRef() { return "hostElement"; }
769
+ static get watchers() { return [{
770
+ "propName": "connector",
771
+ "methodName": "onConnectorChange"
772
+ }, {
773
+ "propName": "state",
774
+ "methodName": "onStateChange"
775
+ }]; }
776
+ static get listeners() { return [{
777
+ "name": "blur",
778
+ "method": "onBlur",
779
+ "target": undefined,
780
+ "capture": false,
781
+ "passive": false
782
+ }, {
783
+ "name": "keydown",
784
+ "method": "onKeyDown",
785
+ "target": undefined,
786
+ "capture": false,
787
+ "passive": false
788
+ }, {
789
+ "name": "keyup",
790
+ "method": "onKeyUp",
791
+ "target": undefined,
792
+ "capture": false,
793
+ "passive": false
794
+ }]; }
795
+ }
796
+ CatSelectRemote.SKELETON_COUNT = 4;
797
+ CatSelectRemote.DROPDOWN_OFFSET = 4;
798
+ //# sourceMappingURL=cat-select-remote.js.map