@upbound/monarch-blocks 0.14.0 → 0.16.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/chat-interface.js.map +1 -1
- package/dist/data-table.d.ts +10 -3
- package/dist/data-table.js +175 -117
- package/dist/data-table.js.map +1 -1
- package/dist/{empty-view-DQt8-Ho8.d.ts → empty-view-DHTvKsil.d.ts} +3 -0
- package/dist/graph.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +227 -163
- package/dist/index.js.map +1 -1
- package/dist/page-header.js +7 -1
- package/dist/page-header.js.map +1 -1
- package/dist/relative-time.d.ts +2 -2
- package/dist/relative-time.js +4 -4
- package/dist/relative-time.js.map +1 -1
- package/package.json +4 -4
package/dist/data-table.js
CHANGED
|
@@ -497,7 +497,7 @@ function formatRelativeDefault(date, locale) {
|
|
|
497
497
|
if (hrs2 < 24) return `in ${hrs2} hour${hrs2 === 1 ? "" : "s"}`;
|
|
498
498
|
if (days2 < 7) return `in ${days2} day${days2 === 1 ? "" : "s"}`;
|
|
499
499
|
if (days2 < 30) return `in ${Math.floor(days2 / 7)} week${Math.floor(days2 / 7) === 1 ? "" : "s"}`;
|
|
500
|
-
return
|
|
500
|
+
return `${date.toLocaleDateString(locale, __spreadValues({
|
|
501
501
|
month: "short",
|
|
502
502
|
day: "numeric"
|
|
503
503
|
}, date.getFullYear() !== now.getFullYear() ? { year: "numeric" } : {}))}`;
|
|
@@ -513,7 +513,7 @@ function formatRelativeDefault(date, locale) {
|
|
|
513
513
|
if (days < 7) return `${days} days ago`;
|
|
514
514
|
if (days < 14) return "last week";
|
|
515
515
|
if (days < 30) return `${Math.floor(days / 7)} weeks ago`;
|
|
516
|
-
return
|
|
516
|
+
return `${date.toLocaleDateString(locale, __spreadValues({
|
|
517
517
|
month: "short",
|
|
518
518
|
day: "numeric"
|
|
519
519
|
}, date.getFullYear() !== now.getFullYear() ? { year: "numeric" } : {}))}`;
|
|
@@ -531,7 +531,7 @@ function formatRelativeCompact(date, locale) {
|
|
|
531
531
|
if (hrs2 < 24) return `in ${hrs2}h`;
|
|
532
532
|
if (days2 < 7) return `in ${days2}d`;
|
|
533
533
|
if (days2 < 30) return `in ${Math.floor(days2 / 7)}w`;
|
|
534
|
-
return
|
|
534
|
+
return `${date.toLocaleDateString(locale, __spreadValues({
|
|
535
535
|
month: "short",
|
|
536
536
|
day: "numeric"
|
|
537
537
|
}, date.getFullYear() !== now.getFullYear() ? { year: "numeric" } : {}))}`;
|
|
@@ -545,7 +545,7 @@ function formatRelativeCompact(date, locale) {
|
|
|
545
545
|
if (hrs < 24) return `${hrs}h ago`;
|
|
546
546
|
if (days < 7) return `${days}d ago`;
|
|
547
547
|
if (days < 30) return `${Math.floor(days / 7)}w ago`;
|
|
548
|
-
return
|
|
548
|
+
return `${date.toLocaleDateString(locale, __spreadValues({
|
|
549
549
|
month: "short",
|
|
550
550
|
day: "numeric"
|
|
551
551
|
}, date.getFullYear() !== now.getFullYear() ? { year: "numeric" } : {}))}`;
|
|
@@ -718,7 +718,7 @@ function TimestampCell({ timestamp }) {
|
|
|
718
718
|
}
|
|
719
719
|
|
|
720
720
|
// src/data-table/data-table.tsx
|
|
721
|
-
import * as
|
|
721
|
+
import * as React11 from "react";
|
|
722
722
|
import {
|
|
723
723
|
useTable
|
|
724
724
|
} from "@tanstack/react-table";
|
|
@@ -3165,6 +3165,7 @@ function FilterToggle({ pressed, onPressedChange, count }) {
|
|
|
3165
3165
|
}
|
|
3166
3166
|
|
|
3167
3167
|
// src/data-table/pagination.tsx
|
|
3168
|
+
import * as React7 from "react";
|
|
3168
3169
|
import { Button as Button6 } from "@upbound/monarch-core";
|
|
3169
3170
|
import { Icon as Icon7 } from "@upbound/monarch-core";
|
|
3170
3171
|
import { Label as Label2 } from "@upbound/monarch-core";
|
|
@@ -3176,6 +3177,7 @@ import {
|
|
|
3176
3177
|
PaginationLink
|
|
3177
3178
|
} from "@upbound/monarch-core";
|
|
3178
3179
|
import { Select as Select2, SelectContent as SelectContent2, SelectGroup as SelectGroup2, SelectItem as SelectItem2, SelectTrigger as SelectTrigger2, SelectValue as SelectValue2 } from "@upbound/monarch-core";
|
|
3180
|
+
import { Spinner } from "@upbound/monarch-core";
|
|
3179
3181
|
import { Tooltip as Tooltip3, TooltipContent as TooltipContent3, TooltipTrigger as TooltipTrigger3 } from "@upbound/monarch-core";
|
|
3180
3182
|
import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
3181
3183
|
var DEFAULT_PAGINATION_CONFIG = {
|
|
@@ -3186,6 +3188,12 @@ var DEFAULT_PAGINATION_CONFIG = {
|
|
|
3186
3188
|
pageSizeOptions: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
|
|
3187
3189
|
};
|
|
3188
3190
|
var PAGE_SIZE_SELECT_ID = "table-page-size-select";
|
|
3191
|
+
var PAGE_ARROWS = {
|
|
3192
|
+
first: { label: "Go to first page", icon: "chevrons-left" },
|
|
3193
|
+
previous: { label: "Go to previous page", icon: "chevron-left" },
|
|
3194
|
+
next: { label: "Go to next page", icon: "chevron-right" },
|
|
3195
|
+
last: { label: "Go to last page", icon: "chevrons-right" }
|
|
3196
|
+
};
|
|
3189
3197
|
function getPageSizeOptions(pageSizeOptions) {
|
|
3190
3198
|
return Array.from(new Set(pageSizeOptions)).filter((option) => option > 0).sort((a, b) => a - b);
|
|
3191
3199
|
}
|
|
@@ -3206,9 +3214,11 @@ function DataTablePagination({
|
|
|
3206
3214
|
rowCount,
|
|
3207
3215
|
rowCountRelation = "eq",
|
|
3208
3216
|
paginationConfig = true,
|
|
3217
|
+
loading = false,
|
|
3209
3218
|
onPageChange,
|
|
3210
3219
|
onPageSizeChange
|
|
3211
3220
|
}) {
|
|
3221
|
+
const [requestedControl, setRequestedControl] = React7.useState(null);
|
|
3212
3222
|
const isRowCountExact = rowCountRelation === "eq";
|
|
3213
3223
|
const resolved = typeof paginationConfig === "object" ? __spreadValues(__spreadValues({}, DEFAULT_PAGINATION_CONFIG), paginationConfig) : DEFAULT_PAGINATION_CONFIG;
|
|
3214
3224
|
const { normalizedPageSizeOptions, effectivePageSize } = normalizePageSizeOptions(pageSize, resolved.pageSizeOptions);
|
|
@@ -3216,6 +3226,33 @@ function DataTablePagination({
|
|
|
3216
3226
|
const currentPage = pageIndex + 1;
|
|
3217
3227
|
const mounted = useMounted();
|
|
3218
3228
|
const locale = mounted ? void 0 : "en-US";
|
|
3229
|
+
const isLoadingControl = (control) => loading && requestedControl === control;
|
|
3230
|
+
const goToPage = (page, control) => {
|
|
3231
|
+
if (loading) return;
|
|
3232
|
+
setRequestedControl(control);
|
|
3233
|
+
onPageChange(page);
|
|
3234
|
+
};
|
|
3235
|
+
const changePageSize = (nextPageSize) => {
|
|
3236
|
+
setRequestedControl(null);
|
|
3237
|
+
onPageSizeChange(nextPageSize);
|
|
3238
|
+
};
|
|
3239
|
+
const renderArrow = (arrow, page, disabled) => {
|
|
3240
|
+
const { label, icon } = PAGE_ARROWS[arrow];
|
|
3241
|
+
const isRequested = isLoadingControl(arrow);
|
|
3242
|
+
return /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
|
|
3243
|
+
Button6,
|
|
3244
|
+
{
|
|
3245
|
+
variant: "outline",
|
|
3246
|
+
size: "icon",
|
|
3247
|
+
"aria-label": label,
|
|
3248
|
+
"aria-busy": isRequested || void 0,
|
|
3249
|
+
"aria-disabled": isRequested || void 0,
|
|
3250
|
+
disabled: !isRequested && (disabled || loading),
|
|
3251
|
+
onClick: () => goToPage(page, arrow),
|
|
3252
|
+
children: isRequested ? /* @__PURE__ */ jsx9(Spinner, {}) : /* @__PURE__ */ jsx9(Icon7, { name: icon, className: "cn-rtl-flip" })
|
|
3253
|
+
}
|
|
3254
|
+
) });
|
|
3255
|
+
};
|
|
3219
3256
|
return /* @__PURE__ */ jsxs9("div", { "data-testid": "table-footer", className: "flex items-center justify-between px-2 pt-4", children: [
|
|
3220
3257
|
resolved.summary ? /* @__PURE__ */ jsxs9("div", { className: "text-body text-muted-foreground", "data-testid": "table-pagination-summary", children: [
|
|
3221
3258
|
"Showing ",
|
|
@@ -3239,34 +3276,22 @@ function DataTablePagination({
|
|
|
3239
3276
|
/* @__PURE__ */ jsxs9("div", { className: "flex items-center gap-4", children: [
|
|
3240
3277
|
resolved.pageSizeSelector && /* @__PURE__ */ jsxs9("div", { className: "flex items-center gap-2", children: [
|
|
3241
3278
|
/* @__PURE__ */ jsx9(Label2, { htmlFor: PAGE_SIZE_SELECT_ID, className: "font-semibold", children: "Rows per page" }),
|
|
3242
|
-
/* @__PURE__ */ jsxs9(
|
|
3243
|
-
|
|
3244
|
-
/* @__PURE__ */ jsx9(SelectContent2, { align: "end", children: /* @__PURE__ */ jsx9(SelectGroup2, { children: normalizedPageSizeOptions.map((option) => /* @__PURE__ */ jsx9(SelectItem2, { value: String(option), children: option }, option)) }) })
|
|
3245
|
-
] })
|
|
3246
|
-
] }),
|
|
3247
|
-
pageCount > 1 && (resolved.arrows || resolved.numbers) && /* @__PURE__ */ jsx9(Pagination, { className: "mx-0 w-auto justify-end", children: /* @__PURE__ */ jsxs9(PaginationContent, { children: [
|
|
3248
|
-
resolved.arrows && /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
|
|
3249
|
-
Button6,
|
|
3279
|
+
/* @__PURE__ */ jsxs9(
|
|
3280
|
+
Select2,
|
|
3250
3281
|
{
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
) }),
|
|
3259
|
-
resolved.arrows && /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
|
|
3260
|
-
Button6,
|
|
3261
|
-
{
|
|
3262
|
-
variant: "outline",
|
|
3263
|
-
size: "icon",
|
|
3264
|
-
"aria-label": "Go to previous page",
|
|
3265
|
-
disabled: currentPage <= 1,
|
|
3266
|
-
onClick: () => onPageChange(currentPage - 1),
|
|
3267
|
-
children: /* @__PURE__ */ jsx9(Icon7, { name: "chevron-left", className: "cn-rtl-flip" })
|
|
3282
|
+
value: String(effectivePageSize),
|
|
3283
|
+
onValueChange: (value) => changePageSize(Number(value)),
|
|
3284
|
+
disabled: loading,
|
|
3285
|
+
children: [
|
|
3286
|
+
/* @__PURE__ */ jsx9(SelectTrigger2, { id: PAGE_SIZE_SELECT_ID, size: "sm", className: "w-18", "data-testid": "table-page-size-select", children: /* @__PURE__ */ jsx9(SelectValue2, {}) }),
|
|
3287
|
+
/* @__PURE__ */ jsx9(SelectContent2, { align: "end", children: /* @__PURE__ */ jsx9(SelectGroup2, { children: normalizedPageSizeOptions.map((option) => /* @__PURE__ */ jsx9(SelectItem2, { value: String(option), children: option }, option)) }) })
|
|
3288
|
+
]
|
|
3268
3289
|
}
|
|
3269
|
-
)
|
|
3290
|
+
)
|
|
3291
|
+
] }),
|
|
3292
|
+
pageCount > 1 && (resolved.arrows || resolved.numbers) && /* @__PURE__ */ jsx9(Pagination, { className: "mx-0 w-auto justify-end", children: /* @__PURE__ */ jsxs9(PaginationContent, { children: [
|
|
3293
|
+
resolved.arrows && renderArrow("first", 1, currentPage <= 1),
|
|
3294
|
+
resolved.arrows && renderArrow("previous", currentPage - 1, currentPage <= 1),
|
|
3270
3295
|
resolved.numbers && visiblePages.map(
|
|
3271
3296
|
(page, index) => page === void 0 ? /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(PaginationEllipsis, {}) }, `ellipsis-${index}`) : /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
|
|
3272
3297
|
PaginationLink,
|
|
@@ -3274,43 +3299,27 @@ function DataTablePagination({
|
|
|
3274
3299
|
href: "#",
|
|
3275
3300
|
size: "icon",
|
|
3276
3301
|
isActive: page === currentPage,
|
|
3302
|
+
"aria-label": `Go to page ${page}`,
|
|
3303
|
+
"aria-busy": isLoadingControl(page) || void 0,
|
|
3304
|
+
"aria-disabled": loading || void 0,
|
|
3305
|
+
className: cn(loading && !isLoadingControl(page) && "opacity-50"),
|
|
3277
3306
|
onClick: (e) => {
|
|
3278
3307
|
e.preventDefault();
|
|
3279
|
-
|
|
3308
|
+
goToPage(page, page);
|
|
3280
3309
|
},
|
|
3281
|
-
children: page
|
|
3310
|
+
children: isLoadingControl(page) ? /* @__PURE__ */ jsx9(Spinner, {}) : page
|
|
3282
3311
|
}
|
|
3283
3312
|
) }, page)
|
|
3284
3313
|
),
|
|
3285
|
-
resolved.arrows &&
|
|
3286
|
-
|
|
3287
|
-
{
|
|
3288
|
-
variant: "outline",
|
|
3289
|
-
size: "icon",
|
|
3290
|
-
"aria-label": "Go to next page",
|
|
3291
|
-
disabled: currentPage >= pageCount,
|
|
3292
|
-
onClick: () => onPageChange(currentPage + 1),
|
|
3293
|
-
children: /* @__PURE__ */ jsx9(Icon7, { name: "chevron-right", className: "cn-rtl-flip" })
|
|
3294
|
-
}
|
|
3295
|
-
) }),
|
|
3296
|
-
resolved.arrows && /* @__PURE__ */ jsx9(PaginationItem, { children: /* @__PURE__ */ jsx9(
|
|
3297
|
-
Button6,
|
|
3298
|
-
{
|
|
3299
|
-
variant: "outline",
|
|
3300
|
-
size: "icon",
|
|
3301
|
-
"aria-label": "Go to last page",
|
|
3302
|
-
disabled: currentPage >= pageCount,
|
|
3303
|
-
onClick: () => onPageChange(pageCount),
|
|
3304
|
-
children: /* @__PURE__ */ jsx9(Icon7, { name: "chevrons-right", className: "cn-rtl-flip" })
|
|
3305
|
-
}
|
|
3306
|
-
) })
|
|
3314
|
+
resolved.arrows && renderArrow("next", currentPage + 1, currentPage >= pageCount),
|
|
3315
|
+
resolved.arrows && renderArrow("last", pageCount, currentPage >= pageCount)
|
|
3307
3316
|
] }) })
|
|
3308
3317
|
] })
|
|
3309
3318
|
] });
|
|
3310
3319
|
}
|
|
3311
3320
|
|
|
3312
3321
|
// src/data-table/table-primitives.tsx
|
|
3313
|
-
import * as
|
|
3322
|
+
import * as React8 from "react";
|
|
3314
3323
|
import { flexRender as flexRender2 } from "@tanstack/react-table";
|
|
3315
3324
|
import { ContextMenu, ContextMenuTrigger } from "@upbound/monarch-core";
|
|
3316
3325
|
import {
|
|
@@ -3455,6 +3464,34 @@ function ColumnActionsMenuItems({
|
|
|
3455
3464
|
] })
|
|
3456
3465
|
] });
|
|
3457
3466
|
}
|
|
3467
|
+
function HeaderTooltip({ content, children }) {
|
|
3468
|
+
if (!content) return children;
|
|
3469
|
+
return /* @__PURE__ */ jsxs10(Tooltip4, { children: [
|
|
3470
|
+
/* @__PURE__ */ jsx10(TooltipTrigger4, { asChild: true, children }),
|
|
3471
|
+
/* @__PURE__ */ jsx10(TooltipContent4, { children: content })
|
|
3472
|
+
] });
|
|
3473
|
+
}
|
|
3474
|
+
function ColumnActionsMenu({
|
|
3475
|
+
header,
|
|
3476
|
+
tooltip,
|
|
3477
|
+
onAutosizeAll,
|
|
3478
|
+
onAutosizeColumn,
|
|
3479
|
+
layout,
|
|
3480
|
+
children
|
|
3481
|
+
}) {
|
|
3482
|
+
return /* @__PURE__ */ jsxs10(DropdownMenu3, { children: [
|
|
3483
|
+
/* @__PURE__ */ jsx10(HeaderTooltip, { content: tooltip, children: /* @__PURE__ */ jsx10(DropdownMenuTrigger3, { asChild: true, children }) }),
|
|
3484
|
+
/* @__PURE__ */ jsx10(
|
|
3485
|
+
ColumnActionsMenuItems,
|
|
3486
|
+
{
|
|
3487
|
+
header,
|
|
3488
|
+
onAutosizeAll,
|
|
3489
|
+
onAutosizeColumn,
|
|
3490
|
+
layout
|
|
3491
|
+
}
|
|
3492
|
+
)
|
|
3493
|
+
] });
|
|
3494
|
+
}
|
|
3458
3495
|
function HeaderCellContent({
|
|
3459
3496
|
header,
|
|
3460
3497
|
canResize,
|
|
@@ -3466,8 +3503,10 @@ function HeaderCellContent({
|
|
|
3466
3503
|
onResetColumnSize,
|
|
3467
3504
|
layout = "auto"
|
|
3468
3505
|
}) {
|
|
3506
|
+
var _a;
|
|
3469
3507
|
const resizeHandler = header.getResizeHandler();
|
|
3470
3508
|
const headerTitle = typeof header.column.columnDef.header === "string" ? header.column.columnDef.header : "";
|
|
3509
|
+
const headerTooltip = (_a = header.column.columnDef.meta) == null ? void 0 : _a.headerTooltip;
|
|
3471
3510
|
const sorted = header.column.getIsSorted();
|
|
3472
3511
|
const labelButton = /* @__PURE__ */ jsxs10(
|
|
3473
3512
|
"button",
|
|
@@ -3493,23 +3532,19 @@ function HeaderCellContent({
|
|
|
3493
3532
|
]
|
|
3494
3533
|
}
|
|
3495
3534
|
);
|
|
3496
|
-
const label = shouldShowActionsMenu ? /* @__PURE__ */
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
] }) : labelButton;
|
|
3535
|
+
const label = shouldShowActionsMenu ? /* @__PURE__ */ jsx10(
|
|
3536
|
+
ColumnActionsMenu,
|
|
3537
|
+
{
|
|
3538
|
+
header,
|
|
3539
|
+
tooltip: headerTooltip,
|
|
3540
|
+
onAutosizeAll,
|
|
3541
|
+
onAutosizeColumn,
|
|
3542
|
+
layout,
|
|
3543
|
+
children: labelButton
|
|
3544
|
+
}
|
|
3545
|
+
) : /* @__PURE__ */ jsx10(HeaderTooltip, { content: headerTooltip, children: labelButton });
|
|
3508
3546
|
return /* @__PURE__ */ jsxs10(Fragment5, { children: [
|
|
3509
|
-
/* @__PURE__ */ jsx10("div", { className: "flex min-w-0 flex-1 items-center gap-1", children: /* @__PURE__ */ jsx10("div", { className: "min-w-0 flex-1", children: !isActionColumn && !isGroupedColumn &&
|
|
3510
|
-
/* @__PURE__ */ jsx10(TooltipTrigger4, { asChild: true, children: label }),
|
|
3511
|
-
/* @__PURE__ */ jsx10(TooltipContent4, { children: headerTitle })
|
|
3512
|
-
] }) : label) }) }),
|
|
3547
|
+
/* @__PURE__ */ jsx10("div", { className: "flex min-w-0 flex-1 items-center gap-1", children: /* @__PURE__ */ jsx10("div", { className: "min-w-0 flex-1", children: !isActionColumn && !isGroupedColumn && label }) }),
|
|
3513
3548
|
canResize && /* @__PURE__ */ jsx10(
|
|
3514
3549
|
"button",
|
|
3515
3550
|
{
|
|
@@ -3615,7 +3650,7 @@ function DataTableHeader({
|
|
|
3615
3650
|
}
|
|
3616
3651
|
return /* @__PURE__ */ jsx10(BaseTableHeader, { children: headerGroups.map((headerGroup, headerGroupIndex) => /* @__PURE__ */ jsx10(BaseTableRow, { children: renderHeaders(headerGroup, headerGroupIndex) }, headerGroup.id)) });
|
|
3617
3652
|
}
|
|
3618
|
-
var DataTableRow =
|
|
3653
|
+
var DataTableRow = React8.forwardRef(
|
|
3619
3654
|
(_a, ref) => {
|
|
3620
3655
|
var _b = _a, { hoverable, disabled, className, layout = "auto" } = _b, props = __objRest(_b, ["hoverable", "disabled", "className", "layout"]);
|
|
3621
3656
|
const classes = cn(
|
|
@@ -3718,6 +3753,10 @@ function DataTableGroupRow({
|
|
|
3718
3753
|
}
|
|
3719
3754
|
return /* @__PURE__ */ jsx10(BaseTableRow, { className: "bg-muted/50 hover:bg-muted/50", children: /* @__PURE__ */ jsx10(BaseTableCell, { colSpan, className: "text-foreground border-b font-semibold whitespace-nowrap", children: groupLabel }) });
|
|
3720
3755
|
}
|
|
3756
|
+
function DefaultSkeletonCell({ actions }) {
|
|
3757
|
+
if (actions) return /* @__PURE__ */ jsx10(Skeleton, { className: "ml-auto size-6" });
|
|
3758
|
+
return /* @__PURE__ */ jsx10("div", { className: "flex h-lh w-full items-center", children: /* @__PURE__ */ jsx10(Skeleton, { className: "h-4 w-full" }) });
|
|
3759
|
+
}
|
|
3721
3760
|
function DataTableSkeletonBody({
|
|
3722
3761
|
rowCount = 10,
|
|
3723
3762
|
columns,
|
|
@@ -3734,14 +3773,14 @@ function DataTableSkeletonBody({
|
|
|
3734
3773
|
role: "cell",
|
|
3735
3774
|
className: cn(TABLE_CELL_CLASSES, "flex items-center overflow-hidden"),
|
|
3736
3775
|
style: { minWidth: col.minSize },
|
|
3737
|
-
children: (_a = renderCell == null ? void 0 : renderCell(col.id)) != null ? _a : /* @__PURE__ */ jsx10(
|
|
3776
|
+
children: (_a = renderCell == null ? void 0 : renderCell(col.id)) != null ? _a : /* @__PURE__ */ jsx10(DefaultSkeletonCell, { actions: col.actions })
|
|
3738
3777
|
},
|
|
3739
3778
|
`skeleton-col-${col.id}-row-${rowIndex}`
|
|
3740
3779
|
) : /* @__PURE__ */ jsx10(
|
|
3741
3780
|
BaseTableCell,
|
|
3742
3781
|
{
|
|
3743
3782
|
style: { width: col.size, minWidth: col.minSize, maxWidth: col.maxSize },
|
|
3744
|
-
children: (_b = renderCell == null ? void 0 : renderCell(col.id)) != null ? _b : /* @__PURE__ */ jsx10(
|
|
3783
|
+
children: (_b = renderCell == null ? void 0 : renderCell(col.id)) != null ? _b : /* @__PURE__ */ jsx10(DefaultSkeletonCell, { actions: col.actions })
|
|
3745
3784
|
},
|
|
3746
3785
|
`skeleton-col-${col.id}-row-${rowIndex}`
|
|
3747
3786
|
);
|
|
@@ -3782,12 +3821,16 @@ function DataTableBody({
|
|
|
3782
3821
|
const visibleColumns = columns.filter((column) => !isFilterOnlyColumn(column));
|
|
3783
3822
|
const colSpan = visibleColumns.length;
|
|
3784
3823
|
if (tableState === "loading") {
|
|
3785
|
-
const skeletonColumns = visibleColumns.map((c) =>
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3824
|
+
const skeletonColumns = visibleColumns.map((c) => {
|
|
3825
|
+
var _a;
|
|
3826
|
+
return {
|
|
3827
|
+
id: c.id,
|
|
3828
|
+
size: c.columnDef.size,
|
|
3829
|
+
minSize: c.columnDef.minSize,
|
|
3830
|
+
maxSize: c.columnDef.maxSize,
|
|
3831
|
+
actions: !!((_a = c.columnDef.meta) == null ? void 0 : _a.actions)
|
|
3832
|
+
};
|
|
3833
|
+
});
|
|
3791
3834
|
return /* @__PURE__ */ jsx10(
|
|
3792
3835
|
DataTableSkeletonBody,
|
|
3793
3836
|
{
|
|
@@ -3806,7 +3849,7 @@ function DataTableBody({
|
|
|
3806
3849
|
}
|
|
3807
3850
|
const isExpanded = !!(((_d = row.getCanExpand) == null ? void 0 : _d.call(row)) && ((_e = row.getIsExpanded) == null ? void 0 : _e.call(row)));
|
|
3808
3851
|
const expandedRow = renderExpandedRow && isExpanded ? renderExpandedRow(row.original) : null;
|
|
3809
|
-
return /* @__PURE__ */ jsxs10(
|
|
3852
|
+
return /* @__PURE__ */ jsxs10(React8.Fragment, { children: [
|
|
3810
3853
|
/* @__PURE__ */ jsx10(
|
|
3811
3854
|
DataTableRow,
|
|
3812
3855
|
__spreadProps(__spreadValues({}, onRowRender ? onRowRender(row.original, row) : {}), {
|
|
@@ -3837,10 +3880,10 @@ function DataTableBody({
|
|
|
3837
3880
|
}
|
|
3838
3881
|
|
|
3839
3882
|
// src/data-table/view-filter.tsx
|
|
3840
|
-
import * as
|
|
3883
|
+
import * as React10 from "react";
|
|
3841
3884
|
|
|
3842
3885
|
// src/filter-bar/filter-bar.tsx
|
|
3843
|
-
import * as
|
|
3886
|
+
import * as React9 from "react";
|
|
3844
3887
|
import { Icon as Icon9 } from "@upbound/monarch-core";
|
|
3845
3888
|
import { Badge as Badge3 } from "@upbound/monarch-core";
|
|
3846
3889
|
import { Button as Button7 } from "@upbound/monarch-core";
|
|
@@ -3940,12 +3983,12 @@ function FilterBar(_a) {
|
|
|
3940
3983
|
const remainingFilters = filters.filter((f) => !usedKeys.has(f.key));
|
|
3941
3984
|
const availableFilters = filters.some(hasOrder) ? remainingFilters : sortBy(remainingFilters, (f) => f.label);
|
|
3942
3985
|
const shouldShowFilters = availableFilters.length > 0 || activeFilters.length > 0;
|
|
3943
|
-
const [pendingOpenKey, setPendingOpenKey] =
|
|
3986
|
+
const [pendingOpenKey, setPendingOpenKey] = React9.useState(null);
|
|
3944
3987
|
function handleAddFilter(key) {
|
|
3945
3988
|
onAddFilter(key);
|
|
3946
3989
|
setPendingOpenKey(key);
|
|
3947
3990
|
}
|
|
3948
|
-
const containerRef =
|
|
3991
|
+
const containerRef = React9.useRef(null);
|
|
3949
3992
|
return /* @__PURE__ */ jsxs11(
|
|
3950
3993
|
"div",
|
|
3951
3994
|
__spreadProps(__spreadValues({
|
|
@@ -4230,7 +4273,7 @@ function TextFilterChip({
|
|
|
4230
4273
|
}) {
|
|
4231
4274
|
const { label, placeholder } = definition;
|
|
4232
4275
|
const text = asTextValue(value);
|
|
4233
|
-
const [open, setOpen] =
|
|
4276
|
+
const [open, setOpen] = React9.useState(!!autoOpen);
|
|
4234
4277
|
return /* @__PURE__ */ jsxs11(ButtonGroup2, { children: [
|
|
4235
4278
|
/* @__PURE__ */ jsx11(ButtonGroupText2, { children: label }),
|
|
4236
4279
|
/* @__PURE__ */ jsxs11(Popover2, { open, onOpenChange: setOpen, children: [
|
|
@@ -4260,7 +4303,7 @@ function MultiTextFilterChip({
|
|
|
4260
4303
|
}) {
|
|
4261
4304
|
const { label, placeholder } = definition;
|
|
4262
4305
|
const tokens = asMultiTextValue(value);
|
|
4263
|
-
const [draft, setDraft] =
|
|
4306
|
+
const [draft, setDraft] = React9.useState("");
|
|
4264
4307
|
const displayLabel = tokens.length === 0 ? "Any" : tokens.length === 1 ? tokens[0] : `${tokens.length} values`;
|
|
4265
4308
|
function addToken() {
|
|
4266
4309
|
const token = draft.trim();
|
|
@@ -4448,7 +4491,7 @@ function ViewFilter({
|
|
|
4448
4491
|
onColumnFiltersChange,
|
|
4449
4492
|
className
|
|
4450
4493
|
}) {
|
|
4451
|
-
const filterableColumns =
|
|
4494
|
+
const filterableColumns = React10.useMemo(
|
|
4452
4495
|
() => columns.filter((column) => column.getCanFilter()).flatMap((column) => {
|
|
4453
4496
|
var _a;
|
|
4454
4497
|
const filter = (_a = column.columnDef.meta) == null ? void 0 : _a.filter;
|
|
@@ -4456,7 +4499,7 @@ function ViewFilter({
|
|
|
4456
4499
|
}),
|
|
4457
4500
|
[columns]
|
|
4458
4501
|
);
|
|
4459
|
-
const filterDefinitions =
|
|
4502
|
+
const filterDefinitions = React10.useMemo(
|
|
4460
4503
|
() => filterableColumns.map(({ key, filter }) => toFilterBarDefinition(key, filter)).sort((a, b) => {
|
|
4461
4504
|
if (a.order == null && b.order == null) return 0;
|
|
4462
4505
|
if (a.order == null) return 1;
|
|
@@ -4465,11 +4508,11 @@ function ViewFilter({
|
|
|
4465
4508
|
}),
|
|
4466
4509
|
[filterableColumns]
|
|
4467
4510
|
);
|
|
4468
|
-
const emptyValueByKey =
|
|
4511
|
+
const emptyValueByKey = React10.useMemo(
|
|
4469
4512
|
() => new Map(filterableColumns.map(({ key, filter }) => [key, emptyValueFor(filter)])),
|
|
4470
4513
|
[filterableColumns]
|
|
4471
4514
|
);
|
|
4472
|
-
const activeFilters =
|
|
4515
|
+
const activeFilters = React10.useMemo(
|
|
4473
4516
|
() => columnFilters.map((filter) => ({ key: filter.id, value: filter.value })),
|
|
4474
4517
|
[columnFilters]
|
|
4475
4518
|
);
|
|
@@ -4518,6 +4561,9 @@ import { Fragment as Fragment7, jsx as jsx14, jsxs as jsxs12 } from "react/jsx-r
|
|
|
4518
4561
|
var DEFAULT_PAGE_SIZE = 20;
|
|
4519
4562
|
var noop = () => {
|
|
4520
4563
|
};
|
|
4564
|
+
function isSamePage(a, b) {
|
|
4565
|
+
return a.pageIndex === b.pageIndex && a.pageSize === b.pageSize;
|
|
4566
|
+
}
|
|
4521
4567
|
var STICKY_HEADER_MAX_HEIGHT_CLASS = "max-h-[calc(100svh-250px)]";
|
|
4522
4568
|
function DataTable({
|
|
4523
4569
|
id,
|
|
@@ -4574,19 +4620,19 @@ function DataTable({
|
|
|
4574
4620
|
}) {
|
|
4575
4621
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
4576
4622
|
const isGrid = layout === "grid";
|
|
4577
|
-
const tableBodyScrollRef =
|
|
4578
|
-
const [innerGlobalFilter, setInnerGlobalFilter] =
|
|
4579
|
-
const [innerColumnOrdering, setInnerColumnOrdering] =
|
|
4580
|
-
const [innerColumnFilters, setInnerColumnFilters] =
|
|
4581
|
-
const [innerSorting, setInnerSorting] =
|
|
4582
|
-
const [innerColumnPinning, setInnerColumnPinning] =
|
|
4583
|
-
const [innerPagination, setInnerPagination] =
|
|
4623
|
+
const tableBodyScrollRef = React11.useRef(null);
|
|
4624
|
+
const [innerGlobalFilter, setInnerGlobalFilter] = React11.useState("");
|
|
4625
|
+
const [innerColumnOrdering, setInnerColumnOrdering] = React11.useState([]);
|
|
4626
|
+
const [innerColumnFilters, setInnerColumnFilters] = React11.useState([]);
|
|
4627
|
+
const [innerSorting, setInnerSorting] = React11.useState(((_a = config.state) == null ? void 0 : _a.sorting) || []);
|
|
4628
|
+
const [innerColumnPinning, setInnerColumnPinning] = React11.useState({ start: [], end: [] });
|
|
4629
|
+
const [innerPagination, setInnerPagination] = React11.useState({
|
|
4584
4630
|
pageIndex: ((_c = (_b = config.state) == null ? void 0 : _b.pagination) == null ? void 0 : _c.pageIndex) || 0,
|
|
4585
4631
|
pageSize: ((_e = (_d = config.state) == null ? void 0 : _d.pagination) == null ? void 0 : _e.pageSize) || DEFAULT_PAGE_SIZE
|
|
4586
4632
|
});
|
|
4587
|
-
const [innerGrouping, setInnerGrouping] =
|
|
4588
|
-
const [innerColumnVisibility, setInnerColumnVisibility] =
|
|
4589
|
-
const [innerExpanded, setInnerExpanded] =
|
|
4633
|
+
const [innerGrouping, setInnerGrouping] = React11.useState([]);
|
|
4634
|
+
const [innerColumnVisibility, setInnerColumnVisibility] = React11.useState({});
|
|
4635
|
+
const [innerExpanded, setInnerExpanded] = React11.useState({});
|
|
4590
4636
|
const {
|
|
4591
4637
|
columnSizing,
|
|
4592
4638
|
handleColumnSizingChange,
|
|
@@ -4613,25 +4659,36 @@ function DataTable({
|
|
|
4613
4659
|
const pagination = parentPagination || innerPagination;
|
|
4614
4660
|
const setPagination = parentSetPagination != null ? parentSetPagination : setInnerPagination;
|
|
4615
4661
|
const shouldDisablePagination = paginationConfig === false;
|
|
4616
|
-
const
|
|
4662
|
+
const [pageRequest, setPageRequest] = React11.useState(null);
|
|
4663
|
+
if (pageRequest && !loading && isSamePage(pageRequest.pagination, pagination)) {
|
|
4664
|
+
setPageRequest(null);
|
|
4665
|
+
}
|
|
4666
|
+
const pageLoading = loading && pageRequest !== null;
|
|
4667
|
+
const shownConfig = pageLoading ? __spreadValues(__spreadValues({}, config), pageRequest.rows) : config;
|
|
4668
|
+
const requestPage = (nextPagination) => {
|
|
4669
|
+
const { data, rowCount: rowCount2, rowCountRelation } = config;
|
|
4670
|
+
setPageRequest({ pagination: nextPagination, rows: { data, rowCount: rowCount2, rowCountRelation } });
|
|
4671
|
+
setPagination(nextPagination);
|
|
4672
|
+
};
|
|
4673
|
+
const resetPageIndexOnFilterChange = React11.useCallback(() => {
|
|
4617
4674
|
if (!serverSidePagination || pagination.pageIndex === 0) return;
|
|
4618
4675
|
setPagination((prev) => __spreadProps(__spreadValues({}, prev), { pageIndex: 0 }));
|
|
4619
4676
|
}, [serverSidePagination, pagination.pageIndex, setPagination]);
|
|
4620
|
-
const setGlobalFilter =
|
|
4677
|
+
const setGlobalFilter = React11.useCallback(
|
|
4621
4678
|
(value) => {
|
|
4622
4679
|
applyGlobalFilter(value);
|
|
4623
4680
|
resetPageIndexOnFilterChange();
|
|
4624
4681
|
},
|
|
4625
4682
|
[applyGlobalFilter, resetPageIndexOnFilterChange]
|
|
4626
4683
|
);
|
|
4627
|
-
const setColumnFilters =
|
|
4684
|
+
const setColumnFilters = React11.useCallback(
|
|
4628
4685
|
(value) => {
|
|
4629
4686
|
applyColumnFilters(value);
|
|
4630
4687
|
resetPageIndexOnFilterChange();
|
|
4631
4688
|
},
|
|
4632
4689
|
[applyColumnFilters, resetPageIndexOnFilterChange]
|
|
4633
4690
|
);
|
|
4634
|
-
|
|
4691
|
+
React11.useLayoutEffect(() => {
|
|
4635
4692
|
var _a2;
|
|
4636
4693
|
if (shouldDisablePagination) return;
|
|
4637
4694
|
(_a2 = tableBodyScrollRef.current) == null ? void 0 : _a2.scrollTo({ top: 0 });
|
|
@@ -4655,8 +4712,8 @@ function DataTable({
|
|
|
4655
4712
|
const hasExternalSearch = parentGlobalFilter !== void 0;
|
|
4656
4713
|
const hasExternalFilters = parentColumnFilters !== void 0;
|
|
4657
4714
|
const shouldDisableFiltersModels = !!disableFilters && !!disableSearch && !hasExternalSearch && !hasExternalFilters;
|
|
4658
|
-
const columns =
|
|
4659
|
-
const table = useTable(__spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues({},
|
|
4715
|
+
const columns = React11.useMemo(() => withDefaultFilterFns(config.columns), [config.columns]);
|
|
4716
|
+
const table = useTable(__spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, shownConfig), {
|
|
4660
4717
|
columns,
|
|
4661
4718
|
features: dataTableFeatures,
|
|
4662
4719
|
// Row models are registered statically in `dataTableFeatures`, so a disabled stage is switched
|
|
@@ -4715,7 +4772,7 @@ function DataTable({
|
|
|
4715
4772
|
const orderedVisibleColumns = table.getVisibleLeafColumns().filter((col) => !isFilterOnlyColumn(col));
|
|
4716
4773
|
const hasFilters = !!celFilterConfig || hasFilterableColumns(flatColumns);
|
|
4717
4774
|
const showFilterToggle = filterToggleRequested && !disableFilters && hasFilters;
|
|
4718
|
-
const [gridMeasuredMins, setGridMeasuredMins] =
|
|
4775
|
+
const [gridMeasuredMins, setGridMeasuredMins] = React11.useState({});
|
|
4719
4776
|
const { gridTemplateColumns, gridRootRef, handleAutosizeAll, handleAutosizeColumn, handleResetColumnSize } = useGridLayout({
|
|
4720
4777
|
layout,
|
|
4721
4778
|
table,
|
|
@@ -4729,7 +4786,7 @@ function DataTable({
|
|
|
4729
4786
|
rawHandleAutosizeColumn,
|
|
4730
4787
|
rawHandleResetColumnSize
|
|
4731
4788
|
});
|
|
4732
|
-
const handleContextCell =
|
|
4789
|
+
const handleContextCell = React11.useCallback(
|
|
4733
4790
|
(filter, cell) => {
|
|
4734
4791
|
var _a2, _b2;
|
|
4735
4792
|
if (celFilterConfig == null ? void 0 : celFilterConfig.onContextualFilter) {
|
|
@@ -4746,13 +4803,13 @@ function DataTable({
|
|
|
4746
4803
|
},
|
|
4747
4804
|
[celFilterConfig, onContextCell, setColumnFilters, table]
|
|
4748
4805
|
);
|
|
4749
|
-
const handleContextSearch =
|
|
4806
|
+
const handleContextSearch = React11.useCallback(
|
|
4750
4807
|
(searchTerm) => {
|
|
4751
4808
|
setGlobalFilter(searchTerm);
|
|
4752
4809
|
},
|
|
4753
4810
|
[setGlobalFilter]
|
|
4754
4811
|
);
|
|
4755
|
-
const totalTableWidth =
|
|
4812
|
+
const totalTableWidth = React11.useMemo(() => {
|
|
4756
4813
|
if (isGrid) return 0;
|
|
4757
4814
|
const firstGroup = headerGroups[0];
|
|
4758
4815
|
if (!firstGroup) return 0;
|
|
@@ -4765,7 +4822,7 @@ function DataTable({
|
|
|
4765
4822
|
return getColumnFilterCount(value, (_b2 = (_a2 = table.getColumn(columnFilterId)) == null ? void 0 : _a2.columnDef.meta) == null ? void 0 : _b2.filter);
|
|
4766
4823
|
}
|
|
4767
4824
|
).reduce((prev, curr) => prev + curr, 0);
|
|
4768
|
-
const tableState = getTableState({ error: !!showError, loading, rowCount });
|
|
4825
|
+
const tableState = getTableState({ error: !!showError, loading: loading && !pageLoading, rowCount });
|
|
4769
4826
|
const shouldDisable = tableState === "error";
|
|
4770
4827
|
const shouldRenderTableContent = tableState !== "error" && tableState !== "empty";
|
|
4771
4828
|
const resetFilters = () => {
|
|
@@ -4776,7 +4833,7 @@ function DataTable({
|
|
|
4776
4833
|
}
|
|
4777
4834
|
setGlobalFilter("");
|
|
4778
4835
|
};
|
|
4779
|
-
|
|
4836
|
+
React11.useEffect(() => {
|
|
4780
4837
|
if (disableColumnReordering) return;
|
|
4781
4838
|
const allColumnIds = flatColumns.map((col) => col.id);
|
|
4782
4839
|
const normalizedColumnOrdering = normalizeColumnOrdering(columnOrdering, allColumnIds);
|
|
@@ -4902,12 +4959,13 @@ function DataTable({
|
|
|
4902
4959
|
DataTablePagination,
|
|
4903
4960
|
{
|
|
4904
4961
|
rowCount,
|
|
4905
|
-
rowCountRelation: (_g =
|
|
4962
|
+
rowCountRelation: (_g = shownConfig.rowCountRelation) != null ? _g : "eq",
|
|
4906
4963
|
paginationConfig,
|
|
4964
|
+
loading: pageLoading,
|
|
4907
4965
|
pageSize: pagination.pageSize,
|
|
4908
4966
|
pageIndex: pagination.pageIndex,
|
|
4909
|
-
onPageChange: (p) =>
|
|
4910
|
-
onPageSizeChange: (
|
|
4967
|
+
onPageChange: (p) => requestPage(__spreadProps(__spreadValues({}, pagination), { pageIndex: p - 1 })),
|
|
4968
|
+
onPageSizeChange: (pageSize) => requestPage({ pageIndex: 0, pageSize })
|
|
4911
4969
|
}
|
|
4912
4970
|
)
|
|
4913
4971
|
] }) : /* @__PURE__ */ jsx14(
|