@invopop/popui 0.1.1 → 0.1.3-6.beta.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/dist/AlertDialog.svelte +10 -11
- package/dist/BaseButton.svelte +25 -104
- package/dist/BaseCard.svelte +35 -30
- package/dist/BaseCounter.svelte +11 -8
- package/dist/BaseDropdown.svelte +5 -5
- package/dist/BaseFlag.svelte +5 -3
- package/dist/BaseFlag.svelte.d.ts +1 -0
- package/dist/BaseTable.svelte +16 -16
- package/dist/BaseTable.svelte.d.ts +1 -1
- package/dist/BaseTableActions.svelte +4 -6
- package/dist/BaseTableCellContent.svelte +9 -21
- package/dist/BaseTableCheckbox.svelte +9 -11
- package/dist/BaseTableHeaderContent.svelte +4 -4
- package/dist/BaseTableHeaderOrderBy.svelte +23 -12
- package/dist/BaseTableRow.svelte +12 -10
- package/dist/Breadcrumb.svelte +40 -0
- package/dist/Breadcrumb.svelte.d.ts +4 -0
- package/dist/Breadcrumbs.svelte +5 -30
- package/dist/ButtonFile.svelte +40 -30
- package/dist/ButtonUuidCopy.svelte +6 -3
- package/dist/CardCheckbox.svelte +45 -32
- package/dist/CardCheckbox.svelte.d.ts +1 -1
- package/dist/CardRelation.svelte +12 -13
- package/dist/CompanySelector.svelte +35 -7
- package/dist/CounterWidget.svelte +52 -0
- package/dist/CounterWidget.svelte.d.ts +4 -0
- package/dist/DataListItem.svelte +14 -10
- package/dist/DatePicker.svelte +20 -17
- package/dist/DrawerContext.svelte +207 -15
- package/dist/DrawerContextItem.svelte +50 -50
- package/dist/DrawerContextSeparator.svelte +1 -1
- package/dist/DropdownSelect.svelte +46 -18
- package/dist/EmptyState.svelte +42 -0
- package/dist/EmptyState.svelte.d.ts +4 -0
- package/dist/FeedEvents.svelte +9 -5
- package/dist/FeedIconEvent.svelte +2 -2
- package/dist/FeedIconStatus.svelte +4 -4
- package/dist/FeedItem.svelte +10 -11
- package/dist/FeedItemDetail.svelte +32 -6
- package/dist/FeedViewer.svelte +1 -1
- package/dist/GlobalSearch.svelte +13 -12
- package/dist/InputCheckbox.svelte +2 -5
- package/dist/InputError.svelte +4 -9
- package/dist/InputLabel.svelte +3 -1
- package/dist/InputRadio.svelte +29 -13
- package/dist/InputRadio.svelte.d.ts +1 -1
- package/dist/InputSearch.svelte +8 -8
- package/dist/InputSelect.svelte +32 -31
- package/dist/InputText.svelte +32 -24
- package/dist/InputTextarea.svelte +25 -19
- package/dist/InputToggle.svelte +24 -18
- package/dist/MenuItem.svelte +16 -11
- package/dist/MenuItemCollapsible.svelte +7 -7
- package/dist/Notification.svelte +60 -25
- package/dist/ProfileAvatar.svelte +43 -14
- package/dist/ProgressBar.svelte +42 -0
- package/dist/ProgressBar.svelte.d.ts +4 -0
- package/dist/ProgressBarCircle.svelte +46 -0
- package/dist/ProgressBarCircle.svelte.d.ts +4 -0
- package/dist/SeparatorHorizontal.svelte +2 -2
- package/dist/ShortcutWrapper.svelte +14 -5
- package/dist/StatusLabel.svelte +4 -5
- package/dist/StepIconList.svelte +11 -9
- package/dist/TagBeta.svelte +26 -14
- package/dist/TagProgress.svelte +28 -0
- package/dist/TagProgress.svelte.d.ts +4 -0
- package/dist/TagSearch.svelte +4 -4
- package/dist/TagStatus.svelte +32 -34
- package/dist/TitleMain.svelte +1 -1
- package/dist/TitleSection.svelte +1 -1
- package/dist/UuidCopy.svelte +4 -4
- package/dist/alert-dialog/alert-dialog-action.svelte +8 -4
- package/dist/alert-dialog/alert-dialog-cancel.svelte +7 -3
- package/dist/alert-dialog/alert-dialog-content.svelte +1 -1
- package/dist/alert-dialog/alert-dialog-description.svelte +1 -1
- package/dist/alert-dialog/alert-dialog-footer.svelte +1 -1
- package/dist/alert-dialog/alert-dialog-header.svelte +1 -1
- package/dist/alert-dialog/alert-dialog-overlay.svelte +1 -1
- package/dist/alert-dialog/alert-dialog-title.svelte +1 -1
- package/dist/alert-dialog/alert-dialog-trigger.svelte +4 -2
- package/dist/button/button.svelte +200 -24
- package/dist/button/button.svelte.d.ts +51 -26
- package/dist/clickOutside.d.ts +5 -2
- package/dist/clickOutside.js +9 -3
- package/dist/data-table/cells/boolean-cell.svelte +16 -0
- package/dist/data-table/cells/boolean-cell.svelte.d.ts +8 -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/column-definitions.d.ts +12 -0
- package/dist/data-table/column-definitions.js +40 -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 +50 -0
- package/dist/data-table/data-table-pagination.svelte +144 -0
- package/dist/data-table/data-table-pagination.svelte.d.ts +4 -0
- package/dist/data-table/data-table-svelte.svelte.d.ts +40 -0
- package/dist/data-table/data-table-svelte.svelte.js +111 -0
- package/dist/data-table/data-table-toolbar.svelte +16 -0
- package/dist/data-table/data-table-toolbar.svelte.d.ts +29 -0
- package/dist/data-table/data-table-types.d.ts +66 -0
- package/dist/data-table/data-table-types.js +1 -0
- package/dist/data-table/data-table-view-options.svelte +88 -0
- package/dist/data-table/data-table-view-options.svelte.d.ts +27 -0
- package/dist/data-table/data-table.svelte +303 -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 +36 -0
- package/dist/data-table/table-setup.js +130 -0
- package/dist/data-table/table-styles.d.ts +17 -0
- package/dist/data-table/table-styles.js +48 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +3 -0
- package/dist/index.d.ts +15 -7
- package/dist/index.js +31 -14
- package/dist/range-calendar/range-calendar-cell.svelte +1 -1
- package/dist/range-calendar/range-calendar-day.svelte +11 -12
- package/dist/range-calendar/range-calendar-head-cell.svelte +1 -1
- package/dist/range-calendar/range-calendar-header.svelte +1 -1
- package/dist/range-calendar/range-calendar-month-select.svelte +1 -1
- package/dist/range-calendar/range-calendar-next-button.svelte +3 -3
- package/dist/range-calendar/range-calendar-prev-button.svelte +3 -3
- package/dist/range-calendar/range-calendar.svelte +1 -1
- package/dist/sonner/index.d.ts +1 -0
- package/dist/sonner/index.js +1 -0
- package/dist/sonner/sonner.svelte +44 -0
- package/dist/sonner/sonner.svelte.d.ts +4 -0
- package/dist/svg/CheckBadge.svelte +18 -0
- package/dist/svg/CheckBadge.svelte.d.ts +26 -0
- package/dist/svg/IconDelivery.svelte +86 -0
- package/dist/svg/IconDelivery.svelte.d.ts +20 -0
- package/dist/svg/IconEmpty.svelte +113 -121
- package/dist/svg/IconOrder.svelte +81 -0
- package/dist/svg/IconOrder.svelte.d.ts +20 -0
- package/dist/svg/IconPayment.svelte +86 -0
- package/dist/svg/IconPayment.svelte.d.ts +20 -0
- package/dist/table/table-body.svelte +5 -1
- package/dist/table/table-cell.svelte +4 -2
- package/dist/table/table-footer.svelte +1 -1
- 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/tabs/tabs-list.svelte +8 -2
- package/dist/tabs/tabs-list.svelte.d.ts +4 -1
- package/dist/tabs/tabs-trigger.svelte +5 -3
- package/dist/tabs/tabs-trigger.svelte.d.ts +4 -1
- package/dist/tailwind.theme.css +998 -0
- package/dist/tooltip/tooltip-content.svelte +2 -2
- package/dist/types.d.ts +71 -50
- package/package.json +21 -11
- package/dist/CounterWorkflow.svelte +0 -19
- package/dist/CounterWorkflow.svelte.d.ts +0 -4
- package/dist/DrawerContextWorkspace.svelte +0 -126
- package/dist/DrawerContextWorkspace.svelte.d.ts +0 -4
- package/dist/EmptyStateIcon.svelte +0 -52
- package/dist/EmptyStateIcon.svelte.d.ts +0 -4
- package/dist/EmptyStateIllustration.svelte +0 -66
- package/dist/EmptyStateIllustration.svelte.d.ts +0 -4
- package/dist/FormLayoutModal.svelte +0 -14
- package/dist/FormLayoutModal.svelte.d.ts +0 -4
- package/dist/ProfileSelector.svelte +0 -41
- package/dist/ProfileSelector.svelte.d.ts +0 -4
- package/dist/SectionLayout.svelte +0 -13
- package/dist/SectionLayout.svelte.d.ts +0 -4
- package/dist/tw.theme.d.ts +0 -142
- package/dist/tw.theme.js +0 -158
package/dist/clickOutside.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Dispatch event on click outside of node
|
|
3
|
+
* @param {HTMLElement} node
|
|
4
|
+
*/
|
|
2
5
|
export function clickOutside(node) {
|
|
6
|
+
/**
|
|
7
|
+
* @param {MouseEvent} event
|
|
8
|
+
*/
|
|
3
9
|
const handleClick = (event) => {
|
|
4
|
-
if (node && !node.contains(event.target) && !event.defaultPrevented) {
|
|
5
|
-
node.dispatchEvent(new CustomEvent('click_outside'
|
|
10
|
+
if (node && !node.contains(/** @type {Node} */ (event.target)) && !event.defaultPrevented) {
|
|
11
|
+
node.dispatchEvent(new CustomEvent('click_outside'))
|
|
6
12
|
}
|
|
7
13
|
}
|
|
8
14
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Icon } from '@steeze-ui/svelte-icon'
|
|
3
|
+
import type { BooleanCellConfig } from '../data-table-types.js'
|
|
4
|
+
|
|
5
|
+
let { value, config }: { value: boolean; config?: BooleanCellConfig } = $props()
|
|
6
|
+
|
|
7
|
+
const showWhenTrue = config?.showWhenTrue ?? true
|
|
8
|
+
const showWhenFalse = config?.showWhenFalse ?? false
|
|
9
|
+
const shouldShow = value ? showWhenTrue : showWhenFalse
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
{#if shouldShow && config?.icon}
|
|
13
|
+
<div class="flex justify-center">
|
|
14
|
+
<Icon src={config.icon} class={config.iconClass ?? 'size-4'} />
|
|
15
|
+
</div>
|
|
16
|
+
{/if}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BooleanCellConfig } from '../data-table-types.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
value: boolean;
|
|
4
|
+
config?: BooleanCellConfig;
|
|
5
|
+
};
|
|
6
|
+
declare const BooleanCell: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type BooleanCell = ReturnType<typeof BooleanCell>;
|
|
8
|
+
export default BooleanCell;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../../utils.js'
|
|
3
|
+
import type { CurrencyCellConfig } from '../data-table-types.js'
|
|
4
|
+
|
|
5
|
+
let { value, config }: { value: any; config?: CurrencyCellConfig } = $props()
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<span class={cn('font-mono text-base text-foreground', config?.className)}>
|
|
9
|
+
{value}
|
|
10
|
+
</span>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CurrencyCellConfig } from '../data-table-types.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
value: any;
|
|
4
|
+
config?: CurrencyCellConfig;
|
|
5
|
+
};
|
|
6
|
+
declare const CurrencyCell: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type CurrencyCell = ReturnType<typeof CurrencyCell>;
|
|
8
|
+
export default CurrencyCell;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../../utils.js'
|
|
3
|
+
import type { DateCellConfig } from '../data-table-types.js'
|
|
4
|
+
|
|
5
|
+
let { value, config }: { value: any; config?: DateCellConfig } = $props()
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<span class={cn('font-mono text-base text-foreground', config?.className)}>
|
|
9
|
+
{value}
|
|
10
|
+
</span>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DateCellConfig } from '../data-table-types.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
value: any;
|
|
4
|
+
config?: DateCellConfig;
|
|
5
|
+
};
|
|
6
|
+
declare const DateCell: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type DateCell = ReturnType<typeof DateCell>;
|
|
8
|
+
export default DateCell;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import TagStatus from '../../TagStatus.svelte'
|
|
3
|
+
import type { TagCellConfig } from '../data-table-types.js'
|
|
4
|
+
|
|
5
|
+
let { value, config }: { value: string; config: TagCellConfig } = $props()
|
|
6
|
+
|
|
7
|
+
const option = $derived(config.options.find((opt) => opt.value === value))
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
{#if option}
|
|
11
|
+
<TagStatus label={option.label} status={option.color} dot={config.showDot ?? false} />
|
|
12
|
+
{/if}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TagCellConfig } from '../data-table-types.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
value: string;
|
|
4
|
+
config: TagCellConfig;
|
|
5
|
+
};
|
|
6
|
+
declare const TagCell: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type TagCell = ReturnType<typeof TagCell>;
|
|
8
|
+
export default TagCell;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../../utils.js'
|
|
3
|
+
import type { TextCellConfig } from '../data-table-types.js'
|
|
4
|
+
|
|
5
|
+
let { value, config }: { value: any; config?: TextCellConfig } = $props()
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<div class={cn('truncate', config?.className)}>
|
|
9
|
+
{value}
|
|
10
|
+
</div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TextCellConfig } from '../data-table-types.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
value: any;
|
|
4
|
+
config?: TextCellConfig;
|
|
5
|
+
};
|
|
6
|
+
declare const TextCell: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type TextCell = ReturnType<typeof TextCell>;
|
|
8
|
+
export default TextCell;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ColumnDef, Row } from '@tanstack/table-core';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
/**
|
|
4
|
+
* Create the selection column definition for row selection
|
|
5
|
+
*/
|
|
6
|
+
export declare function createSelectionColumn<TData>(): ColumnDef<TData>;
|
|
7
|
+
/**
|
|
8
|
+
* Create the actions column definition for row actions
|
|
9
|
+
*/
|
|
10
|
+
export declare function createActionsColumn<TData>(rowActionsSnippet: Snippet<[{
|
|
11
|
+
row: Row<TData>;
|
|
12
|
+
}]>): ColumnDef<TData>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { renderComponent, renderSnippet } from './render-helpers.js';
|
|
2
|
+
import InputCheckbox from '../InputCheckbox.svelte';
|
|
3
|
+
/**
|
|
4
|
+
* Create the selection column definition for row selection
|
|
5
|
+
*/
|
|
6
|
+
export function createSelectionColumn() {
|
|
7
|
+
return {
|
|
8
|
+
id: 'select',
|
|
9
|
+
header: ({ table }) => renderComponent(InputCheckbox, {
|
|
10
|
+
checked: table.getIsAllPageRowsSelected(),
|
|
11
|
+
onchange: (value) => table.toggleAllPageRowsSelected(value),
|
|
12
|
+
indeterminate: table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected(),
|
|
13
|
+
'aria-label': 'Select all'
|
|
14
|
+
}),
|
|
15
|
+
cell: ({ row }) => renderComponent(InputCheckbox, {
|
|
16
|
+
checked: row.getIsSelected(),
|
|
17
|
+
onchange: (value) => row.toggleSelected(value),
|
|
18
|
+
'aria-label': 'Select row'
|
|
19
|
+
}),
|
|
20
|
+
enableSorting: false,
|
|
21
|
+
enableHiding: false,
|
|
22
|
+
enableResizing: false,
|
|
23
|
+
size: 40,
|
|
24
|
+
minSize: 40,
|
|
25
|
+
maxSize: 40
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create the actions column definition for row actions
|
|
30
|
+
*/
|
|
31
|
+
export function createActionsColumn(rowActionsSnippet) {
|
|
32
|
+
return {
|
|
33
|
+
id: 'actions',
|
|
34
|
+
cell: ({ row }) => renderSnippet(rowActionsSnippet, { row }),
|
|
35
|
+
enableResizing: false,
|
|
36
|
+
size: 44,
|
|
37
|
+
minSize: 44,
|
|
38
|
+
maxSize: 44
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ColumnSizingState } from '@tanstack/table-core';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate initial column sizes based on available container width
|
|
4
|
+
* Scales column sizes proportionally if container is wider than default sizes
|
|
5
|
+
*/
|
|
6
|
+
export declare function calculateColumnSizing(columns: any[], containerWidth: number): ColumnSizingState | null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate initial column sizes based on available container width
|
|
3
|
+
* Scales column sizes proportionally if container is wider than default sizes
|
|
4
|
+
*/
|
|
5
|
+
export function calculateColumnSizing(columns, containerWidth) {
|
|
6
|
+
// Collect all column sizes
|
|
7
|
+
const defaultSizes = {};
|
|
8
|
+
columns.forEach((col) => {
|
|
9
|
+
if (col.size) {
|
|
10
|
+
defaultSizes[col.id] = col.size;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const totalDefaultSize = Object.values(defaultSizes).reduce((sum, size) => sum + size, 0);
|
|
14
|
+
// If container is wider than default, scale columns proportionally
|
|
15
|
+
if (containerWidth > totalDefaultSize && totalDefaultSize > 0) {
|
|
16
|
+
const scale = containerWidth / totalDefaultSize;
|
|
17
|
+
const newSizing = {};
|
|
18
|
+
Object.entries(defaultSizes).forEach(([key, value]) => {
|
|
19
|
+
newSizing[key] = Math.floor(value * scale);
|
|
20
|
+
});
|
|
21
|
+
return newSizing;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { renderComponent } from './render-helpers.js';
|
|
2
|
+
import TextCell from './cells/text-cell.svelte';
|
|
3
|
+
import BooleanCell from './cells/boolean-cell.svelte';
|
|
4
|
+
import TagCell from './cells/tag-cell.svelte';
|
|
5
|
+
import DateCell from './cells/date-cell.svelte';
|
|
6
|
+
import CurrencyCell from './cells/currency-cell.svelte';
|
|
7
|
+
export function createColumns(columns) {
|
|
8
|
+
return columns.map((col) => {
|
|
9
|
+
const tanstackCol = {
|
|
10
|
+
id: col.id,
|
|
11
|
+
accessorKey: col.accessorKey,
|
|
12
|
+
header: col.header,
|
|
13
|
+
enableSorting: col.enableSorting ?? true,
|
|
14
|
+
enableHiding: col.enableHiding ?? true,
|
|
15
|
+
enableResizing: col.enableResizing ?? true,
|
|
16
|
+
size: col.size,
|
|
17
|
+
minSize: col.minSize,
|
|
18
|
+
maxSize: col.maxSize
|
|
19
|
+
};
|
|
20
|
+
// Cell renderer
|
|
21
|
+
if (col.cell) {
|
|
22
|
+
// Custom cell renderer
|
|
23
|
+
tanstackCol.cell = ({ row }) => {
|
|
24
|
+
const value = col.accessorKey ? row.original[col.accessorKey] : undefined;
|
|
25
|
+
return col.cell(value, row.original);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else if (col.cellType) {
|
|
29
|
+
// Built-in cell renderer based on type
|
|
30
|
+
tanstackCol.cell = ({ row }) => {
|
|
31
|
+
const value = col.accessorKey ? row.original[col.accessorKey] : undefined;
|
|
32
|
+
switch (col.cellType) {
|
|
33
|
+
case 'text':
|
|
34
|
+
return renderComponent(TextCell, { value: value, config: col.cellConfig });
|
|
35
|
+
case 'boolean':
|
|
36
|
+
return renderComponent(BooleanCell, { value: value, config: col.cellConfig });
|
|
37
|
+
case 'tag':
|
|
38
|
+
return renderComponent(TagCell, { value: value, config: col.cellConfig });
|
|
39
|
+
case 'date':
|
|
40
|
+
return renderComponent(DateCell, { value: value, config: col.cellConfig });
|
|
41
|
+
case 'currency':
|
|
42
|
+
return renderComponent(CurrencyCell, { value: value, config: col.cellConfig });
|
|
43
|
+
default:
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return tanstackCol;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Button from '../button/button.svelte'
|
|
3
|
+
import InputSelect from '../InputSelect.svelte'
|
|
4
|
+
import { ArrowLeft, ArrowRight, ScrollLeft, ScrollRight } from '@invopop/ui-icons'
|
|
5
|
+
import { cn } from '../utils.js'
|
|
6
|
+
import type { DataTablePaginationProps } from './data-table-types.js'
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
table,
|
|
10
|
+
id,
|
|
11
|
+
class: className,
|
|
12
|
+
showRowsPerPage = true,
|
|
13
|
+
rowsPerPageOptions = [10, 25, 50, 100],
|
|
14
|
+
itemsLabel = 'items',
|
|
15
|
+
children
|
|
16
|
+
}: DataTablePaginationProps<any> = $props()
|
|
17
|
+
|
|
18
|
+
let currentPage = $derived(table.getState().pagination.pageIndex + 1)
|
|
19
|
+
let totalPages = $derived(table.getPageCount())
|
|
20
|
+
let totalItems = $derived(table.getFilteredRowModel().rows.length)
|
|
21
|
+
let rowsPerPage = $derived(table.getState().pagination.pageSize)
|
|
22
|
+
|
|
23
|
+
let pageInputValue = $derived(`${currentPage}`)
|
|
24
|
+
|
|
25
|
+
function handlePageInput(event: Event) {
|
|
26
|
+
const target = event.target as HTMLInputElement
|
|
27
|
+
const value = parseInt(target.value)
|
|
28
|
+
if (value >= 1 && value <= totalPages) {
|
|
29
|
+
table.setPageIndex(value - 1)
|
|
30
|
+
} else if (target.value === '') {
|
|
31
|
+
// Allow empty input temporarily
|
|
32
|
+
pageInputValue = ''
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function handlePageBlur(event: Event) {
|
|
37
|
+
const target = event.target as HTMLInputElement
|
|
38
|
+
const value = parseInt(target.value)
|
|
39
|
+
if (isNaN(value) || value < 1) {
|
|
40
|
+
pageInputValue = `${currentPage}`
|
|
41
|
+
} else if (value > totalPages) {
|
|
42
|
+
table.setPageIndex(totalPages - 1)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function formatNumber(num: number): string {
|
|
47
|
+
return new Intl.NumberFormat('en-US').format(num)
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<div
|
|
52
|
+
{id}
|
|
53
|
+
class={cn(
|
|
54
|
+
'flex items-center justify-between h-11 px-4 py-[5px] bg-background backdrop-blur-[10px]',
|
|
55
|
+
className
|
|
56
|
+
)}
|
|
57
|
+
>
|
|
58
|
+
<div class="flex items-center gap-3">
|
|
59
|
+
<div class="flex items-center gap-2">
|
|
60
|
+
<div class="flex items-center gap-1.5">
|
|
61
|
+
<div class="flex items-center">
|
|
62
|
+
<Button
|
|
63
|
+
variant="ghost"
|
|
64
|
+
size="md"
|
|
65
|
+
icon={ScrollLeft}
|
|
66
|
+
onclick={() => table.setPageIndex(0)}
|
|
67
|
+
disabled={currentPage === 1}
|
|
68
|
+
class={cn(currentPage === 1 && 'pointer-events-none opacity-30')}
|
|
69
|
+
aria-label="First page"
|
|
70
|
+
/>
|
|
71
|
+
<Button
|
|
72
|
+
variant="ghost"
|
|
73
|
+
size="md"
|
|
74
|
+
icon={ArrowLeft}
|
|
75
|
+
onclick={() => table.previousPage()}
|
|
76
|
+
disabled={currentPage === 1}
|
|
77
|
+
class={cn(currentPage === 1 && 'pointer-events-none opacity-30')}
|
|
78
|
+
aria-label="Previous page"
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
81
|
+
<div class="flex items-center gap-1.5">
|
|
82
|
+
<input
|
|
83
|
+
type="number"
|
|
84
|
+
bind:value={pageInputValue}
|
|
85
|
+
min="1"
|
|
86
|
+
max={totalPages}
|
|
87
|
+
oninput={handlePageInput}
|
|
88
|
+
onblur={handlePageBlur}
|
|
89
|
+
class="w-12 h-8 px-2 py-1 text-base tracking-tight rounded-lg border border-border-default-secondary bg-background-default-default backdrop-blur-[2px] caret-foreground-accent text-foreground outline-none focus:ring-0 hover:border-border-default-secondary-hover focus:border-border-selected-bold focus:shadow-active [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
|
|
90
|
+
/>
|
|
91
|
+
<span class="text-sm text-foreground-default-secondary whitespace-nowrap">
|
|
92
|
+
/ {totalPages}
|
|
93
|
+
</span>
|
|
94
|
+
</div>
|
|
95
|
+
<div class="flex items-center">
|
|
96
|
+
<Button
|
|
97
|
+
variant="ghost"
|
|
98
|
+
size="md"
|
|
99
|
+
icon={ArrowRight}
|
|
100
|
+
onclick={() => table.nextPage()}
|
|
101
|
+
disabled={currentPage === totalPages}
|
|
102
|
+
class={cn(currentPage === totalPages && 'pointer-events-none opacity-30')}
|
|
103
|
+
aria-label="Next page"
|
|
104
|
+
/>
|
|
105
|
+
<Button
|
|
106
|
+
variant="ghost"
|
|
107
|
+
size="md"
|
|
108
|
+
icon={ScrollRight}
|
|
109
|
+
onclick={() => table.setPageIndex(totalPages - 1)}
|
|
110
|
+
disabled={currentPage === totalPages}
|
|
111
|
+
class={cn(currentPage === totalPages && 'pointer-events-none opacity-30')}
|
|
112
|
+
aria-label="Last page"
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
{#if showRowsPerPage}
|
|
117
|
+
<div class="w-[105px]">
|
|
118
|
+
<InputSelect
|
|
119
|
+
value={`${rowsPerPage}`}
|
|
120
|
+
options={rowsPerPageOptions.map((size) => ({
|
|
121
|
+
value: `${size}`,
|
|
122
|
+
label: `${size} rows`
|
|
123
|
+
}))}
|
|
124
|
+
onchange={(value) => {
|
|
125
|
+
table.setPageSize(Number(value))
|
|
126
|
+
}}
|
|
127
|
+
placeholder="Rows per page"
|
|
128
|
+
disablePlaceholder={true}
|
|
129
|
+
aria-label="Rows per page"
|
|
130
|
+
/>
|
|
131
|
+
</div>
|
|
132
|
+
{/if}
|
|
133
|
+
</div>
|
|
134
|
+
{#if totalItems > 0}
|
|
135
|
+
<span class="text-sm text-foreground-default-secondary">
|
|
136
|
+
{formatNumber(totalItems)}
|
|
137
|
+
{itemsLabel}
|
|
138
|
+
</span>
|
|
139
|
+
{/if}
|
|
140
|
+
</div>
|
|
141
|
+
{#if children}
|
|
142
|
+
{@render children()}
|
|
143
|
+
{/if}
|
|
144
|
+
</div>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DataTablePaginationProps } from './data-table-types.js';
|
|
2
|
+
declare const DataTablePagination: import("svelte").Component<DataTablePaginationProps<any>, {}, "">;
|
|
3
|
+
type DataTablePagination = ReturnType<typeof DataTablePagination>;
|
|
4
|
+
export default DataTablePagination;
|
|
@@ -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,111 @@
|
|
|
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
|
+
updateOptions();
|
|
57
|
+
});
|
|
58
|
+
return table;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Lazily merges several objects (or thunks) while preserving
|
|
62
|
+
* getter semantics from every source.
|
|
63
|
+
*
|
|
64
|
+
* Proxy-based to avoid known WebKit recursion issue.
|
|
65
|
+
*/
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
export function mergeObjects(...sources) {
|
|
68
|
+
const resolve = (src) => typeof src === "function" ? (src() ?? undefined) : src;
|
|
69
|
+
const findSourceWithKey = (key) => {
|
|
70
|
+
for (let i = sources.length - 1; i >= 0; i--) {
|
|
71
|
+
const obj = resolve(sources[i]);
|
|
72
|
+
if (obj && key in obj)
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
};
|
|
77
|
+
return new Proxy(Object.create(null), {
|
|
78
|
+
get(_, key) {
|
|
79
|
+
const src = findSourceWithKey(key);
|
|
80
|
+
return src?.[key];
|
|
81
|
+
},
|
|
82
|
+
has(_, key) {
|
|
83
|
+
return !!findSourceWithKey(key);
|
|
84
|
+
},
|
|
85
|
+
ownKeys() {
|
|
86
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
87
|
+
const all = new Set();
|
|
88
|
+
for (const s of sources) {
|
|
89
|
+
const obj = resolve(s);
|
|
90
|
+
if (obj) {
|
|
91
|
+
for (const k of Reflect.ownKeys(obj)) {
|
|
92
|
+
all.add(k);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return [...all];
|
|
97
|
+
},
|
|
98
|
+
getOwnPropertyDescriptor(_, key) {
|
|
99
|
+
const src = findSourceWithKey(key);
|
|
100
|
+
if (!src)
|
|
101
|
+
return undefined;
|
|
102
|
+
return {
|
|
103
|
+
configurable: true,
|
|
104
|
+
enumerable: true,
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
+
value: src[key],
|
|
107
|
+
writable: true,
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
|
|
6
|
+
let { table, filters }: { table: Table<TData>; filters?: Snippet } = $props()
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<div class="flex items-center justify-between">
|
|
10
|
+
{#if filters}
|
|
11
|
+
<div class="flex-1">
|
|
12
|
+
{@render filters()}
|
|
13
|
+
</div>
|
|
14
|
+
{/if}
|
|
15
|
+
<DataTableViewOptions {table} />
|
|
16
|
+
</div>
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
};
|
|
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 DataTableToolbar: $$IsomorphicComponent;
|
|
28
|
+
type DataTableToolbar<TData> = InstanceType<typeof DataTableToolbar<TData>>;
|
|
29
|
+
export default DataTableToolbar;
|