@lavalogic/scoria 0.34.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 (125) hide show
  1. package/README.md +58 -58
  2. package/dist/Components/AccordionGroup.svelte +42 -42
  3. package/dist/Components/AccordionGroupButton.svelte +99 -99
  4. package/dist/Components/Action.svelte +138 -138
  5. package/dist/Components/AlertModal.svelte +125 -125
  6. package/dist/Components/Base/ContextWrapper.svelte +50 -50
  7. package/dist/Components/Base/Pagination.svelte +190 -190
  8. package/dist/Components/Base/Snippets.svelte +29 -29
  9. package/dist/Components/BigRadioSet.svelte +29 -29
  10. package/dist/Components/Bubble.svelte +77 -77
  11. package/dist/Components/Button.svelte +197 -197
  12. package/dist/Components/Checkbox.svelte +68 -68
  13. package/dist/Components/CollapsibleCard.svelte +70 -70
  14. package/dist/Components/Contexts/ContextMenu.svelte +157 -157
  15. package/dist/Components/Contexts/ContextMenuDivider.svelte +11 -11
  16. package/dist/Components/Contexts/ContextMenuOption.svelte +52 -52
  17. package/dist/Components/Contexts/Toast.svelte +61 -61
  18. package/dist/Components/Contexts/ToastContainer.svelte +46 -46
  19. package/dist/Components/Contexts/Tooltip.svelte +26 -26
  20. package/dist/Components/DataMatrixIcon.svelte +41 -41
  21. package/dist/Components/DateInput.svelte +109 -109
  22. package/dist/Components/DatePicker.svelte +312 -312
  23. package/dist/Components/DesktopModal.svelte +106 -106
  24. package/dist/Components/Dial.svelte +151 -151
  25. package/dist/Components/DimensionInput.svelte +184 -184
  26. package/dist/Components/DragMenu/DragMenuHolder.svelte +106 -106
  27. package/dist/Components/DragMenu/DraggableCard.svelte +41 -41
  28. package/dist/Components/FileCard.svelte +20 -20
  29. package/dist/Components/FileUpload.svelte +196 -196
  30. package/dist/Components/GridInput.svelte +190 -190
  31. package/dist/Components/GridInputSet.svelte +22 -22
  32. package/dist/Components/HorizontalTabGroup.svelte +78 -78
  33. package/dist/Components/HorizontalTabGroupButton.svelte +96 -96
  34. package/dist/Components/Icon.svelte +97 -97
  35. package/dist/Components/Icons.js +357 -357
  36. package/dist/Components/LoadingAnimation.svelte +32 -32
  37. package/dist/Components/LoadingModal.svelte +47 -47
  38. package/dist/Components/LoadingOverlay.svelte +27 -27
  39. package/dist/Components/Modal.svelte +251 -251
  40. package/dist/Components/MultiSelect.svelte +197 -197
  41. package/dist/Components/Nav/Nav.svelte +97 -97
  42. package/dist/Components/Nav/NavServiceMenuList.svelte +34 -34
  43. package/dist/Components/Nav/NavTab.svelte +91 -91
  44. package/dist/Components/Nav/ServiceMenuItem.svelte +91 -91
  45. package/dist/Components/Nav/ServicesNav.svelte +53 -53
  46. package/dist/Components/NumberInput.svelte +144 -144
  47. package/dist/Components/PageHeading.svelte +36 -36
  48. package/dist/Components/PasswordInput.svelte +73 -73
  49. package/dist/Components/Portal.svelte +25 -25
  50. package/dist/Components/ProgressBubble.svelte +80 -80
  51. package/dist/Components/QuerySelect.svelte +411 -411
  52. package/dist/Components/SingleSelect.svelte +261 -261
  53. package/dist/Components/StepButton.svelte +120 -120
  54. package/dist/Components/StepForm.svelte +108 -108
  55. package/dist/Components/Switch.svelte +36 -36
  56. package/dist/Components/Table/Body/QuickSearchCell.svelte +632 -632
  57. package/dist/Components/Table/Body/Rows/ColumnHighlight.svelte +30 -30
  58. package/dist/Components/Table/Body/Rows/ColumnList.svelte +56 -56
  59. package/dist/Components/Table/Body/Rows/ColumnListRow.svelte +179 -179
  60. package/dist/Components/Table/Body/Rows/Columns/AccessorComponent.svelte +49 -49
  61. package/dist/Components/Table/Body/Rows/Columns/ActionsCell.svelte +180 -180
  62. package/dist/Components/Table/Body/Rows/Columns/BubbleCell.svelte +102 -102
  63. package/dist/Components/Table/Body/Rows/Columns/ExpandCell.svelte +119 -119
  64. package/dist/Components/Table/Body/Rows/Columns/FocusableImmutableCell.svelte +114 -114
  65. package/dist/Components/Table/Body/Rows/Columns/ProgressCell.svelte +96 -96
  66. package/dist/Components/Table/Body/Rows/Columns/TableAction.svelte +72 -72
  67. package/dist/Components/Table/Body/Rows/Columns/TableCheckbox.svelte +131 -131
  68. package/dist/Components/Table/Body/Rows/Columns/TableColumn.svelte +144 -144
  69. package/dist/Components/Table/Body/Rows/Columns/TableDatePicker.svelte +238 -238
  70. package/dist/Components/Table/Body/Rows/Columns/TableNumberInput.svelte +358 -358
  71. package/dist/Components/Table/Body/Rows/Columns/TableQuerySelect.svelte +338 -338
  72. package/dist/Components/Table/Body/Rows/Columns/TableRowSelectionCheckbox.svelte +183 -183
  73. package/dist/Components/Table/Body/Rows/Columns/TableSelect.svelte +309 -309
  74. package/dist/Components/Table/Body/Rows/Columns/TableTextInput.svelte +369 -369
  75. package/dist/Components/Table/Body/Rows/Columns/ValidityCell.svelte +170 -170
  76. package/dist/Components/Table/Body/Rows/TableRow.svelte +259 -259
  77. package/dist/Components/Table/Body/TableBody.svelte +67 -67
  78. package/dist/Components/Table/Headers/HighlightAllHeader.svelte +39 -39
  79. package/dist/Components/Table/Headers/SelectAllHeader.svelte +28 -28
  80. package/dist/Components/Table/Headers/TableHead.svelte +260 -260
  81. package/dist/Components/Table/Misc/ColumnPanel.svelte +78 -78
  82. package/dist/Components/Table/Misc/ColumnPanelModal.svelte +99 -99
  83. package/dist/Components/Table/Misc/FilterInput.svelte +556 -556
  84. package/dist/Components/Table/Misc/FilterPanel.svelte +46 -46
  85. package/dist/Components/Table/Misc/FilterPanelModal.svelte +67 -67
  86. package/dist/Components/Table/Misc/SidePanel.svelte +32 -32
  87. package/dist/Components/Table/Misc/TableFooter.svelte +304 -304
  88. package/dist/Components/Table/Misc/TableHorizontalBar.svelte +156 -156
  89. package/dist/Components/Table/Misc/TableSidebar.svelte +176 -176
  90. package/dist/Components/Table/Misc/ToolboxPanel.svelte +77 -77
  91. package/dist/Components/Table/Misc/ToolboxPanelModal.svelte +91 -91
  92. package/dist/Components/Table/NestedTable.svelte +84 -84
  93. package/dist/Components/Table/Table.svelte +492 -492
  94. package/dist/Components/Test/TestContextConsumer.svelte +13 -13
  95. package/dist/Components/TextArea.svelte +108 -108
  96. package/dist/Components/TextInput.svelte +147 -147
  97. package/dist/Components/ThreeStateRadio.svelte +124 -124
  98. package/dist/Components/Touch/BoolCard.svelte +52 -52
  99. package/dist/Components/Touch/DateModal.svelte +217 -217
  100. package/dist/Components/Touch/EditCard.svelte +52 -52
  101. package/dist/Components/Touch/InfoCard.svelte +24 -24
  102. package/dist/Components/Touch/InfoTextCard.svelte +21 -21
  103. package/dist/Components/Touch/ModalExplanation.svelte +20 -20
  104. package/dist/Components/Touch/NumberKeyboard.svelte +268 -268
  105. package/dist/Components/Touch/NumberModal.svelte +69 -69
  106. package/dist/Components/Touch/PlusMinusCard.svelte +50 -50
  107. package/dist/Components/Touch/SelectModal.svelte +105 -105
  108. package/dist/Components/Touch/SummaryCard.svelte +65 -65
  109. package/dist/Components/Touch/TextAreaModal.svelte +86 -86
  110. package/dist/Components/Touch/TextModal.svelte +123 -123
  111. package/dist/Components/Touch/TouchCard.svelte +28 -28
  112. package/dist/Components/Touch/TouchModal.svelte +259 -259
  113. package/dist/Components/Touch/UtilityButton.svelte +91 -91
  114. package/dist/Components/VerticalTabGroup.svelte +66 -66
  115. package/dist/Components/VerticalTabGroupButton.svelte +97 -97
  116. package/dist/Helpers/Datamatrix.d.ts +10 -10
  117. package/dist/Helpers/Datamatrix.js +1 -1
  118. package/dist/Helpers/Helpers.svelte.js +6 -4
  119. package/dist/Types/Examples/ExampleModal.svelte +34 -34
  120. package/dist/scss/_basics.scss +12 -12
  121. package/dist/scss/_colours.scss +134 -134
  122. package/dist/scss/_mixins.scss +3016 -3016
  123. package/dist/scss/_sizing.scss +69 -69
  124. package/dist/scss/_transitions.scss +8 -8
  125. package/package.json +2 -2
