@bsol-oss/react-datatable5 12.0.0-beta.1 → 12.0.0-beta.11

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.
Files changed (51) hide show
  1. package/dist/index.d.ts +55 -45
  2. package/dist/index.js +379 -309
  3. package/dist/index.mjs +376 -308
  4. package/dist/types/components/DataTable/DataTable.d.ts +1 -1
  5. package/dist/types/components/DataTable/DataTableServer.d.ts +1 -1
  6. package/dist/types/components/DataTable/DefaultTable.d.ts +5 -5
  7. package/dist/types/components/DataTable/components/TextCell.d.ts +10 -0
  8. package/dist/types/components/DataTable/context/DataTableContext.d.ts +2 -1
  9. package/dist/types/components/DataTable/controls/DensityFeature.d.ts +23 -0
  10. package/dist/types/components/DataTable/controls/DensityToggleButton.d.ts +6 -0
  11. package/dist/types/components/DataTable/controls/EditSortingButton.d.ts +7 -0
  12. package/dist/types/components/DataTable/controls/FilterDialog.d.ts +5 -0
  13. package/dist/types/components/DataTable/controls/PageSizeControl.d.ts +4 -0
  14. package/dist/types/components/DataTable/controls/Pagination.d.ts +1 -0
  15. package/dist/types/components/DataTable/controls/ReloadButton.d.ts +5 -0
  16. package/dist/types/components/DataTable/controls/ResetFilteringButton.d.ts +4 -0
  17. package/dist/types/components/DataTable/controls/ResetSelectionButton.d.ts +4 -0
  18. package/dist/types/components/DataTable/controls/ResetSortingButton.d.ts +4 -0
  19. package/dist/types/components/DataTable/controls/RowCountText.d.ts +1 -0
  20. package/dist/types/components/DataTable/controls/SelectAllRowsToggle.d.ts +8 -0
  21. package/dist/types/components/DataTable/controls/TableControls.d.ts +21 -0
  22. package/dist/types/components/DataTable/controls/TableFilterTags.d.ts +1 -0
  23. package/dist/types/components/DataTable/controls/TableFilters.d.ts +1 -0
  24. package/dist/types/components/DataTable/controls/TableSelector.d.ts +1 -0
  25. package/dist/types/components/DataTable/controls/TableSorter.d.ts +1 -0
  26. package/dist/types/components/DataTable/controls/TableViewer.d.ts +1 -0
  27. package/dist/types/components/DataTable/controls/ViewDialog.d.ts +5 -0
  28. package/dist/types/components/DataTable/display/CardHeader.d.ts +13 -0
  29. package/dist/types/components/DataTable/display/DataDisplay.d.ts +6 -0
  30. package/dist/types/components/DataTable/display/EmptyState.d.ts +5 -0
  31. package/dist/types/components/DataTable/display/ErrorAlert.d.ts +4 -0
  32. package/dist/types/components/DataTable/display/RecordDisplay.d.ts +9 -0
  33. package/dist/types/components/DataTable/display/Table.d.ts +10 -0
  34. package/dist/types/components/DataTable/display/TableBody.d.ts +21 -0
  35. package/dist/types/components/DataTable/display/TableCardContainer.d.ts +7 -0
  36. package/dist/types/components/DataTable/display/TableCards.d.ts +11 -0
  37. package/dist/types/components/DataTable/display/TableComponent.d.ts +6 -0
  38. package/dist/types/components/DataTable/display/TableDataDisplay.d.ts +6 -0
  39. package/dist/types/components/DataTable/display/TableFooter.d.ts +9 -0
  40. package/dist/types/components/DataTable/display/TableHeader.d.ts +13 -0
  41. package/dist/types/components/DataTable/display/TableLoadingComponent.d.ts +5 -0
  42. package/dist/types/components/DataTable/display/TextCell.d.ts +10 -0
  43. package/dist/types/components/DataTable/useDataTable.d.ts +1 -1
  44. package/dist/types/components/Form/SchemaFormContext.d.ts +13 -0
  45. package/dist/types/components/Form/components/core/DefaultForm.d.ts +7 -0
  46. package/dist/types/components/Form/components/core/FormBody.d.ts +1 -0
  47. package/dist/types/components/Form/components/core/FormRoot.d.ts +39 -0
  48. package/dist/types/components/Form/components/core/FormTitle.d.ts +1 -0
  49. package/dist/types/components/Form/components/core/SubmitButton.d.ts +1 -0
  50. package/dist/types/index.d.ts +37 -35
  51. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1,14 +1,15 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, RadioGroup as RadioGroup$1, Grid, Box, Slider as Slider$1, HStack, For, Flex, Text, Tag as Tag$1, Input, useDisclosure, DialogBackdrop, CheckboxCard as CheckboxCard$1, Menu, createRecipeContext, createContext as createContext$1, Pagination as Pagination$1, usePaginationContext, Image, Card, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Group, InputElement, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$2, VStack, List, Alert, Accordion, Field as Field$1, Popover, NumberInput, Show, RadioCard, CheckboxGroup, Heading, Center } from '@chakra-ui/react';
2
+ import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, Flex, Text, useDisclosure, DialogBackdrop, RadioGroup as RadioGroup$1, Grid, Box, Slider as Slider$1, HStack, For, Tag as Tag$1, Input, Menu, createRecipeContext, createContext as createContext$1, Pagination as Pagination$1, usePaginationContext, CheckboxCard as CheckboxCard$1, Image, EmptyState as EmptyState$2, VStack, Alert, Card, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Group, InputElement, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, List, Accordion, Field as Field$1, Popover, NumberInput, Show, RadioCard, CheckboxGroup, Center, Heading } from '@chakra-ui/react';
3
3
  import { AiOutlineColumnWidth } from 'react-icons/ai';
4
4
  import * as React from 'react';
5
5
  import React__default, { createContext, useContext, useState, useEffect, useRef } from 'react';
6
- import { MdFilterAlt, MdArrowUpward, MdArrowDownward, MdOutlineMoveDown, MdOutlineSort, MdSearch, MdClose, MdOutlineViewColumn, MdFilterListAlt, MdPushPin, MdCancel, MdClear, MdOutlineChecklist } from 'react-icons/md';
7
6
  import { LuX, LuCheck, LuChevronRight, LuChevronDown } from 'react-icons/lu';
8
- import Dayzed from '@bsol-oss/dayzed-react19';
7
+ import { MdOutlineSort, MdFilterAlt, MdSearch, MdClose, MdOutlineViewColumn, MdFilterListAlt, MdPushPin, MdCancel, MdClear, MdOutlineChecklist } from 'react-icons/md';
9
8
  import { FaUpDown, FaGripLinesVertical } from 'react-icons/fa6';
10
9
  import { BiDownArrow, BiUpArrow, BiError } from 'react-icons/bi';
11
10
  import { CgClose } from 'react-icons/cg';
11
+ import Dayzed from '@bsol-oss/dayzed-react19';
12
+ import { HiMiniEllipsisHorizontal, HiChevronLeft, HiChevronRight } from 'react-icons/hi2';
12
13
  import { IoMdEye, IoMdCheckbox } from 'react-icons/io';
13
14
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
14
15
  import { bind, bindAll } from 'bind-event-listener';
@@ -16,7 +17,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
16
17
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
17
18
  import rafSchd from 'raf-schd';
18
19
  import invariant from 'tiny-invariant';
19
- import { HiMiniEllipsisHorizontal, HiChevronLeft, HiChevronRight } from 'react-icons/hi2';
20
+ import { HiColorSwatch } from 'react-icons/hi';
20
21
  import { flexRender, makeStateUpdater, functionalUpdate, useReactTable, getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, createColumnHelper } from '@tanstack/react-table';
21
22
  import { rankItem } from '@tanstack/match-sorter-utils';
22
23
  import { BsExclamationCircleFill } from 'react-icons/bs';
@@ -24,10 +25,9 @@ import { useDebounce } from '@uidotdev/usehooks';
24
25
  import { useQueryClient, useQuery } from '@tanstack/react-query';
25
26
  import { IoReload } from 'react-icons/io5';
26
27
  import { GrAscend, GrDescend } from 'react-icons/gr';
