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