@bsol-oss/react-datatable5 7.0.1 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, useDisclosure, Box, Flex, DialogBackdrop, Menu, Text, createRecipeContext, createContext as createContext$1, Pagination, usePaginationContext, HStack, Tag as Tag$1, Grid, Image, Card, DataList, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$1, VStack, List, Input, Slider as Slider$1, For, RadioGroup as RadioGroup$1, CheckboxCard as CheckboxCard$1, Group, InputElement, Popover, RadioCard, Field as Field$1, NumberInput, Accordion, Show, Heading, Alert, Center } from '@chakra-ui/react';
2
+ import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, useDisclosure, Box, Flex, DialogBackdrop, Menu, Text, createRecipeContext, createContext as createContext$1, Pagination, usePaginationContext, HStack, Tag as Tag$1, Grid, Image, Card, DataList, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$1, VStack, List, RadioGroup as RadioGroup$1, Slider as Slider$1, For, Input, CheckboxCard as CheckboxCard$1, Group, InputElement, Popover, RadioCard, Field as Field$1, NumberInput, Accordion, Show, CheckboxGroup, Heading, Alert, Center } 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, useEffect, useState, useRef } from 'react';
@@ -15,6 +15,7 @@ import { GrAscend, GrDescend } from 'react-icons/gr';
15
15
  import { useQueryClient, useQuery, QueryClient, QueryClientProvider } from '@tanstack/react-query';
16
16
  import { IoReload } from 'react-icons/io5';
17
17
  import { HiColorSwatch, HiOutlineInformationCircle } from 'react-icons/hi';
18
+ import Dayzed from '@bsol-oss/dayzed-react19';
18
19
  import { FaUpDown, FaGripLinesVertical } from 'react-icons/fa6';
19
20
  import { CgClose } from 'react-icons/cg';
20
21
  import { monitorForElements, draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
@@ -22,7 +23,9 @@ import invariant from 'tiny-invariant';
22
23
  import axios from 'axios';
23
24
  import { useFormContext, useForm, FormProvider } from 'react-hook-form';
24
25
  import dayjs from 'dayjs';
25
- import Dayzed from '@bsol-oss/dayzed-react19';
26
+ import { dropTargetForExternal } from '@atlaskit/pragmatic-drag-and-drop/external/adapter';
27
+ import { getFiles } from '@atlaskit/pragmatic-drag-and-drop/external/file';
28
+ import { getText } from '@atlaskit/pragmatic-drag-and-drop/external/text';
26
29
 
27
30
  const DataTableContext = createContext({
28
31
  table: {},
@@ -149,7 +152,7 @@ const ResetSortingButton = ({ text = "Reset Sorting", }) => {
149
152
 
150
153
  const RowCountText = () => {
151
154
  const { table } = useDataTableContext();
152
- return jsx(Text, { children: table.getRowCount() });
155
+ return jsx(Text, { children: table.getFilteredRowModel().flatRows.length ?? 0 });
153
156
  };
154
157
 
155
158
  const { withContext } = createRecipeContext({ key: "button" });
@@ -219,7 +222,7 @@ React.forwardRef(function PaginationPageText(props, ref) {
219
222
  // TODO: not working in client side
220
223
  const TablePagination = () => {
221
224
  const { table } = useDataTableContext();
222
- return (jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: table.getRowCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
225
+ return (jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: table.getFilteredRowModel().flatRows.length ?? 0, pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
223
226
  table.setPageIndex(e.page - 1);
224
227
  }, children: jsxs(HStack, { children: [jsx(PaginationPrevTrigger, {}), jsx(PaginationItems, {}), jsx(PaginationNextTrigger, {})] }) }));
225
228
  };
@@ -264,20 +267,20 @@ const DataDisplay = ({ variant = "" }) => {
264
267
  if (variant == "horizontal") {
265
268
  return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
266
269
  return (jsx(Card.Root, { children: jsx(Card.Body, { children: jsx(DataList.Root, { gap: 4, padding: 4, display: "grid", variant: "subtle", orientation: "horizontal", overflow: "auto", children: row.getVisibleCells().map((cell) => {
267
- return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsx(DataList.ItemValue, { children: `${formatValue(cell.getValue())}` })] }, cell.id));
270
+ return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsx(DataList.ItemValue, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
268
271
  }) }) }) }, `chakra-table-card-${row.id}`));
269
272
  }) }));
270
273
  }
271
274
  if (variant == "stats") {
272
275
  return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
273
276
  return (jsx(Card.Root, { children: jsx(Card.Body, { children: jsx(DataList.Root, { gap: 4, padding: 4, display: "flex", flexFlow: "row", variant: "subtle", overflow: "auto", children: row.getVisibleCells().map((cell) => {
274
- return (jsxs(DataList.Item, { display: "flex", justifyContent: "center", alignItems: "center", flex: "1 0 10rem", children: [jsx(DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsx(DataList.ItemValue, { children: `${formatValue(cell.getValue())}` })] }, cell.id));
277
+ return (jsxs(DataList.Item, { display: "flex", justifyContent: "center", alignItems: "center", flex: "1 0 0%", children: [jsx(DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsx(DataList.ItemValue, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
275
278
  }) }) }) }, `chakra-table-card-${row.id}`));
276
279
  }) }));
277
280
  }
278
281
  return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
279
282
  return (jsx(Card.Root, { children: jsx(Card.Body, { children: jsx(DataList.Root, { gap: 4, padding: 4, display: "grid", variant: "subtle", gridTemplateColumns: "repeat(auto-fit, minmax(20rem, 1fr))", children: row.getVisibleCells().map((cell) => {
280
- return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsx(DataList.ItemValue, { children: `${formatValue(cell.getValue())}` })] }, cell.id));
283
+ return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsx(DataList.ItemValue, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
281
284
  }) }) }) }, `chakra-table-card-${row.id}`));
282
285
  }) }));
283
286
  };
@@ -430,7 +433,7 @@ const DataTableServerContext = createContext({
430
433
  url: "",
431
434
  });
432
435
 
