@emamid/svelte-data-table 0.0.12 → 0.0.13

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.
Files changed (53) hide show
  1. package/dist/DataTable.doc.d.ts +79 -0
  2. package/dist/DataTable.doc.js +79 -0
  3. package/dist/DataTable.svelte +244 -0
  4. package/dist/DataTable.svelte.d.ts +55 -0
  5. package/dist/DataTableDataCell.svelte +46 -0
  6. package/dist/DataTableDataCell.svelte.d.ts +26 -0
  7. package/dist/DataTableHeaderCell.svelte +25 -0
  8. package/dist/DataTableHeaderCell.svelte.d.ts +24 -0
  9. package/dist/cells/Actions.d.ts +71 -0
  10. package/dist/cells/Actions.js +101 -0
  11. package/dist/cells/ActionsCell.doc.d.ts +28 -0
  12. package/dist/cells/ActionsCell.doc.js +28 -0
  13. package/dist/cells/ActionsCell.svelte +31 -0
  14. package/dist/cells/ActionsCell.svelte.d.ts +35 -0
  15. package/dist/cells/ButtonCell.doc.d.ts +6 -0
  16. package/dist/cells/ButtonCell.doc.js +6 -0
  17. package/dist/cells/ButtonCell.svelte +17 -0
  18. package/dist/cells/ButtonCell.svelte.d.ts +22 -0
  19. package/dist/cells/CheckboxCell.doc.d.ts +6 -0
  20. package/dist/cells/CheckboxCell.doc.js +6 -0
  21. package/dist/cells/CheckboxCell.svelte +21 -0
  22. package/dist/cells/CheckboxCell.svelte.d.ts +23 -0
  23. package/dist/cells/InputCell.doc.d.ts +6 -0
  24. package/dist/cells/InputCell.doc.js +6 -0
  25. package/dist/cells/InputCell.svelte +55 -0
  26. package/dist/cells/InputCell.svelte.d.ts +26 -0
  27. package/dist/cells/NumberInputCell.doc.d.ts +6 -0
  28. package/dist/cells/NumberInputCell.doc.js +6 -0
  29. package/dist/cells/NumberInputCell.svelte +48 -0
  30. package/dist/cells/NumberInputCell.svelte.d.ts +25 -0
  31. package/dist/cells/SelectCell.doc.d.ts +8 -0
  32. package/dist/cells/SelectCell.doc.js +8 -0
  33. package/dist/cells/SelectCell.svelte +30 -0
  34. package/dist/cells/SelectCell.svelte.d.ts +27 -0
  35. package/dist/cells/SpinCell.doc.d.ts +13 -0
  36. package/dist/cells/SpinCell.doc.js +13 -0
  37. package/dist/cells/SpinCell.svelte +59 -0
  38. package/dist/cells/SpinCell.svelte.d.ts +29 -0
  39. package/dist/cells/TabWrapper.doc.d.ts +5 -0
  40. package/dist/cells/TabWrapper.doc.js +5 -0
  41. package/dist/cells/TabWrapper.svelte +23 -0
  42. package/dist/cells/TabWrapper.svelte.d.ts +23 -0
  43. package/dist/cells/ToggleCell.doc.d.ts +6 -0
  44. package/dist/cells/ToggleCell.doc.js +6 -0
  45. package/dist/cells/ToggleCell.svelte +21 -0
  46. package/dist/cells/ToggleCell.svelte.d.ts +23 -0
  47. package/dist/cells/index.d.ts +19 -0
  48. package/dist/cells/index.js +19 -0
  49. package/dist/common.d.ts +136 -0
  50. package/dist/common.js +14 -0
  51. package/dist/index.d.ts +4 -0
  52. package/dist/index.js +3 -0
  53. package/package.json +1 -1
