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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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, DialogBackdrop, Box, Text, useDisclosure, RadioGroup as RadioGroup$1, Grid, 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 { MdArrowUpward, MdArrowDownward, MdOutlineMoveDown, 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,89 @@ Dialog.Description;
78
78
  const DialogTrigger = Dialog.Trigger;
79
79
  Dialog.ActionTrigger;
80
80
 
81
+ const ColumnOrderChanger = ({ columns }) => {
82
+ const [order, setOrder] = useState([]);
83
+ const [originalOrder, setOriginalOrder] = useState([]);
84
+ const { table } = useDataTableContext();
85
+ const handleChangeOrder = (startIndex, endIndex) => {
86
+ const newOrder = Array.from(order);
87
+ const [removed] = newOrder.splice(startIndex, 1);
88
+ newOrder.splice(endIndex, 0, removed);
89
+ setOrder(newOrder);
90
+ };
91
+ useEffect(() => {
92
+ setOrder(columns);
93
+ }, [columns]);
94
+ useEffect(() => {
95
+ if (originalOrder.length > 0) {
96
+ return;
97
+ }
98
+ if (columns.length <= 0) {
99
+ return;
100
+ }
101
+ setOriginalOrder(columns);
102
+ }, [columns]);
103
+ 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: () => {
104
+ const prevIndex = index - 1;
105
+ if (prevIndex >= 0) {
106
+ handleChangeOrder(index, prevIndex);
107
+ }
108
+ }, disabled: index === 0, "aria-label": "", children: jsx(MdArrowUpward, {}) }), table
109
+ .getAllFlatColumns()
110
+ .filter((column) => {
111
+ return column.id === columnId;
112
+ })
113
+ .map((column) => {
114
+ const displayName = column.columnDef.meta === undefined
115
+ ? column.id
116
+ : column.columnDef.meta.displayName;
117
+ return jsx("span", { children: displayName }, column.id);
118
+ }), jsx(IconButton, { onClick: () => {
119
+ const nextIndex = index + 1;
120
+ if (nextIndex < order.length) {
121
+ handleChangeOrder(index, nextIndex);
122
+ }
123
+ }, disabled: index === order.length - 1, "aria-label": "", children: jsx(MdArrowDownward, {}) })] }, columnId))) }), jsxs(Flex, { gap: "0.25rem", children: [jsx(Button$1, { onClick: () => {
124
+ table.setColumnOrder(order);
125
+ }, children: "Apply" }), jsx(Button$1, { onClick: () => {
126
+ table.setColumnOrder(originalOrder);
127
+ }, children: "Reset" })] })] }));
128
+ };
129
+ const TableOrderer = () => {
130
+ const { table } = useDataTableContext();
131
+ return (jsx(Fragment, { children: jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
132
+ };
133
+
134
+ const EditOrderButton = ({ text, icon = jsx(MdOutlineMoveDown, {}), title = "Change Order", }) => {
135
+ 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, {})] })] }) }));
136
+ };
137
+
138
+ const TableSorter = () => {
139
+ const { table } = useDataTableContext();
140
+ return (jsx(Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsx(Fragment, { children: headerGroup.headers.map((header) => {
141
+ const displayName = header.column.columnDef.meta === undefined
142
+ ? header.column.id
143
+ : header.column.columnDef.meta.displayName;
144
+ 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: () => {
145
+ header.column.toggleSorting();
146
+ }, 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: () => {
147
+ header.column.clearSorting();
148
+ }, children: jsx(CgClose, {}) }))] })) }));
149
+ }) }))) }));
150
+ };
151
+
152
+ const ResetSortingButton = ({ text = "Reset Sorting", }) => {
153
+ const { table } = useDataTableContext();
154
+ return (jsx(Button$1, { onClick: () => {
155
+ table.resetSorting();
156
+ }, children: text }));
157
+ };
158
+
159
+ const EditSortingButton = ({ text, icon = jsx(MdOutlineSort, {}), title = "Edit Sorting", }) => {
160
+ const sortingModal = useDisclosure();
161
+ 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, {})] })] }) }));
162
+ };
163
+
81
164
  const Radio = React.forwardRef(function Radio(props, ref) {
82
165
  const { children, inputProps, rootRef, ...rest } = props;
83
166
  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 +443,138 @@ const FilterDialog = ({ icon = jsx(MdFilterAlt, {}), }) => {
360
443
  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
444
  };
362
445
 
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 = () => {
446
+ const MenuContent = React.forwardRef(function MenuContent(props, ref) {
447
+ const { portalled = true, portalRef, ...rest } = props;
448
+ return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(Menu.Positioner, { children: jsx(Menu.Content, { ref: ref, ...rest }) }) }));
449
+ });
450
+ React.forwardRef(function MenuArrow(props, ref) {
451
+ return (jsx(Menu.Arrow, { ref: ref, ...props, children: jsx(Menu.ArrowTip, {}) }));
452
+ });
453
+ React.forwardRef(function MenuCheckboxItem(props, ref) {
454
+ return (jsxs(Menu.CheckboxItem, { ref: ref, ...props, children: [jsx(Menu.ItemIndicator, { hidden: false, children: jsx(LuCheck, {}) }), props.children] }));
455
+ });
456
+ React.forwardRef(function MenuRadioItem(props, ref) {
457
+ const { children, ...rest } = props;
458
+ 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 })] }));
459
+ });
460
+ React.forwardRef(function MenuItemGroup(props, ref) {
461
+ const { title, children, ...rest } = props;
462
+ return (jsxs(Menu.ItemGroup, { ref: ref, ...rest, children: [title && (jsx(Menu.ItemGroupLabel, { userSelect: "none", children: title })), children] }));
463
+ });
464
+ React.forwardRef(function MenuTriggerItem(props, ref) {
465
+ const { startIcon, children, ...rest } = props;
466
+ return (jsxs(Menu.TriggerItem, { ref: ref, ...rest, children: [startIcon, children, jsx(LuChevronRight, {})] }));
467
+ });
468
+ Menu.RadioItemGroup;
469
+ Menu.ContextTrigger;
470
+ const MenuRoot = Menu.Root;
471
+ Menu.Separator;
472
+ const MenuItem = Menu.Item;
473
+ Menu.ItemText;
474
+ Menu.ItemCommand;
475
+ const MenuTrigger = Menu.Trigger;
476
+
477
+ const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
412
478
  const { table } = useDataTableContext();
