@kayord/ui 0.15.6 → 0.15.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.
@@ -12,10 +12,10 @@
12
12
  import { cn } from "../../../utils";
13
13
  import { tableStore } from "./table.svelte";
14
14
  import DataTableHeader from "./DataTableHeader.svelte";
15
- import type { ShadTable } from "./shad-table.svelte";
16
15
 
17
16
  interface Props<T> {
18
- tableState: ShadTable<T>;
17
+ table: TableType<T>;
18
+ columns: ColumnDef<T>[];
19
19
  isLoading?: boolean;
20
20
  header?: Snippet;
21
21
  subHeader?: Snippet;
@@ -32,7 +32,8 @@
32
32
  }
33
33
 
34
34
  let {
35
- tableState = $bindable(),
35
+ table = $bindable(),
36
+ columns,
36
37
  isLoading = false,
37
38
  header,
38
39
  subHeader,
@@ -48,8 +49,8 @@
48
49
  disableUISorting = false,
49
50
  }: Props<T> = $props();
50
51
 
51
- const isPaginationEnabled = tableState.table.options.getPaginationRowModel !== undefined;
52
- const enableRowSelection = tableState.table.options.enableRowSelection;
52
+ const isPaginationEnabled = table.options.getPaginationRowModel !== undefined;
53
+ const enableRowSelection = table.options.enableRowSelection;
53
54
 
