svelte-tably 1.0.0-next.7 → 1.0.0-next.9
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 +5 -3
- package/dist/Column.svelte +110 -51
- package/dist/Column.svelte.d.ts +75 -30
- package/dist/Table.svelte +604 -258
- package/dist/Table.svelte.d.ts +51 -47
- package/dist/trigger.svelte.d.ts +10 -0
- package/dist/trigger.svelte.js +27 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,12 +14,13 @@ A high performant dynamic table
|
|
|
14
14
|
- [x] "Virtual" data (for sorting/filtering)
|
|
15
15
|
- [x] Panels
|
|
16
16
|
- [x] Virtual elements
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
17
|
+
- [x] sorting
|
|
18
|
+
- [x] select
|
|
19
19
|
- [ ] filtering
|
|
20
20
|
- [ ] orderable table
|
|
21
21
|
- [ ] row context-menu
|
|
22
22
|
- [ ] dropout section
|
|
23
|
+
- [ ] csv export
|
|
23
24
|
|
|
24
25
|
### Usage Notes
|
|
25
26
|
|
|
@@ -33,9 +34,10 @@ A high performant dynamic table
|
|
|
33
34
|
])
|
|
34
35
|
|
|
35
36
|
let activePanel = $state('columns') as string | undefined
|
|
37
|
+
let selected = $state([]) as typeof data
|
|
36
38
|
</script>
|
|
37
39
|
|
|
38
|
-
<Table {data} panel={activePanel}>
|
|
40
|
+
<Table {data} panel={activePanel} select bind:selected>
|
|
39
41
|
{#snippet content({ Column, Panel, state, data })}
|
|
40
42
|
<Column id='name' sticky>
|
|
41
43
|
{#snippet header()}
|
package/dist/Column.svelte
CHANGED
|
@@ -8,24 +8,92 @@
|
|
|
8
8
|
|
|
9
9
|
-->
|
|
10
10
|
|
|
11
|
-
<script module lang=
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
<script module lang="ts">
|
|
12
|
+
export type RowCtx<V> = {
|
|
13
|
+
readonly value: V
|
|
14
|
+
readonly isHovered: boolean
|
|
15
|
+
readonly index: number
|
|
16
|
+
selected: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ColumnProps<T, V> {
|
|
20
|
+
header?: Snippet<
|
|
21
|
+
[
|
|
22
|
+
/**
|
|
23
|
+
* Is true when displaying in the header,
|
|
24
|
+
* so additional content can be shown if desired,
|
|
25
|
+
* so the header snippet can be re-used.
|
|
26
|
+
*/
|
|
27
|
+
header?: boolean
|
|
28
|
+
]
|
|
29
|
+
>
|
|
30
|
+
row: Snippet<[item: T, row: RowCtx<V>]>
|
|
27
31
|
statusbar?: Snippet
|
|
28
|
-
|
|
32
|
+
|
|
33
|
+
id: string
|
|
34
|
+
|
|
35
|
+
// options
|
|
36
|
+
/**
|
|
37
|
+
* Is this column sticky by default?
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
sticky?: boolean
|
|
41
|
+
/**
|
|
42
|
+
* Fixed is like sticky, but in its own category — meant to not be moved/hidden ex. select-boxes
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
fixed?: boolean
|
|
46
|
+
/**
|
|
47
|
+
* Is this column sorted by default?
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
sort?: boolean
|
|
51
|
+
/**
|
|
52
|
+
* Is this column visible by default?
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
show?: boolean
|
|
56
|
+
/**
|
|
57
|
+
* The width of the column in pixels by default
|
|
58
|
+
* @default 150
|
|
59
|
+
*/
|
|
60
|
+
width?: number
|
|
61
|
+
/**
|
|
62
|
+
* The value of the row. Required for sorting/filtering
|
|
63
|
+
* @example row => row.name
|
|
64
|
+
*/
|
|
65
|
+
value?: (item: T) => V
|
|
66
|
+
/**
|
|
67
|
+
* Makes the column sortable. Sorts based of a sorting function.
|
|
68
|
+
*
|
|
69
|
+
* **Important** `value`-attribute is required adjacent to this.
|
|
70
|
+
*
|
|
71
|
+
* If `true` uses the default `.sort()` algorithm.
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
sorting?: boolean | ((a: V, b: V) => number)
|
|
76
|
+
/**
|
|
77
|
+
* Is this column resizeable?
|
|
78
|
+
* Can not be resized if Table is marked as `resizeable={false}`
|
|
79
|
+
* @default true
|
|
80
|
+
*/
|
|
81
|
+
resizeable?: boolean
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Optional: Provide the table it is a part of
|
|
85
|
+
*/
|
|
86
|
+
table?: TableState
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ColumnState<T = unknown, V = unknown, C extends ColumnProps<T, V> = ColumnProps<T, V>> {
|
|
90
|
+
id: C['id']
|
|
91
|
+
header?: C['header']
|
|
92
|
+
row: C['row']
|
|
93
|
+
statusbar?: C['statusbar']
|
|
94
|
+
|
|
95
|
+
fixed?: boolean
|
|
96
|
+
|
|
29
97
|
/** Default options for initial table */
|
|
30
98
|
defaults: {
|
|
31
99
|
sticky?: boolean
|
|
@@ -35,53 +103,45 @@
|
|
|
35
103
|
}
|
|
36
104
|
/** More options */
|
|
37
105
|
options: {
|
|
38
|
-
value?:
|
|
39
|
-
sorting?:
|
|
106
|
+
value?: C['value']
|
|
107
|
+
sorting?: boolean | ((a: any, b: any) => number)
|
|
40
108
|
resizeable: boolean
|
|
41
109
|
}
|
|
42
110
|
}
|
|
43
|
-
|
|
44
111
|
</script>
|
|
45
112
|
|
|
46
|
-
<script lang=
|
|
47
|
-
|
|
113
|
+
<script lang="ts">
|
|
48
114
|
import { onDestroy, type Snippet } from 'svelte'
|
|
49
|
-
import { getTableState } from './Table.svelte'
|
|
50
|
-
|
|
51
|
-
interface Props {
|
|
52
|
-
header?: Column<T, V>['header']
|
|
53
|
-
row: Column<T, V>['row']
|
|
54
|
-
statusbar?: Column<T, V>['statusbar']
|
|
115
|
+
import { getTableState, type TableState } from './Table.svelte'
|
|
55
116
|
|
|
56
|
-
|
|
117
|
+
type T = $$Generic<Record<PropertyKey, any>>
|
|
118
|
+
type V = $$Generic
|
|
57
119
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
value?: Column<T, V>['options']['value']
|
|
64
|
-
sorting?: Column<T, V>['options']['sorting']
|
|
65
|
-
/** @default true */
|
|
66
|
-
resizeable?: boolean
|
|
67
|
-
}
|
|
120
|
+
let {
|
|
121
|
+
header,
|
|
122
|
+
row,
|
|
123
|
+
statusbar,
|
|
124
|
+
id,
|
|
68
125
|
|
|
69
|
-
let {
|
|
70
|
-
header, row, statusbar, id,
|
|
71
|
-
|
|
72
126
|
sticky = false,
|
|
73
|
-
|
|
127
|
+
fixed = false,
|
|
128
|
+
sort = false,
|
|
74
129
|
show = true,
|
|
75
130
|
width,
|
|
76
|
-
|
|
131
|
+
|
|
77
132
|
resizeable = true,
|
|
78
|
-
value,
|
|
79
|
-
|
|
133
|
+
value,
|
|
134
|
+
sorting,
|
|
135
|
+
|
|
136
|
+
table
|
|
137
|
+
}: ColumnProps<T, V> = $props()
|
|
80
138
|
|
|
81
|
-
const column:
|
|
139
|
+
const column: ColumnState<T, V> = $state({
|
|
140
|
+
id,
|
|
82
141
|
header,
|
|
83
142
|
row,
|
|
84
143
|
statusbar,
|
|
144
|
+
fixed,
|
|
85
145
|
defaults: {
|
|
86
146
|
sticky,
|
|
87
147
|
sort,
|
|
@@ -95,11 +155,10 @@
|
|
|
95
155
|
}
|
|
96
156
|
})
|
|
97
157
|
|
|
98
|
-
|
|
99
|
-
table.addColumn(id, column as
|
|
158
|
+
table ??= getTableState()
|
|
159
|
+
table.addColumn(id, column as ColumnState)
|
|
100
160
|
|
|
101
161
|
onDestroy(() => {
|
|
102
162
|
table.removeColumn(id)
|
|
103
163
|
})
|
|
104
|
-
|
|
105
|
-
</script>
|
|
164
|
+
</script>
|
package/dist/Column.svelte.d.ts
CHANGED
|
@@ -1,21 +1,78 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type RowCtx<V> = {
|
|
2
|
+
readonly value: V;
|
|
3
|
+
readonly isHovered: boolean;
|
|
4
|
+
readonly index: number;
|
|
5
|
+
selected: boolean;
|
|
6
|
+
};
|
|
7
|
+
export interface ColumnProps<T, V> {
|
|
2
8
|
header?: Snippet<[
|
|
3
9
|
/**
|
|
4
10
|
* Is true when displaying in the header,
|
|
5
11
|
* so additional content can be shown if desired,
|
|
6
12
|
* so the header snippet can be re-used.
|
|
7
|
-
|
|
13
|
+
*/
|
|
8
14
|
header?: boolean
|
|
9
15
|
]>;
|
|
10
|
-
row: Snippet<[
|
|
11
|
-
item: T,
|
|
12
|
-
row: {
|
|
13
|
-
readonly value: V;
|
|
14
|
-
readonly isHovered: boolean;
|
|
15
|
-
readonly index: number;
|
|
16
|
-
}
|
|
17
|
-
]>;
|
|
16
|
+
row: Snippet<[item: T, row: RowCtx<V>]>;
|
|
18
17
|
statusbar?: Snippet;
|
|
18
|
+
id: string;
|
|
19
|
+
/**
|
|
20
|
+
* Is this column sticky by default?
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
sticky?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Fixed is like sticky, but in its own category — meant to not be moved/hidden ex. select-boxes
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
fixed?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Is this column sorted by default?
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
sort?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Is this column visible by default?
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
show?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The width of the column in pixels by default
|
|
41
|
+
* @default 150
|
|
42
|
+
*/
|
|
43
|
+
width?: number;
|
|
44
|
+
/**
|
|
45
|
+
* The value of the row. Required for sorting/filtering
|
|
46
|
+
* @example row => row.name
|
|
47
|
+
*/
|
|
48
|
+
value?: (item: T) => V;
|
|
49
|
+
/**
|
|
50
|
+
* Makes the column sortable. Sorts based of a sorting function.
|
|
51
|
+
*
|
|
52
|
+
* **Important** `value`-attribute is required adjacent to this.
|
|
53
|
+
*
|
|
54
|
+
* If `true` uses the default `.sort()` algorithm.
|
|
55
|
+
*
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
sorting?: boolean | ((a: V, b: V) => number);
|
|
59
|
+
/**
|
|
60
|
+
* Is this column resizeable?
|
|
61
|
+
* Can not be resized if Table is marked as `resizeable={false}`
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
resizeable?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Optional: Provide the table it is a part of
|
|
67
|
+
*/
|
|
68
|
+
table?: TableState;
|
|
69
|
+
}
|
|
70
|
+
export interface ColumnState<T = unknown, V = unknown, C extends ColumnProps<T, V> = ColumnProps<T, V>> {
|
|
71
|
+
id: C['id'];
|
|
72
|
+
header?: C['header'];
|
|
73
|
+
row: C['row'];
|
|
74
|
+
statusbar?: C['statusbar'];
|
|
75
|
+
fixed?: boolean;
|
|
19
76
|
/** Default options for initial table */
|
|
20
77
|
defaults: {
|
|
21
78
|
sticky?: boolean;
|
|
@@ -25,37 +82,25 @@ export interface Column<T = unknown, V = unknown> {
|
|
|
25
82
|
};
|
|
26
83
|
/** More options */
|
|
27
84
|
options: {
|
|
28
|
-
value?:
|
|
29
|
-
sorting?:
|
|
85
|
+
value?: C['value'];
|
|
86
|
+
sorting?: boolean | ((a: any, b: any) => number);
|
|
30
87
|
resizeable: boolean;
|
|
31
88
|
};
|
|
32
89
|
}
|
|
33
90
|
import { type Snippet } from 'svelte';
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
row: Column<T_1, V_1>["row"];
|
|
38
|
-
statusbar?: Column<T_1, V_1>["statusbar"];
|
|
39
|
-
id: string;
|
|
40
|
-
sticky?: boolean;
|
|
41
|
-
sort?: boolean;
|
|
42
|
-
show?: boolean;
|
|
43
|
-
width?: number;
|
|
44
|
-
value?: Column<T_1, V_1>["options"]["value"];
|
|
45
|
-
sorting?: Column<T_1, V_1>["options"]["sorting"];
|
|
46
|
-
/** @default true */
|
|
47
|
-
resizeable?: boolean;
|
|
48
|
-
};
|
|
91
|
+
import { type TableState } from './Table.svelte';
|
|
92
|
+
declare class __sveltets_Render<T extends Record<PropertyKey, any>, V> {
|
|
93
|
+
props(): ColumnProps<T, V>;
|
|
49
94
|
events(): {};
|
|
50
95
|
slots(): {};
|
|
51
96
|
bindings(): "";
|
|
52
97
|
exports(): {};
|
|
53
98
|
}
|
|
54
99
|
interface $$IsomorphicComponent {
|
|
55
|
-
new <T extends Record<PropertyKey, any>, V
|
|
100
|
+
new <T extends Record<PropertyKey, any>, V>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T, V>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T, V>['props']>, ReturnType<__sveltets_Render<T, V>['events']>, ReturnType<__sveltets_Render<T, V>['slots']>> & {
|
|
56
101
|
$$bindings?: ReturnType<__sveltets_Render<T, V>['bindings']>;
|
|
57
102
|
} & ReturnType<__sveltets_Render<T, V>['exports']>;
|
|
58
|
-
<T extends Record<PropertyKey, any>, V
|
|
103
|
+
<T extends Record<PropertyKey, any>, V>(internal: unknown, props: ReturnType<__sveltets_Render<T, V>['props']> & {}): ReturnType<__sveltets_Render<T, V>['exports']>;
|
|
59
104
|
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
60
105
|
}
|
|
61
106
|
/**
|
|
@@ -66,5 +111,5 @@ interface $$IsomorphicComponent {
|
|
|
66
111
|
* <Component />
|
|
67
112
|
*/
|
|
68
113
|
declare const Column: $$IsomorphicComponent;
|
|
69
|
-
type Column<T extends Record<PropertyKey, any>, V
|
|
114
|
+
type Column<T extends Record<PropertyKey, any>, V> = InstanceType<typeof Column<T, V>>;
|
|
70
115
|
export default Column;
|