27
- import { HiColorSwatch } from 'react-icons/hi';
28
28
  import { useTranslation } from 'react-i18next';
29
29
  import axios from 'axios';
30
- import { useFormContext, FormProvider, useForm as useForm$1 } from 'react-hook-form';
30
+ import { FormProvider, useFormContext, useForm as useForm$1 } from 'react-hook-form';
31
31
  import dayjs from 'dayjs';
32
32
  import { TiDeleteOutline } from 'react-icons/ti';
33
33
 
@@ -78,6 +78,32 @@ Dialog.Description;
78
78
  const DialogTrigger = Dialog.Trigger;
79
79
  Dialog.ActionTrigger;
80
80
 
81
+ const TableSorter = () => {
82
+ const { table } = useDataTableContext();
83
+ return (jsx(Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsx(Fragment, { children: headerGroup.headers.map((header) => {
84
+ const displayName = header.column.columnDef.meta === undefined
85
+ ? header.column.id
86
+ : header.column.columnDef.meta.displayName;
87
+ return (jsx(Fragment, { children: header.column.getCanSort() && (jsxs(Flex, { alignItems: "center", gap: "0.5rem", padding: "0.5rem", children: [jsx(Text, { children: displayName }), jsxs(Button$1, { variant: "ghost", onClick: () => {
88
+ header.column.toggleSorting();
89
+ }, children: [header.column.getIsSorted() === false && jsx(FaUpDown, {}), header.column.getIsSorted() === "asc" && jsx(BiDownArrow, {}), header.column.getIsSorted() === "desc" && jsx(BiUpArrow, {})] }), header.column.getIsSorted() && (jsx(Button$1, { onClick: () => {
90
+ header.column.clearSorting();
91
+ }, children: jsx(CgClose, {}) }))] })) }));
92
+ }) }))) }));
93
+ };
94
+
95
+ const ResetSortingButton = ({ text = "Reset Sorting", }) => {
96
+ const { table } = useDataTableContext();
97
+ return (jsx(Button$1, { onClick: () => {
98
+ table.resetSorting();
99
+ }, children: text }));
100
+ };
101
+
102
+ const EditSortingButton = ({ text, icon = jsx(MdOutlineSort, {}), title = "Edit Sorting", }) => {
103
+ const sortingModal = useDisclosure();
104
+ return (jsx(Fragment, { children: jsxs(DialogRoot, { size: ["full", "full", "md", "md"], children: [jsx(DialogBackdrop, {}), jsx(DialogTrigger, { children: jsxs(Button$1, { as: "div", variant: "ghost", onClick: sortingModal.onOpen, children: [icon, " ", text] }) }), jsxs(DialogContent, { children: [jsx(DialogCloseTrigger, {}), jsxs(DialogHeader, { children: [jsx(DialogTitle, {}), title] }), jsx(DialogBody, { children: jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(TableSorter, {}), jsx(ResetSortingButton, {})] }) }), jsx(DialogFooter, {})] })] }) }));
105
+ };
106
+
81
107
  const Radio = React.forwardRef(function Radio(props, ref) {
82
108
  const { children, inputProps, rootRef, ...rest } = props;
83
109
  return (jsxs(RadioGroup$1.Item, { ref: rootRef, ...rest, children: [jsx(RadioGroup$1.ItemHiddenInput, { ref: ref, ...inputProps }), jsx(RadioGroup$1.ItemIndicator, {}), children && (jsx(RadioGroup$1.ItemText, { children: children }))] }));
@@ -360,87 +386,138 @@ const FilterDialog = ({ icon = jsx(MdFilterAlt, {}), }) => {
360
386
  return (jsxs(DialogRoot, { size: ["full", "full", "md", "md"], open: filterModal.open, children: [jsx(DialogTrigger, { asChild: true, children: jsxs(Button$1, { as: Box, variant: "ghost", onClick: filterModal.onOpen, children: [icon, " ", translate.t("filterDialog.buttonText")] }) }), jsxs(DialogContent, { children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: translate.t("filterDialog.title") }) }), jsx(DialogBody, { display: "flex", flexFlow: "column", children: jsx(TableFilter, {}) }), jsxs(DialogFooter, { children: [jsx(ResetFilteringButton, { text: translate.t("filterDialog.reset") }), jsx(Button$1, { onClick: filterModal.onClose, variant: "subtle", children: translate.t("filterDialog.close") })] }), jsx(DialogCloseTrigger, { onClick: filterModal.onClose })] })] }));
361
387
  };
362
388
 
363
- const ColumnOrderChanger = ({ columns }) => {
364
- const [order, setOrder] = useState([]);
365
- const [originalOrder, setOriginalOrder] = useState([]);
366
- const { table } = useDataTableContext();
367
- const handleChangeOrder = (startIndex, endIndex) => {
368
- const newOrder = Array.from(order);
369
- const [removed] = newOrder.splice(startIndex, 1);
370
- newOrder.splice(endIndex, 0, removed);
371
- setOrder(newOrder);
372
- };
373
- useEffect(() => {
374
- setOrder(columns);
375
- }, [columns]);
376
- useEffect(() => {
377
- if (originalOrder.length > 0) {
378
- return;
379
- }
380
- if (columns.length <= 0) {
381
- return;
382
- }
383
- setOriginalOrder(columns);
384
- }, [columns]);
385
- return (jsxs(Flex, { gap: 2, flexFlow: "column", children: [jsx(Flex, { gap: 2, flexFlow: "column", children: order.map((columnId, index) => (jsxs(Flex, { gap: 2, alignItems: "center", justifyContent: "space-between", children: [jsx(IconButton, { onClick: () => {
386
- const prevIndex = index - 1;
387
- if (prevIndex >= 0) {
388
- handleChangeOrder(index, prevIndex);
389
- }
390
- }, disabled: index === 0, "aria-label": "", children: jsx(MdArrowUpward, {}) }), table
391
- .getAllFlatColumns()
392
- .filter((column) => {
393
- return column.id === columnId;
394
- })
395
- .map((column) => {
396
- const displayName = column.columnDef.meta === undefined
397
- ? column.id
398
- : column.columnDef.meta.displayName;
399
- return jsx("span", { children: displayName }, column.id);
400
- }), jsx(IconButton, { onClick: () => {
401
- const nextIndex = index + 1;
402
- if (nextIndex < order.length) {
403
- handleChangeOrder(index, nextIndex);
404
- }
405
- }, disabled: index === order.length - 1, "aria-label": "", children: jsx(MdArrowDownward, {}) })] }, columnId))) }), jsxs(Flex, { gap: "0.25rem", children: [jsx(Button$1, { onClick: () => {
406
- table.setColumnOrder(order);
407
- }, children: "Apply" }), jsx(Button$1, { onClick: () => {
408
- table.setColumnOrder(originalOrder);
409
- }, children: "Reset" })] })] }));
410
- };
411
- const TableOrderer = () => {
389
+ const MenuContent = React.forwardRef(function MenuContent(props, ref) {
390
+ const { portalled = true, portalRef, ...rest } = props;
391
+ return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(Menu.Positioner, { children: jsx(Menu.Content, { ref: ref, ...rest }) }) }));
392
+ });
393
+ React.forwardRef(function MenuArrow(props, ref) {
394
+ return (jsx(Menu.Arrow, { ref: ref, ...props, children: jsx(Menu.ArrowTip, {}) }));
395
+ });
396
+ React.forwardRef(function MenuCheckboxItem(props, ref) {
397
+ return (jsxs(Menu.CheckboxItem, { ref: ref, ...props, children: [jsx(Menu.ItemIndicator, { hidden: false, children: jsx(LuCheck, {}) }), props.children] }));
398
+ });
399
+ React.forwardRef(function MenuRadioItem(props, ref) {
400
+ const { children, ...rest } = props;
401
+ return (jsxs(Menu.RadioItem, { ps: "8", ref: ref, ...rest, children: [jsx(AbsoluteCenter, { axis: "horizontal", left: "4", asChild: true, children: jsx(Menu.ItemIndicator, { children: jsx(LuCheck, {}) }) }), jsx(Menu.ItemText, { children: children })] }));
402
+ });
403
+ React.forwardRef(function MenuItemGroup(props, ref) {
404
+ const { title, children, ...rest } = props;
405
+ return (jsxs(Menu.ItemGroup, { ref: ref, ...rest, children: [title && (jsx(Menu.ItemGroupLabel, { userSelect: "none", children: title })), children] }));
406
+ });
407
+ React.forwardRef(function MenuTriggerItem(props, ref) {
408
+ const { startIcon, children, ...rest } = props;
409
+ return (jsxs(Menu.TriggerItem, { ref: ref, ...rest, children: [startIcon, children, jsx(LuChevronRight, {})] }));
410
+ });
411
+ Menu.RadioItemGroup;
412
+ Menu.ContextTrigger;
413
+ const MenuRoot = Menu.Root;
414
+ Menu.Separator;
415
+ const MenuItem = Menu.Item;
416
+ Menu.ItemText;
417
+ Menu.ItemCommand;
418
+ const MenuTrigger = Menu.Trigger;
419
+
420
+ const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
412
421
  const { table } = useDataTableContext();
