@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,360 +1,360 @@
1
- <svelte:options runes />
2
-
3
- <script
4
- lang="ts"
5
- module
6
- >
7
- export interface TableNumberInputProps<T extends object> {
8
- cell: TableCell<T>;
9
- }
10
- </script>
11
-
12
- <script
13
- lang="ts"
14
- generics="T extends object"
15
- >
16
- import NumberInput from '../../../../NumberInput.svelte';
17
- import { NumberInputDef } from '../../../Types/Columns/Definitions/Accessors/NumberInputDef.svelte.js';
18
- import type { TableCell } from '../../../Types/Columns/TableCell.js';
19
- import { TableContext } from '../../../Types/Context/TableContext.svelte.js';
20
- import { TableFocusDetails } from '../../../Types/Focus/TableFocusDetails.svelte.js';
21
- import { devCatch, isValidityTuple, loadingText } from '../../../../../Helpers/Helpers.svelte.js';
22
- import { InputVariant } from '../../../../../Types/Internal/InputVariant.js';
23
- import { Validity } from '../../../../../Types/Internal/Validity.js';
24
- import { getContext, tick, untrack } from 'svelte';
25
-
26
- const { cell }: TableNumberInputProps<T> = $props();
27
-
28
- const value: Promise<number | string | null> | number | string | null = $derived.by(() => {
29
- const _value = cell.getValue();
30
-
31
- return typeof _value === 'string'
32
- ? parseInt(_value)
33
- : typeof _value === 'number'
34
- ? _value
35
- : ((_value as Promise<string | number | null | undefined> | null | undefined)?.then((v) => {
36
- return v === 'string' ? parseInt(v) : (v ?? null);
37
- }) ?? null);
38
- });
39
- let tempNumericValue: number = $state(0);
40
-
41
- const visibleValue = $derived(
42
- cell.column.columnDef.getDisplayValue?.(cell.row.original, cell.row.originalIndex) ?? value
43
- );
44
-
45
- $effect(() => {
46
- void value;
47
- untrack(() => {
48
- resetValue();
49
- });
50
- });
51
-
52
- function resetValue() {
53
- tempNumericValue = typeof value === 'string' ? parseInt(value) : (value as number);
54
- }
55
-
56
- let tdref: HTMLTableCellElement | undefined = $state();
57
- let inputRef: HTMLInputElement | undefined = $state();
58
-
59
- const tableContext = getContext<TableContext<T, never>>(TableContext.identifier);
60
-
61
- const editableAsync = $derived(
62
- cell.column.columnDef.isEditable(cell.row.original, cell.row.originalIndex)
63
- );
64
- let editable = $state(false);
65
- let asyncCounter = 0;
66
- $effect(() => {
67
- void editableAsync;
68
- const localCounter = (asyncCounter = asyncCounter + 1);
69
- (async () => {
70
- try {
71
- const isEditable = await editableAsync;
72
- if (asyncCounter === localCounter) {
73
- editable = isEditable;
74
- } else if (cell.column.columnDef.debug) {
75
- console.log('skipping async editable because it is stale');
76
- }
77
- } catch (e) {
78
- if (cell.column.columnDef.debug) {
79
- console.error(e);
80
- }
81
- if (asyncCounter === localCounter) {
82
- editable = false;
83
- } else if (cell.column.columnDef.debug) {
84
- console.log('skipping async editable because it is stale');
85
- }
86
- }
87
- })().catch(devCatch);
88
- });
89
-
90
- const focusDetails: TableFocusDetails<T, never> = $derived(
91
- new TableFocusDetails(cell, tableContext)
92
- );
93
-
94
- const wantsToBeEdited = $derived(
95
- tableContext.focusStart?.column === focusDetails.coordinates.column &&
96
- tableContext.focusEnd?.column === focusDetails.coordinates.column &&
97
- tableContext.focusStart.row === focusDetails.coordinates.row &&
98
- tableContext.focusEnd.row === focusDetails.coordinates.row &&
99
- !tableContext.isMousingDown &&
100
- tableContext.focusStartIsBeingEdited
101
- );
102
-
103
- let isBeingEdited = $state(false);
104
-
105
- $effect(() => {
106
- if (wantsToBeEdited) {
107
- if (editable) {
108
- tick()
109
- .then(() => {
110
- untrack(() => {
111
- isBeingEdited = true;
112
- });
113
- })
114
- .catch(devCatch);
115
- } else {
116
- tick()
117
- .then(() => {
118
- untrack(() => {
119
- tableContext.focusStartIsBeingEdited = false;
120
- });
121
- })
122
- .catch(devCatch);
123
- }
124
- } else {
125
- if (isBeingEdited) {
126
- untrack(() => {
127
- isBeingEdited = false;
128
- tick()
129
- .then(() => {
130
- onBlur();
131
- })
132
- .catch(devCatch);
133
- });
134
- }
135
- }
136
- });
137
-
138
- let overrideEdit = $state(false);
139
-
140
- $effect(() => {
141
- if (isBeingEdited) {
142
- if (overrideEdit) {
143
- overrideEdit = false;
144
- } else {
145
- handleBeingEdited();
146
- }
147
- }
148
- });
149
-
150
- let validity: Validity = $state(Validity.Valid);
151
- $effect(() => {
152
- const validityPromise = focusDetails.validity;
153
-
154
- validityPromise
155
- .then((v) => {
156
- if (!v) {
157
- validity = Validity.Neutral;
158
- } else if (isValidityTuple(v)) {
159
- validity = v.value;
160
- } else {
161
- validity = v;
162
- }
163
- })
164
- .catch(devCatch);
165
- });
166
-
167
- function handleBeingEdited() {
168
- tableContext.isMousingDown = false;
169
- tick()
170
- .then(() => {
171
- inputRef?.select();
172
- })
173
- .catch(devCatch);
174
- }
175
-
176
- function handleInputKeydown(e: KeyboardEvent) {
177
- switch (e.key) {
178
- case 'Escape':
179
- e.preventDefault();
180
- e.stopPropagation();
181
-
182
- resetValue();
183
- tableContext.focusStartIsBeingEdited = false;
184
- tick()
185
- .then(() => {
186
- tdref?.focus();
187
- })
188
- .catch(devCatch);
189
- break;
190
- case 'Enter':
191
- e.preventDefault();
192
- e.stopPropagation();
193
-
194
- // shouldFocusTDOnBlur.current = true;
195
- tableContext.focusStartIsBeingEdited = false;
196
- (e.target as HTMLInputElement).blur();
197
- tick()
198
- .then(() => {
199
- tdref?.focus();
200
- })
201
- .catch(devCatch);
202
- break;
203
- default: {
204
- //ignore other keys
205
- break;
206
- }
207
- }
208
- }
209
-
210
- function onBlur(): void {
211
- const oldValue = typeof value === 'string' ? parseInt(value) : value;
212
-
213
- if (oldValue != tempNumericValue) {
214
- tableContext
215
- .onEditCell(cell.row.original, focusDetails.coordinates, tempNumericValue)
216
- .catch(devCatch);
217
- }
218
-
219
- if (!tableContext.singleClickEditing) {
220
- tableContext.focusStartIsBeingEdited = false;
221
- }
222
- }
223
-
224
- const onEdit = (e: CustomEvent<{ selectAll: boolean }>) => {
225
- handleTDFocus(e.detail.selectAll);
226
- };
227
-
228
- function onInputFocus(e: FocusEvent) {
229
- (e.target as HTMLInputElement).scrollIntoView({
230
- behavior: 'instant',
231
- block: 'nearest',
232
- inline: 'nearest',
233
- });
234
- }
235
-
236
- function handleTDFocus(selectAll: boolean = false): boolean {
237
- if (
238
- tableContext.focusStart?.column === focusDetails.coordinates.column &&
239
- tableContext.focusStart.row === focusDetails.coordinates.row &&
240
- editable
241
- ) {
242
- if (
243
- tableContext.focusEnd?.column !== focusDetails.coordinates.column ||
244
- tableContext.focusEnd.row !== focusDetails.coordinates.row
245
- ) {
246
- tableContext.setFocusEnd(focusDetails.coordinates);
247
- }
248
-
249
- resetValue();
250
- tableContext.isMousingDown = false;
251
-
252
- if (!selectAll) {
253
- overrideEdit = true;
254
-
255
- tableContext.isMousingDown = false;
256
- tick()
257
- .then(() => {
258
- inputRef?.focus();
259
- })
260
- .catch(devCatch);
261
- }
262
-
263
- tableContext.focusStartIsBeingEdited = true;
264
-
265
- return true;
266
- }
267
-
268
- return false;
269
- }
270
-
271
- function handleSingleClickFocus(): boolean {
272
- return tableContext.singleClickEditing && handleTDFocus();
273
- }
274
-
275
- function handleDoubleClickFocus() {
276
- return !tableContext.singleClickEditing && handleTDFocus();
277
- }
278
-
279
- let prevTdRef: HTMLTableCellElement | undefined;
280
-
281
- $effect(() => {
282
- let unsubscriber = () => {};
283
-
284
- if (tdref != prevTdRef) {
285
- prevTdRef = tdref;
286
- prevTdRef?.addEventListener('edit', onEdit);
287
- unsubscriber = () => {
288
- prevTdRef?.removeEventListener('edit', onEdit);
289
- };
290
- }
291
-
292
- return unsubscriber;
293
- });
294
- </script>
295
-
296
- {#if isBeingEdited}
297
- <!-- {#if true} -->
298
-
299
- <td class="input-cell">
300
- <NumberInput
301
- id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
302
- min={(cell.column.columnDef as NumberInputDef<T>).min}
303
- max={(cell.column.columnDef as NumberInputDef<T>).max}
304
- variant={InputVariant.Table}
305
- onkeydown={handleInputKeydown}
306
- bind:value={tempNumericValue}
307
- onfocus={onInputFocus}
308
- bind:inputRef
309
- />
310
- <!-- HACK this onBlur is now being called by an effect because otherwise it fires twice -->
311
- <!-- onblur={onBlur} -->
312
- </td>
313
- {:else}
314
- <!-- svelte-ignore a11y_mouse_events_have_key_events -->
315
-
316
- <td
317
- style={focusDetails.outline}
318
- id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
319
- onmousedown={(e) => {
320
- // start focus only on left click
321
- if (e.button === 0) {
322
- if (e.shiftKey) {
323
- e.preventDefault();
324
- tableContext.setFocusEnd(focusDetails.coordinates);
325
- } else {
326
- tableContext.startFocus(focusDetails.coordinates);
327
- }
328
- }
329
- }}
330
- onmouseover={() => {
331
- if (tableContext.isMousingDown) {
332
- tableContext.setFocusEnd(focusDetails.coordinates);
333
- }
334
- }}
335
- onmouseup={() => {
336
- const wasHandled = handleSingleClickFocus();
337
- if (!wasHandled) {
338
- tableContext.endFocus(focusDetails.coordinates);
339
- }
340
- }}
341
- bind:this={tdref}
342
- tabIndex="0"
343
- class:editable
344
- class="focusable"
345
- class:multifocus={focusDetails.isMultiFocused}
346
- class:multifocus-start={focusDetails.isMultiFocusStart}
347
- class:info={validity == Validity.Info}
348
- class:success={validity == Validity.Valid}
349
- class:warning={validity == Validity.Warning}
350
- class:error={validity == Validity.Invalid}
351
- ondblclick={handleDoubleClickFocus}
352
- >{#await visibleValue}
353
- {loadingText}
354
- {:then value}{value ?? '-'}{/await}</td
355
- >
356
- {/if}
357
-
1
+ <svelte:options runes />
2
+
3
+ <script
4
+ lang="ts"
5
+ module
6
+ >
7
+ export interface TableNumberInputProps<T extends object> {
8
+ cell: TableCell<T>;
9
+ }
10
+ </script>
11
+
12
+ <script
13
+ lang="ts"
14
+ generics="T extends object"
15
+ >
16
+ import NumberInput from '../../../../NumberInput.svelte';
17
+ import { NumberInputDef } from '../../../Types/Columns/Definitions/Accessors/NumberInputDef.svelte.js';
18
+ import type { TableCell } from '../../../Types/Columns/TableCell.js';
19
+ import { TableContext } from '../../../Types/Context/TableContext.svelte.js';
20
+ import { TableFocusDetails } from '../../../Types/Focus/TableFocusDetails.svelte.js';
21
+ import { devCatch, isValidityTuple, loadingText } from '../../../../../Helpers/Helpers.svelte.js';
22
+ import { InputVariant } from '../../../../../Types/Internal/InputVariant.js';
23
+ import { Validity } from '../../../../../Types/Internal/Validity.js';
24
+ import { getContext, tick, untrack } from 'svelte';
25
+
26
+ const { cell }: TableNumberInputProps<T> = $props();
27
+
28
+ const value: Promise<number | string | null> | number | string | null = $derived.by(() => {
29
+ const _value = cell.getValue();
30
+
31
+ return typeof _value === 'string'
32
+ ? parseInt(_value)
33
+ : typeof _value === 'number'
34
+ ? _value
35
+ : ((_value as Promise<string | number | null | undefined> | null | undefined)?.then((v) => {
36
+ return v === 'string' ? parseInt(v) : (v ?? null);
37
+ }) ?? null);
38
+ });
39
+ let tempNumericValue: number = $state(0);
40
+
41
+ const visibleValue = $derived(
42
+ cell.column.columnDef.getDisplayValue?.(cell.row.original, cell.row.originalIndex) ?? value
43
+ );
44
+
45
+ $effect(() => {
46
+ void value;
47
+ untrack(() => {
48
+ resetValue();
49
+ });
50
+ });
51
+
52
+ function resetValue() {
53
+ tempNumericValue = typeof value === 'string' ? parseInt(value) : (value as number);
54
+ }
55
+
56
+ let tdref: HTMLTableCellElement | undefined = $state();
57
+ let inputRef: HTMLInputElement | undefined = $state();
58
+
59
+ const tableContext = getContext<TableContext<T, never>>(TableContext.identifier);
60
+
61
+ const editableAsync = $derived(
62
+ cell.column.columnDef.isEditable(cell.row.original, cell.row.originalIndex)
63
+ );
64
+ let editable = $state(false);
65
+ let asyncCounter = 0;
66
+ $effect(() => {
67
+ void editableAsync;
68
+ const localCounter = (asyncCounter = asyncCounter + 1);
69
+ (async () => {
70
+ try {
71
+ const isEditable = await editableAsync;
72
+ if (asyncCounter === localCounter) {
73
+ editable = isEditable;
74
+ } else if (cell.column.columnDef.debug) {
75
+ console.log('skipping async editable because it is stale');
76
+ }
77
+ } catch (e) {
78
+ if (cell.column.columnDef.debug) {
79
+ console.error(e);
80
+ }
81
+ if (asyncCounter === localCounter) {
82
+ editable = false;
83
+ } else if (cell.column.columnDef.debug) {
84
+ console.log('skipping async editable because it is stale');
85
+ }
86
+ }
87
+ })().catch(devCatch);
88
+ });
89
+
90
+ const focusDetails: TableFocusDetails<T, never> = $derived(
91
+ new TableFocusDetails(cell, tableContext)
92
+ );
93
+
94
+ const wantsToBeEdited = $derived(
95
+ tableContext.focusStart?.column === focusDetails.coordinates.column &&
96
+ tableContext.focusEnd?.column === focusDetails.coordinates.column &&
97
+ tableContext.focusStart.row === focusDetails.coordinates.row &&
98
+ tableContext.focusEnd.row === focusDetails.coordinates.row &&
99
+ !tableContext.isMousingDown &&
100
+ tableContext.focusStartIsBeingEdited
101
+ );
102
+
103
+ let isBeingEdited = $state(false);
104
+
105
+ $effect(() => {
106
+ if (wantsToBeEdited) {
107
+ if (editable) {
108
+ tick()
109
+ .then(() => {
110
+ untrack(() => {
111
+ isBeingEdited = true;
112
+ });
113
+ })
114
+ .catch(devCatch);
115
+ } else {
116
+ tick()
117
+ .then(() => {
118
+ untrack(() => {
119
+ tableContext.focusStartIsBeingEdited = false;
120
+ });
121
+ })
122
+ .catch(devCatch);
123
+ }
124
+ } else {
125
+ if (isBeingEdited) {
126
+ untrack(() => {
127
+ isBeingEdited = false;
128
+ tick()
129
+ .then(() => {
130
+ onBlur();
131
+ })
132
+ .catch(devCatch);
133
+ });
134
+ }
135
+ }
136
+ });
137
+
138
+ let overrideEdit = $state(false);
139
+
140
+ $effect(() => {
141
+ if (isBeingEdited) {
142
+ if (overrideEdit) {
143
+ overrideEdit = false;
144
+ } else {
145
+ handleBeingEdited();
146
+ }
147
+ }
148
+ });
149
+
150
+ let validity: Validity = $state(Validity.Valid);
151
+ $effect(() => {
152
+ const validityPromise = focusDetails.validity;
153
+
154
+ validityPromise
155
+ .then((v) => {
156
+ if (!v) {
157
+ validity = Validity.Neutral;
158
+ } else if (isValidityTuple(v)) {
159
+ validity = v.value;
160
+ } else {
161
+ validity = v;
162
+ }
163
+ })
164
+ .catch(devCatch);
165
+ });
166
+
167
+ function handleBeingEdited() {
168
+ tableContext.isMousingDown = false;
169
+ tick()
170
+ .then(() => {
171
+ inputRef?.select();
172
+ })
173
+ .catch(devCatch);
174
+ }
175
+
176
+ function handleInputKeydown(e: KeyboardEvent) {
177
+ switch (e.key) {
178
+ case 'Escape':
179
+ e.preventDefault();
180
+ e.stopPropagation();
181
+
182
+ resetValue();
183
+ tableContext.focusStartIsBeingEdited = false;
184
+ tick()
185
+ .then(() => {
186
+ tdref?.focus();
187
+ })
188
+ .catch(devCatch);
189
+ break;
190
+ case 'Enter':
191
+ e.preventDefault();
192
+ e.stopPropagation();
193
+
194
+ // shouldFocusTDOnBlur.current = true;
195
+ tableContext.focusStartIsBeingEdited = false;
196
+ (e.target as HTMLInputElement).blur();
197
+ tick()
198
+ .then(() => {
199
+ tdref?.focus();
200
+ })
201
+ .catch(devCatch);
202
+ break;
203
+ default: {
204
+ //ignore other keys
205
+ break;
206
+ }
207
+ }
208
+ }
209
+
210
+ function onBlur(): void {
211
+ const oldValue = typeof value === 'string' ? parseInt(value) : value;
212
+
213
+ if (oldValue != tempNumericValue) {
214
+ tableContext
215
+ .onEditCell(cell.row.original, focusDetails.coordinates, tempNumericValue)
216
+ .catch(devCatch);
217
+ }
218
+
219
+ if (!tableContext.singleClickEditing) {
220
+ tableContext.focusStartIsBeingEdited = false;
221
+ }
222
+ }
223
+
224
+ const onEdit = (e: CustomEvent<{ selectAll: boolean }>) => {
225
+ handleTDFocus(e.detail.selectAll);
226
+ };
227
+
228
+ function onInputFocus(e: FocusEvent) {
229
+ (e.target as HTMLInputElement).scrollIntoView({
230
+ behavior: 'instant',
231
+ block: 'nearest',
232
+ inline: 'nearest',
233
+ });
234
+ }
235
+
236
+ function handleTDFocus(selectAll: boolean = false): boolean {
237
+ if (
238
+ tableContext.focusStart?.column === focusDetails.coordinates.column &&
239
+ tableContext.focusStart.row === focusDetails.coordinates.row &&
240
+ editable
241
+ ) {
242
+ if (
243
+ tableContext.focusEnd?.column !== focusDetails.coordinates.column ||
244
+ tableContext.focusEnd.row !== focusDetails.coordinates.row
245
+ ) {
246
+ tableContext.setFocusEnd(focusDetails.coordinates);
247
+ }
248
+
249
+ resetValue();
250
+ tableContext.isMousingDown = false;
251
+
252
+ if (!selectAll) {
253
+ overrideEdit = true;
254
+
255
+ tableContext.isMousingDown = false;
256
+ tick()
257
+ .then(() => {
258
+ inputRef?.focus();
259
+ })
260
+ .catch(devCatch);
261
+ }
262
+
263
+ tableContext.focusStartIsBeingEdited = true;
264
+
265
+ return true;
266
+ }
267
+
268
+ return false;
269
+ }
270
+
271
+ function handleSingleClickFocus(): boolean {
272
+ return tableContext.singleClickEditing && handleTDFocus();
273
+ }
274
+
275
+ function handleDoubleClickFocus() {
276
+ return !tableContext.singleClickEditing && handleTDFocus();
277
+ }
278
+
279
+ let prevTdRef: HTMLTableCellElement | undefined;
280
+
281
+ $effect(() => {
282
+ let unsubscriber = () => {};
283
+
284
+ if (tdref != prevTdRef) {
285
+ prevTdRef = tdref;
286
+ prevTdRef?.addEventListener('edit', onEdit);
287
+ unsubscriber = () => {
288
+ prevTdRef?.removeEventListener('edit', onEdit);
289
+ };
290
+ }
291
+
292
+ return unsubscriber;
293
+ });
294
+ </script>
295
+
296
+ {#if isBeingEdited}
297
+ <!-- {#if true} -->
298
+
299
+ <td class="input-cell">
300
+ <NumberInput
301
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
302
+ min={(cell.column.columnDef as NumberInputDef<T>).min}
303
+ max={(cell.column.columnDef as NumberInputDef<T>).max}
304
+ variant={InputVariant.Table}
305
+ onkeydown={handleInputKeydown}
306
+ bind:value={tempNumericValue}
307
+ onfocus={onInputFocus}
308
+ bind:inputRef
309
+ />
310
+ <!-- HACK this onBlur is now being called by an effect because otherwise it fires twice -->
311
+ <!-- onblur={onBlur} -->
312
+ </td>
313
+ {:else}
314
+ <!-- svelte-ignore a11y_mouse_events_have_key_events -->
315
+
316
+ <td
317
+ style={focusDetails.outline}
318
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
319
+ onmousedown={(e) => {
320
+ // start focus only on left click
321
+ if (e.button === 0) {
322
+ if (e.shiftKey) {
323
+ e.preventDefault();
324
+ tableContext.setFocusEnd(focusDetails.coordinates);
325
+ } else {
326
+ tableContext.startFocus(focusDetails.coordinates);
327
+ }
328
+ }
329
+ }}
330
+ onmouseover={() => {
331
+ if (tableContext.isMousingDown) {
332
+ tableContext.setFocusEnd(focusDetails.coordinates);
333
+ }
334
+ }}
335
+ onmouseup={() => {
336
+ const wasHandled = handleSingleClickFocus();
337
+ if (!wasHandled) {
338
+ tableContext.endFocus(focusDetails.coordinates);
339
+ }
340
+ }}
341
+ bind:this={tdref}
342
+ tabIndex="0"
343
+ class:editable
344
+ class="focusable"
345
+ class:multifocus={focusDetails.isMultiFocused}
346
+ class:multifocus-start={focusDetails.isMultiFocusStart}
347
+ class:info={validity == Validity.Info}
348
+ class:success={validity == Validity.Valid}
349
+ class:warning={validity == Validity.Warning}
350
+ class:error={validity == Validity.Invalid}
351
+ ondblclick={handleDoubleClickFocus}
352
+ >{#await visibleValue}
353
+ {loadingText}
354
+ {:then value}{value ?? '-'}{/await}</td
355
+ >
356
+ {/if}
357
+
358
358
  <style>td {
359
359
  transition: line-height 0.2s ease, height 0.2s ease;
360
360
  --input-border: none;
@@ -399,4 +399,4 @@ td.input-cell {
399
399
  padding: unset;
400
400
  box-sizing: border-box;
401
401
  vertical-align: middle;
402
- }</style>
402
+ }</style>