@invopop/popui 0.1.35 → 0.1.41
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/BaseButton.svelte +4 -0
- package/dist/BaseDropdown.svelte +42 -3
- package/dist/BaseDropdown.svelte.d.ts +1 -0
- package/dist/BaseTableHeaderOrderBy.svelte +35 -12
- package/dist/ButtonSearch.svelte +82 -0
- package/dist/ButtonSearch.svelte.d.ts +4 -0
- package/dist/ButtonUuidCopy.svelte +1 -0
- package/dist/DatePicker.svelte +96 -27
- package/dist/DatePicker.svelte.d.ts +5 -1
- package/dist/DrawerContext.svelte +443 -34
- package/dist/DrawerContextItem.svelte +36 -29
- package/dist/DropdownSelect.svelte +68 -18
- package/dist/DropdownSelect.svelte.d.ts +4 -1
- package/dist/DropdownSelectGroup.svelte +15 -0
- package/dist/DropdownSelectGroup.svelte.d.ts +7 -0
- package/dist/EmptyState.svelte +6 -2
- package/dist/InputSearch.svelte +45 -5
- package/dist/InputSelect.svelte +12 -3
- package/dist/InputText.svelte +25 -8
- package/dist/InputToggle.svelte +23 -6
- package/dist/StepIcon.svelte +35 -0
- package/dist/StepIcon.svelte.d.ts +4 -0
- package/dist/StepIconList.svelte +24 -31
- package/dist/TagStatus.svelte +1 -1
- package/dist/button/button.svelte +34 -3
- package/dist/button/button.svelte.d.ts +29 -0
- package/dist/clickOutside.d.ts +5 -2
- package/dist/clickOutside.js +9 -3
- package/dist/data-table/cells/boolean-cell.svelte +29 -0
- package/dist/data-table/cells/boolean-cell.svelte.d.ts +8 -0
- package/dist/data-table/cells/cell-skeleton.svelte +35 -0
- package/dist/data-table/cells/cell-skeleton.svelte.d.ts +4 -0
- package/dist/data-table/cells/currency-cell.svelte +10 -0
- package/dist/data-table/cells/currency-cell.svelte.d.ts +8 -0
- package/dist/data-table/cells/date-cell.svelte +10 -0
- package/dist/data-table/cells/date-cell.svelte.d.ts +8 -0
- package/dist/data-table/cells/tag-cell.svelte +12 -0
- package/dist/data-table/cells/tag-cell.svelte.d.ts +8 -0
- package/dist/data-table/cells/text-cell.svelte +10 -0
- package/dist/data-table/cells/text-cell.svelte.d.ts +8 -0
- package/dist/data-table/cells/uuid-cell.svelte +17 -0
- package/dist/data-table/cells/uuid-cell.svelte.d.ts +8 -0
- package/dist/data-table/column-definitions.d.ts +12 -0
- package/dist/data-table/column-definitions.js +42 -0
- package/dist/data-table/column-sizing-helpers.d.ts +6 -0
- package/dist/data-table/column-sizing-helpers.js +24 -0
- package/dist/data-table/create-columns.d.ts +3 -0
- package/dist/data-table/create-columns.js +67 -0
- package/dist/data-table/data-table-cell.svelte +94 -0
- package/dist/data-table/data-table-cell.svelte.d.ts +25 -0
- package/dist/data-table/data-table-header-cell.svelte +188 -0
- package/dist/data-table/data-table-header-cell.svelte.d.ts +25 -0
- package/dist/data-table/data-table-helpers.d.ts +10 -0
- package/dist/data-table/data-table-helpers.js +124 -0
- package/dist/data-table/data-table-pagination.svelte +221 -0
- package/dist/data-table/data-table-pagination.svelte.d.ts +4 -0
- package/dist/data-table/data-table-row.svelte +57 -0
- package/dist/data-table/data-table-row.svelte.d.ts +25 -0
- package/dist/data-table/data-table-svelte.svelte.d.ts +40 -0
- package/dist/data-table/data-table-svelte.svelte.js +115 -0
- package/dist/data-table/data-table-toolbar.svelte +19 -0
- package/dist/data-table/data-table-toolbar.svelte.d.ts +32 -0
- package/dist/data-table/data-table-types.d.ts +196 -0
- package/dist/data-table/data-table-types.js +1 -0
- package/dist/data-table/data-table-view-options.svelte +126 -0
- package/dist/data-table/data-table-view-options.svelte.d.ts +29 -0
- package/dist/data-table/data-table.svelte +437 -0
- package/dist/data-table/data-table.svelte.d.ts +25 -0
- package/dist/data-table/flex-render.svelte +40 -0
- package/dist/data-table/flex-render.svelte.d.ts +33 -0
- package/dist/data-table/index.d.ts +13 -0
- package/dist/data-table/index.js +13 -0
- package/dist/data-table/render-helpers.d.ts +90 -0
- package/dist/data-table/render-helpers.js +99 -0
- package/dist/data-table/table-setup.d.ts +39 -0
- package/dist/data-table/table-setup.js +151 -0
- package/dist/data-table/table-styles.d.ts +17 -0
- package/dist/data-table/table-styles.js +70 -0
- package/dist/drawer-dnd-helpers.d.ts +30 -0
- package/dist/drawer-dnd-helpers.js +72 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +3 -0
- package/dist/index.d.ts +15 -3
- package/dist/index.js +28 -5
- package/dist/skeleton/index.d.ts +5 -0
- package/dist/skeleton/index.js +7 -0
- package/dist/skeleton/skeleton-avatar.svelte +14 -0
- package/dist/skeleton/skeleton-avatar.svelte.d.ts +7 -0
- package/dist/skeleton/skeleton-card.svelte +22 -0
- package/dist/skeleton/skeleton-card.svelte.d.ts +9 -0
- package/dist/skeleton/skeleton-list.svelte +25 -0
- package/dist/skeleton/skeleton-list.svelte.d.ts +8 -0
- package/dist/skeleton/skeleton.svelte +17 -0
- package/dist/skeleton/skeleton.svelte.d.ts +5 -0
- package/dist/svg/IconDelivery.svelte +1 -1
- package/dist/svg/IconOrder.svelte +1 -1
- package/dist/svg/IconPayment.svelte +1 -1
- package/dist/table/table-cell.svelte +4 -2
- package/dist/table/table-head.svelte +4 -2
- package/dist/table/table-header.svelte +1 -1
- package/dist/table/table-row.svelte +4 -2
- package/dist/table/table.svelte +2 -2
- package/dist/tailwind.theme.css +30 -6
- package/dist/tooltip/index.d.ts +2 -1
- package/dist/tooltip/index.js +3 -2
- package/dist/tooltip/tooltip-auto-hide.svelte +31 -0
- package/dist/tooltip/tooltip-auto-hide.svelte.d.ts +7 -0
- package/dist/types.d.ts +51 -73
- package/package.json +14 -8
- package/dist/BaseTable.svelte +0 -391
- package/dist/BaseTable.svelte.d.ts +0 -4
- package/dist/BaseTableCellContent.svelte +0 -58
- package/dist/BaseTableCellContent.svelte.d.ts +0 -4
- package/dist/BaseTableCheckbox.svelte +0 -33
- package/dist/BaseTableCheckbox.svelte.d.ts +0 -4
- package/dist/BaseTableHeaderContent.svelte +0 -67
- package/dist/BaseTableHeaderContent.svelte.d.ts +0 -4
- package/dist/BaseTableRow.svelte +0 -127
- package/dist/BaseTableRow.svelte.d.ts +0 -4
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type RowData, type TableOptions } from "@tanstack/table-core";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a reactive TanStack table object for Svelte.
|
|
4
|
+
* @param options Table options to create the table with.
|
|
5
|
+
* @returns A reactive table object.
|
|
6
|
+
* @example
|
|
7
|
+
* ```svelte
|
|
8
|
+
* <script>
|
|
9
|
+
* const table = createSvelteTable({ ... })
|
|
10
|
+
* </script>
|
|
11
|
+
*
|
|
12
|
+
* <table>
|
|
13
|
+
* <thead>
|
|
14
|
+
* {#each table.getHeaderGroups() as headerGroup}
|
|
15
|
+
* <tr>
|
|
16
|
+
* {#each headerGroup.headers as header}
|
|
17
|
+
* <th colspan={header.colSpan}>
|
|
18
|
+
* <FlexRender content={header.column.columnDef.header} context={header.getContext()} />
|
|
19
|
+
* </th>
|
|
20
|
+
* {/each}
|
|
21
|
+
* </tr>
|
|
22
|
+
* {/each}
|
|
23
|
+
* </thead>
|
|
24
|
+
* <!-- ... -->
|
|
25
|
+
* </table>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function createSvelteTable<TData extends RowData>(options: TableOptions<TData>): import("@tanstack/table-core").Table<TData>;
|
|
29
|
+
type MaybeThunk<T extends object> = T | (() => T | null | undefined);
|
|
30
|
+
type Intersection<T extends readonly unknown[]> = (T extends [infer H, ...infer R] ? H & Intersection<R> : unknown) & {};
|
|
31
|
+
/**
|
|
32
|
+
* Lazily merges several objects (or thunks) while preserving
|
|
33
|
+
* getter semantics from every source.
|
|
34
|
+
*
|
|
35
|
+
* Proxy-based to avoid known WebKit recursion issue.
|
|
36
|
+
*/
|
|
37
|
+
export declare function mergeObjects<Sources extends readonly MaybeThunk<any>[]>(...sources: Sources): Intersection<{
|
|
38
|
+
[K in keyof Sources]: Sources[K];
|
|
39
|
+
}>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createTable, } from "@tanstack/table-core";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a reactive TanStack table object for Svelte.
|
|
4
|
+
* @param options Table options to create the table with.
|
|
5
|
+
* @returns A reactive table object.
|
|
6
|
+
* @example
|
|
7
|
+
* ```svelte
|
|
8
|
+
* <script>
|
|
9
|
+
* const table = createSvelteTable({ ... })
|
|
10
|
+
* </script>
|
|
11
|
+
*
|
|
12
|
+
* <table>
|
|
13
|
+
* <thead>
|
|
14
|
+
* {#each table.getHeaderGroups() as headerGroup}
|
|
15
|
+
* <tr>
|
|
16
|
+
* {#each headerGroup.headers as header}
|
|
17
|
+
* <th colspan={header.colSpan}>
|
|
18
|
+
* <FlexRender content={header.column.columnDef.header} context={header.getContext()} />
|
|
19
|
+
* </th>
|
|
20
|
+
* {/each}
|
|
21
|
+
* </tr>
|
|
22
|
+
* {/each}
|
|
23
|
+
* </thead>
|
|
24
|
+
* <!-- ... -->
|
|
25
|
+
* </table>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function createSvelteTable(options) {
|
|
29
|
+
const resolvedOptions = mergeObjects({
|
|
30
|
+
state: {},
|
|
31
|
+
onStateChange() { },
|
|
32
|
+
renderFallbackValue: null,
|
|
33
|
+
mergeOptions: (defaultOptions, options) => {
|
|
34
|
+
return mergeObjects(defaultOptions, options);
|
|
35
|
+
},
|
|
36
|
+
}, options);
|
|
37
|
+
const table = createTable(resolvedOptions);
|
|
38
|
+
let state = $state(table.initialState);
|
|
39
|
+
function updateOptions() {
|
|
40
|
+
table.setOptions((prev) => {
|
|
41
|
+
return mergeObjects(prev, options, {
|
|
42
|
+
state: mergeObjects(state, options.state || {}),
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
onStateChange: (updater) => {
|
|
45
|
+
if (updater instanceof Function)
|
|
46
|
+
state = updater(state);
|
|
47
|
+
else
|
|
48
|
+
state = mergeObjects(state, updater);
|
|
49
|
+
options.onStateChange?.(updater);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
updateOptions();
|
|
55
|
+
$effect.pre(() => {
|
|
56
|
+
// Access data and columns to track them - this reads but doesn't write
|
|
57
|
+
// so it won't cause infinite loops
|
|
58
|
+
void options.data;
|
|
59
|
+
void options.columns;
|
|
60
|
+
updateOptions();
|
|
61
|
+
});
|
|
62
|
+
return table;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Lazily merges several objects (or thunks) while preserving
|
|
66
|
+
* getter semantics from every source.
|
|
67
|
+
*
|
|
68
|
+
* Proxy-based to avoid known WebKit recursion issue.
|
|
69
|
+
*/
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
export function mergeObjects(...sources) {
|
|
72
|
+
const resolve = (src) => typeof src === "function" ? (src() ?? undefined) : src;
|
|
73
|
+
const findSourceWithKey = (key) => {
|
|
74
|
+
for (let i = sources.length - 1; i >= 0; i--) {
|
|
75
|
+
const obj = resolve(sources[i]);
|
|
76
|
+
if (obj && key in obj)
|
|
77
|
+
return obj;
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
|
81
|
+
return new Proxy(Object.create(null), {
|
|
82
|
+
get(_, key) {
|
|
83
|
+
const src = findSourceWithKey(key);
|
|
84
|
+
return src?.[key];
|
|
85
|
+
},
|
|
86
|
+
has(_, key) {
|
|
87
|
+
return !!findSourceWithKey(key);
|
|
88
|
+
},
|
|
89
|
+
ownKeys() {
|
|
90
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
91
|
+
const all = new Set();
|
|
92
|
+
for (const s of sources) {
|
|
93
|
+
const obj = resolve(s);
|
|
94
|
+
if (obj) {
|
|
95
|
+
for (const k of Reflect.ownKeys(obj)) {
|
|
96
|
+
all.add(k);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return [...all];
|
|
101
|
+
},
|
|
102
|
+
getOwnPropertyDescriptor(_, key) {
|
|
103
|
+
const src = findSourceWithKey(key);
|
|
104
|
+
if (!src)
|
|
105
|
+
return undefined;
|
|
106
|
+
return {
|
|
107
|
+
configurable: true,
|
|
108
|
+
enumerable: true,
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
+
value: src[key],
|
|
111
|
+
writable: true,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script lang="ts" generics="TData">
|
|
2
|
+
import type { Table } from '@tanstack/table-core'
|
|
3
|
+
import type { Snippet } from 'svelte'
|
|
4
|
+
import { DataTableViewOptions } from './index.js'
|
|
5
|
+
import clsx from 'clsx'
|
|
6
|
+
|
|
7
|
+
let { table, filters, frozenColumns, onFreezeColumn, disabled = false }: { table: Table<TData>; filters?: Snippet; frozenColumns: Set<string>; onFreezeColumn: (columnId: string) => void; disabled?: boolean } = $props()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<div class={clsx('flex items-center justify-between px-4 py-2.5', {
|
|
11
|
+
'pointer-events-none opacity-30': disabled
|
|
12
|
+
})}>
|
|
13
|
+
{#if filters}
|
|
14
|
+
<div class="flex-1">
|
|
15
|
+
{@render filters()}
|
|
16
|
+
</div>
|
|
17
|
+
{/if}
|
|
18
|
+
<DataTableViewOptions {table} {frozenColumns} {onFreezeColumn} />
|
|
19
|
+
</div>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Table } from '@tanstack/table-core';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
declare function $$render<TData>(): {
|
|
4
|
+
props: {
|
|
5
|
+
table: Table<TData>;
|
|
6
|
+
filters?: Snippet;
|
|
7
|
+
frozenColumns: Set<string>;
|
|
8
|
+
onFreezeColumn: (columnId: string) => void;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
exports: {};
|
|
12
|
+
bindings: "";
|
|
13
|
+
slots: {};
|
|
14
|
+
events: {};
|
|
15
|
+
};
|
|
16
|
+
declare class __sveltets_Render<TData> {
|
|
17
|
+
props(): ReturnType<typeof $$render<TData>>['props'];
|
|
18
|
+
events(): ReturnType<typeof $$render<TData>>['events'];
|
|
19
|
+
slots(): ReturnType<typeof $$render<TData>>['slots'];
|
|
20
|
+
bindings(): "";
|
|
21
|
+
exports(): {};
|
|
22
|
+
}
|
|
23
|
+
interface $$IsomorphicComponent {
|
|
24
|
+
new <TData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData>['props']>, ReturnType<__sveltets_Render<TData>['events']>, ReturnType<__sveltets_Render<TData>['slots']>> & {
|
|
25
|
+
$$bindings?: ReturnType<__sveltets_Render<TData>['bindings']>;
|
|
26
|
+
} & ReturnType<__sveltets_Render<TData>['exports']>;
|
|
27
|
+
<TData>(internal: unknown, props: ReturnType<__sveltets_Render<TData>['props']> & {}): ReturnType<__sveltets_Render<TData>['exports']>;
|
|
28
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
29
|
+
}
|
|
30
|
+
declare const DataTableToolbar: $$IsomorphicComponent;
|
|
31
|
+
type DataTableToolbar<TData> = InstanceType<typeof DataTableToolbar<TData>>;
|
|
32
|
+
export default DataTableToolbar;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { Component, Snippet } from 'svelte';
|
|
2
|
+
import type { StatusType, AnyProp, TableAction, EmptyStateProps, TableSortBy } from '../types.js';
|
|
3
|
+
import type { IconSource } from '@steeze-ui/svelte-icon';
|
|
4
|
+
import type { Table, Row, Header, Cell } from '@tanstack/table-core';
|
|
5
|
+
import type { RenderComponentConfig, RenderSnippetConfig } from './render-helpers.js';
|
|
6
|
+
import type BaseDropdown from '../BaseDropdown.svelte';
|
|
7
|
+
export type CellType = 'text' | 'boolean' | 'tag' | 'date' | 'currency' | 'uuid' | 'custom';
|
|
8
|
+
export type StickyCellWrapperSnippet = Snippet<[
|
|
9
|
+
{
|
|
10
|
+
children: any;
|
|
11
|
+
align?: 'left' | 'right';
|
|
12
|
+
isFirst?: boolean;
|
|
13
|
+
isLast?: boolean;
|
|
14
|
+
isFrozen?: boolean;
|
|
15
|
+
isLastFrozen?: boolean;
|
|
16
|
+
}
|
|
17
|
+
]>;
|
|
18
|
+
export interface BooleanCellConfig {
|
|
19
|
+
icon?: IconSource;
|
|
20
|
+
iconClass?: string;
|
|
21
|
+
showWhenTrue?: boolean;
|
|
22
|
+
showWhenFalse?: boolean;
|
|
23
|
+
hintWhenTrue?: string;
|
|
24
|
+
hintWhenFalse?: string;
|
|
25
|
+
}
|
|
26
|
+
export type CellConfig = TextCellConfig | BooleanCellConfig | TagCellConfig | DateCellConfig | CurrencyCellConfig | UuidCellConfig;
|
|
27
|
+
export interface CurrencyCellConfig {
|
|
28
|
+
className?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface DataTableColumn<TData> {
|
|
31
|
+
id: string;
|
|
32
|
+
accessorKey?: keyof TData;
|
|
33
|
+
header?: string;
|
|
34
|
+
cellType?: CellType;
|
|
35
|
+
cellConfig?: CellConfig;
|
|
36
|
+
cell?: Snippet<[TData]> | ((value: any, row: TData) => Snippet | Component | string | RenderComponentConfig<any> | RenderSnippetConfig<any>);
|
|
37
|
+
enableSorting?: boolean;
|
|
38
|
+
enableHiding?: boolean;
|
|
39
|
+
enableResizing?: boolean;
|
|
40
|
+
disableColumnFilter?: boolean;
|
|
41
|
+
size?: number;
|
|
42
|
+
minSize?: number;
|
|
43
|
+
maxSize?: number;
|
|
44
|
+
meta?: DataTableColumnMeta;
|
|
45
|
+
loadingConfig?: LoadingConfig;
|
|
46
|
+
}
|
|
47
|
+
export interface DataTableColumnMeta {
|
|
48
|
+
cellType?: CellType;
|
|
49
|
+
dbField?: string;
|
|
50
|
+
disableColumnFilter?: boolean;
|
|
51
|
+
filterIcon?: IconSource;
|
|
52
|
+
filterLabel?: string;
|
|
53
|
+
filterOptions?: Array<{
|
|
54
|
+
value: string;
|
|
55
|
+
label: string;
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}>;
|
|
58
|
+
filterType?: 'select' | 'text' | 'numeric' | 'date' | 'uuid';
|
|
59
|
+
loadingConfig?: LoadingConfig;
|
|
60
|
+
}
|
|
61
|
+
export interface DataTableCellProps<TData> {
|
|
62
|
+
cell: Cell<TData, unknown>;
|
|
63
|
+
index: number;
|
|
64
|
+
visibleCells: Cell<TData, unknown>[];
|
|
65
|
+
allCells: Cell<TData, unknown>[];
|
|
66
|
+
frozenColumns: Set<string>;
|
|
67
|
+
loading?: boolean;
|
|
68
|
+
StickyCellWrapper: StickyCellWrapperSnippet;
|
|
69
|
+
}
|
|
70
|
+
export interface DataTableHeaderCellProps<TData> {
|
|
71
|
+
header: Header<TData, unknown>;
|
|
72
|
+
index: number;
|
|
73
|
+
headers: Header<TData, unknown>[];
|
|
74
|
+
frozenColumns: Set<string>;
|
|
75
|
+
columnDropdowns?: Record<string, BaseDropdown>;
|
|
76
|
+
onSortingChange?: (columnId: string, direction: TableSortBy) => void;
|
|
77
|
+
onFilterChange?: (columnId: string) => void;
|
|
78
|
+
onFreezeChange?: (columnId: string) => void;
|
|
79
|
+
manualPagination?: boolean;
|
|
80
|
+
loading?: boolean;
|
|
81
|
+
}
|
|
82
|
+
export interface DataTablePaginationProps<T> {
|
|
83
|
+
table: Table<T>;
|
|
84
|
+
id?: string;
|
|
85
|
+
class?: string;
|
|
86
|
+
showRowsPerPage?: boolean;
|
|
87
|
+
rowsPerPageOptions?: number[];
|
|
88
|
+
itemsLabel?: string;
|
|
89
|
+
children?: Snippet;
|
|
90
|
+
onPageChange?: (pageIndex: number) => void;
|
|
91
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
92
|
+
data?: T[];
|
|
93
|
+
rowCount?: number;
|
|
94
|
+
manualPagination?: boolean;
|
|
95
|
+
disabled?: boolean;
|
|
96
|
+
disableJumpToPage?: boolean;
|
|
97
|
+
}
|
|
98
|
+
export interface DataTableRowProps<TData> {
|
|
99
|
+
row: Row<TData>;
|
|
100
|
+
rowIndex: number;
|
|
101
|
+
frozenColumns: Set<string>;
|
|
102
|
+
focusedRowIndex: number;
|
|
103
|
+
loading?: boolean;
|
|
104
|
+
onRowClick?: (row: TData) => void;
|
|
105
|
+
getRowClassName?: (row: TData) => string;
|
|
106
|
+
getRowState?: (row: TData) => {
|
|
107
|
+
isSuccess?: boolean;
|
|
108
|
+
isError?: boolean;
|
|
109
|
+
isWarning?: boolean;
|
|
110
|
+
};
|
|
111
|
+
StickyCellWrapper: StickyCellWrapperSnippet;
|
|
112
|
+
}
|
|
113
|
+
export interface DataTableProps<TData> {
|
|
114
|
+
data: TData[];
|
|
115
|
+
columns: DataTableColumn<TData>[];
|
|
116
|
+
loading?: boolean;
|
|
117
|
+
disableSelection?: boolean;
|
|
118
|
+
disablePagination?: boolean;
|
|
119
|
+
disableKeyboardNavigation?: boolean;
|
|
120
|
+
disableControls?: boolean;
|
|
121
|
+
disableJumpToPage?: boolean;
|
|
122
|
+
rowActions?: TableAction[];
|
|
123
|
+
getRowActions?: (row: TData) => TableAction[];
|
|
124
|
+
onRowAction?: (action: AnyProp, row: TData) => void;
|
|
125
|
+
initialPageSize?: number;
|
|
126
|
+
initialPage?: number;
|
|
127
|
+
initialSortColumn?: string;
|
|
128
|
+
initialSortDirection?: TableSortBy;
|
|
129
|
+
initialFrozenColumns?: string[];
|
|
130
|
+
initialColumnOrder?: string[];
|
|
131
|
+
initialColumnVisibility?: Record<string, boolean>;
|
|
132
|
+
initialColumnSizing?: Record<string, number>;
|
|
133
|
+
pageSizeOptions?: number[];
|
|
134
|
+
emptyState?: Omit<EmptyStateProps, 'children' | 'check'>;
|
|
135
|
+
onRowClick?: (row: TData) => void;
|
|
136
|
+
onSelectionChange?: (selectedRows: TData[]) => void;
|
|
137
|
+
filters?: Snippet;
|
|
138
|
+
paginationSlot?: Snippet;
|
|
139
|
+
children?: Snippet;
|
|
140
|
+
manualPagination?: boolean;
|
|
141
|
+
manualSorting?: boolean;
|
|
142
|
+
pageCount?: number;
|
|
143
|
+
rowCount?: number;
|
|
144
|
+
onPageChange?: (pageIndex: number) => void;
|
|
145
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
146
|
+
onSortingChange?: (columnId: string, direction: TableSortBy) => void;
|
|
147
|
+
onFilterChange?: (columnId: string) => void;
|
|
148
|
+
onFreezeChange?: (columnId: string) => void;
|
|
149
|
+
onColumnResize?: (columnSizes: Record<string, number>) => void;
|
|
150
|
+
onColumnOrderChange?: (columnOrder: string[]) => void;
|
|
151
|
+
onColumnVisibilityChange?: (visibility: Record<string, boolean>) => void;
|
|
152
|
+
getRowClassName?: (row: TData) => string;
|
|
153
|
+
getRowState?: (row: TData) => {
|
|
154
|
+
isSuccess?: boolean;
|
|
155
|
+
isError?: boolean;
|
|
156
|
+
isWarning?: boolean;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export interface DateCellConfig {
|
|
160
|
+
className?: string;
|
|
161
|
+
}
|
|
162
|
+
export interface CellSkeletonProps {
|
|
163
|
+
isBoolean?: boolean;
|
|
164
|
+
loadingConfig?: LoadingConfig;
|
|
165
|
+
withPadding?: boolean;
|
|
166
|
+
}
|
|
167
|
+
export interface LoadingConfig {
|
|
168
|
+
lines?: number;
|
|
169
|
+
showAvatar?: boolean;
|
|
170
|
+
avatarSize?: number;
|
|
171
|
+
}
|
|
172
|
+
declare module '@tanstack/table-core' {
|
|
173
|
+
interface ColumnMeta<TData, TValue> {
|
|
174
|
+
cellType?: CellType;
|
|
175
|
+
disableColumnFilter?: boolean;
|
|
176
|
+
loadingConfig?: LoadingConfig;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
export interface TagCellConfig {
|
|
180
|
+
options: Array<{
|
|
181
|
+
value: string;
|
|
182
|
+
label: string;
|
|
183
|
+
color: StatusType;
|
|
184
|
+
}>;
|
|
185
|
+
showDot?: boolean;
|
|
186
|
+
}
|
|
187
|
+
export interface TextCellConfig {
|
|
188
|
+
className?: string;
|
|
189
|
+
}
|
|
190
|
+
export interface UuidCellConfig {
|
|
191
|
+
prefixLength?: number;
|
|
192
|
+
suffixLength?: number;
|
|
193
|
+
full?: boolean;
|
|
194
|
+
disabled?: boolean;
|
|
195
|
+
onCopy?: (value: string) => void;
|
|
196
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<script lang="ts" generics="TData">
|
|
2
|
+
import { Sliders, Drag } from '@invopop/ui-icons'
|
|
3
|
+
import type { Table } from '@tanstack/table-core'
|
|
4
|
+
import type { DrawerOption, DrawerGroup } from '../types.js'
|
|
5
|
+
import BaseDropdown from '../BaseDropdown.svelte'
|
|
6
|
+
import DrawerContext from '../DrawerContext.svelte'
|
|
7
|
+
import InputToggle from '../InputToggle.svelte'
|
|
8
|
+
import BaseButton from '../BaseButton.svelte'
|
|
9
|
+
import { capitalize } from '../helpers.js'
|
|
10
|
+
|
|
11
|
+
let {
|
|
12
|
+
table,
|
|
13
|
+
frozenColumns,
|
|
14
|
+
onFreezeColumn
|
|
15
|
+
}: {
|
|
16
|
+
table: Table<TData>
|
|
17
|
+
frozenColumns: Set<string>
|
|
18
|
+
onFreezeColumn: (columnId: string) => void
|
|
19
|
+
} = $props()
|
|
20
|
+
|
|
21
|
+
const groups: DrawerGroup[] = [
|
|
22
|
+
{
|
|
23
|
+
label: 'Frozen columns',
|
|
24
|
+
slug: 'frozen',
|
|
25
|
+
emptyDescription: 'Drop items to this list',
|
|
26
|
+
hideCounter: true
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: 'Table options',
|
|
30
|
+
slug: 'regular',
|
|
31
|
+
emptyDescription: 'Drop items to this list',
|
|
32
|
+
hideCounter: true
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
let itemsWithActions = $derived.by(() => {
|
|
37
|
+
const columnOrder = table.getState().columnOrder
|
|
38
|
+
const allColumns = table.getAllColumns()
|
|
39
|
+
|
|
40
|
+
let orderedColumns
|
|
41
|
+
// If there's a custom order, use it; otherwise use default order
|
|
42
|
+
if (columnOrder.length > 0) {
|
|
43
|
+
orderedColumns = columnOrder
|
|
44
|
+
.map((id) => allColumns.find((col) => col.id === id))
|
|
45
|
+
.filter((col) => col && col.id !== 'select' && col.id !== 'actions')
|
|
46
|
+
} else {
|
|
47
|
+
orderedColumns = allColumns.filter((col) => col.id !== 'select' && col.id !== 'actions')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return orderedColumns.map((col) => {
|
|
51
|
+
const isFrozen = frozenColumns.has(col?.id || '')
|
|
52
|
+
return {
|
|
53
|
+
label: (col?.columnDef.header as string) || capitalize(col?.id || ''),
|
|
54
|
+
value: col?.id,
|
|
55
|
+
icon: Drag,
|
|
56
|
+
action: toggleAction,
|
|
57
|
+
groupBy: isFrozen ? 'frozen' : 'regular'
|
|
58
|
+
}
|
|
59
|
+
}) as DrawerOption[]
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
function handleDropItem(groupsDistribution: Record<string, DrawerOption[]>) {
|
|
63
|
+
const frozenItems = groupsDistribution['frozen'] || []
|
|
64
|
+
const regularItems = groupsDistribution['regular'] || []
|
|
65
|
+
|
|
66
|
+
// Build sets of what should be frozen and regular after the drop
|
|
67
|
+
const shouldBeFrozen = new Set(frozenItems.map((item) => item.value as string))
|
|
68
|
+
const shouldBeRegular = new Set(regularItems.map((item) => item.value as string))
|
|
69
|
+
|
|
70
|
+
// Freeze columns that are in the frozen group but not currently frozen
|
|
71
|
+
shouldBeFrozen.forEach((columnId) => {
|
|
72
|
+
if (!frozenColumns.has(columnId)) {
|
|
73
|
+
onFreezeColumn(columnId)
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
// Unfreeze columns that are in the regular group but currently frozen
|
|
78
|
+
shouldBeRegular.forEach((columnId) => {
|
|
79
|
+
if (frozenColumns.has(columnId)) {
|
|
80
|
+
onFreezeColumn(columnId)
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// Get all column IDs from the table
|
|
85
|
+
const allColumnIds = table.getAllColumns().map((col) => col.id)
|
|
86
|
+
const selectColumn = 'select'
|
|
87
|
+
const actionsColumn = 'actions'
|
|
88
|
+
|
|
89
|
+
// Build the final column order: select, frozen (in order), regular (in order), actions
|
|
90
|
+
const frozenOrder = frozenItems.map((item) => item.value as string)
|
|
91
|
+
const regularOrder = regularItems.map((item) => item.value as string)
|
|
92
|
+
|
|
93
|
+
const finalOrder = [
|
|
94
|
+
...(allColumnIds.includes(selectColumn) ? [selectColumn] : []),
|
|
95
|
+
...frozenOrder,
|
|
96
|
+
...regularOrder,
|
|
97
|
+
...(allColumnIds.includes(actionsColumn) ? [actionsColumn] : [])
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
table.setColumnOrder(finalOrder)
|
|
101
|
+
}
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
{#snippet toggleAction(item: DrawerOption)}
|
|
105
|
+
{@const column = table.getColumn(String(item.value))}
|
|
106
|
+
{#if column?.getCanHide()}
|
|
107
|
+
<InputToggle
|
|
108
|
+
class="cursor-default"
|
|
109
|
+
checked={column?.getIsVisible() ?? false}
|
|
110
|
+
onchange={(v) => column?.toggleVisibility(!!v)}
|
|
111
|
+
/>
|
|
112
|
+
{/if}
|
|
113
|
+
{/snippet}
|
|
114
|
+
|
|
115
|
+
<BaseDropdown class="ms-auto hidden lg:flex">
|
|
116
|
+
{#snippet trigger()}
|
|
117
|
+
<BaseButton icon={Sliders} variant="outline" size="md" />
|
|
118
|
+
{/snippet}
|
|
119
|
+
<DrawerContext
|
|
120
|
+
items={itemsWithActions}
|
|
121
|
+
{groups}
|
|
122
|
+
draggable
|
|
123
|
+
collapsibleGroups={false}
|
|
124
|
+
ondropitem={handleDropItem}
|
|
125
|
+
/>
|
|
126
|
+
</BaseDropdown>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Table } from '@tanstack/table-core';
|
|
2
|
+
declare function $$render<TData>(): {
|
|
3
|
+
props: {
|
|
4
|
+
table: Table<TData>;
|
|
5
|
+
frozenColumns: Set<string>;
|
|
6
|
+
onFreezeColumn: (columnId: string) => void;
|
|
7
|
+
};
|
|
8
|
+
exports: {};
|
|
9
|
+
bindings: "";
|
|
10
|
+
slots: {};
|
|
11
|
+
events: {};
|
|
12
|
+
};
|
|
13
|
+
declare class __sveltets_Render<TData> {
|
|
14
|
+
props(): ReturnType<typeof $$render<TData>>['props'];
|
|
15
|
+
events(): ReturnType<typeof $$render<TData>>['events'];
|
|
16
|
+
slots(): ReturnType<typeof $$render<TData>>['slots'];
|
|
17
|
+
bindings(): "";
|
|
18
|
+
exports(): {};
|
|
19
|
+
}
|
|
20
|
+
interface $$IsomorphicComponent {
|
|
21
|
+
new <TData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData>['props']>, ReturnType<__sveltets_Render<TData>['events']>, ReturnType<__sveltets_Render<TData>['slots']>> & {
|
|
22
|
+
$$bindings?: ReturnType<__sveltets_Render<TData>['bindings']>;
|
|
23
|
+
} & ReturnType<__sveltets_Render<TData>['exports']>;
|
|
24
|
+
<TData>(internal: unknown, props: ReturnType<__sveltets_Render<TData>['props']> & {}): ReturnType<__sveltets_Render<TData>['exports']>;
|
|
25
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
26
|
+
}
|
|
27
|
+
declare const DataTableViewOptions: $$IsomorphicComponent;
|
|
28
|
+
type DataTableViewOptions<TData> = InstanceType<typeof DataTableViewOptions<TData>>;
|
|
29
|
+
export default DataTableViewOptions;
|