@emamid/svelte-data-table 0.0.22 → 1.0.1
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 +303 -239
- package/dist/DataTable.svelte.d.ts +30 -60
- package/dist/DataTableDataCell.svelte +157 -90
- package/dist/DataTableDataCell.svelte.d.ts +18 -27
- package/dist/DataTableHeaderCell.svelte +63 -21
- package/dist/DataTableHeaderCell.svelte.d.ts +9 -23
- package/dist/DataTableIcon.svelte +25 -0
- package/dist/DataTableIcon.svelte.d.ts +9 -0
- package/dist/DataTableRow.svelte +150 -80
- package/dist/DataTableRow.svelte.d.ts +26 -34
- package/dist/cells/Actions.d.ts +1 -1
- package/dist/cells/Actions.js +10 -11
- package/dist/cells/ActionsCell.svelte +56 -33
- package/dist/cells/ActionsCell.svelte.d.ts +9 -47
- package/dist/cells/ButtonCell.svelte +58 -16
- package/dist/cells/ButtonCell.svelte.d.ts +11 -20
- package/dist/cells/CheckboxCell.svelte +72 -19
- package/dist/cells/CheckboxCell.svelte.d.ts +11 -22
- package/dist/cells/InputCell.svelte +93 -48
- package/dist/cells/InputCell.svelte.d.ts +14 -25
- package/dist/cells/MultiSelectCell.svelte +85 -25
- package/dist/cells/MultiSelectCell.svelte.d.ts +15 -26
- package/dist/cells/NumberInputCell.svelte +90 -44
- package/dist/cells/NumberInputCell.svelte.d.ts +13 -24
- package/dist/cells/RadioCell.svelte +66 -0
- package/dist/cells/RadioCell.svelte.d.ts +12 -0
- package/dist/cells/RangeCell.svelte +66 -17
- package/dist/cells/RangeCell.svelte.d.ts +13 -22
- package/dist/cells/SelectCell.svelte +87 -25
- package/dist/cells/SelectCell.svelte.d.ts +15 -26
- package/dist/cells/SpinCell.svelte +91 -42
- package/dist/cells/SpinCell.svelte.d.ts +13 -28
- package/dist/cells/TabWrapper.svelte +23 -21
- package/dist/cells/TabWrapper.svelte.d.ts +10 -22
- package/dist/cells/index.d.ts +2 -4
- package/dist/cells/index.js +2 -4
- package/dist/common.d.ts +199 -53
- package/dist/common.js +30 -11
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/themes/active.d.ts +4 -0
- package/dist/themes/active.js +12 -0
- package/dist/themes/daisyUI.d.ts +2 -0
- package/dist/themes/daisyUI.js +47 -0
- package/dist/themes/default.d.ts +2 -0
- package/dist/themes/default.js +57 -0
- package/dist/themes/iconify.d.ts +2 -0
- package/dist/themes/iconify.js +33 -0
- package/dist/themes/index.d.ts +4 -0
- package/dist/themes/index.js +4 -0
- package/package.json +28 -32
- package/dist/DataTable.doc.d.ts +0 -81
- package/dist/DataTable.doc.js +0 -81
- package/dist/cells/ActionsCell.doc.d.ts +0 -28
- package/dist/cells/ActionsCell.doc.js +0 -28
- package/dist/cells/ButtonCell.doc.d.ts +0 -9
- package/dist/cells/ButtonCell.doc.js +0 -9
- package/dist/cells/CheckboxCell.doc.d.ts +0 -6
- package/dist/cells/CheckboxCell.doc.js +0 -6
- package/dist/cells/InputCell.doc.d.ts +0 -6
- package/dist/cells/InputCell.doc.js +0 -6
- package/dist/cells/MultiSelectCell.doc.d.ts +0 -8
- package/dist/cells/MultiSelectCell.doc.js +0 -8
- package/dist/cells/NumberInputCell.doc.d.ts +0 -6
- package/dist/cells/NumberInputCell.doc.js +0 -6
- package/dist/cells/RangeCell.doc.d.ts +0 -7
- package/dist/cells/RangeCell.doc.js +0 -7
- package/dist/cells/RatingCell.doc.d.ts +0 -7
- package/dist/cells/RatingCell.doc.js +0 -7
- package/dist/cells/RatingCell.svelte +0 -13
- package/dist/cells/RatingCell.svelte.d.ts +0 -22
- package/dist/cells/SelectCell.doc.d.ts +0 -8
- package/dist/cells/SelectCell.doc.js +0 -8
- package/dist/cells/SpinCell.doc.d.ts +0 -13
- package/dist/cells/SpinCell.doc.js +0 -13
- package/dist/cells/TabWrapper.doc.d.ts +0 -5
- package/dist/cells/TabWrapper.doc.js +0 -5
- package/dist/cells/ToggleCell.doc.d.ts +0 -6
- package/dist/cells/ToggleCell.doc.js +0 -6
- package/dist/cells/ToggleCell.svelte +0 -21
- package/dist/cells/ToggleCell.svelte.d.ts +0 -23
|
@@ -1,21 +1,74 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
getDataTableContext,
|
|
4
|
+
joinInputClasses,
|
|
5
|
+
} from '../common';
|
|
6
|
+
import type {
|
|
7
|
+
ColumnConfig,
|
|
8
|
+
DataCellChangedEvent,
|
|
9
|
+
} from '../common';
|
|
10
|
+
import { activeTheme } from '../themes/active';
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
caption?: string;
|
|
14
|
+
column: ColumnConfig;
|
|
15
|
+
item: any;
|
|
16
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
17
|
+
value: any;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
caption = '',
|
|
23
|
+
column,
|
|
24
|
+
item,
|
|
25
|
+
oncellchanged,
|
|
26
|
+
value,
|
|
27
|
+
...inputProps
|
|
28
|
+
}: Props = $props();
|
|
29
|
+
|
|
30
|
+
let internalValue = $derived(value);
|
|
31
|
+
const tableTheme = getDataTableContext()?.theme || {};
|
|
32
|
+
|
|
33
|
+
const toggleChanged = () => {
|
|
34
|
+
oncellchanged?.({
|
|
35
|
+
column,
|
|
36
|
+
item,
|
|
37
|
+
oldValue: value,
|
|
38
|
+
newValue: internalValue,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const getClass = (element: string) => joinInputClasses(
|
|
43
|
+
'checkbox',
|
|
44
|
+
element, [
|
|
45
|
+
activeTheme,
|
|
46
|
+
tableTheme,
|
|
47
|
+
column.theme,
|
|
48
|
+
],
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
const labelClass = $derived(getClass('label'));
|
|
52
|
+
const inputClass = $derived(getClass('input'));
|
|
17
53
|
</script>
|
|
18
54
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
55
|
+
{#if caption}
|
|
56
|
+
<label class={labelClass}>
|
|
57
|
+
<input
|
|
58
|
+
bind:checked={internalValue}
|
|
59
|
+
class={inputClass}
|
|
60
|
+
onchange={toggleChanged}
|
|
61
|
+
type="checkbox"
|
|
62
|
+
{...inputProps}
|
|
63
|
+
/>
|
|
64
|
+
{caption}
|
|
65
|
+
</label>
|
|
66
|
+
{:else}
|
|
67
|
+
<input
|
|
68
|
+
bind:checked={internalValue}
|
|
69
|
+
class={inputClass}
|
|
70
|
+
onchange={toggleChanged}
|
|
71
|
+
type="checkbox"
|
|
72
|
+
{...inputProps}
|
|
73
|
+
/>
|
|
74
|
+
{/if}
|
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
value: any;
|
|
10
|
-
};
|
|
11
|
-
events: {
|
|
12
|
-
cellChanged: CustomEvent<any>;
|
|
13
|
-
} & {
|
|
14
|
-
[evt: string]: CustomEvent<any>;
|
|
15
|
-
};
|
|
16
|
-
slots: {};
|
|
17
|
-
};
|
|
18
|
-
export type CheckboxCellProps = typeof __propDef.props;
|
|
19
|
-
export type CheckboxCellEvents = typeof __propDef.events;
|
|
20
|
-
export type CheckboxCellSlots = typeof __propDef.slots;
|
|
21
|
-
export default class CheckboxCell extends SvelteComponent<CheckboxCellProps, CheckboxCellEvents, CheckboxCellSlots> {
|
|
1
|
+
import type { ColumnConfig, DataCellChangedEvent } from '../common';
|
|
2
|
+
interface Props {
|
|
3
|
+
caption?: string;
|
|
4
|
+
column: ColumnConfig;
|
|
5
|
+
item: any;
|
|
6
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
7
|
+
value: any;
|
|
8
|
+
[key: string]: any;
|
|
22
9
|
}
|
|
23
|
-
|
|
10
|
+
declare const CheckboxCell: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type CheckboxCell = ReturnType<typeof CheckboxCell>;
|
|
12
|
+
export default CheckboxCell;
|
|
@@ -1,54 +1,99 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
43
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
getDataTableContext,
|
|
4
|
+
joinInputClasses,
|
|
5
|
+
} from '../common';
|
|
6
|
+
import type {
|
|
7
|
+
ColumnConfig,
|
|
8
|
+
DataCellChangedEvent,
|
|
9
|
+
DataCellEvent,
|
|
10
|
+
} from '../common';
|
|
11
|
+
import { activeTheme } from '../themes/active';
|
|
12
|
+
|
|
13
|
+
import TabWrapper from './TabWrapper.svelte';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
column: ColumnConfig;
|
|
17
|
+
inputType?: string; // InputType;
|
|
18
|
+
item: any;
|
|
19
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
20
|
+
onenterpressed?: (event: DataCellEvent) => void;
|
|
21
|
+
onnexttab?: (event: DataCellEvent) => void;
|
|
22
|
+
onprevtab?: (event: DataCellEvent) => void;
|
|
23
|
+
value: string;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
let {
|
|
28
|
+
column,
|
|
29
|
+
inputType = 'text',
|
|
30
|
+
item,
|
|
31
|
+
oncellchanged,
|
|
32
|
+
onenterpressed,
|
|
33
|
+
onnexttab,
|
|
34
|
+
onprevtab,
|
|
35
|
+
value,
|
|
36
|
+
...inputProps
|
|
37
|
+
}: Props = $props();
|
|
38
|
+
|
|
39
|
+
let internalValue = $derived(value);
|
|
40
|
+
const tableTheme = getDataTableContext()?.theme || {};
|
|
41
|
+
|
|
42
|
+
const dispatchCellChanged = () => {
|
|
43
|
+
if (value !== internalValue) {
|
|
44
|
+
oncellchanged?.({
|
|
45
|
+
column,
|
|
46
|
+
item,
|
|
47
|
+
oldValue: value,
|
|
48
|
+
newValue: internalValue,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const keypress = (event: KeyboardEvent) => {
|
|
54
|
+
if (event.key === 'Enter') {
|
|
55
|
+
onenterpressed?.({
|
|
56
|
+
column,
|
|
57
|
+
item,
|
|
58
|
+
});
|
|
59
|
+
dispatchCellChanged();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const prevTab = (_event: any) => {
|
|
64
|
+
onprevtab?.({
|
|
65
|
+
column,
|
|
66
|
+
item,
|
|
67
|
+
});
|
|
68
|
+
dispatchCellChanged();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const nextTab = (_event: any) => {
|
|
72
|
+
onnexttab?.({
|
|
73
|
+
column,
|
|
74
|
+
item,
|
|
75
|
+
});
|
|
76
|
+
dispatchCellChanged();
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const inputClass = $derived(joinInputClasses(
|
|
80
|
+
'input',
|
|
81
|
+
'input', [
|
|
82
|
+
activeTheme,
|
|
83
|
+
tableTheme,
|
|
84
|
+
column.theme,
|
|
85
|
+
],
|
|
86
|
+
));
|
|
44
87
|
</script>
|
|
45
88
|
|
|
46
|
-
<TabWrapper
|
|
47
|
-
|
|
89
|
+
<TabWrapper column={column} item={item} onprevtab={prevTab} onnexttab={nextTab}>
|
|
90
|
+
<!-- svelte-ignore a11y_autofocus -->
|
|
91
|
+
<input
|
|
92
|
+
autofocus
|
|
93
|
+
class={inputClass}
|
|
94
|
+
onkeypress={keypress}
|
|
48
95
|
type={inputType}
|
|
49
96
|
bind:value={internalValue}
|
|
50
|
-
{
|
|
51
|
-
on:keypress={keypress}
|
|
52
|
-
autofocus
|
|
97
|
+
{...inputProps}
|
|
53
98
|
/>
|
|
54
99
|
</TabWrapper>
|
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
cellChanged: CustomEvent<any>;
|
|
13
|
-
enterPressed: CustomEvent<any>;
|
|
14
|
-
prevTab: CustomEvent<any>;
|
|
15
|
-
nextTab: CustomEvent<any>;
|
|
16
|
-
} & {
|
|
17
|
-
[evt: string]: CustomEvent<any>;
|
|
18
|
-
};
|
|
19
|
-
slots: {};
|
|
20
|
-
};
|
|
21
|
-
export type InputCellProps = typeof __propDef.props;
|
|
22
|
-
export type InputCellEvents = typeof __propDef.events;
|
|
23
|
-
export type InputCellSlots = typeof __propDef.slots;
|
|
24
|
-
export default class InputCell extends SvelteComponent<InputCellProps, InputCellEvents, InputCellSlots> {
|
|
1
|
+
import type { ColumnConfig, DataCellChangedEvent, DataCellEvent } from '../common';
|
|
2
|
+
interface Props {
|
|
3
|
+
column: ColumnConfig;
|
|
4
|
+
inputType?: string;
|
|
5
|
+
item: any;
|
|
6
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
7
|
+
onenterpressed?: (event: DataCellEvent) => void;
|
|
8
|
+
onnexttab?: (event: DataCellEvent) => void;
|
|
9
|
+
onprevtab?: (event: DataCellEvent) => void;
|
|
10
|
+
value: string;
|
|
11
|
+
[key: string]: any;
|
|
25
12
|
}
|
|
26
|
-
|
|
13
|
+
declare const InputCell: import("svelte").Component<Props, {}, "">;
|
|
14
|
+
type InputCell = ReturnType<typeof InputCell>;
|
|
15
|
+
export default InputCell;
|
|
@@ -1,29 +1,89 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
getDataTableContext,
|
|
4
|
+
joinInputClasses,
|
|
5
|
+
} from '../common';
|
|
6
|
+
import type {
|
|
7
|
+
ColumnConfig,
|
|
8
|
+
DataCellChangedEvent,
|
|
9
|
+
DataCellEvent,
|
|
10
|
+
} from '../common';
|
|
11
|
+
import { activeTheme } from '../themes/active';
|
|
12
|
+
|
|
13
|
+
import TabWrapper from './TabWrapper.svelte';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
column: ColumnConfig;
|
|
17
|
+
item: any;
|
|
18
|
+
displayProp?: string;
|
|
19
|
+
valueProp?: string;
|
|
20
|
+
items: any[];
|
|
21
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
22
|
+
onnexttab?: (event: DataCellEvent) => void;
|
|
23
|
+
onprevtab?: (event: DataCellEvent) => void;
|
|
24
|
+
value: any;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
column,
|
|
30
|
+
item,
|
|
31
|
+
displayProp = 'name',
|
|
32
|
+
valueProp = 'id',
|
|
33
|
+
items,
|
|
34
|
+
oncellchanged,
|
|
35
|
+
onnexttab,
|
|
36
|
+
onprevtab,
|
|
37
|
+
value,
|
|
38
|
+
...inputProps
|
|
39
|
+
}: Props = $props();
|
|
40
|
+
|
|
41
|
+
let internalValue = $derived(value);
|
|
42
|
+
const tableTheme = getDataTableContext()?.theme || {};
|
|
43
|
+
|
|
44
|
+
const dispatchCellChanged = () => {
|
|
45
|
+
if (value !== internalValue) {
|
|
46
|
+
oncellchanged?.({
|
|
47
|
+
column,
|
|
48
|
+
item,
|
|
49
|
+
oldValue: value,
|
|
50
|
+
newValue: internalValue,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const getClass = (element: string) => joinInputClasses(
|
|
56
|
+
'select',
|
|
57
|
+
element, [
|
|
58
|
+
activeTheme,
|
|
59
|
+
tableTheme,
|
|
60
|
+
column.theme,
|
|
61
|
+
],
|
|
62
|
+
)
|
|
20
63
|
</script>
|
|
21
64
|
|
|
22
|
-
<TabWrapper
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
65
|
+
<TabWrapper
|
|
66
|
+
{column}
|
|
67
|
+
{item}
|
|
68
|
+
{onprevtab}
|
|
69
|
+
{onnexttab}
|
|
70
|
+
>
|
|
71
|
+
<!-- svelte-ignore a11y_autofocus -->
|
|
72
|
+
<select
|
|
27
73
|
autofocus
|
|
28
|
-
|
|
74
|
+
class={getClass('select')}
|
|
75
|
+
multiple
|
|
76
|
+
onchange={dispatchCellChanged}
|
|
77
|
+
bind:value={internalValue}
|
|
78
|
+
{...inputProps}
|
|
79
|
+
>
|
|
80
|
+
{#each items as selectItem}
|
|
81
|
+
<option
|
|
82
|
+
class={getClass('option')}
|
|
83
|
+
value={selectItem[valueProp]}
|
|
84
|
+
>
|
|
85
|
+
{selectItem[displayProp]}
|
|
86
|
+
</option>
|
|
87
|
+
{/each}
|
|
88
|
+
</select>
|
|
29
89
|
</TabWrapper>
|
|
@@ -1,27 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
events: {
|
|
14
|
-
prevTab: CustomEvent<any>;
|
|
15
|
-
nextTab: CustomEvent<any>;
|
|
16
|
-
cellChanged: CustomEvent<any>;
|
|
17
|
-
} & {
|
|
18
|
-
[evt: string]: CustomEvent<any>;
|
|
19
|
-
};
|
|
20
|
-
slots: {};
|
|
21
|
-
};
|
|
22
|
-
export type MultiSelectCellProps = typeof __propDef.props;
|
|
23
|
-
export type MultiSelectCellEvents = typeof __propDef.events;
|
|
24
|
-
export type MultiSelectCellSlots = typeof __propDef.slots;
|
|
25
|
-
export default class MultiSelectCell extends SvelteComponent<MultiSelectCellProps, MultiSelectCellEvents, MultiSelectCellSlots> {
|
|
1
|
+
import type { ColumnConfig, DataCellChangedEvent, DataCellEvent } from '../common';
|
|
2
|
+
interface Props {
|
|
3
|
+
column: ColumnConfig;
|
|
4
|
+
item: any;
|
|
5
|
+
displayProp?: string;
|
|
6
|
+
valueProp?: string;
|
|
7
|
+
items: any[];
|
|
8
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
9
|
+
onnexttab?: (event: DataCellEvent) => void;
|
|
10
|
+
onprevtab?: (event: DataCellEvent) => void;
|
|
11
|
+
value: any;
|
|
12
|
+
[key: string]: any;
|
|
26
13
|
}
|
|
27
|
-
|
|
14
|
+
declare const MultiSelectCell: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type MultiSelectCell = ReturnType<typeof MultiSelectCell>;
|
|
16
|
+
export default MultiSelectCell;
|
|
@@ -1,47 +1,93 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
getDataTableContext,
|
|
4
|
+
joinInputClasses,
|
|
5
|
+
} from '../common';
|
|
6
|
+
import type { ColumnConfig, DataCellChangedEvent, DataCellEvent } from '../common';
|
|
7
|
+
import { activeTheme } from '../themes/active';
|
|
8
|
+
|
|
9
|
+
import TabWrapper from './TabWrapper.svelte';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
column: ColumnConfig;
|
|
13
|
+
item: any;
|
|
14
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
15
|
+
onenterpressed?: (event: DataCellEvent) => void;
|
|
16
|
+
onnexttab?: (event: DataCellEvent) => void;
|
|
17
|
+
onprevtab?: (event: DataCellEvent) => void;
|
|
18
|
+
value: number;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let {
|
|
23
|
+
column,
|
|
24
|
+
item,
|
|
25
|
+
oncellchanged,
|
|
26
|
+
onenterpressed,
|
|
27
|
+
onnexttab,
|
|
28
|
+
onprevtab,
|
|
29
|
+
value,
|
|
30
|
+
...inputProps
|
|
31
|
+
}: Props = $props();
|
|
32
|
+
|
|
33
|
+
let internalValue: number = $derived(value);
|
|
34
|
+
const tableTheme = getDataTableContext()?.theme || {};
|
|
35
|
+
|
|
36
|
+
const dispatchCellChanged = () => {
|
|
37
|
+
if (value !== internalValue) {
|
|
38
|
+
oncellchanged?.({
|
|
39
|
+
column,
|
|
40
|
+
item,
|
|
41
|
+
oldValue: value,
|
|
42
|
+
newValue: internalValue,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const keypress = (event: KeyboardEvent) => {
|
|
48
|
+
if (event.key === 'Enter') {
|
|
49
|
+
onenterpressed?.({
|
|
50
|
+
column,
|
|
51
|
+
item,
|
|
52
|
+
});
|
|
53
|
+
dispatchCellChanged();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const prevTab = (_event: any) => {
|
|
58
|
+
onprevtab?.({
|
|
59
|
+
column,
|
|
60
|
+
item,
|
|
61
|
+
});
|
|
62
|
+
dispatchCellChanged();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const nextTab = (_event: any) => {
|
|
66
|
+
onnexttab?.({
|
|
67
|
+
column,
|
|
68
|
+
item,
|
|
69
|
+
});
|
|
70
|
+
dispatchCellChanged();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const inputClass = $derived(joinInputClasses(
|
|
74
|
+
'numberInput',
|
|
75
|
+
'input', [
|
|
76
|
+
activeTheme,
|
|
77
|
+
tableTheme,
|
|
78
|
+
column.theme,
|
|
79
|
+
],
|
|
80
|
+
));
|
|
43
81
|
</script>
|
|
44
82
|
|
|
45
|
-
<TabWrapper
|
|
46
|
-
|
|
83
|
+
<TabWrapper column={column} item={item} onprevtab={prevTab} onnexttab={nextTab}>
|
|
84
|
+
<!-- svelte-ignore a11y_autofocus -->
|
|
85
|
+
<input
|
|
86
|
+
autofocus
|
|
87
|
+
class={inputClass}
|
|
88
|
+
onkeypress={keypress}
|
|
89
|
+
type="number"
|
|
90
|
+
bind:value={internalValue}
|
|
91
|
+
{...inputProps}
|
|
92
|
+
/>
|
|
47
93
|
</TabWrapper>
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
cellChanged: CustomEvent<any>;
|
|
12
|
-
enterPressed: CustomEvent<any>;
|
|
13
|
-
prevTab: CustomEvent<any>;
|
|
14
|
-
nextTab: CustomEvent<any>;
|
|
15
|
-
} & {
|
|
16
|
-
[evt: string]: CustomEvent<any>;
|
|
17
|
-
};
|
|
18
|
-
slots: {};
|
|
19
|
-
};
|
|
20
|
-
export type NumberInputCellProps = typeof __propDef.props;
|
|
21
|
-
export type NumberInputCellEvents = typeof __propDef.events;
|
|
22
|
-
export type NumberInputCellSlots = typeof __propDef.slots;
|
|
23
|
-
export default class NumberInputCell extends SvelteComponent<NumberInputCellProps, NumberInputCellEvents, NumberInputCellSlots> {
|
|
1
|
+
import type { ColumnConfig, DataCellChangedEvent, DataCellEvent } from '../common';
|
|
2
|
+
interface Props {
|
|
3
|
+
column: ColumnConfig;
|
|
4
|
+
item: any;
|
|
5
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
6
|
+
onenterpressed?: (event: DataCellEvent) => void;
|
|
7
|
+
onnexttab?: (event: DataCellEvent) => void;
|
|
8
|
+
onprevtab?: (event: DataCellEvent) => void;
|
|
9
|
+
value: number;
|
|
10
|
+
[key: string]: any;
|
|
24
11
|
}
|
|
25
|
-
|
|
12
|
+
declare const NumberInputCell: import("svelte").Component<Props, {}, "">;
|
|
13
|
+
type NumberInputCell = ReturnType<typeof NumberInputCell>;
|
|
14
|
+
export default NumberInputCell;
|