413
- return (jsx(Fragment, { children: jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
479
+ 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: () => {
480
+ table.setPageSize(Number(pageSize));
481
+ }, children: pageSize }, `chakra-table-pageSize-${pageSize}`))) })] }));
414
482
  };
415
483
 
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, {})] })] }) }));
484
+ const { withContext } = createRecipeContext({ key: "button" });
485
+ // Replace "a" with your framework's link component
486
+ const LinkButton = withContext("a");
487
+
488
+ const [RootPropsProvider, useRootProps] = createContext$1({
489
+ name: "RootPropsProvider",
490
+ });
491
+ const variantMap = {
492
+ outline: { default: "ghost", ellipsis: "plain", current: "outline" },
493
+ solid: { default: "outline", ellipsis: "outline", current: "solid" },
494
+ subtle: { default: "ghost", ellipsis: "plain", current: "subtle" },
418
495
  };
496
+ const PaginationRoot = React.forwardRef(function PaginationRoot(props, ref) {
497
+ const { size = "sm", variant = "outline", getHref, ...rest } = props;
498
+ return (jsx(RootPropsProvider, { value: { size, variantMap: variantMap[variant], getHref }, children: jsx(Pagination$1.Root, { ref: ref, type: getHref ? "link" : "button", ...rest }) }));
499
+ });
500
+ const PaginationEllipsis = React.forwardRef(function PaginationEllipsis(props, ref) {
501
+ const { size, variantMap } = useRootProps();
502
+ return (jsx(Pagination$1.Ellipsis, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { as: "span", variant: variantMap.ellipsis, size: size, children: jsx(HiMiniEllipsisHorizontal, {}) }) }));
503
+ });
504
+ const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
505
+ const { page } = usePaginationContext();
506
+ const { size, variantMap, getHref } = useRootProps();
507
+ const current = page === props.value;
508
+ const variant = current ? variantMap.current : variantMap.default;
509
+ if (getHref) {
510
+ return (jsx(LinkButton, { href: getHref(props.value), variant: variant, size: size, children: props.value }));
511
+ }
512
+ return (jsx(Pagination$1.Item, { ref: ref, ...props, asChild: true, children: jsx(Button$1, { variant: variant, size: size, children: props.value }) }));
513
+ });
514
+ const PaginationPrevTrigger = React.forwardRef(function PaginationPrevTrigger(props, ref) {
515
+ const { size, variantMap, getHref } = useRootProps();
516
+ const { previousPage } = usePaginationContext();
517
+ if (getHref) {
518
+ return (jsx(LinkButton, { href: previousPage != null ? getHref(previousPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }));
519
+ }
520
+ return (jsx(Pagination$1.PrevTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronLeft, {}) }) }));
521
+ });
522
+ const PaginationNextTrigger = React.forwardRef(function PaginationNextTrigger(props, ref) {
523
+ const { size, variantMap, getHref } = useRootProps();
524
+ const { nextPage } = usePaginationContext();
525
+ if (getHref) {
526
+ return (jsx(LinkButton, { href: nextPage != null ? getHref(nextPage) : undefined, variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }));
527
+ }
528
+ return (jsx(Pagination$1.NextTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }) }));
529
+ });
530
+ const PaginationItems = (props) => {
531
+ return (jsx(Pagination$1.Context, { children: ({ pages }) => pages.map((page, index) => {
532
+ return page.type === "ellipsis" ? (jsx(PaginationEllipsis, { index: index, ...props }, index)) : (jsx(PaginationItem, { type: "page", value: page.value, ...props }, index));
533
+ }) }));
534
+ };
535
+ const PaginationPageText = React.forwardRef(function PaginationPageText(props, ref) {
536
+ const { format = "compact", ...rest } = props;
537
+ const { page, totalPages, pageRange, count } = usePaginationContext();
538
+ const content = React.useMemo(() => {
539
+ if (format === "short")
540
+ return `${page} / ${totalPages}`;
541
+ if (format === "compact")
542
+ return `${page} / ${totalPages}`;
543
+ return `${pageRange.start + 1} - ${Math.min(pageRange.end, count)} / ${count}`;
544
+ }, [format, page, totalPages, pageRange, count]);
545
+ return (jsx(Text, { fontWeight: "medium", ref: ref, ...rest, children: content }));
546
+ });
419
547
 
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
- }) }))) }));
548
+ // TODO: not working in client side
549
+ const Pagination = () => {
550
+ const { table, type } = useDataTableContext();
551
+ const getCount = () => {
552
+ if (type === "client") {
553
+ return table.getFilteredRowModel().flatRows.length ?? 0;
554
+ }
555
+ return table.getRowCount();
556
+ };
557
+ return (jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: getCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
558
+ table.setPageIndex(e.page - 1);
559
+ }, children: jsxs(HStack, { children: [jsx(PaginationPrevTrigger, {}), jsx(PaginationItems, {}), jsx(PaginationNextTrigger, {})] }) }));
432
560
  };