54
55
  if (enableRowSelection) {
55
56
  const rowSelectionColumn: ColumnDef<T> = {
@@ -57,8 +58,8 @@
57
58
  // cell: (info) => "[]",
58
59
  header: () =>
59
60
  renderComponent(DataTableCheckbox, {
60
- checked: tableState.table.getIsAllPageRowsSelected(),
61
- onCheckedChange: () => tableState.table.toggleAllPageRowsSelected(),
61
+ checked: table.getIsAllPageRowsSelected(),
62
+ onCheckedChange: () => table.toggleAllPageRowsSelected(),
62
63
  }),
63
64
  cell: (r) =>
64
65
  renderComponent(DataTableCheckbox, {
@@ -68,7 +69,7 @@
68
69
  enableResizing: false,
69
70
  enableSorting: false,
70
71
  };
71
- tableState.columns.unshift(rowSelectionColumn);
72
+ columns.unshift(rowSelectionColumn);
72
73
  }
73
74
  </script>
74
75
 
@@ -96,7 +97,7 @@
96
97
  {/if}
97
98
  {#if enableVisibility}
98
99
  <div>
99
- <VisibilitySelect bind:tableState />
100
+ <VisibilitySelect bind:table />
100
101
  </div>
101
102
  {/if}
102
103
  {#if enableFullscreen}
@@ -123,10 +124,10 @@
123
124
  <Table.Root class="table-auto">
124
125
  {#if !hideHeader}
125
126
  <Table.Header>
126
- {#each tableState.table.getHeaderGroups() as headerGroup, headerGroupIndex}
127
+ {#each table.getHeaderGroups() as headerGroup, headerGroupIndex}
127
128
  <Table.Row>
128
129
  {#each headerGroup.headers as header, headerIndex}
129
- <DataTableHeader {headerGroupIndex} {headerIndex} bind:tableState {disableUISorting} />
130
+ <DataTableHeader {headerGroupIndex} {headerIndex} bind:table {disableUISorting} />
130
131
  {/each}
131
132
  </Table.Row>
132
133
  {/each}
@@ -134,10 +135,10 @@
134
135
  {/if}
135
136
 
136
137
  <Table.Body>
137
- {#if isLoading && tableState.table.getRowModel().rows.length == 0}
138
+ {#if isLoading && table.getRowModel().rows.length == 0}
138
139
  {#each { length: 5 } as _, i}
139
140
  <Table.Row>
140
- {#each tableState.columns as _cell}
141
+ {#each columns as _cell}
141
142
  <Table.Cell>
142
143
  <Skeleton class="h-4" />
143
144
  </Table.Cell>
@@ -145,14 +146,14 @@
145
146
  </Table.Row>
146
147
  {/each}
147
148
  {:else}
148
- {#if tableState.table.getRowModel().rows.length == 0}
149
+ {#if table.getRowModel().rows.length == 0}
149
150
  <Table.Row>
150
- <Table.Cell colspan={tableState.table.getAllColumns().length}>
151
+ <Table.Cell colspan={table.getAllColumns().length}>
151
152
  <div class="text-center">{noDataMessage}</div>
152
153
  </Table.Cell>
153
154
  </Table.Row>
154
155
  {/if}
155
- {#each tableState.table.getRowModel().rows as row}
156
+ {#each table.getRowModel().rows as row}
156
157
  <Table.Row data-state={row.getIsSelected() && "selected"}>
157
158
  {#each row.getVisibleCells() as cell}
158
159
  <Table.Cell
@@ -173,7 +174,7 @@
173
174
  {/if}
174
175
  </div>
175
176
  {#if isPaginationEnabled}
176
- <Pagination bind:tableState />
177
+ <Pagination bind:table />
177
178
  {/if}
178
179
 
179
180
  {#if footer}
@@ -1,7 +1,8 @@
1
+ import { type ColumnDef, type Table as TableType } from "@tanstack/table-core";
1
2
  import type { Snippet } from "svelte";
2
- import type { ShadTable } from "./shad-table.svelte";
3
3
  interface Props<T> {
4
- tableState: ShadTable<T>;
4
+ table: TableType<T>;
5
+ columns: ColumnDef<T>[];
5
6
  isLoading?: boolean;
6
7
  header?: Snippet;
7
8
  subHeader?: Snippet;
@@ -20,7 +21,7 @@ declare class __sveltets_Render<T> {
20
21
  props(): Props<T>;
21
22
  events(): {};
22
23
  slots(): {};
23
- bindings(): "tableState";
24
+ bindings(): "table";
24
25
  exports(): {};
25
26
  }
26
27
  interface $$IsomorphicComponent {
@@ -2,22 +2,19 @@
2
2
  import { FlexRender, Table } from "../../..";
3
3
  import { type Header, type Table as TypeType } from "@tanstack/table-core";
4
4
  import { ArrowUpDownIcon, ArrowDownIcon, ArrowUpIcon } from "@lucide/svelte";
5
- import type { ShadTable } from "./shad-table.svelte";
6
5
 
7
6
  interface Props<T> {
8
7
  headerGroupIndex: number;
9
8
  headerIndex: number;
10
- tableState: ShadTable<T>;
9
+ table: TypeType<T>;
11
10
  disableUISorting?: boolean;
12
11
  }
13
12
 
14
- let { headerGroupIndex, headerIndex, tableState = $bindable(), disableUISorting = false }: Props<T> = $props();
13
+ let { headerGroupIndex, headerIndex, table = $bindable(), disableUISorting = false }: Props<T> = $props();
15
14
 
16
- const isSortingEnabled = $derived(
17
- tableState.table.options.getSortedRowModel !== undefined && disableUISorting !== true
18
- );
15
+ const isSortingEnabled = $derived(table.options.getSortedRowModel !== undefined && disableUISorting !== true);
19
16
 
20
- const header = tableState.table.getHeaderGroups()[headerGroupIndex].headers[headerIndex];
17
+ const header = table.getHeaderGroups()[headerGroupIndex].headers[headerIndex];
21
18
  </script>
22
19
 
23
20
  <Table.Head
@@ -1,15 +1,15 @@
1
- import type { ShadTable } from "./shad-table.svelte";
1
+ import { type Table as TypeType } from "@tanstack/table-core";
2
2
  interface Props<T> {
3
3
  headerGroupIndex: number;
4
4
  headerIndex: number;
5
- tableState: ShadTable<T>;
5
+ table: TypeType<T>;
6
6
  disableUISorting?: boolean;
7
7
  }
8
8
  declare class __sveltets_Render<T> {
9
9
  props(): Props<T>;
10
10
  events(): {};
11
11
  slots(): {};
12
- bindings(): "tableState";
12
+ bindings(): "table";
13
13
  exports(): {};
14
14
  }
15
15
  interface $$IsomorphicComponent {
@@ -5,23 +5,22 @@
5
5
  import DoubleArrowLeft from "@lucide/svelte/icons/arrow-left";
6
6
  import DoubleArrowRight from "@lucide/svelte/icons/arrow-right";
7
7
  import { Select, Button } from "../../..";
8
- import type { ShadTable } from "./shad-table.svelte";
9
8
 
10
9
  interface Props<T> {
11
- tableState: ShadTable<T>;
10
+ table: Table<T>;
12
11
  canChangePageSize?: boolean;
13
12
  }
14
13
 
15
- let { tableState = $bindable(), canChangePageSize = false }: Props<T> = $props();
14
+ let { table = $bindable(), canChangePageSize = false }: Props<T> = $props();
16
15
 
17
- let value = $state(tableState.table.getState().pagination.pageSize.toString());
16
+ let value = $state(table.getState().pagination.pageSize.toString());
18
17
  </script>
19
18
 
20
19
  <div class="flex items-center justify-between py-2">
21
20
  <div class="text-muted-foreground flex-1 text-sm">
22
- {#if tableState.table.options.enableRowSelection}
23
- {tableState.table.getFilteredSelectedRowModel().rows.length} of
24
- {tableState.table.getFilteredRowModel().rows.length} row(s) selected.
21
+ {#if table.options.enableRowSelection}
22
+ {table.getFilteredSelectedRowModel().rows.length} of
23
+ {table.getFilteredRowModel().rows.length} row(s) selected.
25
24
  {/if}
26
25
  </div>
27
26
  <div class="flex items-center space-x-6 lg:space-x-8">
@@ -32,7 +31,7 @@
32
31
  type="single"
33
32
  bind:value
34
33
  onValueChange={(value) => {
35
- tableState.table.setPageSize(Number(value));
34
+ table.setPageSize(Number(value));
36
35
  }}
37
36
  >
38
37
  <Select.Trigger class="h-8 w-[70px]">Select page size</Select.Trigger>
@@ -47,15 +46,15 @@
47
46
  {/if}
48
47
  </div>
49
48
  <div class="flex w-[100px] items-center justify-center text-sm font-medium">
50
- Page {tableState.table.getState().pagination.pageIndex + 1} of
51
- {tableState.table.getPageCount()}
49
+ Page {table.getState().pagination.pageIndex + 1} of
50
+ {table.getPageCount()}
52
51
  </div>
53
52
  <div class="flex items-center space-x-2">
54
53
  <Button
55
54
  variant="outline"
56
55
  class="hidden size-8 p-0 lg:flex"
57
- onclick={() => tableState.table.setPageIndex(0)}
58
- disabled={!tableState.table.getCanPreviousPage()}
56
+ onclick={() => table.setPageIndex(0)}
57
+ disabled={!table.getCanPreviousPage()}
59
58
  >
60
59
  <span class="sr-only">Go to first page</span>
61
60
  <DoubleArrowLeft class="size-4" />
@@ -63,26 +62,21 @@
63
62
  <Button
64
63
  variant="outline"
65
64
  class="size-8 p-0"
66
- onclick={() => tableState.table.previousPage()}
67
- disabled={!tableState.table.getCanPreviousPage()}
65
+ onclick={() => table.previousPage()}
66
+ disabled={!table.getCanPreviousPage()}
68
67
  >
69
68
  <span class="sr-only">Go to previous page</span>
70
69
  <ChevronLeft class="size-4" />
71
70
  </Button>
72
- <Button
73
- variant="outline"
74
- class="size-8 p-0"
75
- onclick={() => tableState.table.nextPage()}
76
- disabled={!tableState.table.getCanNextPage()}
77
- >
71
+ <Button variant="outline" class="size-8 p-0" onclick={() => table.nextPage()} disabled={!table.getCanNextPage()}>
78
72
  <span class="sr-only">Go to next page</span>
79
73
  <ChevronRight class="size-4" />
80
74
  </Button>
81
75
  <Button
82
76
  variant="outline"
83
77
  class="hidden size-8 p-0 lg:flex"
84
- onclick={() => tableState.table.setPageIndex(tableState.table.getPageCount() - 1)}
85
- disabled={!tableState.table.getCanNextPage()}
78
+ onclick={() => table.setPageIndex(table.getPageCount() - 1)}
79
+ disabled={!table.getCanNextPage()}
86
80
  >
87
81
  <span class="sr-only">Go to last page</span>
88
82
  <DoubleArrowRight class="size-4" />
@@ -1,13 +1,13 @@
1
- import type { ShadTable } from "./shad-table.svelte";
1
+ import type { Table } from "@tanstack/table-core";
2
2
  interface Props<T> {
3
- tableState: ShadTable<T>;
3
+ table: Table<T>;
4
4
  canChangePageSize?: boolean;
5
5
  }
6
6
  declare class __sveltets_Render<T> {
7
7
  props(): Props<T>;
8
8
  events(): {};
9
9
  slots(): {};
10
- bindings(): "tableState";
10
+ bindings(): "table";
11
11
  exports(): {};
12
12
  }
13
13
  interface $$IsomorphicComponent {
@@ -2,13 +2,13 @@
2
2
  import * as DropdownMenu from "../../ui/dropdown-menu";
3
3
  import { Button } from "../../ui/button";
4
4
  import { Settings2Icon } from "@lucide/svelte";
5
- import type { ShadTable } from "./shad-table.svelte";
5
+ import type { Table } from "@tanstack/table-core";
6
6
 
7
7
  interface Props<T> {
8
- tableState: ShadTable<T>;
8
+ table: Table<T>;
9
9
  }
10
10
 
11
- let { tableState = $bindable() }: Props<T> = $props();
11
+ let { table = $bindable() }: Props<T> = $props();
12
12
  </script>
13
13
 
14
14
  <DropdownMenu.Root>
@@ -20,7 +20,7 @@
20
20
  <DropdownMenu.Content>
21
21
  <DropdownMenu.Label>Toggle columns</DropdownMenu.Label>
22
22
  <DropdownMenu.Separator />
23
- {#each tableState.table.getAllLeafColumns() as column}
23
+ {#each table.getAllLeafColumns() as column}
24
24
  <DropdownMenu.CheckboxItem checked={column.getIsVisible()} onCheckedChange={() => column.toggleVisibility()}>
25
25
  {column.id}
26
26
  </DropdownMenu.CheckboxItem>
@@ -1,12 +1,12 @@
1
- import type { ShadTable } from "./shad-table.svelte";
1
+ import type { Table } from "@tanstack/table-core";
2
2
  interface Props<T> {
3
- tableState: ShadTable<T>;
3
+ table: Table<T>;
4
4
  }
5
5
  declare class __sveltets_Render<T> {
6
6
  props(): Props<T>;
7
7
  events(): {};
8
8
  slots(): {};
9
- bindings(): "tableState";
9
+ bindings(): "table";
10
10
  exports(): {};
11
11
  }
12
12
  interface $$IsomorphicComponent {
@@ -1,2 +1,2 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
- export { createShadTable, ShadTable } from "./shad-table.svelte";
2
+ export { ShadTable } from "./shad-table.svelte";
@@ -1,2 +1,2 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
- export { createShadTable, ShadTable } from "./shad-table.svelte";
2
+ export { ShadTable } from "./shad-table.svelte";
@@ -13,5 +13,4 @@ export declare class ShadTable<TData extends RowData> {
13
13
  updateOptions(): void;
14
14
  features(): void;
15
15
  }
16
- export declare const createShadTable: <TData extends RowData>(options: ShadTableOptions<TData>) => Table<TData>;
17
16
  export {};
@@ -131,129 +131,6 @@ export class ShadTable {
131
131
  }
132
132
  }
133
133
  }
134
- export const createShadTable = (options) => {
135
- // Set the default getCoreRowModel
136
- if (!options.getCoreRowModel) {
137
- options.getCoreRowModel = getCoreRowModel();
138
- }
139
- const plainOptions = options;
140
- const resolvedOptions = mergeObjects({
141
- state: {},
142
- onStateChange() { },
143
- renderFallbackValue: null,
144
- mergeOptions: (defaultOptions, options) => {
145
- return mergeObjects(defaultOptions, options);
146
- },
147
- }, plainOptions);
148
- const table = createTable(resolvedOptions);
149
- let state = $state(table.initialState);
150
- function updateOptions() {
151
- table.setOptions((prev) => {
152
- return mergeObjects(prev, options, {
153
- state: mergeObjects(state, options.state || {}),
154
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
- onStateChange: (updater) => {
156
- if (updater instanceof Function)
157
- state = updater(state);
158
- else
159
- state = mergeObjects(state, updater);
160
- options.onStateChange?.(updater);
161
- },
162
- });
163
- });
164
- }
165
- // Sorting
166
- if ((options.enableSorting ?? true) && !options.getSortedRowModel) {
167
- options.getSortedRowModel = getSortedRowModel();
168
- options.onSortingChange = (updater) => {
169
- if (typeof updater === "function") {
170
- if (options.state?.sorting) {
171
- options.state.sorting = updater(options.state.sorting);
172
- }
173
- else if (state.sorting) {
174
- state.sorting = updater(state.sorting);
175
- }
176
- }
177
- else {
178
- if (options.state?.sorting) {
179
- options.state.sorting = updater;
180
- }
181
- else {
182
- state.sorting = updater;
183
- }
184
- }
185
- };
186
- }
187
- // Paging
188
- if ((options.enablePaging ?? true) && !options.getPaginationRowModel) {
189
- options.getPaginationRowModel = getPaginationRowModel();
190
- options.onPaginationChange = (updater) => {
191
- if (typeof updater === "function") {
192
- if (options.state?.pagination) {
193
- options.state.pagination = updater(options.state.pagination);
194
- }
195
- else if (state.pagination) {
196
- state.pagination = updater(state.pagination);
197
- }
198
- }
199
- else {
200
- if (options.state?.pagination) {
201
- options.state.pagination = updater;
202
- }
203
- else {
204
- state.pagination = updater;
205
- }
206
- }
207
- };
208
- }
209
- // Row Selection
210
- if ((options.enableRowSelection ?? true) && !options.onRowSelectionChange) {
211
- options.onRowSelectionChange = (updater) => {
212
- if (typeof updater === "function") {
213
- if (options.state?.rowSelection) {
214
- options.state.rowSelection = updater(options.state.rowSelection);
215
- }
216
- else if (state.rowSelection) {
217
- state.rowSelection = updater(state.rowSelection);
218
- }
219
- }
220
- else {
221
- if (options.state?.rowSelection) {
222
- options.state.rowSelection = updater;
223
- }
224
- else {
225
- state.rowSelection = updater;
226
- }
227
- }
228
- };
229
- }
230
- // Column Visibility
231
- if ((options.enableVisibility ?? false) && !options.onColumnVisibilityChange) {
232
- options.onColumnVisibilityChange = (updater) => {
233
- if (typeof updater === "function") {
234
- if (options.state?.columnVisibility) {
235
- options.state.columnVisibility = updater(options.state.columnVisibility);
236
- }
237
- else if (state.columnVisibility) {
238
- state.columnVisibility = updater(state.columnVisibility);
239
- }
240
- }
241
- else {
242
- if (options.state?.columnVisibility) {
243
- options.state.columnVisibility = updater;
244
- }
245
- else {
246
- state.columnVisibility = updater;
247
- }
248
- }
249
- };
250
- }
251
- updateOptions();
252
- $effect.pre(() => {
253
- updateOptions();
254
- });
255
- return table;
256
- };
257
134
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
258
135
  function mergeObjects(...sources) {
259
136
  const target = {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayord/ui",
3
3
  "private": false,
4
- "version": "0.15.6",
4
+ "version": "0.15.7",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",