@emamid/svelte-data-table 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -1,58 +0,0 @@
1
- # create-svelte
2
-
3
- Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
4
-
5
- Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
6
-
7
- ## Creating a project
8
-
9
- If you're seeing this, you've probably already done this step. Congrats!
10
-
11
- ```bash
12
- # create a new project in the current directory
13
- npm create svelte@latest
14
-
15
- # create a new project in my-app
16
- npm create svelte@latest my-app
17
- ```
18
-
19
- ## Developing
20
-
21
- Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
22
-
23
- ```bash
24
- npm run dev
25
-
26
- # or start the server and open the app in a new browser tab
27
- npm run dev -- --open
28
- ```
29
-
30
- Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
31
-
32
- ## Building
33
-
34
- To build your library:
35
-
36
- ```bash
37
- npm run package
38
- ```
39
-
40
- To create a production version of your showcase app:
41
-
42
- ```bash
43
- npm run build
44
- ```
45
-
46
- You can preview the production build with `npm run preview`.
47
-
48
- > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
49
-
50
- ## Publishing
51
-
52
- Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
53
-
54
- To publish your library to [npm](https://www.npmjs.com):
55
-
56
- ```bash
57
- npm publish
58
- ```
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The DataTable component based on {@link https://flowbite-svelte.com/docs/components/table}
3
+ * @typedef {object} DataTable
4
+ * @property {ColumnConfig[]} columns - Configuration for each column to be displayed in the table.
5
+ * @property {any[]} items - Data for the rows in the table.
6
+ * @property {string} [sortKey] - Data property to sort by.
7
+ * @property {SortFunction} [sortFunction] - Function for more complex-sorting.
8
+ * @property {boolean} [reverseSort] - True when sorting is reversed.
9
+ * @property {string} [sortColumnID] - The id (or key) property of the column being sorted by.
10
+ * @property {string} [itemKey] - Property to use when distinguish between rows. If not populated, the array index is used.
11
+ * @property {EnterAction} [enterAction] - Determines what pressing the enter key in a focused cell does. Can be 'next', 'down', or 'stay'. Default is 'next'. If 'next', enter will act the same as tab. If 'down', focus will move down to the row below the current one. If 'stay', the enter key will not cause movement.
12
+ * @property {string} [divClassAppend] - Classes to be appended to Table.divClass .
13
+ * @property {string} [divClassOverride] - Classes to replace Table.divClass with.
14
+ * @property {string} [tableClassAppend] - Classes to be appended to Table.class .
15
+ * @property {string} [tableClassOverride] - Classes to replace Table.class with.
16
+ * @property {string} [theadClassAppend] - Classes to be appended to TableHead.theadClass .
17
+ * @property {string} [theadClassOverride] - Classes to replace TableHead.theadClass with.
18
+ * @property {string} [thClassAppend] - Classes to be appended to TableHeadCell.class .
19
+ * @property {string} [thClassOverride] - Classes to replace TableHeadCell.class with.
20
+ * @property {string} [tableBodyClassAppend] - Classes to be appended to TableBody.tableBodyClass .
21
+ * @property {string} [tableBodyClassOverride] - Classes to replace TableBody.tableBodyClass with.
22
+ * @property {string} [tdClassAppend] - Classes to be appended to TableBodyCell.tdClass . Column configs can further modify this.
23
+ * @property {string} [tdClassOverride] - Classes to replace TableBodyCell.tdClass with. Column configs can further modify this.
24
+ * @property {string} [tdFocusedClassAppend] - Classes to be appended to TableBodyCell.tdClass when a cell is focused. Column configs can further modify this.
25
+ * @property {string} [tdFocusedClassOverride] - Classes to replace TableBodyCell.tdClass with with a cell is focused. Column configs can further modify this.
26
+ * @property {string} [trClassAppend] - Classes to be appended to TableBodyRow.class . trClassGetter can further modify this.
27
+ * @property {string} [trClassOverride] - Classes to replace TableBodyRow.class with. trClassGetter can further modify this.
28
+ * @property {RowClassFunction} [trClassGetter] - Calculates the CSS classes for a TableBodyRow .
29
+ * @fires action
30
+ * @fires cellChanged
31
+ * @fires cellClicked
32
+ * @fires headerClicked
33
+ * @fires rowClicked
34
+ */
35
+ export {};
36
+ /**
37
+ * @event cellClicked
38
+ * @type {object}
39
+ * @property {any} detail.item - Data for the cell's row.
40
+ * @property {ColumnConfig} detail.column - Configuration for the cell's column.
41
+ */
42
+ /**
43
+ * @event headerClicked
44
+ * @type {object}
45
+ * @property {ColumnConfig} detail.column - Configuration for the header's column.
46
+ * @property {string} detail.sortColumnID - The current sortColumnID.
47
+ * @property {string} detail.sortKey - The current sortKey.
48
+ * @property {SortFunction} detail.sortFunction The current sortFunction.
49
+ * @property {boolean} detail.reverseSort - True if the grid is currently sorting in reverse.
50
+ */
51
+ /**
52
+ * @event rowClicked
53
+ * @type {object}
54
+ * @property {any} detail.item - Data for the row.
55
+ */
56
+ /**
57
+ * @event action
58
+ * @type {object}
59
+ * @property {string} detail.action - The name property of the action whose button was clicked.
60
+ * @property {any} detail.item - Data for the action cell's row.
61
+ * @property {ColumnConfig} detail.column - Configuration for the action cell's column.
62
+ */
63
+ /**
64
+ * @event cellChanged
65
+ * @type {object}
66
+ * @property {any} detail.item - Data for the cell's row, prior to the change.
67
+ * @property {ColumnConfig} detail.column - Configuration for the cell's column.
68
+ * @property {any} detail.oldValue - The data value of the cell before the change.
69
+ * @property {any} detail.newValue - The new value that needs to be applied to the cell.
70
+ */
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * The DataTable component based on {@link https://flowbite-svelte.com/docs/components/table}
4
+ * @typedef {object} DataTable
5
+ * @property {ColumnConfig[]} columns - Configuration for each column to be displayed in the table.
6
+ * @property {any[]} items - Data for the rows in the table.
7
+ * @property {string} [sortKey] - Data property to sort by.
8
+ * @property {SortFunction} [sortFunction] - Function for more complex-sorting.
9
+ * @property {boolean} [reverseSort] - True when sorting is reversed.
10
+ * @property {string} [sortColumnID] - The id (or key) property of the column being sorted by.
11
+ * @property {string} [itemKey] - Property to use when distinguish between rows. If not populated, the array index is used.
12
+ * @property {EnterAction} [enterAction] - Determines what pressing the enter key in a focused cell does. Can be 'next', 'down', or 'stay'. Default is 'next'. If 'next', enter will act the same as tab. If 'down', focus will move down to the row below the current one. If 'stay', the enter key will not cause movement.
13
+ * @property {string} [divClassAppend] - Classes to be appended to Table.divClass .
14
+ * @property {string} [divClassOverride] - Classes to replace Table.divClass with.
15
+ * @property {string} [tableClassAppend] - Classes to be appended to Table.class .
16
+ * @property {string} [tableClassOverride] - Classes to replace Table.class with.
17
+ * @property {string} [theadClassAppend] - Classes to be appended to TableHead.theadClass .
18
+ * @property {string} [theadClassOverride] - Classes to replace TableHead.theadClass with.
19
+ * @property {string} [thClassAppend] - Classes to be appended to TableHeadCell.class .
20
+ * @property {string} [thClassOverride] - Classes to replace TableHeadCell.class with.
21
+ * @property {string} [tableBodyClassAppend] - Classes to be appended to TableBody.tableBodyClass .
22
+ * @property {string} [tableBodyClassOverride] - Classes to replace TableBody.tableBodyClass with.
23
+ * @property {string} [tdClassAppend] - Classes to be appended to TableBodyCell.tdClass . Column configs can further modify this.
24
+ * @property {string} [tdClassOverride] - Classes to replace TableBodyCell.tdClass with. Column configs can further modify this.
25
+ * @property {string} [tdFocusedClassAppend] - Classes to be appended to TableBodyCell.tdClass when a cell is focused. Column configs can further modify this.
26
+ * @property {string} [tdFocusedClassOverride] - Classes to replace TableBodyCell.tdClass with with a cell is focused. Column configs can further modify this.
27
+ * @property {string} [trClassAppend] - Classes to be appended to TableBodyRow.class . trClassGetter can further modify this.
28
+ * @property {string} [trClassOverride] - Classes to replace TableBodyRow.class with. trClassGetter can further modify this.
29
+ * @property {RowClassFunction} [trClassGetter] - Calculates the CSS classes for a TableBodyRow .
30
+ * @fires action
31
+ * @fires cellChanged
32
+ * @fires cellClicked
33
+ * @fires headerClicked
34
+ * @fires rowClicked
35
+ */
36
+ /**
37
+ * @event cellClicked
38
+ * @type {object}
39
+ * @property {any} detail.item - Data for the cell's row.
40
+ * @property {ColumnConfig} detail.column - Configuration for the cell's column.
41
+ */
42
+ /**
43
+ * @event headerClicked
44
+ * @type {object}
45
+ * @property {ColumnConfig} detail.column - Configuration for the header's column.
46
+ * @property {string} detail.sortColumnID - The current sortColumnID.
47
+ * @property {string} detail.sortKey - The current sortKey.
48
+ * @property {SortFunction} detail.sortFunction The current sortFunction.
49
+ * @property {boolean} detail.reverseSort - True if the grid is currently sorting in reverse.
50
+ */
51
+ /**
52
+ * @event rowClicked
53
+ * @type {object}
54
+ * @property {any} detail.item - Data for the row.
55
+ */
56
+ /**
57
+ * @event action
58
+ * @type {object}
59
+ * @property {string} detail.action - The name property of the action whose button was clicked.
60
+ * @property {any} detail.item - Data for the action cell's row.
61
+ * @property {ColumnConfig} detail.column - Configuration for the action cell's column.
62
+ */
63
+ /**
64
+ * @event cellChanged
65
+ * @type {object}
66
+ * @property {any} detail.item - Data for the cell's row, prior to the change.
67
+ * @property {ColumnConfig} detail.column - Configuration for the cell's column.
68
+ * @property {any} detail.oldValue - The data value of the cell before the change.
69
+ * @property {any} detail.newValue - The new value that needs to be applied to the cell.
70
+ */
@@ -42,7 +42,7 @@ let focusedItemKey = null;
42
42
  const sortBySortKey = (a, b) => {
43
43
  const aValue = a[sortKey];
44
44
  const bValue = b[sortKey];
45
- if (typeof aValue === "string") {
45
+ if (typeof aValue === "string" && typeof bValue === "string") {
46
46
  return aValue.localeCompare(bValue);
47
47
  }
48
48
  if (isFinite(aValue) && isFinite(bValue)) {
@@ -216,7 +216,6 @@ const rowClicked = (item) => {
216
216
  on:nextTab={nextTab}
217
217
  on:action
218
218
  on:cellChanged
219
- on:cellInput
220
219
  />
221
220
  {/each}
222
221
  </TableBodyRow>
@@ -31,7 +31,6 @@ declare const __propDef: {
31
31
  events: {
32
32
  action: any;
33
33
  cellChanged: any;
34
- cellInput: any;
35
34
  cellClicked: CustomEvent<any>;
36
35
  headerClicked: CustomEvent<any>;
37
36
  rowClicked: CustomEvent<any>;
@@ -17,7 +17,6 @@ export let isCellFocused;
17
17
  value={dataValue}
18
18
  on:action
19
19
  on:cellChanged
20
- on:cellInput
21
20
  on:click
22
21
  on:enterPressed
23
22
  on:prevTab
@@ -32,7 +31,6 @@ export let isCellFocused;
32
31
  value={dataValue}
33
32
  on:action
34
33
  on:cellChanged
35
- on:cellInput
36
34
  on:click
37
35
  on:enterPressed
38
36
  on:prevTab
@@ -10,7 +10,6 @@ declare const __propDef: {
10
10
  click: any;
11
11
  action: any;
12
12
  cellChanged: any;
13
- cellInput: any;
14
13
  enterPressed: any;
15
14
  prevTab: any;
16
15
  nextTab: any;
@@ -1,11 +1,71 @@
1
1
  import type { Action } from './ActionsCell.svelte';
2
+ /**
3
+ * @constant bookmarkAction
4
+ * @type {Action}
5
+ * @property {string} name - bookmark
6
+ * @property {ConstructorOfATypedSvelteComponent} icon - BookmarkOutline
7
+ */
2
8
  export declare const bookmarkAction: Action;
9
+ /**
10
+ * @constant deleteAction
11
+ * @type {Action}
12
+ * @property {string} name - delete
13
+ * @property {ConstructorOfATypedSvelteComponent} icon - TrashBinOutline
14
+ */
3
15
  export declare const deleteAction: Action;
16
+ /**
17
+ * @constant downAction
18
+ * @type {Action}
19
+ * @property {string} name - down
20
+ * @property {ConstructorOfATypedSvelteComponent} icon - ArrowDownSolid
21
+ */
4
22
  export declare const downAction: Action;
23
+ /**
24
+ * @constant editAction
25
+ * @type {Action}
26
+ * @property {string} name - edit
27
+ * @property {ConstructorOfATypedSvelteComponent} icon - EditOutline
28
+ */
5
29
  export declare const editAction: Action;
30
+ /**
31
+ * @constant favoriteAction
32
+ * @type {Action}
33
+ * @property {string} name - favorite
34
+ * @property {ConstructorOfATypedSvelteComponent} icon - HeartSolid
35
+ */
6
36
  export declare const favoriteAction: Action;
37
+ /**
38
+ * @constant infoAction
39
+ * @type {Action}
40
+ * @property {string} name - info
41
+ * @property {ConstructorOfATypedSvelteComponent} icon - InfoCircleOutline
42
+ */
7
43
  export declare const infoAction: Action;
44
+ /**
45
+ * @constant notificationAction
46
+ * @type {Action}
47
+ * @property {string} name - notification
48
+ * @property {ConstructorOfATypedSvelteComponent} icon - BellActiveOutline
49
+ */
8
50
  export declare const notificationAction: Action;
51
+ /**
52
+ * @constant settingsAction
53
+ * @type {Action}
54
+ * @property {string} name - settings
55
+ * @property {ConstructorOfATypedSvelteComponent} icon - CogOutline
56
+ */
9
57
  export declare const settingsAction: Action;
58
+ /**
59
+ * @constant shareAction
60
+ * @type {Action}
61
+ * @property {string} name - share
62
+ * @property {ConstructorOfATypedSvelteComponent} icon - ShareNodesOutline
63
+ */
10
64
  export declare const shareAction: Action;
65
+ /**
66
+ * @constant upAction
67
+ * @type {Action}
68
+ * @property {string} name - up
69
+ * @property {ConstructorOfATypedSvelteComponent} icon - UpArrowSolid
70
+ */
11
71
  export declare const upAction: Action;
@@ -1,40 +1,100 @@
1
1
  import { ArrowDownSolid, ArrowUpSolid, BellActiveOutline, BookmarkOutline, CogOutline, EditOutline, HeartSolid, InfoCircleOutline, ShareNodesOutline, TrashBinOutline, } from 'flowbite-svelte-icons';
2
+ /**
3
+ * @constant bookmarkAction
4
+ * @type {Action}
5
+ * @property {string} name - bookmark
6
+ * @property {ConstructorOfATypedSvelteComponent} icon - BookmarkOutline
7
+ */
2
8
  export const bookmarkAction = {
3
9
  icon: BookmarkOutline,
4
10
  name: 'bookmark',
5
11
  };
12
+ /**
13
+ * @constant deleteAction
14
+ * @type {Action}
15
+ * @property {string} name - delete
16
+ * @property {ConstructorOfATypedSvelteComponent} icon - TrashBinOutline
17
+ */
6
18
  export const deleteAction = {
7
19
  icon: TrashBinOutline,
8
20
  name: 'delete',
9
21
  };
22
+ /**
23
+ * @constant downAction
24
+ * @type {Action}
25
+ * @property {string} name - down
26
+ * @property {ConstructorOfATypedSvelteComponent} icon - ArrowDownSolid
27
+ */
10
28
  export const downAction = {
11
29
  icon: ArrowDownSolid,
12
30
  name: 'down',
13
31
  };
32
+ /**
33
+ * @constant editAction
34
+ * @type {Action}
35
+ * @property {string} name - edit
36
+ * @property {ConstructorOfATypedSvelteComponent} icon - EditOutline
37
+ */
14
38
  export const editAction = {
15
39
  icon: EditOutline,
16
40
  name: 'edit',
17
41
  };
42
+ /**
43
+ * @constant favoriteAction
44
+ * @type {Action}
45
+ * @property {string} name - favorite
46
+ * @property {ConstructorOfATypedSvelteComponent} icon - HeartSolid
47
+ */
18
48
  export const favoriteAction = {
19
49
  icon: HeartSolid,
20
50
  name: 'favorite',
21
51
  };
52
+ /**
53
+ * @constant infoAction
54
+ * @type {Action}
55
+ * @property {string} name - info
56
+ * @property {ConstructorOfATypedSvelteComponent} icon - InfoCircleOutline
57
+ */
22
58
  export const infoAction = {
23
59
  icon: InfoCircleOutline,
24
60
  name: 'info',
25
61
  };
62
+ /**
63
+ * @constant notificationAction
64
+ * @type {Action}
65
+ * @property {string} name - notification
66
+ * @property {ConstructorOfATypedSvelteComponent} icon - BellActiveOutline
67
+ */
26
68
  export const notificationAction = {
27
69
  icon: BellActiveOutline,
28
70
  name: 'notification',
29
71
  };
72
+ /**
73
+ * @constant settingsAction
74
+ * @type {Action}
75
+ * @property {string} name - settings
76
+ * @property {ConstructorOfATypedSvelteComponent} icon - CogOutline
77
+ */
30
78
  export const settingsAction = {
31
79
  icon: CogOutline,
32
80
  name: 'settings',
33
81
  };
82
+ /**
83
+ * @constant shareAction
84
+ * @type {Action}
85
+ * @property {string} name - share
86
+ * @property {ConstructorOfATypedSvelteComponent} icon - ShareNodesOutline
87
+ */
34
88
  export const shareAction = {
35
89
  icon: ShareNodesOutline,
36
90
  name: 'share',
37
91
  };
92
+ /**
93
+ * @constant upAction
94
+ * @type {Action}
95
+ * @property {string} name - up
96
+ * @property {ConstructorOfATypedSvelteComponent} icon - UpArrowSolid
97
+ */
38
98
  export const upAction = {
39
99
  icon: ArrowUpSolid,
40
100
  name: 'up',
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Returns true if the action should be disabled for the row.
3
+ * @callback ActionDisablementFunction
4
+ * @param {any} item - The row of data
5
+ * @param {ColumnConfig} column - The configuration for the ActionCell's column
6
+ * @param {Action} action - The action to disable or enable
7
+ * @returns {boolean}
8
+ */
9
+ export {};
10
+ /**
11
+ * An action to be displayed inside an ActionCell
12
+ * @interface Action
13
+ * @property {string} [buttonClass] - Class for the button. If not populated, the cell's buttonClass will be used.
14
+ * @property {ButtonColor} [buttonColor] - See {@link https://flowbite-svelte.com/docs/pages/typescript}. If not populated, the cell's buttonColor will be used.
15
+ * @property {string} [caption] - Text displayed with the icon.
16
+ * @property {string} name - Name of the action. Returned as part of the action event on DataGrid when the button is clicked.
17
+ * @property {ConstructorOfATypedSvelteComponent} icon - Icon to be displayed in the button.
18
+ * @property {string} [iconClass] - Class for the icon to be displayed in the button. If not populated, the cell's iconClass will be used.
19
+ * @property {ActionDisablementFunction} [isDisabled] - If populated, will be called to check whether the button should be enabled or disabled for each row.
20
+ */
21
+ /**
22
+ * Cell containing an array of Button ({@link https://flowbite-svelte.com/docs/components/buttons}) components which fire the action event on the grid when clicked.
23
+ * @typedef {object} ActionsCell
24
+ * @property [Action[]] actions - The actions to be displayed inside the cell.
25
+ * @property {string} [buttonClass] - Class for the cell's buttons. Defaults to 'border-0 p-1'.
26
+ * @property {ButtonColor} [buttonColor] - See {@link https://flowbite-svelte.com/docs/pages/typescript}. Defaults to 'light'.
27
+ * @property {string} [iconClass] - Class for the icon to be displayed in the button. Defaults to 'w-4 h-4'.
28
+ */
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * Returns true if the action should be disabled for the row.
4
+ * @callback ActionDisablementFunction
5
+ * @param {any} item - The row of data
6
+ * @param {ColumnConfig} column - The configuration for the ActionCell's column
7
+ * @param {Action} action - The action to disable or enable
8
+ * @returns {boolean}
9
+ */
10
+ /**
11
+ * An action to be displayed inside an ActionCell
12
+ * @interface Action
13
+ * @property {string} [buttonClass] - Class for the button. If not populated, the cell's buttonClass will be used.
14
+ * @property {ButtonColor} [buttonColor] - See {@link https://flowbite-svelte.com/docs/pages/typescript}. If not populated, the cell's buttonColor will be used.
15
+ * @property {string} [caption] - Text displayed with the icon.
16
+ * @property {string} name - Name of the action. Returned as part of the action event on DataGrid when the button is clicked.
17
+ * @property {ConstructorOfATypedSvelteComponent} icon - Icon to be displayed in the button.
18
+ * @property {string} [iconClass] - Class for the icon to be displayed in the button. If not populated, the cell's iconClass will be used.
19
+ * @property {ActionDisablementFunction} [isDisabled] - If populated, will be called to check whether the button should be enabled or disabled for each row.
20
+ */
21
+ /**
22
+ * Cell containing an array of Button ({@link https://flowbite-svelte.com/docs/components/buttons}) components which fire the action event on the grid when clicked.
23
+ * @typedef {object} ActionsCell
24
+ * @property [Action[]] actions - The actions to be displayed inside the cell.
25
+ * @property {string} [buttonClass] - Class for the cell's buttons. Defaults to 'border-0 p-1'.
26
+ * @property {ButtonColor} [buttonColor] - See {@link https://flowbite-svelte.com/docs/pages/typescript}. Defaults to 'light'.
27
+ * @property {string} [iconClass] - Class for the icon to be displayed in the button. Defaults to 'w-4 h-4'.
28
+ */
@@ -1,6 +1,7 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import type { ColumnConfig } from '../common.js';
3
3
  type ButtonColor = 'red' | 'yellow' | 'green' | 'purple' | 'blue' | 'light' | 'dark' | 'primary' | 'none' | 'alternative' | undefined;
4
+ export type ActionDisablementFunction = (item: any, column: ColumnConfig, action: Action) => boolean;
4
5
  export interface Action {
5
6
  buttonClass?: string;
6
7
  buttonColor?: ButtonColor;
@@ -8,7 +9,7 @@ export interface Action {
8
9
  name: string;
9
10
  icon: ConstructorOfATypedSvelteComponent;
10
11
  iconClass?: string;
11
- isDisabled?: (item: any, column: ColumnConfig, action: Action) => boolean;
12
+ isDisabled?: ActionDisablementFunction;
12
13
  }
13
14
  declare const __propDef: {
14
15
  props: {
@@ -0,0 +1,6 @@
1
+ export {};
2
+ /**
3
+ * Cell containing a Button ({@link https://flowbite-svelte.com/docs/components/buttons}) component.
4
+ * @typedef {object} ButtonCell
5
+ * @property {string} [caption] - Text to be displayed inside the button.
6
+ */
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Cell containing a Button ({@link https://flowbite-svelte.com/docs/components/buttons}) component.
4
+ * @typedef {object} ButtonCell
5
+ * @property {string} [caption] - Text to be displayed inside the button.
6
+ */
@@ -0,0 +1,6 @@
1
+ export {};
2
+ /**
3
+ * Cell containing a Checkbox {@link (https://flowbite-svelte.com/docs/forms/checkbox}) component.
4
+ * @typedef {object} CheckboxCell
5
+ * @property {string} [caption] - Text to be displayed next to the checkbox.
6
+ */
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Cell containing a Checkbox {@link (https://flowbite-svelte.com/docs/forms/checkbox}) component.
4
+ * @typedef {object} CheckboxCell
5
+ * @property {string} [caption] - Text to be displayed next to the checkbox.
6
+ */
@@ -0,0 +1,6 @@
1
+ export {};
2
+ /**
3
+ * Cell containing an Input {@link (https://flowbite-svelte.com/docs/forms/input-field}) component.
4
+ * @typedef {object} InputCell
5
+ * @property {string} [inputType] - See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types}
6
+ */
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Cell containing an Input {@link (https://flowbite-svelte.com/docs/forms/input-field}) component.
4
+ * @typedef {object} InputCell
5
+ * @property {string} [inputType] - See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types}
6
+ */
@@ -0,0 +1,6 @@
1
+ export {};
2
+ /**
3
+ * Cell containing a NumberInput ({@link https://flowbite-svelte.com/docs/forms/input-field#Number_input}) component.
4
+ * @typedef {object} NumberInputCell
5
+ * @property {string} [inputType] - See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types
6
+ */
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Cell containing a NumberInput ({@link https://flowbite-svelte.com/docs/forms/input-field#Number_input}) component.
4
+ * @typedef {object} NumberInputCell
5
+ * @property {string} [inputType] - See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types
6
+ */
@@ -0,0 +1,8 @@
1
+ export {};
2
+ /**
3
+ * Cell containing a Select ({@link https://flowbite-svelte.com/docs/forms/select}) component.
4
+ * @typedef {object} SelectCell
5
+ * @property {string} [displayProp] - Property within items which displays in the list. Defaults to 'name'.
6
+ * @property {string} [valueProp] - Property within tems used to populate the cell's value when picked. Defaults to 'id'.
7
+ * @property {any[]} items - Array of objects the user can select from.
8
+ */
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Cell containing a Select ({@link https://flowbite-svelte.com/docs/forms/select}) component.
4
+ * @typedef {object} SelectCell
5
+ * @property {string} [displayProp] - Property within items which displays in the list. Defaults to 'name'.
6
+ * @property {string} [valueProp] - Property within tems used to populate the cell's value when picked. Defaults to 'id'.
7
+ * @property {any[]} items - Array of objects the user can select from.
8
+ */
@@ -0,0 +1,13 @@
1
+ export {};
2
+ /**
3
+ * Cell containing a numeric value and plus and minus buttons. The value is decremented or incremented when the buttons are clicked.
4
+ * @typedef {object} SpinCell
5
+ * @property {number} [decValue] - Amount to decrement the value by when the minus button is clicked. Defaults to 1.
6
+ * @property {number} [incValue] - Amount to increment the value by when the plus button is clicked. Defaults to 1.
7
+ * @property {number} [minValue] - If specified, the minus button cannot make the value go lower than this.
8
+ * @property {number} [maxValue] - If specified, the plus button cannot make the value go higher than this.
9
+ * @property {ConstructorOfATypedSvelteComponent} [minusIcon] Svelte component class for the minus icon. Defaults to MinusSolid from {@link https://flowbite.com/icons/}
10
+ * @property {string} [minusIconClass] - CSS class of the minus icon, defaults to 'pr-1 w-3 h-3'
11
+ * @property {ConstructorOfATypedSvelteComponent} [plusIcon] Svelte component class for the plus icon. Defaults to PlusSolid from {@link https://flowbite.com/icons/}
12
+ * @property {string} [plusIconClass] - CSS class of the plus icon, defaults to 'pr-1 w-3 h-3'
13
+ */
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Cell containing a numeric value and plus and minus buttons. The value is decremented or incremented when the buttons are clicked.
4
+ * @typedef {object} SpinCell
5
+ * @property {number} [decValue] - Amount to decrement the value by when the minus button is clicked. Defaults to 1.
6
+ * @property {number} [incValue] - Amount to increment the value by when the plus button is clicked. Defaults to 1.
7
+ * @property {number} [minValue] - If specified, the minus button cannot make the value go lower than this.
8
+ * @property {number} [maxValue] - If specified, the plus button cannot make the value go higher than this.
9
+ * @property {ConstructorOfATypedSvelteComponent} [minusIcon] Svelte component class for the minus icon. Defaults to MinusSolid from {@link https://flowbite.com/icons/}
10
+ * @property {string} [minusIconClass] - CSS class of the minus icon, defaults to 'pr-1 w-3 h-3'
11
+ * @property {ConstructorOfATypedSvelteComponent} [plusIcon] Svelte component class for the plus icon. Defaults to PlusSolid from {@link https://flowbite.com/icons/}
12
+ * @property {string} [plusIconClass] - CSS class of the plus icon, defaults to 'pr-1 w-3 h-3'
13
+ */
@@ -0,0 +1,5 @@
1
+ export {};
2
+ /**
3
+ * Utility component to make tabbing between focused cells work. See InputCell.svelte as an example.
4
+ * @typedef {object} TabWrapper
5
+ */
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /**
3
+ * Utility component to make tabbing between focused cells work. See InputCell.svelte as an example.
4
+ * @typedef {object} TabWrapper
5
+ */
@@ -0,0 +1,6 @@
1
+ export {};
2
+ /**
3
+ * Cell containing a Toggle ({@link https://flowbite-svelte.com/docs/forms/toggle}) component.
4
+ * @typedef {object} ToggleCell
5
+ * @property {string} [caption] - Text to be displayed inside the button.
6
+ */
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Cell containing a Toggle ({@link https://flowbite-svelte.com/docs/forms/toggle}) component.
4
+ * @typedef {object} ToggleCell
5
+ * @property {string} [caption] - Text to be displayed inside the button.
6
+ */
@@ -1,10 +1,19 @@
1
1
  export * from './Actions.js';
2
2
  export * from './ActionsCell.svelte';
3
+ export { default as ActionsCell } from './ActionsCell.svelte';
3
4
  export * from './ButtonCell.svelte';
5
+ export { default as ButtonCell } from './ButtonCell.svelte';
4
6
  export * from './CheckboxCell.svelte';
7
+ export { default as CheckboxCell } from './CheckboxCell.svelte';
5
8
  export * from './InputCell.svelte';
9
+ export { default as InputCell } from './InputCell.svelte';
6
10
  export * from './NumberInputCell.svelte';
11
+ export { default as NumberInputCell } from './NumberInputCell.svelte';
7
12
  export * from './SelectCell.svelte';
13
+ export { default as SelectCell } from './SelectCell.svelte';
8
14
  export * from './SpinCell.svelte';
15
+ export { default as SpinCell } from './SpinCell.svelte';
9
16
  export * from './TabWrapper.svelte';
17
+ export { default as TabWrapper } from './TabWrapper.svelte';
10
18
  export * from './ToggleCell.svelte';
19
+ export { default as ToggleCell } from './ToggleCell.svelte';
@@ -1,10 +1,19 @@
1
1
  export * from './Actions.js';
2
2
  export * from './ActionsCell.svelte';
3
+ export { default as ActionsCell } from './ActionsCell.svelte';
3
4
  export * from './ButtonCell.svelte';
5
+ export { default as ButtonCell } from './ButtonCell.svelte';
4
6
  export * from './CheckboxCell.svelte';
7
+ export { default as CheckboxCell } from './CheckboxCell.svelte';
5
8
  export * from './InputCell.svelte';
9
+ export { default as InputCell } from './InputCell.svelte';
6
10
  export * from './NumberInputCell.svelte';
11
+ export { default as NumberInputCell } from './NumberInputCell.svelte';
7
12
  export * from './SelectCell.svelte';
13
+ export { default as SelectCell } from './SelectCell.svelte';
8
14
  export * from './SpinCell.svelte';
15
+ export { default as SpinCell } from './SpinCell.svelte';
9
16
  export * from './TabWrapper.svelte';
17
+ export { default as TabWrapper } from './TabWrapper.svelte';
10
18
  export * from './ToggleCell.svelte';
19
+ export { default as ToggleCell } from './ToggleCell.svelte';
package/dist/common.d.ts CHANGED
@@ -1,3 +1,78 @@
1
+ /**
2
+ * Values for a given column/row, returned by cellRenderer (or the default renderer).
3
+ * @typedef {object} CellValue
4
+ * @property {any} dataValue The data value for the cell.
5
+ * @property {any} [displayValue] The value to be displayed for the cell. If this is not set, value will be used instead.
6
+ */
7
+ export interface CellValue {
8
+ dataValue: any;
9
+ displayValue?: any;
10
+ }
11
+ /**
12
+ * Returns the value for a given column/row combination.
13
+ * @callback CellRenderer
14
+ * @returns {CellValue}
15
+ */
16
+ export type CellRenderer = (
17
+ /** Configuration for the cell's column. */
18
+ column: ColumnConfig,
19
+ /** Data for the cell's row. */
20
+ item: any) => Promise<CellValue>;
21
+ /**
22
+ * Returns the a class string for a data cell.
23
+ * @callback DataCellClassFunction
24
+ * @returns {string}
25
+ */
26
+ export type DataCellClassFunction = (
27
+ /** Data for the cell's row. */
28
+ item: any,
29
+ /** Configuration for the cell's column. */
30
+ column: ColumnConfig,
31
+ /** Value for the data cell, after Column.cellRenderer (if any) has been called. */
32
+ value: CellValue,
33
+ /** True if the cell is focused. */
34
+ isFocused: boolean,
35
+ /** Classes as termined by grid and column properties and focus state. */
36
+ calcClass: string,
37
+ /** Default classes for a TableBodyCell component as defined by FlowBite. */
38
+ defaultClass: string,
39
+ /** tdClassAppend from DataTable. */
40
+ appendClass: string,
41
+ /** tdClassOveride from DataTable. */
42
+ overrideClass: string) => string;
43
+ /**
44
+ * Returns a comparison between two values, used for sorting.
45
+ * @callback SortFunction
46
+ * @returns {number}
47
+ */
48
+ export type SortFunction = (
49
+ /** First value to compare. */
50
+ a: any,
51
+ /** Second value to compare. */
52
+ b: any) => number;
53
+ /**
54
+ * Configuration options for a grid column
55
+ * @typedef {object} ColumnConfig
56
+ * @property {string} [id] - Used to distinguish between multiple columns that have the same key.
57
+ * @property {string} [key] - Name of the property in each row item that will be used for this column's value.
58
+ * @property {string} [title] - Text to display in the column's header.
59
+ * @property {CellRenderer} [cellRenderer] - Dynamically determines the data value and display value for a cell.
60
+ * @property {ConstructorOfATypedSvelteComponent} [viewComponent] - Svelte component class to be displayed in the cell regardless of focus. If set, focusComponent will be ignored.
61
+ * @property {object} [viewComponentConfig] - Properties to be passed when creating viewComponent.
62
+ * @property {ConstructorOfATypedSvelteComponent} [focusComponent] - Svelte component class to be displayed in the cell when it has focus.
63
+ * @property {object} [focusComponentConfig] - Properties to be passed when creating focusComponent.
64
+ * @property {string} [tdClassAppend] - Classes to append to existing CSS when not focused.
65
+ * @property {string} [tdClassOverride] - Classes to replace existing CSS with when not focused.
66
+ * @property {string} [tdFocusedClassAppend] - Classes to append to existing CSS when focused.
67
+ * @property {string} [tdFocusedClassOverride] - Classes to replace existing CSS with when focused.
68
+ * @property {DataCellClassFunction} [tdClassGetter] - Dynamically determines CSS classes for a cell.
69
+ * @property {string} [thClassAppend] - Classes to append to existing CSS for header cells.
70
+ * @property {string} [thClassOverride] - Class to replace existing CSS for header cells.
71
+ * @property {boolean} [canFocus] - True if cells in this column can be focused.
72
+ * @property {boolean} [canSort] - If true, clicking the column's header will set sorting to sortFunction or sortKey, or reverse it if already set.
73
+ * @property {SortFunction} [sortFunction] - Comparison function for complex sorting.
74
+ * @property {string} [sortKey] - Item property to sort by, if sortFunction is not defined.
75
+ */
1
76
  export interface ColumnConfig {
2
77
  id?: string;
3
78
  key?: string;
@@ -19,18 +94,39 @@ export interface ColumnConfig {
19
94
  sortFunction?: SortFunction;
20
95
  sortKey?: string;
21
96
  }
22
- export type CellRenderer = (columnConfig: ColumnConfig, item: any) => Promise<any>;
23
- export type SortFunction = (a: any, b: any) => number;
24
- export type RowClassFunction = (item: any, isFocused: boolean, calcClass: string, defaultClass: string, appendClass: string, overrideClass: string) => string;
25
- export type DataCellClassFunction = (item: any, column: ColumnConfig, value: any, isFocused: boolean, calcClass: string, defaultClass: string, appendClass: string, overrideClass: string) => string;
97
+ /**
98
+ * Returns the a class string for a data row.
99
+ * @callback RowClassFunction
100
+ * @returns {string}
101
+ */
102
+ export type RowClassFunction = (
103
+ /** Data for the cell's row. */
104
+ item: any,
105
+ /** True if a cell on this row is focused. */
106
+ isFocused: boolean,
107
+ /** Classes as termined by grid properties. */
108
+ calcClass: string,
109
+ /** Default classes for a TableBodyRow component as defined by FlowBite. */
110
+ defaultClass: string,
111
+ /** trClassAppend from DataTable. */
112
+ appendClass: string,
113
+ /** trClassOveride from DataTable. */
114
+ overrideClass: string) => string;
115
+ /**
116
+ * Joins an array of classes into a string, removing any falsey values.
117
+ * @function joinClasses
118
+ * @param {...string} items - Strings of CSS classes to join.
119
+ * @returns {string}
120
+ */
26
121
  export declare const joinClasses: (...classes: (string | false | null | undefined)[]) => string;
122
+ /**
123
+ * Values for enterAction on DataTable.
124
+ * @enum {string} EnterAction
125
+ */
126
+ export type EnterAction = 'next' | 'down' | 'stay';
27
127
  export type GetTDClassFunction = (item: any, value: any, isFocused: boolean) => string;
28
128
  export interface InternalColumnConfig extends ColumnConfig {
29
129
  getTDClass: GetTDClassFunction;
30
130
  }
31
- export declare const blankCellValues: {
32
- dataValue: null;
33
- displayValue: string;
34
- };
131
+ export declare const blankCellValue: CellValue;
35
132
  export declare const defaultCellRenderer: CellRenderer;
36
- export type EnterAction = 'next' | 'down' | 'stay';
package/dist/common.js CHANGED
@@ -1,8 +1,14 @@
1
+ /**
2
+ * Joins an array of classes into a string, removing any falsey values.
3
+ * @function joinClasses
4
+ * @param {...string} items - Strings of CSS classes to join.
5
+ * @returns {string}
6
+ */
1
7
  export const joinClasses = (...classes) => (classes || []).filter((value) => !!value).join(' ');
2
- export const blankCellValues = {
8
+ export const blankCellValue = {
3
9
  dataValue: null,
4
10
  displayValue: '',
5
11
  };
6
12
  export const defaultCellRenderer = async (column, item) => column.key
7
13
  ? { dataValue: item[column.key], displayValue: item[column.key] || '' }
8
- : blankCellValues;
14
+ : blankCellValue;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@emamid/svelte-data-table",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
+ "homepage": "htts://davidemami.net/",
4
5
  "scripts": {
5
6
  "dev": "vite dev",
6
7
  "build": "vite build && npm run package",
@@ -11,7 +12,8 @@
11
12
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12
13
  "test": "vitest",
13
14
  "lint": "prettier --check . && eslint .",
14
- "format": "prettier --write ."
15
+ "format": "prettier --write .",
16
+ "jsdoc": "jsdoc -c jsdoc.json"
15
17
  },
16
18
  "exports": {
17
19
  ".": {
@@ -35,12 +37,15 @@
35
37
  "@types/eslint": "8.56.0",
36
38
  "@typescript-eslint/eslint-plugin": "^6.0.0",
37
39
  "@typescript-eslint/parser": "^6.0.0",
40
+ "better-docs": "^2.7.3",
38
41
  "eslint": "^8.56.0",
39
42
  "eslint-config-prettier": "^9.1.0",
40
43
  "eslint-plugin-svelte": "^2.35.1",
41
44
  "flowbite": "^2.2.1",
42
45
  "flowbite-svelte": "^0.44.22",
43
46
  "flowbite-svelte-icons": "^1.0.2",
47
+ "jsdoc": "^4.0.2",
48
+ "jsdoc-plugin-typescript": "^2.2.1",
44
49
  "prettier": "^3.1.1",
45
50
  "prettier-plugin-svelte": "^3.1.2",
46
51
  "publint": "^0.1.9",