433
561
 
434
- const ResetSortingButton = ({ text = "Reset Sorting", }) => {
562
+ const ResetSelectionButton = ({ text = "Reset Selection", }) => {
435
563
  const { table } = useDataTableContext();
436
564
  return (jsx(Button$1, { onClick: () => {
437
- table.resetSorting();
565
+ table.resetRowSelection();
438
566
  }, children: text }));
439
567
  };
440
568
 
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, {})] })] }) }));
569
+ const RowCountText = () => {
570
+ const { table, type } = useDataTableContext();
571
+ const getCount = () => {
572
+ if (type === "client") {
573
+ return table.getFilteredRowModel().flatRows.length ?? 0;
574
+ }
575
+ return table.getRowCount();
576
+ };
577
+ return jsx(Text, { children: getCount() });
444
578
  };
445
579
 
446
580
  // pulling this into a separate file so adapter(s) that don't
@@ -2360,219 +2494,85 @@ function ColumnCard({ columnId }) {
2360
2494
  onDrop: () => setDragging(false), // NEW
2361
2495
  });
2362
2496
  }, [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() }) })] }));
2364
- }
2365
- function CardContainer({ location, children }) {
2366
- const ref = useRef(null);
2367
- const [isDraggedOver, setIsDraggedOver] = useState(false);
2368
- useEffect(() => {
2369
- const el = ref.current;
2370
- invariant(el);
2371
- return dropTargetForElements({
2372
- element: el,
2373
- getData: () => ({ location }),
2374
- onDragEnter: () => setIsDraggedOver(true),
2375
- onDragLeave: () => setIsDraggedOver(false),
2376
- onDrop: () => setIsDraggedOver(false),
2377
- });
2378
- }, [location]);
2379
- // const isDark = (location + location) % 2 === 1;
2380
- function getColor(isDraggedOver) {
2381
- if (isDraggedOver) {
2382
- return {
2383
- backgroundColor: "blue.400",
2384
- _dark: {
2385
- backgroundColor: "blue.400",
2386
- },
2387
- };
2388
- }
2389
- // return isDark ? "lightgrey" : "white";
2390
- return {
2391
- backgroundColor: undefined,
2392
- _dark: {
2393
- backgroundColor: undefined,
2394
- },
2395
- };
2396
- }
2397
- return (jsx(Box, { ...getColor(isDraggedOver), ref: ref, children: children }));
2398
- }
2399
- const TableViewer = () => {
2400
- const { table } = useDataTableContext();
2401
- const order = table.getState().columnOrder.length > 0
2402
- ? table.getState().columnOrder
2403
- : table.getAllLeafColumns().map(({ id }) => {
2404
- return id;
2405
- });
2406
- useEffect(() => {
2407
- return monitorForElements({
2408
- onDrop({ source, location }) {
2409
- const destination = location.current.dropTargets[0];
2410
- if (!destination) {
2411
- return;
2412
- }
2413
- const destinationLocation = destination.data.location;
2414
- // const sourceLocation = source.data.location;
2415
- const sourceColumn = source.data.column;
2416
- const columnOrder = order.map((id) => {
2417
- if (id == sourceColumn.id) {
2418
- return "<marker>";
2419
- }
2420
- return id;
2421
- });
2422
- const columnBefore = columnOrder.slice(0, destinationLocation + 1);
2423
- const columnAfter = columnOrder.slice(destinationLocation + 1, columnOrder.length);
2424
- const newOrder = [
2425
- ...columnBefore,
2426
- sourceColumn.id,
2427
- ...columnAfter,
2428
- ].filter((id) => id != "<marker>");
2429
- table.setColumnOrder(newOrder);
2430
- },
2431
- });
2432
- }, [table]);
2433
- return (jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: order.map((columnId, index) => {
2434
- return (jsx(CardContainer, { location: index, children: jsx(ColumnCard, { columnId: columnId }) }));
2435
- }) }));
2436
- };
2437
-
2438
- const ViewDialog = ({ icon = jsx(IoMdEye, {}) }) => {
2439
- const viewModel = useDisclosure();
2440
- const { translate } = useDataTableContext();
2441
- 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
- };
2443
-
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() });
2498
- };
2499
-
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, {}) }));
2497
+ 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() }) })] }));
2498
+ }
2499
+ function CardContainer({ location, children }) {
2500
+ const ref = useRef(null);
2501
+ const [isDraggedOver, setIsDraggedOver] = useState(false);
2502
+ useEffect(() => {
2503
+ const el = ref.current;
2504
+ invariant(el);
2505
+ return dropTargetForElements({
2506
+ element: el,
2507
+ getData: () => ({ location }),
2508
+ onDragEnter: () => setIsDraggedOver(true),
2509
+ onDragLeave: () => setIsDraggedOver(false),
2510
+ onDrop: () => setIsDraggedOver(false),
2511
+ });
2512
+ }, [location]);
2513
+ // const isDark = (location + location) % 2 === 1;
2514
+ function getColor(isDraggedOver) {
2515
+ if (isDraggedOver) {
2516
+ return {
2517
+ backgroundColor: "blue.400",
2518
+ _dark: {
2519
+ backgroundColor: "blue.400",
2520
+ },
2521
+ };
2522
+ }
2523
+ // return isDark ? "lightgrey" : "white";
2524
+ return {
2525
+ backgroundColor: undefined,
2526
+ _dark: {
2527
+ backgroundColor: undefined,
2528
+ },
2529
+ };
2543
2530
  }
2544
- return (jsx(Pagination$1.NextTrigger, { ref: ref, asChild: true, ...props, children: jsx(IconButton, { variant: variantMap.default, size: size, children: jsx(HiChevronRight, {}) }) }));
2545
- });
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));
2531
+ return (jsx(Box, { ...getColor(isDraggedOver), ref: ref, children: children }));
2532
+ }
2533
+ const TableViewer = () => {
2534
+ const { table } = useDataTableContext();
2535
+ const order = table.getState().columnOrder.length > 0
2536
+ ? table.getState().columnOrder
2537
+ : table.getAllLeafColumns().map(({ id }) => {
2538
+ return id;
2539
+ });
2540
+ useEffect(() => {
2541
+ return monitorForElements({
2542
+ onDrop({ source, location }) {
2543
+ const destination = location.current.dropTargets[0];
2544
+ if (!destination) {
2545
+ return;
2546
+ }
2547
+ const destinationLocation = destination.data.location;
2548
+ // const sourceLocation = source.data.location;
2549
+ const sourceColumn = source.data.column;
2550
+ const columnOrder = order.map((id) => {
2551
+ if (id == sourceColumn.id) {
2552
+ return "<marker>";
2553
+ }
2554
+ return id;
2555
+ });
2556
+ const columnBefore = columnOrder.slice(0, destinationLocation + 1);
2557
+ const columnAfter = columnOrder.slice(destinationLocation + 1, columnOrder.length);
2558
+ const newOrder = [
2559
+ ...columnBefore,
2560
+ sourceColumn.id,
2561
+ ...columnAfter,
2562
+ ].filter((id) => id != "<marker>");
2563
+ table.setColumnOrder(newOrder);
2564
+ },
2565
+ });
2566
+ }, [table]);
2567
+ return (jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: order.map((columnId, index) => {
2568
+ return (jsx(CardContainer, { location: index, children: jsx(ColumnCard, { columnId: columnId }) }));
2549
2569
  }) }));
