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