@kayord/ui 2.1.2 → 2.1.4

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 (31) hide show
  1. package/dist/components/custom/data-table/DataTable.svelte +47 -19
  2. package/dist/components/custom/{data-grid/DataGridView.svelte.d.ts → data-table/DataTableView.svelte.d.ts} +3 -3
  3. package/dist/components/custom/data-table/index.d.ts +1 -0
  4. package/dist/components/custom/data-table/index.js +1 -0
  5. package/dist/components/custom/data-table/shad-table-old.svelte.d.ts +9 -0
  6. package/dist/components/custom/data-table/shad-table-old.svelte.js +202 -0
  7. package/dist/components/custom/data-table/shad-table.svelte.js +221 -161
  8. package/dist/components/custom/data-table/types.d.ts +8 -0
  9. package/dist/components/custom/data-table/types.js +7 -1
  10. package/package.json +9 -13
  11. package/dist/components/custom/data-grid/DataGrid.svelte +0 -183
  12. package/dist/components/custom/data-grid/DataGrid.svelte.d.ts +0 -43
  13. package/dist/components/custom/data-grid/DataGridCheckbox.svelte +0 -15
  14. package/dist/components/custom/data-grid/DataGridCheckbox.svelte.d.ts +0 -10
  15. package/dist/components/custom/data-grid/DataGridFooter.svelte +0 -35
  16. package/dist/components/custom/data-grid/DataGridFooter.svelte.d.ts +0 -28
  17. package/dist/components/custom/data-grid/DataGridHeader.svelte +0 -48
  18. package/dist/components/custom/data-grid/DataGridHeader.svelte.d.ts +0 -30
  19. package/dist/components/custom/data-grid/Pagination.svelte +0 -89
  20. package/dist/components/custom/data-grid/Pagination.svelte.d.ts +0 -31
  21. package/dist/components/custom/data-grid/createGrid.svelte.d.ts +0 -3
  22. package/dist/components/custom/data-grid/createGrid.svelte.js +0 -297
  23. package/dist/components/custom/data-grid/index.d.ts +0 -5
  24. package/dist/components/custom/data-grid/index.js +0 -4
  25. package/dist/components/custom/data-grid/types.d.ts +0 -44
  26. package/dist/components/custom/data-grid/types.js +0 -15
  27. package/dist/components/custom/data-table/VisibilitySelect.svelte +0 -27
  28. package/dist/components/custom/data-table/VisibilitySelect.svelte.d.ts +0 -28
  29. package/dist/data-grid/index.d.ts +0 -2
  30. package/dist/data-grid/index.js +0 -2
  31. /package/dist/components/custom/{data-grid/DataGridView.svelte → data-table/DataTableView.svelte} +0 -0
@@ -3,14 +3,13 @@
3
3
  import { FlexRender } from "../../ui/data-table";
4
4
  import { Skeleton, Table } from "../../ui";
5
5
  import Pagination from "./Pagination.svelte";
6
- import { onMount, type Snippet } from "svelte";
6
+ import { onMount, untrack, type Snippet } from "svelte";
7
7
  import { fade } from "svelte/transition";
8
8
  import { ProgressLoading } from "../progress-loading";
9
9
  import FullscreenModeToggle from "./FullscreenModeToggle.svelte";
10
10
  import { cn } from "../../../utils";
11
11
  import { TableStore } from "./table.svelte";
12
12
  import DataTableHeader from "./DataTableHeader.svelte";
13
- import VisibilitySelect from "./VisibilitySelect.svelte";
14
13
  import DataTableFooter from "./DataTableFooter.svelte";
15
14
  import { beforeNavigate, goto } from "$app/navigation";
16
15
  import {
@@ -18,8 +17,13 @@
18
17
  decodeGlobalFilter,
19
18
  decodePageIndex,
20
19
  decodeSorting,
20
+ encodeColumnFilters,
21
+ encodeSorting,
21
22
  encodeTableState,
22
23
  } from "./table-search-params";
24
+ import { useSearchParams } from "runed/kit";
25
+ import { defaultSearchParamSchema } from "./types";
26
+ import DataTableView from "./DataTableView.svelte";
23
27
 
