@kayord/ui 1.0.8 → 1.0.10
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.
- package/dist/components/custom/data-table/index.d.ts +1 -1
- package/dist/components/custom/data-table/index.js +1 -1
- package/dist/components/custom/data-table/shad-table.svelte.d.ts +2 -1
- package/dist/components/custom/data-table/shad-table.svelte.js +8 -4
- package/dist/components/custom/data-table/table-search-params.d.ts +6 -5
- package/dist/components/custom/data-table/table-search-params.js +17 -6
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as DataTable } from "./DataTable.svelte";
|
|
2
2
|
export { createShadTable } from "./shad-table.svelte";
|
|
3
3
|
export { max, min, sum, uniqueCount } from "./data-table-utils";
|
|
4
|
-
export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
|
|
4
|
+
export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, decodeTableState, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as DataTable } from "./DataTable.svelte";
|
|
2
2
|
export { createShadTable } from "./shad-table.svelte";
|
|
3
3
|
export { max, min, sum, uniqueCount } from "./data-table-utils";
|
|
4
|
-
export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
|
|
4
|
+
export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, decodeTableState, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
|
|
@@ -4,6 +4,7 @@ interface ShadTableOptions<TData extends RowData> extends Omit<TableOptions<TDat
|
|
|
4
4
|
enablePaging?: boolean;
|
|
5
5
|
enableVisibility?: boolean;
|
|
6
6
|
enableRowSelectionUI?: boolean;
|
|
7
|
+
defaultState?: Partial<TableState>;
|
|
7
8
|
}
|
|
8
|
-
export declare function createShadTable<TData extends RowData>(shadOptions: ShadTableOptions<TData
|
|
9
|
+
export declare function createShadTable<TData extends RowData>(shadOptions: ShadTableOptions<TData>): Table<TData>;
|
|
9
10
|
export {};
|
|
@@ -2,7 +2,7 @@ import { createTable, getCoreRowModel, getFilteredRowModel, getPaginationRowMode
|
|
|
2
2
|
import DataTableCheckbox from "./DataTableCheckbox.svelte";
|
|
3
3
|
import { renderComponent } from "../../ui";
|
|
4
4
|
import { mergeObjects } from "../../ui/data-table/data-table.svelte";
|
|
5
|
-
export function createShadTable(shadOptions
|
|
5
|
+
export function createShadTable(shadOptions) {
|
|
6
6
|
if (!shadOptions.getCoreRowModel) {
|
|
7
7
|
shadOptions.getCoreRowModel = getCoreRowModel();
|
|
8
8
|
}
|
|
@@ -176,6 +176,10 @@ export function createShadTable(shadOptions, stateUpdate) {
|
|
|
176
176
|
}, options);
|
|
177
177
|
const table = createTable(resolvedOptions);
|
|
178
178
|
let state = $state(table.initialState);
|
|
179
|
+
// DefaultState
|
|
180
|
+
if (shadOptions.defaultState) {
|
|
181
|
+
state = { ...state, ...shadOptions.defaultState };
|
|
182
|
+
}
|
|
179
183
|
const updateOptions = (table, state) => {
|
|
180
184
|
table.setOptions((prev) => {
|
|
181
185
|
return mergeObjects(prev, options, {
|
|
@@ -192,8 +196,8 @@ export function createShadTable(shadOptions, stateUpdate) {
|
|
|
192
196
|
});
|
|
193
197
|
};
|
|
194
198
|
updateOptions(table, state);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
199
|
+
$effect.pre(() => {
|
|
200
|
+
updateOptions(table, state);
|
|
201
|
+
});
|
|
198
202
|
return table;
|
|
199
203
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { TableState } from "@tanstack/table-core";
|
|
2
|
-
export declare const encodeSorting: (state: TableState) => string;
|
|
2
|
+
export declare const encodeSorting: (state: Partial<TableState>) => string;
|
|
3
3
|
export declare const decodeSorting: () => {
|
|
4
4
|
id: string;
|
|
5
5
|
desc: boolean;
|
|
6
6
|
}[];
|
|
7
|
-
export declare const encodeGlobalFilter: (state: TableState) => any;
|
|
7
|
+
export declare const encodeGlobalFilter: (state: Partial<TableState>) => any;
|
|
8
8
|
export declare const decodeGlobalFilter: () => string;
|
|
9
|
-
export declare const encodePageIndex: (state: TableState) => string;
|
|
9
|
+
export declare const encodePageIndex: (state: Partial<TableState>) => string;
|
|
10
10
|
export declare const decodePageIndex: () => number;
|
|
11
|
-
export declare const encodeColumnFilters: (state: TableState) => string;
|
|
11
|
+
export declare const encodeColumnFilters: (state: Partial<TableState>) => string;
|
|
12
12
|
export declare const decodeColumnFilters: () => {
|
|
13
13
|
id: string;
|
|
14
14
|
value: any;
|
|
@@ -19,5 +19,6 @@ interface Options {
|
|
|
19
19
|
pagination?: boolean;
|
|
20
20
|
columnFilter?: boolean;
|
|
21
21
|
}
|
|
22
|
-
export declare const
|
|
22
|
+
export declare const decodeTableState: () => Partial<TableState>;
|
|
23
|
+
export declare const encodeTableState: (state: Partial<TableState>, options?: Options, searchParams?: URLSearchParams) => string;
|
|
23
24
|
export {};
|
|
@@ -21,15 +21,15 @@ export const decodeGlobalFilter = () => {
|
|
|
21
21
|
return page.url.searchParams.get("globalFilter") ?? "";
|
|
22
22
|
};
|
|
23
23
|
export const encodePageIndex = (state) => {
|
|
24
|
-
return state.pagination?.pageIndex?.toString() ??
|
|
24
|
+
return state.pagination?.pageIndex?.toString() ?? "";
|
|
25
25
|
};
|
|
26
26
|
export const decodePageIndex = () => {
|
|
27
27
|
return Number(page.url.searchParams.get("page") ?? "0");
|
|
28
28
|
};
|
|
29
29
|
export const encodeColumnFilters = (state) => {
|
|
30
|
-
return state.columnFilters
|
|
30
|
+
return (state.columnFilters
|
|
31
31
|
?.map(({ id, value }) => `${id}.${encodeURIComponent(JSON.stringify(value).replaceAll(".", "%2E"))}`)
|
|
32
|
-
.join(",");
|
|
32
|
+
.join(",") ?? "");
|
|
33
33
|
};
|
|
34
34
|
export const decodeColumnFilters = () => {
|
|
35
35
|
return (page.url.searchParams
|
|
@@ -48,6 +48,17 @@ export const decodeColumnFilters = () => {
|
|
|
48
48
|
})
|
|
49
49
|
.filter((x) => x !== null) ?? []);
|
|
50
50
|
};
|
|
51
|
+
export const decodeTableState = () => {
|
|
52
|
+
return {
|
|
53
|
+
pagination: {
|
|
54
|
+
pageIndex: decodePageIndex(),
|
|
55
|
+
pageSize: 10,
|
|
56
|
+
},
|
|
57
|
+
sorting: decodeSorting(),
|
|
58
|
+
columnFilters: decodeColumnFilters(),
|
|
59
|
+
globalFilter: decodeGlobalFilter(),
|
|
60
|
+
};
|
|
61
|
+
};
|
|
51
62
|
export const encodeTableState = (state, options, searchParams) => {
|
|
52
63
|
if (searchParams === undefined) {
|
|
53
64
|
searchParams = new URLSearchParams();
|
|
@@ -59,16 +70,16 @@ export const encodeTableState = (state, options, searchParams) => {
|
|
|
59
70
|
options.globalFilter = options.globalFilter ?? true;
|
|
60
71
|
options.sorting = options.sorting ?? true;
|
|
61
72
|
options.columnFilter = options.columnFilter ?? true;
|
|
62
|
-
if (options.pagination && state.pagination
|
|
73
|
+
if (options.pagination && state.pagination?.pageIndex != 0) {
|
|
63
74
|
searchParams.set("page", encodePageIndex(state));
|
|
64
75
|
}
|
|
65
76
|
if (options.globalFilter && state.globalFilter?.length > 0) {
|
|
66
77
|
searchParams.set("globalFilter", encodeGlobalFilter(state));
|
|
67
78
|
}
|
|
68
|
-
if (options.sorting && state.sorting?.length > 0) {
|
|
79
|
+
if (options.sorting && (state.sorting?.length ?? 0) > 0) {
|
|
69
80
|
searchParams.set("sort", encodeSorting(state));
|
|
70
81
|
}
|
|
71
|
-
if (options.columnFilter && state.columnFilters?.length > 0) {
|
|
82
|
+
if (options.columnFilter && (state.columnFilters?.length ?? 0) > 0) {
|
|
72
83
|
searchParams.set("columnFilters", encodeColumnFilters(state));
|
|
73
84
|
}
|
|
74
85
|
return `?${searchParams.toString()}`;
|