@emamid/svelte-data-table 0.0.1 → 0.0.2
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/dist/DataTable.svelte +34 -9
- package/dist/DataTable.svelte.d.ts +1 -1
- package/dist/DataTableDataCell.svelte +37 -39
- package/dist/DataTableDataCell.svelte.d.ts +1 -1
- package/dist/DataTableHeaderCell.svelte +3 -3
- package/dist/DataTableHeaderCell.svelte.d.ts +1 -1
- package/dist/cells/ActionsCell.svelte +3 -2
- package/dist/cells/ActionsCell.svelte.d.ts +1 -1
- package/dist/cells/ButtonCell.svelte +3 -1
- package/dist/cells/ButtonCell.svelte.d.ts +1 -1
- package/dist/cells/CheckboxCell.svelte +3 -1
- package/dist/cells/CheckboxCell.svelte.d.ts +1 -1
- package/dist/cells/InputCell.svelte +7 -1
- package/dist/cells/InputCell.svelte.d.ts +1 -1
- package/dist/cells/NumberInputCell.svelte +1 -1
- package/dist/cells/NumberInputCell.svelte.d.ts +1 -1
- package/dist/cells/SelectCell.svelte +1 -1
- package/dist/cells/SelectCell.svelte.d.ts +1 -1
- package/dist/cells/SpinCell.svelte +15 -3
- package/dist/cells/SpinCell.svelte.d.ts +1 -1
- package/dist/cells/TabWrapper.svelte +2 -2
- package/dist/cells/TabWrapper.svelte.d.ts +1 -1
- package/dist/cells/ToggleCell.svelte +3 -1
- package/dist/cells/ToggleCell.svelte.d.ts +1 -1
- package/dist/cells/index.d.ts +1 -1
- package/dist/cells/index.js +1 -1
- package/dist/common.js +4 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +4 -4
package/dist/DataTable.svelte
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Table, TableBody, TableBodyRow, TableHead } from "flowbite-svelte";
|
|
3
3
|
import DataTableDataCell from "./DataTableDataCell.svelte";
|
|
4
4
|
import DataTableHeaderCell from "./DataTableHeaderCell.svelte";
|
|
5
|
-
import { joinClasses } from "./common.
|
|
5
|
+
import { joinClasses } from "./common.js";
|
|
6
6
|
export let columns = [];
|
|
7
7
|
export let items = [];
|
|
8
8
|
export let sortKey = "";
|
|
@@ -63,18 +63,36 @@ const divClass = joinClasses(divClassOverride || divClassDefault, divClassAppend
|
|
|
63
63
|
const tableClass = joinClasses(tableClassOverride || tableClassDefault, tableClassAppend);
|
|
64
64
|
const theadClass = joinClasses(theadClassOverride || theadClassDefault, theadClassAppend);
|
|
65
65
|
const thClass = joinClasses(thClassOverride || thClassDefault, thClassAppend);
|
|
66
|
-
const tableBodyClass = joinClasses(
|
|
66
|
+
const tableBodyClass = joinClasses(
|
|
67
|
+
tableBodyClassOverride || tableBodyClassDefault,
|
|
68
|
+
tableBodyClassAppend
|
|
69
|
+
);
|
|
67
70
|
const trClass = joinClasses(trClassOverride || trClassDefault, trClassAppend);
|
|
68
71
|
const tdClass = joinClasses(tdClassOverride || tdClassDefault, tdClassAppend);
|
|
69
|
-
const tdFocusedClass = joinClasses(
|
|
72
|
+
const tdFocusedClass = joinClasses(
|
|
73
|
+
tdFocusedClassOverride || tdFocusedClassDefault,
|
|
74
|
+
tdFocusedClassAppend
|
|
75
|
+
);
|
|
70
76
|
const getTRClass = (item, isRowFocused) => trClassGetter ? trClassGetter(item, isRowFocused, trClass, trClassDefault, trClassAppend, trClassOverride) : trClass;
|
|
71
77
|
const internalColumns = columns.map((column) => {
|
|
72
78
|
const columnTDClass = joinClasses(column.tdClassOverride || tdClass, column.tdClassAppend);
|
|
73
|
-
const columnFocusedTDClass = joinClasses(
|
|
79
|
+
const columnFocusedTDClass = joinClasses(
|
|
80
|
+
column.tdFocusedClassOverride || tdFocusedClass,
|
|
81
|
+
column.tdFocusedClassAppend
|
|
82
|
+
);
|
|
74
83
|
let getTDClass;
|
|
75
84
|
const tdClassGetter = column.tdClassGetter;
|
|
76
85
|
if (tdClassGetter) {
|
|
77
|
-
getTDClass = (item, value, isFocused) => tdClassGetter(
|
|
86
|
+
getTDClass = (item, value, isFocused) => tdClassGetter(
|
|
87
|
+
item,
|
|
88
|
+
column,
|
|
89
|
+
value,
|
|
90
|
+
isFocused,
|
|
91
|
+
columnTDClass,
|
|
92
|
+
tdClassDefault,
|
|
93
|
+
tdClassAppend,
|
|
94
|
+
tdClassOverride
|
|
95
|
+
);
|
|
78
96
|
} else {
|
|
79
97
|
getTDClass = (_item, _value, isFocused) => isFocused ? columnFocusedTDClass : columnTDClass;
|
|
80
98
|
}
|
|
@@ -172,15 +190,22 @@ const rowClicked = (item) => {
|
|
|
172
190
|
<Table class={tableClass} {divClass}>
|
|
173
191
|
<TableHead defaultRow={false} {theadClass}>
|
|
174
192
|
{#each internalColumns as column}
|
|
175
|
-
<DataTableHeaderCell
|
|
193
|
+
<DataTableHeaderCell
|
|
194
|
+
{column}
|
|
195
|
+
isSorted={!!sortColumnID && getColumnID(column) === sortColumnID}
|
|
196
|
+
{reverseSort}
|
|
197
|
+
{thClass}
|
|
198
|
+
on:click={() => headerClicked(column)}
|
|
199
|
+
/>
|
|
176
200
|
{/each}
|
|
177
201
|
</TableHead>
|
|
178
202
|
<TableBody {tableBodyClass}>
|
|
179
203
|
{#each sortedItems as item}
|
|
180
|
-
|
|
204
|
+
{@const isRowFocused = !!focusedItemKey && focusedItemKey === getItemKey(item)}
|
|
181
205
|
<TableBodyRow class={getTRClass(item, isRowFocused)} on:click={() => rowClicked(item)}>
|
|
182
206
|
{#each internalColumns as column}
|
|
183
|
-
{@const isCellFocused =
|
|
207
|
+
{@const isCellFocused =
|
|
208
|
+
isRowFocused && focusedColumnKeyID && focusedColumnKeyID === getColumnID(column)}
|
|
184
209
|
<DataTableDataCell
|
|
185
210
|
{column}
|
|
186
211
|
{isCellFocused}
|
|
@@ -197,4 +222,4 @@ const rowClicked = (item) => {
|
|
|
197
222
|
</TableBodyRow>
|
|
198
223
|
{/each}
|
|
199
224
|
</TableBody>
|
|
200
|
-
</Table>
|
|
225
|
+
</Table>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type { ColumnConfig, EnterAction, RowClassFunction, SortFunction } from './common.
|
|
2
|
+
import type { ColumnConfig, EnterAction, RowClassFunction, SortFunction } from './common.js';
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
5
|
columns?: ColumnConfig[] | undefined;
|
|
@@ -1,50 +1,48 @@
|
|
|
1
1
|
<script>import { TableBodyCell } from "flowbite-svelte";
|
|
2
|
-
import { defaultCellRenderer } from "./common.
|
|
2
|
+
import { defaultCellRenderer } from "./common.js";
|
|
3
3
|
export let column;
|
|
4
4
|
export let item;
|
|
5
5
|
export let isCellFocused;
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
{#await (column.cellRenderer || defaultCellRenderer)(column, item)}
|
|
9
|
-
<TableBodyCell tdClass={column.getTDClass(item, '', isCellFocused)}/>
|
|
10
|
-
{:then {dataValue, displayValue}}
|
|
11
|
-
<TableBodyCell tdClass={column.getTDClass(item, dataValue, isCellFocused)} on:click>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/>
|
|
9
|
+
<TableBodyCell tdClass={column.getTDClass(item, '', isCellFocused)} />
|
|
10
|
+
{:then { dataValue, displayValue }}
|
|
11
|
+
<TableBodyCell tdClass={column.getTDClass(item, dataValue, isCellFocused)} on:click>
|
|
12
|
+
{#if column.viewComponent}
|
|
13
|
+
<svelte:component
|
|
14
|
+
this={column.viewComponent}
|
|
15
|
+
{column}
|
|
16
|
+
{item}
|
|
17
|
+
value={dataValue}
|
|
18
|
+
on:action
|
|
19
|
+
on:cellChanged
|
|
20
|
+
on:cellInput
|
|
21
|
+
on:click
|
|
22
|
+
on:enterPressed
|
|
23
|
+
on:prevTab
|
|
24
|
+
on:nextTab
|
|
25
|
+
{...column.viewComponentConfig}
|
|
26
|
+
/>
|
|
27
|
+
{:else if column.focusComponent && isCellFocused}
|
|
28
|
+
<svelte:component
|
|
29
|
+
this={column.focusComponent}
|
|
30
|
+
{column}
|
|
31
|
+
{item}
|
|
32
|
+
value={dataValue}
|
|
33
|
+
on:action
|
|
34
|
+
on:cellChanged
|
|
35
|
+
on:cellInput
|
|
36
|
+
on:click
|
|
37
|
+
on:enterPressed
|
|
38
|
+
on:prevTab
|
|
39
|
+
on:nextTab
|
|
40
|
+
{...column.focusComponentConfig}
|
|
41
|
+
/>
|
|
43
42
|
{:else}
|
|
44
|
-
|
|
43
|
+
{displayValue}
|
|
45
44
|
{/if}
|
|
46
|
-
|
|
47
|
-
</TableBodyCell>
|
|
45
|
+
</TableBodyCell>
|
|
48
46
|
{:catch}
|
|
49
|
-
<TableBodyCell tdClass={column.getTDClass(item, '', isCellFocused)} />
|
|
47
|
+
<TableBodyCell tdClass={column.getTDClass(item, '', isCellFocused)} />
|
|
50
48
|
{/await}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>import { TableHeadCell } from "flowbite-svelte";
|
|
2
2
|
import { ArrowDownSolid, ArrowUpSolid } from "flowbite-svelte-icons";
|
|
3
|
-
import { joinClasses } from "./common.
|
|
3
|
+
import { joinClasses } from "./common.js";
|
|
4
4
|
export let column;
|
|
5
5
|
export let reverseSort;
|
|
6
6
|
export let isSorted;
|
|
@@ -13,9 +13,9 @@ export let thClass;
|
|
|
13
13
|
>
|
|
14
14
|
{#if isSorted}
|
|
15
15
|
{#if reverseSort}
|
|
16
|
-
|
|
16
|
+
<ArrowUpSolid class="inline" />
|
|
17
17
|
{:else}
|
|
18
|
-
|
|
18
|
+
<ArrowDownSolid class="inline" />
|
|
19
19
|
{/if}
|
|
20
20
|
{/if}
|
|
21
21
|
<span>{column.title}</span>
|
|
@@ -23,8 +23,9 @@ const actionClicked = (action) => {
|
|
|
23
23
|
class={action.buttonClass || buttonClass}
|
|
24
24
|
color={action.buttonColor || buttonColor}
|
|
25
25
|
disabled={action.isDisabled?.(item, column, action)}
|
|
26
|
-
on:click={() => actionClicked(action)}
|
|
27
|
-
|
|
26
|
+
on:click={() => actionClicked(action)}
|
|
27
|
+
>
|
|
28
|
+
<svelte:component this={action.icon} class={action.iconClass || iconClass} />
|
|
28
29
|
{#if action.caption}{action.caption}{/if}
|
|
29
30
|
</Button>
|
|
30
31
|
{/each}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type { ColumnConfig } from '../common.
|
|
2
|
+
import type { ColumnConfig } from '../common.js';
|
|
3
3
|
type ButtonColor = 'red' | 'yellow' | 'green' | 'purple' | 'blue' | 'light' | 'dark' | 'primary' | 'none' | 'alternative' | undefined;
|
|
4
4
|
export interface Action {
|
|
5
5
|
buttonClass?: string;
|
|
@@ -16,4 +16,6 @@ const toggleChanged = () => {
|
|
|
16
16
|
};
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
|
-
<Checkbox {...$$props} bind:checked={localValue} on:change={toggleChanged}
|
|
19
|
+
<Checkbox {...$$props} bind:checked={localValue} on:change={toggleChanged}
|
|
20
|
+
>{#if caption}{caption}{/if}</Checkbox
|
|
21
|
+
>
|
|
@@ -45,5 +45,11 @@ const nextTab = (_event) => {
|
|
|
45
45
|
</script>
|
|
46
46
|
|
|
47
47
|
<TabWrapper on:prevTab={prevTab} on:nextTab={nextTab}>
|
|
48
|
-
<Input
|
|
48
|
+
<Input
|
|
49
|
+
type={inputType}
|
|
50
|
+
bind:value={internalValue}
|
|
51
|
+
{...$$props}
|
|
52
|
+
on:keypress={keypress}
|
|
53
|
+
autofocus
|
|
54
|
+
/>
|
|
49
55
|
</TabWrapper>
|
|
@@ -44,5 +44,5 @@ const nextTab = (_event) => {
|
|
|
44
44
|
</script>
|
|
45
45
|
|
|
46
46
|
<TabWrapper on:prevTab={prevTab} on:nextTab={nextTab}>
|
|
47
|
-
<NumberInput bind:value={internalValue} {...$$props} on:keypress={keypress} autofocus/>
|
|
47
|
+
<NumberInput bind:value={internalValue} {...$$props} on:keypress={keypress} autofocus />
|
|
48
48
|
</TabWrapper>
|
|
@@ -23,7 +23,7 @@ $:
|
|
|
23
23
|
<TabWrapper {column} {item} on:prevTab on:nextTab>
|
|
24
24
|
<Select
|
|
25
25
|
{...$$props}
|
|
26
|
-
items={items.map(item => ({ value: item[valueProp], name: item[displayProp]}))}
|
|
26
|
+
items={items.map((item) => ({ value: item[valueProp], name: item[displayProp] }))}
|
|
27
27
|
bind:value={newValue}
|
|
28
28
|
autofocus
|
|
29
29
|
/>
|
|
@@ -32,9 +32,21 @@ const increment = () => {
|
|
|
32
32
|
</script>
|
|
33
33
|
|
|
34
34
|
<div class="spinner">
|
|
35
|
-
<Button
|
|
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
|
+
>
|
|
36
42
|
{value || 0}
|
|
37
|
-
<Button
|
|
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
|
+
>
|
|
38
50
|
</div>
|
|
39
51
|
|
|
40
52
|
<style>
|
|
@@ -44,4 +56,4 @@ const increment = () => {
|
|
|
44
56
|
justify-content: center;
|
|
45
57
|
align-items: center;
|
|
46
58
|
}
|
|
47
|
-
</style>
|
|
59
|
+
</style>
|
|
@@ -17,7 +17,7 @@ const nextTab = (_event) => {
|
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
19
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex-->
|
|
20
|
-
<div tabindex="0" on:focus={prevTab}/>
|
|
20
|
+
<div tabindex="0" on:focus={prevTab} />
|
|
21
21
|
<slot />
|
|
22
22
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex-->
|
|
23
|
-
<div tabindex="0" on:focus={nextTab}/>
|
|
23
|
+
<div tabindex="0" on:focus={nextTab} />
|
|
@@ -16,4 +16,6 @@ const toggleChanged = () => {
|
|
|
16
16
|
};
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
|
-
<Toggle {...$$props} bind:checked={localValue} on:change={toggleChanged}
|
|
19
|
+
<Toggle {...$$props} bind:checked={localValue} on:change={toggleChanged}
|
|
20
|
+
>{#if caption}{caption}{/if}</Toggle
|
|
21
|
+
>
|
package/dist/cells/index.d.ts
CHANGED
package/dist/cells/index.js
CHANGED
package/dist/common.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export const joinClasses = (...classes) => (classes || []).filter(value => !!value).join(' ');
|
|
1
|
+
export const joinClasses = (...classes) => (classes || []).filter((value) => !!value).join(' ');
|
|
2
2
|
export const blankCellValues = {
|
|
3
3
|
dataValue: null,
|
|
4
4
|
displayValue: '',
|
|
5
5
|
};
|
|
6
|
-
export const defaultCellRenderer = async (column, item) => column.key
|
|
6
|
+
export const defaultCellRenderer = async (column, item) => column.key
|
|
7
|
+
? { dataValue: item[column.key], displayValue: item[column.key] || '' }
|
|
8
|
+
: blankCellValues;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import DataTable from './DataTable.svelte';
|
|
2
|
-
export type { CellRenderer, ColumnConfig, DataCellClassFunction, RowClassFunction, SortFunction } from './common.
|
|
3
|
-
export * from './cells/index.
|
|
2
|
+
export type { CellRenderer, ColumnConfig, DataCellClassFunction, RowClassFunction, SortFunction, } from './common.js';
|
|
3
|
+
export * from './cells/index.js';
|
|
4
4
|
export default DataTable;
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emamid/svelte-data-table",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "vite build && npm run package",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"eslint": "^8.56.0",
|
|
39
39
|
"eslint-config-prettier": "^9.1.0",
|
|
40
40
|
"eslint-plugin-svelte": "^2.35.1",
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
"flowbite": "^2.2.1",
|
|
42
|
+
"flowbite-svelte": "^0.44.22",
|
|
43
|
+
"flowbite-svelte-icons": "^1.0.2",
|
|
44
44
|
"prettier": "^3.1.1",
|
|
45
45
|
"prettier-plugin-svelte": "^3.1.2",
|
|
46
46
|
"publint": "^0.1.9",
|