compote-ui 0.55.4 → 0.56.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/dist/components/data-table-v9/column-helper.d.ts +12 -0
- package/dist/components/data-table-v9/column-helper.js +42 -0
- package/dist/components/data-table-v9/create-table.svelte.d.ts +42 -0
- package/dist/components/data-table-v9/create-table.svelte.js +248 -0
- package/dist/components/data-table-v9/data-table-cell-content.svelte +66 -0
- package/dist/components/data-table-v9/data-table-cell-content.svelte.d.ts +28 -0
- package/dist/components/data-table-v9/data-table-foot.svelte +111 -0
- package/dist/components/data-table-v9/data-table-foot.svelte.d.ts +32 -0
- package/dist/components/{data-table/data-table-head.svelte.md → data-table-v9/data-table-head.svelte} +47 -39
- package/dist/components/data-table-v9/data-table-head.svelte.d.ts +32 -0
- package/dist/components/data-table-v9/data-table-title.svelte.d.ts +10 -0
- package/dist/components/data-table-v9/data-table-utils.d.ts +53 -0
- package/dist/components/data-table-v9/data-table-utils.js +181 -0
- package/dist/components/data-table-v9/data-table.svelte +151 -0
- package/dist/components/data-table-v9/data-table.svelte.d.ts +41 -0
- package/dist/components/data-table-v9/features.d.ts +12 -0
- package/dist/components/data-table-v9/features.js +14 -0
- package/dist/components/data-table-v9/index.d.ts +11 -0
- package/dist/components/data-table-v9/index.js +9 -0
- package/dist/components/data-table-v9/table-view-state.svelte.d.ts +74 -0
- package/dist/components/data-table-v9/table-view-state.svelte.js +182 -0
- package/dist/components/data-table-v9/toolbar/data-table-column-filter.svelte +380 -0
- package/dist/components/data-table-v9/toolbar/data-table-column-filter.svelte.d.ts +29 -0
- package/dist/components/data-table-v9/toolbar/data-table-column-visibility.svelte +73 -0
- package/dist/components/data-table-v9/toolbar/data-table-column-visibility.svelte.d.ts +29 -0
- package/dist/components/data-table-v9/toolbar/data-table-search.svelte +58 -0
- package/dist/components/data-table-v9/toolbar/data-table-search.svelte.d.ts +32 -0
- package/dist/components/{data-table/data-table-toolbar.svelte.md → data-table-v9/toolbar/data-table-toolbar.svelte} +14 -15
- package/dist/components/data-table-v9/toolbar/data-table-toolbar.svelte.d.ts +12 -0
- package/dist/components/data-table-v9/types.d.ts +74 -0
- package/dist/components/data-table-v9/types.js +1 -0
- package/dist/components/data-table-v9/virtual/data-table-virtual-rows.svelte +131 -0
- package/dist/components/data-table-v9/virtual/data-table-virtual-rows.svelte.d.ts +40 -0
- package/dist/components/data-table-v9/virtual/data-table-virtualized.svelte +79 -0
- package/dist/components/data-table-v9/virtual/data-table-virtualized.svelte.d.ts +41 -0
- package/dist/components/data-table-v9/virtual/index.d.ts +3 -0
- package/dist/components/data-table-v9/virtual/index.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/package.json +12 -2
- package/dist/components/data-table/column-helper.ts.md +0 -96
- package/dist/components/data-table/create-table.ts.md +0 -386
- package/dist/components/data-table/data-table-column-filter.svelte.md +0 -249
- package/dist/components/data-table/data-table-column-visibility.svelte.md +0 -74
- package/dist/components/data-table/data-table-new.svelte.md +0 -245
- package/dist/components/data-table/data-table-utils.ts.md +0 -179
- package/dist/components/data-table/data-table-virtual-rows.svelte.md +0 -171
- package/dist/components/data-table/data-table-virtualized.svelte.md +0 -108
- package/dist/components/data-table/data-table.svelte.md +0 -214
- package/dist/components/data-table/index.ts.md +0 -22
- package/dist/components/data-table/types.ts.md +0 -101
- package/dist/components/data-table/virtual/index.ts.md +0 -26
- /package/dist/components/{data-table/data-table-title.svelte.md → data-table-v9/data-table-title.svelte} +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
2
|
+
import type { DataTableInstance } from '../data-table-utils';
|
|
3
|
+
declare function $$render<T extends RowData>(): {
|
|
4
|
+
props: {
|
|
5
|
+
table: DataTableInstance<T>;
|
|
6
|
+
triggerLabel?: string;
|
|
7
|
+
};
|
|
8
|
+
exports: {};
|
|
9
|
+
bindings: "";
|
|
10
|
+
slots: {};
|
|
11
|
+
events: {};
|
|
12
|
+
};
|
|
13
|
+
declare class __sveltets_Render<T extends RowData> {
|
|
14
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
15
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
16
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
17
|
+
bindings(): "";
|
|
18
|
+
exports(): {};
|
|
19
|
+
}
|
|
20
|
+
interface $$IsomorphicComponent {
|
|
21
|
+
new <T extends RowData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
22
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
23
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
24
|
+
<T extends RowData>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
25
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
26
|
+
}
|
|
27
|
+
declare const DataTableColumnFilter: $$IsomorphicComponent;
|
|
28
|
+
type DataTableColumnFilter<T extends RowData> = InstanceType<typeof DataTableColumnFilter<T>>;
|
|
29
|
+
export default DataTableColumnFilter;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends RowData">
|
|
2
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
3
|
+
import * as Popover from '../../popover';
|
|
4
|
+
import * as ScrollArea from '../../scroll-area';
|
|
5
|
+
import Checkbox from '../../checkbox/checkbox.svelte';
|
|
6
|
+
import type { DataTableInstance } from '../data-table-utils';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
table: DataTableInstance<T>;
|
|
10
|
+
triggerLabel?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let { table, triggerLabel = 'Columns' }: Props = $props();
|
|
14
|
+
|
|
15
|
+
const columnVisibility = $derived.by(() => table.atoms.columnVisibility.get());
|
|
16
|
+
const allLeafColumns = $derived.by(() => {
|
|
17
|
+
void columnVisibility;
|
|
18
|
+
return table.getAllLeafColumns();
|
|
19
|
+
});
|
|
20
|
+
const allColumnsVisible = $derived(
|
|
21
|
+
allLeafColumns.every((c) => !c.getCanHide() || columnVisibility[c.id] !== false)
|
|
22
|
+
);
|
|
23
|
+
const someColumnsVisible = $derived(
|
|
24
|
+
allLeafColumns.some((c) => c.getCanHide() && columnVisibility[c.id] !== false)
|
|
25
|
+
);
|
|
26
|
+
const allColumnsVisibilityState = $derived(
|
|
27
|
+
allColumnsVisible ? true : someColumnsVisible ? ('indeterminate' as const) : false
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
function getColumnLabel(column: { columnDef: { header?: unknown }; id: string }) {
|
|
31
|
+
return typeof column.columnDef.header === 'string' ? column.columnDef.header : column.id;
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<Popover.Root positioning={{ placement: 'bottom-end' }}>
|
|
36
|
+
<Popover.Trigger
|
|
37
|
+
class="flex h-9 cursor-pointer items-center rounded-md border border-surface-3 bg-surface-1 px-3 text-sm font-medium text-ink shadow-sm outline-none hover:bg-surface-2 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"
|
|
38
|
+
>
|
|
39
|
+
{triggerLabel}
|
|
40
|
+
</Popover.Trigger>
|
|
41
|
+
|
|
42
|
+
<Popover.Content class="w-56 p-2" showArrow={false}>
|
|
43
|
+
<div class="border-b border-surface-3 px-2 pb-2">
|
|
44
|
+
<Checkbox
|
|
45
|
+
label="All columns"
|
|
46
|
+
checked={allColumnsVisibilityState}
|
|
47
|
+
onCheckedChange={({ checked }) => table.toggleAllColumnsVisible(checked === true)}
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
<ScrollArea.Root class="h-72">
|
|
52
|
+
<ScrollArea.Viewport>
|
|
53
|
+
<ScrollArea.Content class="py-1 pe-3">
|
|
54
|
+
<div class="flex flex-col">
|
|
55
|
+
{#each allLeafColumns as column (column.id)}
|
|
56
|
+
<Checkbox
|
|
57
|
+
label={getColumnLabel(column)}
|
|
58
|
+
class="min-h-8 rounded-sm px-2 hover:bg-surface-2"
|
|
59
|
+
checked={columnVisibility[column.id] !== false}
|
|
60
|
+
disabled={!column.getCanHide()}
|
|
61
|
+
onCheckedChange={({ checked }) => column.toggleVisibility(checked === true)}
|
|
62
|
+
/>
|
|
63
|
+
{/each}
|
|
64
|
+
</div>
|
|
65
|
+
</ScrollArea.Content>
|
|
66
|
+
</ScrollArea.Viewport>
|
|
67
|
+
<ScrollArea.Scrollbar orientation="vertical">
|
|
68
|
+
<ScrollArea.Thumb />
|
|
69
|
+
</ScrollArea.Scrollbar>
|
|
70
|
+
<ScrollArea.Corner />
|
|
71
|
+
</ScrollArea.Root>
|
|
72
|
+
</Popover.Content>
|
|
73
|
+
</Popover.Root>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
2
|
+
import type { DataTableInstance } from '../data-table-utils';
|
|
3
|
+
declare function $$render<T extends RowData>(): {
|
|
4
|
+
props: {
|
|
5
|
+
table: DataTableInstance<T>;
|
|
6
|
+
triggerLabel?: string;
|
|
7
|
+
};
|
|
8
|
+
exports: {};
|
|
9
|
+
bindings: "";
|
|
10
|
+
slots: {};
|
|
11
|
+
events: {};
|
|
12
|
+
};
|
|
13
|
+
declare class __sveltets_Render<T extends RowData> {
|
|
14
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
15
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
16
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
17
|
+
bindings(): "";
|
|
18
|
+
exports(): {};
|
|
19
|
+
}
|
|
20
|
+
interface $$IsomorphicComponent {
|
|
21
|
+
new <T extends RowData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
22
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
23
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
24
|
+
<T extends RowData>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
25
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
26
|
+
}
|
|
27
|
+
declare const DataTableColumnVisibility: $$IsomorphicComponent;
|
|
28
|
+
type DataTableColumnVisibility<T extends RowData> = InstanceType<typeof DataTableColumnVisibility<T>>;
|
|
29
|
+
export default DataTableColumnVisibility;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends RowData">
|
|
2
|
+
import { onDestroy } from 'svelte';
|
|
3
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
4
|
+
import { cn, type ClassValue } from 'tailwind-variants';
|
|
5
|
+
import { PhMagnifyingGlass, PhX } from '../../../icons';
|
|
6
|
+
import * as Field from '../../field';
|
|
7
|
+
import type { DataTableInstance } from '../data-table-utils';
|
|
8
|
+
|
|
9
|
+
type Props = {
|
|
10
|
+
table: DataTableInstance<T>;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
class?: ClassValue;
|
|
13
|
+
debounceMs?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
let { table, placeholder = 'Search...', class: className, debounceMs = 300 }: Props = $props();
|
|
17
|
+
|
|
18
|
+
const globalFilter = $derived.by(
|
|
19
|
+
() => (table.atoms.globalFilter.get() as string | undefined) ?? ''
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
23
|
+
|
|
24
|
+
onDestroy(() => clearTimeout(timer));
|
|
25
|
+
|
|
26
|
+
function handleInput(e: Event) {
|
|
27
|
+
const value = (e.currentTarget as HTMLInputElement).value;
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
timer = setTimeout(() => {
|
|
30
|
+
table.setGlobalFilter(value || undefined);
|
|
31
|
+
}, debounceMs);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function clearFilter() {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
table.setGlobalFilter(undefined);
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<Field.Root class={cn(className)}>
|
|
41
|
+
<Field.Input {placeholder} value={globalFilter} oninput={handleInput}>
|
|
42
|
+
{#snippet startIcon()}
|
|
43
|
+
<PhMagnifyingGlass class="size-4" />
|
|
44
|
+
{/snippet}
|
|
45
|
+
{#snippet endIcon()}
|
|
46
|
+
{#if globalFilter}
|
|
47
|
+
<button
|
|
48
|
+
type="button"
|
|
49
|
+
onclick={clearFilter}
|
|
50
|
+
aria-label="Clear search"
|
|
51
|
+
class="flex size-5 items-center justify-center rounded text-ink-dim hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
|
|
52
|
+
>
|
|
53
|
+
<PhX class="size-3.5" />
|
|
54
|
+
</button>
|
|
55
|
+
{/if}
|
|
56
|
+
{/snippet}
|
|
57
|
+
</Field.Input>
|
|
58
|
+
</Field.Root>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
2
|
+
import { type ClassValue } from 'tailwind-variants';
|
|
3
|
+
import type { DataTableInstance } from '../data-table-utils';
|
|
4
|
+
declare function $$render<T extends RowData>(): {
|
|
5
|
+
props: {
|
|
6
|
+
table: DataTableInstance<T>;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
class?: ClassValue;
|
|
9
|
+
debounceMs?: number;
|
|
10
|
+
};
|
|
11
|
+
exports: {};
|
|
12
|
+
bindings: "";
|
|
13
|
+
slots: {};
|
|
14
|
+
events: {};
|
|
15
|
+
};
|
|
16
|
+
declare class __sveltets_Render<T extends RowData> {
|
|
17
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
18
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
19
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
20
|
+
bindings(): "";
|
|
21
|
+
exports(): {};
|
|
22
|
+
}
|
|
23
|
+
interface $$IsomorphicComponent {
|
|
24
|
+
new <T extends RowData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
25
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
26
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
27
|
+
<T extends RowData>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
28
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
29
|
+
}
|
|
30
|
+
declare const DataTableSearch: $$IsomorphicComponent;
|
|
31
|
+
type DataTableSearch<T extends RowData> = InstanceType<typeof DataTableSearch<T>>;
|
|
32
|
+
export default DataTableSearch;
|
|
@@ -21,20 +21,19 @@
|
|
|
21
21
|
{@render children?.()}
|
|
22
22
|
</div>
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{#if right}
|
|
33
|
-
<div
|
|
34
|
-
class="col-start-3 row-start-1 flex min-w-0 flex-wrap items-center justify-end gap-3 justify-self-end"
|
|
35
|
-
>
|
|
36
|
-
{@render right()}
|
|
37
|
-
</div>
|
|
38
|
-
{/if}
|
|
24
|
+
{#if center}
|
|
25
|
+
<div
|
|
26
|
+
class="col-start-2 row-start-1 flex min-w-0 flex-wrap items-center justify-center gap-3 justify-self-center"
|
|
27
|
+
>
|
|
28
|
+
{@render center()}
|
|
29
|
+
</div>
|
|
30
|
+
{/if}
|
|
39
31
|
|
|
32
|
+
{#if right}
|
|
33
|
+
<div
|
|
34
|
+
class="col-start-3 row-start-1 flex min-w-0 flex-wrap items-center justify-end gap-3 justify-self-end"
|
|
35
|
+
>
|
|
36
|
+
{@render right()}
|
|
37
|
+
</div>
|
|
38
|
+
{/if}
|
|
40
39
|
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import { type ClassValue } from 'tailwind-variants';
|
|
4
|
+
type Props = Omit<HTMLAttributes<HTMLDivElement>, 'class'> & {
|
|
5
|
+
class?: ClassValue;
|
|
6
|
+
children?: Snippet;
|
|
7
|
+
center?: Snippet;
|
|
8
|
+
right?: Snippet;
|
|
9
|
+
};
|
|
10
|
+
declare const DataTableToolbar: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type DataTableToolbar = ReturnType<typeof DataTableToolbar>;
|
|
12
|
+
export default DataTableToolbar;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { FilterFnOption, RowData } from '@tanstack/svelte-table';
|
|
2
|
+
import type { Component, Snippet } from 'svelte';
|
|
3
|
+
import type { DataTableFeatures } from './features';
|
|
4
|
+
export type DataTableAlign = 'left' | 'center' | 'right';
|
|
5
|
+
export type DataTableColumnType = 'text' | 'number' | 'currency' | 'percent' | 'boolean' | 'select' | 'url' | 'date' | 'time' | 'date-time';
|
|
6
|
+
export type DataTableCellRenderer<T extends RowData> = (value: unknown, row: T) => string | number | boolean | null | undefined;
|
|
7
|
+
export type DataTableCellRenderProps<T extends RowData> = {
|
|
8
|
+
value: unknown;
|
|
9
|
+
row: T;
|
|
10
|
+
};
|
|
11
|
+
export type DataTableCellPropsResolver<T extends RowData> = (value: unknown, row: T) => Record<string, unknown>;
|
|
12
|
+
export type DataTableColumnOptions<T extends RowData> = {
|
|
13
|
+
size?: number;
|
|
14
|
+
minSize?: number;
|
|
15
|
+
maxSize?: number;
|
|
16
|
+
enableResizing?: boolean;
|
|
17
|
+
enableHiding?: boolean;
|
|
18
|
+
enableSorting?: boolean;
|
|
19
|
+
sortDescFirst?: boolean;
|
|
20
|
+
enableColumnFilter?: boolean;
|
|
21
|
+
filterFn?: FilterFnOption<DataTableFeatures, T>;
|
|
22
|
+
};
|
|
23
|
+
export type DataTableColumnBase = {
|
|
24
|
+
header: string;
|
|
25
|
+
align?: DataTableAlign;
|
|
26
|
+
};
|
|
27
|
+
export type DataTableLeafColumnBase<T extends RowData> = DataTableColumnOptions<T> & DataTableColumnBase & {
|
|
28
|
+
cell?: DataTableCellRenderer<T>;
|
|
29
|
+
cellComponent?: Component<DataTableCellRenderProps<T>> | Component<never>;
|
|
30
|
+
cellProps?: DataTableCellPropsResolver<T>;
|
|
31
|
+
cellSnippet?: Snippet<[DataTableCellRenderProps<T>]>;
|
|
32
|
+
type?: DataTableColumnType;
|
|
33
|
+
formatOptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions;
|
|
34
|
+
formatLocale?: string;
|
|
35
|
+
pinned?: 'left' | 'right';
|
|
36
|
+
grow?: boolean;
|
|
37
|
+
sum?: boolean;
|
|
38
|
+
footer?: (values: unknown[]) => string | number | undefined;
|
|
39
|
+
columns?: never;
|
|
40
|
+
};
|
|
41
|
+
export type DataTableAccessorKeyColumn<T extends RowData> = DataTableLeafColumnBase<T> & {
|
|
42
|
+
accessorKey: Extract<keyof T, string>;
|
|
43
|
+
id?: string;
|
|
44
|
+
accessorFn?: never;
|
|
45
|
+
};
|
|
46
|
+
export type DataTableAccessorFnColumn<T extends RowData> = DataTableLeafColumnBase<T> & {
|
|
47
|
+
accessorFn: (row: T) => unknown;
|
|
48
|
+
id: string;
|
|
49
|
+
accessorKey?: never;
|
|
50
|
+
};
|
|
51
|
+
export type DataTableLeafColumn<T extends RowData> = DataTableAccessorKeyColumn<T> | DataTableAccessorFnColumn<T>;
|
|
52
|
+
export type DataTableGroupColumn<T extends RowData> = DataTableColumnBase & {
|
|
53
|
+
id?: string;
|
|
54
|
+
columns: DataTableColumn<T>[];
|
|
55
|
+
accessorKey?: never;
|
|
56
|
+
accessorFn?: never;
|
|
57
|
+
cell?: never;
|
|
58
|
+
cellComponent?: never;
|
|
59
|
+
cellProps?: never;
|
|
60
|
+
cellSnippet?: never;
|
|
61
|
+
type?: never;
|
|
62
|
+
formatOptions?: never;
|
|
63
|
+
formatLocale?: never;
|
|
64
|
+
};
|
|
65
|
+
export type DataTableColumn<T extends RowData> = DataTableLeafColumn<T> | DataTableGroupColumn<T>;
|
|
66
|
+
export type DataTableColumnMeta = {
|
|
67
|
+
align?: DataTableAlign;
|
|
68
|
+
type?: DataTableColumnType;
|
|
69
|
+
formatOptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions;
|
|
70
|
+
formatLocale?: string;
|
|
71
|
+
grow?: boolean;
|
|
72
|
+
sum?: boolean;
|
|
73
|
+
footer?: (values: unknown[]) => string | number | undefined;
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends RowData">
|
|
2
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
3
|
+
import { createVirtualizer } from '@tanstack/svelte-virtual';
|
|
4
|
+
import { untrack } from 'svelte';
|
|
5
|
+
import { cn } from 'tailwind-variants';
|
|
6
|
+
import type { DataTableInstance } from '../data-table-utils';
|
|
7
|
+
import type { DataTableViewState } from '../table-view-state.svelte';
|
|
8
|
+
import DataTableCellContent from '../data-table-cell-content.svelte';
|
|
9
|
+
import {
|
|
10
|
+
alignClass,
|
|
11
|
+
getColumnMeta,
|
|
12
|
+
getPinningStyle,
|
|
13
|
+
getRowCells,
|
|
14
|
+
joinStyles,
|
|
15
|
+
justifyClass,
|
|
16
|
+
virtualColumnSizeStyle,
|
|
17
|
+
virtualGrowColumnSizeStyle,
|
|
18
|
+
virtualSelectionColumnSizeStyle
|
|
19
|
+
} from '../data-table-utils';
|
|
20
|
+
|
|
21
|
+
type Props = {
|
|
22
|
+
table: DataTableInstance<T>;
|
|
23
|
+
view: DataTableViewState<T>;
|
|
24
|
+
scrollContainer: HTMLDivElement;
|
|
25
|
+
emptyMessage: string;
|
|
26
|
+
onRowClick?: (details: { row: T; event: MouseEvent }) => void;
|
|
27
|
+
onRowDoubleClick?: (details: { row: T; event: MouseEvent }) => void;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
let { table, view, scrollContainer, emptyMessage, onRowClick, onRowDoubleClick }: Props =
|
|
31
|
+
$props();
|
|
32
|
+
|
|
33
|
+
const rows = $derived(view.rowModel.rows);
|
|
34
|
+
|
|
35
|
+
const rowVirtualizer = createVirtualizer<HTMLDivElement, HTMLTableRowElement>({
|
|
36
|
+
get count() {
|
|
37
|
+
return rows.length;
|
|
38
|
+
},
|
|
39
|
+
estimateSize: () => 37,
|
|
40
|
+
getScrollElement: () => scrollContainer,
|
|
41
|
+
// Upstream-recommended workaround: dynamic measurement is skipped on
|
|
42
|
+
// Firefox because its sub-pixel row heights make the virtualizer jitter.
|
|
43
|
+
measureElement:
|
|
44
|
+
typeof window !== 'undefined' && !navigator.userAgent.includes('Firefox')
|
|
45
|
+
? (element) => element.getBoundingClientRect().height
|
|
46
|
+
: undefined,
|
|
47
|
+
overscan: 5
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function measureRowElement(node: HTMLTableRowElement) {
|
|
51
|
+
$rowVirtualizer.measureElement(node);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
$effect(() => {
|
|
55
|
+
const count = rows.length;
|
|
56
|
+
untrack(() => {
|
|
57
|
+
$rowVirtualizer.setOptions({ ...$rowVirtualizer.options, count });
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<tbody style="display: grid; height: {$rowVirtualizer.getTotalSize()}px; position: relative">
|
|
63
|
+
{#if rows.length === 0}
|
|
64
|
+
<tr style="display: flex; position: absolute; width: 100%; top: 0">
|
|
65
|
+
<td class="px-3 py-10 text-center text-sm text-ink-dim" style="flex: 1">
|
|
66
|
+
{emptyMessage}
|
|
67
|
+
</td>
|
|
68
|
+
</tr>
|
|
69
|
+
{:else}
|
|
70
|
+
{#each $rowVirtualizer.getVirtualItems() as virtualRow (virtualRow.index)}
|
|
71
|
+
{@const row = rows[virtualRow.index]}
|
|
72
|
+
{#if row}
|
|
73
|
+
{@const rowSelected = view.rowSelection[row.id] === true}
|
|
74
|
+
<tr
|
|
75
|
+
data-index={virtualRow.index}
|
|
76
|
+
use:measureRowElement
|
|
77
|
+
class={cn(
|
|
78
|
+
'group/row border-b border-surface-2 last:border-b-0',
|
|
79
|
+
'[--row-bg:var(--compote-surface-1)]',
|
|
80
|
+
'hover:bg-well/60 hover:[--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]',
|
|
81
|
+
rowSelected &&
|
|
82
|
+
'bg-well/60 [--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]'
|
|
83
|
+
)}
|
|
84
|
+
style="display: flex; position: absolute; transform: translateY({virtualRow.start}px); width: 100%"
|
|
85
|
+
onclick={(event) => onRowClick?.({ row: row.original, event })}
|
|
86
|
+
ondblclick={(event) => onRowDoubleClick?.({ row: row.original, event })}
|
|
87
|
+
>
|
|
88
|
+
{#if view.isRowSelectionEnabled}
|
|
89
|
+
<td
|
|
90
|
+
class="items-center justify-center bg-(--row-bg) px-3 py-2 text-center align-middle"
|
|
91
|
+
style={joinStyles(
|
|
92
|
+
virtualSelectionColumnSizeStyle(),
|
|
93
|
+
'position: sticky; left: 0; z-index: 1'
|
|
94
|
+
)}
|
|
95
|
+
onclick={(event) => event.stopPropagation()}
|
|
96
|
+
ondblclick={(event) => event.stopPropagation()}
|
|
97
|
+
>
|
|
98
|
+
<input
|
|
99
|
+
type="checkbox"
|
|
100
|
+
aria-label="Select row"
|
|
101
|
+
class="table-checkbox mx-auto block size-4"
|
|
102
|
+
checked={rowSelected}
|
|
103
|
+
disabled={!row.getCanSelect()}
|
|
104
|
+
onchange={(e) => row.toggleSelected(e.currentTarget.checked)}
|
|
105
|
+
/>
|
|
106
|
+
</td>
|
|
107
|
+
{/if}
|
|
108
|
+
{#each getRowCells(row, view) as cell (cell.id)}
|
|
109
|
+
{@const meta = getColumnMeta(cell.column.columnDef)}
|
|
110
|
+
<td
|
|
111
|
+
class={cn(
|
|
112
|
+
'items-center truncate px-3 py-2',
|
|
113
|
+
alignClass(meta?.align),
|
|
114
|
+
justifyClass(meta?.align),
|
|
115
|
+
cell.column.getIsPinned() && 'bg-(--row-bg)'
|
|
116
|
+
)}
|
|
117
|
+
style={joinStyles(
|
|
118
|
+
meta?.grow
|
|
119
|
+
? virtualGrowColumnSizeStyle()
|
|
120
|
+
: virtualColumnSizeStyle(cell.column.getSize()),
|
|
121
|
+
getPinningStyle(cell.column, table, view, false, view.isRowSelectionEnabled)
|
|
122
|
+
)}
|
|
123
|
+
>
|
|
124
|
+
<DataTableCellContent {cell} />
|
|
125
|
+
</td>
|
|
126
|
+
{/each}
|
|
127
|
+
</tr>
|
|
128
|
+
{/if}
|
|
129
|
+
{/each}
|
|
130
|
+
{/if}
|
|
131
|
+
</tbody>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
2
|
+
import type { DataTableInstance } from '../data-table-utils';
|
|
3
|
+
import type { DataTableViewState } from '../table-view-state.svelte';
|
|
4
|
+
declare function $$render<T extends RowData>(): {
|
|
5
|
+
props: {
|
|
6
|
+
table: DataTableInstance<T>;
|
|
7
|
+
view: DataTableViewState<T>;
|
|
8
|
+
scrollContainer: HTMLDivElement;
|
|
9
|
+
emptyMessage: string;
|
|
10
|
+
onRowClick?: (details: {
|
|
11
|
+
row: T;
|
|
12
|
+
event: MouseEvent;
|
|
13
|
+
}) => void;
|
|
14
|
+
onRowDoubleClick?: (details: {
|
|
15
|
+
row: T;
|
|
16
|
+
event: MouseEvent;
|
|
17
|
+
}) => void;
|
|
18
|
+
};
|
|
19
|
+
exports: {};
|
|
20
|
+
bindings: "";
|
|
21
|
+
slots: {};
|
|
22
|
+
events: {};
|
|
23
|
+
};
|
|
24
|
+
declare class __sveltets_Render<T extends RowData> {
|
|
25
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
26
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
27
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
28
|
+
bindings(): "";
|
|
29
|
+
exports(): {};
|
|
30
|
+
}
|
|
31
|
+
interface $$IsomorphicComponent {
|
|
32
|
+
new <T extends RowData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
33
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
34
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
35
|
+
<T extends RowData>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
36
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
37
|
+
}
|
|
38
|
+
declare const DataTableVirtualRows: $$IsomorphicComponent;
|
|
39
|
+
type DataTableVirtualRows<T extends RowData> = InstanceType<typeof DataTableVirtualRows<T>>;
|
|
40
|
+
export default DataTableVirtualRows;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends RowData">
|
|
2
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
import { cn, type ClassValue } from 'tailwind-variants';
|
|
5
|
+
import type { DataTableInstance } from '../data-table-utils';
|
|
6
|
+
import { createTableViewState } from '../table-view-state.svelte';
|
|
7
|
+
import DataTableHead from '../data-table-head.svelte';
|
|
8
|
+
import DataTableFoot from '../data-table-foot.svelte';
|
|
9
|
+
import DataTableVirtualRows from './data-table-virtual-rows.svelte';
|
|
10
|
+
import { tableSizeStyle } from '../data-table-utils';
|
|
11
|
+
|
|
12
|
+
type Props = Omit<HTMLAttributes<HTMLDivElement>, 'class'> & {
|
|
13
|
+
table: DataTableInstance<T>;
|
|
14
|
+
caption?: string;
|
|
15
|
+
emptyMessage?: string;
|
|
16
|
+
class?: ClassValue;
|
|
17
|
+
onRowClick?: (details: { row: T; event: MouseEvent }) => void;
|
|
18
|
+
onRowDoubleClick?: (details: { row: T; event: MouseEvent }) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
table,
|
|
23
|
+
caption,
|
|
24
|
+
emptyMessage = 'No rows found',
|
|
25
|
+
class: className,
|
|
26
|
+
onRowClick,
|
|
27
|
+
onRowDoubleClick,
|
|
28
|
+
...rest
|
|
29
|
+
}: Props = $props();
|
|
30
|
+
|
|
31
|
+
let scrollContainerRef = $state<HTMLDivElement | undefined>(undefined);
|
|
32
|
+
|
|
33
|
+
const view = createTableViewState(() => table);
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<div
|
|
37
|
+
class={cn(
|
|
38
|
+
'flex max-h-full min-h-0 flex-col overflow-hidden rounded-lg border border-surface-3 bg-surface-1',
|
|
39
|
+
className
|
|
40
|
+
)}
|
|
41
|
+
{...rest}
|
|
42
|
+
>
|
|
43
|
+
{#if view.isColumnResizing}
|
|
44
|
+
<div aria-hidden="true" class="fixed inset-0 z-50 cursor-col-resize select-none"></div>
|
|
45
|
+
{/if}
|
|
46
|
+
|
|
47
|
+
<div class="min-h-0 flex-1 overflow-auto" bind:this={scrollContainerRef}>
|
|
48
|
+
<table
|
|
49
|
+
class="table-fixed border-separate border-spacing-0 text-sm"
|
|
50
|
+
style="display: grid; {tableSizeStyle(table, view.isRowSelectionEnabled, view)}"
|
|
51
|
+
>
|
|
52
|
+
{#if caption}
|
|
53
|
+
<caption class="sr-only">{caption}</caption>
|
|
54
|
+
{/if}
|
|
55
|
+
<DataTableHead {table} {view} isVirtual />
|
|
56
|
+
{#if scrollContainerRef}
|
|
57
|
+
<DataTableVirtualRows
|
|
58
|
+
{table}
|
|
59
|
+
{view}
|
|
60
|
+
scrollContainer={scrollContainerRef}
|
|
61
|
+
{emptyMessage}
|
|
62
|
+
{onRowClick}
|
|
63
|
+
{onRowDoubleClick}
|
|
64
|
+
/>
|
|
65
|
+
{/if}
|
|
66
|
+
{#if view.hasFooter}
|
|
67
|
+
<DataTableFoot {table} {view} hasGrowColumn={false} isVirtual />
|
|
68
|
+
{/if}
|
|
69
|
+
</table>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div class="shrink-0 border-t border-surface-3 bg-surface-2 px-3 py-2 text-sm text-ink-dim">
|
|
73
|
+
{#if view.isRowSelectionEnabled}
|
|
74
|
+
{view.selectedRowCount} of {view.rowModel.rows.length} rows selected
|
|
75
|
+
{:else}
|
|
76
|
+
{view.rowModel.rows.length} rows
|
|
77
|
+
{/if}
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import { type ClassValue } from 'tailwind-variants';
|
|
4
|
+
import type { DataTableInstance } from '../data-table-utils';
|
|
5
|
+
declare function $$render<T extends RowData>(): {
|
|
6
|
+
props: Omit<HTMLAttributes<HTMLDivElement>, "class"> & {
|
|
7
|
+
table: DataTableInstance<T>;
|
|
8
|
+
caption?: string;
|
|
9
|
+
emptyMessage?: string;
|
|
10
|
+
class?: ClassValue;
|
|
11
|
+
onRowClick?: (details: {
|
|
12
|
+
row: T;
|
|
13
|
+
event: MouseEvent;
|
|
14
|
+
}) => void;
|
|
15
|
+
onRowDoubleClick?: (details: {
|
|
16
|
+
row: T;
|
|
17
|
+
event: MouseEvent;
|
|
18
|
+
}) => void;
|
|
19
|
+
};
|
|
20
|
+
exports: {};
|
|
21
|
+
bindings: "";
|
|
22
|
+
slots: {};
|
|
23
|
+
events: {};
|
|
24
|
+
};
|
|
25
|
+
declare class __sveltets_Render<T extends RowData> {
|
|
26
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
27
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
28
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
29
|
+
bindings(): "";
|
|
30
|
+
exports(): {};
|
|
31
|
+
}
|
|
32
|
+
interface $$IsomorphicComponent {
|
|
33
|
+
new <T extends RowData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
34
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
35
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
36
|
+
<T extends RowData>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
37
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
38
|
+
}
|
|
39
|
+
declare const DataTableVirtualized: $$IsomorphicComponent;
|
|
40
|
+
type DataTableVirtualized<T extends RowData> = InstanceType<typeof DataTableVirtualized<T>>;
|
|
41
|
+
export default DataTableVirtualized;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { default as Root } from './data-table-virtualized.svelte';
|
|
2
|
+
export { ColumnFilter, ColumnVisibility, FlexRender, Search, Title, Toolbar, createDataTableColumnHelper, createTable, renderComponent, renderSnippet } from '../index';
|
|
3
|
+
export type { CreateDataTableOptions, DataTableAccessorFnColumn, DataTableAccessorKeyColumn, DataTableAlign, DataTableCellPropsResolver, DataTableCellRenderProps, DataTableColumn, DataTableColumnBase, DataTableColumnOptions, DataTableColumnType, DataTableGroupColumn, DataTableInstance, DataTableLeafColumn, DataTableLeafColumnBase } from '../index';
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export type { DatePickerProps } from './components/date-picker/types';
|
|
|
23
23
|
export * as Dialog from './components/dialog';
|
|
24
24
|
export { default as AlertDialog } from './components/dialog/alert-dialog.svelte';
|
|
25
25
|
export type { AlertDialogProps } from './components/dialog/dialog.types';
|
|
26
|
+
export * as DataTable from './components/data-table-v9';
|
|
27
|
+
export * as VirtualDataTable from './components/data-table-v9/virtual';
|
|
28
|
+
export * as DataTableV8 from './components/data-table-v8';
|
|
29
|
+
export * as VirtualDataTableV8 from './components/data-table-v8/virtual';
|
|
26
30
|
export * as Drawer from './components/drawer';
|
|
27
31
|
export { default as FileUploadDropzone } from './components/file-upload/file-upload-dropzone.svelte';
|
|
28
32
|
export { default as FileUpload } from './components/file-upload/file-upload.svelte';
|