svelte-tably 1.0.0-next.9 → 1.0.1-next.0
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/LICENSE +21 -0
- package/README.md +299 -93
- package/dist/column/Column.svelte +39 -0
- package/dist/column/Column.svelte.d.ts +46 -0
- package/dist/column/column-state.svelte.d.ts +138 -0
- package/dist/column/column-state.svelte.js +64 -0
- package/dist/conditional.svelte.d.ts +10 -0
- package/dist/conditional.svelte.js +26 -0
- package/dist/expandable/Expandable.svelte +24 -0
- package/dist/expandable/Expandable.svelte.d.ts +26 -0
- package/dist/expandable/expandable-state.svelte.d.ts +48 -0
- package/dist/expandable/expandable-state.svelte.js +27 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +5 -3
- package/dist/panel/Panel.svelte +21 -0
- package/dist/{Panel.svelte.d.ts → panel/Panel.svelte.d.ts} +2 -28
- package/dist/panel/panel-state.svelte.d.ts +25 -0
- package/dist/panel/panel-state.svelte.js +18 -0
- package/dist/row/Row.svelte +24 -0
- package/dist/row/Row.svelte.d.ts +26 -0
- package/dist/row/row-state.svelte.d.ts +43 -0
- package/dist/row/row-state.svelte.js +28 -0
- package/dist/size-tween.svelte.d.ts +16 -0
- package/dist/size-tween.svelte.js +33 -0
- package/dist/table/Table.svelte +1140 -0
- package/dist/table/Table.svelte.d.ts +123 -0
- package/dist/table/data.svelte.d.ts +14 -0
- package/dist/table/data.svelte.js +81 -0
- package/dist/table/table-state.svelte.d.ts +107 -0
- package/dist/table/table-state.svelte.js +76 -0
- package/dist/table/virtualization.svelte.d.ts +14 -0
- package/dist/table/virtualization.svelte.js +86 -0
- package/dist/utility.svelte.d.ts +24 -0
- package/dist/utility.svelte.js +107 -0
- package/package.json +29 -53
- package/dist/Column.svelte +0 -164
- package/dist/Column.svelte.d.ts +0 -115
- package/dist/Panel.svelte +0 -74
- package/dist/Table.svelte +0 -906
- package/dist/Table.svelte.d.ts +0 -112
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Svelte Tably
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,93 +1,299 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- [x]
|
|
10
|
-
- [x]
|
|
11
|
-
- [x]
|
|
12
|
-
- [x]
|
|
13
|
-
- [x]
|
|
14
|
-
- [x]
|
|
15
|
-
- [x]
|
|
16
|
-
- [x]
|
|
17
|
-
- [x]
|
|
18
|
-
- [x]
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
1
|
+
# Svelte Tably
|
|
2
|
+
|
|
3
|
+
Via the amazing capabilities braught to us by Svelte 5 — a performant, dynamic, flexible, feature rich table. It's as simple, or as flexible as you need it to be.
|
|
4
|
+
|
|
5
|
+
Simple example on [Svelte 5 Playground](https://svelte.dev/playground/f79124e8473546d29433a95a68440d6d?version=5.16.0)
|
|
6
|
+
<br>
|
|
7
|
+
Fledged out example on [Svelte 5 Playground](https://svelte.dev/playground/a16d71c97445455e80a55b77ec1cf915?version=5)
|
|
8
|
+
|
|
9
|
+
- [x] Columns
|
|
10
|
+
- [x] Sticky
|
|
11
|
+
- [x] Show/hide
|
|
12
|
+
- [x] Re-order
|
|
13
|
+
- [x] Resize
|
|
14
|
+
- [x] Data manipulation
|
|
15
|
+
- [x] "Virtual" data
|
|
16
|
+
- [x] Sorting
|
|
17
|
+
- [x] Select
|
|
18
|
+
- [x] Filtering
|
|
19
|
+
- [x] Reorderable
|
|
20
|
+
- [x] Statusbar
|
|
21
|
+
- [x] Panels
|
|
22
|
+
- [x] Row context
|
|
23
|
+
- [x] Expandable rows
|
|
24
|
+
- [x] Virtual rendering
|
|
25
|
+
- [x] To CSV
|
|
26
|
+
- [x] Auto: Create columns based on data
|
|
27
|
+
|
|
28
|
+
On top of that, the library API is extensive, so the table can meet your needs.
|
|
29
|
+
|
|
30
|
+
## Usage Notes
|
|
31
|
+
|
|
32
|
+
`bun add -D svelte-tably`
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<script lang='ts'>
|
|
36
|
+
import Table from 'svelte-tably'
|
|
37
|
+
|
|
38
|
+
const data = $state([
|
|
39
|
+
{ name: 'Giraffe', age: 26, email: 'giraffe@example.com' },
|
|
40
|
+
{ name: 'Shiboo', age: 21, email: 'shiboo@example.com' }
|
|
41
|
+
])
|
|
42
|
+
|
|
43
|
+
let activePanel = $state('columns') as string | undefined
|
|
44
|
+
let selected = $state([]) as typeof data
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<!-- Auto: Generate Columns based on data properties -->
|
|
48
|
+
<Table auto {data} resizeable={false} filters={[...]} />
|
|
49
|
+
|
|
50
|
+
<Table {data} panel={activePanel} select bind:selected>
|
|
51
|
+
{#snippet content({ Column, Panel, Expandable, Row, state, table })}
|
|
52
|
+
<Column id='name' sticky sort value={r => r.name} filter={v => v.includes('Giraffe')}>
|
|
53
|
+
{#snippet header(ctx)}
|
|
54
|
+
Name
|
|
55
|
+
{/snippet}
|
|
56
|
+
{#snippet row(row, ctx)}
|
|
57
|
+
{row.name}
|
|
58
|
+
{/snippet}
|
|
59
|
+
{#snippet statusbar(ctx)}
|
|
60
|
+
{table.data.length}
|
|
61
|
+
{/snippet}
|
|
62
|
+
</Column>
|
|
63
|
+
|
|
64
|
+
<!-- Simplified -->
|
|
65
|
+
<Column id='age' header='Age' value={r => r.age} sort={(a,b) => a - b} />
|
|
66
|
+
|
|
67
|
+
<Expandable click={false}>
|
|
68
|
+
{#snippet content(item, ctx)}
|
|
69
|
+
...
|
|
70
|
+
{/snippet}
|
|
71
|
+
</Expandable>
|
|
72
|
+
|
|
73
|
+
<Row onclick={...} oncontextmenu={...}>
|
|
74
|
+
{#snippet contextHeader()}
|
|
75
|
+
<button ...> <Icon icon='add' /> </button>
|
|
76
|
+
{/snippet}
|
|
77
|
+
{#snippet context(item, ctx)}
|
|
78
|
+
<button ...> <Icon icon='menu' /> </button>
|
|
79
|
+
{/snippet}
|
|
80
|
+
</Row>
|
|
81
|
+
|
|
82
|
+
<Panel id='columns'>
|
|
83
|
+
<!-- Anything you might like -->
|
|
84
|
+
</Panel>
|
|
85
|
+
<Panel ... backdrop={false}>
|
|
86
|
+
...
|
|
87
|
+
</Panel>
|
|
88
|
+
{/snippet}
|
|
89
|
+
</Table>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Styling
|
|
93
|
+
|
|
94
|
+
For quick styling
|
|
95
|
+
|
|
96
|
+
| CSS Variable | Description | Default |
|
|
97
|
+
| - | - | - |
|
|
98
|
+
| --tably-bg | Background color | `hsl(0, 0%, 100%)` |
|
|
99
|
+
| --tably-color | Text color | `hsl(0, 0%, 0%)` |
|
|
100
|
+
| --tably-border | Border for sticky columns and header | `hsl(0, 0%, 90%)` |
|
|
101
|
+
| --tably-border-grid | Border for the table-grid | `hsl(0, 0%, 98%)` |
|
|
102
|
+
| --tably-statusbar | background-color for the statusbar | `hsl(0, 0%, 98%)` |
|
|
103
|
+
| --tably-padding-y | Padding above/below each column | `.5rem` |
|
|
104
|
+
| --tably-padding-x | Padding left of each column | `1rem` |
|
|
105
|
+
| --tably-radius | Table radius | `.25rem` |
|
|
106
|
+
|
|
107
|
+
> [!TIP]
|
|
108
|
+
> For the CSS variables, apply them to `:global(:root) { ... }`
|
|
109
|
+
|
|
110
|
+
> [!NOTE]
|
|
111
|
+
> Advanced styling can be done via `:global(.svelte-tably)`
|
|
112
|
+
> `table > thead > tr > th, table > tbody > tr > td, table > tfoot > tr > td`
|
|
113
|
+
|
|
114
|
+
<br>
|
|
115
|
+
<br>
|
|
116
|
+
|
|
117
|
+
## Components
|
|
118
|
+
|
|
119
|
+
All components except Table are meant to be children of the `Table` component.
|
|
120
|
+
|
|
121
|
+
However, you can safely create a `Component.svelte` and use these components,
|
|
122
|
+
and then provide `<Component/>` as a child to `<Table>`.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import Table from 'svelte-tably'
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Table
|
|
129
|
+
|
|
130
|
+
The table component.
|
|
131
|
+
|
|
132
|
+
```html
|
|
133
|
+
<Table auto {data} />
|
|
134
|
+
|
|
135
|
+
<Table {data} ...>
|
|
136
|
+
{#snippet content?({ Column, Row, Expandable, Panel, table })}
|
|
137
|
+
...
|
|
138
|
+
{/snippet}
|
|
139
|
+
</Table>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Where `table` is `TableState<T>` and the rest are typed; `Component<T>`.
|
|
143
|
+
|
|
144
|
+
| Attribute | Description | Type |
|
|
145
|
+
| - | - | - |
|
|
146
|
+
| content? | The contents of the table | `Snippet<[ctx: ContentCtx<T>]>?` |
|
|
147
|
+
| | | |
|
|
148
|
+
| id? | The `#id` for the table | `string` |
|
|
149
|
+
| data | An array of objects for the table | `T[]` |
|
|
150
|
+
| bind:selected? | The currently selected items | `T[]` |
|
|
151
|
+
| bind:panel? | The currently open panel | `string` |
|
|
152
|
+
| filters? | An array of filters applied to the table | `((item: T) => boolean)[]` |
|
|
153
|
+
| reorderable? | Whether the rows can be re-ordered (via [runic-reorder](https://github.com/Refzlund/runic-reorder)) | `boolean` |
|
|
154
|
+
| resizeable? | Whether or not the columns can be resized | `boolean` |
|
|
155
|
+
| select? | Whether ot not the rows items can be selected | `boolean \| SelectOptions<T>` |
|
|
156
|
+
| auto? | Create missing columns automatically? | `boolean` |
|
|
157
|
+
|
|
158
|
+
#### SelectOptions
|
|
159
|
+
|
|
160
|
+
| Properties | Description | Type |
|
|
161
|
+
| - | - | - |
|
|
162
|
+
| show? | When to show the row-select when not selected | `'hover' \| 'always' \| 'never'` |
|
|
163
|
+
| headerSnippet? | Custom snippet for the header select-input | `Snippet<[context: HeaderSelectCtx]>` |
|
|
164
|
+
| rowSnippet? | Custom snippet for the row select-input | `Snippet<[context: RowSelectCtx<T>]>` |
|
|
165
|
+
|
|
166
|
+
<br>
|
|
167
|
+
|
|
168
|
+
### Column
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import { Column } from 'svelte-tably'
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
This component designates a column where options like sorting, filtering etc. are provided.
|
|
175
|
+
|
|
176
|
+
```html
|
|
177
|
+
<Column id='...' header='...' value={row => row.value} />
|
|
178
|
+
|
|
179
|
+
<Column id='...' ...>
|
|
180
|
+
{#snippet header?(ctx: HeaderCtx<T>)}
|
|
181
|
+
...
|
|
182
|
+
{/snippet}
|
|
183
|
+
{#snippet row?(item: T, ctx: RowColumnCtx<T>)}
|
|
184
|
+
...
|
|
185
|
+
{/snippet}
|
|
186
|
+
{#snippet statusbar?(ctx: StatusbarCtx<T>)}
|
|
187
|
+
...
|
|
188
|
+
{/snippet}
|
|
189
|
+
</Column>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
| Attribute | Description | Type |
|
|
193
|
+
| - | - | - |
|
|
194
|
+
| header? | The header element/contents | `string \| Snippet<[ctx: HeaderCtx<T>]>` |
|
|
195
|
+
| row? | The row element. If not provided, `value: V` will be used. | `Snippet<[item: T, ctx: RowColumnCtx<T, V>]>` |
|
|
196
|
+
| statusbar? | The statusbar element | `Snippet<[ctx: StatusbarCtx<T>]>` |
|
|
197
|
+
| | | |
|
|
198
|
+
| sticky? | Should be sticky by default | `boolean` |
|
|
199
|
+
| show? | Should be visible by default | `boolean` |
|
|
200
|
+
| sortby? | Should sort by this by default | `boolean` |
|
|
201
|
+
| width? | Default width | `number` |
|
|
202
|
+
| value? | The value this column contains | `(item: T) => V` |
|
|
203
|
+
| sort? | A boolean (`localeCompare`) or sorting function | `boolean \| ((a: V, b: V) => number)` |
|
|
204
|
+
| resizeable? | Whether this column is resizeable | `boolean` |
|
|
205
|
+
| filter? | A filter for this columns value | `(item: V) => boolean` |
|
|
206
|
+
| style? | Styling the `td` (row-column) element | `string` |
|
|
207
|
+
| pad? | Apply padding to the child-element of `td`/`th` instead of the column element itself | `'row' \| 'header' \| 'both'` |
|
|
208
|
+
| onclick? | When the column is clicked | `(event: MouseEvent, ctx: RowColumnCtx<T, V>) => void` |
|
|
209
|
+
|
|
210
|
+
<br>
|
|
211
|
+
|
|
212
|
+
### Row
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
import { Row } from 'svelte-tably'
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
This component can add a context-menu on the side of each row, as well as provide event handlers to the row element.
|
|
219
|
+
|
|
220
|
+
```html
|
|
221
|
+
<Row ... />
|
|
222
|
+
|
|
223
|
+
<Row ...>
|
|
224
|
+
{#snippet context?(item: T, ctx: RowCtx<T>)}
|
|
225
|
+
...
|
|
226
|
+
{/snippet}
|
|
227
|
+
{#snippet contextHeader?()}
|
|
228
|
+
...
|
|
229
|
+
{/snippet}
|
|
230
|
+
</Row>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
| Attribute | Description | Type |
|
|
234
|
+
| - | - | - |
|
|
235
|
+
| context? | A sticky column on the right for each row | `Snippet<[item: T, ctx: RowCtx<T>]>` |
|
|
236
|
+
| contextHeader? | A sticky column on the right for the header | `Snippet<[item: T, ctx: RowCtx<T>]>` |
|
|
237
|
+
| | | |
|
|
238
|
+
| contextOptions? | Options for the Context-column | `ContextOptions<T>` |
|
|
239
|
+
| onclick? | When row is clicked | `(event: MouseEvent, ctx: RowCtx<T>) => void` |
|
|
240
|
+
| oncontextmenu? | When row is right-clicked | `(event: MouseEvent, ctx: RowCtx<T>) => void` |
|
|
241
|
+
|
|
242
|
+
#### ContextOptions
|
|
243
|
+
|
|
244
|
+
| Properties | Description | Type |
|
|
245
|
+
| - | - | - |
|
|
246
|
+
| hover? | Only show when hovering? | `boolean` |
|
|
247
|
+
| width? | The width for the context-column | `string` |
|
|
248
|
+
|
|
249
|
+
<br>
|
|
250
|
+
|
|
251
|
+
### Expandable
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import { Expandable } from 'svelte-tably'
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
This component gives your rows the ability to be expanded.
|
|
258
|
+
|
|
259
|
+
```html
|
|
260
|
+
<Expandable ...>
|
|
261
|
+
{#snippet content(item: T, ctx: RowCtx<T>)}
|
|
262
|
+
...
|
|
263
|
+
{/snippet}
|
|
264
|
+
</Expandable>
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
| Attribute | Description | Type |
|
|
268
|
+
| - | - | - |
|
|
269
|
+
| content | The contents of the expanded row. | `Snippet<[item: T, ctx: RowCtx<T>]>` |
|
|
270
|
+
| | | |
|
|
271
|
+
| slide? | Options for sliding the expanding part | `{ duration?: number, easing?: EasingFunction }` |
|
|
272
|
+
| click? | Whether you can click on a row to expand/collapse it | `boolean` |
|
|
273
|
+
| chevron? | Whether to show the chevron on the left fixed column | `'always' \| 'hover' \| 'never'` |
|
|
274
|
+
| multiple? | Can multiple rows be open at the same time? | `boolean` |
|
|
275
|
+
|
|
276
|
+
<br>
|
|
277
|
+
|
|
278
|
+
### Panel
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
import { Panel } from 'svelte-tably'
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
This component creates a panel that can be opened on the side of the table.
|
|
285
|
+
|
|
286
|
+
```html
|
|
287
|
+
<Panel id='...' ...>
|
|
288
|
+
{#snippet children(ctx: PanelCtx<T>)}
|
|
289
|
+
...
|
|
290
|
+
{/snippet}
|
|
291
|
+
</Panel>
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
| Attribute | Description | Type |
|
|
295
|
+
| - | - | - |
|
|
296
|
+
| children | The contents of the panel | `Snippet<[ctx: PanelCtx<T>]>` |
|
|
297
|
+
| | | |
|
|
298
|
+
| id | The id for the panel that determines whether it's open or closed, from the Table attribute | `string` |
|
|
299
|
+
| backdrop? | Whether there should be a backdrop or not | `boolean` |
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!-- @component
|
|
2
|
+
|
|
3
|
+
This is a description, \
|
|
4
|
+
on how to use this.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
<Component />
|
|
8
|
+
|
|
9
|
+
-->
|
|
10
|
+
|
|
11
|
+
<script module lang='ts'>
|
|
12
|
+
|
|
13
|
+
export function getDefaultHeader<T extends AnyRecord,V>(title: string) {
|
|
14
|
+
return (
|
|
15
|
+
(anchor: Comment) => snippetLiteral(defaultHeader)(anchor, () => title)
|
|
16
|
+
) as unknown as () => any
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang='ts'>
|
|
22
|
+
|
|
23
|
+
import { fromProps, snippetLiteral, type AnyRecord } from '../utility.svelte.js'
|
|
24
|
+
import { ColumnState, type ColumnProps, type HeaderCtx, type ColumnSnippets } from './column-state.svelte.js'
|
|
25
|
+
|
|
26
|
+
type T = $$Generic<Record<PropertyKey, any>>
|
|
27
|
+
type V = $$Generic
|
|
28
|
+
|
|
29
|
+
let {...props}: ColumnProps<T, V> = $props()
|
|
30
|
+
const properties = fromProps(props)
|
|
31
|
+
|
|
32
|
+
new ColumnState<T, V>(properties)
|
|
33
|
+
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
{#snippet defaultHeader(title: string)}
|
|
38
|
+
{title}
|
|
39
|
+
{/snippet}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare function getDefaultHeader<T extends AnyRecord, V>(title: string): () => any;
|
|
2
|
+
import { type AnyRecord } from '../utility.svelte.js';
|
|
3
|
+
import { type HeaderCtx } from './column-state.svelte.js';
|
|
4
|
+
declare class __sveltets_Render<T extends Record<PropertyKey, any>, V> {
|
|
5
|
+
props(): {
|
|
6
|
+
id: string;
|
|
7
|
+
table?: import("../index.js").TableState<T> | undefined;
|
|
8
|
+
header?: string | import("svelte").Snippet<[ctx: HeaderCtx<T>]> | undefined;
|
|
9
|
+
row?: import("svelte").Snippet<[item: T, ctx: import("./column-state.svelte.js").RowColumnCtx<T, V>]> | undefined;
|
|
10
|
+
statusbar?: import("svelte").Snippet<[ctx: import("./column-state.svelte.js").StatusbarCtx<T>]> | undefined;
|
|
11
|
+
sticky?: boolean | undefined;
|
|
12
|
+
show?: boolean | undefined;
|
|
13
|
+
sortby?: boolean | undefined;
|
|
14
|
+
width?: number | undefined;
|
|
15
|
+
fixed?: boolean | undefined;
|
|
16
|
+
value?: ((item: T) => V) | undefined;
|
|
17
|
+
sort?: boolean | ((a: V, b: V) => number) | undefined;
|
|
18
|
+
resizeable?: boolean | undefined;
|
|
19
|
+
filter?: ((value: V) => boolean) | undefined;
|
|
20
|
+
style?: string | undefined;
|
|
21
|
+
class?: string | undefined;
|
|
22
|
+
onclick?: ((event: MouseEvent, rowColumnCtx: import("./column-state.svelte.js").RowColumnCtx<T, V>) => void) | undefined;
|
|
23
|
+
pad?: "row" | "header" | "both" | undefined;
|
|
24
|
+
};
|
|
25
|
+
events(): {};
|
|
26
|
+
slots(): {};
|
|
27
|
+
bindings(): "";
|
|
28
|
+
exports(): {};
|
|
29
|
+
}
|
|
30
|
+
interface $$IsomorphicComponent {
|
|
31
|
+
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']>> & {
|
|
32
|
+
$$bindings?: ReturnType<__sveltets_Render<T, V>['bindings']>;
|
|
33
|
+
} & ReturnType<__sveltets_Render<T, V>['exports']>;
|
|
34
|
+
<T extends Record<PropertyKey, any>, V>(internal: unknown, props: ReturnType<__sveltets_Render<T, V>['props']> & {}): ReturnType<__sveltets_Render<T, V>['exports']>;
|
|
35
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* This is a description, \
|
|
39
|
+
* on how to use this.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* <Component />
|
|
43
|
+
*/
|
|
44
|
+
declare const Column: $$IsomorphicComponent;
|
|
45
|
+
type Column<T extends Record<PropertyKey, any>, V> = InstanceType<typeof Column<T, V>>;
|
|
46
|
+
export default Column;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import { TableState, type RowCtx } from '../table/table-state.svelte.js';
|
|
3
|
+
import { type AnyRecord } from '../utility.svelte.js';
|
|
4
|
+
export type ColumnProps<T extends AnyRecord, V> = ({
|
|
5
|
+
id: string;
|
|
6
|
+
table?: TableState<T>;
|
|
7
|
+
} & ColumnSnippets<T, V> & ColumnDefaults<T> & ColumnOptions<T, V>) extends infer K ? {
|
|
8
|
+
[P in keyof K]: K[P];
|
|
9
|
+
} : never;
|
|
10
|
+
export interface HeaderCtx<T> {
|
|
11
|
+
readonly data: T[];
|
|
12
|
+
/**
|
|
13
|
+
* Is true when displaying in the header,
|
|
14
|
+
* so additional content can be shown if desired,
|
|
15
|
+
* so the header snippet can be re-used.
|
|
16
|
+
*/
|
|
17
|
+
readonly header?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface RowColumnCtx<T extends AnyRecord, V> extends RowCtx<T> {
|
|
20
|
+
readonly value: V;
|
|
21
|
+
readonly columnHovered: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type StatusbarCtx<T extends AnyRecord> = {
|
|
24
|
+
readonly data: T[];
|
|
25
|
+
};
|
|
26
|
+
export type ColumnSnippets<T extends AnyRecord, V> = {
|
|
27
|
+
header?: Snippet<[ctx: HeaderCtx<T>]> | string;
|
|
28
|
+
row?: Snippet<[item: T, ctx: RowColumnCtx<T, V>]>;
|
|
29
|
+
statusbar?: Snippet<[ctx: StatusbarCtx<T>]>;
|
|
30
|
+
};
|
|
31
|
+
type ColumnDefaults<T> = {
|
|
32
|
+
/**
|
|
33
|
+
* Is this column sticky by default?
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
sticky?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Is this column visible by default?
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
show?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Is this column sorted by default?
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
sortby?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The width of the column in pixels by default
|
|
49
|
+
* @default 150
|
|
50
|
+
*/
|
|
51
|
+
width?: number;
|
|
52
|
+
};
|
|
53
|
+
type ColumnOptions<T extends AnyRecord, V> = {
|
|
54
|
+
/**
|
|
55
|
+
* Fixed is like sticky, but in its own category — meant to not be moved/hidden ex. select-boxes
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
fixed?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The value of the row. Required for sorting/filtering
|
|
61
|
+
* @example row => row.name
|
|
62
|
+
*/
|
|
63
|
+
value?: (item: T) => V;
|
|
64
|
+
/**
|
|
65
|
+
* Makes the column sortable. Sorts based of a sorting function.
|
|
66
|
+
*
|
|
67
|
+
* **Important** `value`-attribute is required adjacent to this.
|
|
68
|
+
*
|
|
69
|
+
* If `true` uses the default `.sort()` algorithm.
|
|
70
|
+
*
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
73
|
+
sort?: boolean | ((a: V, b: V) => number);
|
|
74
|
+
/**
|
|
75
|
+
* Is this column resizeable?
|
|
76
|
+
* Can not be resized if Table is marked as `resizeable={false}`
|
|
77
|
+
* @default true
|
|
78
|
+
*/
|
|
79
|
+
resizeable?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @example (value) => value.includes(search)
|
|
83
|
+
*/
|
|
84
|
+
filter?: (value: V) => boolean;
|
|
85
|
+
/** Styling for the column element (td) */
|
|
86
|
+
style?: string;
|
|
87
|
+
/** Class for the column element (td) */
|
|
88
|
+
class?: string;
|
|
89
|
+
/** Event when the row-column is clicked */
|
|
90
|
+
onclick?: (event: MouseEvent, rowColumnCtx: RowColumnCtx<T, V>) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Pad child element of `td`/`th` instead of the column element itself.
|
|
93
|
+
* This ensures the child element "fills" the whole column.
|
|
94
|
+
* Ex. good if you want to make the column an anchor link; `<a href='...'>`
|
|
95
|
+
*/
|
|
96
|
+
pad?: 'row' | 'header' | 'both';
|
|
97
|
+
};
|
|
98
|
+
export declare class ColumnState<T extends AnyRecord = any, V = any> {
|
|
99
|
+
#private;
|
|
100
|
+
id: string;
|
|
101
|
+
/**
|
|
102
|
+
* Associated table
|
|
103
|
+
*/
|
|
104
|
+
table: TableState<T>;
|
|
105
|
+
snippets: {
|
|
106
|
+
header: Snippet<[ctx: HeaderCtx<T>]> | (() => any) | undefined;
|
|
107
|
+
/** Title is the header-snippet, with header-ctx: `{ header: false }` */
|
|
108
|
+
title: (...args: any[]) => any;
|
|
109
|
+
row: Snippet<[item: T, ctx: RowColumnCtx<T, V>]> | undefined;
|
|
110
|
+
statusbar: Snippet<[ctx: StatusbarCtx<T>]> | undefined;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Variables that can be saved (e.g. localStorage)
|
|
114
|
+
* and re-provided, where these are default-fallbacks
|
|
115
|
+
*/
|
|
116
|
+
defaults: {
|
|
117
|
+
sticky: boolean;
|
|
118
|
+
show: boolean;
|
|
119
|
+
sortby: boolean;
|
|
120
|
+
width: number;
|
|
121
|
+
};
|
|
122
|
+
/** Static options */
|
|
123
|
+
options: {
|
|
124
|
+
fixed: boolean;
|
|
125
|
+
sort: boolean | ((a: V, b: V) => number);
|
|
126
|
+
filter: ((value: V) => boolean) | undefined;
|
|
127
|
+
value: ((item: T) => V) | undefined;
|
|
128
|
+
resizeable: boolean;
|
|
129
|
+
style: string | undefined;
|
|
130
|
+
class: string | undefined;
|
|
131
|
+
onclick: ((event: MouseEvent, rowColumnCtx: RowColumnCtx<T, V>) => void) | undefined;
|
|
132
|
+
padRow: boolean;
|
|
133
|
+
padHeader: boolean;
|
|
134
|
+
};
|
|
135
|
+
toggleVisiblity(): void;
|
|
136
|
+
constructor(props: ColumnProps<T, V>);
|
|
137
|
+
}
|
|
138
|
+
export {};
|