@lavalogic/scoria 0.40.0 → 0.40.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -58
- package/dist/Components/AccordionGroup.svelte +46 -46
- package/dist/Components/AccordionGroupButton.svelte +76 -76
- package/dist/Components/Action.svelte +136 -136
- package/dist/Components/AlertModal.svelte +195 -195
- package/dist/Components/AppointmentCalendar/AppointmentCalendar.svelte +729 -729
- package/dist/Components/Base/BaseModal.svelte +125 -125
- package/dist/Components/Base/ContextWrapper.svelte +72 -72
- package/dist/Components/Base/Pagination.svelte +198 -198
- package/dist/Components/Base/Snippets.svelte +36 -36
- package/dist/Components/BigRadioSet.svelte +38 -38
- package/dist/Components/Bubble.svelte +101 -101
- package/dist/Components/Button.svelte +209 -209
- package/dist/Components/Checkbox.svelte +86 -86
- package/dist/Components/CollapsibleCard.svelte +78 -78
- package/dist/Components/Contexts/ContextMenu.svelte +164 -164
- package/dist/Components/Contexts/ContextMenuDivider.svelte +15 -15
- package/dist/Components/Contexts/ContextMenuOption.svelte +60 -60
- package/dist/Components/Contexts/Toast.svelte +86 -86
- package/dist/Components/Contexts/ToastContainer.svelte +65 -65
- package/dist/Components/Contexts/Tooltip.svelte +37 -37
- package/dist/Components/DataMatrixIcon.svelte +112 -112
- package/dist/Components/DateInput.svelte +148 -148
- package/dist/Components/DatePicker.svelte +300 -300
- package/dist/Components/DesktopModal.svelte +90 -90
- package/dist/Components/Dial.svelte +204 -204
- package/dist/Components/DimensionInput.svelte +170 -170
- package/dist/Components/DragMenu/DragMenuHolder.svelte +119 -119
- package/dist/Components/DragMenu/DraggableCard.svelte +77 -77
- package/dist/Components/FileCard.svelte +24 -24
- package/dist/Components/FileUpload.svelte +236 -236
- package/dist/Components/GridInput.svelte +196 -196
- package/dist/Components/GridInputSet.svelte +29 -29
- package/dist/Components/HorizontalTabGroup.svelte +82 -82
- package/dist/Components/HorizontalTabGroupButton.svelte +44 -44
- package/dist/Components/Icon.svelte +128 -128
- package/dist/Components/Icons.js +357 -357
- package/dist/Components/InfoAlert.svelte +35 -35
- package/dist/Components/LoadingAnimation.svelte +29 -29
- package/dist/Components/LoadingModal.svelte +45 -45
- package/dist/Components/LoadingOverlay.svelte +25 -25
- package/dist/Components/Modal.svelte +258 -258
- package/dist/Components/MultiSelect.svelte +220 -220
- package/dist/Components/Nav/Nav.svelte +110 -110
- package/dist/Components/Nav/NavServiceMenuList.svelte +43 -43
- package/dist/Components/Nav/NavTab.svelte +62 -62
- package/dist/Components/Nav/ServiceMenuItem.svelte +112 -112
- package/dist/Components/Nav/ServicesNav.svelte +80 -80
- package/dist/Components/NumberInput.svelte +157 -157
- package/dist/Components/PageHeading.svelte +25 -25
- package/dist/Components/PasswordInput.svelte +88 -88
- package/dist/Components/Portal.svelte +36 -36
- package/dist/Components/ProgressBubble.svelte +107 -107
- package/dist/Components/QuerySelect.svelte +366 -366
- package/dist/Components/SingleSelect.svelte +250 -250
- package/dist/Components/StepButton.svelte +70 -70
- package/dist/Components/StepForm.svelte +140 -140
- package/dist/Components/Switch.svelte +69 -69
- package/dist/Components/Table/ARCHITECTURE.md +298 -298
- package/dist/Components/Table/Body/QuickSearchCell.svelte +679 -679
- package/dist/Components/Table/Body/Rows/ColumnHighlight.svelte +51 -51
- package/dist/Components/Table/Body/Rows/ColumnList.svelte +59 -59
- package/dist/Components/Table/Body/Rows/ColumnListRow.svelte +454 -454
- package/dist/Components/Table/Body/Rows/Columns/AccessorComponent.svelte +79 -79
- package/dist/Components/Table/Body/Rows/Columns/ActionsCell.svelte +185 -185
- package/dist/Components/Table/Body/Rows/Columns/BubbleCell.svelte +124 -124
- package/dist/Components/Table/Body/Rows/Columns/ExpandCell.svelte +131 -120
- package/dist/Components/Table/Body/Rows/Columns/FocusableImmutableCell.svelte +234 -234
- package/dist/Components/Table/Body/Rows/Columns/ProgressCell.svelte +105 -105
- package/dist/Components/Table/Body/Rows/Columns/TableAction.svelte +87 -87
- package/dist/Components/Table/Body/Rows/Columns/TableCheckbox.svelte +126 -126
- package/dist/Components/Table/Body/Rows/Columns/TableColumn.svelte +159 -159
- package/dist/Components/Table/Body/Rows/Columns/TableDatePicker.svelte +246 -246
- package/dist/Components/Table/Body/Rows/Columns/TableNumberInput.svelte +216 -216
- package/dist/Components/Table/Body/Rows/Columns/TableQuerySelect.svelte +252 -252
- package/dist/Components/Table/Body/Rows/Columns/TableRowSelectionCheckbox.svelte +179 -179
- package/dist/Components/Table/Body/Rows/Columns/TableSelect.svelte +221 -221
- package/dist/Components/Table/Body/Rows/Columns/TableTextInput.svelte +197 -197
- package/dist/Components/Table/Body/Rows/Columns/ValidityCell.svelte +190 -190
- package/dist/Components/Table/Body/Rows/TableRow.svelte +290 -290
- package/dist/Components/Table/Body/TableBody.svelte +155 -155
- package/dist/Components/Table/ColumnFactory.svelte.js +1 -0
- package/dist/Components/Table/Headers/HighlightAllHeader.svelte +41 -41
- package/dist/Components/Table/Headers/SelectAllHeader.svelte +30 -30
- package/dist/Components/Table/Headers/TableHead.svelte +415 -415
- package/dist/Components/Table/Misc/ColumnPanel.svelte +39 -39
- package/dist/Components/Table/Misc/ColumnPanelModal.svelte +39 -39
- package/dist/Components/Table/Misc/FilterInput.svelte +641 -641
- package/dist/Components/Table/Misc/FilterPanel.svelte +190 -190
- package/dist/Components/Table/Misc/FilterPanelModal.svelte +31 -31
- package/dist/Components/Table/Misc/ShareViewModal.svelte +291 -291
- package/dist/Components/Table/Misc/SidePanel.svelte +35 -35
- package/dist/Components/Table/Misc/TableConfigurationModal.svelte +644 -644
- package/dist/Components/Table/Misc/TableFooter.svelte +340 -340
- package/dist/Components/Table/Misc/TableHorizontalBar.svelte +140 -140
- package/dist/Components/Table/Misc/TableSidebar.svelte +200 -200
- package/dist/Components/Table/Misc/TableViewDropdown.svelte +105 -105
- package/dist/Components/Table/Misc/ToolboxPanel.svelte +100 -100
- package/dist/Components/Table/Misc/ToolboxPanelModal.svelte +107 -107
- package/dist/Components/Table/Misc/UpdateViewOptionsModal.svelte +192 -192
- package/dist/Components/Table/NestedTable.svelte +130 -130
- package/dist/Components/Table/Table.svelte +692 -692
- package/dist/Components/Table/Types/Columns/Definitions/Expand/ExpandDef.svelte.d.ts +5 -0
- package/dist/Components/Table/Types/Columns/Definitions/Expand/ExpandDef.svelte.js +3 -0
- package/dist/Components/Table/Types/Public/ColumnOptions.d.ts +10 -0
- package/dist/Components/Test/TestContextConsumer.svelte +13 -13
- package/dist/Components/TextArea.svelte +130 -130
- package/dist/Components/TextInput.svelte +176 -176
- package/dist/Components/ThreeStateRadio.svelte +131 -131
- package/dist/Components/Touch/BoolCard.svelte +45 -45
- package/dist/Components/Touch/DateModal.svelte +209 -209
- package/dist/Components/Touch/EditCard.svelte +59 -59
- package/dist/Components/Touch/InfoCard.svelte +31 -31
- package/dist/Components/Touch/InfoTextCard.svelte +28 -28
- package/dist/Components/Touch/ModalExplanation.svelte +17 -17
- package/dist/Components/Touch/NumberKeyboard.svelte +225 -225
- package/dist/Components/Touch/NumberModal.svelte +79 -79
- package/dist/Components/Touch/PlusMinusCard.svelte +46 -46
- package/dist/Components/Touch/SelectModal.svelte +127 -127
- package/dist/Components/Touch/SummaryCard.svelte +93 -93
- package/dist/Components/Touch/TextAreaModal.svelte +95 -95
- package/dist/Components/Touch/TextModal.svelte +106 -106
- package/dist/Components/Touch/TouchCard.svelte +33 -33
- package/dist/Components/Touch/TouchModal.svelte +274 -274
- package/dist/Components/Touch/UtilityButton.svelte +109 -109
- package/dist/Components/VerticalTabGroup.svelte +79 -79
- package/dist/Components/VerticalTabGroupButton.svelte +58 -58
- package/dist/Helpers/Datamatrix.d.ts +19 -19
- package/dist/Helpers/Datamatrix.js +291 -291
- package/dist/Types/Examples/ExampleModal.svelte +35 -35
- package/dist/scss/_basics.scss +12 -12
- package/dist/scss/_colours.scss +134 -134
- package/dist/scss/_mixins.scss +3392 -3392
- package/dist/scss/_motion.scss +57 -57
- package/dist/scss/_sizing.scss +85 -85
- package/dist/scss/_transitions.scss +8 -8
- package/package.json +1 -1
|
@@ -1,252 +1,252 @@
|
|
|
1
|
-
<svelte:options runes />
|
|
2
|
-
|
|
3
|
-
<script
|
|
4
|
-
lang="ts"
|
|
5
|
-
generics="V extends object, VP extends ValueProp<V>"
|
|
6
|
-
>
|
|
7
|
-
import { devCatch, generateWeakId, vowels } from '../Helpers/Helpers.svelte.js';
|
|
8
|
-
import { attachDropdownPortal } from '../Helpers/dropdownPortal.js';
|
|
9
|
-
import { Colour, ColourSet } from '../scss/colours.js';
|
|
10
|
-
import type { ValueProp } from '../Types/Internal/Misc.js';
|
|
11
|
-
import { Size } from '../Types/Internal/Size.js';
|
|
12
|
-
import Svelecte from 'svelecte';
|
|
13
|
-
import { onMount, tick } from 'svelte';
|
|
14
|
-
import Action from './Action.svelte';
|
|
15
|
-
import type { SingleSelectProps } from './SingleSelectProps.js';
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
label,
|
|
19
|
-
options,
|
|
20
|
-
labelProp,
|
|
21
|
-
valueProp,
|
|
22
|
-
focusOnLoad = false,
|
|
23
|
-
searchable = true,
|
|
24
|
-
creatable = false,
|
|
25
|
-
|
|
26
|
-
createFilter,
|
|
27
|
-
disabled,
|
|
28
|
-
width,
|
|
29
|
-
height,
|
|
30
|
-
name = 'Item',
|
|
31
|
-
valueAsObject,
|
|
32
|
-
minHeight,
|
|
33
|
-
clearable = false,
|
|
34
|
-
required = false,
|
|
35
|
-
invalid = false,
|
|
36
|
-
borderless = false,
|
|
37
|
-
lazyDropdown = false,
|
|
38
|
-
forceUpwards = false,
|
|
39
|
-
inputId = generateWeakId(),
|
|
40
|
-
value: selectedValue,
|
|
41
|
-
onchange,
|
|
42
|
-
onfocus,
|
|
43
|
-
onCreateOption,
|
|
44
|
-
}: SingleSelectProps<V, VP> = $props();
|
|
45
|
-
|
|
46
|
-
// Single source of truth for the current value. The previous code mixed
|
|
47
|
-
// `$derived` and `$effect.pre`, which fired a redundant assignment on mount.
|
|
48
|
-
const currentValue = $derived(selectedValue);
|
|
49
|
-
let ref = $state<Svelecte | undefined>();
|
|
50
|
-
let wrapperRef: HTMLDivElement | undefined = $state();
|
|
51
|
-
|
|
52
|
-
const an = $derived(name && vowels.has(name.at(0)?.toLocaleLowerCase() ?? '') ? 'an' : 'a');
|
|
53
|
-
|
|
54
|
-
const isInvalid = $derived((required && !currentValue) || invalid);
|
|
55
|
-
|
|
56
|
-
let hasAutoFocused = $state(false);
|
|
57
|
-
|
|
58
|
-
// ResizeObserver-driven height. Replaces the layout-forcing
|
|
59
|
-
// `getBoundingClientRect()` call that used to run inside a `$derived`.
|
|
60
|
-
let dropdownBottom = $state(0);
|
|
61
|
-
$effect(() => {
|
|
62
|
-
if (!wrapperRef) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const ro = new ResizeObserver((entries) => {
|
|
66
|
-
const entry = entries[0];
|
|
67
|
-
dropdownBottom = entry.borderBoxSize[0].blockSize;
|
|
68
|
-
});
|
|
69
|
-
ro.observe(wrapperRef);
|
|
70
|
-
return () => {
|
|
71
|
-
ro.disconnect();
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
function forceShowDropdown(input: HTMLInputElement) {
|
|
76
|
-
if (focusOnLoad && !hasAutoFocused) {
|
|
77
|
-
hasAutoFocused = true;
|
|
78
|
-
input.click();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let isExpanded = $state(false);
|
|
83
|
-
|
|
84
|
-
onMount(() => {
|
|
85
|
-
if (focusOnLoad) {
|
|
86
|
-
tick()
|
|
87
|
-
.then(() => {
|
|
88
|
-
(ref as HTMLSelectElement | undefined)?.focus();
|
|
89
|
-
})
|
|
90
|
-
.catch(devCatch);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const input = document.getElementById(inputId);
|
|
94
|
-
const svelecteRoot = input?.closest('div.svelecte') as HTMLElement | null;
|
|
95
|
-
const dropdownRef =
|
|
96
|
-
(svelecteRoot?.querySelector('.sv_dropdown') as HTMLElement | null) ?? undefined;
|
|
97
|
-
|
|
98
|
-
// HACK callback for is-open on/off. Drives the chevron
|
|
99
|
-
// rotation / clear icon visibility below.
|
|
100
|
-
const observer = new MutationObserver((mutations: Array<MutationRecord>) => {
|
|
101
|
-
for (let i = mutations.length - 1; i > -1; i--) {
|
|
102
|
-
const mutation = mutations[i];
|
|
103
|
-
if (mutation.attributeName === 'class') {
|
|
104
|
-
isExpanded = dropdownRef?.classList.contains('is-open') ?? false;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
if (dropdownRef) {
|
|
110
|
-
observer.observe(dropdownRef, { attributes: true });
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Teleport the dropdown to `document.body` while open so it
|
|
114
|
-
// escapes every ancestor `overflow` / `transform` / `z-index`
|
|
115
|
-
// stacking context (filter-panel groups, sticky table strips,
|
|
116
|
-
// modals, etc.). The portal helper also auto-flips upwards
|
|
117
|
-
// when there is not enough space below the trigger and
|
|
118
|
-
// repositions on scroll / resize. See
|
|
119
|
-
// `Helpers/dropdownPortal.ts` for the full rationale.
|
|
120
|
-
const detachPortal = attachDropdownPortal({
|
|
121
|
-
getTrigger: () => svelecteRoot,
|
|
122
|
-
getDropdown: () => dropdownRef,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
return () => {
|
|
126
|
-
observer.disconnect();
|
|
127
|
-
detachPortal();
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
function isObject(value: SingleSelectProps<V, VP>['value']): value is V {
|
|
132
|
-
return value !== null && typeof value === 'object';
|
|
133
|
-
}
|
|
134
|
-
</script>
|
|
135
|
-
|
|
136
|
-
<div
|
|
137
|
-
class="select-wrapper"
|
|
138
|
-
class:no-border={borderless}
|
|
139
|
-
style={`${width ? `--input-width: ${width};` : ''}${height ? `--input-height: ${height};` : ''} --dropdown-bottom: calc(${dropdownBottom}px + 1px); --sv-min-height: ${minHeight ?? '2rem'};`}
|
|
140
|
-
class:invalid={isInvalid}
|
|
141
|
-
class:force-upwards={forceUpwards}
|
|
142
|
-
bind:this={wrapperRef}
|
|
143
|
-
>
|
|
144
|
-
{#if label}
|
|
145
|
-
<label for={inputId}>
|
|
146
|
-
<span
|
|
147
|
-
>{label}{#if !required} - <i>optional</i>{/if}</span
|
|
148
|
-
>
|
|
149
|
-
<span class="border"
|
|
150
|
-
>{label}{#if !required} - <i>optional</i>{/if}</span
|
|
151
|
-
>
|
|
152
|
-
</label>
|
|
153
|
-
{/if}
|
|
154
|
-
|
|
155
|
-
<Svelecte
|
|
156
|
-
{createFilter}
|
|
157
|
-
{disabled}
|
|
158
|
-
{name}
|
|
159
|
-
onFocus={(target: HTMLInputElement) => {
|
|
160
|
-
forceShowDropdown(target);
|
|
161
|
-
onfocus?.(target);
|
|
162
|
-
}}
|
|
163
|
-
bind:this={ref}
|
|
164
|
-
{valueAsObject}
|
|
165
|
-
{inputId}
|
|
166
|
-
{required}
|
|
167
|
-
valueField={valueProp}
|
|
168
|
-
labelField={labelProp}
|
|
169
|
-
virtualList={false}
|
|
170
|
-
{options}
|
|
171
|
-
{creatable}
|
|
172
|
-
searchProps={{ keepSelectionInList: true }}
|
|
173
|
-
{onCreateOption}
|
|
174
|
-
placeholder="Please Select {name ? `${an} ${name}` : ''}"
|
|
175
|
-
{lazyDropdown}
|
|
176
|
-
value={// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
177
|
-
currentValue as Array<any>}
|
|
178
|
-
onChange={(newValue: V | null) => {
|
|
179
|
-
// svelecte always emits the full option object regardless of
|
|
180
|
-
// `valueAsObject`. Map to the shape the discriminated variant
|
|
181
|
-
// promised: primitive for AsPrimitive, object for AsObject.
|
|
182
|
-
if (valueAsObject) {
|
|
183
|
-
void (onchange as (v: V | null) => void | Promise<void>)(newValue);
|
|
184
|
-
} else {
|
|
185
|
-
const primitive = newValue == null ? null : newValue[valueProp];
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
187
|
-
void (onchange as (v: V[VP] | null) => void | Promise<void>)(primitive);
|
|
188
|
-
}
|
|
189
|
-
}}
|
|
190
|
-
{searchable}
|
|
191
|
-
selectOnTab
|
|
192
|
-
keepSelectionInList
|
|
193
|
-
deselectMode={clearable ? 'toggle' : 'none'}
|
|
194
|
-
>
|
|
195
|
-
{#snippet option(opt)}<span class="dropdown-item"> {(opt as V)[labelProp]}</span>{/snippet}
|
|
196
|
-
|
|
197
|
-
{#snippet append()}
|
|
198
|
-
<div class="icons">
|
|
199
|
-
{#if clearable && currentValue}
|
|
200
|
-
<Action
|
|
201
|
-
noTabIndex
|
|
202
|
-
onclick={(e: MouseEvent) => {
|
|
203
|
-
if (isExpanded) {
|
|
204
|
-
e.stopPropagation();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
void onchange(null);
|
|
208
|
-
}}
|
|
209
|
-
{disabled}
|
|
210
|
-
colourSet={ColourSet.Auxiliary}
|
|
211
|
-
size={Size.Small}
|
|
212
|
-
icon={{
|
|
213
|
-
name: 'close-menu-cross',
|
|
214
|
-
colour: Colour['$ui-blue-10'],
|
|
215
|
-
}}
|
|
216
|
-
/>
|
|
217
|
-
{/if}
|
|
218
|
-
|
|
219
|
-
<Action
|
|
220
|
-
noTabIndex
|
|
221
|
-
colourSet={ColourSet.Auxiliary}
|
|
222
|
-
size={Size.Small}
|
|
223
|
-
{disabled}
|
|
224
|
-
icon={{
|
|
225
|
-
name: isExpanded ? 'chevron-up' : 'chevron-down',
|
|
226
|
-
colour: Colour['$ui-blue-10'],
|
|
227
|
-
}}
|
|
228
|
-
/>
|
|
229
|
-
</div>
|
|
230
|
-
{/snippet}
|
|
231
|
-
{#snippet toggleIcon()}
|
|
232
|
-
<div class="nothing"></div>
|
|
233
|
-
{/snippet}
|
|
234
|
-
|
|
235
|
-
{#snippet selection(/*_selectedOptions: Array<any>*/)}
|
|
236
|
-
<span
|
|
237
|
-
class="selection"
|
|
238
|
-
class:invalid={isInvalid}
|
|
239
|
-
>
|
|
240
|
-
{#if isObject(selectedValue)}
|
|
241
|
-
{selectedValue[labelProp]}
|
|
242
|
-
{:else}
|
|
243
|
-
{options.find((it) => it[valueProp] === selectedValue)?.[labelProp]}
|
|
244
|
-
{/if}
|
|
245
|
-
</span>
|
|
246
|
-
{/snippet}
|
|
247
|
-
</Svelecte>
|
|
248
|
-
</div>
|
|
249
|
-
|
|
1
|
+
<svelte:options runes />
|
|
2
|
+
|
|
3
|
+
<script
|
|
4
|
+
lang="ts"
|
|
5
|
+
generics="V extends object, VP extends ValueProp<V>"
|
|
6
|
+
>
|
|
7
|
+
import { devCatch, generateWeakId, vowels } from '../Helpers/Helpers.svelte.js';
|
|
8
|
+
import { attachDropdownPortal } from '../Helpers/dropdownPortal.js';
|
|
9
|
+
import { Colour, ColourSet } from '../scss/colours.js';
|
|
10
|
+
import type { ValueProp } from '../Types/Internal/Misc.js';
|
|
11
|
+
import { Size } from '../Types/Internal/Size.js';
|
|
12
|
+
import Svelecte from 'svelecte';
|
|
13
|
+
import { onMount, tick } from 'svelte';
|
|
14
|
+
import Action from './Action.svelte';
|
|
15
|
+
import type { SingleSelectProps } from './SingleSelectProps.js';
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
label,
|
|
19
|
+
options,
|
|
20
|
+
labelProp,
|
|
21
|
+
valueProp,
|
|
22
|
+
focusOnLoad = false,
|
|
23
|
+
searchable = true,
|
|
24
|
+
creatable = false,
|
|
25
|
+
|
|
26
|
+
createFilter,
|
|
27
|
+
disabled,
|
|
28
|
+
width,
|
|
29
|
+
height,
|
|
30
|
+
name = 'Item',
|
|
31
|
+
valueAsObject,
|
|
32
|
+
minHeight,
|
|
33
|
+
clearable = false,
|
|
34
|
+
required = false,
|
|
35
|
+
invalid = false,
|
|
36
|
+
borderless = false,
|
|
37
|
+
lazyDropdown = false,
|
|
38
|
+
forceUpwards = false,
|
|
39
|
+
inputId = generateWeakId(),
|
|
40
|
+
value: selectedValue,
|
|
41
|
+
onchange,
|
|
42
|
+
onfocus,
|
|
43
|
+
onCreateOption,
|
|
44
|
+
}: SingleSelectProps<V, VP> = $props();
|
|
45
|
+
|
|
46
|
+
// Single source of truth for the current value. The previous code mixed
|
|
47
|
+
// `$derived` and `$effect.pre`, which fired a redundant assignment on mount.
|
|
48
|
+
const currentValue = $derived(selectedValue);
|
|
49
|
+
let ref = $state<Svelecte | undefined>();
|
|
50
|
+
let wrapperRef: HTMLDivElement | undefined = $state();
|
|
51
|
+
|
|
52
|
+
const an = $derived(name && vowels.has(name.at(0)?.toLocaleLowerCase() ?? '') ? 'an' : 'a');
|
|
53
|
+
|
|
54
|
+
const isInvalid = $derived((required && !currentValue) || invalid);
|
|
55
|
+
|
|
56
|
+
let hasAutoFocused = $state(false);
|
|
57
|
+
|
|
58
|
+
// ResizeObserver-driven height. Replaces the layout-forcing
|
|
59
|
+
// `getBoundingClientRect()` call that used to run inside a `$derived`.
|
|
60
|
+
let dropdownBottom = $state(0);
|
|
61
|
+
$effect(() => {
|
|
62
|
+
if (!wrapperRef) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const ro = new ResizeObserver((entries) => {
|
|
66
|
+
const entry = entries[0];
|
|
67
|
+
dropdownBottom = entry.borderBoxSize[0].blockSize;
|
|
68
|
+
});
|
|
69
|
+
ro.observe(wrapperRef);
|
|
70
|
+
return () => {
|
|
71
|
+
ro.disconnect();
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
function forceShowDropdown(input: HTMLInputElement) {
|
|
76
|
+
if (focusOnLoad && !hasAutoFocused) {
|
|
77
|
+
hasAutoFocused = true;
|
|
78
|
+
input.click();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let isExpanded = $state(false);
|
|
83
|
+
|
|
84
|
+
onMount(() => {
|
|
85
|
+
if (focusOnLoad) {
|
|
86
|
+
tick()
|
|
87
|
+
.then(() => {
|
|
88
|
+
(ref as HTMLSelectElement | undefined)?.focus();
|
|
89
|
+
})
|
|
90
|
+
.catch(devCatch);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const input = document.getElementById(inputId);
|
|
94
|
+
const svelecteRoot = input?.closest('div.svelecte') as HTMLElement | null;
|
|
95
|
+
const dropdownRef =
|
|
96
|
+
(svelecteRoot?.querySelector('.sv_dropdown') as HTMLElement | null) ?? undefined;
|
|
97
|
+
|
|
98
|
+
// HACK callback for is-open on/off. Drives the chevron
|
|
99
|
+
// rotation / clear icon visibility below.
|
|
100
|
+
const observer = new MutationObserver((mutations: Array<MutationRecord>) => {
|
|
101
|
+
for (let i = mutations.length - 1; i > -1; i--) {
|
|
102
|
+
const mutation = mutations[i];
|
|
103
|
+
if (mutation.attributeName === 'class') {
|
|
104
|
+
isExpanded = dropdownRef?.classList.contains('is-open') ?? false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (dropdownRef) {
|
|
110
|
+
observer.observe(dropdownRef, { attributes: true });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Teleport the dropdown to `document.body` while open so it
|
|
114
|
+
// escapes every ancestor `overflow` / `transform` / `z-index`
|
|
115
|
+
// stacking context (filter-panel groups, sticky table strips,
|
|
116
|
+
// modals, etc.). The portal helper also auto-flips upwards
|
|
117
|
+
// when there is not enough space below the trigger and
|
|
118
|
+
// repositions on scroll / resize. See
|
|
119
|
+
// `Helpers/dropdownPortal.ts` for the full rationale.
|
|
120
|
+
const detachPortal = attachDropdownPortal({
|
|
121
|
+
getTrigger: () => svelecteRoot,
|
|
122
|
+
getDropdown: () => dropdownRef,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return () => {
|
|
126
|
+
observer.disconnect();
|
|
127
|
+
detachPortal();
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
function isObject(value: SingleSelectProps<V, VP>['value']): value is V {
|
|
132
|
+
return value !== null && typeof value === 'object';
|
|
133
|
+
}
|
|
134
|
+
</script>
|
|
135
|
+
|
|
136
|
+
<div
|
|
137
|
+
class="select-wrapper"
|
|
138
|
+
class:no-border={borderless}
|
|
139
|
+
style={`${width ? `--input-width: ${width};` : ''}${height ? `--input-height: ${height};` : ''} --dropdown-bottom: calc(${dropdownBottom}px + 1px); --sv-min-height: ${minHeight ?? '2rem'};`}
|
|
140
|
+
class:invalid={isInvalid}
|
|
141
|
+
class:force-upwards={forceUpwards}
|
|
142
|
+
bind:this={wrapperRef}
|
|
143
|
+
>
|
|
144
|
+
{#if label}
|
|
145
|
+
<label for={inputId}>
|
|
146
|
+
<span
|
|
147
|
+
>{label}{#if !required} - <i>optional</i>{/if}</span
|
|
148
|
+
>
|
|
149
|
+
<span class="border"
|
|
150
|
+
>{label}{#if !required} - <i>optional</i>{/if}</span
|
|
151
|
+
>
|
|
152
|
+
</label>
|
|
153
|
+
{/if}
|
|
154
|
+
|
|
155
|
+
<Svelecte
|
|
156
|
+
{createFilter}
|
|
157
|
+
{disabled}
|
|
158
|
+
{name}
|
|
159
|
+
onFocus={(target: HTMLInputElement) => {
|
|
160
|
+
forceShowDropdown(target);
|
|
161
|
+
onfocus?.(target);
|
|
162
|
+
}}
|
|
163
|
+
bind:this={ref}
|
|
164
|
+
{valueAsObject}
|
|
165
|
+
{inputId}
|
|
166
|
+
{required}
|
|
167
|
+
valueField={valueProp}
|
|
168
|
+
labelField={labelProp}
|
|
169
|
+
virtualList={false}
|
|
170
|
+
{options}
|
|
171
|
+
{creatable}
|
|
172
|
+
searchProps={{ keepSelectionInList: true }}
|
|
173
|
+
{onCreateOption}
|
|
174
|
+
placeholder="Please Select {name ? `${an} ${name}` : ''}"
|
|
175
|
+
{lazyDropdown}
|
|
176
|
+
value={// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
177
|
+
currentValue as Array<any>}
|
|
178
|
+
onChange={(newValue: V | null) => {
|
|
179
|
+
// svelecte always emits the full option object regardless of
|
|
180
|
+
// `valueAsObject`. Map to the shape the discriminated variant
|
|
181
|
+
// promised: primitive for AsPrimitive, object for AsObject.
|
|
182
|
+
if (valueAsObject) {
|
|
183
|
+
void (onchange as (v: V | null) => void | Promise<void>)(newValue);
|
|
184
|
+
} else {
|
|
185
|
+
const primitive = newValue == null ? null : newValue[valueProp];
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
187
|
+
void (onchange as (v: V[VP] | null) => void | Promise<void>)(primitive);
|
|
188
|
+
}
|
|
189
|
+
}}
|
|
190
|
+
{searchable}
|
|
191
|
+
selectOnTab
|
|
192
|
+
keepSelectionInList
|
|
193
|
+
deselectMode={clearable ? 'toggle' : 'none'}
|
|
194
|
+
>
|
|
195
|
+
{#snippet option(opt)}<span class="dropdown-item"> {(opt as V)[labelProp]}</span>{/snippet}
|
|
196
|
+
|
|
197
|
+
{#snippet append()}
|
|
198
|
+
<div class="icons">
|
|
199
|
+
{#if clearable && currentValue}
|
|
200
|
+
<Action
|
|
201
|
+
noTabIndex
|
|
202
|
+
onclick={(e: MouseEvent) => {
|
|
203
|
+
if (isExpanded) {
|
|
204
|
+
e.stopPropagation();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
void onchange(null);
|
|
208
|
+
}}
|
|
209
|
+
{disabled}
|
|
210
|
+
colourSet={ColourSet.Auxiliary}
|
|
211
|
+
size={Size.Small}
|
|
212
|
+
icon={{
|
|
213
|
+
name: 'close-menu-cross',
|
|
214
|
+
colour: Colour['$ui-blue-10'],
|
|
215
|
+
}}
|
|
216
|
+
/>
|
|
217
|
+
{/if}
|
|
218
|
+
|
|
219
|
+
<Action
|
|
220
|
+
noTabIndex
|
|
221
|
+
colourSet={ColourSet.Auxiliary}
|
|
222
|
+
size={Size.Small}
|
|
223
|
+
{disabled}
|
|
224
|
+
icon={{
|
|
225
|
+
name: isExpanded ? 'chevron-up' : 'chevron-down',
|
|
226
|
+
colour: Colour['$ui-blue-10'],
|
|
227
|
+
}}
|
|
228
|
+
/>
|
|
229
|
+
</div>
|
|
230
|
+
{/snippet}
|
|
231
|
+
{#snippet toggleIcon()}
|
|
232
|
+
<div class="nothing"></div>
|
|
233
|
+
{/snippet}
|
|
234
|
+
|
|
235
|
+
{#snippet selection(/*_selectedOptions: Array<any>*/)}
|
|
236
|
+
<span
|
|
237
|
+
class="selection"
|
|
238
|
+
class:invalid={isInvalid}
|
|
239
|
+
>
|
|
240
|
+
{#if isObject(selectedValue)}
|
|
241
|
+
{selectedValue[labelProp]}
|
|
242
|
+
{:else}
|
|
243
|
+
{options.find((it) => it[valueProp] === selectedValue)?.[labelProp]}
|
|
244
|
+
{/if}
|
|
245
|
+
</span>
|
|
246
|
+
{/snippet}
|
|
247
|
+
</Svelecte>
|
|
248
|
+
</div>
|
|
249
|
+
|
|
250
250
|
<style>.select-wrapper {
|
|
251
251
|
min-width: var(--input-min-width, 12rem);
|
|
252
252
|
width: var(--input-width, 100%);
|
|
@@ -409,4 +409,4 @@ div.icons {
|
|
|
409
409
|
}
|
|
410
410
|
:global(.dropdown-item) .toggle-icon.yes {
|
|
411
411
|
opacity: 1;
|
|
412
|
-
}</style>
|
|
412
|
+
}</style>
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
<svelte:options runes />
|
|
2
|
-
|
|
3
|
-
<script
|
|
4
|
-
lang="ts"
|
|
5
|
-
generics="Args"
|
|
6
|
-
>
|
|
7
|
-
import { useAsyncFlag } from '../Helpers/AsyncFlag.svelte.js';
|
|
8
|
-
import { useTooltip } from '../Helpers/useTooltip.svelte.js';
|
|
9
|
-
import { Colour } from '../scss/colours.js';
|
|
10
|
-
import { Side } from '../Types/Internal/Side.js';
|
|
11
|
-
import { Size } from '../Types/Internal/Size.js';
|
|
12
|
-
import Icon from './Icon.svelte';
|
|
13
|
-
import type { StepButtonProps } from './StepButtonProps.js';
|
|
14
|
-
|
|
15
|
-
const { option, selected, index }: StepButtonProps<Args> = $props();
|
|
16
|
-
|
|
17
|
-
const isValid = useAsyncFlag(() => option.isValid, true);
|
|
18
|
-
const disabled = useAsyncFlag(() => option.disabled, false);
|
|
19
|
-
const visible = useAsyncFlag(() => option.visible, true);
|
|
20
|
-
|
|
21
|
-
// Shared tooltip lifecycle: hover handlers plus unmount-time teardown
|
|
22
|
-
// (load-bearing because StepButton lives inside StepForm which
|
|
23
|
-
// re-renders the tab strip on every step change).
|
|
24
|
-
const tt = useTooltip({
|
|
25
|
-
text: () => option.label,
|
|
26
|
-
arrow: () => Side.Top,
|
|
27
|
-
});
|
|
28
|
-
</script>
|
|
29
|
-
|
|
30
|
-
<button
|
|
31
|
-
class:selected
|
|
32
|
-
disabled={disabled.value}
|
|
33
|
-
onclick={() => {
|
|
34
|
-
option.onclick();
|
|
35
|
-
}}
|
|
36
|
-
type="button"
|
|
37
|
-
class="tab"
|
|
38
|
-
class:invalid={!isValid.value}
|
|
39
|
-
class:hidden={!visible.value}
|
|
40
|
-
onmouseenter={tt.onmouseenter}
|
|
41
|
-
onmouseleave={tt.onmouseleave}
|
|
42
|
-
>
|
|
43
|
-
<div
|
|
44
|
-
class="bordered"
|
|
45
|
-
class:invalid={!isValid.value}
|
|
46
|
-
>
|
|
47
|
-
{#if option.iconLeft}
|
|
48
|
-
<Icon
|
|
49
|
-
{...option.iconLeft}
|
|
50
|
-
colour={Colour['$brand-primary']}
|
|
51
|
-
/>
|
|
52
|
-
{/if}
|
|
53
|
-
{index + 1}
|
|
54
|
-
{#if !isValid.value}
|
|
55
|
-
<Icon
|
|
56
|
-
name="error"
|
|
57
|
-
colour={Colour['$error-border']}
|
|
58
|
-
size={Size.Small}
|
|
59
|
-
/>
|
|
60
|
-
{:else if option.iconRight}
|
|
61
|
-
<Icon
|
|
62
|
-
colour={Colour['$brand-primary']}
|
|
63
|
-
size={Size.Small}
|
|
64
|
-
{...option.iconRight}
|
|
65
|
-
/>
|
|
66
|
-
{/if}
|
|
67
|
-
</div>
|
|
68
|
-
</button>
|
|
69
|
-
|
|
1
|
+
<svelte:options runes />
|
|
2
|
+
|
|
3
|
+
<script
|
|
4
|
+
lang="ts"
|
|
5
|
+
generics="Args"
|
|
6
|
+
>
|
|
7
|
+
import { useAsyncFlag } from '../Helpers/AsyncFlag.svelte.js';
|
|
8
|
+
import { useTooltip } from '../Helpers/useTooltip.svelte.js';
|
|
9
|
+
import { Colour } from '../scss/colours.js';
|
|
10
|
+
import { Side } from '../Types/Internal/Side.js';
|
|
11
|
+
import { Size } from '../Types/Internal/Size.js';
|
|
12
|
+
import Icon from './Icon.svelte';
|
|
13
|
+
import type { StepButtonProps } from './StepButtonProps.js';
|
|
14
|
+
|
|
15
|
+
const { option, selected, index }: StepButtonProps<Args> = $props();
|
|
16
|
+
|
|
17
|
+
const isValid = useAsyncFlag(() => option.isValid, true);
|
|
18
|
+
const disabled = useAsyncFlag(() => option.disabled, false);
|
|
19
|
+
const visible = useAsyncFlag(() => option.visible, true);
|
|
20
|
+
|
|
21
|
+
// Shared tooltip lifecycle: hover handlers plus unmount-time teardown
|
|
22
|
+
// (load-bearing because StepButton lives inside StepForm which
|
|
23
|
+
// re-renders the tab strip on every step change).
|
|
24
|
+
const tt = useTooltip({
|
|
25
|
+
text: () => option.label,
|
|
26
|
+
arrow: () => Side.Top,
|
|
27
|
+
});
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<button
|
|
31
|
+
class:selected
|
|
32
|
+
disabled={disabled.value}
|
|
33
|
+
onclick={() => {
|
|
34
|
+
option.onclick();
|
|
35
|
+
}}
|
|
36
|
+
type="button"
|
|
37
|
+
class="tab"
|
|
38
|
+
class:invalid={!isValid.value}
|
|
39
|
+
class:hidden={!visible.value}
|
|
40
|
+
onmouseenter={tt.onmouseenter}
|
|
41
|
+
onmouseleave={tt.onmouseleave}
|
|
42
|
+
>
|
|
43
|
+
<div
|
|
44
|
+
class="bordered"
|
|
45
|
+
class:invalid={!isValid.value}
|
|
46
|
+
>
|
|
47
|
+
{#if option.iconLeft}
|
|
48
|
+
<Icon
|
|
49
|
+
{...option.iconLeft}
|
|
50
|
+
colour={Colour['$brand-primary']}
|
|
51
|
+
/>
|
|
52
|
+
{/if}
|
|
53
|
+
{index + 1}
|
|
54
|
+
{#if !isValid.value}
|
|
55
|
+
<Icon
|
|
56
|
+
name="error"
|
|
57
|
+
colour={Colour['$error-border']}
|
|
58
|
+
size={Size.Small}
|
|
59
|
+
/>
|
|
60
|
+
{:else if option.iconRight}
|
|
61
|
+
<Icon
|
|
62
|
+
colour={Colour['$brand-primary']}
|
|
63
|
+
size={Size.Small}
|
|
64
|
+
{...option.iconRight}
|
|
65
|
+
/>
|
|
66
|
+
{/if}
|
|
67
|
+
</div>
|
|
68
|
+
</button>
|
|
69
|
+
|
|
70
70
|
<style>button.tab.hidden {
|
|
71
71
|
display: none !important;
|
|
72
72
|
}
|
|
@@ -107,4 +107,4 @@
|
|
|
107
107
|
color: #aa1414;
|
|
108
108
|
border-color: #aa1414;
|
|
109
109
|
background-color: #f9e9e9;
|
|
110
|
-
}</style>
|
|
110
|
+
}</style>
|