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