433
- const DataTableServer = ({ columns, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, query, children, url }) => {
436
+ const DataTableServer = ({ columns, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, query, children, url, }) => {
434
437
  const table = useReactTable({
435
438
  _features: [DensityFeature],
436
439
  data: query.data?.data ?? [],
@@ -490,7 +493,7 @@ const Checkbox = React.forwardRef(function Checkbox(props, ref) {
490
493
  return (jsxs(Checkbox$1.Root, { ref: rootRef, ...rest, children: [jsx(Checkbox$1.HiddenInput, { ref: ref, ...inputProps }), jsx(Checkbox$1.Control, { children: icon || jsx(Checkbox$1.Indicator, {}) }), children != null && (jsx(Checkbox$1.Label, { children: children }))] }));
491
494
  });
492
495
 
493
- const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, }) => {
496
+ const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, canResize = true, }) => {
494
497
  const { table } = useDataTableContext();
495
498
  const SELECTION_BOX_WIDTH = 20;
496
499
  const [hoveredRow, setHoveredRow] = useState(-1);
@@ -513,12 +516,25 @@ const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, sho
513
516
  : {};
514
517
  return tdProps;
515
518
  };
519
+ const getTrProps = ({ hoveredRow, index, }) => {
520
+ if (hoveredRow === -1) {
521
+ return {};
522
+ }
523
+ if (hoveredRow === index) {
524
+ return {
525
+ opacity: "1",
526
+ };
527
+ }
528
+ return {
529
+ opacity: "0.8",
530
+ };
531
+ };
516
532
  return (jsx(Table$1.Body, { children: table.getRowModel().rows.map((row, index) => {
517
- return (jsxs(Table$1.Row, { display: "flex", _hover: { backgroundColor: "rgba(178,178,178,0.1)" }, zIndex: 1, onMouseEnter: () => handleRowHover(index), onMouseLeave: () => handleRowHover(-1), children: [showSelector && (jsx(TableRowSelector, { index: index, row: row, hoveredRow: hoveredRow, alwaysShowSelector: alwaysShowSelector })), row.getVisibleCells().map((cell, index) => {
533
+ return (jsxs(Table$1.Row, { display: "flex", zIndex: 1, onMouseEnter: () => handleRowHover(index), onMouseLeave: () => handleRowHover(-1), ...getTrProps({ hoveredRow, index }), children: [showSelector && (jsx(TableRowSelector, { index: index, row: row, hoveredRow: hoveredRow, alwaysShowSelector: alwaysShowSelector })), row.getVisibleCells().map((cell, index) => {
518
534
  return (jsx(Table$1.Cell, { padding: `${table.getDensityValue()}px`,
519
535
  // styling resize and pinning start
520
- maxWidth: `${cell.column.getSize()}px`, width: `${cell.column.getSize()}px`, backgroundColor: "white", ...getTdProps(cell), _dark: {
521
- backgroundColor: "gray.950"
536
+ flex: `${canResize ? "0" : "1"} 0 ${cell.column.getSize()}px`, backgroundColor: "white", ...getTdProps(cell), _dark: {
537
+ backgroundColor: "gray.950",
522
538
  }, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
523
539
  })] }, `chakra-table-row-${row.id}`));
524
540
  }) }));
@@ -550,7 +566,6 @@ const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gr
550
566
  // styling resize and pinning end
551
567
  display: "grid", children: [!isCheckBoxVisible(index, row) && (jsx(Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` })), isCheckBoxVisible(index, row) && (jsx(Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: row.getIsSelected(),
552
568
  disabled: !row.getCanSelect(),
553
- // indeterminate: row.getIsSomeSelected(),
554
569
  onChange: row.getToggleSelectedHandler() }) }))] }));
555
570
  };
556
571
 
@@ -629,7 +644,7 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, s
629
644
  jsx(Fragment, {})), header.column.getIsSorted() === "asc" && (jsx(BiUpArrow, {})), header.column.getIsSorted() === "desc" && (jsx(BiDownArrow, {}))] })) })] }) }) }) }) }, `chakra-table-footer-${header.column.id}-${footerGroup.id}`)))] }, `chakra-table-footergroup-${footerGroup.id}`))) }));
630
645
  };
631
646
 
632
- const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, isSticky = true, alwaysShowSelector = true, tHeadProps = {}, }) => {
647
+ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, isSticky = true, alwaysShowSelector = true, tHeadProps = {}, }) => {
633
648
  const { table } = useDataTableContext();
634
649
  const SELECTION_BOX_WIDTH = 20;
635
650
  const [hoveredCheckBox, setHoveredCheckBox] = useState(false);
@@ -690,7 +705,12 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
690
705
  };
691
706
  return (jsxs(Table$1.ColumnHeader, { padding: 0, columnSpan: `${header.colSpan}`,
692
707
  // styling resize and pinning start
693
- width: `${header.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: header.index, ...getThProps(header), children: [jsxs(MenuRoot, { children: [jsx(MenuTrigger, { asChild: true, children: jsx(Grid, { padding: `${table.getDensityValue()}px`, display: "flex", alignItems: "center", justifyContent: "start", borderRadius: "0rem", overflow: "auto", _hover: { backgroundColor: "gray.100" }, children: jsxs(Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
708
+ flex: `${canResize ? "0" : "1"} 0 ${header.column.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: header.index, ...getThProps(header), children: [jsxs(MenuRoot, { children: [jsx(MenuTrigger, { asChild: true, children: jsx(Flex, { padding: `${table.getDensityValue()}px`, alignItems: "center", justifyContent: "start", borderRadius: "0rem", overflow: "auto", _hover: {
709
+ backgroundColor: "gray.100",
710
+ _dark: {
711
+ backgroundColor: "gray.700",
712
+ },
713
+ }, children: jsxs(Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
694
714
  ? null
695
715
  : flexRender(header.column.columnDef.header, header.getContext()), jsx(Box, { children: header.column.getCanSort() && (jsxs(Fragment, { children: [header.column.getIsSorted() === false && jsx(Fragment, {}), header.column.getIsSorted() === "asc" && (jsx(BiUpArrow, {})), header.column.getIsSorted() === "desc" && (jsx(BiDownArrow, {}))] })) }), jsx(Box, { children: header.column.getIsFiltered() && jsx(MdFilterListAlt, {}) })] }) }) }), jsxs(MenuContent, { children: [!header.column.getIsPinned() && (jsx(MenuItem, { asChild: true, value: "pin-column", children: jsxs(Button, { variant: "ghost", onClick: () => {
696
716
  header.column.pin("left");
@@ -724,8 +744,11 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
724
744
  })] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
725
745
  };
726
746
 
727
- const DefaultTable = ({ showFooter = false, showSelector = false, tableProps = {}, tHeadProps = {}, controlProps = {}, }) => {
728
- return (jsx(TableControls, { ...controlProps, children: jsxs(Table, { ...tableProps, children: [jsx(TableHeader, { canResize: true, showSelector: showSelector, tHeadProps: tHeadProps }), jsx(TableBody, { showSelector: showSelector }), showFooter && jsx(TableFooter, { showSelector: showSelector })] }) }));
747
+ const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, controlProps = {}, tableFooterProps = {}, variant = "", }) => {
748
+ if (variant === "greedy") {
749
+ return (jsx(TableControls, { ...controlProps, children: jsxs(Table, { canResize: false, ...tableProps, children: [jsx(TableHeader, { canResize: false, ...tableHeaderProps }), jsx(TableBody, { canResize: false, ...tableBodyProps }), showFooter && (jsx(TableFooter, { canResize: false, ...tableFooterProps }))] }) }));
750
+ }
751
+ return (jsx(TableControls, { ...controlProps, children: jsxs(Table, { ...tableProps, children: [jsx(TableHeader, { ...tableHeaderProps }), jsx(TableBody, { ...tableBodyProps }), showFooter && jsx(TableFooter, { ...tableFooterProps })] }) }));
729
752
  };
730
753
 
731
754
  const useDataTableServerContext = () => {
@@ -751,12 +774,12 @@ const EmptyState = React.forwardRef(function EmptyState(props, ref) {
751
774
  });
752
775
 
753
776
  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" })] }) }));
754
- const Table = ({ children, emptyComponent = EmptyResult, ...props }) => {
777
+ const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
755
778
  const { table } = useDataTableContext();
756
779
  if (table.getRowModel().rows.length <= 0) {
757
780
  return emptyComponent;
758
781
  }
759
- return (jsx(Table$1.Root, { stickyHeader: true, variant: "outline", width: table.getCenterTotalSize(), ...props, children: children }));
782
+ return (jsx(Table$1.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, ...props, children: children }));
760
783
  };
761
784
 
762
785
  const TableCardContainer = ({ children, variant = "", ...props }) => {
@@ -791,9 +814,143 @@ const TableComponent = ({ render = () => {
791
814
  return render(table);
792
815
  };
793
816
 
794
- const DateRangeFilter = ({ startDate, endDate, setStartDate, setEndDate, }) => {
795
- console.log(startDate, endDate, "dflp");
796
- return (jsx(Box, { p: "1rem", children: jsxs(VStack, { children: [jsxs(Box, { children: [jsx(Box, { children: "Start Date" }), jsx(Input, { id: "start-date", type: "date", value: startDate, onChange: (e) => setStartDate(e.target.value) })] }), jsxs(Box, { children: [jsx(Box, { children: "End Date" }), jsx(Input, { id: "end-date", type: "date", value: endDate, onChange: (e) => setEndDate(e.target.value) })] })] }) }));
817
+ const Radio = React.forwardRef(function Radio(props, ref) {
818
+ const { children, inputProps, rootRef, ...rest } = props;
819
+ 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 }))] }));
820
+ });
821
+ const RadioGroup = RadioGroup$1.Root;
822
+
823
+ const monthNamesFull = [
824
+ "January",
825
+ "February",
826
+ "March",
827
+ "April",
828
+ "May",
829
+ "June",
830
+ "July",
831
+ "August",
832
+ "September",
833
+ "October",
834
+ "November",
835
+ "December",
836
+ ];
837
+ const weekdayNamesShort$1 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
838
+ function Calendar$1({ calendars, getBackProps, getForwardProps, getDateProps, selected = [], firstDayOfWeek = 0, }) {
839
+ const [hoveredDate, setHoveredDate] = useState();
840
+ const onMouseLeave = () => {
841
+ setHoveredDate(undefined);
842
+ };
843
+ const onMouseEnter = (date) => {
844
+ setHoveredDate(date);
845
+ };
846
+ const isInRange = (date) => {
847
+ if (selected.length) {
848
+ const firstSelected = selected[0].getTime();
849
+ if (selected.length === 2) {
850
+ const secondSelected = selected[1].getTime();
851
+ return (firstSelected < date.getTime() && secondSelected > date.getTime());
852
+ }
853
+ else {
854
+ return !!(hoveredDate &&
855
+ ((firstSelected < date.getTime() &&
856
+ hoveredDate.getTime() >= date.getTime()) ||
857
+ (date.getTime() < firstSelected &&
858
+ date.getTime() >= hoveredDate.getTime())));
859
+ }
860
+ }
861
+ return false;
862
+ };
863
+ if (calendars.length) {
864
+ return (jsxs(Grid, { onMouseLeave: onMouseLeave, children: [jsxs(Grid, { templateColumns: "repeat(4, auto)", justifyContent: "center", children: [jsx(Button$1, { variant: "ghost", ...getBackProps({
865
+ calendars,
866
+ offset: 12,
867
+ }), children: "<<" }), jsx(Button$1, { variant: "ghost", ...getBackProps({ calendars }), children: "Back" }), jsx(Button$1, { variant: "ghost", ...getForwardProps({ calendars }), children: "Next" }), jsx(Button$1, { variant: "ghost", ...getForwardProps({
868
+ calendars,
869
+ offset: 12,
870
+ }), children: ">>" })] }), jsx(Grid, { templateColumns: "repeat(2, auto)", justifyContent: "center", gap: 4, children: calendars.map((calendar) => (jsxs(Grid, { gap: 4, children: [jsxs(Grid, { justifyContent: "center", children: [monthNamesFull[calendar.month], " ", calendar.year] }), jsx(Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: [0, 1, 2, 3, 4, 5, 6].map((weekdayNum) => {
871
+ const weekday = (weekdayNum + firstDayOfWeek) % 7;
872
+ return (jsx(Box, { minWidth: "48px", textAlign: "center", children: weekdayNamesShort$1[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
873
+ }) }), jsx(Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: calendar.weeks.map((week, windex) => week.map((dateObj, index) => {
874
+ const key = `${calendar.month}${calendar.year}${windex}${index}`;
875
+ if (!dateObj) {
876
+ return jsx(Box, {}, key);
877
+ }
878
+ const { date, selected, selectable, today } = dateObj;
879
+ const getStyle = ({ selected, unavailable, today, isInRange, }) => {
880
+ if (unavailable) {
881
+ return {
882
+ colorPalette: "gray",
883
+ variant: "solid",
884
+ };
885
+ }
886
+ if (selected) {
887
+ return {
888
+ colorPalette: "blue",
889
+ variant: "solid",
890
+ };
891
+ }
892
+ if (isInRange) {
893
+ return {
894
+ colorPalette: "blue",
895
+ variant: "subtle",
896
+ };
897
+ }
898
+ if (today) {
899
+ return {
900
+ colorPalette: "green",
901
+ variant: "solid",
902
+ };
903
+ }
904
+ return { variant: "ghost" };
905
+ };
906
+ return (jsx(Button$1, { ...getDateProps({
907
+ dateObj,
908
+ onMouseEnter: () => {
909
+ onMouseEnter(date);
910
+ },
911
+ }), ...getStyle({
912
+ selected,
913
+ unavailable: !selectable,
914
+ today,
915
+ isInRange: isInRange(date),
916
+ }), children: selectable ? date.getDate() : "X" }, key));
917
+ })) })] }, `${calendar.month}${calendar.year}`))) })] }));
918
+ }
919
+ return null;
920
+ }
921
+ class RangeDatePicker extends React__default.Component {
922
+ render() {
923
+ return (jsx(Dayzed, { onDateSelected: this.props.onDateSelected, selected: this.props.selected, firstDayOfWeek: this.props.firstDayOfWeek, showOutsideDays: this.props.showOutsideDays, date: this.props.date, minDate: this.props.minDate, maxDate: this.props.maxDate, monthsToDisplay: this.props.monthsToDisplay, render: (dayzedData) => (jsx(Calendar$1, { ...dayzedData,
924
+ firstDayOfWeek: this.props.firstDayOfWeek,
925
+ selected: this.props.selected })) }));
926
+ }
927
+ }
928
+
929
+ const getRangeDates = ({ selectable, date, selectedDates, }) => {
930
+ if (!selectable) {
931
+ return;
932
+ }
933
+ const dateTime = date.getTime();
934
+ const newDates = [...selectedDates];
935
+ if (selectedDates.length) {
936
+ if (selectedDates.length === 1) {
937
+ const firstTime = selectedDates[0].getTime();
938
+ if (firstTime < dateTime) {
939
+ newDates.push(date);
940
+ }
941
+ else {
942
+ newDates.unshift(date);
943
+ }
944
+ return newDates;
945
+ }
946
+ else if (newDates.length === 2) {
947
+ return [date];
948
+ }
949
+ }
950
+ else {
951
+ newDates.push(date);
952
+ return newDates;
953
+ }
797
954
  };
798
955
 
799
956
  const Slider = React.forwardRef(function Slider(props, ref) {
@@ -840,19 +997,10 @@ const TagFilter = ({ availableTags, selectedTags, onTagChange, }) => {
840
997
  return (jsx(Flex, { flexFlow: "wrap", p: "0.5rem", gap: "0.5rem", children: availableTags.map((tag) => (jsx(Tag, { variant: selectedTags.includes(tag) ? "solid" : "outline", cursor: "pointer", closable: selectedTags.includes(tag) ? true : undefined, onClick: () => toggleTag(tag), children: tag }))) }));
841
998
  };
842
999
 
843
- const Radio = React.forwardRef(function Radio(props, ref) {
844
- const { children, inputProps, rootRef, ...rest } = props;
845
- 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 }))] }));
846
- });
847
- const RadioGroup = RadioGroup$1.Root;
848
-
849
1000
  const Filter = ({ column }) => {
850
1001
  const { filterVariant } = column.columnDef.meta ?? {};
851
1002
  const displayName = column.columnDef.meta?.displayName ?? column.id;
852
1003
  const filterOptions = column.columnDef.meta?.filterOptions ?? [];
853
- // const collection = createListCollection({
854
- // items: filterOptions,
855
- // });
856
1004
  if (column.columns.length > 0) {
857
1005
  return (jsxs(Flex, { flexFlow: "column", gap: 1, children: [jsx(Text, { children: displayName }), jsx(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(20rem, 1fr))", gap: 1, children: column.columns.map((column) => {
858
1006
  return jsx(Filter, { column: column }, column.id);
@@ -900,17 +1048,15 @@ const Filter = ({ column }) => {
900
1048
  }, defaultValue: defaultValue, min: min, max: max, step: step })] }, column.id));
901
1049
  }
902
1050
  if (filterVariant === "dateRange") {
903
- const [start, end] = column.getFilterValue() ?? [
904
- "",
905
- "",
906
- ];
907
- return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsx(DateRangeFilter, { startDate: start, endDate: end, setStartDate: function (value) {
908
- column.setFilterValue((state) => {
909
- return [value, (state ?? ["", ""])[1]];
910
- });
911
- }, setEndDate: function (value) {
912
- column.setFilterValue((state) => {
913
- return [(state ?? ["", ""])[0], value];
1051
+ const filterValue = column.getFilterValue() ?? [];
1052
+ return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsx(RangeDatePicker, { selected: filterValue, onDateSelected: ({ selected, selectable, date }) => {
1053
+ const newDates = getRangeDates({
1054
+ selectable,
1055
+ date,
1056
+ selectedDates: filterValue,
1057
+ }) ?? [];
1058
+ column.setFilterValue(() => {
1059
+ return newDates;
914
1060
  });
915
1061
  } })] }, column.id));
916
1062
  }
@@ -1369,7 +1515,7 @@ const SchemaFormContext = createContext({
1369
1515
  serverUrl: "",
1370
1516
  order: [],
1371
1517
  ignore: [],
1372
- onSubmit: () => { },
1518
+ onSubmit: async () => { },
1373
1519
  preLoadedValues: {},
1374
1520
  rowNumber: 0,
1375
1521
  displayText: {},
@@ -1422,12 +1568,12 @@ const useSchemaContext = () => {
1422
1568
  };
1423
1569
  };
1424
1570
 
1425
- const getTableData = async ({ serverUrl, in_table, searching = '', where = [], limit = 10, }) => {
1571
+ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, }) => {
1426
1572
  if (serverUrl === undefined || serverUrl.length == 0) {
1427
- throw new Error('The serverUrl is missing');
1573
+ throw new Error("The serverUrl is missing");
1428
1574
  }
1429
1575
  if (in_table === undefined || in_table.length == 0) {
1430
- throw new Error('The in_table is missing');
1576
+ throw new Error("The in_table is missing");
1431
1577
  }
1432
1578
  const options = {
1433
1579
  method: "GET",
@@ -1453,8 +1599,8 @@ const getTableData = async ({ serverUrl, in_table, searching = '', where = [], l
1453
1599
  }
1454
1600
  };
1455
1601
 
1456
- const IdPicker = ({ column, in_table, column_ref, display_column, }) => {
1457
- const { formState: { errors }, setValue, } = useFormContext();
1602
+ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = false, }) => {
1603
+ const { watch, formState: { errors }, setValue, } = useFormContext();
1458
1604
  const { schema, serverUrl, displayText } = useSchemaContext();
1459
1605
  const { fieldRequired } = displayText;
1460
1606
  const { required } = schema;
@@ -1463,7 +1609,7 @@ const IdPicker = ({ column, in_table, column_ref, display_column, }) => {
1463
1609
  throw new Error("schema properties when using DatePicker");
1464
1610
  }
1465
1611
  const { gridColumn, gridRow, title } = schema.properties[column];
1466
- const [selectedId, setSelectedId] = useState();
1612
+ const [selectedIds, setSelectedIds] = useState([]);
1467
1613
  const [searchText, setSearchText] = useState();
1468
1614
  const [limit, setLimit] = useState(10);
1469
1615
  const [openSearchResult, setOpenSearchResult] = useState();
@@ -1509,31 +1655,37 @@ const IdPicker = ({ column, in_table, column_ref, display_column, }) => {
1509
1655
  ];
1510
1656
  }));
1511
1657
  };
1512
- const getSelectedName = () => {
1513
- const selectedItem = getIdMap(dataList)[selectedId ?? ""];
1658
+ const getSelectedName = (id) => {
1659
+ const selectedItem = getIdMap(dataList)[id];
1514
1660
  if (selectedItem == undefined) {
1515
1661
  return "";
1516
1662
  }
1517
1663
  return selectedItem[display_column];
1518
1664
  };
1519
- if (selectedId != undefined) {
1665
+ if (selectedIds.length >= 1 && isMultiple === false) {
1520
1666
  return (jsx(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, gridColumn,
1521
1667
  gridRow, children: jsx(Tag, { closable: true, onClick: () => {
1522
- setSelectedId(undefined);
1668
+ setSelectedIds([]);
1523
1669
  setValue(column, "");
1524
- }, children: getSelectedName() }) }));
1670
+ }, children: getSelectedName(selectedIds[0]) }) }));
1525
1671
  }
1526
1672
  return (jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
1527
- gridRow, children: [jsx(Input, { placeholder: "Type to search", onChange: (event) => {
1673
+ gridRow, children: [selectedIds.map((id) => {
1674
+ return (jsx(Tag, { closable: true, onClick: () => {
1675
+ setSelectedIds([]);
1676
+ setValue(column, "");
1677
+ }, children: getSelectedName(id) }));
1678
+ }), jsx(Input, { placeholder: "Type to search", onChange: (event) => {
1528
1679
  onSearchChange(event);
1529
1680
  setOpenSearchResult(true);
1530
- }, autoComplete: "off", ref: ref }), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsxs(RadioCardRoot, { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [isFetching && jsx(Fragment, { children: "isFetching" }), isLoading && jsx(Fragment, { children: "isLoading" }), isPending && jsx(Fragment, { children: "isPending" }), isError && jsx(Fragment, { children: "isError" }), jsx(Text, { children: `Search Result: ${count}, Showing ${limit}` }), jsx(Button, { onClick: async () => {
1681
+ }, autoComplete: "off", ref: ref }), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsxs(RadioCardRoot, { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [isFetching && jsx(Fragment, { children: "isFetching" }), isLoading && jsx(Fragment, { children: "isLoading" }), isPending && jsx(Fragment, { children: "isPending" }), isError && jsx(Fragment, { children: "isError" }), jsx(Text, { children: `Search Result: ${count}, Showing ${limit}` }), jsx(Button, { onClick: async () => {
1531
1682
  setOpenSearchResult(false);
1532
1683
  }, children: "close" }),
1533
1684
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1534
1685
  getItemList(dataList).map((item) => (jsx(RadioCardItem, { label: item.label, description: item.description, value: item.value, onClick: () => {
1535
- setSelectedId(item.key);
1536
- setValue(column, item.key);
1686
+ const ids = watch(column);
1687
+ setSelectedIds((state) => [...state, item.key]);
1688
+ setValue(column, [...(ids ?? []), item.key]);
1537
1689
  setOpenSearchResult(false);
1538
1690
  }, indicator: false }, item.key))), isDirty && (jsxs(Fragment, { children: [dataList.length <= 0 && jsx(Fragment, { children: "Empty Search Result" }), " ", count > dataList.length && (jsx(Fragment, { children: jsx(Button, { onClick: async () => {
1539
1691
  setLimit((limit) => limit + 10);
@@ -1679,8 +1831,8 @@ const monthNamesShort = [
1679
1831
  "Nov",
1680
1832
  "Dec",
1681
1833
  ];
1682
- const weekdayNamesShort$1 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1683
- const Calendar$1 = ({ calendars, getBackProps, getForwardProps, getDateProps, firstDayOfWeek = 0, }) => {
1834
+ const weekdayNamesShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1835
+ const Calendar = ({ calendars, getBackProps, getForwardProps, getDateProps, firstDayOfWeek = 0, }) => {
1684
1836
  if (calendars.length) {
1685
1837
  return (jsxs(Grid, { children: [jsxs(Grid, { templateColumns: "repeat(4, auto)", justifyContent: "center", children: [jsx(Button$1, { variant: "ghost", ...getBackProps({
1686
1838
  calendars,
@@ -1690,7 +1842,7 @@ const Calendar$1 = ({ calendars, getBackProps, getForwardProps, getDateProps, fi
1690
1842
  offset: 12,
1691
1843
  }), children: ">>" })] }), jsx(Grid, { templateColumns: "repeat(2, auto)", justifyContent: "center", children: calendars.map((calendar) => (jsxs(Grid, { gap: 4, children: [jsxs(Grid, { justifyContent: "center", children: [monthNamesShort[calendar.month], " ", calendar.year] }), jsxs(Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: [[0, 1, 2, 3, 4, 5, 6].map((weekdayNum) => {
1692
1844
  const weekday = (weekdayNum + firstDayOfWeek) % 7;
1693
- return (jsx(Text, { textAlign: "center", children: weekdayNamesShort$1[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
1845
+ return (jsx(Text, { textAlign: "center", children: weekdayNamesShort[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
1694
1846
  }), calendar.weeks.map((week, weekIndex) => week.map((dateObj, index) => {
1695
1847
  const key = `${calendar.month}${calendar.year}${weekIndex}${index}`;
1696
1848
  if (!dateObj) {
@@ -1711,13 +1863,13 @@ const Calendar$1 = ({ calendars, getBackProps, getForwardProps, getDateProps, fi
1711
1863
  };
1712
1864
  const getVariant = ({ today, selected, selectable, }) => {
1713
1865
  if (!selectable) {
1714
- return "solid";
1866
+ return "surface";
1715
1867
  }
1716
1868
  if (selected) {
1717
1869
  return "solid";
1718
1870
  }
1719
1871
  if (today) {
1720
- return "solid";
1872
+ return "surface";
1721
1873
  }
1722
1874
  return "ghost";
1723
1875
  };
@@ -1730,7 +1882,7 @@ const Calendar$1 = ({ calendars, getBackProps, getForwardProps, getDateProps, fi
1730
1882
  };
1731
1883
  let DatePicker$1 = class DatePicker extends React__default.Component {
1732
1884
  render() {
1733
- return (jsx(Dayzed, { onDateSelected: this.props.onDateSelected, selected: this.props.selected, firstDayOfWeek: this.props.firstDayOfWeek, showOutsideDays: this.props.showOutsideDays, date: this.props.date, minDate: this.props.minDate, maxDate: this.props.maxDate, monthsToDisplay: this.props.monthsToDisplay, render: (dayzedData) => (jsx(Calendar$1, { ...dayzedData, firstDayOfWeek: this.props.firstDayOfWeek })) }));
1885
+ return (jsx(Dayzed, { onDateSelected: this.props.onDateSelected, selected: this.props.selected, firstDayOfWeek: this.props.firstDayOfWeek, showOutsideDays: this.props.showOutsideDays, date: this.props.date, minDate: this.props.minDate, maxDate: this.props.maxDate, monthsToDisplay: this.props.monthsToDisplay, render: (dayzedData) => (jsx(Calendar, { ...dayzedData, firstDayOfWeek: this.props.firstDayOfWeek })) }));
1734
1886
  }
1735
1887
  };
1736
1888
 
@@ -1814,8 +1966,164 @@ const ObjectInput = ({ column }) => {
1814
1966
  }, children: addNew ?? "Add New" }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
1815
1967
  };
1816
1968
 
1969
+ const TagPicker = ({ column }) => {
1970
+ const { watch, formState: { errors }, setValue, } = useFormContext();
1971
+ const { schema, serverUrl } = useSchemaContext();
1972
+ if (schema.properties == undefined) {
1973
+ throw new Error("schema properties undefined when using DatePicker");
1974
+ }
1975
+ const { gridColumn, gridRow, in_table, object_id_column } = schema.properties[column];
1976
+ if (in_table === undefined) {
1977
+ throw new Error("in_table is undefined when using TagPicker");
1978
+ }
1979
+ if (object_id_column === undefined) {
1980
+ throw new Error("object_id_column is undefined when using TagPicker");
1981
+ }
1982
+ const query = useQuery({
1983
+ queryKey: [`tagpicker`, in_table],
1984
+ queryFn: async () => {
1985
+ return await getTableData({
1986
+ serverUrl,
1987
+ in_table: "tables_tags_view",
1988
+ where: [
1989
+ {
1990
+ id: "table_name",
1991
+ value: [in_table],
1992
+ },
1993
+ ],
1994
+ limit: 100,
1995
+ });
1996
+ },
1997
+ staleTime: 10000,
1998
+ });
1999
+ const object_id = watch(object_id_column);
2000
+ const existingTagsQuery = useQuery({
2001
+ queryKey: [`existing`, in_table, object_id_column, object_id],
2002
+ queryFn: async () => {
2003
+ return await getTableData({
2004
+ serverUrl,
2005
+ in_table: in_table,
2006
+ where: [
2007
+ {
2008
+ id: object_id_column,
2009
+ value: [object_id],
2010
+ },
2011
+ ],
2012
+ limit: 100,
2013
+ });
2014
+ },
2015
+ enabled: object_id != undefined,
2016
+ staleTime: 10000,
2017
+ });
2018
+ const { isLoading, isFetching, data, isPending, isError } = query;
2019
+ const dataList = data?.data ?? [];
2020
+ const existingTagList = existingTagsQuery.data?.data ?? [];
2021
+ if (!!object_id === false) {
2022
+ return jsx(Fragment, {});
2023
+ }
2024
+ return (jsxs(Flex, { flexFlow: "column", gap: 4, gridColumn,
2025
+ gridRow, children: [isFetching && jsx(Fragment, { children: "isFetching" }), isLoading && jsx(Fragment, { children: "isLoading" }), isPending && jsx(Fragment, { children: "isPending" }), isError && jsx(Fragment, { children: "isError" }), dataList.map(({ parent_tag_name, all_tags, is_mutually_exclusive }) => {
2026
+ return (jsxs(Flex, { flexFlow: "column", gap: 2, children: [jsx(Text, { children: parent_tag_name }), is_mutually_exclusive && (jsx(RadioCardRoot, { defaultValue: "next", variant: "surface", onValueChange: (tagIds) => {
2027
+ const existedTags = Object.values(all_tags)
2028
+ .filter(({ id }) => {
2029
+ return existingTagList.some(({ tag_id }) => tag_id === id);
2030
+ })
2031
+ .map(({ id }) => {
2032
+ return id;
2033
+ });
2034
+ setValue(`${column}.${parent_tag_name}.current`, [
2035
+ tagIds.value,
2036
+ ]);
2037
+ setValue(`${column}.${parent_tag_name}.old`, existedTags);
2038
+ }, children: jsx(Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
2039
+ if (existingTagList.some(({ tag_id }) => tag_id === id)) {
2040
+ return (jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", disabled: true }, `${tagName}-${id}`));
2041
+ }
2042
+ return (jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", colorPalette: "blue" }, `${tagName}-${id}`));
2043
+ }) }) })), !is_mutually_exclusive && (jsx(CheckboxGroup, { onValueChange: (tagIds) => {
2044
+ setValue(`${column}.${parent_tag_name}.current`, tagIds);
2045
+ }, children: jsx(Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
2046
+ if (existingTagList.some(({ tag_id }) => tag_id === id)) {
2047
+ return (jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%", disabled: true, colorPalette: "blue" }, `${tagName}-${id}`));
2048
+ }
2049
+ return (jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%" }, `${tagName}-${id}`));
2050
+ }) }) }))] }));
2051
+ }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
2052
+ };
2053
+
2054
+ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }, placeholder = "Drop files here or click to upload", }) => {
2055
+ const ref = useRef(null);
2056
+ const [isDraggedOver, setIsDraggedOver] = useState(false);
2057
+ useEffect(() => {
2058
+ const el = ref.current;
2059
+ invariant(el);
2060
+ return dropTargetForExternal({
2061
+ element: el,
2062
+ onDragEnter: () => setIsDraggedOver(true),
2063
+ onDragLeave: () => setIsDraggedOver(false),
2064
+ // canDrop: some(containsFiles, containsText),
2065
+ onDrop: ({ source }) => {
2066
+ const files = getFiles({ source });
2067
+ const text = getText({ source });
2068
+ console.log(files, text, "dfposa");
2069
+ onDrop({ files, text });
2070
+ },
2071
+ });
2072
+ }, [onDrop]);
2073
+ // const isDark = (location + location) % 2 === 1;
2074
+ function getColor(isDraggedOver) {
2075
+ if (isDraggedOver) {
2076
+ return {
2077
+ backgroundColor: "blue.400",
2078
+ _dark: {
2079
+ backgroundColor: "blue.400",
2080
+ },
2081
+ };
2082
+ }
2083
+ // return isDark ? "lightgrey" : "white";
2084
+ return {
2085
+ backgroundColor: undefined,
2086
+ _dark: {
2087
+ backgroundColor: undefined,
2088
+ },
2089
+ };
2090
+ }
2091
+ const fileInput = useRef(null);
2092
+ const handleClick = () => {
2093
+ fileInput.current?.click();
2094
+ };
2095
+ const handleChange = (event) => {
2096
+ // @ts-expect-error find appropriate types for event target files
2097
+ const filesArray = [...event.target.files];
2098
+ onDrop({ files: filesArray });
2099
+ };
2100
+ return (jsxs(Grid, { ...getColor(isDraggedOver), ref: ref, cursor: "pointer", onClick: handleClick, borderStyle: "dashed", borderColor: "gray.400", alignContent: "center", justifyContent: "center", borderWidth: 1, borderRadius: 4, ...gridProps, children: [children, !!children === false && (jsxs(Fragment, { children: [jsx(Flex, { children: placeholder }), jsx(Input, { type: "file", multiple: true, style: { display: "none" }, ref: fileInput, onChange: handleChange })] }))] }));
2101
+ };
2102
+
2103
+ const FilePicker = ({ column }) => {
2104
+ const { setValue, formState: { errors }, watch, } = useFormContext();
2105
+ const { schema, displayText } = useSchemaContext();
2106
+ const { fieldRequired } = displayText;
2107
+ const { required } = schema;
2108
+ const isRequired = required?.some((columnId) => columnId === column);
2109
+ if (schema.properties == undefined) {
2110
+ throw new Error("schema properties when using String Input Field");
2111
+ }
2112
+ const { gridColumn, gridRow, title } = schema.properties[column];
2113
+ const currentFiles = (watch(column) ?? []);
2114
+ return (jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: 'auto 1fr auto', alignItems: 'stretch', children: [jsx(FileDropzone, { onDrop: ({ files }) => {
2115
+ const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
2116
+ setValue(column, [...currentFiles, ...newFiles]);
2117
+ } }), jsx(Flex, { flexFlow: "wrap", alignItems: "start", gap: 1, children: currentFiles.map((file) => {
2118
+ return (jsx(Tag, { cursor: "pointer", onClick: () => {
2119
+ setValue(column, currentFiles.filter(({ name }) => {
2120
+ return name !== file.name;
2121
+ }));
2122
+ }, children: file.name }));
2123
+ }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
2124
+ };
2125
+
1817
2126
  const idPickerSanityCheck = (column, in_table, column_ref, display_column) => {
1818
- console.log(!!in_table, "okgsd");
1819
2127
  if (!!in_table == false) {
1820
2128
  throw new Error(`The key in_table does not exist in properties of column ${column}.`);
1821
2129
  }
@@ -1849,19 +2157,10 @@ const FormInternal = () => {
1849
2157
  const onSubmitSuccess = () => {
1850
2158
  setIsSuccess(true);
1851
2159
  };
1852
- const defaultOnSubmit = async (data) => {
1853
- const options = {
1854
- method: "POST",
1855
- url: `${serverUrl}/api/g/${schema.title}`,
1856
- headers: {
1857
- Apikey: "YOUR_SECRET_TOKEN",
1858
- "Content-Type": "application/json",
1859
- },
1860
- data: clearEmptyString(data),
1861
- };
2160
+ const defaultOnSubmit = async (promise) => {
1862
2161
  try {
1863
2162
  onBeforeSubmit();
1864
- await axios.request(options);
2163
+ await promise;
1865
2164
  onSubmitSuccess();
1866
2165
  }
1867
2166
  catch (error) {
@@ -1873,13 +2172,25 @@ const FormInternal = () => {
1873
2172
  onAfterSubmit();
1874
2173
  }
1875
2174
  };
2175
+ const defaultSubmitPromise = (data) => {
2176
+ const options = {
2177
+ method: "POST",
2178
+ url: `${serverUrl}/api/g/${schema.title}`,
2179
+ headers: {
2180
+ Apikey: "YOUR_SECRET_TOKEN",
2181
+ "Content-Type": "application/json",
2182
+ },
2183
+ data: clearEmptyString(data),
2184
+ };
2185
+ return axios.request(options);
2186
+ };
1876
2187
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1877
2188
  const onFormSubmit = async (data) => {
1878
2189
  if (onSubmit === undefined) {
1879
- defaultOnSubmit(data);
2190
+ await defaultOnSubmit(defaultSubmitPromise(data));
1880
2191
  return;
1881
2192
  }
1882
- onSubmit(data);
2193
+ await defaultOnSubmit(onSubmit(data));
1883
2194
  };
1884
2195
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1885
2196
  const onValid = (data) => {
@@ -1971,7 +2282,18 @@ const FormInternal = () => {
1971
2282
  return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
1972
2283
  }
1973
2284
  if (type === "array") {
1974
- return jsx(Fragment, { children: `array ${column}` });
2285
+ if (variant === "tag-picker") {
2286
+ const value = (validatedData ?? {})[column];
2287
+ return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${snakeToLabel(column)}`, ...getDataListProps(JSON.stringify(value)) }, `form-${key}`));
2288
+ }
2289
+ if (variant === "file-picker") {
2290
+ const fileNames = ((validatedData ?? {})[column] ?? []).map((file) => {
2291
+ return file.name;
2292
+ });
2293
+ return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps(JSON.stringify(fileNames)) }, `form-${key}`));
2294
+ }
2295
+ const objectString = JSON.stringify((validatedData ?? {})[column]);
2296
+ return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps(objectString) }, `form-${key}`));
1975
2297
  }
1976
2298
  if (type === "null") {
1977
2299
  return jsx(Fragment, { children: `null ${column}` });
@@ -2017,6 +2339,16 @@ const FormInternal = () => {
2017
2339
  return (jsx(Fragment, { children: jsx(ObjectInput, { column: key }, `form-${key}`) }));
2018
2340
  }
2019
2341
  if (type === "array") {
2342
+ if (variant === "id-picker") {
2343
+ idPickerSanityCheck(column, in_table, column_ref, display_column);
2344
+ return (jsx(IdPicker, { column: key, in_table: in_table, column_ref: column_ref, display_column: display_column, isMultiple: true }, `form-${key}`));
2345
+ }
2346
+ if (variant === "tag-picker") {
2347
+ return jsx(TagPicker, { column: key }, `form-${key}`);
2348
+ }
2349
+ if (variant === "file-picker") {
2350
+ return jsx(FilePicker, { column: key }, `form-${key}`);
2351
+ }
2020
2352
  return jsx(Fragment, { children: `array ${column}` });
2021
2353
  }
2022
2354
  if (type === "null") {
@@ -2063,137 +2395,4 @@ const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) =
2063
2395
  }
2064
2396
  };
2065
2397
 
2066
- const getRangeDates = ({ selectable, date, selectedDates, }) => {
2067
- if (!selectable) {
2068
- return;
2069
- }
2070
- const dateTime = date.getTime();
2071
- const newDates = [...selectedDates];
2072
- if (selectedDates.length) {
2073
- if (selectedDates.length === 1) {
2074
- const firstTime = selectedDates[0].getTime();
2075
- if (firstTime < dateTime) {
2076
- newDates.push(date);
2077
- }
2078
- else {
2079
- newDates.unshift(date);
2080
- }
2081
- return newDates;
2082
- }
2083
- else if (newDates.length === 2) {
2084
- return [date];
2085
- }
2086
- }
2087
- else {
2088
- newDates.push(date);
2089
- return newDates;
2090
- }
2091
- };
2092
-
2093
- const monthNamesFull = [
2094
- "January",
2095
- "February",
2096
- "March",
2097
- "April",
2098
- "May",
2099
- "June",
2100
- "July",
2101
- "August",
2102
- "September",
2103
- "October",
2104
- "November",
2105
- "December",
2106
- ];
2107
- const weekdayNamesShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
2108
- function Calendar({ calendars, getBackProps, getForwardProps, getDateProps, selected = [], firstDayOfWeek = 0, }) {
2109
- const [hoveredDate, setHoveredDate] = useState();
2110
- const onMouseLeave = () => {
2111
- setHoveredDate(undefined);
2112
- };
2113
- const onMouseEnter = (date) => {
2114
- setHoveredDate(date);
2115
- };
2116
- const isInRange = (date) => {
2117
- if (selected.length) {
2118
- const firstSelected = selected[0].getTime();
2119
- if (selected.length === 2) {
2120
- const secondSelected = selected[1].getTime();
2121
- return (firstSelected < date.getTime() && secondSelected > date.getTime());
2122
- }
2123
- else {
2124
- return !!(hoveredDate &&
2125
- ((firstSelected < date.getTime() &&
2126
- hoveredDate.getTime() >= date.getTime()) ||
2127
- (date.getTime() < firstSelected &&
2128
- date.getTime() >= hoveredDate.getTime())));
2129
- }
2130
- }
2131
- return false;
2132
- };
2133
- if (calendars.length) {
2134
- return (jsxs(Grid, { onMouseLeave: onMouseLeave, children: [jsxs(Grid, { templateColumns: "repeat(4, auto)", justifyContent: "center", children: [jsx(Button$1, { variant: "ghost", ...getBackProps({
2135
- calendars,
2136
- offset: 12,
2137
- }), children: "<<" }), jsx(Button$1, { variant: "ghost", ...getBackProps({ calendars }), children: "Back" }), jsx(Button$1, { variant: "ghost", ...getForwardProps({ calendars }), children: "Next" }), jsx(Button$1, { variant: "ghost", ...getForwardProps({
2138
- calendars,
2139
- offset: 12,
2140
- }), children: ">>" })] }), jsx(Grid, { templateColumns: "repeat(2, auto)", justifyContent: "center", gap: 4, children: calendars.map((calendar) => (jsxs(Grid, { gap: 4, children: [jsxs(Grid, { justifyContent: "center", children: [monthNamesFull[calendar.month], " ", calendar.year] }), jsx(Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: [0, 1, 2, 3, 4, 5, 6].map((weekdayNum) => {
2141
- const weekday = (weekdayNum + firstDayOfWeek) % 7;
2142
- return (jsx(Box, { minWidth: "48px", textAlign: 'center', children: weekdayNamesShort[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
2143
- }) }), jsx(Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: calendar.weeks.map((week, windex) => week.map((dateObj, index) => {
2144
- const key = `${calendar.month}${calendar.year}${windex}${index}`;
2145
- if (!dateObj) {
2146
- return jsx(Box, {}, key);
2147
- }
2148
- const { date, selected, selectable, today } = dateObj;
2149
- const getStyle = ({ selected, unavailable, today, isInRange, }) => {
2150
- if (unavailable) {
2151
- return {
2152
- colorPalette: "gray",
2153
- variant: "solid",
2154
- };
2155
- }
2156
- if (selected) {
2157
- return {
2158
- colorPalette: "blue",
2159
- variant: "solid",
2160
- };
2161
- }
2162
- if (isInRange) {
2163
- return {
2164
- colorPalette: "blue",
2165
- variant: "subtle",
2166
- };
2167
- }
2168
- if (today) {
2169
- return {
2170
- colorPalette: "green",
2171
- variant: "solid",
2172
- };
2173
- }
2174
- return { variant: "ghost" };
2175
- };
2176
- return (jsx(Button$1, { ...getDateProps({
2177
- dateObj,
2178
- onMouseEnter: () => {
2179
- onMouseEnter(date);
2180
- },
2181
- }), ...getStyle({
2182
- selected,
2183
- unavailable: !selectable,
2184
- today,
2185
- isInRange: isInRange(date),
2186
- }), children: selectable ? date.getDate() : "X" }, key));
2187
- })) })] }, `${calendar.month}${calendar.year}`))) })] }));
2188
- }
2189
- return null;
2190
- }
2191
- class RangeDatePicker extends React__default.Component {
2192
- render() {
2193
- return (jsx(Dayzed, { onDateSelected: this.props.onDateSelected, selected: this.props.selected, firstDayOfWeek: this.props.firstDayOfWeek, showOutsideDays: this.props.showOutsideDays, date: this.props.date, minDate: this.props.minDate, maxDate: this.props.maxDate, monthsToDisplay: this.props.monthsToDisplay, render: (dayzedData) => (jsx(Calendar, { ...dayzedData,
2194
- firstDayOfWeek: this.props.firstDayOfWeek,
2195
- selected: this.props.selected })) }));
2196
- }
2197
- }
2198
-
2199
2398
  export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultTable, DensityToggleButton, EditFilterButton, EditOrderButton, EditSortingButton, EditViewButton, FilterOptions, Form, GlobalFilter, PageSizeControl, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TablePagination, TableSelector, TableSorter, TableViewer, TextCell, getColumns, getMultiDates, getRangeDates, useDataTable, useDataTableContext, useDataTableServer, widthSanityCheck };