@kayord/ui 1.1.1 → 1.1.3

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.
@@ -1,4 +1,8 @@
1
- export declare const sum: <T>(data: T[], columnId: keyof T) => number;
2
- export declare const min: <T>(data: T[], columnId: keyof T) => number | undefined;
3
- export declare const max: <T>(data: T[], columnId: keyof T) => number | undefined;
4
- export declare const uniqueCount: <T>(data: T[], columnId: keyof T) => number;
1
+ export declare const aggregationFns: {
2
+ sum: <T>(data: T[], columnId: keyof T) => number;
3
+ min: <T>(data: T[], columnId: keyof T) => number | undefined;
4
+ max: <T>(data: T[], columnId: keyof T) => number | undefined;
5
+ mean: <T>(data: T[], columnId: keyof T) => number | undefined;
6
+ uniqueCount: <T>(data: T[], columnId: keyof T) => number;
7
+ count: <T>(data: T[], columnId: keyof T) => number;
8
+ };
@@ -1,10 +1,10 @@
1
- export const sum = (data, columnId) => {
1
+ const sum = (data, columnId) => {
2
2
  return data.reduce((sum, next) => {
3
3
  const nextValue = next[columnId];
4
4
  return sum + (typeof nextValue === "number" ? nextValue : 0);
5
5
  }, 0);
6
6
  };
7
- export const min = (data, columnId) => {
7
+ const min = (data, columnId) => {
8
8
  let min;
9
9
  data.forEach((row) => {
10
10
  const value = Number(row[columnId]);
@@ -14,7 +14,7 @@ export const min = (data, columnId) => {
14
14
  });
15
15
  return min;
16
16
  };
17
- export const max = (data, columnId) => {
17
+ const max = (data, columnId) => {
18
18
  let max;
19
19
  data.forEach((row) => {
20
20
  const value = Number(row[columnId]);
@@ -24,6 +24,30 @@ export const max = (data, columnId) => {
24
24
  });
25
25
  return max;
26
26
  };
27
- export const uniqueCount = (data, columnId) => {
27
+ const uniqueCount = (data, columnId) => {
28
28
  return new Set(data.map((d) => d[columnId])).size;
29
29
  };
30
+ const count = (data, columnId) => {
31
+ return data.length;
32
+ };
33
+ const mean = (data, columnId) => {
34
+ let count = 0;
35
+ let sum = 0;
36
+ data.forEach((row) => {
37
+ let value = Number(row[columnId]);
38
+ if (value != null && (value = +value) >= value) {
39
+ (++count, (sum += value));
40
+ }
41
+ });
42
+ if (count)
43
+ return sum / count;
44
+ return;
45
+ };
46
+ export const aggregationFns = {
47
+ sum,
48
+ min,
49
+ max,
50
+ mean,
51
+ uniqueCount,
52
+ count,
53
+ };
@@ -1,5 +1,5 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
2
  export { createShadTable } from "./shad-table.svelte";
3
- export { max, min, sum, uniqueCount } from "./data-table-utils";
3
+ export { aggregationFns } from "./data-table-utils";
4
4
  export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, decodeTableState, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
5
5
  export type { CustomColumnMeta, CustomOptions } from "./types";
@@ -1,4 +1,4 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
2
  export { createShadTable } from "./shad-table.svelte";
3
- export { max, min, sum, uniqueCount } from "./data-table-utils";
3
+ export { aggregationFns } from "./data-table-utils";
4
4
  export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, decodeTableState, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
@@ -19,7 +19,7 @@
19
19
  data-slot="dropdown-menu-content"
20
20
  {sideOffset}
21
21
  class={cn(
22
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md outline-none",
22
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--bits-dropdown-menu-content-available-height) min-w-[8rem] origin-(--bits-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md outline-none",
23
23
  className
24
24
  )}
25
25
  {...restProps}
@@ -9,7 +9,7 @@
9
9
  bind:ref
10
10
  data-slot="dropdown-menu-sub-content"
11
11
  class={cn(
12
- "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
12
+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--bits-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
13
13
  className
14
14
  )}
15
15
  {...restProps}
@@ -0,0 +1,2 @@
1
+ export { UseClipboard } from "./use-clipboard.svelte";
2
+ export { useMedia } from "./use-media.svelte";
@@ -0,0 +1,2 @@
1
+ export { UseClipboard } from "./use-clipboard.svelte";
2
+ export { useMedia } from "./use-media.svelte";
@@ -0,0 +1,10 @@
1
+ export type Breakpoints<K extends string> = Record<K, string>;
2
+ /** Based on the default Tailwind CSS breakpoints https://tailwindcss.com/docs/responsive-design.
3
+ * A breakpoint is `true` when the width of the screen is greater than or equal to the breakpoint. */
4
+ export declare const TAILWIND_BREAKPOINTS: Breakpoints<"sm" | "md" | "lg" | "xl" | "2xl">;
5
+ /** Dynamically creates media queries for the provided breakpoints allowing you to access them as `media.<name>`.
6
+ *
7
+ * @param breakpoints
8
+ * @returns
9
+ */
10
+ export declare function useMedia<K extends string = keyof typeof TAILWIND_BREAKPOINTS>(breakpoints?: Breakpoints<K>): Record<K, boolean>;
@@ -0,0 +1,25 @@
1
+ import { MediaQuery } from "svelte/reactivity";
2
+ /** Based on the default Tailwind CSS breakpoints https://tailwindcss.com/docs/responsive-design.
3
+ * A breakpoint is `true` when the width of the screen is greater than or equal to the breakpoint. */
4
+ export const TAILWIND_BREAKPOINTS = {
5
+ sm: "40rem",
6
+ md: "48rem",
7
+ lg: "64rem",
8
+ xl: "80rem",
9
+ "2xl": "96rem",
10
+ };
11
+ /** Dynamically creates media queries for the provided breakpoints allowing you to access them as `media.<name>`.
12
+ *
13
+ * @param breakpoints
14
+ * @returns
15
+ */
16
+ export function useMedia(breakpoints = TAILWIND_BREAKPOINTS) {
17
+ const queries = {};
18
+ for (const [name, size] of Object.entries(breakpoints)) {
19
+ const query = new MediaQuery(`min-width: ${size}`);
20
+ Object.defineProperty(queries, name, {
21
+ get: () => query.current,
22
+ });
23
+ }
24
+ return queries;
25
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./components/ui/index.js";
2
2
  export * from "./components/custom/index.js";
3
+ export * from "./hooks/index.js";
package/dist/index.js CHANGED
@@ -2,3 +2,5 @@
2
2
  export * from "./components/ui/index.js";
3
3
  // Custom components
4
4
  export * from "./components/custom/index.js";
5
+ // Hooks
6
+ export * from "./hooks/index.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayord/ui",
3
3
  "private": false,
4
- "version": "1.1.1",
4
+ "version": "1.1.3",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -58,12 +58,12 @@
58
58
  "@testing-library/user-event": "^14.6.1",
59
59
  "@types/d3-scale": "^4.0.9",
60
60
  "@types/d3-shape": "^3.1.7",
61
- "@typescript-eslint/eslint-plugin": "^8.37.0",
62
- "@typescript-eslint/parser": "^8.37.0",
61
+ "@typescript-eslint/eslint-plugin": "^8.38.0",
62
+ "@typescript-eslint/parser": "^8.38.0",
63
63
  "d3-scale": "^4.0.2",
64
64
  "d3-shape": "^3.2.0",
65
65
  "eslint": "^9.31.0",
66
- "eslint-config-prettier": "^10.1.5",
66
+ "eslint-config-prettier": "^10.1.8",
67
67
  "eslint-plugin-svelte": "^3.11.0",
68
68
  "happy-dom": "^18.0.1",
69
69
  "layerchart": "2.0.0-next.30",
@@ -71,7 +71,7 @@
71
71
  "prettier-plugin-svelte": "^3.4.0",
72
72
  "prettier-plugin-tailwindcss": "^0.6.14",
73
73
  "publint": "^0.3.12",
74
- "svelte": "5.36.7",
74
+ "svelte": "5.36.13",
75
75
  "svelte-check": "^4.3.0",
76
76
  "sveltekit-superforms": "^2.27.1",
77
77
  "tailwindcss": "^4.1.11",