@bsol-oss/react-datatable5 12.0.0-beta.0 → 12.0.0-beta.10

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 +54 -45
  2. package/dist/index.js +381 -311
  3. package/dist/index.mjs +378 -310
  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 +4 -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,75 @@ 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 }) => {
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
+ 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) => {
3546
+ return (jsx(Box, { flex: "1 0 0%", paddingX: "2", py: "1", overflow: "auto", textOverflow: "ellipsis", children: translate.t(`column_header.${header}`) }));
3547
+ }) }), data.map((record) => {
3548
+ return (jsx(Fragment, { children: columnHeaders.map((header) => {
3549
+ if (!!record === false) {
3550
+ return (jsx(Box, { ...cellProps, children: translate.t(`column_cell.placeholder`) }));
3551
+ }
3552
+ if (!!record[header] === false) {
3553
+ return (jsx(Box, { ...cellProps, children: translate.t(`column_cell.placeholder`) }));
3554
+ }
3555
+ if (typeof record[header] === "object") {
3556
+ return (jsx(Box, { ...cellProps, children: jsx(RecordDisplay, { object: record[header] }) }));
3557
+ }
3558
+ return jsx(Box, { ...cellProps, children: record[header] ?? "" });
3559
+ }) }));
3560
+ })] }));
3516
3561
  };
3517
3562
 
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
- };
3563
+ const AccordionItemTrigger = React.forwardRef(function AccordionItemTrigger(props, ref) {
3564
+ const { children, indicatorPlacement = "end", ...rest } = props;
3565
+ 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, {}) }))] }));
3566
+ });
3567
+ const AccordionItemContent = React.forwardRef(function AccordionItemContent(props, ref) {
3568
+ return (jsx(Accordion.ItemContent, { children: jsx(Accordion.ItemBody, { ...props, ref: ref }) }));
3569
+ });
3570
+ const AccordionRoot = Accordion.Root;
3571
+ const AccordionItem = Accordion.Item;
3523
3572
 
3524
3573
  //@ts-expect-error TODO: find appropriate type