413
- return (jsx(Fragment, { children: jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
422
+ return (jsxs(MenuRoot, { children: [jsx(MenuTrigger, { asChild: true, children: jsxs(Button$1, { variant: "ghost", gap: "0.5rem", children: [table.getState().pagination.pageSize, " ", jsx(BiDownArrow, {})] }) }), jsx(MenuContent, { children: pageSizes.map((pageSize) => (jsx(MenuItem, { value: `chakra-table-pageSize-${pageSize}`, onClick: () => {
423
+ table.setPageSize(Number(pageSize));
424
+ }, children: pageSize }, `chakra-table-pageSize-${pageSize}`))) })] }));
414
425
  };
415
426
 
416
- const EditOrderButton = ({ text, icon = jsx(MdOutlineMoveDown, {}), title = "Change Order", }) => {
417
- return (jsx(Fragment, { children: jsxs(DialogRoot, { size: "cover", children: [jsx(DialogBackdrop, {}), jsx(DialogTrigger, { asChild: true, children: jsxs(Button$1, { as: Box, variant: "ghost", children: [icon, " ", text] }) }), jsxs(DialogContent, { children: [jsx(DialogCloseTrigger, {}), jsxs(DialogHeader, { children: [jsx(DialogTitle, {}), title] }), jsx(DialogBody, { children: jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: jsx(TableOrderer, {}) }) }), jsx(DialogFooter, {})] })] }) }));
427
+ const { withContext } = createRecipeContext({ key: "button" });
428
+ // Replace "a" with your framework's link component
429
+ const LinkButton = withContext("a");
430
+
431
+ const [RootPropsProvider, useRootProps] = createContext$1({
432
+ name: "RootPropsProvider",
433
+ });
434
+ const variantMap = {
435
+ outline: { default: "ghost", ellipsis: "plain", current: "outline" },
436
+ solid: { default: "outline", ellipsis: "outline", current: "solid" },
437
+ subtle: { default: "ghost", ellipsis: "plain", current: "subtle" },
418
438
  };
439
+ const PaginationRoot = React.forwardRef(function PaginationRoot(props, ref) {
440
+ const { size = "sm", variant = "outline", getHref, ...rest } = props;
441
+ return (jsx(RootPropsProvider, { value: { size, variantMap: variantMap[variant], getHref }, children: jsx(Pagination$1.Root, { ref: ref, type: getHref ? "link" : "button", ...rest }) }));
442
+ });
443
+ const PaginationEllipsis = React.forwardRef(function PaginationEllipsis(props, ref) {
444
+ const { size, variantMap } = useRootProps();
445
+ return (jsx(Pagination$1.Ellipsis, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { as: "span", variant: variantMap.ellipsis, size: size, children: jsx(HiMiniEllipsisHorizontal, {}) }) }));
446
+ });
447
+ const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
448
+ const { page } = usePaginationContext();
449
+ const { size, variantMap, getHref } = useRootProps();
450
+ const current = page === props.value;
451
+ const variant = current ? variantMap.current : variantMap.default;
452
+ if (getHref) {
453
+ return (jsx(LinkButton, { href: getHref(props.value), variant: variant, size: size, children: props.value }));
454
+ }
455
+ return (jsx(Pagination$1.Item, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { variant: variant, size: size, children: props.value }) }));
456
+ });
457
+ const PaginationPrevTrigger = React.forwardRef(function PaginationPrevTrigger(props, ref) {
458
+ const { size, variantMap, getHref } = useRootProps();
459
+ const { previousPage } = usePaginationContext();
460
+ if (getHref) {
461
+ return (jsx(LinkButton, { href: previousPage != null ? getHref(previousPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }));
462
+ }
463
+ return (jsx(Pagination$1.PrevTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }) }));
464
+ });
465
+ const PaginationNextTrigger = React.forwardRef(function PaginationNextTrigger(props, ref) {
466
+ const { size, variantMap, getHref } = useRootProps();
467
+ const { nextPage } = usePaginationContext();
468
+ if (getHref) {
469
+ return (jsx(LinkButton, { href: nextPage != null ? getHref(nextPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }));
470
+ }
471
+ return (jsx(Pagination$1.NextTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }) }));
472
+ });
473
+ const PaginationItems = (props) => {
474
+ return (jsx(Pagination$1.Context, { children: ({ pages }) => pages.map((page, index) => {
475
+ return page.type === "ellipsis" ? (jsx(PaginationEllipsis, { index: index, ...props }, index)) : (jsx(PaginationItem, { type: "page", value: page.value, ...props }, index));
476
+ }) }));
477
+ };
478
+ const PaginationPageText = React.forwardRef(function PaginationPageText(props, ref) {
479
+ const { format = "compact", ...rest } = props;
480
+ const { page, totalPages, pageRange, count } = usePaginationContext();
481
+ const content = React.useMemo(() => {
482
+ if (format === "short")
483
+ return `${page} / ${totalPages}`;
484
+ if (format === "compact")
485
+ return `${page} / ${totalPages}`;
486
+ return `${pageRange.start + 1} - ${Math.min(pageRange.end, count)} / ${count}`;
487
+ }, [format, page, totalPages, pageRange, count]);
488
+ return (jsx(Text, { fontWeight: "medium", ref: ref, ...rest, children: content }));
489
+ });
419
490
 
420
- const TableSorter = () => {
421
- const { table } = useDataTableContext();
422
- return (jsx(Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsx(Fragment, { children: headerGroup.headers.map((header) => {
423
- const displayName = header.column.columnDef.meta === undefined
424
- ? header.column.id
425
- : header.column.columnDef.meta.displayName;
426
- return (jsx(Fragment, { children: header.column.getCanSort() && (jsxs(Flex, { alignItems: "center", gap: "0.5rem", padding: "0.5rem", children: [jsx(Text, { children: displayName }), jsxs(Button$1, { variant: "ghost", onClick: () => {
427
- header.column.toggleSorting();
428
- }, children: [header.column.getIsSorted() === false && jsx(FaUpDown, {}), header.column.getIsSorted() === "asc" && jsx(BiDownArrow, {}), header.column.getIsSorted() === "desc" && jsx(BiUpArrow, {})] }), header.column.getIsSorted() && (jsx(Button$1, { onClick: () => {
429
- header.column.clearSorting();
430
- }, children: jsx(CgClose, {}) }))] })) }));
431
- }) }))) }));
491
+ // TODO: not working in client side
492
+ const Pagination = () => {
493
+ const { table, type } = useDataTableContext();
494
+ const getCount = () => {
495
+ if (type === "client") {
496
+ return table.getFilteredRowModel().flatRows.length ?? 0;
497
+ }
498
+ return table.getRowCount();
499
+ };
500
+ return (jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: getCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
501
+ table.setPageIndex(e.page - 1);
502
+ }, children: jsxs(HStack, { children: [jsx(PaginationPrevTrigger, {}), jsx(PaginationItems, {}), jsx(PaginationNextTrigger, {})] }) }));
432
503
  };
433
504
 
