sveltacular 0.0.69 → 0.0.70

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.
@@ -28,12 +28,16 @@ const getColType = (col) => {
28
28
  return col.type;
29
29
  if (!rows?.length)
30
30
  return "string";
31
- return typeof rows[0][col.key];
31
+ const firstRow = rows[0];
32
+ if (!firstRow)
33
+ return "undefined";
34
+ if (col.key in firstRow)
35
+ return typeof firstRow[col.key];
32
36
  };
33
37
  const format = (row, key) => {
34
38
  const col = cols.find((col2) => col2.key === key);
35
39
  if (!col)
36
- return row[key];
40
+ return key in row ? String(row[key]) : "";
37
41
  if ((row[key] === null || row[key] === void 0) && col.nullText)
38
42
  return col.nullText;
39
43
  if (String(row[key]).trim() === "" && col.emptyText)
@@ -44,7 +48,7 @@ const format = (row, key) => {
44
48
  return formatDateTime(String(row[key])).substring(0, 10);
45
49
  if (col.type === "date-time")
46
50
  return formatDateTime(String(row[key]));
47
- return row[key];
51
+ return String(row[key]);
48
52
  };
49
53
  const calculateTotalPages = () => {
50
54
  if (!pagination || !rows)
@@ -1,19 +1,19 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { DataCol, DataRow, PaginationProperties } from '../types/data.js';
2
+ import type { DataCol, JsonObject, PaginationProperties } from '../types/data.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  captionSide?: "top" | "bottom" | undefined;
6
6
  captionAlign?: "center" | "left" | "right" | undefined;
7
- rows?: DataRow[] | undefined;
7
+ rows?: JsonObject[] | undefined;
8
8
  cols: DataCol[];
9
9
  pagination?: PaginationProperties | undefined;
10
10
  actions?: {
11
11
  text: string;
12
- onClick: (row: DataRow) => unknown;
12
+ onClick: (row: JsonObject) => unknown;
13
13
  }[] | undefined;
14
14
  /**
15
15
  * Handle page change, which should return the new filtered/fetched rows.
16
- */ onPageChange?: ((pagination: PaginationProperties) => Promise<DataRow[]>) | null | undefined;
16
+ */ onPageChange?: ((pagination: PaginationProperties) => Promise<JsonObject[]>) | null | undefined;
17
17
  };
18
18
  events: {
19
19
  [evt: string]: CustomEvent<any>;
@@ -1,12 +1,17 @@
1
- export type DataRow = Record<string, unknown>;
2
- export type DataCol<T extends DataRow = DataRow> = {
1
+ export type JsonValue = string | number | boolean | null | {
2
+ [key: string]: JsonValue;
3
+ } | JsonValue[];
4
+ export type JsonObject = {
5
+ [key: string]: JsonValue;
6
+ };
7
+ export type DataCol = {
3
8
  key: string;
4
9
  label: string;
5
10
  type?: string;
6
11
  nullText?: string;
7
12
  emptyText?: string;
8
- format?: (row: T, key: keyof T) => string;
9
- link?: (row: T, key: keyof T) => string;
13
+ format?: (row: JsonObject, key: string) => string;
14
+ link?: (row: JsonObject, key: string) => string;
10
15
  hide?: boolean;
11
16
  width?: number | string;
12
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveltacular",
3
- "version": "0.0.69",
3
+ "version": "0.0.70",
4
4
  "description": "A Svelte component library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",