24
28
  interface Props<T> {
25
29
  table: TableType<T>;
@@ -60,11 +64,22 @@
60
64
  const isPaginationEnabled = table.options.getPaginationRowModel !== undefined;
61
65
 
62
66
  // Load Default Values from Page Params
67
+ // onMount(() => {
68
+ // if (table.options.useURLSearchParams) {
69
+ // table.setPageIndex(decodePageIndex());
70
+ // table.setSorting(decodeSorting() ?? []);
71
+ // table.setGlobalFilter(decodeGlobalFilter());
72
+ // table.setColumnFilters(decodeColumnFilters() ?? []);
73
+ // }
74
+ // });
75
+
76
+ const params = useSearchParams(defaultSearchParamSchema, { pushHistory: false });
77
+ // Load current url search params
63
78
  onMount(() => {
64
79
  if (table.options.useURLSearchParams) {
65
- table.setPageIndex(decodePageIndex());
80
+ table.setGlobalFilter(params.search);
66
81
  table.setSorting(decodeSorting() ?? []);
67
- table.setGlobalFilter(decodeGlobalFilter());
82
+ table.setPageIndex(params.page);
68
83
  table.setColumnFilters(decodeColumnFilters() ?? []);
69
84
  }
70
85
  });
@@ -85,20 +100,33 @@
85
100
  }
86
101
  });
87
102
 
