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