@@ -0,0 +1,59 @@
1
+ <script>import { createEventDispatcher } from "svelte";
2
+ import { Button } from "flowbite-svelte";
3
+ import { MinusSolid, PlusSolid } from "flowbite-svelte-icons";
4
+ export let item;
5
+ export let column;
6
+ export let value;
7
+ export let decValue = 1;
8
+ export let incValue = 1;
9
+ export let minValue = void 0;
10
+ export let maxValue = void 0;
11
+ export let minusIcon = MinusSolid;
12
+ export let minusIconClass = "pr-1 w-3 h-3";
13
+ export let plusIcon = PlusSolid;
14
+ export let plusIconClass = "pr-1 w-3 h-3";
15
+ const dispatch = createEventDispatcher();
16
+ const decrement = () => {
17
+ dispatch("cellChanged", {
18
+ column,
19
+ item,
20
+ oldValue: value,
21
+ newValue: (value || 0) - decValue
22
+ });
23
+ };
24
+ const increment = () => {
25
+ dispatch("cellChanged", {
26
+ column,
27
+ item,
28
+ oldValue: value,
29
+ newValue: (value || 0) + incValue
30
+ });
31
+ };
32
+ </script>
33
+
34
+ <div class="spinner">
35
+ <Button
36
+ color="none"
37
+ class="pr-1"
38
+ on:click={decrement}
39
+ disabled={minValue !== undefined && value - decValue < minValue}
40
+ ><svelte:component this={minusIcon} class={minusIconClass} /></Button
41
+ >
42
+ {value || 0}
43
+ <Button
44
+ color="none"
45
+ class="pl-1"
46
+ on:click={increment}
47
+ disabled={maxValue !== undefined && value + incValue > maxValue}
48
+ ><svelte:component this={plusIcon} class={plusIconClass} /></Button
49
+ >
50
+ </div>
51
+
52
+ <style>
53
+ .spinner {
54
+ display: flex;
55
+ flex-direction: row;
56
+ justify-content: center;
57
+ align-items: center;
58
+ }
59
+ </style>
@@ -0,0 +1,29 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { ColumnConfig } from '../common.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ item: any;
6
+ column: ColumnConfig;
7
+ value: any;
8
+ decValue?: number | undefined;
9
+ incValue?: number | undefined;
10
+ minValue?: number | undefined;
11
+ maxValue?: number | undefined;
12
+ minusIcon?: ConstructorOfATypedSvelteComponent | undefined;
13
+ minusIconClass?: string | undefined;
14
+ plusIcon?: ConstructorOfATypedSvelteComponent | undefined;
15
+ plusIconClass?: string | undefined;
16
+ };
17
+ events: {
18
+ cellChanged: CustomEvent<any>;
19
+ } & {
20
+ [evt: string]: CustomEvent<any>;
21
+ };
22
+ slots: {};
23
+ };
24
+ export type SpinCellProps = typeof __propDef.props;
25
+ export type SpinCellEvents = typeof __propDef.events;
26
+ export type SpinCellSlots = typeof __propDef.slots;
27
+ export default class SpinCell extends SvelteComponent<SpinCellProps, SpinCellEvents, SpinCellSlots> {
28
+ }
29
+ export {};
@@ -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,23 @@
1
+ <script>import { createEventDispatcher } from "svelte";
2
+ export let item = null;
3
+ export let column = null;
4
+ const dispatch = createEventDispatcher();
5
+ const prevTab = (_event) => {
6
+ dispatch("prevTab", {
7
+ column,
8
+ item
9
+ });
10
+ };
11
+ const nextTab = (_event) => {
12
+ dispatch("nextTab", {
13
+ column,
14
+ item
15
+ });
16
+ };
17
+ </script>
18
+
19
+ <!-- svelte-ignore a11y-no-noninteractive-tabindex-->
20
+ <div tabindex="0" on:focus={prevTab} />
21
+ <slot />
22
+ <!-- svelte-ignore a11y-no-noninteractive-tabindex-->
23
+ <div tabindex="0" on:focus={nextTab} />
@@ -0,0 +1,23 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { ColumnConfig } from '../common.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ item?: any;
6
+ column?: ColumnConfig | null | undefined;
7
+ };
8
+ events: {
9
+ prevTab: CustomEvent<any>;
10
+ nextTab: CustomEvent<any>;
11
+ } & {
12
+ [evt: string]: CustomEvent<any>;
13
+ };
14
+ slots: {
15
+ default: {};
16
+ };
17
+ };
18
+ export type TabWrapperProps = typeof __propDef.props;
19
+ export type TabWrapperEvents = typeof __propDef.events;
20
+ export type TabWrapperSlots = typeof __propDef.slots;
21
+ export default class TabWrapper extends SvelteComponent<TabWrapperProps, TabWrapperEvents, TabWrapperSlots> {
22
+ }
23
+ export {};
@@ -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
+ */
@@ -0,0 +1,21 @@
1
+ <script>import { createEventDispatcher } from "svelte";
2
+ import { Toggle } from "flowbite-svelte";
3
+ export let caption = "";
4
+ export let column;
5
+ export let item;
6
+ export let value;
7
+ let localValue = value;
8
+ const dispatch = createEventDispatcher();
9
+ const toggleChanged = () => {
10
+ dispatch("cellChanged", {
11
+ column,
12
+ item,
13
+ oldValue: value,
14
+ newValue: localValue
15
+ });
16
+ };
17
+ </script>
18
+
19
+ <Toggle {...$$props} bind:checked={localValue} on:change={toggleChanged}
20
+ >{#if caption}{caption}{/if}</Toggle
21
+ >
@@ -0,0 +1,23 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { ColumnConfig } from '../common.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ [x: string]: any;
6
+ caption?: string | undefined;
7
+ column: ColumnConfig;
8
+ item: any;
9
+ value: any;
10
+ };
11
+ events: {
12
+ cellChanged: CustomEvent<any>;
13
+ } & {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {};
17
+ };
18
+ export type ToggleCellProps = typeof __propDef.props;
19
+ export type ToggleCellEvents = typeof __propDef.events;
20
+ export type ToggleCellSlots = typeof __propDef.slots;
21
+ export default class ToggleCell extends SvelteComponent<ToggleCellProps, ToggleCellEvents, ToggleCellSlots> {
22
+ }
23
+ export {};
@@ -0,0 +1,19 @@
1
+ export * from './Actions.js';
2
+ export * from './ActionsCell.svelte';
3
+ export { default as ActionsCell } from './ActionsCell.svelte';
4
+ export * from './ButtonCell.svelte';
5
+ export { default as ButtonCell } from './ButtonCell.svelte';
6
+ export * from './CheckboxCell.svelte';
7
+ export { default as CheckboxCell } from './CheckboxCell.svelte';
8
+ export * from './InputCell.svelte';
9
+ export { default as InputCell } from './InputCell.svelte';
10
+ export * from './NumberInputCell.svelte';
11
+ export { default as NumberInputCell } from './NumberInputCell.svelte';
12
+ export * from './SelectCell.svelte';
13
+ export { default as SelectCell } from './SelectCell.svelte';
14
+ export * from './SpinCell.svelte';
15
+ export { default as SpinCell } from './SpinCell.svelte';
16
+ export * from './TabWrapper.svelte';
17
+ export { default as TabWrapper } from './TabWrapper.svelte';
18
+ export * from './ToggleCell.svelte';
19
+ export { default as ToggleCell } from './ToggleCell.svelte';
@@ -0,0 +1,19 @@
1
+ export * from './Actions.js';
2
+ export * from './ActionsCell.svelte';
3
+ export { default as ActionsCell } from './ActionsCell.svelte';
4
+ export * from './ButtonCell.svelte';
5
+ export { default as ButtonCell } from './ButtonCell.svelte';
6
+ export * from './CheckboxCell.svelte';
7
+ export { default as CheckboxCell } from './CheckboxCell.svelte';
8
+ export * from './InputCell.svelte';
9
+ export { default as InputCell } from './InputCell.svelte';
10
+ export * from './NumberInputCell.svelte';
11
+ export { default as NumberInputCell } from './NumberInputCell.svelte';
12
+ export * from './SelectCell.svelte';
13
+ export { default as SelectCell } from './SelectCell.svelte';
14
+ export * from './SpinCell.svelte';
15
+ export { default as SpinCell } from './SpinCell.svelte';
16
+ export * from './TabWrapper.svelte';
17
+ export { default as TabWrapper } from './TabWrapper.svelte';
18
+ export * from './ToggleCell.svelte';
19
+ export { default as ToggleCell } from './ToggleCell.svelte';
@@ -0,0 +1,136 @@
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 determined 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 {ConstructorOfATypedSvelteComponent} [sortAscendingIcon] - Svelte component class to be displayed in the column is sorting ascended (overrides table).
74
+ * @property {ConstructorOfATypedSvelteComponent} [sortDescendingIcon] - Svelte component class to be displayed in the column is sorting descended (overrides table).
75
+ * @property {SortFunction} [sortFunction] - Comparison function for complex sorting.
76
+ * @property {string} [sortKey] - Item property to sort by, if sortFunction is not defined.
77
+ */
78
+ export interface ColumnConfig {
79
+ id?: string;
80
+ key?: string;
81
+ title?: string;
82
+ cellRenderer?: CellRenderer;
83
+ viewComponent?: ConstructorOfATypedSvelteComponent;
84
+ viewComponentConfig?: any;
85
+ focusComponent?: ConstructorOfATypedSvelteComponent;
86
+ focusComponentConfig?: any;
87
+ tdClassAppend?: string;
88
+ tdClassOverride?: string;
89
+ tdFocusedClassAppend?: string;
90
+ tdFocusedClassOverride?: string;
91
+ tdClassGetter?: DataCellClassFunction;
92
+ thClassAppend?: string;
93
+ thClassOverride?: string;
94
+ canFocus?: boolean;
95
+ canSort?: boolean;
96
+ sortFunction?: SortFunction;
97
+ sortKey?: string;
98
+ sortAscendingIcon?: ConstructorOfATypedSvelteComponent;
99
+ sortDescendingIcon?: ConstructorOfATypedSvelteComponent;
100
+ }
101
+ /**
102
+ * Returns the a class string for a data row.
103
+ * @callback RowClassFunction
104
+ * @returns {string}
105
+ */
106
+ export type RowClassFunction = (
107
+ /** Data for the cell's row. */
108
+ item: any,
109
+ /** True if a cell on this row is focused. */
110
+ isFocused: boolean,
111
+ /** Classes as termined by grid properties. */
112
+ calcClass: string,
113
+ /** Default classes for a TableBodyRow component as defined by FlowBite. */
114
+ defaultClass: string,
115
+ /** trClassAppend from DataTable. */
116
+ appendClass: string,
117
+ /** trClassOveride from DataTable. */
118
+ overrideClass: string) => string;
119
+ /**
120
+ * Joins an array of classes into a string, removing any falsey values.
121
+ * @function joinClasses
122
+ * @param {...string} items - Strings of CSS classes to join.
123
+ * @returns {string}
124
+ */
125
+ export declare const joinClasses: (...classes: (string | false | null | undefined)[]) => string;
126
+ /**
127
+ * Values for enterAction on DataTable.
128
+ * @enum {string} EnterAction
129
+ */
130
+ export type EnterAction = 'next' | 'down' | 'stay';
131
+ export type GetTDClassFunction = (item: any, value: any, isFocused: boolean) => string;
132
+ export interface InternalColumnConfig extends ColumnConfig {
133
+ getTDClass: GetTDClassFunction;
134
+ }
135
+ export declare const blankCellValue: CellValue;
136
+ export declare const defaultCellRenderer: CellRenderer;
package/dist/common.js ADDED
@@ -0,0 +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
+ */
7
+ export const joinClasses = (...classes) => (classes || []).filter((value) => !!value).join(' ');
8
+ export const blankCellValue = {
9
+ dataValue: null,
10
+ displayValue: '',
11
+ };
12
+ export const defaultCellRenderer = async (column, item) => column.key
13
+ ? { dataValue: item[column.key], displayValue: item[column.key] || '' }
14
+ : blankCellValue;
@@ -0,0 +1,4 @@
1
+ import DataTable from './DataTable.svelte';
2
+ export type { CellRenderer, ColumnConfig, DataCellClassFunction, RowClassFunction, SortFunction, } from './common.js';
3
+ export * from './cells/index.js';
4
+ export default DataTable;
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import DataTable from './DataTable.svelte';
2
+ export * from './cells/index.js';
3
+ export default DataTable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emamid/svelte-data-table",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "homepage": "https://github.com/emamid/svelte-data-table",
5
5
  "scripts": {
6
6
  "dev": "vite dev",