3525
3574
  const SchemaFormContext = createContext({
@@ -3542,15 +3591,56 @@ const clearEmptyString = (object) => {
3542
3591
  return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
3543
3592
  };
3544
3593
 
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;
3594
+ const idPickerSanityCheck = (column, foreign_key) => {
3595
+ if (!!foreign_key == false) {
3596
+ throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
3597
+ }
3598
+ const { table, column: foreignKeyColumn, display_column } = foreign_key;
3599
+ if (!!table == false) {
3600
+ throw new Error(`The key table does not exist in properties of column ${table} when using id-picker.`);
3601
+ }
3602
+ if (!!display_column == false) {
3603
+ throw new Error(`The key display_column does not exist in properties of column ${column} when using id-picker.`);
3604
+ }
3605
+ if (!!foreignKeyColumn == false) {
3606
+ throw new Error(`The key column does not exist in properties of column ${column} when using id-picker.`);
3607
+ }
3608
+ };
3609
+ const FormRoot = ({ schema, idMap, setIdMap, form, serverUrl, translate, children, order = [], ignore = [], include = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, getUpdatedData = () => { }, }) => {
3610
+ const [isSuccess, setIsSuccess] = useState(false);
3611
+ const [isError, setIsError] = useState(false);
3612
+ const [isSubmiting, setIsSubmiting] = useState(false);
3613
+ const [isConfirming, setIsConfirming] = useState(false);
3614
+ const [validatedData, setValidatedData] = useState();
3615
+ const [error, setError] = useState();
3616
+ return (jsx(SchemaFormContext.Provider, { value: {
3617
+ schema,
3618
+ serverUrl,
3619
+ order,
3620
+ ignore,
3621
+ include,
3622
+ // @ts-expect-error TODO: find appropriate types
3623
+ onSubmit,
3624
+ rowNumber,
3625
+ idMap,
3626
+ setIdMap,
3627
+ translate,
3628
+ requestOptions,
3629
+ isSuccess,
3630
+ setIsSuccess,
3631
+ isError,
3632
+ setIsError,
3633
+ isSubmiting,
3634
+ setIsSubmiting,
3635
+ isConfirming,
3636
+ setIsConfirming,
3637
+ validatedData,
3638
+ setValidatedData,
3639
+ error,
3640
+ setError,
3641
+ getUpdatedData,
3642
+ }, children: jsx(FormProvider, { ...form, children: children }) }));
3643
+ };
3554
3644
 
3555
3645
  function removeIndex(str) {
3556
3646
  return str.replace(/\.\d+\./g, '.');
@@ -3701,10 +3791,11 @@ const DatePicker = ({ column, schema, prefix }) => {
3701
3791
  const colLabel = `${prefix}${column}`;
3702
3792
  const [open, setOpen] = useState(false);
3703
3793
  const selectedDate = watch(colLabel);
3794
+ const formatedDate = dayjs(selectedDate).format("YYYY-MM-DD");
3704
3795
  return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
3705
3796
  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
3797
  setOpen(true);
3707
- }, children: selectedDate !== undefined ? selectedDate : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
3798
+ }, children: selectedDate !== undefined ? `${formatedDate}` : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
3708
3799
  // @ts-expect-error TODO: find appropriate types
3709
3800
  , {
3710
3801
  // @ts-expect-error TODO: find appropriate types
@@ -4186,7 +4277,7 @@ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], l
4186
4277
 
4187
4278
  const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4188
4279
  const { watch, formState: { errors }, setValue, } = useFormContext();
4189
- const { serverUrl, idMap, setIdMap, translate } = useSchemaContext();
4280
+ const { serverUrl, idMap, setIdMap, translate, schema: parentSchema, } = useSchemaContext();
4190
4281
  const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
4191
4282
  const isRequired = required?.some((columnId) => columnId === column);
4192
4283
  const { table, column: column_ref, display_column, } = foreign_key;
@@ -4229,7 +4320,10 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4229
4320
  const watchId = watch(colLabel);
4230
4321
  const watchIds = (watch(colLabel) ?? []);
4231
4322
  useQuery({
4232
- queryKey: [`idpicker`, { column, searchText, limit, page }],
4323
+ queryKey: [
4324
+ `idpicker`,
4325
+ { form: parentSchema.title, column, searchText, limit, page },
4326
+ ],
4233
4327
  queryFn: async () => {
4234
4328
  const data = await getTableData({
4235
4329
  serverUrl,
@@ -4251,7 +4345,6 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4251
4345
  });
4252
4346
  return data;
4253
4347
  },
4254
- staleTime: 300000,
4255
4348
  });
4256
4349
  const onSearchChange = async (event) => {
4257
4350
  setSearchText(event.target.value);
@@ -4905,30 +4998,23 @@ const ColumnViewer = ({ column, properties, prefix, }) => {
4905
4998
  return jsx(SchemaViewer, { schema: colSchema, prefix, column });
4906
4999
  };
4907
5000
 
4908
- const idPickerSanityCheck = (column, foreign_key) => {
4909
- if (!!foreign_key == false) {
4910
- throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
4911
- }
4912
- const { table, column: foreignKeyColumn, display_column } = foreign_key;
4913
- if (!!table == false) {
4914
- throw new Error(`The key table does not exist in properties of column ${table} when using id-picker.`);
4915
- }
4916
- if (!!display_column == false) {
4917
- throw new Error(`The key display_column does not exist in properties of column ${column} when using id-picker.`);
4918
- }
4919
- if (!!foreignKeyColumn == false) {
4920
- throw new Error(`The key column does not exist in properties of column ${column} when using id-picker.`);
4921
- }
5001
+ const SubmitButton = () => {
5002
+ const { translate, setValidatedData, setIsError, setIsConfirming } = useSchemaContext();
5003
+ const methods = useFormContext();
5004
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5005
+ const onValid = (data) => {
5006
+ setValidatedData(data);
5007
+ setIsError(false);
5008
+ setIsConfirming(true);
5009
+ };
5010
+ return (jsx(Button$1, { onClick: () => {
5011
+ methods.handleSubmit(onValid)();
5012
+ }, formNoValidate: true, children: translate.t("submit") }));
4922
5013
  };
4923
- const FormInternal = () => {
4924
- const { schema, requestUrl, order, ignore, include, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
5014
+
5015
+ const FormBody = () => {
5016
+ const { schema, requestUrl, order, ignore, include, onSubmit, rowNumber, translate, requestOptions, isSuccess, setIsSuccess, isError, setIsError, isSubmiting, setIsSubmiting, isConfirming, setIsConfirming, validatedData, setValidatedData, error, setError, getUpdatedData, } = useSchemaContext();
4925
5017
  const methods = useFormContext();
4926
- const [isSuccess, setIsSuccess] = useState(false);
4927
- const [isError, setIsError] = useState(false);
4928
- const [isSubmiting, setIsSubmiting] = useState(false);
4929
- const [isConfirming, setIsConfirming] = useState(false);
4930
- const [validatedData, setValidatedData] = useState();
4931
- const [error, setError] = useState();
4932
5018
  const { properties } = schema;
4933
5019
  const onBeforeSubmit = () => {
4934
5020
  setIsSubmiting(true);
@@ -4936,8 +5022,9 @@ const FormInternal = () => {
4936
5022
  const onAfterSubmit = () => {
4937
5023
  setIsSubmiting(false);
4938
5024
  };
4939
- const onSubmitError = () => {
5025
+ const onSubmitError = (error) => {
4940
5026
  setIsError(true);
5027
+ setError(error);
4941
5028
  };
4942
5029
  const onSubmitSuccess = () => {
4943
5030
  setIsSuccess(true);
@@ -4949,9 +5036,7 @@ const FormInternal = () => {
4949
5036
  onSubmitSuccess();
4950
5037
  }
4951
5038
  catch (error) {
4952
- setIsError(true);
4953
- setError(error);
4954
- onSubmitError();
5039
+ onSubmitError(error);
4955
5040
  }
4956
5041
  finally {
4957
5042
  onAfterSubmit();
@@ -4974,12 +5059,6 @@ const FormInternal = () => {
4974
5059
  }
4975
5060
  await defaultOnSubmit(onSubmit(data));
4976
5061
  };
4977
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4978
- const onValid = (data) => {
4979
- setValidatedData(data);
4980
- setIsError(false);
4981
- setIsConfirming(true);
4982
- };
4983
5062
  const renderColumns = ({ order, keys, ignore, include, }) => {
4984
5063
  const included = include.length > 0 ? include : keys;
4985
5064
  const not_exist = included.filter((columnA) => !order.some((columnB) => columnA === columnB));
@@ -4994,58 +5073,47 @@ const FormInternal = () => {
4994
5073
  include,
4995
5074
  });
4996
5075
  if (isSuccess) {
4997
- 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: () => {
5076
+ 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 () => {
4998
5077
  setIsError(false);
4999
5078
  setIsSubmiting(false);
5000
5079
  setIsSuccess(false);
5001
5080
  setIsConfirming(false);
5002
5081
  setValidatedData(undefined);
5003
- methods.reset();
5082
+ const data = await getUpdatedData();
5083
+ methods.reset(data);
5004
5084
  }, formNoValidate: true, children: translate.t("submitAgain") }) })] }));
5005
5085
  }
5006
5086
  if (isConfirming) {
5007
- 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) => {
5087
+ 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) => {
5008
5088
  return (jsx(ColumnViewer
5009
5089
  // @ts-expect-error find suitable types
5010
5090
  , {
5011
5091
  // @ts-expect-error find suitable types
5012
5092
  properties: properties, prefix: ``, column }, `form-viewer-${column}`));
5013
- }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
5093
+ }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button$1, { onClick: () => {
5014
5094
  setIsConfirming(false);
5015
- }, variant: "subtle", children: translate.t("cancel") }), jsx(Button, { onClick: () => {
5095
+ }, variant: "subtle", children: translate.t("cancel") }), jsx(Button$1, { onClick: () => {
5016
5096
  onFormSubmit(validatedData);
5017
- }, 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)}` })] }) }) }) }) }))] }));
5097
+ }, 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)}` })] }) }) }) }) }))] }));
5018
5098
  }
