@isoftdata/svelte-table 2.8.2 → 2.9.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/README.md +387 -387
- package/dist/DraggableRows.svelte +276 -276
- package/dist/Pagination.svelte +303 -303
- package/dist/Table.svelte +1074 -1072
- package/dist/Td.svelte +156 -153
- package/dist/Td.svelte.d.ts +38 -24
- package/dist/TreeRow.svelte +170 -170
- package/package.json +2 -2
package/dist/Td.svelte
CHANGED
|
@@ -1,153 +1,156 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
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
|
-
|
|
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
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
{
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
td.text-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
td.text-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
1
|
+
<script
|
|
2
|
+
lang="ts"
|
|
3
|
+
generics="R extends UuidRowProps = any"
|
|
4
|
+
>
|
|
5
|
+
import type { ColumnInfo, RowProperties, UuidRowProps } from './'
|
|
6
|
+
import type { ColumnInfoRunicStore } from './column-info-store.svelte'
|
|
7
|
+
import type { HTMLTdAttributes, ClassValue } from 'svelte/elements'
|
|
8
|
+
import type { Writable } from 'svelte/store'
|
|
9
|
+
import { getContext, onMount, type Snippet } from 'svelte'
|
|
10
|
+
|
|
11
|
+
// Get the columnInfo store from the Table component
|
|
12
|
+
const columnInfo = getContext<ColumnInfoRunicStore<UuidRowProps>>('columnInfo')
|
|
13
|
+
const columnResizingEnabled = getContext<Writable<boolean>>('columnResizingEnabled')
|
|
14
|
+
const bs5 = getContext<boolean>('bs5')
|
|
15
|
+
|
|
16
|
+
interface Props extends Omit<HTMLTdAttributes, 'align'> {
|
|
17
|
+
class?: ClassValue
|
|
18
|
+
property: ColumnInfo<R>['property']
|
|
19
|
+
/** Direction to align the column's contents
|
|
20
|
+
*
|
|
21
|
+
* `start` and `end` are only available in Bootstrap 5+
|
|
22
|
+
*
|
|
23
|
+
* `left` and `right`should only be used while you transition to Boostrap 5+
|
|
24
|
+
*/
|
|
25
|
+
align?: 'start' | 'left' | 'center' | 'right' | 'end'
|
|
26
|
+
/** If enabled, pressing enter while focused in this Td will focus the next non-disabled input/select/textarea in the column. Holding shift will go up instead of down.
|
|
27
|
+
*
|
|
28
|
+
* Can also be a callback that is fired when the enter key is used to move between rows.
|
|
29
|
+
*/
|
|
30
|
+
enterGoesDown?: boolean | ((ctx: { event: KeyboardEvent; tr: HTMLTableRowElement }) => void)
|
|
31
|
+
/** If enabled, keypress (enter only) and click events on the Td's contents will have `stopPropagation`/`preventDefault` called on them. */
|
|
32
|
+
stopPropagation?: boolean
|
|
33
|
+
tagName?: 'TD' | 'TH'
|
|
34
|
+
children?: Snippet
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let {
|
|
38
|
+
//
|
|
39
|
+
class: classNames = '',
|
|
40
|
+
property,
|
|
41
|
+
align = $bindable(columnInfo.current[property]?.align),
|
|
42
|
+
enterGoesDown = false,
|
|
43
|
+
stopPropagation = false,
|
|
44
|
+
tagName = 'TD',
|
|
45
|
+
children,
|
|
46
|
+
...rest
|
|
47
|
+
}: Props = $props()
|
|
48
|
+
|
|
49
|
+
const thisColumnInfo = $derived(columnInfo.current[property])
|
|
50
|
+
const alignClass = $derived.by(() => {
|
|
51
|
+
let alignment = align || thisColumnInfo?.align || (thisColumnInfo?.numeric ? 'right' : undefined)
|
|
52
|
+
if (bs5 && alignment === 'right') {
|
|
53
|
+
alignment = 'end'
|
|
54
|
+
} else if (bs5 && alignment === 'left') {
|
|
55
|
+
alignment = 'start'
|
|
56
|
+
}
|
|
57
|
+
return alignment ? (`text-${alignment}` as const) : ''
|
|
58
|
+
})
|
|
59
|
+
const visible = $derived(thisColumnInfo?.visible ?? true)
|
|
60
|
+
|
|
61
|
+
/** Handle `stopPropagation` and `enterGoesDown` props */
|
|
62
|
+
function onkeypress(event: KeyboardEvent) {
|
|
63
|
+
if (event.key === 'Enter') {
|
|
64
|
+
event.stopPropagation()
|
|
65
|
+
event.preventDefault()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (event.key === 'Enter' && enterGoesDown) {
|
|
69
|
+
const target = event.target
|
|
70
|
+
if (!(target instanceof HTMLElement)) {
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
const tr = target?.closest('tr') ?? null
|
|
74
|
+
const td = target?.closest('td') ?? null
|
|
75
|
+
const tdIndex = td ? Array.from(tr?.children ?? []).indexOf(td) : -1
|
|
76
|
+
const allTrs = Array.from(tr?.parentElement?.children ?? [])
|
|
77
|
+
|
|
78
|
+
// if they're holding shift, reverse the tr list
|
|
79
|
+
if (event.shiftKey) {
|
|
80
|
+
allTrs.reverse()
|
|
81
|
+
}
|
|
82
|
+
// Find the next Td in the column with a non-disabled input, select, or textarea
|
|
83
|
+
const lastTrIndex = tr ? allTrs.indexOf(tr) : -1
|
|
84
|
+
const newTrIndex = allTrs.findIndex(
|
|
85
|
+
(tr, index) =>
|
|
86
|
+
index > lastTrIndex &&
|
|
87
|
+
tr.children[tdIndex]?.querySelector('input:enabled, select:enabled, textarea:enabled') &&
|
|
88
|
+
tr instanceof HTMLTableRowElement &&
|
|
89
|
+
tr.offsetParent !== null,
|
|
90
|
+
)
|
|
91
|
+
const theTd = allTrs[newTrIndex]?.children[tdIndex] ?? null
|
|
92
|
+
theTd?.querySelector<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>('input,select,textarea')?.focus()
|
|
93
|
+
if (typeof enterGoesDown === 'function') {
|
|
94
|
+
enterGoesDown({
|
|
95
|
+
tr: allTrs[newTrIndex] as HTMLTableRowElement,
|
|
96
|
+
event,
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
onMount(() => {
|
|
103
|
+
if (!(property in columnInfo.current)) {
|
|
104
|
+
console.warn(
|
|
105
|
+
`Column "${property}" does not exist in its parent Table component's list of columns.\r\n\r\nPlease check that this Td's "property" prop matches the "property" prop of one of the columns in the parent Table component.`,
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
</script>
|
|
110
|
+
|
|
111
|
+
{#if visible}
|
|
112
|
+
<svelte:element
|
|
113
|
+
this={tagName}
|
|
114
|
+
class={[classNames, alignClass]}
|
|
115
|
+
{...rest}
|
|
116
|
+
style:font-variant-numeric={thisColumnInfo?.numeric ? 'tabular-nums' : undefined}
|
|
117
|
+
style:overflow={$columnResizingEnabled ? 'hidden' : undefined}
|
|
118
|
+
style:text-overflow={$columnResizingEnabled ? 'ellipsis' : undefined}
|
|
119
|
+
>
|
|
120
|
+
<!--
|
|
121
|
+
Don't listen to events that the user hasn't turned on the features for.
|
|
122
|
+
Also, put them on a span so they can still click in the td to click the row but not the td's child content
|
|
123
|
+
-->
|
|
124
|
+
{#if stopPropagation || enterGoesDown}
|
|
125
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
126
|
+
<span
|
|
127
|
+
onclick={stopPropagation ? e => e.stopPropagation() : undefined}
|
|
128
|
+
{onkeypress}
|
|
129
|
+
>
|
|
130
|
+
{@render children?.()}
|
|
131
|
+
</span>
|
|
132
|
+
{:else}
|
|
133
|
+
{@render children?.()}
|
|
134
|
+
{/if}
|
|
135
|
+
</svelte:element>
|
|
136
|
+
{/if}
|
|
137
|
+
|
|
138
|
+
<style>
|
|
139
|
+
td.text-right :global(input),
|
|
140
|
+
td.text-end :global(input) {
|
|
141
|
+
text-align: right;
|
|
142
|
+
}
|
|
143
|
+
td.text-right :global(select),
|
|
144
|
+
td.text-end :global(select) {
|
|
145
|
+
text-align: right;
|
|
146
|
+
}
|
|
147
|
+
td.text-right :global(textarea),
|
|
148
|
+
td.text-end :global(textarea) {
|
|
149
|
+
text-align: right;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* BS5 uses floats for checkbox alignment, which overrides the text align classes, so undo that here. */
|
|
153
|
+
td:where(.text-start, .text-center, .text-end) :global(.form-check-input) {
|
|
154
|
+
float: unset;
|
|
155
|
+
}
|
|
156
|
+
</style>
|
package/dist/Td.svelte.d.ts
CHANGED
|
@@ -1,28 +1,42 @@
|
|
|
1
|
+
import type { RowProperties, UuidRowProps } from './';
|
|
1
2
|
import type { HTMLTdAttributes, ClassValue } from 'svelte/elements';
|
|
2
3
|
import { type Snippet } from 'svelte';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
declare class __sveltets_Render<R extends UuidRowProps = any> {
|
|
5
|
+
props(): Omit<HTMLTdAttributes, "align"> & {
|
|
6
|
+
class?: ClassValue;
|
|
7
|
+
property: `_${string}` | RowProperties<R>;
|
|
8
|
+
/** Direction to align the column's contents
|
|
9
|
+
*
|
|
10
|
+
* `start` and `end` are only available in Bootstrap 5+
|
|
11
|
+
*
|
|
12
|
+
* `left` and `right`should only be used while you transition to Boostrap 5+
|
|
13
|
+
*/
|
|
14
|
+
align?: "start" | "left" | "center" | "right" | "end";
|
|
15
|
+
/** If enabled, pressing enter while focused in this Td will focus the next non-disabled input/select/textarea in the column. Holding shift will go up instead of down.
|
|
16
|
+
*
|
|
17
|
+
* Can also be a callback that is fired when the enter key is used to move between rows.
|
|
18
|
+
*/
|
|
19
|
+
enterGoesDown?: boolean | ((ctx: {
|
|
20
|
+
event: KeyboardEvent;
|
|
21
|
+
tr: HTMLTableRowElement;
|
|
22
|
+
}) => void) | undefined;
|
|
23
|
+
/** If enabled, keypress (enter only) and click events on the Td's contents will have `stopPropagation`/`preventDefault` called on them. */
|
|
24
|
+
stopPropagation?: boolean;
|
|
25
|
+
tagName?: "TD" | "TH";
|
|
26
|
+
children?: Snippet;
|
|
27
|
+
};
|
|
28
|
+
events(): {};
|
|
29
|
+
slots(): {};
|
|
30
|
+
bindings(): "align";
|
|
31
|
+
exports(): {};
|
|
25
32
|
}
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
interface $$IsomorphicComponent {
|
|
34
|
+
new <R extends UuidRowProps = any>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<R>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<R>['props']>, ReturnType<__sveltets_Render<R>['events']>, ReturnType<__sveltets_Render<R>['slots']>> & {
|
|
35
|
+
$$bindings?: ReturnType<__sveltets_Render<R>['bindings']>;
|
|
36
|
+
} & ReturnType<__sveltets_Render<R>['exports']>;
|
|
37
|
+
<R extends UuidRowProps = any>(internal: unknown, props: ReturnType<__sveltets_Render<R>['props']> & {}): ReturnType<__sveltets_Render<R>['exports']>;
|
|
38
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
39
|
+
}
|
|
40
|
+
declare const Td: $$IsomorphicComponent;
|
|
41
|
+
type Td<R extends UuidRowProps = any> = InstanceType<typeof Td<R>>;
|
|
28
42
|
export default Td;
|