2550
2570
  };
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
2571
 
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, {})] }) }));
2572
+ const ViewDialog = ({ icon = jsx(IoMdEye, {}) }) => {
2573
+ const viewModel = useDisclosure();
2574
+ const { translate } = useDataTableContext();
2575
+ 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, {})] })] }));
2576
2576
  };
2577
2577
 
2578
2578
  const CardHeader = ({ row, imageColumnId = undefined, titleColumnId = undefined, tagColumnId = undefined, tagIcon = undefined, showTag = true, imageProps = {}, }) => {
@@ -2583,6 +2583,28 @@ const CardHeader = ({ row, imageColumnId = undefined, titleColumnId = undefined,
2583
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] }))] }))] }));
2584
2584
  };
2585
2585
 
2586
+ const DataTableServerContext = createContext({
2587
+ url: "",
2588
+ });
2589
+
2590
+ const useDataTableServerContext = () => {
2591
+ const context = useContext(DataTableServerContext);
2592
+ const { query } = context;
2593
+ const isEmpty = (query.data?.count ?? 0) <= 0;
2594
+ return { ...context, isEmpty };
2595
+ };
2596
+
2597
+ const EmptyState$1 = ({ title = "No records", description = "Add a new events to get started or refine your search", }) => {
2598
+ const { isEmpty } = useDataTableServerContext();
2599
+ 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 })] })] }) })) }));
2600
+ };
2601
+
2602
+ const ErrorAlert = ({ showMessage = true }) => {
2603
+ const { query } = useDataTableServerContext();
2604
+ const { isError, error } = query;
2605
+ 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 }))] })] })) }));
2606
+ };
2607
+
2586
2608
  const snakeToLabel = (str) => {
2587
2609
  return str
2588
2610
  .split("_") // Split by underscore
@@ -2829,10 +2851,6 @@ function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSel
2829
2851
  }, children: children }));