434
- const ResetSortingButton = ({ text = "Reset Sorting", }) => {
505
+ const ResetSelectionButton = ({ text = "Reset Selection", }) => {
435
506
  const { table } = useDataTableContext();
436
507
  return (jsx(Button$1, { onClick: () => {
437
- table.resetSorting();
508
+ table.resetRowSelection();
438
509
  }, children: text }));
439
510
  };
440
511
 
441
- const EditSortingButton = ({ text, icon = jsx(MdOutlineSort, {}), title = "Edit Sorting", }) => {
442
- const sortingModal = useDisclosure();
443
- return (jsx(Fragment, { children: jsxs(DialogRoot, { size: ["full", "full", "md", "md"], children: [jsx(DialogBackdrop, {}), jsx(DialogTrigger, { children: jsxs(Button$1, { as: "div", variant: "ghost", onClick: sortingModal.onOpen, children: [icon, " ", text] }) }), jsxs(DialogContent, { children: [jsx(DialogCloseTrigger, {}), jsxs(DialogHeader, { children: [jsx(DialogTitle, {}), title] }), jsx(DialogBody, { children: jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(TableSorter, {}), jsx(ResetSortingButton, {})] }) }), jsx(DialogFooter, {})] })] }) }));
512
+ const RowCountText = () => {
513
+ const { table, type } = useDataTableContext();
514
+ const getCount = () => {
515
+ if (type === "client") {
516
+ return table.getFilteredRowModel().flatRows.length ?? 0;
517
+ }
518
+ return table.getRowCount();
519
+ };
520
+ return jsx(Text, { children: getCount() });
444
521
  };
445
522
 
446
523
  // pulling this into a separate file so adapter(s) that don't
@@ -2360,13 +2437,16 @@ function ColumnCard({ columnId }) {
2360
2437
  onDrop: () => setDragging(false), // NEW
2361
2438
  });
2362
2439
  }, [columnId, table]);
2363
- return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", cursor: 'grab', children: jsx(FaGripLinesVertical, { color: "gray.400" }) }), jsx(Flex, { justifyContent: "space-between", alignItems: "center", children: jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
2440
+ return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", cursor: "grab", children: jsx(FaGripLinesVertical, { color: "gray.400" }) }), jsx(Flex, { justifyContent: "space-between", alignItems: "center", children: jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
2364
2441
  }
2365
2442
  function CardContainer({ location, children }) {
2366
2443
  const ref = useRef(null);
2367
2444
  const [isDraggedOver, setIsDraggedOver] = useState(false);
2368
2445
  useEffect(() => {
2369
2446
  const el = ref.current;
2447
+ if (el === null) {
2448
+ return;
2449
+ }
2370
2450
  invariant(el);
2371
2451
  return dropTargetForElements({
2372
2452
  element: el,
@@ -2441,146 +2521,34 @@ const ViewDialog = ({ icon = jsx(IoMdEye, {}) }) => {
2441
2521
  return (jsxs(DialogRoot, { children: [jsx(DialogBackdrop, {}), jsx(DialogTrigger, { asChild: true, children: jsxs(Button$1, { as: Box, variant: "ghost", onClick: viewModel.onOpen, children: [icon, " ", translate.t("viewDialog.buttonText")] }) }), jsxs(DialogContent, { children: [jsx(DialogCloseTrigger, {}), jsx(DialogHeader, { children: jsx(DialogTitle, { children: translate.t("viewDialog.title") }) }), jsx(DialogBody, { children: jsx(TableViewer, {}) }), jsx(DialogFooter, {})] })] }));
2442
2522
  };
2443
2523
 
2444
- const MenuContent = React.forwardRef(function MenuContent(props, ref) {
2445
- const { portalled = true, portalRef, ...rest } = props;
2446
- return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(Menu.Positioner, { children: jsx(Menu.Content, { ref: ref, ...rest }) }) }));
2447
- });
2448
- React.forwardRef(function MenuArrow(props, ref) {
2449
- return (jsx(Menu.Arrow, { ref: ref, ...props, children: jsx(Menu.ArrowTip, {}) }));
2450
- });
2451
- React.forwardRef(function MenuCheckboxItem(props, ref) {
2452
- return (jsxs(Menu.CheckboxItem, { ref: ref, ...props, children: [jsx(Menu.ItemIndicator, { hidden: false, children: jsx(LuCheck, {}) }), props.children] }));
2453
- });
2454
- React.forwardRef(function MenuRadioItem(props, ref) {
2455
- const { children, ...rest } = props;
2456
- return (jsxs(Menu.RadioItem, { ps: "8", ref: ref, ...rest, children: [jsx(AbsoluteCenter, { axis: "horizontal", left: "4", asChild: true, children: jsx(Menu.ItemIndicator, { children: jsx(LuCheck, {}) }) }), jsx(Menu.ItemText, { children: children })] }));
2457
- });
2458
- React.forwardRef(function MenuItemGroup(props, ref) {
2459
- const { title, children, ...rest } = props;
2460
- return (jsxs(Menu.ItemGroup, { ref: ref, ...rest, children: [title && (jsx(Menu.ItemGroupLabel, { userSelect: "none", children: title })), children] }));
2461
- });
2462
- React.forwardRef(function MenuTriggerItem(props, ref) {
2463
- const { startIcon, children, ...rest } = props;
2464
- return (jsxs(Menu.TriggerItem, { ref: ref, ...rest, children: [startIcon, children, jsx(LuChevronRight, {})] }));
2465
- });
2466
- Menu.RadioItemGroup;
2467
- Menu.ContextTrigger;
2468
- const MenuRoot = Menu.Root;
2469
- Menu.Separator;
2470
- const MenuItem = Menu.Item;
2471
- Menu.ItemText;
2472
- Menu.ItemCommand;
2473
- const MenuTrigger = Menu.Trigger;
2474
-
2475
- const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
2476
- const { table } = useDataTableContext();
2477
- return (jsxs(MenuRoot, { children: [jsx(MenuTrigger, { asChild: true, children: jsxs(Button$1, { variant: "ghost", gap: "0.5rem", children: [table.getState().pagination.pageSize, " ", jsx(BiDownArrow, {})] }) }), jsx(MenuContent, { children: pageSizes.map((pageSize) => (jsx(MenuItem, { value: `chakra-table-pageSize-${pageSize}`, onClick: () => {
2478
- table.setPageSize(Number(pageSize));
2479
- }, children: pageSize }, `chakra-table-pageSize-${pageSize}`))) })] }));
2480
- };
2481
-
2482
- const ResetSelectionButton = ({ text = "Reset Selection", }) => {
2483
- const { table } = useDataTableContext();
2484
- return (jsx(Button$1, { onClick: () => {
2485
- table.resetRowSelection();
2486
- }, children: text }));
2487
- };
2488
-
2489
- const RowCountText = () => {
2490
- const { table, type } = useDataTableContext();
2491
- const getCount = () => {
2492
- if (type === "client") {
2493
- return table.getFilteredRowModel().flatRows.length ?? 0;
2494
- }
2495
- return table.getRowCount();
2496
- };
2497
- return jsx(Text, { children: getCount() });
2524
+ const CardHeader = ({ row, imageColumnId = undefined, titleColumnId = undefined, tagColumnId = undefined, tagIcon = undefined, showTag = true, imageProps = {}, }) => {
2525
+ if (!!row.original === false) {
2526
+ return jsx(Fragment, {});
2527
+ }
2528
+ const isShowFirstColumn = !!titleColumnId || showTag;
2529
+ return (jsxs(Grid, { templateRows: "auto auto", gap: "1rem", children: [!!imageColumnId && (jsx(Image, { width: "100%", src: row.original[imageColumnId], ...imageProps })), isShowFirstColumn && (jsxs(Flex, { gap: "0.5rem", flexFlow: "wrap", children: [!!titleColumnId && (jsx(Text, { fontWeight: "bold", fontSize: "large", children: row.original[titleColumnId] })), showTag && (jsx(Tag, { fontSize: "large", startElement: tagIcon && tagIcon({}), children: row.original[tagColumnId] }))] }))] }));
2498
2530
  };
2499
2531
 
2500
- const { withContext } = createRecipeContext({ key: "button" });
2501
- // Replace "a" with your framework's link component
2502
- const LinkButton = withContext("a");
2503
-
2504
- const [RootPropsProvider, useRootProps] = createContext$1({
2505
- name: "RootPropsProvider",
2506
- });
2507
- const variantMap = {
2508
- outline: { default: "ghost", ellipsis: "plain", current: "outline" },
2509
- solid: { default: "outline", ellipsis: "outline", current: "solid" },
2510
- subtle: { default: "ghost", ellipsis: "plain", current: "subtle" },
2511
- };
2512
- const PaginationRoot = React.forwardRef(function PaginationRoot(props, ref) {
2513
- const { size = "sm", variant = "outline", getHref, ...rest } = props;
2514
- return (jsx(RootPropsProvider, { value: { size, variantMap: variantMap[variant], getHref }, children: jsx(Pagination$1.Root, { ref: ref, type: getHref ? "link" : "button", ...rest }) }));
2515
- });
2516
- const PaginationEllipsis = React.forwardRef(function PaginationEllipsis(props, ref) {
2517
- const { size, variantMap } = useRootProps();
2518
- return (jsx(Pagination$1.Ellipsis, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { as: "span", variant: variantMap.ellipsis, size: size, children: jsx(HiMiniEllipsisHorizontal, {}) }) }));
2519
- });
2520
- const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
2521
- const { page } = usePaginationContext();
2522
- const { size, variantMap, getHref } = useRootProps();
2523
- const current = page === props.value;
2524
- const variant = current ? variantMap.current : variantMap.default;
2525
- if (getHref) {
2526
- return (jsx(LinkButton, { href: getHref(props.value), variant: variant, size: size, children: props.value }));
2527
- }
2528
- return (jsx(Pagination$1.Item, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { variant: variant, size: size, children: props.value }) }));
2529
- });
2530
- const PaginationPrevTrigger = React.forwardRef(function PaginationPrevTrigger(props, ref) {
2531
- const { size, variantMap, getHref } = useRootProps();
2532
- const { previousPage } = usePaginationContext();
2533
- if (getHref) {
2534
- return (jsx(LinkButton, { href: previousPage != null ? getHref(previousPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }));
2535
- }
2536
- return (jsx(Pagination$1.PrevTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }) }));
2537
- });
2538
- const PaginationNextTrigger = React.forwardRef(function PaginationNextTrigger(props, ref) {
2539
- const { size, variantMap, getHref } = useRootProps();
2540
- const { nextPage } = usePaginationContext();
2541
- if (getHref) {
2542
- return (jsx(LinkButton, { href: nextPage != null ? getHref(nextPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }));
2543
- }
2544
- return (jsx(Pagination$1.NextTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }) }));
2532
+ const DataTableServerContext = createContext({
2533
+ url: "",
2545
2534
  });
