compote-ui 0.31.1 → 0.33.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/checkbox/checkbox.svelte +34 -9
- package/dist/components/checkbox/checkbox.types.d.ts +5 -2
- package/dist/components/data-table/core/cells.d.ts +78 -0
- package/dist/components/data-table/core/cells.js +66 -0
- package/dist/components/data-table/core/create-table.svelte.d.ts +24 -0
- package/dist/components/data-table/core/create-table.svelte.js +74 -0
- package/dist/components/data-table/core/index.d.ts +3 -0
- package/dist/components/data-table/core/index.js +2 -0
- package/dist/components/data-table/data-table-column-visibility.svelte +79 -0
- package/dist/components/data-table/data-table-column-visibility.svelte.d.ts +29 -0
- package/dist/components/data-table/data-table-filters.svelte +285 -0
- package/dist/components/data-table/data-table-filters.svelte.d.ts +29 -0
- package/dist/components/data-table/data-table-title.svelte +16 -0
- package/dist/components/data-table/data-table-title.svelte.d.ts +10 -0
- package/dist/components/data-table/data-table-toolbar.svelte +16 -0
- package/dist/components/data-table/data-table-toolbar.svelte.d.ts +10 -0
- package/dist/components/data-table/data-table.svelte +342 -0
- package/dist/components/data-table/data-table.svelte.d.ts +32 -0
- package/dist/components/data-table/index.d.ts +7 -0
- package/dist/components/data-table/index.js +7 -0
- package/dist/components/field/field-input.svelte +8 -6
- package/dist/components/number-input/number-input.svelte +3 -0
- package/dist/components/popover/index.d.ts +6 -0
- package/dist/components/popover/index.js +6 -0
- package/dist/components/popover/popover-close-trigger.svelte +25 -0
- package/dist/components/popover/popover-close-trigger.svelte.d.ts +8 -0
- package/dist/components/popover/popover-content.svelte +71 -0
- package/dist/components/popover/popover-content.svelte.d.ts +10 -0
- package/dist/components/popover/popover-description.svelte +15 -0
- package/dist/components/popover/popover-description.svelte.d.ts +8 -0
- package/dist/components/popover/popover-root.svelte +24 -0
- package/dist/components/popover/popover-root.svelte.d.ts +11 -0
- package/dist/components/popover/popover-title.svelte +15 -0
- package/dist/components/popover/popover-title.svelte.d.ts +8 -0
- package/dist/components/popover/popover-trigger.svelte +17 -0
- package/dist/components/popover/popover-trigger.svelte.d.ts +10 -0
- package/dist/components/scroll-area/scroll-area-content.svelte +1 -1
- package/dist/components/toggle/toggle.svelte +17 -0
- package/dist/components/toggle/toggle.svelte.d.ts +4 -0
- package/dist/components/toggle/toggle.variants.d.ts +21 -0
- package/dist/components/toggle/toggle.variants.js +12 -0
- package/dist/components/toggle/types.d.ts +8 -0
- package/dist/components/toggle/types.js +1 -0
- package/dist/components/toggle-group/toggle-group-context.d.ts +8 -0
- package/dist/components/toggle-group/toggle-group-context.js +2 -0
- package/dist/components/toggle-group/toggle-group-item.svelte +7 -6
- package/dist/components/toggle-group/toggle-group-item.svelte.d.ts +2 -0
- package/dist/components/toggle-group/toggle-group.svelte +17 -2
- package/dist/components/toggle-group/toggle-group.svelte.d.ts +2 -0
- package/dist/components/tooltip/tooltip-trigger.svelte +2 -4
- package/dist/components/tooltip/tooltip-trigger.svelte.d.ts +2 -4
- package/dist/components/tree-view/tree-view.svelte +1 -1
- package/dist/icons/PhArrowSquareOut.svelte +18 -0
- package/dist/icons/PhArrowSquareOut.svelte.d.ts +5 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/theme.css +1 -1
- package/package.json +12 -1
|
@@ -1,26 +1,51 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { Checkbox } from '@ark-ui/svelte/checkbox';
|
|
3
|
+
import { cn } from 'tailwind-variants';
|
|
3
4
|
import type { CheckboxProps as Props } from './checkbox.types.js';
|
|
4
5
|
import { PhCheck, PhMinus } from '../../icons';
|
|
5
6
|
|
|
6
|
-
let {
|
|
7
|
+
let {
|
|
8
|
+
checked = $bindable(),
|
|
9
|
+
label,
|
|
10
|
+
children,
|
|
11
|
+
size = 'md',
|
|
12
|
+
class: className,
|
|
13
|
+
...rest
|
|
14
|
+
}: Props = $props();
|
|
15
|
+
|
|
16
|
+
const checkboxSize = {
|
|
17
|
+
sm: {
|
|
18
|
+
control: 'size-4',
|
|
19
|
+
icon: 'size-3'
|
|
20
|
+
},
|
|
21
|
+
md: {
|
|
22
|
+
control: 'size-5',
|
|
23
|
+
icon: 'size-3.5'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
7
26
|
</script>
|
|
8
27
|
|
|
9
28
|
<Checkbox.Root
|
|
10
29
|
bind:checked
|
|
11
|
-
class=
|
|
30
|
+
class={cn(
|
|
31
|
+
'inline-flex cursor-pointer gap-2 leading-none',
|
|
32
|
+
children ? 'items-start' : 'items-center',
|
|
33
|
+
className
|
|
34
|
+
)}
|
|
12
35
|
{...rest}
|
|
13
36
|
>
|
|
14
37
|
<Checkbox.Control
|
|
15
|
-
class=
|
|
16
|
-
? 'mt-0.5'
|
|
17
|
-
|
|
38
|
+
class={cn(
|
|
39
|
+
children ? 'mt-0.5' : '',
|
|
40
|
+
checkboxSize[size].control,
|
|
41
|
+
'relative grid shrink-0 place-items-center rounded-sm border bg-transparent transition-colors hover:border-primary/50 data-disabled:pointer-events-none data-disabled:opacity-50 data-focus-visible:outline-2 data-focus-visible:outline-offset-2 data-focus-visible:outline-ring data-invalid:border-danger data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary'
|
|
42
|
+
)}
|
|
18
43
|
>
|
|
19
|
-
<Checkbox.Indicator>
|
|
20
|
-
<PhCheck class=
|
|
44
|
+
<Checkbox.Indicator class="absolute inset-0 grid place-items-center leading-none">
|
|
45
|
+
<PhCheck class={cn(checkboxSize[size].icon, 'block text-ink-inverse')} />
|
|
21
46
|
</Checkbox.Indicator>
|
|
22
|
-
<Checkbox.Indicator indeterminate>
|
|
23
|
-
<PhMinus class=
|
|
47
|
+
<Checkbox.Indicator indeterminate class="absolute inset-0 grid place-items-center leading-none">
|
|
48
|
+
<PhMinus class={cn(checkboxSize[size].icon, 'block text-ink-inverse')} />
|
|
24
49
|
</Checkbox.Indicator>
|
|
25
50
|
</Checkbox.Control>
|
|
26
51
|
{#if label}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CheckboxRootProps } from '@ark-ui/svelte/checkbox';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
|
|
3
|
+
import type { ClassValue } from 'tailwind-variants';
|
|
4
|
+
export interface CheckboxProps extends Omit<CheckboxRootProps, 'children' | 'asChild' | 'class' | 'ref'> {
|
|
5
|
+
class?: ClassValue;
|
|
4
6
|
label?: string;
|
|
7
|
+
size?: 'sm' | 'md';
|
|
5
8
|
children?: Snippet;
|
|
6
9
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { AccessorFnColumnDef, AccessorKeyColumnDef, Cell, CellData, ColumnDef, DisplayColumnDef, GroupColumnDef, RowData } from '@tanstack/svelte-table';
|
|
2
|
+
import type { DataTableFeatures } from './create-table.svelte';
|
|
3
|
+
type NumericFormat = {
|
|
4
|
+
locale?: string;
|
|
5
|
+
minimumFractionDigits?: number;
|
|
6
|
+
maximumFractionDigits?: number;
|
|
7
|
+
fractionDigits?: number;
|
|
8
|
+
};
|
|
9
|
+
export type DataTableCellConfig<TData extends RowData = RowData, TValue = unknown> = ({
|
|
10
|
+
type: 'text';
|
|
11
|
+
} & {
|
|
12
|
+
fallback?: string;
|
|
13
|
+
}) | ({
|
|
14
|
+
type: 'number';
|
|
15
|
+
} & NumericFormat) | ({
|
|
16
|
+
type: 'currency';
|
|
17
|
+
currency: string;
|
|
18
|
+
currencyDisplay?: Intl.NumberFormatOptions['currencyDisplay'];
|
|
19
|
+
} & NumericFormat) | ({
|
|
20
|
+
type: 'percentage';
|
|
21
|
+
} & NumericFormat) | {
|
|
22
|
+
type: 'boolean';
|
|
23
|
+
trueLabel?: string;
|
|
24
|
+
falseLabel?: string;
|
|
25
|
+
nullLabel?: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'link';
|
|
28
|
+
href?: string | ((value: TValue, row: TData) => string);
|
|
29
|
+
target?: HTMLAnchorElement['target'];
|
|
30
|
+
fallback?: string;
|
|
31
|
+
};
|
|
32
|
+
export type DataTableCellType<TData extends RowData = RowData, TValue = unknown> = DataTableCellConfig<TData, TValue> | Exclude<DataTableCellConfig<TData, TValue>['type'], 'currency' | 'link'>;
|
|
33
|
+
export type DataTableColumnMeta<TData extends RowData = RowData, TValue = unknown> = {
|
|
34
|
+
dataTable?: {
|
|
35
|
+
align?: DataTableColumnAlign;
|
|
36
|
+
cell?: DataTableCellConfig<TData, TValue>;
|
|
37
|
+
filter?: DataTableFilterConfig<TValue>;
|
|
38
|
+
hasCustomCell?: boolean;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export type DataTableColumnAlign = 'left' | 'center' | 'right';
|
|
42
|
+
export type DataTableFilterOption<TValue = unknown> = {
|
|
43
|
+
label: string;
|
|
44
|
+
value: TValue;
|
|
45
|
+
};
|
|
46
|
+
export type DataTableFilterConfig<TValue = unknown> = {
|
|
47
|
+
type: 'text';
|
|
48
|
+
placeholder?: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'facet';
|
|
51
|
+
options?: DataTableFilterOption<TValue>[];
|
|
52
|
+
maxOptions?: number;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'number-range';
|
|
55
|
+
min?: number;
|
|
56
|
+
max?: number;
|
|
57
|
+
step?: number;
|
|
58
|
+
formatOptions?: Intl.NumberFormatOptions;
|
|
59
|
+
} | {
|
|
60
|
+
type: 'boolean';
|
|
61
|
+
trueLabel?: string;
|
|
62
|
+
falseLabel?: string;
|
|
63
|
+
};
|
|
64
|
+
export type DataTableFilterType<TValue = unknown> = DataTableFilterConfig<TValue> | DataTableFilterConfig<TValue>['type'];
|
|
65
|
+
type DataTableColumnDefOptions<TData extends RowData, TValue> = {
|
|
66
|
+
align?: DataTableColumnAlign;
|
|
67
|
+
cellType?: DataTableCellType<TData, TValue>;
|
|
68
|
+
filter?: DataTableFilterType<TValue>;
|
|
69
|
+
};
|
|
70
|
+
export type DataTableColumnDef<TData extends RowData, TValue extends CellData = CellData> = (AccessorKeyColumnDef<DataTableFeatures, TData, TValue> & DataTableColumnDefOptions<TData, TValue>) | (AccessorFnColumnDef<DataTableFeatures, TData, TValue> & DataTableColumnDefOptions<TData, TValue>) | (DisplayColumnDef<DataTableFeatures, TData, TValue> & DataTableColumnDefOptions<TData, TValue>) | (Omit<GroupColumnDef<DataTableFeatures, TData, TValue>, 'columns'> & DataTableColumnDefOptions<TData, TValue> & {
|
|
71
|
+
columns?: DataTableColumnDef<TData, CellData>[];
|
|
72
|
+
});
|
|
73
|
+
export type DataTableCell<TData extends RowData = RowData, TValue = unknown> = Cell<DataTableFeatures, TData, TValue>;
|
|
74
|
+
export declare function getDataTableCellConfig<TData extends RowData, TValue>(cell: DataTableCell<TData, TValue>): DataTableCellConfig<TData, TValue> | undefined;
|
|
75
|
+
export declare function getDataTableFilterConfig<TData extends RowData, TValue>(columnDef: ColumnDef<DataTableFeatures, TData, TValue>): DataTableFilterConfig<TValue> | undefined;
|
|
76
|
+
export declare function hasCustomDataTableCell<TData extends RowData, TValue>(cell: DataTableCell<TData, TValue>): boolean;
|
|
77
|
+
export declare function normalizeDataTableColumns<TData extends RowData>(columns: DataTableColumnDef<TData>[]): ColumnDef<DataTableFeatures, TData, CellData>[];
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function getDataTableCellConfig(cell) {
|
|
2
|
+
return cell.column.columnDef.meta?.dataTable
|
|
3
|
+
?.cell;
|
|
4
|
+
}
|
|
5
|
+
export function getDataTableFilterConfig(columnDef) {
|
|
6
|
+
return columnDef.meta?.dataTable?.filter;
|
|
7
|
+
}
|
|
8
|
+
export function hasCustomDataTableCell(cell) {
|
|
9
|
+
return (cell.column.columnDef.meta?.dataTable
|
|
10
|
+
?.hasCustomCell ?? false);
|
|
11
|
+
}
|
|
12
|
+
export function normalizeDataTableColumns(columns) {
|
|
13
|
+
return columns.map((columnDef) => {
|
|
14
|
+
const { cellType, filter, align, columns: childColumns, meta, ...column } = columnDef;
|
|
15
|
+
const cell = normalizeDataTableCellType(cellType);
|
|
16
|
+
const filterConfig = normalizeDataTableFilterType(filter);
|
|
17
|
+
const hasCustomCell = 'cell' in column;
|
|
18
|
+
const filterFn = 'filterFn' in column ? column.filterFn : getDefaultDataTableFilterFn(filterConfig);
|
|
19
|
+
const nextMeta = cell || align || filterConfig
|
|
20
|
+
? {
|
|
21
|
+
...(meta ?? {}),
|
|
22
|
+
dataTable: {
|
|
23
|
+
...(meta?.dataTable ?? {}),
|
|
24
|
+
...(align ? { align } : {}),
|
|
25
|
+
...(cell ? { cell } : {}),
|
|
26
|
+
...(filterConfig ? { filter: filterConfig } : {}),
|
|
27
|
+
hasCustomCell
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
: meta;
|
|
31
|
+
return {
|
|
32
|
+
...column,
|
|
33
|
+
...(childColumns ? { columns: normalizeDataTableColumns(childColumns) } : {}),
|
|
34
|
+
...(filterFn ? { filterFn } : {}),
|
|
35
|
+
...(nextMeta ? { meta: nextMeta } : {})
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function normalizeDataTableCellType(cellType) {
|
|
40
|
+
if (!cellType)
|
|
41
|
+
return undefined;
|
|
42
|
+
return typeof cellType === 'string' ? { type: cellType } : cellType;
|
|
43
|
+
}
|
|
44
|
+
function normalizeDataTableFilterType(filter) {
|
|
45
|
+
if (!filter)
|
|
46
|
+
return undefined;
|
|
47
|
+
return typeof filter === 'string' ? { type: filter } : filter;
|
|
48
|
+
}
|
|
49
|
+
function getDefaultDataTableFilterFn(filter) {
|
|
50
|
+
if (!filter)
|
|
51
|
+
return undefined;
|
|
52
|
+
if (filter.type === 'facet')
|
|
53
|
+
return dataTableFacetFilter;
|
|
54
|
+
if (filter.type === 'number-range')
|
|
55
|
+
return 'inNumberRange';
|
|
56
|
+
if (filter.type === 'boolean')
|
|
57
|
+
return 'equals';
|
|
58
|
+
return 'includesString';
|
|
59
|
+
}
|
|
60
|
+
const dataTableFacetFilter = (row, columnId, filterValue) => {
|
|
61
|
+
if (!Array.isArray(filterValue) || filterValue.length === 0)
|
|
62
|
+
return true;
|
|
63
|
+
const value = row.getValue(columnId);
|
|
64
|
+
return filterValue.some((filterItem) => Object.is(filterItem, value));
|
|
65
|
+
};
|
|
66
|
+
dataTableFacetFilter.autoRemove = (filterValue) => !Array.isArray(filterValue) || filterValue.length === 0;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RowData, SvelteTable, TableOptions, TableState, Updater } from '@tanstack/svelte-table';
|
|
2
|
+
import { type DataTableColumnDef } from './cells';
|
|
3
|
+
declare const dataTableFeatures: {
|
|
4
|
+
columnFilteringFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnFilteringFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
5
|
+
columnFacetingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnFacetingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
6
|
+
columnVisibilityFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnVisibilityFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
7
|
+
columnSizingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnSizingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
8
|
+
columnResizingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnResizingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
9
|
+
rowSelectionFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").RowSelectionFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
10
|
+
rowSortingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").RowSortingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
11
|
+
};
|
|
12
|
+
export type DataTableFeatures = typeof dataTableFeatures;
|
|
13
|
+
type DataTableData<TData extends RowData> = ReadonlyArray<TData> | (() => ReadonlyArray<TData>);
|
|
14
|
+
export type DataTableSelectedState = Pick<TableState<DataTableFeatures>, 'columnFilters' | 'columnResizing' | 'columnVisibility' | 'rowSelection' | 'sorting'>;
|
|
15
|
+
export type DataTableOptions<TData extends RowData> = Omit<TableOptions<DataTableFeatures, TData>, '_features' | 'data' | 'columns'> & {
|
|
16
|
+
data: DataTableData<TData>;
|
|
17
|
+
columns: DataTableColumnDef<TData>[];
|
|
18
|
+
} & Partial<Pick<TableOptions<DataTableFeatures, TData>, '_features'>>;
|
|
19
|
+
export type DataTable<TData extends RowData, TSelected = DataTableSelectedState> = SvelteTable<DataTableFeatures, TData, TSelected> & {
|
|
20
|
+
setData: (data: ReadonlyArray<TData>) => void;
|
|
21
|
+
updateData: (updater: Updater<ReadonlyArray<TData>>) => void;
|
|
22
|
+
};
|
|
23
|
+
export declare function createDataTable<TData extends RowData, TSelected = DataTableSelectedState>(options: DataTableOptions<TData>, selector?: (state: TableState<DataTableFeatures>) => TSelected): DataTable<TData, TSelected>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { columnFacetingFeature, columnFilteringFeature, columnVisibilityFeature, columnResizingFeature, columnSizingFeature, createFacetedMinMaxValues, createFacetedRowModel, createFacetedUniqueValues, createCoreRowModel, createFilteredRowModel, createSortedRowModel, createTable as createTanStackTable, filterFns, functionalUpdate, rowSortingFeature, rowSelectionFeature, sortFns, tableFeatures } from '@tanstack/svelte-table';
|
|
2
|
+
import { normalizeDataTableColumns } from './cells';
|
|
3
|
+
const dataTableFeatures = tableFeatures({
|
|
4
|
+
columnFilteringFeature,
|
|
5
|
+
columnFacetingFeature,
|
|
6
|
+
columnVisibilityFeature,
|
|
7
|
+
columnSizingFeature,
|
|
8
|
+
columnResizingFeature,
|
|
9
|
+
rowSelectionFeature,
|
|
10
|
+
rowSortingFeature
|
|
11
|
+
});
|
|
12
|
+
const dataTableStateSelector = (state) => ({
|
|
13
|
+
columnFilters: state.columnFilters,
|
|
14
|
+
columnResizing: state.columnResizing,
|
|
15
|
+
columnVisibility: state.columnVisibility,
|
|
16
|
+
rowSelection: state.rowSelection,
|
|
17
|
+
sorting: state.sorting
|
|
18
|
+
});
|
|
19
|
+
class DataTableState {
|
|
20
|
+
#options = $state.raw({});
|
|
21
|
+
#table;
|
|
22
|
+
#columns;
|
|
23
|
+
constructor(options, selector) {
|
|
24
|
+
this.#options = options;
|
|
25
|
+
this.#columns = normalizeDataTableColumns(options.columns);
|
|
26
|
+
const getData = () => this.#getData();
|
|
27
|
+
this.#table = createTanStackTable({
|
|
28
|
+
...options,
|
|
29
|
+
columns: this.#columns,
|
|
30
|
+
enableRowSelection: options.enableRowSelection ?? false,
|
|
31
|
+
get data() {
|
|
32
|
+
return getData();
|
|
33
|
+
},
|
|
34
|
+
_features: options._features ?? dataTableFeatures,
|
|
35
|
+
_rowModels: {
|
|
36
|
+
coreRowModel: createCoreRowModel(),
|
|
37
|
+
filteredRowModel: createFilteredRowModel(filterFns),
|
|
38
|
+
facetedRowModel: createFacetedRowModel(),
|
|
39
|
+
facetedUniqueValues: createFacetedUniqueValues(),
|
|
40
|
+
facetedMinMaxValues: createFacetedMinMaxValues(),
|
|
41
|
+
sortedRowModel: createSortedRowModel(sortFns),
|
|
42
|
+
...options._rowModels
|
|
43
|
+
}
|
|
44
|
+
}, selector ?? dataTableStateSelector);
|
|
45
|
+
}
|
|
46
|
+
get table() {
|
|
47
|
+
const table = this.#table;
|
|
48
|
+
table.setData = (data) => {
|
|
49
|
+
this.setData(data);
|
|
50
|
+
};
|
|
51
|
+
table.updateData = (updater) => {
|
|
52
|
+
this.updateData(updater);
|
|
53
|
+
};
|
|
54
|
+
return table;
|
|
55
|
+
}
|
|
56
|
+
setData(data) {
|
|
57
|
+
this.#options = {
|
|
58
|
+
...this.#options,
|
|
59
|
+
data
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
updateData(updater) {
|
|
63
|
+
this.setData(functionalUpdate(updater, this.#getData()));
|
|
64
|
+
}
|
|
65
|
+
#resolveData(data) {
|
|
66
|
+
return typeof data === 'function' ? data() : data;
|
|
67
|
+
}
|
|
68
|
+
#getData() {
|
|
69
|
+
return this.#resolveData(this.#options.data);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function createDataTable(options, selector) {
|
|
73
|
+
return new DataTableState(options, selector).table;
|
|
74
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createDataTable } from './create-table.svelte';
|
|
2
|
+
export type { DataTable, DataTableFeatures, DataTableOptions, DataTableSelectedState } from './create-table.svelte';
|
|
3
|
+
export { getDataTableCellConfig, getDataTableFilterConfig, hasCustomDataTableCell, normalizeDataTableColumns, type DataTableCell, type DataTableCellConfig, type DataTableCellType, type DataTableColumnAlign, type DataTableColumnDef, type DataTableColumnMeta, type DataTableFilterConfig, type DataTableFilterOption, type DataTableFilterType } from './cells';
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script lang="ts" generics="TData extends RowData, TSelected = object">
|
|
2
|
+
import * as Popover from '../popover';
|
|
3
|
+
import * as ScrollArea from '../scroll-area';
|
|
4
|
+
import Checkbox from '../checkbox/checkbox.svelte';
|
|
5
|
+
import type { Column, RowData } from '@tanstack/svelte-table';
|
|
6
|
+
import type { DataTable, DataTableFeatures, DataTableSelectedState } from './core';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
table: DataTable<TData, TSelected>;
|
|
10
|
+
triggerLabel?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let { table, triggerLabel = 'Columns' }: Props = $props();
|
|
14
|
+
|
|
15
|
+
const columnVisibility = $derived(
|
|
16
|
+
(table.state as unknown as DataTableSelectedState).columnVisibility
|
|
17
|
+
);
|
|
18
|
+
const allColumnsVisible = $derived(table.getIsAllColumnsVisible());
|
|
19
|
+
const someColumnsVisible = $derived(
|
|
20
|
+
table.getAllLeafColumns().some((column) => column.getCanHide() && column.getIsVisible())
|
|
21
|
+
);
|
|
22
|
+
const allColumnsVisibilityState = $derived(
|
|
23
|
+
allColumnsVisible ? true : someColumnsVisible ? 'indeterminate' : false
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
function getColumnLabel(column: Column<DataTableFeatures, TData, unknown>) {
|
|
27
|
+
return typeof column.columnDef.header === 'string' ? column.columnDef.header : column.id;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getColumnIsVisible(
|
|
31
|
+
column: Column<DataTableFeatures, TData, unknown>,
|
|
32
|
+
visibilityState: unknown
|
|
33
|
+
) {
|
|
34
|
+
void visibilityState;
|
|
35
|
+
return column.getIsVisible();
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<Popover.Root positioning={{ placement: 'bottom-end' }}>
|
|
40
|
+
<Popover.Trigger
|
|
41
|
+
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"
|
|
42
|
+
>
|
|
43
|
+
{triggerLabel}
|
|
44
|
+
</Popover.Trigger>
|
|
45
|
+
|
|
46
|
+
<Popover.Content class="w-56 p-2" showArrow={false}>
|
|
47
|
+
<div class="border-b border-surface-3 px-2 pb-2">
|
|
48
|
+
<Checkbox
|
|
49
|
+
size="sm"
|
|
50
|
+
label="All columns"
|
|
51
|
+
checked={allColumnsVisibilityState}
|
|
52
|
+
onCheckedChange={({ checked }) => table.toggleAllColumnsVisible(checked === true)}
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<ScrollArea.Root class="h-72">
|
|
57
|
+
<ScrollArea.Viewport>
|
|
58
|
+
<ScrollArea.Content class="py-1 pe-3">
|
|
59
|
+
<div class="flex flex-col">
|
|
60
|
+
{#each table.getAllLeafColumns() as column (column.id)}
|
|
61
|
+
<Checkbox
|
|
62
|
+
size="md"
|
|
63
|
+
label={getColumnLabel(column)}
|
|
64
|
+
class="min-h-8 rounded-sm px-2 hover:bg-surface-2"
|
|
65
|
+
checked={getColumnIsVisible(column, columnVisibility)}
|
|
66
|
+
disabled={!column.getCanHide()}
|
|
67
|
+
onCheckedChange={({ checked }) => column.toggleVisibility(checked === true)}
|
|
68
|
+
/>
|
|
69
|
+
{/each}
|
|
70
|
+
</div>
|
|
71
|
+
</ScrollArea.Content>
|
|
72
|
+
</ScrollArea.Viewport>
|
|
73
|
+
<ScrollArea.Scrollbar orientation="vertical">
|
|
74
|
+
<ScrollArea.Thumb />
|
|
75
|
+
</ScrollArea.Scrollbar>
|
|
76
|
+
<ScrollArea.Corner />
|
|
77
|
+
</ScrollArea.Root>
|
|
78
|
+
</Popover.Content>
|
|
79
|
+
</Popover.Root>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RowData } from '@tanstack/svelte-table';
|
|
2
|
+
import type { DataTable } from './core';
|
|
3
|
+
declare function $$render<TData extends RowData, TSelected = object>(): {
|
|
4
|
+
props: {
|
|
5
|
+
table: DataTable<TData, TSelected>;
|
|
6
|
+
triggerLabel?: string;
|
|
7
|
+
};
|
|
8
|
+
exports: {};
|
|
9
|
+
bindings: "";
|
|
10
|
+
slots: {};
|
|
11
|
+
events: {};
|
|
12
|
+
};
|
|
13
|
+
declare class __sveltets_Render<TData extends RowData, TSelected = object> {
|
|
14
|
+
props(): ReturnType<typeof $$render<TData, TSelected>>['props'];
|
|
15
|
+
events(): ReturnType<typeof $$render<TData, TSelected>>['events'];
|
|
16
|
+
slots(): ReturnType<typeof $$render<TData, TSelected>>['slots'];
|
|
17
|
+
bindings(): "";
|
|
18
|
+
exports(): {};
|
|
19
|
+
}
|
|
20
|
+
interface $$IsomorphicComponent {
|
|
21
|
+
new <TData extends RowData, TSelected = object>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData, TSelected>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData, TSelected>['props']>, ReturnType<__sveltets_Render<TData, TSelected>['events']>, ReturnType<__sveltets_Render<TData, TSelected>['slots']>> & {
|
|
22
|
+
$$bindings?: ReturnType<__sveltets_Render<TData, TSelected>['bindings']>;
|
|
23
|
+
} & ReturnType<__sveltets_Render<TData, TSelected>['exports']>;
|
|
24
|
+
<TData extends RowData, TSelected = object>(internal: unknown, props: ReturnType<__sveltets_Render<TData, TSelected>['props']> & {}): ReturnType<__sveltets_Render<TData, TSelected>['exports']>;
|
|
25
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
26
|
+
}
|
|
27
|
+
declare const DataTableColumnVisibility: $$IsomorphicComponent;
|
|
28
|
+
type DataTableColumnVisibility<TData extends RowData, TSelected = object> = InstanceType<typeof DataTableColumnVisibility<TData, TSelected>>;
|
|
29
|
+
export default DataTableColumnVisibility;
|