2830
2852
  }
2831
2853
 
2832
- const DataTableServerContext = createContext({
2833
- url: "",
2834
- });
2835
-
2836
2854
  /**
2837
2855
  * DataTableServer will create a context to hold all values to
2838
2856
  * help the render of the DataTable in serverside
@@ -3016,13 +3034,6 @@ const GlobalFilter = () => {
3016
3034
  } }) }) }));
3017
3035
  };
3018
3036
 
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
3037
  const ReloadButton = ({ text = "Reload", variant = "icon", }) => {
3027
3038
  const { url } = useDataTableServerContext();
3028
3039
  const queryClient = useQueryClient();
@@ -3236,12 +3247,12 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
3236
3247
  })] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
3237
3248
  };
3238
3249
 
3239
- const EmptyState$1 = React.forwardRef(function EmptyState(props, ref) {
3250
+ const EmptyState = React.forwardRef(function EmptyState(props, ref) {
3240
3251
  const { title, description, icon, children, ...rest } = props;
3241
3252
  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
3253
  });
3243
3254
 
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" })] }) }));
3255
+ 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
3256
  const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
3246
3257
  const { table } = useDataTableContext();
3247
3258
  if (table.getRowModel().rows.length <= 0) {
@@ -3510,16 +3521,15 @@ const getColumns = ({ schema, include = [], ignore = [], width = [], meta = {},
3510
3521
  return columns;
3511
3522
  };
3512
3523
 
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 })] })] }) })) }));
3516
- };
3517
-
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
- };
3524
+ const AccordionItemTrigger = React.forwardRef(function AccordionItemTrigger(props, ref) {
3525
+ const { children, indicatorPlacement = "end", ...rest } = props;
3526
+ 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, {}) }))] }));
3527
+ });
3528
+ const AccordionItemContent = React.forwardRef(function AccordionItemContent(props, ref) {
3529
+ return (jsx(Accordion.ItemContent, { children: jsx(Accordion.ItemBody, { ...props, ref: ref }) }));
3530
+ });
3531
+ const AccordionRoot = Accordion.Root;
3532
+ const AccordionItem = Accordion.Item;
3523
3533
 
3524
3534
  //@ts-expect-error TODO: find appropriate type
3525
3535
  const SchemaFormContext = createContext({
@@ -3542,15 +3552,56 @@ const clearEmptyString = (object) => {
3542
3552
  return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
3543
3553
  };
3544
3554
 
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;
3555
+ const idPickerSanityCheck = (column, foreign_key) => {
3556
+ if (!!foreign_key == false) {
3557
+ throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
3558
+ }
3559
+ const { table, column: foreignKeyColumn, display_column } = foreign_key;
3560
+ if (!!table == false) {
3561
+ throw new Error(`The key table does not exist in properties of column ${table} when using id-picker.`);
3562
+ }
3563
+ if (!!display_column == false) {
3564
+ throw new Error(`The key display_column does not exist in properties of column ${column} when using id-picker.`);
3565
+ }
3566
+ if (!!foreignKeyColumn == false) {
3567
+ throw new Error(`The key column does not exist in properties of column ${column} when using id-picker.`);
3568
+ }
3569
+ };
3570
+ const FormRoot = ({ schema, idMap, setIdMap, form, serverUrl, translate, children, order = [], ignore = [], include = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, getUpdatedData = () => { }, }) => {
3571
+ const [isSuccess, setIsSuccess] = useState(false);
3572
+ const [isError, setIsError] = useState(false);
3573
+ const [isSubmiting, setIsSubmiting] = useState(false);
3574
+ const [isConfirming, setIsConfirming] = useState(false);
3575
+ const [validatedData, setValidatedData] = useState();
3576
+ const [error, setError] = useState();
3577
+ return (jsx(SchemaFormContext.Provider, { value: {
3578
+ schema,
3579
+ serverUrl,
3580
+ order,
3581
+ ignore,
3582
+ include,
3583
+ // @ts-expect-error TODO: find appropriate types
3584
+ onSubmit,
3585
+ rowNumber,
3586
+ idMap,
3587
+ setIdMap,
3588
+ translate,
3589
+ requestOptions,
3590
+ isSuccess,
3591
+ setIsSuccess,
3592
+ isError,
3593
+ setIsError,
3594
+ isSubmiting,
3595
+ setIsSubmiting,
3596
+ isConfirming,
3597
+ setIsConfirming,
3598
+ validatedData,
3599
+ setValidatedData,
3600
+ error,
3601
+ setError,
3602
+ getUpdatedData,
3603
+ }, children: jsx(FormProvider, { ...form, children: children }) }));
3604
+ };
3554
3605
 
3555
3606
  function removeIndex(str) {
3556
3607
  return str.replace(/\.\d+\./g, '.');
@@ -4254,7 +4305,6 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4254
4305
  });
4255
4306
  return data;
4256
4307
  },
4257
- staleTime: 300000,
4258
4308
  });
4259
4309
  const onSearchChange = async (event) => {
4260
4310
  setSearchText(event.target.value);
@@ -4908,30 +4958,23 @@ const ColumnViewer = ({ column, properties, prefix, }) => {
4908
4958
  return jsx(SchemaViewer, { schema: colSchema, prefix, column });
4909
4959
  };
4910
4960
 
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
- }
4961
+ const SubmitButton = () => {
4962
+ const { translate, setValidatedData, setIsError, setIsConfirming } = useSchemaContext();
4963
+ const methods = useFormContext();
4964
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4965
+ const onValid = (data) => {
4966
+ setValidatedData(data);
4967
+ setIsError(false);
4968
+ setIsConfirming(true);
4969
+ };
4970
+ return (jsx(Button$1, { onClick: () => {
4971
+ methods.handleSubmit(onValid)();
4972
+ }, formNoValidate: true, children: translate.t("submit") }));
4925
4973
  };
4926
- const FormInternal = () => {
4927
- const { schema, requestUrl, order, ignore, include, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
4974
+
4975
+ const FormBody = () => {
4976
+ 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
4977
  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
4978
  const { properties } = schema;
4936
4979
  const onBeforeSubmit = () => {
4937
4980
  setIsSubmiting(true);
@@ -4939,8 +4982,9 @@ const FormInternal = () => {
4939
4982
  const onAfterSubmit = () => {
4940
4983
  setIsSubmiting(false);
4941
4984
  };
4942
- const onSubmitError = () => {
4985
+ const onSubmitError = (error) => {
4943
4986
  setIsError(true);
4987
+ setError(error);
4944
4988
  };
4945
4989
  const onSubmitSuccess = () => {
4946
4990
  setIsSuccess(true);
@@ -4952,9 +4996,7 @@ const FormInternal = () => {
4952
4996
  onSubmitSuccess();
4953
4997
  }
4954
4998
  catch (error) {
4955
- setIsError(true);
4956
- setError(error);
4957
- onSubmitError();
4999
+ onSubmitError(error);
4958
5000
  }
4959
5001
  finally {
4960
5002
  onAfterSubmit();
@@ -4977,12 +5019,6 @@ const FormInternal = () => {
4977
5019
  }
4978
5020
  await defaultOnSubmit(onSubmit(data));
4979
5021
  };
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
5022
  const renderColumns = ({ order, keys, ignore, include, }) => {
4987
5023
  const included = include.length > 0 ? include : keys;
4988
5024
  const not_exist = included.filter((columnA) => !order.some((columnB) => columnA === columnB));
@@ -4997,58 +5033,47 @@ const FormInternal = () => {
4997
5033
  include,
4998
5034
  });
4999
5035
  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: () => {
5036
+ 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
5037
  setIsError(false);
5002
5038
  setIsSubmiting(false);
5003
5039
  setIsSuccess(false);
5004
5040
  setIsConfirming(false);
5005
5041
  setValidatedData(undefined);
5006
- methods.reset();
5042
+ const data = await getUpdatedData();
5043
+ methods.reset(data);
5007
5044
  }, formNoValidate: true, children: translate.t("submitAgain") }) })] }));
5008
5045
  }
5009
5046
  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) => {
5047
+ 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
5048
  return (jsx(ColumnViewer
5012
5049
  // @ts-expect-error find suitable types
5013
5050
  , {
5014
5051
  // @ts-expect-error find suitable types
5015
5052
  properties: properties, prefix: ``, column }, `form-viewer-${column}`));
5016
- }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
5053
+ }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button$1, { onClick: () => {
5017
5054
  setIsConfirming(false);
5018
- }, variant: "subtle", children: translate.t("cancel") }), jsx(Button, { onClick: () => {
5055
+ }, variant: "subtle", children: translate.t("cancel") }), jsx(Button$1, { onClick: () => {
5019
5056
  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)}` })] }) }) }) }) }))] }));
5057
+ }, 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
5058
  }
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
5059
+ 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) => {
5060
+ return (jsx(ColumnRenderer
5061
+ // @ts-expect-error find suitable types
5062
+ , {
5024
5063
  // @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") })] })] }) }));
5064
+ properties: properties, prefix: ``, column }, `form-input-${column}`));
5065
+ }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button$1, { onClick: () => {
5066
+ methods.reset();
5067
+ }, variant: "subtle", children: translate.t("reset") }), jsx(SubmitButton, {})] })] }));
5033
5068
  };
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, {}) }) }));
5069
+
5070
+ const FormTitle = () => {
5071
+ const { translate } = useSchemaContext();
5072
+ return jsx(Heading, { children: translate.t("title") });
5073
+ };
5074
+
5075
+ const DefaultForm = ({ formConfig, }) => {
5076
+ return (jsx(FormRoot, { ...formConfig, children: jsxs(Grid, { gap: "2", children: [jsx(FormTitle, {}), jsx(FormBody, {})] }) }));
5052
5077
  };
5053
5078
 
5054
5079
  const useForm = ({ preLoadedValues, keyPrefix }) => {
@@ -5081,4 +5106,4 @@ const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) =
5081
5106
  }
5082
5107
  };
5083
5108
 
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 };
5109
+ export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultForm, DefaultTable, DensityToggleButton, EditOrderButton, 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, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TableSelector, TableSorter, TableViewer, TextCell, ViewDialog, getColumns, getMultiDates, getRangeDates, idPickerSanityCheck, useDataTable, useDataTableContext, useDataTableServer, useForm, widthSanityCheck };