88
- // Set URL Page Params
103
+ // Set url search params
89
104
  $effect(() => {
90
105
  if (table.options.useURLSearchParams) {
91
- const params = encodeTableState(table.getState());
92
- goto(params, {
93
- replaceState: true,
94
- keepFocus: true,
95
- noScroll: true,
96
- }).catch(() => {
97
- // Ignore navigation errors in test environments
106
+ const tableState = table.getState();
107
+ untrack(() => {
108
+ params.search = tableState.globalFilter;
109
+ params.page = tableState.pagination.pageIndex;
110
+ params.sort = encodeSorting(tableState);
111
+ params.filter = encodeColumnFilters(tableState);
98
112
  });
99
113
  }
100
114
  });
101
115
 
116
+ // Set URL Page Params
117
+ // $effect(() => {
118
+ // if (table.options.useURLSearchParams) {
119
+ // const params = encodeTableState(table.getState());
120
+ // goto(params, {
121
+ // replaceState: true,
122
+ // keepFocus: true,
123
+ // noScroll: true,
124
+ // }).catch(() => {
125
+ // // Ignore navigation errors in test environments
126
+ // });
127
+ // }
128
+ // });
129
+
102
130
  let end: HTMLElement | undefined = $state();
103
131
  </script>
104
132
 
@@ -128,7 +156,7 @@
128
156
  {/if}
129
157
  {#if enableVisibility}
130
158
  <div>
131
- <VisibilitySelect {table} />
159
+ <DataTableView {table} />
132
160
  </div>
133
161
  {/if}
134
162
  {#if enableFullscreen}
@@ -155,9 +183,9 @@
155
183
  <Table.Root class="table-auto">
156
184
  {#if !hideHeader}
157
185
  <Table.Header>
158
- {#each table.getHeaderGroups() as headerGroup}
186
+ {#each table.getHeaderGroups() as headerGroup (headerGroup)}
159
187
  <Table.Row>
160
- {#each headerGroup.headers as header}
188
+ {#each headerGroup.headers as header (header)}
161
189
  <DataTableHeader {header} {table} {disableUISorting} />
162
190
  {/each}
163
191
  </Table.Row>
@@ -167,9 +195,9 @@
167
195
 
168
196
  <Table.Body>
169
197
  {#if isLoading && table.getRowModel().rows.length == 0}
170
- {#each { length: 5 } as _, i}
198
+ {#each { length: 5 } as loadingTemplate (loadingTemplate)}
171
199
  <Table.Row>
172
- {#each table.getAllColumns() as _cell}
200
+ {#each table.getAllColumns() as _cell (_cell)}
173
201
  <Table.Cell>
174
202
  <Skeleton class="h-4" />
175
203
  </Table.Cell>
@@ -184,9 +212,9 @@
184
212
  </Table.Cell>
185
213
  </Table.Row>
186
214
  {/if}
187
- {#each table.getRowModel().rows as row}
215
+ {#each table.getRowModel().rows as row (row)}
188
216
  <Table.Row data-state={row.getIsSelected() && "selected"}>
189
- {#each row.getVisibleCells() as cell}
217
+ {#each row.getVisibleCells() as cell (cell)}
190
218
  <Table.Cell
191
219
  class={cell.column.columnDef.meta?.className}
192
220
  style={`width: ${cell.column.getSize()}px; min-width:${cell.column.columnDef.minSize}px; max-width:${cell.column.columnDef.maxSize}px`}
@@ -24,6 +24,6 @@ interface $$IsomorphicComponent {
24
24
  <TData>(internal: unknown, props: ReturnType<__sveltets_Render<TData>['props']> & {}): ReturnType<__sveltets_Render<TData>['exports']>;
25
25
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
26
26
  }
27
- declare const DataGridView: $$IsomorphicComponent;
28
- type DataGridView<TData> = InstanceType<typeof DataGridView<TData>>;
29
- export default DataGridView;
27
+ declare const DataTableView: $$IsomorphicComponent;
28
+ type DataTableView<TData> = InstanceType<typeof DataTableView<TData>>;
29
+ export default DataTableView;
@@ -1,5 +1,6 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
2
  export { createShadTable } from "./shad-table.svelte";
3
+ export { createShadTableOld } from "./shad-table-old.svelte";
3
4
  export { aggregationFns } from "./data-table-utils";
4
5
  export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, decodeTableState, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
5
6
  export type { CustomColumnMeta, CustomOptions } from "./types";
@@ -1,4 +1,5 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
2
  export { createShadTable } from "./shad-table.svelte";
3
+ export { createShadTableOld } from "./shad-table-old.svelte";
3
4
  export { aggregationFns } from "./data-table-utils";
4
5
  export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, decodeTableState, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
@@ -0,0 +1,9 @@
1
+ import { type RowData, type RowModel, type Table, type TableOptions } from "@tanstack/table-core";
2
+ interface ShadTableOptions<TData extends RowData> extends Omit<TableOptions<TData>, "getCoreRowModel"> {
3
+ getCoreRowModel?: (table: Table<any>) => () => RowModel<any>;
4
+ enablePaging?: boolean;
5
+ enableVisibility?: boolean;
6
+ enableRowSelectionUI?: boolean;
7
+ }
8
+ export declare function createShadTableOld<TData extends RowData>(shadOptions: ShadTableOptions<TData>): Table<TData>;
9
+ export {};
@@ -0,0 +1,202 @@
1
+ import { createTable, getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, } from "@tanstack/table-core";
2
+ import DataTableCheckbox from "./DataTableCheckbox.svelte";
3
+ import { renderComponent } from "../../../data-table";
4
+ import { mergeObjects } from "../../ui/data-table/data-table.svelte";
5
+ export function createShadTableOld(shadOptions) {
6
+ if (!shadOptions.getCoreRowModel) {
7
+ shadOptions.getCoreRowModel = getCoreRowModel();
8
+ }
9
+ if ((shadOptions.enablePaging ?? true) == false) {
10
+ shadOptions.manualPagination = true;
11
+ }
12
+ if (shadOptions.useURLSearchParams) {
13
+ shadOptions.autoResetPageIndex = false;
14
+ }
15
+ const options = shadOptions;
16
+ // Features
17
+ // Sorting
18
+ if ((options.enableSorting ?? true) && !options.getSortedRowModel) {
19
+ options.getSortedRowModel = getSortedRowModel();
20
+ if (!options.onSortingChange) {
21
+ options.onSortingChange = (updater) => {
22
+ if (typeof updater === "function") {
23
+ if (options.state?.sorting) {
24
+ options.state.sorting = updater(options.state.sorting);
25
+ }
26
+ else if (state.sorting) {
27
+ state.sorting = updater(state.sorting);
28
+ }
29
+ }
30
+ else {
31
+ if (options.state?.sorting) {
32
+ options.state.sorting = updater;
33
+ }
34
+ else {
35
+ state.sorting = updater;
36
+ }
37
+ }
38
+ };
39
+ }
40
+ }
41
+ // Paging
42
+ if ((shadOptions.enablePaging ?? true) && !options.getPaginationRowModel) {
43
+ options.getPaginationRowModel = getPaginationRowModel();
44
+ if (!options.onPaginationChange) {
45
+ options.onPaginationChange = (updater) => {
46
+ if (typeof updater === "function") {
47
+ if (options.state?.pagination) {
48
+ options.state.pagination = updater(options.state.pagination);
49
+ }
50
+ else if (state.pagination) {
51
+ state.pagination = updater(state.pagination);
52
+ }
53
+ }
54
+ else {
55
+ if (options.state?.pagination) {
56
+ options.state.pagination = updater;
57
+ }
58
+ else {
59
+ state.pagination = updater;
60
+ }
61
+ }
62
+ };
63
+ }
64
+ }
65
+ // Row Selection
66
+ if ((options.enableRowSelection ?? true) && !options.onRowSelectionChange) {
67
+ options.onRowSelectionChange = (updater) => {
68
+ if (typeof updater === "function") {
69
+ if (options.state?.rowSelection) {
70
+ options.state.rowSelection = updater(options.state.rowSelection);
71
+ }
72
+ else if (state.rowSelection) {
73
+ state.rowSelection = updater(state.rowSelection);
74
+ }
75
+ }
76
+ else {
77
+ if (options.state?.rowSelection) {
78
+ options.state.rowSelection = updater;
79
+ }
80
+ else {
81
+ state.rowSelection = updater;
82
+ }
83
+ }
84
+ };
85
+ }
86
+ if (options.enableRowSelection && (shadOptions.enableRowSelectionUI ?? true)) {
87
+ const rowSelectionColumn = {
88
+ id: "select",
89
+ header: () => renderComponent(DataTableCheckbox, {
90
+ checked: table.getIsAllPageRowsSelected(),
91
+ onCheckedChange: () => table.toggleAllPageRowsSelected(),
92
+ }),
93
+ cell: (r) => renderComponent(DataTableCheckbox, {
94
+ checked: r.row.getIsSelected(),
95
+ onCheckedChange: () => r.row.toggleSelected(),
96
+ }),
97
+ enableResizing: false,
98
+ enableSorting: false,
99
+ };
100
+ options.columns.unshift(rowSelectionColumn);
101
+ }
102
+ // Column Visibility
103
+ if ((shadOptions.enableVisibility ?? false) && !options.onColumnVisibilityChange) {
104
+ options.onColumnVisibilityChange = (updater) => {
105
+ if (typeof updater === "function") {
106
+ if (options.state?.columnVisibility) {
107
+ options.state.columnVisibility = updater(options.state.columnVisibility);
108
+ }
109
+ else if (state.columnVisibility) {
110
+ state.columnVisibility = updater(state.columnVisibility);
111
+ }
112
+ }
113
+ else {
114
+ if (options.state?.columnVisibility) {
115
+ options.state.columnVisibility = updater;
116
+ }
117
+ else {
118
+ state.columnVisibility = updater;
119
+ }
120
+ }
121
+ };
122
+ }
123
+ // Filtering
124
+ if ((options.enableFilters ?? true) && !options.getFilteredRowModel) {
125
+ options.getFilteredRowModel = getFilteredRowModel();
126
+ // Global Filtering
127
+ if (options.enableGlobalFilter ?? false) {
128
+ if (!options.onGlobalFilterChange) {
129
+ options.onGlobalFilterChange = (updater) => {
130
+ if (typeof updater === "function") {
131
+ if (options.state?.globalFilter) {
132
+ options.state.globalFilter = updater(options.state.globalFilter);
133
+ }
134
+ else if (state.globalFilter) {
135
+ state.globalFilter = updater(state.globalFilter);
136
+ }
137
+ }
138
+ else {
139
+ if (options.state?.globalFilter) {
140
+ options.state.globalFilter = updater;
141
+ }
142
+ else {
143
+ state.globalFilter = updater;
144
+ }
145
+ }
146
+ };
147
+ }
148
+ }
149
+ else {
150
+ if (!options.onColumnFiltersChange) {
151
+ options.onColumnFiltersChange = (updater) => {
152
+ if (typeof updater === "function") {
153
+ if (options.state?.columnFilters) {
154
+ options.state.columnFilters = updater(options.state.columnFilters);
155
+ }
156
+ else if (state.columnFilters) {
157
+ state.columnFilters = updater(state.columnFilters);
158
+ }
159
+ }
160
+ else {
161
+ if (options.state?.columnFilters) {
162
+ options.state.columnFilters = updater;
163
+ }
164
+ else {
165
+ state.columnFilters = updater;
166
+ }
167
+ }
168
+ };
169
+ }
170
+ }
171
+ }
172
+ const resolvedOptions = mergeObjects({
173
+ state: {},
174
+ onStateChange() { },
175
+ renderFallbackValue: null,
176
+ mergeOptions: (defaultOptions, options) => {
177
+ return mergeObjects(defaultOptions, options);
178
+ },
179
+ }, options);
180
+ const table = createTable(resolvedOptions);
181
+ let state = $state(table.initialState);
182
+ const updateOptions = (table, state) => {
183
+ table.setOptions((prev) => {
184
+ return mergeObjects(prev, options, {
185
+ state: mergeObjects(state, options.state || {}),
186
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
187
+ onStateChange: (updater) => {
188
+ if (updater instanceof Function)
189
+ state = updater(state);
190
+ else
191
+ state = mergeObjects(state, updater);
192
+ options.onStateChange?.(updater);
193
+ },
194
+ });
195
+ });
196
+ };
197
+ updateOptions(table, state);
198
+ $effect.pre(() => {
199
+ updateOptions(table, state);
200
+ });
201
+ return table;
202
+ }