@lavalogic/scoria 0.33.0 → 0.35.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 (130) hide show
  1. package/README.md +58 -58
  2. package/dist/Components/AccordionGroup.svelte +44 -63
  3. package/dist/Components/AccordionGroup.svelte.d.ts +2 -25
  4. package/dist/Components/AccordionGroupButton.svelte +106 -114
  5. package/dist/Components/AccordionGroupButton.svelte.d.ts +2 -2
  6. package/dist/Components/AccordionGroupButtonProps.d.ts +21 -0
  7. package/dist/Components/AccordionGroupButtonProps.js +1 -0
  8. package/dist/Components/Action.svelte +138 -138
  9. package/dist/Components/AlertModal.svelte +125 -125
  10. package/dist/Components/Base/ContextWrapper.svelte +50 -50
  11. package/dist/Components/Base/Pagination.svelte +190 -190
  12. package/dist/Components/Base/Snippets.svelte +29 -29
  13. package/dist/Components/BigRadioSet.svelte +29 -29
  14. package/dist/Components/Bubble.svelte +77 -77
  15. package/dist/Components/Button.svelte +197 -197
  16. package/dist/Components/Checkbox.svelte +68 -68
  17. package/dist/Components/CollapsibleCard.svelte +70 -70
  18. package/dist/Components/Contexts/ContextMenu.svelte +157 -157
  19. package/dist/Components/Contexts/ContextMenuDivider.svelte +11 -11
  20. package/dist/Components/Contexts/ContextMenuOption.svelte +52 -52
  21. package/dist/Components/Contexts/Toast.svelte +61 -61
  22. package/dist/Components/Contexts/ToastContainer.svelte +46 -46
  23. package/dist/Components/Contexts/Tooltip.svelte +26 -26
  24. package/dist/Components/DataMatrixIcon.svelte +41 -41
  25. package/dist/Components/DateInput.svelte +109 -109
  26. package/dist/Components/DatePicker.svelte +312 -312
  27. package/dist/Components/DesktopModal.svelte +106 -106
  28. package/dist/Components/Dial.svelte +151 -151
  29. package/dist/Components/DimensionInput.svelte +184 -184
  30. package/dist/Components/DragMenu/DragMenuHolder.svelte +106 -106
  31. package/dist/Components/DragMenu/DraggableCard.svelte +41 -41
  32. package/dist/Components/FileCard.svelte +20 -20
  33. package/dist/Components/FileUpload.svelte +196 -196
  34. package/dist/Components/GridInput.svelte +190 -190
  35. package/dist/Components/GridInputSet.svelte +22 -22
  36. package/dist/Components/HorizontalTabGroup.svelte +78 -78
  37. package/dist/Components/HorizontalTabGroupButton.svelte +96 -96
  38. package/dist/Components/Icon.svelte +97 -97
  39. package/dist/Components/Icons.js +357 -357
  40. package/dist/Components/LoadingAnimation.svelte +32 -32
  41. package/dist/Components/LoadingModal.svelte +47 -47
  42. package/dist/Components/LoadingOverlay.svelte +27 -27
  43. package/dist/Components/Modal.svelte +251 -251
  44. package/dist/Components/MultiSelect.svelte +197 -197
  45. package/dist/Components/Nav/Nav.svelte +97 -97
  46. package/dist/Components/Nav/NavServiceMenuList.svelte +34 -34
  47. package/dist/Components/Nav/NavTab.svelte +91 -91
  48. package/dist/Components/Nav/ServiceMenuItem.svelte +91 -91
  49. package/dist/Components/Nav/ServicesNav.svelte +53 -53
  50. package/dist/Components/NumberInput.svelte +144 -144
  51. package/dist/Components/PageHeading.svelte +36 -36
  52. package/dist/Components/PasswordInput.svelte +73 -73
  53. package/dist/Components/Portal.svelte +25 -25
  54. package/dist/Components/ProgressBubble.svelte +80 -80
  55. package/dist/Components/QuerySelect.svelte +411 -411
  56. package/dist/Components/SingleSelect.svelte +261 -261
  57. package/dist/Components/StepButton.svelte +120 -120
  58. package/dist/Components/StepForm.svelte +108 -108
  59. package/dist/Components/Switch.svelte +36 -36
  60. package/dist/Components/Table/Body/QuickSearchCell.svelte +632 -632
  61. package/dist/Components/Table/Body/Rows/ColumnHighlight.svelte +30 -30
  62. package/dist/Components/Table/Body/Rows/ColumnList.svelte +56 -56
  63. package/dist/Components/Table/Body/Rows/ColumnListRow.svelte +179 -179
  64. package/dist/Components/Table/Body/Rows/Columns/AccessorComponent.svelte +49 -49
  65. package/dist/Components/Table/Body/Rows/Columns/ActionsCell.svelte +180 -180
  66. package/dist/Components/Table/Body/Rows/Columns/BubbleCell.svelte +102 -102
  67. package/dist/Components/Table/Body/Rows/Columns/ExpandCell.svelte +119 -119
  68. package/dist/Components/Table/Body/Rows/Columns/FocusableImmutableCell.svelte +114 -114
  69. package/dist/Components/Table/Body/Rows/Columns/ProgressCell.svelte +96 -96
  70. package/dist/Components/Table/Body/Rows/Columns/TableAction.svelte +72 -72
  71. package/dist/Components/Table/Body/Rows/Columns/TableCheckbox.svelte +131 -131
  72. package/dist/Components/Table/Body/Rows/Columns/TableColumn.svelte +144 -144
  73. package/dist/Components/Table/Body/Rows/Columns/TableDatePicker.svelte +238 -238
  74. package/dist/Components/Table/Body/Rows/Columns/TableNumberInput.svelte +358 -358
  75. package/dist/Components/Table/Body/Rows/Columns/TableQuerySelect.svelte +338 -338
  76. package/dist/Components/Table/Body/Rows/Columns/TableRowSelectionCheckbox.svelte +183 -183
  77. package/dist/Components/Table/Body/Rows/Columns/TableSelect.svelte +309 -309
  78. package/dist/Components/Table/Body/Rows/Columns/TableTextInput.svelte +369 -369
  79. package/dist/Components/Table/Body/Rows/Columns/ValidityCell.svelte +170 -170
  80. package/dist/Components/Table/Body/Rows/TableRow.svelte +259 -259
  81. package/dist/Components/Table/Body/TableBody.svelte +67 -67
  82. package/dist/Components/Table/Headers/HighlightAllHeader.svelte +39 -39
  83. package/dist/Components/Table/Headers/SelectAllHeader.svelte +28 -28
  84. package/dist/Components/Table/Headers/TableHead.svelte +260 -260
  85. package/dist/Components/Table/Misc/ColumnPanel.svelte +78 -78
  86. package/dist/Components/Table/Misc/ColumnPanelModal.svelte +99 -99
  87. package/dist/Components/Table/Misc/FilterInput.svelte +556 -556
  88. package/dist/Components/Table/Misc/FilterPanel.svelte +46 -46
  89. package/dist/Components/Table/Misc/FilterPanelModal.svelte +67 -67
  90. package/dist/Components/Table/Misc/SidePanel.svelte +32 -32
  91. package/dist/Components/Table/Misc/TableFooter.svelte +304 -304
  92. package/dist/Components/Table/Misc/TableHorizontalBar.svelte +156 -156
  93. package/dist/Components/Table/Misc/TableSidebar.svelte +176 -176
  94. package/dist/Components/Table/Misc/ToolboxPanel.svelte +77 -77
  95. package/dist/Components/Table/Misc/ToolboxPanelModal.svelte +91 -91
  96. package/dist/Components/Table/NestedTable.svelte +84 -84
  97. package/dist/Components/Table/Table.svelte +492 -492
  98. package/dist/Components/Test/TestContextConsumer.svelte +13 -13
  99. package/dist/Components/TextArea.svelte +108 -108
  100. package/dist/Components/TextInput.svelte +147 -147
  101. package/dist/Components/ThreeStateRadio.svelte +124 -124
  102. package/dist/Components/Touch/BoolCard.svelte +52 -52
  103. package/dist/Components/Touch/DateModal.svelte +217 -217
  104. package/dist/Components/Touch/EditCard.svelte +52 -52
  105. package/dist/Components/Touch/InfoCard.svelte +24 -24
  106. package/dist/Components/Touch/InfoTextCard.svelte +21 -21
  107. package/dist/Components/Touch/ModalExplanation.svelte +20 -20
  108. package/dist/Components/Touch/NumberKeyboard.svelte +268 -268
  109. package/dist/Components/Touch/NumberModal.svelte +69 -69
  110. package/dist/Components/Touch/PlusMinusCard.svelte +50 -50
  111. package/dist/Components/Touch/SelectModal.svelte +105 -105
  112. package/dist/Components/Touch/SummaryCard.svelte +65 -65
  113. package/dist/Components/Touch/TextAreaModal.svelte +86 -86
  114. package/dist/Components/Touch/TextModal.svelte +123 -123
  115. package/dist/Components/Touch/TouchCard.svelte +28 -28
  116. package/dist/Components/Touch/TouchModal.svelte +259 -259
  117. package/dist/Components/Touch/UtilityButton.svelte +91 -91
  118. package/dist/Components/VerticalTabGroup.svelte +66 -66
  119. package/dist/Components/VerticalTabGroupButton.svelte +97 -97
  120. package/dist/Helpers/Datamatrix.d.ts +10 -10
  121. package/dist/Helpers/Datamatrix.js +1 -1
  122. package/dist/Helpers/Helpers.svelte.js +6 -4
  123. package/dist/Types/Examples/ExampleModal.svelte +34 -34
  124. package/dist/index.d.ts +1 -0
  125. package/dist/scss/_basics.scss +12 -12
  126. package/dist/scss/_colours.scss +134 -134
  127. package/dist/scss/_mixins.scss +3016 -3016
  128. package/dist/scss/_sizing.scss +69 -69
  129. package/dist/scss/_transitions.scss +8 -8
  130. package/package.json +2 -2
