@softwareone/spi-sv5-library 1.11.5 → 1.11.7

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.
@@ -199,7 +199,7 @@
199
199
 
200
200
  <style>
201
201
  .container {
202
- --color-red: #b30825;
202
+ --color-red: #dc2626;
203
203
  --color-gray-outer: #434952;
204
204
  --color-gray-auro: #6b7180;
205
205
  --color-gray: #e0e5e8;
@@ -238,9 +238,7 @@
238
238
 
239
239
  .text-error {
240
240
  color: var(--color-red);
241
- margin: 4px;
242
241
  font-size: 12px;
243
- line-height: 16px;
244
242
  }
245
243
 
246
244
  .drop-area {
@@ -7,7 +7,7 @@
7
7
  showModal?: boolean;
8
8
  ondelete: () => Promise<boolean> | boolean;
9
9
  onclose?: VoidFunction;
10
- ondeleteSuccess?: VoidFunction;
10
+ ondeleteSuccess?: () => Promise<void> | void;
11
11
  }
12
12
 
13
13
  let {
@@ -28,15 +28,17 @@
28
28
 
29
29
  const handleDelete = async () => {
30
30
  isLoading = true;
31
+
31
32
  const isSuccessful = await ondelete();
32
- isLoading = false;
33
33
 
34
34
  if (isSuccessful) {
35
+ await ondeleteSuccess?.();
35
36
  showModal = false;
36
- ondeleteSuccess?.();
37
37
  } else {
38
38
  addToast({ message: 'There was an unexpected error.', type: 'danger' });
39
39
  }
40
+
41
+ isLoading = false;
40
42
  };
41
43
  </script>
42
44
 
@@ -4,7 +4,7 @@ interface DeleteConfirmationProps {
4
4
  showModal?: boolean;
5
5
  ondelete: () => Promise<boolean> | boolean;
6
6
  onclose?: VoidFunction;
7
- ondeleteSuccess?: VoidFunction;
7
+ ondeleteSuccess?: () => Promise<void> | void;
8
8
  }
9
9
  declare const DeleteConfirmation: import("svelte").Component<DeleteConfirmationProps, {}, "showModal">;
10
10
  type DeleteConfirmation = ReturnType<typeof DeleteConfirmation>;
@@ -52,7 +52,7 @@
52
52
  let isLoading = $state(false);
53
53
 
54
54
  const { form, errors, isFormValid } = getFormContext<Schema>(contextName);
55
- $form = structuredClone($state.snapshot(initialData));
55
+ $form = $state.snapshot(initialData);
56
56
 
57
57
  const onUpdated = () => {
58
58
  isLoading = false;
@@ -4,16 +4,32 @@
4
4
 
5
5
  interface Props {
6
6
  bodyRows: Row<T>[];
7
+ enableChecked?: boolean;
7
8
  }
8
9
 
9
- let { bodyRows }: Props = $props();
10
+ let { bodyRows, enableChecked = false }: Props = $props();
11
+
12
+ const CLICKABLE_TAGS = ['td', 'span', 'p'];
13
+
14
+ const handleRowClick = (row: Row<T>, target: EventTarget | null) => {
15
+ const isHtmlElement = target instanceof HTMLElement;
16
+ const tagName = isHtmlElement ? target.tagName.toLocaleLowerCase() : '';
17
+ if (isHtmlElement && CLICKABLE_TAGS.includes(tagName)) {
18
+ row.toggleSelected();
19
+ }
20
+ };
10
21
  </script>
11
22
 
12
23
  <tbody class="table-body">
13
24
  {#each bodyRows as row (row.id)}
14
25
  <tr
15
26
  animate:flip={{ duration: 500 }}
16
- class={['table-row', row.getIsSelected() && 'table-row--selected']}
27
+ class={[
28
+ 'table-row',
29
+ row.getIsSelected() && 'table-row--selected',
30
+ enableChecked && 'table-row--clickable'
31
+ ]}
32
+ onclick={enableChecked ? (event) => handleRowClick(row, event.target) : undefined}
17
33
  >
18
34
  {#each row.getVisibleCells() as cell}
19
35
  {@const alignColumn = cell.column.columnDef.meta?.alignColumn}
@@ -66,6 +82,10 @@
66
82
  background: var(--color-row-selected);
67
83
  }
68
84
 
85
+ .table-row--clickable {
86
+ cursor: pointer;
87
+ }
88
+
69
89
  .table-cell {
70
90
  max-width: 50px;
71
91
  padding: var(--spacing-md) var(--spacing-lg);
@@ -2,6 +2,7 @@ import { type Row } from './adapter/index.js';
2
2
  declare function $$render<T>(): {
3
3
  props: {
4
4
  bodyRows: Row<T>[];
5
+ enableChecked?: boolean;
5
6
  };
6
7
  exports: {};
7
8
  bindings: "";
@@ -48,7 +48,7 @@
48
48
  pagination?: Pagination;
49
49
  excelSetting?: ExcelSetting;
50
50
  header?: Snippet;
51
- bulkActions?: Snippet<[selectedRows: T[]]>;
51
+ bulkActions?: Snippet<[selectedRows: T[], clearSelection: VoidFunction]>;
52
52
  onpagechange?: (pageSize: number, pageNumber: number) => void;
53
53
  onpagesizechange?: (pageSize: number) => void;
54
54
  }
@@ -87,11 +87,23 @@
87
87
  const tableManualPagination = manualPagination ? setPaginationTableContext() : undefined;
88
88
  const hasData = $derived(data.length > 0);
89
89
 
90
+ const tableColumns = $derived.by(() => {
91
+ if (!enableChecked) return columns;
92
+
93
+ const checkedColumnExists = columns.some((column) => column.id === 'checked');
94
+ if (checkedColumnExists) return columns;
95
+
96
+ const checkedColumn = createCheckedColumn<T>();
97
+ return [checkedColumn, ...columns];
98
+ });
99
+
90
100
  const table = createSvelteTable({
91
101
  get data() {
92
102
  return tableData;
93
103
  },
94
- columns,
104
+ get columns() {
105
+ return tableColumns;
106
+ },
95
107
  state: {
96
108
  get sorting() {
97
109
  return sorting;
@@ -194,6 +206,10 @@
194
206
  }
195
207
  }
196
208
 
209
+ const clearSelection = () => {
210
+ rowSelection = {};
211
+ };
212
+
197
213
  const changeFilters = (filters: Filter[]) => {
198
214
  const searchParams = new URLSearchParams(page.url.searchParams);
199
215
  searchParams.delete('filter');
@@ -222,16 +238,6 @@
222
238
  $tableManualPagination = { ...pagination };
223
239
  }
224
240
  });
225
-
226
- $effect.pre(() => {
227
- if (enableChecked && columns.length) {
228
- const checkedColumnExists = columns.some((column) => column.id === 'checked');
229
- if (!checkedColumnExists) {
230
- const checkedColumn = createCheckedColumn<T>();
231
- columns.unshift(checkedColumn);
232
- }
233
- }
234
- });
235
241
  </script>
236
242
 
237
243
  <section class="table-container">
@@ -284,7 +290,10 @@
284
290
  </p>
285
291
  {#if bulkActions}
286
292
  <hr class="action-divider" />
287
- {@render bulkActions?.(selectedRows.map((row) => row.original))}
293
+ {@render bulkActions?.(
294
+ selectedRows.map((row) => row.original),
295
+ clearSelection
296
+ )}
288
297
  {/if}
289
298
  </div>
290
299
  {/if}
@@ -293,7 +302,7 @@
293
302
  <table class="table-main">
294
303
  <Header headerGroups={table.getHeaderGroups()} {enableColumnSearch} />
295
304
  {#if hasData}
296
- <Body bodyRows={table.getRowModel().rows} />
305
+ <Body bodyRows={table.getRowModel().rows} {enableChecked} />
297
306
  {/if}
298
307
  </table>
299
308
  </article>
@@ -18,7 +18,7 @@ declare function $$render<T>(): {
18
18
  pagination?: Pagination;
19
19
  excelSetting?: ExcelSetting;
20
20
  header?: Snippet;
21
- bulkActions?: Snippet<[selectedRows: T[]]>;
21
+ bulkActions?: Snippet<[selectedRows: T[], clearSelection: VoidFunction]>;
22
22
  onpagechange?: (pageSize: number, pageNumber: number) => void;
23
23
  onpagesizechange?: (pageSize: number) => void;
24
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwareone/spi-sv5-library",
3
- "version": "1.11.5",
3
+ "version": "1.11.7",
4
4
  "description": "Svelte components",
5
5
  "keywords": [
6
6
  "svelte",