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