@@ -1,340 +1,340 @@
1
- <svelte:options runes />
2
-
3
- <script
4
- lang="ts"
5
- generics="T extends object,"
6
- >
7
- import QuerySelect from '../../../../QuerySelect.svelte';
8
- import type { QueryDef } from '../../../Types/Columns/Definitions/Accessors/QueryDef.svelte.js';
9
- import { TableContext } from '../../../Types/Context/TableContext.svelte.js';
10
- import { TableFocusDetails } from '../../../Types/Focus/TableFocusDetails.svelte.js';
11
- import { devCatch, isValidityTuple, loadingText } from '../../../../../Helpers/Helpers.svelte.js';
12
- import type { SelectOption } from '../../../../../Types/Internal/SelectOption.js';
13
- import { Validity } from '../../../../../Types/Internal/Validity.js';
14
- import { getContext, tick, untrack } from 'svelte';
15
- import type { TableQuerySelectProps } from './TableQuerySelectProps.js';
16
-
17
- const { cell }: TableQuerySelectProps<T, unknown> = $props();
18
-
19
- const value = $derived((cell.getValue() ?? null) as unknown);
20
-
21
- const visibleValue = $derived(
22
- cell.column.columnDef.getDisplayValue(cell.row.original, cell.row.originalIndex)
23
- );
24
-
25
- let tdref = $state<HTMLTableCellElement | undefined>();
26
-
27
- const columnDef: QueryDef<T> = $derived(cell.column.columnDef) as unknown as QueryDef<T>; // TODO stabilise and remove `as unknown`
28
- // const optional = $derived(columnDef.optional ?? false);
29
-
30
- let lastOptions: Array<SelectOption<unknown>> = $state([]);
31
-
32
- const tableContext = getContext<TableContext<T, never>>(TableContext.identifier);
33
-
34
- const editable = $derived(
35
- cell.column.columnDef.isEditable(cell.row.original, cell.row.originalIndex)
36
- );
37
-
38
- let valueAsyncCounter = 0;
39
- $effect(() => {
40
- void value;
41
- void lastOptions;
42
-
43
- untrack(() => {
44
- const localCounter = (valueAsyncCounter = valueAsyncCounter + 1);
45
- (async () => {
46
- try {
47
- const awaitedValue = await value;
48
- const label = (await visibleValue) ?? awaitedValue?.toString();
49
-
50
- if (awaitedValue != null && valueAsyncCounter === localCounter) {
51
- if (label == null) {
52
- throw new Error('invalid label and value');
53
- }
54
- if (!lastOptions.some((it) => it.value == awaitedValue)) {
55
- lastOptions.push({
56
- label,
57
- value: awaitedValue,
58
- });
59
- }
60
- } else if (columnDef.debug) {
61
- console.debug(
62
- `${cell.column.columnDef.id}: `,
63
- 'skipping async option insertion because it is stale'
64
- );
65
- }
66
- } catch (e) {
67
- if (columnDef.debug) {
68
- console.error(e);
69
- }
70
- if (valueAsyncCounter === localCounter) {
71
- //nothing happens
72
- } else if (columnDef.debug) {
73
- console.debug(
74
- `${cell.column.columnDef.id}: `,
75
- 'skipping caught async option insertion error because it is stale'
76
- );
77
- }
78
- }
79
- })().catch(devCatch);
80
- });
81
- });
82
-
83
- const focusDetails: TableFocusDetails<T, never> = $derived(
84
- new TableFocusDetails(cell, tableContext)
85
- );
86
-
87
- const wantsToBeEdited = $derived(
88
- tableContext.focusStart?.column === focusDetails.coordinates.column &&
89
- tableContext.focusEnd?.column === focusDetails.coordinates.column &&
90
- tableContext.focusStart.row === focusDetails.coordinates.row &&
91
- tableContext.focusEnd.row === focusDetails.coordinates.row &&
92
- !tableContext.isMousingDown &&
93
- tableContext.focusStartIsBeingEdited
94
- );
95
-
96
- let isBeingEdited = $state(false);
97
-
98
- function handleIsEditable(isEditable: boolean): Promise<void> {
99
- if (isEditable) {
100
- return tick().then(() => {
101
- isBeingEdited = true;
102
- });
103
- } else {
104
- if (isBeingEdited) {
105
- return tick()
106
- .then(() => {
107
- if (!tableContext.singleClickEditing) {
108
- tableContext.focusStartIsBeingEdited = false;
109
- }
110
-
111
- isBeingEdited = false;
112
- })
113
- .catch(devCatch);
114
- }
115
- }
116
- return Promise.resolve();
117
- }
118
-
119
- $effect(() => {
120
- void editable;
121
- if (wantsToBeEdited) {
122
- if (editable instanceof Promise) {
123
- editable
124
- .then((isEditable) => {
125
- return handleIsEditable(isEditable);
126
- })
127
-
128
- .catch(devCatch);
129
- } else {
130
- handleIsEditable(editable).catch(devCatch);
131
- }
132
- } else {
133
- tick()
134
- .then(() => {
135
- isBeingEdited = false;
136
- tableContext.focusStartIsBeingEdited = false;
137
- })
138
- .catch(devCatch);
139
- }
140
- });
141
-
142
- let validity: Validity = $state(Validity.Valid);
143
- $effect(() => {
144
- const validityPromise = focusDetails.validity;
145
-
146
- validityPromise
147
- .then((v) => {
148
- if (!v) {
149
- validity = Validity.Neutral;
150
- } else if (isValidityTuple(v)) {
151
- validity = v.value;
152
- } else {
153
- validity = v;
154
- }
155
- })
156
- .catch(devCatch);
157
- });
158
-
159
- const handleTDFocus = async () => {
160
- if (
161
- (await editable) &&
162
- tableContext.focusStart?.column === focusDetails.coordinates.column &&
163
- tableContext.focusStart.row === focusDetails.coordinates.row
164
- ) {
165
- if (
166
- tableContext.focusEnd?.column !== focusDetails.coordinates.column ||
167
- tableContext.focusEnd.row !== focusDetails.coordinates.row
168
- ) {
169
- tableContext.setFocusEnd(focusDetails.coordinates);
170
- }
171
-
172
- tableContext.isMousingDown = false;
173
- tableContext.focusStartIsBeingEdited = true;
174
- return true;
175
- }
176
-
177
- return false;
178
- };
179
-
180
- async function handleSingleClick(): Promise<boolean> {
181
- return tableContext.singleClickEditing && (await handleTDFocus());
182
- }
183
- async function handleDoubleClick(): Promise<boolean> {
184
- return !tableContext.singleClickEditing && (await handleTDFocus());
185
- }
186
-
187
- function tryHandleTDFocus() {
188
- handleTDFocus().catch(devCatch);
189
- }
190
-
191
- function handleUnfocus(e: KeyboardEvent) {
192
- if (e.key === 'Escape') {
193
- e.preventDefault();
194
- e.stopPropagation();
195
-
196
- tableContext.focusStartIsBeingEdited = false;
197
- tick()
198
- .then(() => {
199
- tdref?.focus();
200
- })
201
- .catch(devCatch);
202
-
203
- return true;
204
- }
205
-
206
- if (e.key === 'Tab') {
207
- e.preventDefault();
208
- return true;
209
- }
210
-
211
- return false;
212
- }
213
-
214
- function keydownForce(e: KeyboardEvent) {
215
- const shouldStop = handleUnfocus(e);
216
- if (!shouldStop && !(e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
217
- tick()
218
- .then(() => {
219
- tdref?.dispatchEvent(
220
- new KeyboardEvent('keydown', {
221
- key: e.key,
222
- altKey: e.getModifierState('Alt'),
223
- metaKey: e.getModifierState('Meta'),
224
- shiftKey: e.getModifierState('Shift'),
225
- ctrlKey: e.getModifierState('Control'),
226
- bubbles: true,
227
- })
228
- );
229
- })
230
- .catch(devCatch);
231
- }
232
- }
233
-
234
- function addKeydownEvent(target: HTMLInputElement | undefined) {
235
- target?.addEventListener('keydown', keydownForce);
236
- }
237
-
238
- let prevtdref: HTMLTableCellElement | undefined = undefined;
239
- $effect(() => {
240
- void tdref;
241
- untrack(() => {
242
- if (tdref && tdref != prevtdref) {
243
- tdref.addEventListener('edit', tryHandleTDFocus);
244
- } else {
245
- prevtdref = tdref;
246
- }
247
- });
248
- });
249
- </script>
250
-
251
- {#if isBeingEdited}
252
- <!-- onkeydown={handleInputKeydown} -->
253
- <!-- onkeydown={handleEsc} -->
254
- <td
255
- class="select-cell"
256
- bind:this={tdref}
257
- >
258
- <!-- TODO: -->
259
- {#await value then value}
260
- <QuerySelect
261
- focusOnLoad
262
- name={cell.column.columnDef.id}
263
- valueProp="value"
264
- labelProp="label"
265
- clearable={cell.column.columnDef.clearable}
266
- valueAsObject={false}
267
- {value}
268
- query={(v: string) => columnDef.query(v, cell.row.original, cell.row.originalIndex)}
269
- bind:options={lastOptions}
270
- onfocus={addKeydownEvent}
271
- onchange={(newValue: SelectOption<unknown> | null) => {
272
- if (newValue?.value !== value) {
273
- tableContext
274
- .onEditCell(cell.row.original, focusDetails.coordinates, newValue?.value ?? null)
275
- .catch(devCatch);
276
- }
277
-
278
- tableContext.focusStartIsBeingEdited = false;
279
- tick()
280
- .then(() => {
281
- tdref?.focus();
282
- })
283
- .catch(devCatch);
284
- }}
285
- />
286
- {/await}
287
- </td>
288
- {:else}
289
- <!-- // onkeydown={handleTdKeydown} -->
290
- <!-- svelte-ignore a11y_mouse_events_have_key_events -->
291
- <td
292
- style={focusDetails.outline}
293
- bind:this={tdref}
294
- tabIndex="0"
295
- id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
296
- class="focusable editable"
297
- class:multifocus={focusDetails.isMultiFocused}
298
- class:multifocus-start={focusDetails.isMultiFocusStart}
299
- class:info={validity == Validity.Info}
300
- class:success={validity == Validity.Valid}
301
- class:warning={validity == Validity.Warning}
302
- class:error={validity == Validity.Invalid}
303
- ondblclick={handleDoubleClick}
304
- onmousedown={(e) => {
305
- // start focus only on left click
306
- if (e.button === 0) {
307
- if (e.shiftKey) {
308
- e.preventDefault();
309
- tableContext.setFocusEnd(focusDetails.coordinates);
310
- } else {
311
- tableContext.startFocus(focusDetails.coordinates);
312
- }
313
- }
314
- }}
315
- onmouseover={() => {
316
- if (tableContext.isMousingDown) {
317
- tableContext.setFocusEnd(focusDetails.coordinates);
318
- }
319
- }}
320
- onmouseup={() => {
321
- handleSingleClick()
322
- .then((wasHandled) => {
323
- if (!wasHandled) {
324
- tableContext.endFocus(focusDetails.coordinates);
325
- }
326
- })
327
- .catch(devCatch);
328
- }}
329
- >
330
- {#await visibleValue}
331
- {loadingText}
332
- {:then v}
333
- {v}
334
- {/await}
335
- </td>
336
- {/if}
337
-
1
+ <svelte:options runes />
2
+
3
+ <script
4
+ lang="ts"
5
+ generics="T extends object,"
6
+ >
7
+ import QuerySelect from '../../../../QuerySelect.svelte';
8
+ import type { QueryDef } from '../../../Types/Columns/Definitions/Accessors/QueryDef.svelte.js';
9
+ import { TableContext } from '../../../Types/Context/TableContext.svelte.js';
10
+ import { TableFocusDetails } from '../../../Types/Focus/TableFocusDetails.svelte.js';
11
+ import { devCatch, isValidityTuple, loadingText } from '../../../../../Helpers/Helpers.svelte.js';
12
+ import type { SelectOption } from '../../../../../Types/Internal/SelectOption.js';
13
+ import { Validity } from '../../../../../Types/Internal/Validity.js';
14
+ import { getContext, tick, untrack } from 'svelte';
15
+ import type { TableQuerySelectProps } from './TableQuerySelectProps.js';
16
+
17
+ const { cell }: TableQuerySelectProps<T, unknown> = $props();
18
+
19
+ const value = $derived((cell.getValue() ?? null) as unknown);
20
+
21
+ const visibleValue = $derived(
22
+ cell.column.columnDef.getDisplayValue(cell.row.original, cell.row.originalIndex)
23
+ );
24
+
25
+ let tdref = $state<HTMLTableCellElement | undefined>();
26
+
27
+ const columnDef: QueryDef<T> = $derived(cell.column.columnDef) as unknown as QueryDef<T>; // TODO stabilise and remove `as unknown`
28
+ // const optional = $derived(columnDef.optional ?? false);
29
+
30
+ let lastOptions: Array<SelectOption<unknown>> = $state([]);
31
+
32
+ const tableContext = getContext<TableContext<T, never>>(TableContext.identifier);
33
+
34
+ const editable = $derived(
35
+ cell.column.columnDef.isEditable(cell.row.original, cell.row.originalIndex)
36
+ );
37
+
38
+ let valueAsyncCounter = 0;
39
+ $effect(() => {
40
+ void value;
41
+ void lastOptions;
42
+
43
+ untrack(() => {
44
+ const localCounter = (valueAsyncCounter = valueAsyncCounter + 1);
45
+ (async () => {
46
+ try {
47
+ const awaitedValue = await value;
48
+ const label = (await visibleValue) ?? awaitedValue?.toString();
49
+
50
+ if (awaitedValue != null && valueAsyncCounter === localCounter) {
51
+ if (label == null) {
52
+ throw new Error('invalid label and value');
53
+ }
54
+ if (!lastOptions.some((it) => it.value == awaitedValue)) {
55
+ lastOptions.push({
56
+ label,
57
+ value: awaitedValue,
58
+ });
59
+ }
60
+ } else if (columnDef.debug) {
61
+ console.debug(
62
+ `${cell.column.columnDef.id}: `,
63
+ 'skipping async option insertion because it is stale'
64
+ );
65
+ }
66
+ } catch (e) {
67
+ if (columnDef.debug) {
68
+ console.error(e);
69
+ }
70
+ if (valueAsyncCounter === localCounter) {
71
+ //nothing happens
72
+ } else if (columnDef.debug) {
73
+ console.debug(
74
+ `${cell.column.columnDef.id}: `,
75
+ 'skipping caught async option insertion error because it is stale'
76
+ );
77
+ }
78
+ }
79
+ })().catch(devCatch);
80
+ });
81
+ });
82
+
83
+ const focusDetails: TableFocusDetails<T, never> = $derived(
84
+ new TableFocusDetails(cell, tableContext)
85
+ );
86
+
87
+ const wantsToBeEdited = $derived(
88
+ tableContext.focusStart?.column === focusDetails.coordinates.column &&
89
+ tableContext.focusEnd?.column === focusDetails.coordinates.column &&
90
+ tableContext.focusStart.row === focusDetails.coordinates.row &&
91
+ tableContext.focusEnd.row === focusDetails.coordinates.row &&
92
+ !tableContext.isMousingDown &&
93
+ tableContext.focusStartIsBeingEdited
94
+ );
95
+
96
+ let isBeingEdited = $state(false);
97
+
98
+ function handleIsEditable(isEditable: boolean): Promise<void> {
99
+ if (isEditable) {
100
+ return tick().then(() => {
101
+ isBeingEdited = true;
102
+ });
103
+ } else {
104
+ if (isBeingEdited) {
105
+ return tick()
106
+ .then(() => {
107
+ if (!tableContext.singleClickEditing) {
108
+ tableContext.focusStartIsBeingEdited = false;
109
+ }
110
+
111
+ isBeingEdited = false;
112
+ })
113
+ .catch(devCatch);
114
+ }
115
+ }
116
+ return Promise.resolve();
117
+ }
118
+
119
+ $effect(() => {
120
+ void editable;
121
+ if (wantsToBeEdited) {
122
+ if (editable instanceof Promise) {
123
+ editable
124
+ .then((isEditable) => {
125
+ return handleIsEditable(isEditable);
126
+ })
127
+
128
+ .catch(devCatch);
129
+ } else {
130
+ handleIsEditable(editable).catch(devCatch);
131
+ }
132
+ } else {
133
+ tick()
134
+ .then(() => {
135
+ isBeingEdited = false;
136
+ tableContext.focusStartIsBeingEdited = false;
137
+ })
138
+ .catch(devCatch);
139
+ }
140
+ });
141
+
142
+ let validity: Validity = $state(Validity.Valid);
143
+ $effect(() => {
144
+ const validityPromise = focusDetails.validity;
145
+
146
+ validityPromise
147
+ .then((v) => {
148
+ if (!v) {
149
+ validity = Validity.Neutral;
150
+ } else if (isValidityTuple(v)) {
151
+ validity = v.value;
152
+ } else {
153
+ validity = v;
154
+ }
155
+ })
156
+ .catch(devCatch);
157
+ });
158
+
159
+ const handleTDFocus = async () => {
160
+ if (
161
+ (await editable) &&
162
+ tableContext.focusStart?.column === focusDetails.coordinates.column &&
163
+ tableContext.focusStart.row === focusDetails.coordinates.row
164
+ ) {
165
+ if (
166
+ tableContext.focusEnd?.column !== focusDetails.coordinates.column ||
167
+ tableContext.focusEnd.row !== focusDetails.coordinates.row
168
+ ) {
169
+ tableContext.setFocusEnd(focusDetails.coordinates);
170
+ }
171
+
172
+ tableContext.isMousingDown = false;
173
+ tableContext.focusStartIsBeingEdited = true;
174
+ return true;
175
+ }
176
+
177
+ return false;
178
+ };
179
+
180
+ async function handleSingleClick(): Promise<boolean> {
181
+ return tableContext.singleClickEditing && (await handleTDFocus());
182
+ }
183
+ async function handleDoubleClick(): Promise<boolean> {
184
+ return !tableContext.singleClickEditing && (await handleTDFocus());
185
+ }
186
+
187
+ function tryHandleTDFocus() {
188
+ handleTDFocus().catch(devCatch);
189
+ }
190
+
191
+ function handleUnfocus(e: KeyboardEvent) {
192
+ if (e.key === 'Escape') {
193
+ e.preventDefault();
194
+ e.stopPropagation();
195
+
196
+ tableContext.focusStartIsBeingEdited = false;
197
+ tick()
198
+ .then(() => {
199
+ tdref?.focus();
200
+ })
201
+ .catch(devCatch);
202
+
203
+ return true;
204
+ }
205
+
206
+ if (e.key === 'Tab') {
207
+ e.preventDefault();
208
+ return true;
209
+ }
210
+
211
+ return false;
212
+ }
213
+
214
+ function keydownForce(e: KeyboardEvent) {
215
+ const shouldStop = handleUnfocus(e);
216
+ if (!shouldStop && !(e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
217
+ tick()
218
+ .then(() => {
219
+ tdref?.dispatchEvent(
220
+ new KeyboardEvent('keydown', {
221
+ key: e.key,
222
+ altKey: e.getModifierState('Alt'),
223
+ metaKey: e.getModifierState('Meta'),
224
+ shiftKey: e.getModifierState('Shift'),
225
+ ctrlKey: e.getModifierState('Control'),
226
+ bubbles: true,
227
+ })
228
+ );
229
+ })
230
+ .catch(devCatch);
231
+ }
232
+ }
233
+
234
+ function addKeydownEvent(target: HTMLInputElement | undefined) {
235
+ target?.addEventListener('keydown', keydownForce);
236
+ }
237
+
238
+ let prevtdref: HTMLTableCellElement | undefined = undefined;
239
+ $effect(() => {
240
+ void tdref;
241
+ untrack(() => {
242
+ if (tdref && tdref != prevtdref) {
243
+ tdref.addEventListener('edit', tryHandleTDFocus);
244
+ } else {
245
+ prevtdref = tdref;
246
+ }
247
+ });
248
+ });
249
+ </script>
250
+
251
+ {#if isBeingEdited}
252
+ <!-- onkeydown={handleInputKeydown} -->
253
+ <!-- onkeydown={handleEsc} -->
254
+ <td
255
+ class="select-cell"
256
+ bind:this={tdref}
257
+ >
258
+ <!-- TODO: -->
259
+ {#await value then value}
260
+ <QuerySelect
261
+ focusOnLoad
262
+ name={cell.column.columnDef.id}
263
+ valueProp="value"
264
+ labelProp="label"
265
+ clearable={cell.column.columnDef.clearable}
266
+ valueAsObject={false}
267
+ {value}
268
+ query={(v: string) => columnDef.query(v, cell.row.original, cell.row.originalIndex)}
269
+ bind:options={lastOptions}
270
+ onfocus={addKeydownEvent}
271
+ onchange={(newValue: SelectOption<unknown> | null) => {
272
+ if (newValue?.value !== value) {
273
+ tableContext
274
+ .onEditCell(cell.row.original, focusDetails.coordinates, newValue?.value ?? null)
275
+ .catch(devCatch);
276
+ }
277
+
278
+ tableContext.focusStartIsBeingEdited = false;
279
+ tick()
280
+ .then(() => {
281
+ tdref?.focus();
282
+ })
283
+ .catch(devCatch);
284
+ }}
285
+ />
286
+ {/await}
287
+ </td>
288
+ {:else}
289
+ <!-- // onkeydown={handleTdKeydown} -->
290
+ <!-- svelte-ignore a11y_mouse_events_have_key_events -->
291
+ <td
292
+ style={focusDetails.outline}
293
+ bind:this={tdref}
294
+ tabIndex="0"
295
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
296
+ class="focusable editable"
297
+ class:multifocus={focusDetails.isMultiFocused}
298
+ class:multifocus-start={focusDetails.isMultiFocusStart}
299
+ class:info={validity == Validity.Info}
300
+ class:success={validity == Validity.Valid}
301
+ class:warning={validity == Validity.Warning}
302
+ class:error={validity == Validity.Invalid}
303
+ ondblclick={handleDoubleClick}
304
+ onmousedown={(e) => {
305
+ // start focus only on left click
306
+ if (e.button === 0) {
307
+ if (e.shiftKey) {
308
+ e.preventDefault();
309
+ tableContext.setFocusEnd(focusDetails.coordinates);
310
+ } else {
311
+ tableContext.startFocus(focusDetails.coordinates);
312
+ }
313
+ }
314
+ }}
315
+ onmouseover={() => {
316
+ if (tableContext.isMousingDown) {
317
+ tableContext.setFocusEnd(focusDetails.coordinates);
318
+ }
319
+ }}
320
+ onmouseup={() => {
321
+ handleSingleClick()
322
+ .then((wasHandled) => {
323
+ if (!wasHandled) {
324
+ tableContext.endFocus(focusDetails.coordinates);
325
+ }
326
+ })
327
+ .catch(devCatch);
328
+ }}
329
+ >
330
+ {#await visibleValue}
331
+ {loadingText}
332
+ {:then v}
333
+ {v}
334
+ {/await}
335
+ </td>
336
+ {/if}
337
+
338
338
  <style>td {
339
339
  transition: line-height 0.2s ease, height 0.2s ease;
340
340
  --input-border: none;
@@ -390,4 +390,4 @@ td :global(.select-wrapper) {
390
390
  --sv-general-padding: 0px;
391
391
  --sv-item-wrap-padding: 0px 0.75rem;
392
392
  --input-height: var(--height);
393
- }</style>
393
+ }</style>