@lavalogic/scoria 0.38.12 → 0.38.13

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 (94) hide show
  1. package/dist/Components/AccordionGroup.svelte +46 -46
  2. package/dist/Components/AccordionGroupButton.svelte +76 -76
  3. package/dist/Components/Action.svelte +136 -136
  4. package/dist/Components/AppointmentCalendar/AppointmentCalendar.svelte +712 -702
  5. package/dist/Components/Base/BaseModal.svelte +125 -125
  6. package/dist/Components/Base/ContextWrapper.svelte +72 -72
  7. package/dist/Components/Base/Pagination.svelte +198 -198
  8. package/dist/Components/Base/Snippets.svelte +36 -36
  9. package/dist/Components/BigRadioSet.svelte +38 -38
  10. package/dist/Components/Bubble.svelte +101 -101
  11. package/dist/Components/Button.svelte +209 -209
  12. package/dist/Components/Checkbox.svelte +86 -86
  13. package/dist/Components/Contexts/ContextMenu.svelte +164 -164
  14. package/dist/Components/Contexts/ContextMenuDivider.svelte +15 -15
  15. package/dist/Components/Contexts/ContextMenuOption.svelte +60 -60
  16. package/dist/Components/Contexts/ToastContainer.svelte +65 -65
  17. package/dist/Components/Contexts/Tooltip.svelte +37 -37
  18. package/dist/Components/DataMatrixIcon.svelte +112 -112
  19. package/dist/Components/DateInput.svelte +148 -148
  20. package/dist/Components/DatePicker.svelte +300 -300
  21. package/dist/Components/DesktopModal.svelte +90 -90
  22. package/dist/Components/Dial.svelte +204 -204
  23. package/dist/Components/DimensionInput.svelte +170 -170
  24. package/dist/Components/DragMenu/DragMenuHolder.svelte +119 -119
  25. package/dist/Components/DragMenu/DraggableCard.svelte +77 -77
  26. package/dist/Components/FileCard.svelte +24 -24
  27. package/dist/Components/FileUpload.svelte +236 -236
  28. package/dist/Components/GridInputSet.svelte +29 -29
  29. package/dist/Components/HorizontalTabGroup.svelte +82 -82
  30. package/dist/Components/HorizontalTabGroupButton.svelte +44 -44
  31. package/dist/Components/Icon.svelte +128 -128
  32. package/dist/Components/Icons.js +357 -357
  33. package/dist/Components/LoadingAnimation.svelte +29 -29
  34. package/dist/Components/LoadingModal.svelte +45 -45
  35. package/dist/Components/LoadingOverlay.svelte +25 -25
  36. package/dist/Components/Modal.svelte +258 -258
  37. package/dist/Components/MultiSelect.svelte +220 -220
  38. package/dist/Components/Nav/NavServiceMenuList.svelte +43 -43
  39. package/dist/Components/Nav/NavTab.svelte +62 -62
  40. package/dist/Components/Nav/ServicesNav.svelte +80 -80
  41. package/dist/Components/NumberInput.svelte +157 -157
  42. package/dist/Components/PageHeading.svelte +25 -25
  43. package/dist/Components/PasswordInput.svelte +88 -88
  44. package/dist/Components/Portal.svelte +36 -36
  45. package/dist/Components/QuerySelect.svelte +366 -366
  46. package/dist/Components/SingleSelect.svelte +250 -250
  47. package/dist/Components/StepButton.svelte +70 -70
  48. package/dist/Components/StepForm.svelte +140 -140
  49. package/dist/Components/Switch.svelte +69 -69
  50. package/dist/Components/Table/Body/Rows/ColumnHighlight.svelte +51 -51
  51. package/dist/Components/Table/Body/Rows/ColumnList.svelte +59 -59
  52. package/dist/Components/Table/Body/Rows/Columns/AccessorComponent.svelte +79 -79
  53. package/dist/Components/Table/Body/Rows/Columns/ExpandCell.svelte +120 -120
  54. package/dist/Components/Table/Body/Rows/Columns/ProgressCell.svelte +105 -105
  55. package/dist/Components/Table/Body/Rows/Columns/TableAction.svelte +87 -87
  56. package/dist/Components/Table/Body/Rows/Columns/TableCheckbox.svelte +126 -126
  57. package/dist/Components/Table/Body/Rows/Columns/TableColumn.svelte +159 -159
  58. package/dist/Components/Table/Body/Rows/Columns/TableDatePicker.svelte +246 -246
  59. package/dist/Components/Table/Body/Rows/Columns/TableNumberInput.svelte +216 -216
  60. package/dist/Components/Table/Body/Rows/Columns/TableRowSelectionCheckbox.svelte +179 -179
  61. package/dist/Components/Table/Body/Rows/Columns/TableTextInput.svelte +197 -197
  62. package/dist/Components/Table/Body/Rows/Columns/ValidityCell.svelte +190 -190
  63. package/dist/Components/Table/Body/Rows/TableRow.svelte +290 -290
  64. package/dist/Components/Table/Headers/HighlightAllHeader.svelte +41 -41
  65. package/dist/Components/Table/Headers/SelectAllHeader.svelte +30 -30
  66. package/dist/Components/Table/Misc/SidePanel.svelte +35 -35
  67. package/dist/Components/Table/Misc/ToolboxPanel.svelte +100 -100
  68. package/dist/Components/Table/Misc/ToolboxPanelModal.svelte +107 -107
  69. package/dist/Components/TextArea.svelte +130 -130
  70. package/dist/Components/TextInput.svelte +176 -176
  71. package/dist/Components/ThreeStateRadio.svelte +131 -131
  72. package/dist/Components/Touch/BoolCard.svelte +45 -45
  73. package/dist/Components/Touch/DateModal.svelte +209 -209
  74. package/dist/Components/Touch/EditCard.svelte +59 -59
  75. package/dist/Components/Touch/InfoCard.svelte +31 -31
  76. package/dist/Components/Touch/InfoTextCard.svelte +28 -28
  77. package/dist/Components/Touch/ModalExplanation.svelte +17 -17
  78. package/dist/Components/Touch/NumberKeyboard.svelte +225 -225
  79. package/dist/Components/Touch/NumberModal.svelte +79 -79
  80. package/dist/Components/Touch/PlusMinusCard.svelte +46 -46
  81. package/dist/Components/Touch/SummaryCard.svelte +93 -93
  82. package/dist/Components/Touch/TextAreaModal.svelte +95 -95
  83. package/dist/Components/Touch/TextModal.svelte +106 -106
  84. package/dist/Components/Touch/TouchCard.svelte +33 -33
  85. package/dist/Components/Touch/TouchModal.svelte +274 -274
  86. package/dist/Components/Touch/UtilityButton.svelte +109 -109
  87. package/dist/Components/VerticalTabGroup.svelte +79 -79
  88. package/dist/Components/VerticalTabGroupButton.svelte +58 -58
  89. package/dist/Helpers/Datamatrix.d.ts +19 -19
  90. package/dist/Helpers/Datamatrix.js +291 -291
  91. package/dist/Types/Examples/ExampleModal.svelte +35 -35
  92. package/dist/scss/_motion.scss +57 -57
  93. package/dist/scss/_sizing.scss +85 -85
  94. package/package.json +30 -30
