@kayord/ui 1.0.9 → 1.0.11

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.
@@ -36,7 +36,6 @@
36
36
  class?: string;
37
37
  headerClass?: string;
38
38
  disableUISorting?: boolean;
39
- useQueryParamState?: boolean;
40
39
  }
41
40
 
42
41
  let {
@@ -54,31 +53,11 @@
54
53
  class: className,
55
54
  headerClass,
56
55
  disableUISorting = false,
57
- useQueryParamState = false,
58
56
  }: Props<T> = $props();
59
57
 
60
58
  const tableStore = new TableStore();
61
59
  const isPaginationEnabled = table.options.getPaginationRowModel !== undefined;
62
60
  let end: HTMLElement | undefined = $state();
63
-
64
- $effect(() => {
65
- if (useQueryParamState) {
66
- const params = encodeTableState(table.getState());
67
- goto(params, {
68
- replaceState: true,
69
- keepFocus: true,
70
- noScroll: true,
71
- });
72
- }
73
- });
74
- onMount(() => {
75
- if (useQueryParamState) {
76
- table.setColumnFilters(decodeColumnFilters());
77
- table.setGlobalFilter(decodeGlobalFilter());
78
- table.setSorting(decodeSorting());
79
- table.setPageIndex(decodePageIndex());
80
- }
81
- });
82
61
  </script>
83
62
 
84
63
  <div
@@ -15,7 +15,6 @@ interface Props<T> {
15
15
  class?: string;
16
16
  headerClass?: string;
17
17
  disableUISorting?: boolean;
18
- useQueryParamState?: boolean;
19
18
  }
20
19
  declare class __sveltets_Render<T> {
21
20
  props(): Props<T>;
@@ -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";
@@ -1,9 +1,9 @@
1
- import { type RowData, type RowModel, type Table, type TableOptions, type TableState } from "@tanstack/table-core";
1
+ import { type RowData, type RowModel, type Table, type TableOptions } from "@tanstack/table-core";
2
2
  interface ShadTableOptions<TData extends RowData> extends Omit<TableOptions<TData>, "getCoreRowModel"> {
3
3
  getCoreRowModel?: (table: Table<any>) => () => RowModel<any>;
4
4
  enablePaging?: boolean;
5
5
  enableVisibility?: boolean;
6
6
  enableRowSelectionUI?: boolean;
7
7
  }
8
- export declare function createShadTable<TData extends RowData>(shadOptions: ShadTableOptions<TData>, stateUpdate?: (state: Partial<TableState>) => void): Table<TData>;
8
+ export declare function createShadTable<TData extends RowData>(shadOptions: ShadTableOptions<TData>): Table<TData>;
9
9
  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, stateUpdate) {
5
+ export function createShadTable(shadOptions) {
6
6
  if (!shadOptions.getCoreRowModel) {
7
7
  shadOptions.getCoreRowModel = getCoreRowModel();
8
8
  }
@@ -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 encodeTableState: (state: TableState, options?: Options, searchParams?: URLSearchParams) => string;
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() ?? undefined;
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.pageIndex != 0) {
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()}`;
@@ -2,11 +2,17 @@
2
2
  import { Avatar as AvatarPrimitive } from "bits-ui";
3
3
  import { cn } from "../../../utils.js";
4
4
 
5
- let { ref = $bindable(null), class: className, ...restProps }: AvatarPrimitive.RootProps = $props();
5
+ let {
6
+ ref = $bindable(null),
7
+ loadingStatus = $bindable("loading"),
8
+ class: className,
9
+ ...restProps
10
+ }: AvatarPrimitive.RootProps = $props();
6
11
  </script>
7
12
 
8
13
  <AvatarPrimitive.Root
9
14
  bind:ref
15
+ bind:loadingStatus
10
16
  data-slot="avatar"
11
17
  class={cn("relative flex size-8 shrink-0 overflow-hidden rounded-full", className)}
12
18
  {...restProps}
@@ -1,4 +1,4 @@
1
1
  import { Avatar as AvatarPrimitive } from "bits-ui";
2
- declare const Avatar: import("svelte").Component<AvatarPrimitive.RootProps, {}, "ref">;
2
+ declare const Avatar: import("svelte").Component<AvatarPrimitive.RootProps, {}, "ref" | "loadingStatus">;
3
3
  type Avatar = ReturnType<typeof Avatar>;
4
4
  export default Avatar;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayord/ui",
3
3
  "private": false,
4
- "version": "1.0.9",
4
+ "version": "1.0.11",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -49,8 +49,8 @@
49
49
  "devDependencies": {
50
50
  "@lucide/svelte": "^0.523.0",
51
51
  "@sveltejs/adapter-auto": "^6.0.1",
52
- "@sveltejs/kit": "^2.22.0",
53
- "@sveltejs/package": "^2.3.11",
52
+ "@sveltejs/kit": "^2.22.1",
53
+ "@sveltejs/package": "^2.3.12",
54
54
  "@sveltejs/vite-plugin-svelte": "^5.1.0",
55
55
  "@tailwindcss/vite": "^4.1.10",
56
56
  "@testing-library/jest-dom": "^6.6.3",