2546
- const PaginationItems = (props) => {
2547
- return (jsx(Pagination$1.Context, { children: ({ pages }) => pages.map((page, index) => {
2548
- return page.type === "ellipsis" ? (jsx(PaginationEllipsis, { index: index, ...props }, index)) : (jsx(PaginationItem, { type: "page", value: page.value, ...props }, index));
2549
- }) }));
2535
+
2536
+ const useDataTableServerContext = () => {
2537
+ const context = useContext(DataTableServerContext);
2538
+ const { query } = context;
2539
+ const isEmpty = (query.data?.count ?? 0) <= 0;
2540
+ return { ...context, isEmpty };
2550
2541
  };
2551
- const PaginationPageText = React.forwardRef(function PaginationPageText(props, ref) {
2552
- const { format = "compact", ...rest } = props;
2553
- const { page, totalPages, pageRange, count } = usePaginationContext();
2554
- const content = React.useMemo(() => {
2555
- if (format === "short")
2556
- return `${page} / ${totalPages}`;
2557
- if (format === "compact")
2558
- return `${page} / ${totalPages}`;
2559
- return `${pageRange.start + 1} - ${Math.min(pageRange.end, count)} / ${count}`;
2560
- }, [format, page, totalPages, pageRange, count]);
2561
- return (jsx(Text, { fontWeight: "medium", ref: ref, ...rest, children: content }));
2562
- });
2563
2542
 
2564
- // TODO: not working in client side
2565
- const Pagination = () => {
2566
- const { table, type } = useDataTableContext();
2567
- const getCount = () => {
2568
- if (type === "client") {
2569
- return table.getFilteredRowModel().flatRows.length ?? 0;
2570
- }
2571
- return table.getRowCount();
2572
- };
2573
- return (jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: getCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
2574
- table.setPageIndex(e.page - 1);
2575
- }, children: jsxs(HStack, { children: [jsx(PaginationPrevTrigger, {}), jsx(PaginationItems, {}), jsx(PaginationNextTrigger, {})] }) }));
2543
+ const EmptyState$1 = ({ title = "No records", description = "Add a new events to get started or refine your search", }) => {
2544
+ const { isEmpty } = useDataTableServerContext();
2545
+ return (jsx(Fragment, { children: isEmpty && (jsx(EmptyState$2.Root, { children: jsxs(EmptyState$2.Content, { children: [jsx(EmptyState$2.Indicator, { children: jsx(HiColorSwatch, {}) }), jsxs(VStack, { textAlign: "center", children: [jsx(EmptyState$2.Title, { children: title }), jsx(EmptyState$2.Description, { children: description })] })] }) })) }));
2576
2546
  };
2577
2547
 
2578
- const CardHeader = ({ row, imageColumnId = undefined, titleColumnId = undefined, tagColumnId = undefined, tagIcon = undefined, showTag = true, imageProps = {}, }) => {
2579
- if (!!row.original === false) {
2580
- return jsx(Fragment, {});
2581
- }
2582
- const isShowFirstColumn = !!titleColumnId || showTag;
2583
- return (jsxs(Grid, { templateRows: "auto auto", gap: "1rem", children: [!!imageColumnId && (jsx(Image, { width: "100%", src: row.original[imageColumnId], ...imageProps })), isShowFirstColumn && (jsxs(Flex, { gap: "0.5rem", flexFlow: "wrap", children: [!!titleColumnId && (jsx(Text, { fontWeight: "bold", fontSize: "large", children: row.original[titleColumnId] })), showTag && (jsx(Tag, { fontSize: "large", startElement: tagIcon && tagIcon({}), children: row.original[tagColumnId] }))] }))] }));
2548
+ const ErrorAlert = ({ showMessage = true }) => {
2549
+ const { query } = useDataTableServerContext();
2550
+ const { isError, error } = query;
2551
+ return (jsx(Fragment, { children: isError && (jsxs(Alert.Root, { status: "error", children: [jsx(Alert.Indicator, {}), jsxs(Alert.Content, { children: [jsx(Alert.Title, { children: error.name }), showMessage && (jsx(Alert.Description, { children: error.message }))] })] })) }));
2584
2552
  };
2585
2553
 
2586
2554
  const snakeToLabel = (str) => {
@@ -2826,13 +2794,25 @@ function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSel
2826
2794
  setGlobalFilter,
2827
2795
  type: "client",
2828
2796
  translate,
2797
+ columns,
2798
+ sorting,
2799
+ setSorting,
2800
+ columnFilters,
2801
+ setColumnFilters,
2802
+ pagination,
2803
+ setPagination,
2804
+ rowSelection,
2805
+ setRowSelection,
2806
+ columnOrder,
2807
+ setColumnOrder,
2808
+ density,
2809
+ setDensity,
2810
+ columnVisibility,
2811
+ setColumnVisibility,
2812
+ data,
2829
2813
  }, children: children }));
2830
2814
  }
2831
2815
 