@@ -1,98 +1,98 @@
1
- <svelte:options runes />
2
-
3
- <script
4
- lang="ts"
5
- module
6
- >
7
- import ProgressBubble from '../../../../ProgressBubble.svelte';
8
- import type { ProgressBarTableCell } from '../../../Types/Columns/ProgressBarTableCell.js';
9
- import { TableContext } from '../../../Types/Context/TableContext.svelte.js';
10
- import { TableFocusDetails } from '../../../Types/Focus/TableFocusDetails.svelte.js';
11
- import { devCatch, isValidityTuple } from '../../../../../Helpers/Helpers.svelte.js';
12
- import { Validity } from '../../../../../Types/Internal/Validity.js';
13
- import { getContext } from 'svelte';
14
-
15
- export interface ProgressCellProps<T extends object, FilterValueType> {
16
- cell: ProgressBarTableCell<T, FilterValueType>;
17
- }
18
- </script>
19
-
20
- <!-- TODO editable version of this should contain a multi select -->
21
- <script
22
- lang="ts"
23
- generics="T extends object, FilterValueType"
24
- >
25
- const { cell }: ProgressCellProps<T, FilterValueType> = $props();
26
-
27
- const value: [number, number] = $derived(cell.getValue()) as [number, number];
28
-
29
- const tableContext = getContext<TableContext<T, never>>(TableContext.identifier);
30
- // const previousRowIndex: number | undefined = $state(undefined);
31
-
32
- const focusDetails = $derived(new TableFocusDetails<T, never>(cell, tableContext));
33
-
34
- let validity: Validity = $state(Validity.Valid);
35
- $effect(() => {
36
- const validityPromise = focusDetails.validity;
37
-
38
- validityPromise
39
- .then((v) => {
40
- if (!v) {
41
- validity = Validity.Neutral;
42
- } else if (isValidityTuple(v)) {
43
- validity = v.value;
44
- } else {
45
- validity = v;
46
- }
47
- })
48
- .catch(devCatch);
49
- });
50
-
51
- const colours = $derived(
52
- cell.column.columnDef.getColour(cell.row.original, cell.row.originalIndex, value)
53
- );
54
- </script>
55
-
56
- <!-- svelte-ignore a11y_mouse_events_have_key_events -->
57
- <td
58
- id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
59
- tabIndex={0}
60
- class="focusable"
61
- class:multifocus={focusDetails.isMultiFocused}
62
- class:multifocus-start={focusDetails.isMultiFocusStart}
63
- style={focusDetails.outline}
64
- class:info={validity == Validity.Info}
65
- class:success={validity == Validity.Valid}
66
- class:warning={validity == Validity.Warning}
67
- class:error={validity == Validity.Invalid}
68
- onmousedown={(e) => {
69
- // start focus only on left click
70
- if (e.button === 0) {
71
- if (e.shiftKey) {
72
- e.preventDefault();
73
- tableContext.setFocusEnd(focusDetails.coordinates);
74
- } else {
75
- tableContext.startFocus(focusDetails.coordinates);
76
- }
77
- }
78
- }}
79
- onmouseover={() => {
80
- if (tableContext.isMousingDown) {
81
- tableContext.setFocusEnd(focusDetails.coordinates);
82
- }
83
- }}
84
- onmouseup={() => {
85
- tableContext.endFocus(focusDetails.coordinates);
86
- }}
87
- >
88
- <div class="bubble-parent">
89
- <ProgressBubble
90
- {value}
91
- {colours}
92
- />
93
- </div>
94
- </td>
95
-
1
+ <svelte:options runes />
2
+
3
+ <script
4
+ lang="ts"
5
+ module
6
+ >
7
+ import ProgressBubble from '../../../../ProgressBubble.svelte';
8
+ import type { ProgressBarTableCell } from '../../../Types/Columns/ProgressBarTableCell.js';
9
+ import { TableContext } from '../../../Types/Context/TableContext.svelte.js';
10
+ import { TableFocusDetails } from '../../../Types/Focus/TableFocusDetails.svelte.js';
11
+ import { devCatch, isValidityTuple } from '../../../../../Helpers/Helpers.svelte.js';
12
+ import { Validity } from '../../../../../Types/Internal/Validity.js';
13
+ import { getContext } from 'svelte';
14
+
15
+ export interface ProgressCellProps<T extends object, FilterValueType> {
16
+ cell: ProgressBarTableCell<T, FilterValueType>;
17
+ }
18
+ </script>
19
+
20
+ <!-- TODO editable version of this should contain a multi select -->
21
+ <script
22
+ lang="ts"
23
+ generics="T extends object, FilterValueType"
24
+ >
25
+ const { cell }: ProgressCellProps<T, FilterValueType> = $props();
26
+
27
+ const value: [number, number] = $derived(cell.getValue()) as [number, number];
28
+
29
+ const tableContext = getContext<TableContext<T, never>>(TableContext.identifier);
30
+ // const previousRowIndex: number | undefined = $state(undefined);
31
+
32
+ const focusDetails = $derived(new TableFocusDetails<T, never>(cell, tableContext));
33
+
34
+ let validity: Validity = $state(Validity.Valid);
35
+ $effect(() => {
36
+ const validityPromise = focusDetails.validity;
37
+
38
+ validityPromise
39
+ .then((v) => {
40
+ if (!v) {
41
+ validity = Validity.Neutral;
42
+ } else if (isValidityTuple(v)) {
43
+ validity = v.value;
44
+ } else {
45
+ validity = v;
46
+ }
47
+ })
48
+ .catch(devCatch);
49
+ });
50
+
51
+ const colours = $derived(
52
+ cell.column.columnDef.getColour(cell.row.original, cell.row.originalIndex, value)
53
+ );
54
+ </script>
55
+
56
+ <!-- svelte-ignore a11y_mouse_events_have_key_events -->
57
+ <td
58
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
59
+ tabIndex={0}
60
+ class="focusable"
61
+ class:multifocus={focusDetails.isMultiFocused}
62
+ class:multifocus-start={focusDetails.isMultiFocusStart}
63
+ style={focusDetails.outline}
64
+ class:info={validity == Validity.Info}
65
+ class:success={validity == Validity.Valid}
66
+ class:warning={validity == Validity.Warning}
67
+ class:error={validity == Validity.Invalid}
68
+ onmousedown={(e) => {
69
+ // start focus only on left click
70
+ if (e.button === 0) {
71
+ if (e.shiftKey) {
72
+ e.preventDefault();
73
+ tableContext.setFocusEnd(focusDetails.coordinates);
74
+ } else {
75
+ tableContext.startFocus(focusDetails.coordinates);
76
+ }
77
+ }
78
+ }}
79
+ onmouseover={() => {
80
+ if (tableContext.isMousingDown) {
81
+ tableContext.setFocusEnd(focusDetails.coordinates);
82
+ }
83
+ }}
84
+ onmouseup={() => {
85
+ tableContext.endFocus(focusDetails.coordinates);
86
+ }}
87
+ >
88
+ <div class="bubble-parent">
89
+ <ProgressBubble
90
+ {value}
91
+ {colours}
92
+ />
93
+ </div>
94
+ </td>
95
+
96
96
  <style>td {
97
97
  transition: line-height 0.2s ease, height 0.2s ease;
98
98
  --input-border: none;
@@ -153,4 +153,4 @@ div.bubble-parent {
153
153
  align-items: center;
154
154
  gap: 0.75rem;
155
155
  --line-height: 1;
156
- }</style>
156
+ }</style>
@@ -1,72 +1,72 @@
1
- <svelte:options runes />
2
-
3
- <script
4
- lang="ts"
5
- module
6
- >
7
- import Button from '../../../../Button.svelte';
8
- import type { TableActionButton } from '../../../Types/Columns/TableActionButton.js';
9
- import { getErrorMessage } from '../../../../../Helpers/Helpers.svelte.js';
10
- import { ColourSet } from '../../../../../scss/colours.js';
11
- import { Size } from '../../../../../Types/Internal/Size.js';
12
- import type { ActionsTableCell } from './ActionsTableCell.js';
13
-
14
- export interface TableActionProps<T extends object, FilterValueType> {
15
- action: TableActionButton<T>;
16
- cell: ActionsTableCell<T, FilterValueType>;
17
- }
18
- </script>
19
-
20
- <script
21
- lang="ts"
22
- generics="T extends object,FilterValueType"
23
- >
24
- const { action, cell }: TableActionProps<T, FilterValueType> = $props();
25
-
26
- const isEnabledPromise: boolean | Promise<boolean> = $derived.by(() => {
27
- const disabled = action.isDisabled?.(cell.row.original, cell.row.originalIndex);
28
-
29
- if (disabled != null) {
30
- if (typeof disabled == 'boolean') {
31
- return !disabled;
32
- } else {
33
- return disabled.then((it) => !it);
34
- }
35
- }
36
- return (
37
- cell.column.columnDef.isEnabled?.(cell.row.original, cell.row.originalIndex, action) ?? true
38
- );
39
- });
40
-
41
- const labelPromise: Promise<string> = $derived.by(() => {
42
- const result = action.getLabel(cell.row.original, cell.row.originalIndex);
43
-
44
- if (typeof result == 'object') {
45
- return result.then((it) => it);
46
- } else {
47
- return Promise.resolve(result);
48
- }
49
- });
50
- </script>
51
-
52
- {#await labelPromise then label}
53
- {#await isEnabledPromise then isEnabled}
54
- <Button
55
- fullWidth
56
- size={Size.Medium}
57
- colourSet={cell.column.columnDef.getColourSet?.(
58
- cell.row.original,
59
- cell.row.originalIndex,
60
- action
61
- ) ?? ColourSet.Secondary}
62
- disabled={!isEnabled}
63
- onclick={() => {
64
- action.callback(cell.row.original, cell.row.originalIndex);
65
- }}>{label}</Button
66
- >
67
- {:catch e}
68
- Error Loading Button: {getErrorMessage(e)}
69
- {/await}
70
- {:catch e}
71
- Error Loading Button: {getErrorMessage(e)}
72
- {/await}
1
+ <svelte:options runes />
2
+
3
+ <script
4
+ lang="ts"
5
+ module
6
+ >
7
+ import Button from '../../../../Button.svelte';
8
+ import type { TableActionButton } from '../../../Types/Columns/TableActionButton.js';
9
+ import { getErrorMessage } from '../../../../../Helpers/Helpers.svelte.js';
10
+ import { ColourSet } from '../../../../../scss/colours.js';
11
+ import { Size } from '../../../../../Types/Internal/Size.js';
12
+ import type { ActionsTableCell } from './ActionsTableCell.js';
13
+
14
+ export interface TableActionProps<T extends object, FilterValueType> {
15
+ action: TableActionButton<T>;
16
+ cell: ActionsTableCell<T, FilterValueType>;
17
+ }
18
+ </script>
19
+
20
+ <script
21
+ lang="ts"
22
+ generics="T extends object,FilterValueType"
23
+ >
24
+ const { action, cell }: TableActionProps<T, FilterValueType> = $props();
25
+
26
+ const isEnabledPromise: boolean | Promise<boolean> = $derived.by(() => {
27
+ const disabled = action.isDisabled?.(cell.row.original, cell.row.originalIndex);
28
+
29
+ if (disabled != null) {
30
+ if (typeof disabled == 'boolean') {
31
+ return !disabled;
32
+ } else {
33
+ return disabled.then((it) => !it);
34
+ }
35
+ }
36
+ return (
37
+ cell.column.columnDef.isEnabled?.(cell.row.original, cell.row.originalIndex, action) ?? true
38
+ );
39
+ });
40
+
41
+ const labelPromise: Promise<string> = $derived.by(() => {
42
+ const result = action.getLabel(cell.row.original, cell.row.originalIndex);
43
+
44
+ if (typeof result == 'object') {
45
+ return result.then((it) => it);
46
+ } else {
47
+ return Promise.resolve(result);
48
+ }
49
+ });
50
+ </script>
51
+
52
+ {#await labelPromise then label}
53
+ {#await isEnabledPromise then isEnabled}
54
+ <Button
55
+ fullWidth
56
+ size={Size.Medium}
57
+ colourSet={cell.column.columnDef.getColourSet?.(
58
+ cell.row.original,
59
+ cell.row.originalIndex,
60
+ action
61
+ ) ?? ColourSet.Secondary}
62
+ disabled={!isEnabled}
63
+ onclick={() => {
64
+ action.callback(cell.row.original, cell.row.originalIndex);
65
+ }}>{label}</Button
66
+ >
67
+ {:catch e}
68
+ Error Loading Button: {getErrorMessage(e)}
69
+ {/await}
70
+ {:catch e}
71
+ Error Loading Button: {getErrorMessage(e)}
72
+ {/await}
@@ -1,133 +1,133 @@
1
- <svelte:options runes />
2
-
3
- <script
4
- lang="ts"
5
- module
6
- >
7
- export interface TableCheckboxProps<T extends object> {
8
- cell: TableCell<T, BoolFilterValueType>;
9
-
10
- onchange?: ChangeEventHandler<HTMLInputElement>;
11
- }
12
- </script>
13
-
14
- <script
15
- lang="ts"
16
- generics="T extends object"
17
- >
18
- import type { TableCell } from '../../../Types/Columns/TableCell.js';
19
- import { TableContext } from '../../../Types/Context/TableContext.svelte.js';
20
- import type { BoolFilterValueType } from '../../../Types/Filtering/FilterFn.js';
21
- import { TableFocusDetails } from '../../../Types/Focus/TableFocusDetails.svelte.js';
22
- import { devCatch, isValidityTuple } from '../../../../../Helpers/Helpers.svelte.js';
23
- import { Validity } from '../../../../../Types/Internal/Validity.js';
24
- import { getContext, tick } from 'svelte';
25
-
26
- import type { ChangeEventHandler } from 'svelte/elements';
27
-
28
- const { cell, onchange: parentOnchange }: TableCheckboxProps<T> = $props();
29
-
30
- const value = $derived(!!cell.getValue());
31
-
32
- const tableContext = getContext<TableContext<T, never>>(TableContext.identifier);
33
-
34
- const focusDetails: TableFocusDetails<T, never> = $derived(
35
- new TableFocusDetails(cell, tableContext)
36
- );
37
-
38
- let inputRef: HTMLInputElement | undefined = $state();
39
-
40
- const onchange: ChangeEventHandler<HTMLInputElement> = (e) => {
41
- tableContext
42
- .onEditCell(
43
- cell.row.original,
44
- focusDetails.coordinates,
45
- (e.target as HTMLInputElement).checked
46
- )
47
- .catch(devCatch);
48
- parentOnchange?.(e);
49
-
50
- tick()
51
- .then(() => {
52
- if (inputRef && value != inputRef.checked) {
53
- inputRef.checked = value;
54
- }
55
- })
56
- .catch(devCatch);
57
- };
58
-
59
- let validity: Validity = $state(Validity.Valid);
60
- $effect(() => {
61
- const validityPromise = focusDetails.validity;
62
-
63
- validityPromise
64
- .then((v) => {
65
- if (!v) {
66
- validity = Validity.Neutral;
67
- } else if (isValidityTuple(v)) {
68
- validity = v.value;
69
- } else {
70
- validity = v;
71
- }
72
- })
73
- .catch(devCatch);
74
- });
75
- </script>
76
-
77
- <!-- svelte-ignore a11y_mouse_events_have_key_events -->
78
- <td
79
- class="checkbox-cell"
80
- onmousedown={(e) => {
81
- // start focus only on left click
82
- if (e.button === 0) {
83
- if (e.shiftKey) {
84
- e.preventDefault();
85
- tableContext.setFocusEnd(focusDetails.coordinates);
86
- } else {
87
- tableContext.startFocus(focusDetails.coordinates);
88
- }
89
- }
90
- }}
91
- onkeyup={(e: KeyboardEvent) => {
92
- if (e.key === 'Enter') {
93
- e.stopPropagation();
94
- tableContext.onEditCell(cell.row.original, focusDetails.coordinates, !value).catch(devCatch);
95
- }
96
- }}
97
- onkeydown={(e: KeyboardEvent) => {
98
- if (e.key == 'Enter' || e.key == 'F2') {
99
- e.stopPropagation();
100
- }
101
- }}
102
- onmouseover={() => {
103
- if (tableContext.isMousingDown) {
104
- tableContext.setFocusEnd(focusDetails.coordinates);
105
- }
106
- }}
107
- onmouseup={() => {
108
- tableContext.endFocus(focusDetails.coordinates);
109
- }}
110
- class:info={validity == Validity.Info}
111
- class:success={validity == Validity.Valid}
112
- class:warning={validity == Validity.Warning}
113
- class:error={validity == Validity.Invalid}
114
- >
115
- &nbsp;
116
- <label
117
- class:multifocus={focusDetails.isMultiFocused}
118
- class:multifocus-start={focusDetails.isMultiFocusStart}
119
- style={focusDetails.outline}
120
- >
121
- <input
122
- bind:this={inputRef}
123
- id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
124
- {onchange}
125
- type="checkbox"
126
- checked={value}
127
- />
128
- </label>
129
- </td>
130
-
1
+ <svelte:options runes />
2
+
3
+ <script
4
+ lang="ts"
5
+ module
6
+ >
7
+ export interface TableCheckboxProps<T extends object> {
8
+ cell: TableCell<T, BoolFilterValueType>;
9
+
10
+ onchange?: ChangeEventHandler<HTMLInputElement>;
11
+ }
12
+ </script>
13
+
14
+ <script
15
+ lang="ts"
16
+ generics="T extends object"
17
+ >
18
+ import type { TableCell } from '../../../Types/Columns/TableCell.js';
19
+ import { TableContext } from '../../../Types/Context/TableContext.svelte.js';
20
+ import type { BoolFilterValueType } from '../../../Types/Filtering/FilterFn.js';
21
+ import { TableFocusDetails } from '../../../Types/Focus/TableFocusDetails.svelte.js';
22
+ import { devCatch, isValidityTuple } from '../../../../../Helpers/Helpers.svelte.js';
23
+ import { Validity } from '../../../../../Types/Internal/Validity.js';
24
+ import { getContext, tick } from 'svelte';
25
+
26
+ import type { ChangeEventHandler } from 'svelte/elements';
27
+
28
+ const { cell, onchange: parentOnchange }: TableCheckboxProps<T> = $props();
29
+
30
+ const value = $derived(!!cell.getValue());
31
+
32
+ const tableContext = getContext<TableContext<T, never>>(TableContext.identifier);
33
+
34
+ const focusDetails: TableFocusDetails<T, never> = $derived(
35
+ new TableFocusDetails(cell, tableContext)
36
+ );
37
+
38
+ let inputRef: HTMLInputElement | undefined = $state();
39
+
40
+ const onchange: ChangeEventHandler<HTMLInputElement> = (e) => {
41
+ tableContext
42
+ .onEditCell(
43
+ cell.row.original,
44
+ focusDetails.coordinates,
45
+ (e.target as HTMLInputElement).checked
46
+ )
47
+ .catch(devCatch);
48
+ parentOnchange?.(e);
49
+
50
+ tick()
51
+ .then(() => {
52
+ if (inputRef && value != inputRef.checked) {
53
+ inputRef.checked = value;
54
+ }
55
+ })
56
+ .catch(devCatch);
57
+ };
58
+
59
+ let validity: Validity = $state(Validity.Valid);
60
+ $effect(() => {
61
+ const validityPromise = focusDetails.validity;
62
+
63
+ validityPromise
64
+ .then((v) => {
65
+ if (!v) {
66
+ validity = Validity.Neutral;
67
+ } else if (isValidityTuple(v)) {
68
+ validity = v.value;
69
+ } else {
70
+ validity = v;
71
+ }
72
+ })
73
+ .catch(devCatch);
74
+ });
75
+ </script>
76
+
77
+ <!-- svelte-ignore a11y_mouse_events_have_key_events -->
78
+ <td
79
+ class="checkbox-cell"
80
+ onmousedown={(e) => {
81
+ // start focus only on left click
82
+ if (e.button === 0) {
83
+ if (e.shiftKey) {
84
+ e.preventDefault();
85
+ tableContext.setFocusEnd(focusDetails.coordinates);
86
+ } else {
87
+ tableContext.startFocus(focusDetails.coordinates);
88
+ }
89
+ }
90
+ }}
91
+ onkeyup={(e: KeyboardEvent) => {
92
+ if (e.key === 'Enter') {
93
+ e.stopPropagation();
94
+ tableContext.onEditCell(cell.row.original, focusDetails.coordinates, !value).catch(devCatch);
95
+ }
96
+ }}
97
+ onkeydown={(e: KeyboardEvent) => {
98
+ if (e.key == 'Enter' || e.key == 'F2') {
99
+ e.stopPropagation();
100
+ }
101
+ }}
102
+ onmouseover={() => {
103
+ if (tableContext.isMousingDown) {
104
+ tableContext.setFocusEnd(focusDetails.coordinates);
105
+ }
106
+ }}
107
+ onmouseup={() => {
108
+ tableContext.endFocus(focusDetails.coordinates);
109
+ }}
110
+ class:info={validity == Validity.Info}
111
+ class:success={validity == Validity.Valid}
112
+ class:warning={validity == Validity.Warning}
113
+ class:error={validity == Validity.Invalid}
114
+ >
115
+ &nbsp;
116
+ <label
117
+ class:multifocus={focusDetails.isMultiFocused}
118
+ class:multifocus-start={focusDetails.isMultiFocusStart}
119
+ style={focusDetails.outline}
120
+ >
121
+ <input
122
+ bind:this={inputRef}
123
+ id={`${tableContext.tableName}-cell-${cell.row.visibleIndex}-${cell.column.id}`}
124
+ {onchange}
125
+ type="checkbox"
126
+ checked={value}
127
+ />
128
+ </label>
129
+ </td>
130
+
131
131
  <style>td {
132
132
  transition: line-height 0.2s ease, height 0.2s ease;
133
133
  --input-border: none;
@@ -186,4 +186,4 @@ td.warning {
186
186
  }
187
187
  td.error {
188
188
  background-color: #f9e9e9;
189
- }</style>
189
+ }</style>