@@ -1,368 +1,368 @@
1
- <svelte:options runes />
2
-
3
- <script
4
- lang="ts"
5
- generics="V extends object, VP extends ValueProp<V>"
6
- >
7
- import { ToastContext } from '../Contexts/ToastContext.svelte.js';
8
-
9
- import { dev } from '$app/environment';
10
- import { devCatch, generateWeakId, vowels } from '../Helpers/Helpers.svelte.js';
11
- import { attachDropdownPortal } from '../Helpers/dropdownPortal.js';
12
- import { Colour, ColourSet } from '../scss/colours.js';
13
- import type { ValueProp } from '../Types/Internal/Misc.js';
14
- import { Size } from '../Types/Internal/Size.js';
15
- import Svelecte from 'svelecte';
16
- import { getContext, onMount, type Snippet, tick, untrack } from 'svelte';
17
- import Action from './Action.svelte';
18
- import type { QuerySelectProps } from './QuerySelectProps.js';
19
-
20
- let {
21
- label,
22
- labelProp,
23
- valueProp,
24
- clearable = false,
25
- required = false,
26
- invalid = false,
27
- valueAsObject,
28
- name = 'Item',
29
- disabled,
30
- query,
31
- width,
32
- height,
33
- focusOnLoad = false,
34
- inputId = generateWeakId(),
35
- value: selectedValue,
36
- options = $bindable<Array<V>>([]),
37
- isValid,
38
- onchange,
39
- onfocus,
40
- }: QuerySelectProps<V, VP> = $props();
41
-
42
- export function forceQuery() {
43
- clearTimeout(timeoutHandler);
44
-
45
- const input = document.getElementById(inputId);
46
- const searchValue = (input as HTMLInputElement).value;
47
-
48
- const currentHandler = (timeoutHandler = setTimeout(() => {
49
- tryQuery(currentHandler, searchValue).catch(devCatch);
50
- }, 500) as unknown as number);
51
- tryQuery(currentHandler, searchValue).catch(devCatch);
52
- }
53
-
54
- let ref: Svelecte | undefined = $state();
55
- let hasAutoFocused = $state(false);
56
- let loadingDiv: HTMLDivElement | undefined = $state();
57
- let isLoading = $state(false);
58
- let hasRegisteredListeners = $state(false);
59
- // Abort controller used to remove input listeners on unmount.
60
- let listenerAbort: AbortController | undefined;
61
-
62
- function isObjectValue(value: unknown): value is V {
63
- return value !== null && typeof value == 'object' && labelProp in value && valueProp in value;
64
- }
65
-
66
- $effect.pre(() => {
67
- void selectedValue;
68
- untrack(() => {
69
- if (selectedValue != null) {
70
- if (valueAsObject) {
71
- if (isObjectValue(selectedValue)) {
72
- if (!options.some((opt: V) => opt[valueProp] === selectedValue[valueProp])) {
73
- // Immutable update so the bindable propagates even when the
74
- // parent did not declare `$state` on its side.
75
- options = [...options, selectedValue];
76
- }
77
- } else if (dev) {
78
- console.warn(`valueAsObject is true but the value doesn't match`, selectedValue);
79
- return;
80
- }
81
- } else if (!options.some((opt: V) => opt[valueProp] === selectedValue)) {
82
- options = [
83
- ...options,
84
- {
85
- //best-effort solution. Not a good one
86
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
87
- [labelProp]: selectedValue.toString(),
88
- [valueProp]: selectedValue,
89
- } as V,
90
- ];
91
- }
92
- }
93
- });
94
- });
95
-
96
- const isInvalid = $derived(
97
- (required && !selectedValue) ||
98
- invalid ||
99
- isValid?.(
100
- valueAsObject
101
- ? (selectedValue as V)
102
- : (options.find((a) => a[valueProp] === selectedValue) ?? null)
103
- ) === false
104
- );
105
-
106
- const toastContext = getContext<ToastContext>(ToastContext.identifier);
107
-
108
- function forceShowDropdown(e: HTMLInputElement) {
109
- if (focusOnLoad && !hasAutoFocused) {
110
- hasAutoFocused = true;
111
- e.click();
112
- }
113
- }
114
-
115
- // HACK svelecte type shenanigans
116
- function isFocusable(ref: unknown): ref is HTMLInputElement {
117
- return ref != null;
118
- }
119
-
120
- onMount(() => {
121
- if (focusOnLoad) {
122
- tick()
123
- .then(() => {
124
- if (isFocusable(ref)) {
125
- ref.focus();
126
- }
127
- })
128
- .catch(devCatch);
129
- }
130
-
131
- const input = document.getElementById(inputId);
132
- const svelecteRoot = input?.closest('div.svelecte') as HTMLElement | null;
133
- const dropdownRef =
134
- (svelecteRoot?.querySelector('.sv_dropdown') as HTMLElement | null) ?? undefined;
135
-
136
- // HACK callback for is-open on/off; drives the chevron rotation
137
- // in the action snippet further down.
138
- const observer = new MutationObserver((mutations: Array<MutationRecord>) => {
139
- for (let i = mutations.length - 1; i > -1; i--) {
140
- const mutation = mutations[i];
141
- if (mutation.attributeName === 'class') {
142
- isExpanded = dropdownRef?.classList.contains('is-open') ?? false;
143
- }
144
- }
145
- });
146
-
147
- if (dropdownRef) {
148
- observer.observe(dropdownRef, { attributes: true });
149
- }
150
-
151
- // Teleport the Svelecte dropdown to `document.body` while open
152
- // so it escapes every ancestor `overflow` / `transform` /
153
- // `z-index` stacking context. See `Helpers/dropdownPortal.ts`.
154
- const detachPortal = attachDropdownPortal({
155
- getTrigger: () => svelecteRoot,
156
- getDropdown: () => dropdownRef,
157
- });
158
-
159
- return () => {
160
- observer.disconnect();
161
- detachPortal();
162
- clearTimeout(timeoutHandler);
163
- listenerAbort?.abort();
164
- };
165
- });
166
-
167
- let timeoutHandler = -1;
168
-
169
- $effect(() => {
170
- if (loadingDiv && isLoading) {
171
- loadingDiv.classList.add('is-loading');
172
- } else {
173
- loadingDiv?.classList.remove('is-loading');
174
- }
175
- });
176
-
177
- function registerInputListeners(e: HTMLInputElement) {
178
- if (!hasRegisteredListeners) {
179
- hasRegisteredListeners = true;
180
- listenerAbort = new AbortController();
181
- const signal = listenerAbort.signal;
182
-
183
- const inputElement = e;
184
-
185
- loadingDiv = inputElement.parentElement?.parentElement?.nextElementSibling as
186
- | HTMLDivElement
187
- | undefined;
188
-
189
- const currentHandler = (timeoutHandler = setTimeout(() => {
190
- tryQuery(currentHandler, '').catch(devCatch);
191
- }, 500) as unknown as number);
192
-
193
- inputElement.addEventListener(
194
- 'input',
195
- (e) => {
196
- clearTimeout(timeoutHandler);
197
-
198
- const searchValue = (e.target as HTMLInputElement).value;
199
-
200
- const currentHandler = (timeoutHandler = setTimeout(() => {
201
- tryQuery(currentHandler, searchValue).catch(devCatch);
202
- }, 500) as unknown as number);
203
- },
204
- { signal }
205
- );
206
-
207
- inputElement.addEventListener(
208
- 'keydown',
209
- (e) => {
210
- if (e.key === 'Enter') {
211
- tick()
212
- .then(() => {
213
- const searchValue = (e.target as HTMLInputElement).value;
214
- if (searchValue) {
215
- clearTimeout(timeoutHandler);
216
-
217
- const currentHandler = (timeoutHandler = setTimeout(() => {
218
- tryQuery(currentHandler, searchValue, true).catch(devCatch);
219
- }, 1) as unknown as number);
220
- }
221
- })
222
- .catch(devCatch);
223
- }
224
- },
225
- { signal }
226
- );
227
- }
228
- }
229
-
230
- async function tryQuery(handler: number, value: string, andSelectIt = false) {
231
- if (timeoutHandler === handler) {
232
- isLoading = true;
233
- try {
234
- const newValues = await query(value);
235
- isLoading = false;
236
-
237
- if (timeoutHandler === handler) {
238
- options = newValues;
239
-
240
- if (andSelectIt) {
241
- if (newValues.length === 1) {
242
- onChange(newValues[0]);
243
- }
244
- }
245
- }
246
- } catch (e) {
247
- toastContext.toast(e);
248
- }
249
- }
250
- }
251
-
252
- function onChange(newValue: V | null | undefined) {
253
- if (clearable || newValue != null) {
254
- // svelecte always passes the full option object; normalise to
255
- // the shape the variant promised. AsPrimitive callbacks
256
- // receive the primitive key (`V[VP]`), not the object.
257
- if (valueAsObject) {
258
- void (onchange as (v: V | null) => void | Promise<void>)(newValue ?? null);
259
- } else {
260
- const primitive = newValue == null ? null : newValue[valueProp];
261
- // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
262
- void (onchange as (v: V[VP] | null) => void | Promise<void>)(primitive);
263
- }
264
- }
265
- }
266
-
267
- const an = $derived(vowels.has(name[0].toLocaleLowerCase()) ? 'an' : 'a');
268
-
269
- let isExpanded = $state(false);
270
- </script>
271
-
272
- <div
273
- class="select-wrapper"
274
- class:invalid={isInvalid}
275
- style={`${width ? `--input-width: ${width};` : ''}${height ? `--input-height: ${height};` : ''}`}
276
- >
277
- {#if label}
278
- <label for={inputId}>
279
- <span
280
- >{label}{#if !required}&nbsp;- <i>optional</i>{/if}</span
281
- >
282
- <span class="border"
283
- >{label}{#if !required}&nbsp;- <i>optional</i>{/if}</span
284
- >
285
- </label>
286
- {/if}
287
- <!-- strict mode is used to stop svelecte from rejecting perfectly valid values -->
288
- <Svelecte
289
- strictMode={false}
290
- keepCreated
291
- onFocus={(e: HTMLInputElement) => {
292
- registerInputListeners(e);
293
- forceShowDropdown(e);
294
- onfocus?.(e);
295
- }}
296
- placeholder="Please Select{name ? ` ${an} ${name}` : ''}"
297
- bind:this={ref}
298
- {inputId}
299
- {disabled}
300
- valueField={valueProp}
301
- labelField={labelProp}
302
- virtualList={false}
303
- searchable
304
- searchProps={{ keepSelectionInList: true }}
305
- lazyDropdown
306
- {valueAsObject}
307
- {options}
308
- value={selectedValue as Array<unknown>}
309
- {onChange}
310
- selectOnTab
311
- deselectMode={required && !clearable ? 'none' : 'toggle'}
312
- keepSelectionInList
313
- {name}
314
- selection={selection as (selectedOptions: Array<object>) => ReturnType<Snippet>}
315
- {append}
316
- >
317
- {#snippet toggleIcon()}
318
- <div class="nothing"></div>
319
- {/snippet}
320
- </Svelecte>
321
-
322
- {#snippet append()}
323
- <div class="icons">
324
- {#if clearable && selectedValue}
325
- <Action
326
- {disabled}
327
- noTabIndex
328
- colourSet={ColourSet.Auxiliary}
329
- size={Size.Small}
330
- onclick={(e: MouseEvent) => {
331
- if (isExpanded) {
332
- e.stopPropagation();
333
- }
334
-
335
- onChange(null);
336
- }}
337
- icon={{
338
- name: 'close-menu-cross',
339
- colour: Colour['$ui-blue-9'],
340
- }}
341
- />
342
- {/if}
343
-
344
- <Action
345
- {disabled}
346
- noTabIndex
347
- colourSet={ColourSet.Auxiliary}
348
- size={Size.Small}
349
- icon={{
350
- name: isExpanded ? 'chevron-up' : 'chevron-down',
351
- colour: Colour['$ui-blue-9'],
352
- }}
353
- />
354
- </div>
355
- {/snippet}
356
-
357
- {#snippet selection(selectedOptions: Array<V>)}
358
- {#if selectedOptions.length == 0}
359
- <span class="selection">Please Select {an} {name}</span>
360
- {:else}
361
- <span class="selection">{selectedOptions[0][labelProp]}</span>
362
- {/if}
363
- {/snippet}
364
- </div>
365
-
1
+ <svelte:options runes />
2
+
3
+ <script
4
+ lang="ts"
5
+ generics="V extends object, VP extends ValueProp<V>"
6
+ >
7
+ import { ToastContext } from '../Contexts/ToastContext.svelte.js';
8
+
9
+ import { dev } from '$app/environment';
10
+ import { devCatch, generateWeakId, vowels } from '../Helpers/Helpers.svelte.js';
11
+ import { attachDropdownPortal } from '../Helpers/dropdownPortal.js';
12
+ import { Colour, ColourSet } from '../scss/colours.js';
13
+ import type { ValueProp } from '../Types/Internal/Misc.js';
14
+ import { Size } from '../Types/Internal/Size.js';
15
+ import Svelecte from 'svelecte';
16
+ import { getContext, onMount, type Snippet, tick, untrack } from 'svelte';
17
+ import Action from './Action.svelte';
18
+ import type { QuerySelectProps } from './QuerySelectProps.js';
19
+
20
+ let {
21
+ label,
22
+ labelProp,
23
+ valueProp,
24
+ clearable = false,
25
+ required = false,
26
+ invalid = false,
27
+ valueAsObject,
28
+ name = 'Item',
29
+ disabled,
30
+ query,
31
+ width,
32
+ height,
33
+ focusOnLoad = false,
34
+ inputId = generateWeakId(),
35
+ value: selectedValue,
36
+ options = $bindable<Array<V>>([]),
37
+ isValid,
38
+ onchange,
39
+ onfocus,
40
+ }: QuerySelectProps<V, VP> = $props();
41
+
42
+ export function forceQuery() {
43
+ clearTimeout(timeoutHandler);
44
+
45
+ const input = document.getElementById(inputId);
46
+ const searchValue = (input as HTMLInputElement).value;
47
+
48
+ const currentHandler = (timeoutHandler = setTimeout(() => {
49
+ tryQuery(currentHandler, searchValue).catch(devCatch);
50
+ }, 500) as unknown as number);
51
+ tryQuery(currentHandler, searchValue).catch(devCatch);
52
+ }
53
+
54
+ let ref: Svelecte | undefined = $state();
55
+ let hasAutoFocused = $state(false);
56
+ let loadingDiv: HTMLDivElement | undefined = $state();
57
+ let isLoading = $state(false);
58
+ let hasRegisteredListeners = $state(false);
59
+ // Abort controller used to remove input listeners on unmount.
60
+ let listenerAbort: AbortController | undefined;
61
+
62
+ function isObjectValue(value: unknown): value is V {
63
+ return value !== null && typeof value == 'object' && labelProp in value && valueProp in value;
64
+ }
65
+
66
+ $effect.pre(() => {
67
+ void selectedValue;
68
+ untrack(() => {
69
+ if (selectedValue != null) {
70
+ if (valueAsObject) {
71
+ if (isObjectValue(selectedValue)) {
72
+ if (!options.some((opt: V) => opt[valueProp] === selectedValue[valueProp])) {
73
+ // Immutable update so the bindable propagates even when the
74
+ // parent did not declare `$state` on its side.
75
+ options = [...options, selectedValue];
76
+ }
77
+ } else if (dev) {
78
+ console.warn(`valueAsObject is true but the value doesn't match`, selectedValue);
79
+ return;
80
+ }
81
+ } else if (!options.some((opt: V) => opt[valueProp] === selectedValue)) {
82
+ options = [
83
+ ...options,
84
+ {
85
+ //best-effort solution. Not a good one
86
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
87
+ [labelProp]: selectedValue.toString(),
88
+ [valueProp]: selectedValue,
89
+ } as V,
90
+ ];
91
+ }
92
+ }
93
+ });
94
+ });
95
+
96
+ const isInvalid = $derived(
97
+ (required && !selectedValue) ||
98
+ invalid ||
99
+ isValid?.(
100
+ valueAsObject
101
+ ? (selectedValue as V)
102
+ : (options.find((a) => a[valueProp] === selectedValue) ?? null)
103
+ ) === false
104
+ );
105
+
106
+ const toastContext = getContext<ToastContext>(ToastContext.identifier);
107
+
108
+ function forceShowDropdown(e: HTMLInputElement) {
109
+ if (focusOnLoad && !hasAutoFocused) {
110
+ hasAutoFocused = true;
111
+ e.click();
112
+ }
113
+ }
114
+
115
+ // HACK svelecte type shenanigans
116
+ function isFocusable(ref: unknown): ref is HTMLInputElement {
117
+ return ref != null;
118
+ }
119
+
120
+ onMount(() => {
121
+ if (focusOnLoad) {
122
+ tick()
123
+ .then(() => {
124
+ if (isFocusable(ref)) {
125
+ ref.focus();
126
+ }
127
+ })
128
+ .catch(devCatch);
129
+ }
130
+
131
+ const input = document.getElementById(inputId);
132
+ const svelecteRoot = input?.closest('div.svelecte') as HTMLElement | null;
133
+ const dropdownRef =
134
+ (svelecteRoot?.querySelector('.sv_dropdown') as HTMLElement | null) ?? undefined;
135
+
136
+ // HACK callback for is-open on/off; drives the chevron rotation
137
+ // in the action snippet further down.
138
+ const observer = new MutationObserver((mutations: Array<MutationRecord>) => {
139
+ for (let i = mutations.length - 1; i > -1; i--) {
140
+ const mutation = mutations[i];
141
+ if (mutation.attributeName === 'class') {
142
+ isExpanded = dropdownRef?.classList.contains('is-open') ?? false;
143
+ }
144
+ }
145
+ });
146
+
147
+ if (dropdownRef) {
148
+ observer.observe(dropdownRef, { attributes: true });
149
+ }
150
+
151
+ // Teleport the Svelecte dropdown to `document.body` while open
152
+ // so it escapes every ancestor `overflow` / `transform` /
153
+ // `z-index` stacking context. See `Helpers/dropdownPortal.ts`.
154
+ const detachPortal = attachDropdownPortal({
155
+ getTrigger: () => svelecteRoot,
156
+ getDropdown: () => dropdownRef,
157
+ });
158
+
159
+ return () => {
160
+ observer.disconnect();
161
+ detachPortal();
162
+ clearTimeout(timeoutHandler);
163
+ listenerAbort?.abort();
164
+ };
165
+ });
166
+
167
+ let timeoutHandler = -1;
168
+
169
+ $effect(() => {
170
+ if (loadingDiv && isLoading) {
171
+ loadingDiv.classList.add('is-loading');
172
+ } else {
173
+ loadingDiv?.classList.remove('is-loading');
174
+ }
175
+ });
176
+
177
+ function registerInputListeners(e: HTMLInputElement) {
178
+ if (!hasRegisteredListeners) {
179
+ hasRegisteredListeners = true;
180
+ listenerAbort = new AbortController();
181
+ const signal = listenerAbort.signal;
182
+
183
+ const inputElement = e;
184
+
185
+ loadingDiv = inputElement.parentElement?.parentElement?.nextElementSibling as
186
+ | HTMLDivElement
187
+ | undefined;
188
+
189
+ const currentHandler = (timeoutHandler = setTimeout(() => {
190
+ tryQuery(currentHandler, '').catch(devCatch);
191
+ }, 500) as unknown as number);
192
+
193
+ inputElement.addEventListener(
194
+ 'input',
195
+ (e) => {
196
+ clearTimeout(timeoutHandler);
197
+
198
+ const searchValue = (e.target as HTMLInputElement).value;
199
+
200
+ const currentHandler = (timeoutHandler = setTimeout(() => {
201
+ tryQuery(currentHandler, searchValue).catch(devCatch);
202
+ }, 500) as unknown as number);
203
+ },
204
+ { signal }
205
+ );
206
+
207
+ inputElement.addEventListener(
208
+ 'keydown',
209
+ (e) => {
210
+ if (e.key === 'Enter') {
211
+ tick()
212
+ .then(() => {
213
+ const searchValue = (e.target as HTMLInputElement).value;
214
+ if (searchValue) {
215
+ clearTimeout(timeoutHandler);
216
+
217
+ const currentHandler = (timeoutHandler = setTimeout(() => {
218
+ tryQuery(currentHandler, searchValue, true).catch(devCatch);
219
+ }, 1) as unknown as number);
220
+ }
221
+ })
222
+ .catch(devCatch);
223
+ }
224
+ },
225
+ { signal }
226
+ );
227
+ }
228
+ }
229
+
230
+ async function tryQuery(handler: number, value: string, andSelectIt = false) {
231
+ if (timeoutHandler === handler) {
232
+ isLoading = true;
233
+ try {
234
+ const newValues = await query(value);
235
+ isLoading = false;
236
+
237
+ if (timeoutHandler === handler) {
238
+ options = newValues;
239
+
240
+ if (andSelectIt) {
241
+ if (newValues.length === 1) {
242
+ onChange(newValues[0]);
243
+ }
244
+ }
245
+ }
246
+ } catch (e) {
247
+ toastContext.toast(e);
248
+ }
249
+ }
250
+ }
251
+
252
+ function onChange(newValue: V | null | undefined) {
253
+ if (clearable || newValue != null) {
254
+ // svelecte always passes the full option object; normalise to
255
+ // the shape the variant promised. AsPrimitive callbacks
256
+ // receive the primitive key (`V[VP]`), not the object.
257
+ if (valueAsObject) {
258
+ void (onchange as (v: V | null) => void | Promise<void>)(newValue ?? null);
259
+ } else {
260
+ const primitive = newValue == null ? null : newValue[valueProp];
261
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
262
+ void (onchange as (v: V[VP] | null) => void | Promise<void>)(primitive);
263
+ }
264
+ }
265
+ }
266
+
267
+ const an = $derived(vowels.has(name[0].toLocaleLowerCase()) ? 'an' : 'a');
268
+
269
+ let isExpanded = $state(false);
270
+ </script>
271
+
272
+ <div
273
+ class="select-wrapper"
274
+ class:invalid={isInvalid}
275
+ style={`${width ? `--input-width: ${width};` : ''}${height ? `--input-height: ${height};` : ''}`}
276
+ >
277
+ {#if label}
278
+ <label for={inputId}>
279
+ <span
280
+ >{label}{#if !required}&nbsp;- <i>optional</i>{/if}</span
281
+ >
282
+ <span class="border"
283
+ >{label}{#if !required}&nbsp;- <i>optional</i>{/if}</span
284
+ >
285
+ </label>
286
+ {/if}
287
+ <!-- strict mode is used to stop svelecte from rejecting perfectly valid values -->
288
+ <Svelecte
289
+ strictMode={false}
290
+ keepCreated
291
+ onFocus={(e: HTMLInputElement) => {
292
+ registerInputListeners(e);
293
+ forceShowDropdown(e);
294
+ onfocus?.(e);
295
+ }}
296
+ placeholder="Please Select{name ? ` ${an} ${name}` : ''}"
297
+ bind:this={ref}
298
+ {inputId}
299
+ {disabled}
300
+ valueField={valueProp}
301
+ labelField={labelProp}
302
+ virtualList={false}
303
+ searchable
304
+ searchProps={{ keepSelectionInList: true }}
305
+ lazyDropdown
306
+ {valueAsObject}
307
+ {options}
308
+ value={selectedValue as Array<unknown>}
309
+ {onChange}
310
+ selectOnTab
311
+ deselectMode={required && !clearable ? 'none' : 'toggle'}
312
+ keepSelectionInList
313
+ {name}
314
+ selection={selection as (selectedOptions: Array<object>) => ReturnType<Snippet>}
315
+ {append}
316
+ >
317
+ {#snippet toggleIcon()}
318
+ <div class="nothing"></div>
319
+ {/snippet}
320
+ </Svelecte>
321
+
322
+ {#snippet append()}
323
+ <div class="icons">
324
+ {#if clearable && selectedValue}
325
+ <Action
326
+ {disabled}
327
+ noTabIndex
328
+ colourSet={ColourSet.Auxiliary}
329
+ size={Size.Small}
330
+ onclick={(e: MouseEvent) => {
331
+ if (isExpanded) {
332
+ e.stopPropagation();
333
+ }
334
+
335
+ onChange(null);
336
+ }}
337
+ icon={{
338
+ name: 'close-menu-cross',
339
+ colour: Colour['$ui-blue-9'],
340
+ }}
341
+ />
342
+ {/if}
343
+
344
+ <Action
345
+ {disabled}
346
+ noTabIndex
347
+ colourSet={ColourSet.Auxiliary}
348
+ size={Size.Small}
349
+ icon={{
350
+ name: isExpanded ? 'chevron-up' : 'chevron-down',
351
+ colour: Colour['$ui-blue-9'],
352
+ }}
353
+ />
354
+ </div>
355
+ {/snippet}
356
+
357
+ {#snippet selection(selectedOptions: Array<V>)}
358
+ {#if selectedOptions.length == 0}
359
+ <span class="selection">Please Select {an} {name}</span>
360
+ {:else}
361
+ <span class="selection">{selectedOptions[0][labelProp]}</span>
362
+ {/if}
363
+ {/snippet}
364
+ </div>
365
+
366
366
  <style>.select-wrapper {
367
367
  min-width: var(--input-min-width, 12rem);
368
368
  width: var(--input-width, 100%);
@@ -525,4 +525,4 @@ div.icons {
525
525
  }
526
526
  :global(.dropdown-item) .toggle-icon.yes {
527
527
  opacity: 1;
528
- }</style>
528
+ }</style>