2832
- const DataTableServerContext = createContext({
2833
- url: "",
2834
- });
2835
-
2836
2816
  /**
2837
2817
  * DataTableServer will create a context to hold all values to
2838
2818
  * help the render of the DataTable in serverside
@@ -2898,6 +2878,22 @@ function DataTableServer({ columns, enableRowSelection = true, enableMultiRowSel
2898
2878
  setGlobalFilter,
2899
2879
  type: "server",
2900
2880
  translate,
2881
+ columns,
2882
+ sorting,
2883
+ setSorting,
2884
+ columnFilters,
2885
+ setColumnFilters,
2886
+ pagination,
2887
+ setPagination,
2888
+ rowSelection,
2889
+ setRowSelection,
2890
+ columnOrder,
2891
+ setColumnOrder,
2892
+ density,
2893
+ setDensity,
2894
+ columnVisibility,
2895
+ setColumnVisibility,
2896
+ data: query.data?.data ?? [],
2901
2897
  }, children: jsx(DataTableServerContext.Provider, { value: { url, query }, children: children }) }));
2902
2898
  }
2903
2899
 
@@ -2907,6 +2903,7 @@ const Checkbox = React.forwardRef(function Checkbox(props, ref) {
2907
2903
  });
2908
2904
 
2909
2905
  const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, canResize = true, }) => {
2906
+ "use no memo";
2910
2907
  const { table } = useDataTableContext();
2911
2908
  const SELECTION_BOX_WIDTH = 20;
2912
2909
  const [hoveredRow, setHoveredRow] = useState(-1);
@@ -3016,13 +3013,6 @@ const GlobalFilter = () => {
3016
3013
  } }) }) }));
3017
3014
  };
3018
3015
 
3019
- const useDataTableServerContext = () => {
3020
- const context = useContext(DataTableServerContext);
3021
- const { query } = context;
3022
- const isEmpty = (query.data?.count ?? 0) <= 0;
3023
- return { ...context, isEmpty };
3024
- };
3025
-
3026
3016
  const ReloadButton = ({ text = "Reload", variant = "icon", }) => {
3027
3017
  const { url } = useDataTableServerContext();
3028
3018
  const queryClient = useQueryClient();
@@ -3236,12 +3226,12 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
3236
3226
  })] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
3237
3227
  };
3238
3228
 
3239
- const EmptyState$1 = React.forwardRef(function EmptyState(props, ref) {
3229
+ const EmptyState = React.forwardRef(function EmptyState(props, ref) {
3240
3230
  const { title, description, icon, children, ...rest } = props;
3241
3231
  return (jsx(EmptyState$2.Root, { ref: ref, ...rest, children: jsxs(EmptyState$2.Content, { children: [icon && (jsx(EmptyState$2.Indicator, { children: icon })), description ? (jsxs(VStack, { textAlign: "center", children: [jsx(EmptyState$2.Title, { children: title }), jsx(EmptyState$2.Description, { children: description })] })) : (jsx(EmptyState$2.Title, { children: title })), children] }) }));
3242
3232
  });
3243
3233
 
3244
- const EmptyResult = (jsx(EmptyState$1, { icon: jsx(HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxs(List.Root, { variant: "marker", children: [jsx(List.Item, { children: "Try removing filters" }), jsx(List.Item, { children: "Try different keywords" })] }) }));
3234
+ const EmptyResult = (jsx(EmptyState, { icon: jsx(HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxs(List.Root, { variant: "marker", children: [jsx(List.Item, { children: "Try removing filters" }), jsx(List.Item, { children: "Try different keywords" })] }) }));
3245
3235
  const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
3246
3236
  const { table } = useDataTableContext();
3247
3237
  if (table.getRowModel().rows.length <= 0) {
@@ -3510,16 +3500,78 @@ const getColumns = ({ schema, include = [], ignore = [], width = [], meta = {},
3510
3500
  return columns;
3511
3501
  };
3512
3502
 
3513
- const EmptyState = ({ title = "No records", description = "Add a new events to get started or refine your search", }) => {
3514
- const { isEmpty } = useDataTableServerContext();
3515
- return (jsx(Fragment, { children: isEmpty && (jsx(EmptyState$2.Root, { children: jsxs(EmptyState$2.Content, { children: [jsx(EmptyState$2.Indicator, { children: jsx(HiColorSwatch, {}) }), jsxs(VStack, { textAlign: "center", children: [jsx(EmptyState$2.Title, { children: title }), jsx(EmptyState$2.Description, { children: description })] })] }) })) }));
3503
+ const TableDataDisplay = ({ colorPalette, emptyComponent, }) => {
3504
+ const { table, columns, translate, data } = useDataTableContext();
3505
+ const columnDef = table._getColumnDefs();
3506
+ console.log(columnDef, "glp");
3507
+ console.log(columnDef, columns, table.getState().columnOrder, data, "glp");
3508
+ const columnsMap = Object.fromEntries(columns.map((def) => {
3509
+ const { accessorKey, id } = def;
3510
+ if (accessorKey) {
3511
+ return [accessorKey, def];
3512
+ }
3513
+ return [id, def];
3514
+ }));
3515
+ const columnHeaders = Object.keys(columnsMap);
3516
+ const totalWidths = columns
3517
+ .map(({ size }) => {
3518
+ if (!!size === false) {
3519
+ return 0;
3520
+ }
3521
+ if (typeof size === "number") {
3522
+ return size;
3523
+ }
3524
+ return 0;
3525
+ })
3526
+ .reduce((previous, current) => previous + current, 0);
3527
+ const columnWidths = columns
3528
+ .map(({ size }) => {
3529
+ if (!!size === false) {
3530
+ return "1fr";
3531
+ }
3532
+ return `minmax(${size}px, ${(size / totalWidths) * 100}%)`;
3533
+ })
3534
+ .join(" ");
3535
+ console.log({ columnWidths }, "hadfg");
3536
+ const cellProps = {
3537
+ flex: "1 0 0%",
3538
+ overflow: "auto",
3539
+ paddingX: "2",
3540
+ py: "1",
3541
+ borderBottomColor: { base: "colorPalette.200", _dark: "colorPalette.800" },
3542
+ borderBottomWidth: "1px",
3543
+ ...{ colorPalette },
3544
+ };
3545
+ if (data.length <= 0) {
3546
+ return jsx(Fragment, { children: emptyComponent });
3547
+ }
3548
+ return (jsxs(Grid, { templateColumns: `${columnWidths}`, overflow: "auto", borderWidth: "1px", borderColor: { base: "colorPalette.200", _dark: "colorPalette.800" }, colorPalette, children: [jsx(Grid, { templateColumns: `${columnWidths}`, column: `1/span ${columns.length}`, bg: { base: "colorPalette.200", _dark: "colorPalette.800" }, colorPalette, children: columnHeaders.map((header) => {
3549
+ return (jsx(Box, { flex: "1 0 0%", paddingX: "2", py: "1", overflow: "auto", textOverflow: "ellipsis", children: translate.t(`column_header.${header}`) }));
3550
+ }) }), data.map((record) => {
3551
+ return (jsx(Fragment, { children: columnHeaders.map((header) => {
3552
+ if (!!record === false) {
3553
+ return (jsx(Box, { ...cellProps, children: translate.t(`column_cell.placeholder`) }));
3554
+ }
3555
+ if (!!record[header] === false) {
3556
+ return (jsx(Box, { ...cellProps, children: translate.t(`column_cell.placeholder`) }));
3557
+ }
3558
+ if (typeof record[header] === "object") {
3559
+ return (jsx(Box, { ...cellProps, children: jsx(RecordDisplay, { object: record[header] }) }));
3560
+ }
3561
+ return jsx(Box, { ...cellProps, children: record[header] ?? "" });
3562
+ }) }));
3563
+ })] }));
3516
3564
  };
3517
3565
 
3518
- const ErrorAlert = ({ showMessage = true }) => {
3519
- const { query } = useDataTableServerContext();
3520
- const { isError, error } = query;
3521
- return (jsx(Fragment, { children: isError && (jsxs(Alert.Root, { status: "error", children: [jsx(Alert.Indicator, {}), jsxs(Alert.Content, { children: [jsx(Alert.Title, { children: error.name }), showMessage && (jsx(Alert.Description, { children: error.message }))] })] })) }));
3522
- };
3566
+ const AccordionItemTrigger = React.forwardRef(function AccordionItemTrigger(props, ref) {
3567
+ const { children, indicatorPlacement = "end", ...rest } = props;
3568
+ return (jsxs(Accordion.ItemTrigger, { ...rest, ref: ref, children: [indicatorPlacement === "start" && (jsx(Accordion.ItemIndicator, { rotate: { base: "-90deg", _open: "0deg" }, children: jsx(LuChevronDown, {}) })), jsx(HStack, { gap: "4", flex: "1", textAlign: "start", width: "full", children: children }), indicatorPlacement === "end" && (jsx(Accordion.ItemIndicator, { children: jsx(LuChevronDown, {}) }))] }));
3569
+ });
3570
+ const AccordionItemContent = React.forwardRef(function AccordionItemContent(props, ref) {
3571
+ return (jsx(Accordion.ItemContent, { children: jsx(Accordion.ItemBody, { ...props, ref: ref }) }));
3572
+ });
3573
+ const AccordionRoot = Accordion.Root;
3574
+ const AccordionItem = Accordion.Item;
3523
3575
 
3524
3576
  //@ts-expect-error TODO: find appropriate type
3525
3577
  const SchemaFormContext = createContext({
@@ -3542,15 +3594,56 @@ const clearEmptyString = (object) => {
3542
3594
  return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
3543
3595
  };
3544
3596
 
3545
- const AccordionItemTrigger = React.forwardRef(function AccordionItemTrigger(props, ref) {
3546
- const { children, indicatorPlacement = "end", ...rest } = props;
3547
- return (jsxs(Accordion.ItemTrigger, { ...rest, ref: ref, children: [indicatorPlacement === "start" && (jsx(Accordion.ItemIndicator, { rotate: { base: "-90deg", _open: "0deg" }, children: jsx(LuChevronDown, {}) })), jsx(HStack, { gap: "4", flex: "1", textAlign: "start", width: "full", children: children }), indicatorPlacement === "end" && (jsx(Accordion.ItemIndicator, { children: jsx(LuChevronDown, {}) }))] }));
3548
- });
3549
- const AccordionItemContent = React.forwardRef(function AccordionItemContent(props, ref) {
3550
- return (jsx(Accordion.ItemContent, { children: jsx(Accordion.ItemBody, { ...props, ref: ref }) }));
3551
- });
3552
- const AccordionRoot = Accordion.Root;
3553
- const AccordionItem = Accordion.Item;
3597
+ const idPickerSanityCheck = (column, foreign_key) => {
3598
+ if (!!foreign_key == false) {
3599
+ throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
3600
+ }
3601
+ const { table, column: foreignKeyColumn, display_column } = foreign_key;
3602
+ if (!!table == false) {
3603
+ throw new Error(`The key table does not exist in properties of column ${table} when using id-picker.`);
3604
+ }
3605
+ if (!!display_column == false) {
3606
+ throw new Error(`The key display_column does not exist in properties of column ${column} when using id-picker.`);
3607
+ }
3608
+ if (!!foreignKeyColumn == false) {
3609
+ throw new Error(`The key column does not exist in properties of column ${column} when using id-picker.`);
3610
+ }
3611
+ };
3612
+ const FormRoot = ({ schema, idMap, setIdMap, form, serverUrl, translate, children, order = [], ignore = [], include = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, getUpdatedData = () => { }, }) => {
3613
+ const [isSuccess, setIsSuccess] = useState(false);
3614
+ const [isError, setIsError] = useState(false);
3615
+ const [isSubmiting, setIsSubmiting] = useState(false);
3616
+ const [isConfirming, setIsConfirming] = useState(false);
3617
+ const [validatedData, setValidatedData] = useState();
3618
+ const [error, setError] = useState();
3619
+ return (jsx(SchemaFormContext.Provider, { value: {
3620
+ schema,
3621
+ serverUrl,
3622
+ order,
3623
+ ignore,
3624
+ include,
3625
+ // @ts-expect-error TODO: find appropriate types
3626
+ onSubmit,
3627
+ rowNumber,
3628
+ idMap,
3629
+ setIdMap,
3630
+ translate,
3631
+ requestOptions,
3632
+ isSuccess,
3633
+ setIsSuccess,
3634
+ isError,
3635
+ setIsError,
3636
+ isSubmiting,
3637
+ setIsSubmiting,
3638
+ isConfirming,
3639
+ setIsConfirming,
3640
+ validatedData,
3641
+ setValidatedData,
3642
+ error,
3643
+ setError,
3644
+ getUpdatedData,
3645
+ }, children: jsx(FormProvider, { ...form, children: children }) }));
3646
+ };
3554
3647
 
3555
3648
  function removeIndex(str) {
3556
3649
  return str.replace(/\.\d+\./g, '.');
@@ -3701,10 +3794,11 @@ const DatePicker = ({ column, schema, prefix }) => {
3701
3794
  const colLabel = `${prefix}${column}`;
3702
3795
  const [open, setOpen] = useState(false);
3703
3796
  const selectedDate = watch(colLabel);
3797
+ const formatedDate = dayjs(selectedDate).format("YYYY-MM-DD");
3704
3798
  return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
3705
3799
  gridRow, children: [jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsx(PopoverTrigger, { asChild: true, children: jsx(Button, { size: "sm", variant: "outline", onClick: () => {
3706
3800
  setOpen(true);
3707
- }, children: selectedDate !== undefined ? selectedDate : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
3801
+ }, children: selectedDate !== undefined ? `${formatedDate}` : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
3708
3802
  // @ts-expect-error TODO: find appropriate types
3709
3803
  , {
3710
3804
  // @ts-expect-error TODO: find appropriate types
@@ -4254,7 +4348,6 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4254
4348
  });
4255
4349
  return data;
4256
4350
  },
4257
- staleTime: 300000,
4258
4351
  });
4259
4352
  const onSearchChange = async (event) => {
4260
4353
  setSearchText(event.target.value);
@@ -4908,30 +5001,23 @@ const ColumnViewer = ({ column, properties, prefix, }) => {
4908
5001
  return jsx(SchemaViewer, { schema: colSchema, prefix, column });
4909
5002
  };
4910
5003
 
4911
- const idPickerSanityCheck = (column, foreign_key) => {
4912
- if (!!foreign_key == false) {
4913
- throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
4914
- }
4915
- const { table, column: foreignKeyColumn, display_column } = foreign_key;
4916
- if (!!table == false) {
4917
- throw new Error(`The key table does not exist in properties of column ${table} when using id-picker.`);
4918
- }
4919
- if (!!display_column == false) {
4920
- throw new Error(`The key display_column does not exist in properties of column ${column} when using id-picker.`);
4921
- }
4922
- if (!!foreignKeyColumn == false) {
4923
- throw new Error(`The key column does not exist in properties of column ${column} when using id-picker.`);
4924
- }
5004
+ const SubmitButton = () => {
5005
+ const { translate, setValidatedData, setIsError, setIsConfirming } = useSchemaContext();
5006
+ const methods = useFormContext();
5007
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5008
+ const onValid = (data) => {
5009
+ setValidatedData(data);
5010
+ setIsError(false);
5011
+ setIsConfirming(true);
5012
+ };
5013
+ return (jsx(Button$1, { onClick: () => {
5014
+ methods.handleSubmit(onValid)();
5015
+ }, formNoValidate: true, children: translate.t("submit") }));
4925
5016
  };
4926
- const FormInternal = () => {
4927
- const { schema, requestUrl, order, ignore, include, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
5017
+
5018
+ const FormBody = () => {
5019
+ const { schema, requestUrl, order, ignore, include, onSubmit, rowNumber, translate, requestOptions, isSuccess, setIsSuccess, isError, setIsError, isSubmiting, setIsSubmiting, isConfirming, setIsConfirming, validatedData, setValidatedData, error, setError, getUpdatedData, } = useSchemaContext();
4928
5020
  const methods = useFormContext();
4929
- const [isSuccess, setIsSuccess] = useState(false);
4930
- const [isError, setIsError] = useState(false);
4931
- const [isSubmiting, setIsSubmiting] = useState(false);
4932
- const [isConfirming, setIsConfirming] = useState(false);
4933
- const [validatedData, setValidatedData] = useState();
4934
- const [error, setError] = useState();
4935
5021
  const { properties } = schema;
4936
5022
  const onBeforeSubmit = () => {
4937
5023
  setIsSubmiting(true);
@@ -4939,8 +5025,9 @@ const FormInternal = () => {
4939
5025
  const onAfterSubmit = () => {
4940
5026
  setIsSubmiting(false);
4941
5027
  };
4942
- const onSubmitError = () => {
5028
+ const onSubmitError = (error) => {
4943
5029
  setIsError(true);
5030
+ setError(error);
4944
5031
  };
4945
5032
  const onSubmitSuccess = () => {
4946
5033
  setIsSuccess(true);
@@ -4952,9 +5039,7 @@ const FormInternal = () => {
4952
5039
  onSubmitSuccess();
4953
5040
  }
4954
5041
  catch (error) {
4955
- setIsError(true);
4956
- setError(error);
4957
- onSubmitError();
5042
+ onSubmitError(error);
4958
5043
  }
4959
5044
  finally {
4960
5045
  onAfterSubmit();
@@ -4977,12 +5062,6 @@ const FormInternal = () => {
4977
5062
  }
4978
5063
  await defaultOnSubmit(onSubmit(data));
4979
5064
  };
4980
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4981
- const onValid = (data) => {
4982
- setValidatedData(data);
4983
- setIsError(false);
4984
- setIsConfirming(true);
4985
- };
4986
5065
  const renderColumns = ({ order, keys, ignore, include, }) => {
4987
5066
  const included = include.length > 0 ? include : keys;
4988
5067
  const not_exist = included.filter((columnA) => !order.some((columnB) => columnA === columnB));
@@ -4997,58 +5076,47 @@ const FormInternal = () => {
4997
5076
  include,
4998
5077
  });
4999
5078
  if (isSuccess) {
5000
- return (jsxs(Grid, { gap: 2, children: [jsx(Heading, { children: translate.t("title") }), jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: translate.t("submitSuccess") })] }), jsx(Flex, { justifyContent: "end", children: jsx(Button, { onClick: () => {
5079
+ return (jsxs(Flex, { flexFlow: "column", gap: "2", children: [jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: translate.t("submitSuccess") })] }), jsx(Flex, { justifyContent: "end", children: jsx(Button$1, { onClick: async () => {
5001
5080
  setIsError(false);
5002
5081
  setIsSubmiting(false);
5003
5082
  setIsSuccess(false);
5004
5083
  setIsConfirming(false);
5005
5084
  setValidatedData(undefined);
5006
- methods.reset();
5085
+ const data = await getUpdatedData();
5086
+ methods.reset(data);
5007
5087
  }, formNoValidate: true, children: translate.t("submitAgain") }) })] }));
5008
5088
  }
5009
5089
  if (isConfirming) {
5010
- return (jsxs(Grid, { gap: 2, children: [jsxs(Heading, { children: [" ", translate.t("title")] }), jsx(Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
5090
+ return (jsxs(Flex, { flexFlow: "column", gap: "2", children: [jsx(Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
5011
5091
  return (jsx(ColumnViewer
5012
5092
  // @ts-expect-error find suitable types
5013
5093
  , {
5014
5094
  // @ts-expect-error find suitable types
5015
5095
  properties: properties, prefix: ``, column }, `form-viewer-${column}`));
5016
- }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
5096
+ }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button$1, { onClick: () => {
5017
5097
  setIsConfirming(false);
5018
- }, variant: "subtle", children: translate.t("cancel") }), jsx(Button, { onClick: () => {
5098
+ }, variant: "subtle", children: translate.t("cancel") }), jsx(Button$1, { onClick: () => {
5019
5099
  onFormSubmit(validatedData);
5020
- }, children: translate.t("confirm") })] }), isSubmiting && (jsx(Box, { pos: "absolute", inset: "0", bg: "bg/80", children: jsx(Center, { h: "full", children: jsx(Spinner, { color: "teal.500" }) }) })), isError && (jsx(Fragment, { children: jsx(Alert.Root, { status: "error", children: jsx(Alert.Title, { children: jsx(AccordionRoot, { collapsible: true, defaultValue: ["b"], children: jsxs(AccordionItem, { value: "b", children: [jsxs(AccordionItemTrigger, { children: [jsx(Alert.Indicator, {}), `${error}`] }), jsx(AccordionItemContent, { children: `${JSON.stringify(error)}` })] }) }) }) }) }))] }));
5100
+ }, children: translate.t("confirm") })] }), isSubmiting && (jsx(Box, { pos: "absolute", inset: "0", bg: "bg/80", children: jsx(Center, { h: "full", children: jsx(Spinner, { color: "teal.500" }) }) })), isError && (jsx(Fragment, { children: jsx(Alert.Root, { status: "error", children: jsx(Alert.Title, { children: jsx(AccordionRoot, { collapsible: true, defaultValue: [], children: jsxs(AccordionItem, { value: "b", children: [jsxs(AccordionItemTrigger, { children: [jsx(Alert.Indicator, {}), `${error}`] }), jsx(AccordionItemContent, { children: `${JSON.stringify(error)}` })] }) }) }) }) }))] }));
5021
5101
  }
5022
- return (jsx(Fragment, { children: jsxs(Grid, { gap: "2", children: [jsxs(Heading, { children: [" ", translate.t("title")] }), jsx(Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
5023
- return (jsx(ColumnRenderer
5102
+ return (jsxs(Flex, { flexFlow: "column", gap: "2", children: [jsx(Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
5103
+ return (jsx(ColumnRenderer
5104
+ // @ts-expect-error find suitable types
5105
+ , {
5024
5106
  // @ts-expect-error find suitable types
5025
- , {
5026
- // @ts-expect-error find suitable types
5027
- properties: properties, prefix: ``, column }, `form-input-${column}`));
5028
- }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
5029
- methods.reset();
5030
- }, variant: "subtle", children: translate.t("reset") }), jsx(Button, { onClick: () => {
5031
- methods.handleSubmit(onValid)();
5032
- }, formNoValidate: true, children: translate.t("submit") })] })] }) }));
5107
+ properties: properties, prefix: ``, column }, `form-input-${column}`));
5108
+ }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button$1, { onClick: () => {
5109
+ methods.reset();
5110
+ }, variant: "subtle", children: translate.t("reset") }), jsx(SubmitButton, {})] })] }));
5033
5111
  };
5034
- const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], include = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, }) => {
5035
- // const { properties } = schema;
5036
- // idListSanityCheck("order", order, properties as object);
5037
- // idListSanityCheck("ignore", ignore, properties as object);
5038
- return (jsx(SchemaFormContext.Provider, { value: {
5039
- schema,
5040
- serverUrl,
5041
- order,
5042
- ignore,
5043
- include,
5044
- // @ts-expect-error TODO: find appropriate types
5045
- onSubmit,
5046
- rowNumber,
5047
- idMap,
5048
- setIdMap,
5049
- translate,
5050
- requestOptions,
5051
- }, children: jsx(FormProvider, { ...form, children: jsx(FormInternal, {}) }) }));
5112
+
5113
+ const FormTitle = () => {
5114
+ const { translate } = useSchemaContext();
5115
+ return jsx(Heading, { children: translate.t("title") });
5116
+ };
5117
+
5118
+ const DefaultForm = ({ formConfig, showTitle = true, }) => {
5119
+ return (jsx(FormRoot, { ...formConfig, children: jsxs(Grid, { gap: "2", children: [showTitle && jsx(FormTitle, {}), jsx(FormBody, {})] }) }));
5052
5120
  };
5053
5121
 
5054
5122
  const useForm = ({ preLoadedValues, keyPrefix }) => {
@@ -5081,4 +5149,4 @@ const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) =
5081
5149
  }
5082
5150
  };
5083
5151
 
5084
- export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultTable, DensityToggleButton, EditOrderButton, EditSortingButton, EmptyState, ErrorAlert, FilterDialog, FilterOptions, Form, GlobalFilter, PageSizeControl, Pagination, RecordDisplay, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TableSelector, TableSorter, TableViewer, TextCell, ViewDialog, getColumns, getMultiDates, getRangeDates, idPickerSanityCheck, useDataTable, useDataTableContext, useDataTableServer, useForm, widthSanityCheck };
5152
+ export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultForm, DefaultTable, DensityToggleButton, EditSortingButton, EmptyState$1 as EmptyState, ErrorAlert, FilterDialog, FilterOptions, FormBody, FormRoot, FormTitle, GlobalFilter, PageSizeControl, Pagination, RecordDisplay, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableDataDisplay, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableSelector, TableSorter, TableViewer, TextCell, ViewDialog, getColumns, getMultiDates, getRangeDates, idPickerSanityCheck, useDataTable, useDataTableContext, useDataTableServer, useForm, widthSanityCheck };