5019
- 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) => {
5020
- return (jsx(ColumnRenderer
5099
+ 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) => {
5100
+ return (jsx(ColumnRenderer
5101
+ // @ts-expect-error find suitable types
5102
+ , {
5021
5103
  // @ts-expect-error find suitable types
5022
- , {
5023
- // @ts-expect-error find suitable types
5024
- properties: properties, prefix: ``, column }, `form-input-${column}`));
5025
- }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
5026
- methods.reset();
5027
- }, variant: "subtle", children: translate.t("reset") }), jsx(Button, { onClick: () => {
5028
- methods.handleSubmit(onValid)();
5029
- }, formNoValidate: true, children: translate.t("submit") })] })] }) }));
5104
+ properties: properties, prefix: ``, column }, `form-input-${column}`));
5105
+ }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button$1, { onClick: () => {
5106
+ methods.reset();
5107
+ }, variant: "subtle", children: translate.t("reset") }), jsx(SubmitButton, {})] })] }));
5030
5108
  };
5031
- const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], include = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, }) => {
5032
- // const { properties } = schema;
5033
- // idListSanityCheck("order", order, properties as object);
5034
- // idListSanityCheck("ignore", ignore, properties as object);
5035
- return (jsx(SchemaFormContext.Provider, { value: {
5036
- schema,
5037
- serverUrl,
5038
- order,
5039
- ignore,
5040
- include,
5041
- // @ts-expect-error TODO: find appropriate types
5042
- onSubmit,
5043
- rowNumber,
5044
- idMap,
5045
- setIdMap,
5046
- translate,
5047
- requestOptions,
5048
- }, children: jsx(FormProvider, { ...form, children: jsx(FormInternal, {}) }) }));
5109
+
5110
+ const FormTitle = () => {
5111
+ const { translate } = useSchemaContext();
5112
+ return jsx(Heading, { children: translate.t("title") });
5113
+ };
5114
+
5115
+ const DefaultForm = ({ formConfig, showTitle = true, }) => {
5116
+ return (jsx(FormRoot, { ...formConfig, children: jsxs(Grid, { gap: "2", children: [showTitle && jsx(FormTitle, {}), jsx(FormBody, {})] }) }));
5049
5117
  };
5050
5118
 
5051
5119
  const useForm = ({ preLoadedValues, keyPrefix }) => {
@@ -5078,4 +5146,4 @@ const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) =
5078
5146
  }
5079
5147
  };
5080
5148
 
5081
- 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 };
5149
+ 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 };