@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.js CHANGED
@@ -16,6 +16,7 @@ var gr = require('react-icons/gr');
16
16
  var reactQuery = require('@tanstack/react-query');
17
17
  var io5 = require('react-icons/io5');
18
18
  var hi = require('react-icons/hi');
19
+ var Dayzed = require('@bsol-oss/dayzed-react19');
19
20
  var fa6 = require('react-icons/fa6');
20
21
  var cg = require('react-icons/cg');
21
22
  var adapter = require('@atlaskit/pragmatic-drag-and-drop/element/adapter');
@@ -23,7 +24,9 @@ var invariant = require('tiny-invariant');
23
24
  var axios = require('axios');
24
25
  var reactHookForm = require('react-hook-form');
25
26
  var dayjs = require('dayjs');
26
- var Dayzed = require('@bsol-oss/dayzed-react19');
27
+ var adapter$1 = require('@atlaskit/pragmatic-drag-and-drop/external/adapter');
28
+ var file = require('@atlaskit/pragmatic-drag-and-drop/external/file');
29
+ var text = require('@atlaskit/pragmatic-drag-and-drop/external/text');
27
30
 
28
31
  function _interopNamespaceDefault(e) {
29
32
  var n = Object.create(null);
@@ -169,7 +172,7 @@ const ResetSortingButton = ({ text = "Reset Sorting", }) => {
169
172
 
170
173
  const RowCountText = () => {
171
174
  const { table } = useDataTableContext();
172
- return jsxRuntime.jsx(react.Text, { children: table.getRowCount() });
175
+ return jsxRuntime.jsx(react.Text, { children: table.getFilteredRowModel().flatRows.length ?? 0 });
173
176
  };
174
177
 
175
178
  const { withContext } = react.createRecipeContext({ key: "button" });
@@ -239,7 +242,7 @@ React__namespace.forwardRef(function PaginationPageText(props, ref) {
239
242
  // TODO: not working in client side
240
243
  const TablePagination = () => {
241
244
  const { table } = useDataTableContext();
242
- return (jsxRuntime.jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: table.getRowCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
245
+ return (jsxRuntime.jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: table.getFilteredRowModel().flatRows.length ?? 0, pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
243
246
  table.setPageIndex(e.page - 1);
244
247
  }, children: jsxRuntime.jsxs(react.HStack, { children: [jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationItems, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) }));
245
248
  };
@@ -284,20 +287,20 @@ const DataDisplay = ({ variant = "" }) => {
284
287
  if (variant == "horizontal") {
285
288
  return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
286
289
  return (jsxRuntime.jsx(react.Card.Root, { children: jsxRuntime.jsx(react.Card.Body, { children: jsxRuntime.jsx(react.DataList.Root, { gap: 4, padding: 4, display: "grid", variant: "subtle", orientation: "horizontal", overflow: "auto", children: row.getVisibleCells().map((cell) => {
287
- return (jsxRuntime.jsxs(react.DataList.Item, { children: [jsxRuntime.jsx(react.DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsxRuntime.jsx(react.DataList.ItemValue, { children: `${formatValue(cell.getValue())}` })] }, cell.id));
290
+ return (jsxRuntime.jsxs(react.DataList.Item, { children: [jsxRuntime.jsx(react.DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsxRuntime.jsx(react.DataList.ItemValue, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
288
291
  }) }) }) }, `chakra-table-card-${row.id}`));
289
292
  }) }));
290
293
  }
291
294
  if (variant == "stats") {
292
295
  return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
293
296
  return (jsxRuntime.jsx(react.Card.Root, { children: jsxRuntime.jsx(react.Card.Body, { children: jsxRuntime.jsx(react.DataList.Root, { gap: 4, padding: 4, display: "flex", flexFlow: "row", variant: "subtle", overflow: "auto", children: row.getVisibleCells().map((cell) => {
294
- return (jsxRuntime.jsxs(react.DataList.Item, { display: "flex", justifyContent: "center", alignItems: "center", flex: "1 0 10rem", children: [jsxRuntime.jsx(react.DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsxRuntime.jsx(react.DataList.ItemValue, { children: `${formatValue(cell.getValue())}` })] }, cell.id));
297
+ return (jsxRuntime.jsxs(react.DataList.Item, { display: "flex", justifyContent: "center", alignItems: "center", flex: "1 0 0%", children: [jsxRuntime.jsx(react.DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsxRuntime.jsx(react.DataList.ItemValue, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
295
298
  }) }) }) }, `chakra-table-card-${row.id}`));
296
299
  }) }));
297
300
  }
298
301
  return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
299
302
  return (jsxRuntime.jsx(react.Card.Root, { children: jsxRuntime.jsx(react.Card.Body, { children: jsxRuntime.jsx(react.DataList.Root, { gap: 4, padding: 4, display: "grid", variant: "subtle", gridTemplateColumns: "repeat(auto-fit, minmax(20rem, 1fr))", children: row.getVisibleCells().map((cell) => {
300
- return (jsxRuntime.jsxs(react.DataList.Item, { children: [jsxRuntime.jsx(react.DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsxRuntime.jsx(react.DataList.ItemValue, { children: `${formatValue(cell.getValue())}` })] }, cell.id));
303
+ return (jsxRuntime.jsxs(react.DataList.Item, { children: [jsxRuntime.jsx(react.DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsxRuntime.jsx(react.DataList.ItemValue, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
301
304
  }) }) }) }, `chakra-table-card-${row.id}`));
302
305
  }) }));
303
306
  };
@@ -450,7 +453,7 @@ const DataTableServerContext = React.createContext({
450
453
  url: "",
451
454
  });
452
455
 
453
- 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 }) => {
456
+ 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, }) => {
454
457
  const table = reactTable.useReactTable({
455
458
  _features: [DensityFeature],
456
459
  data: query.data?.data ?? [],
@@ -510,7 +513,7 @@ const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
510
513
  return (jsxRuntime.jsxs(react.Checkbox.Root, { ref: rootRef, ...rest, children: [jsxRuntime.jsx(react.Checkbox.HiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsx(react.Checkbox.Control, { children: icon || jsxRuntime.jsx(react.Checkbox.Indicator, {}) }), children != null && (jsxRuntime.jsx(react.Checkbox.Label, { children: children }))] }));
511
514
  });
512
515
 
513
- const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, }) => {
516
+ const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, canResize = true, }) => {
514
517
  const { table } = useDataTableContext();
515
518
  const SELECTION_BOX_WIDTH = 20;
516
519
  const [hoveredRow, setHoveredRow] = React.useState(-1);
@@ -533,12 +536,25 @@ const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, sho
533
536
  : {};
534
537
  return tdProps;
535
538
  };
539
+ const getTrProps = ({ hoveredRow, index, }) => {
540
+ if (hoveredRow === -1) {
541
+ return {};
542
+ }
543
+ if (hoveredRow === index) {
544
+ return {
545
+ opacity: "1",
546
+ };
547
+ }
548
+ return {
549
+ opacity: "0.8",
550
+ };
551
+ };
536
552
  return (jsxRuntime.jsx(react.Table.Body, { children: table.getRowModel().rows.map((row, index) => {
537
- return (jsxRuntime.jsxs(react.Table.Row, { display: "flex", _hover: { backgroundColor: "rgba(178,178,178,0.1)" }, zIndex: 1, onMouseEnter: () => handleRowHover(index), onMouseLeave: () => handleRowHover(-1), children: [showSelector && (jsxRuntime.jsx(TableRowSelector, { index: index, row: row, hoveredRow: hoveredRow, alwaysShowSelector: alwaysShowSelector })), row.getVisibleCells().map((cell, index) => {
553
+ return (jsxRuntime.jsxs(react.Table.Row, { display: "flex", zIndex: 1, onMouseEnter: () => handleRowHover(index), onMouseLeave: () => handleRowHover(-1), ...getTrProps({ hoveredRow, index }), children: [showSelector && (jsxRuntime.jsx(TableRowSelector, { index: index, row: row, hoveredRow: hoveredRow, alwaysShowSelector: alwaysShowSelector })), row.getVisibleCells().map((cell, index) => {
538
554
  return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`,
539
555
  // styling resize and pinning start
540
- maxWidth: `${cell.column.getSize()}px`, width: `${cell.column.getSize()}px`, backgroundColor: "white", ...getTdProps(cell), _dark: {
541
- backgroundColor: "gray.950"
556
+ flex: `${canResize ? "0" : "1"} 0 ${cell.column.getSize()}px`, backgroundColor: "white", ...getTdProps(cell), _dark: {
557
+ backgroundColor: "gray.950",
542
558
  }, children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
543
559
  })] }, `chakra-table-row-${row.id}`));
544
560
  }) }));
@@ -570,7 +586,6 @@ const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gr
570
586
  // styling resize and pinning end
571
587
  display: "grid", children: [!isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` })), isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: row.getIsSelected(),
572
588
  disabled: !row.getCanSelect(),
573
- // indeterminate: row.getIsSomeSelected(),
574
589
  onChange: row.getToggleSelectedHandler() }) }))] }));
575
590
  };
576
591
 
@@ -649,7 +664,7 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, s
649
664
  jsxRuntime.jsx(jsxRuntime.Fragment, {})), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(bi.BiUpArrow, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(bi.BiDownArrow, {}))] })) })] }) }) }) }) }, `chakra-table-footer-${header.column.id}-${footerGroup.id}`)))] }, `chakra-table-footergroup-${footerGroup.id}`))) }));
650
665
  };
651
666
 
652
- const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, isSticky = true, alwaysShowSelector = true, tHeadProps = {}, }) => {
667
+ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, isSticky = true, alwaysShowSelector = true, tHeadProps = {}, }) => {
653
668
  const { table } = useDataTableContext();
654
669
  const SELECTION_BOX_WIDTH = 20;
655
670
  const [hoveredCheckBox, setHoveredCheckBox] = React.useState(false);
@@ -710,7 +725,12 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
710
725
  };
711
726
  return (jsxRuntime.jsxs(react.Table.ColumnHeader, { padding: 0, columnSpan: `${header.colSpan}`,
712
727
  // styling resize and pinning start
713
- width: `${header.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: header.index, ...getThProps(header), children: [jsxRuntime.jsxs(MenuRoot, { children: [jsxRuntime.jsx(MenuTrigger, { asChild: true, children: jsxRuntime.jsx(react.Grid, { padding: `${table.getDensityValue()}px`, display: "flex", alignItems: "center", justifyContent: "start", borderRadius: "0rem", overflow: "auto", _hover: { backgroundColor: "gray.100" }, children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
728
+ flex: `${canResize ? "0" : "1"} 0 ${header.column.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: header.index, ...getThProps(header), children: [jsxRuntime.jsxs(MenuRoot, { children: [jsxRuntime.jsx(MenuTrigger, { asChild: true, children: jsxRuntime.jsx(react.Flex, { padding: `${table.getDensityValue()}px`, alignItems: "center", justifyContent: "start", borderRadius: "0rem", overflow: "auto", _hover: {
729
+ backgroundColor: "gray.100",
730
+ _dark: {
731
+ backgroundColor: "gray.700",
732
+ },
733
+ }, children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
714
734
  ? null
715
735
  : reactTable.flexRender(header.column.columnDef.header, header.getContext()), jsxRuntime.jsx(react.Box, { children: header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [header.column.getIsSorted() === false && jsxRuntime.jsx(jsxRuntime.Fragment, {}), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(bi.BiUpArrow, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(bi.BiDownArrow, {}))] })) }), jsxRuntime.jsx(react.Box, { children: header.column.getIsFiltered() && jsxRuntime.jsx(md.MdFilterListAlt, {}) })] }) }) }), jsxRuntime.jsxs(MenuContent, { children: [!header.column.getIsPinned() && (jsxRuntime.jsx(MenuItem, { asChild: true, value: "pin-column", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
716
736
  header.column.pin("left");
@@ -744,8 +764,11 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
744
764
  })] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
745
765
  };
746
766
 
747
- const DefaultTable = ({ showFooter = false, showSelector = false, tableProps = {}, tHeadProps = {}, controlProps = {}, }) => {
748
- return (jsxRuntime.jsx(TableControls, { ...controlProps, children: jsxRuntime.jsxs(Table, { ...tableProps, children: [jsxRuntime.jsx(TableHeader, { canResize: true, showSelector: showSelector, tHeadProps: tHeadProps }), jsxRuntime.jsx(TableBody, { showSelector: showSelector }), showFooter && jsxRuntime.jsx(TableFooter, { showSelector: showSelector })] }) }));
767
+ const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, controlProps = {}, tableFooterProps = {}, variant = "", }) => {
768
+ if (variant === "greedy") {
769
+ return (jsxRuntime.jsx(TableControls, { ...controlProps, children: jsxRuntime.jsxs(Table, { canResize: false, ...tableProps, children: [jsxRuntime.jsx(TableHeader, { canResize: false, ...tableHeaderProps }), jsxRuntime.jsx(TableBody, { canResize: false, ...tableBodyProps }), showFooter && (jsxRuntime.jsx(TableFooter, { canResize: false, ...tableFooterProps }))] }) }));
770
+ }
771
+ return (jsxRuntime.jsx(TableControls, { ...controlProps, children: jsxRuntime.jsxs(Table, { ...tableProps, children: [jsxRuntime.jsx(TableHeader, { ...tableHeaderProps }), jsxRuntime.jsx(TableBody, { ...tableBodyProps }), showFooter && jsxRuntime.jsx(TableFooter, { ...tableFooterProps })] }) }));
749
772
  };
750
773
 
751
774
  const useDataTableServerContext = () => {
@@ -771,12 +794,12 @@ const EmptyState = React__namespace.forwardRef(function EmptyState(props, ref) {
771
794
  });
772
795
 
773
796
  const EmptyResult = (jsxRuntime.jsx(EmptyState, { icon: jsxRuntime.jsx(hi.HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxRuntime.jsxs(react.List.Root, { variant: "marker", children: [jsxRuntime.jsx(react.List.Item, { children: "Try removing filters" }), jsxRuntime.jsx(react.List.Item, { children: "Try different keywords" })] }) }));
774
- const Table = ({ children, emptyComponent = EmptyResult, ...props }) => {
797
+ const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
775
798
  const { table } = useDataTableContext();
776
799
  if (table.getRowModel().rows.length <= 0) {
777
800
  return emptyComponent;
778
801
  }
779
- return (jsxRuntime.jsx(react.Table.Root, { stickyHeader: true, variant: "outline", width: table.getCenterTotalSize(), ...props, children: children }));
802
+ return (jsxRuntime.jsx(react.Table.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, ...props, children: children }));
780
803
  };
781
804
 
782
805
  const TableCardContainer = ({ children, variant = "", ...props }) => {
@@ -811,9 +834,143 @@ const TableComponent = ({ render = () => {
811
834
  return render(table);
812
835
  };
813
836
 
814
- const DateRangeFilter = ({ startDate, endDate, setStartDate, setEndDate, }) => {
815
- console.log(startDate, endDate, "dflp");
816
- return (jsxRuntime.jsx(react.Box, { p: "1rem", children: jsxRuntime.jsxs(react.VStack, { children: [jsxRuntime.jsxs(react.Box, { children: [jsxRuntime.jsx(react.Box, { children: "Start Date" }), jsxRuntime.jsx(react.Input, { id: "start-date", type: "date", value: startDate, onChange: (e) => setStartDate(e.target.value) })] }), jsxRuntime.jsxs(react.Box, { children: [jsxRuntime.jsx(react.Box, { children: "End Date" }), jsxRuntime.jsx(react.Input, { id: "end-date", type: "date", value: endDate, onChange: (e) => setEndDate(e.target.value) })] })] }) }));
837
+ const Radio = React__namespace.forwardRef(function Radio(props, ref) {
838
+ const { children, inputProps, rootRef, ...rest } = props;
839
+ return (jsxRuntime.jsxs(react.RadioGroup.Item, { ref: rootRef, ...rest, children: [jsxRuntime.jsx(react.RadioGroup.ItemHiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsx(react.RadioGroup.ItemIndicator, {}), children && (jsxRuntime.jsx(react.RadioGroup.ItemText, { children: children }))] }));
840
+ });
841
+ const RadioGroup = react.RadioGroup.Root;
842
+
843
+ const monthNamesFull = [
844
+ "January",
845
+ "February",
846
+ "March",
847
+ "April",
848
+ "May",
849
+ "June",
850
+ "July",
851
+ "August",
852
+ "September",
853
+ "October",
854
+ "November",
855
+ "December",
856
+ ];
857
+ const weekdayNamesShort$1 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
858
+ function Calendar$1({ calendars, getBackProps, getForwardProps, getDateProps, selected = [], firstDayOfWeek = 0, }) {
859
+ const [hoveredDate, setHoveredDate] = React.useState();
860
+ const onMouseLeave = () => {
861
+ setHoveredDate(undefined);
862
+ };
863
+ const onMouseEnter = (date) => {
864
+ setHoveredDate(date);
865
+ };
866
+ const isInRange = (date) => {
867
+ if (selected.length) {
868
+ const firstSelected = selected[0].getTime();
869
+ if (selected.length === 2) {
870
+ const secondSelected = selected[1].getTime();
871
+ return (firstSelected < date.getTime() && secondSelected > date.getTime());
872
+ }
873
+ else {
874
+ return !!(hoveredDate &&
875
+ ((firstSelected < date.getTime() &&
876
+ hoveredDate.getTime() >= date.getTime()) ||
877
+ (date.getTime() < firstSelected &&
878
+ date.getTime() >= hoveredDate.getTime())));
879
+ }
880
+ }
881
+ return false;
882
+ };
883
+ if (calendars.length) {
884
+ return (jsxRuntime.jsxs(react.Grid, { onMouseLeave: onMouseLeave, children: [jsxRuntime.jsxs(react.Grid, { templateColumns: "repeat(4, auto)", justifyContent: "center", children: [jsxRuntime.jsx(react.Button, { variant: "ghost", ...getBackProps({
885
+ calendars,
886
+ offset: 12,
887
+ }), children: "<<" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getBackProps({ calendars }), children: "Back" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getForwardProps({ calendars }), children: "Next" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getForwardProps({
888
+ calendars,
889
+ offset: 12,
890
+ }), children: ">>" })] }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(2, auto)", justifyContent: "center", gap: 4, children: calendars.map((calendar) => (jsxRuntime.jsxs(react.Grid, { gap: 4, children: [jsxRuntime.jsxs(react.Grid, { justifyContent: "center", children: [monthNamesFull[calendar.month], " ", calendar.year] }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: [0, 1, 2, 3, 4, 5, 6].map((weekdayNum) => {
891
+ const weekday = (weekdayNum + firstDayOfWeek) % 7;
892
+ return (jsxRuntime.jsx(react.Box, { minWidth: "48px", textAlign: "center", children: weekdayNamesShort$1[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
893
+ }) }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: calendar.weeks.map((week, windex) => week.map((dateObj, index) => {
894
+ const key = `${calendar.month}${calendar.year}${windex}${index}`;
895
+ if (!dateObj) {
896
+ return jsxRuntime.jsx(react.Box, {}, key);
897
+ }
898
+ const { date, selected, selectable, today } = dateObj;
899
+ const getStyle = ({ selected, unavailable, today, isInRange, }) => {
900
+ if (unavailable) {
901
+ return {
902
+ colorPalette: "gray",
903
+ variant: "solid",
904
+ };
905
+ }
906
+ if (selected) {
907
+ return {
908
+ colorPalette: "blue",
909
+ variant: "solid",
910
+ };
911
+ }
912
+ if (isInRange) {
913
+ return {
914
+ colorPalette: "blue",
915
+ variant: "subtle",
916
+ };
917
+ }
918
+ if (today) {
919
+ return {
920
+ colorPalette: "green",
921
+ variant: "solid",
922
+ };
923
+ }
924
+ return { variant: "ghost" };
925
+ };
926
+ return (jsxRuntime.jsx(react.Button, { ...getDateProps({
927
+ dateObj,
928
+ onMouseEnter: () => {
929
+ onMouseEnter(date);
930
+ },
931
+ }), ...getStyle({
932
+ selected,
933
+ unavailable: !selectable,
934
+ today,
935
+ isInRange: isInRange(date),
936
+ }), children: selectable ? date.getDate() : "X" }, key));
937
+ })) })] }, `${calendar.month}${calendar.year}`))) })] }));
938
+ }
939
+ return null;
940
+ }
941
+ class RangeDatePicker extends React.Component {
942
+ render() {
943
+ return (jsxRuntime.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) => (jsxRuntime.jsx(Calendar$1, { ...dayzedData,
944
+ firstDayOfWeek: this.props.firstDayOfWeek,
945
+ selected: this.props.selected })) }));
946
+ }
947
+ }
948
+
949
+ const getRangeDates = ({ selectable, date, selectedDates, }) => {
950
+ if (!selectable) {
951
+ return;
952
+ }
953
+ const dateTime = date.getTime();
954
+ const newDates = [...selectedDates];
955
+ if (selectedDates.length) {
956
+ if (selectedDates.length === 1) {
957
+ const firstTime = selectedDates[0].getTime();
958
+ if (firstTime < dateTime) {
959
+ newDates.push(date);
960
+ }
961
+ else {
962
+ newDates.unshift(date);
963
+ }
964
+ return newDates;
965
+ }
966
+ else if (newDates.length === 2) {
967
+ return [date];
968
+ }
969
+ }
970
+ else {
971
+ newDates.push(date);
972
+ return newDates;
973
+ }
817
974
  };
818
975
 
819
976
  const Slider = React__namespace.forwardRef(function Slider(props, ref) {
@@ -860,19 +1017,10 @@ const TagFilter = ({ availableTags, selectedTags, onTagChange, }) => {
860
1017
  return (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", p: "0.5rem", gap: "0.5rem", children: availableTags.map((tag) => (jsxRuntime.jsx(Tag, { variant: selectedTags.includes(tag) ? "solid" : "outline", cursor: "pointer", closable: selectedTags.includes(tag) ? true : undefined, onClick: () => toggleTag(tag), children: tag }))) }));
861
1018
  };
862
1019
 
863
- const Radio = React__namespace.forwardRef(function Radio(props, ref) {
864
- const { children, inputProps, rootRef, ...rest } = props;
865
- return (jsxRuntime.jsxs(react.RadioGroup.Item, { ref: rootRef, ...rest, children: [jsxRuntime.jsx(react.RadioGroup.ItemHiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsx(react.RadioGroup.ItemIndicator, {}), children && (jsxRuntime.jsx(react.RadioGroup.ItemText, { children: children }))] }));
866
- });
867
- const RadioGroup = react.RadioGroup.Root;
868
-
869
1020
  const Filter = ({ column }) => {
870
1021
  const { filterVariant } = column.columnDef.meta ?? {};
871
1022
  const displayName = column.columnDef.meta?.displayName ?? column.id;
872
1023
  const filterOptions = column.columnDef.meta?.filterOptions ?? [];
873
- // const collection = createListCollection({
874
- // items: filterOptions,
875
- // });
876
1024
  if (column.columns.length > 0) {
877
1025
  return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 1, children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(20rem, 1fr))", gap: 1, children: column.columns.map((column) => {
878
1026
  return jsxRuntime.jsx(Filter, { column: column }, column.id);
@@ -920,17 +1068,15 @@ const Filter = ({ column }) => {
920
1068
  }, defaultValue: defaultValue, min: min, max: max, step: step })] }, column.id));
921
1069
  }
922
1070
  if (filterVariant === "dateRange") {
923
- const [start, end] = column.getFilterValue() ?? [
924
- "",
925
- "",
926
- ];
927
- return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(DateRangeFilter, { startDate: start, endDate: end, setStartDate: function (value) {
928
- column.setFilterValue((state) => {
929
- return [value, (state ?? ["", ""])[1]];
930
- });
931
- }, setEndDate: function (value) {
932
- column.setFilterValue((state) => {
933
- return [(state ?? ["", ""])[0], value];
1071
+ const filterValue = column.getFilterValue() ?? [];
1072
+ return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(RangeDatePicker, { selected: filterValue, onDateSelected: ({ selected, selectable, date }) => {
1073
+ const newDates = getRangeDates({
1074
+ selectable,
1075
+ date,
1076
+ selectedDates: filterValue,
1077
+ }) ?? [];
1078
+ column.setFilterValue(() => {
1079
+ return newDates;
934
1080
  });
935
1081
  } })] }, column.id));
936
1082
  }
@@ -1389,7 +1535,7 @@ const SchemaFormContext = React.createContext({
1389
1535
  serverUrl: "",
1390
1536
  order: [],
1391
1537
  ignore: [],
1392
- onSubmit: () => { },
1538
+ onSubmit: async () => { },
1393
1539
  preLoadedValues: {},
1394
1540
  rowNumber: 0,
1395
1541
  displayText: {},
@@ -1442,12 +1588,12 @@ const useSchemaContext = () => {
1442
1588
  };
1443
1589
  };
1444
1590
 
1445
- const getTableData = async ({ serverUrl, in_table, searching = '', where = [], limit = 10, }) => {
1591
+ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, }) => {
1446
1592
  if (serverUrl === undefined || serverUrl.length == 0) {
1447
- throw new Error('The serverUrl is missing');
1593
+ throw new Error("The serverUrl is missing");
1448
1594
  }
1449
1595
  if (in_table === undefined || in_table.length == 0) {
1450
- throw new Error('The in_table is missing');
1596
+ throw new Error("The in_table is missing");
1451
1597
  }
1452
1598
  const options = {
1453
1599
  method: "GET",
@@ -1473,8 +1619,8 @@ const getTableData = async ({ serverUrl, in_table, searching = '', where = [], l
1473
1619
  }
1474
1620
  };
1475
1621
 
1476
- const IdPicker = ({ column, in_table, column_ref, display_column, }) => {
1477
- const { formState: { errors }, setValue, } = reactHookForm.useFormContext();
1622
+ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = false, }) => {
1623
+ const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
1478
1624
  const { schema, serverUrl, displayText } = useSchemaContext();
1479
1625
  const { fieldRequired } = displayText;
1480
1626
  const { required } = schema;
@@ -1483,7 +1629,7 @@ const IdPicker = ({ column, in_table, column_ref, display_column, }) => {
1483
1629
  throw new Error("schema properties when using DatePicker");
1484
1630
  }
1485
1631
  const { gridColumn, gridRow, title } = schema.properties[column];
1486
- const [selectedId, setSelectedId] = React.useState();
1632
+ const [selectedIds, setSelectedIds] = React.useState([]);
1487
1633
  const [searchText, setSearchText] = React.useState();
1488
1634
  const [limit, setLimit] = React.useState(10);
1489
1635
  const [openSearchResult, setOpenSearchResult] = React.useState();
@@ -1529,31 +1675,37 @@ const IdPicker = ({ column, in_table, column_ref, display_column, }) => {
1529
1675
  ];
1530
1676
  }));
1531
1677
  };
1532
- const getSelectedName = () => {
1533
- const selectedItem = getIdMap(dataList)[selectedId ?? ""];
1678
+ const getSelectedName = (id) => {
1679
+ const selectedItem = getIdMap(dataList)[id];
1534
1680
  if (selectedItem == undefined) {
1535
1681
  return "";
1536
1682
  }
1537
1683
  return selectedItem[display_column];
1538
1684
  };
1539
- if (selectedId != undefined) {
1685
+ if (selectedIds.length >= 1 && isMultiple === false) {
1540
1686
  return (jsxRuntime.jsx(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, gridColumn,
1541
1687
  gridRow, children: jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
1542
- setSelectedId(undefined);
1688
+ setSelectedIds([]);
1543
1689
  setValue(column, "");
1544
- }, children: getSelectedName() }) }));
1690
+ }, children: getSelectedName(selectedIds[0]) }) }));
1545
1691
  }
1546
1692
  return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
1547
- gridRow, children: [jsxRuntime.jsx(react.Input, { placeholder: "Type to search", onChange: (event) => {
1693
+ gridRow, children: [selectedIds.map((id) => {
1694
+ return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
1695
+ setSelectedIds([]);
1696
+ setValue(column, "");
1697
+ }, children: getSelectedName(id) }));
1698
+ }), jsxRuntime.jsx(react.Input, { placeholder: "Type to search", onChange: (event) => {
1548
1699
  onSearchChange(event);
1549
1700
  setOpenSearchResult(true);
1550
- }, autoComplete: "off", ref: ref }), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsxs(RadioCardRoot, { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [isFetching && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isFetching" }), isLoading && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isLoading" }), isPending && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isPending" }), isError && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isError" }), jsxRuntime.jsx(react.Text, { children: `Search Result: ${count}, Showing ${limit}` }), jsxRuntime.jsx(Button, { onClick: async () => {
1701
+ }, autoComplete: "off", ref: ref }), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsxs(RadioCardRoot, { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [isFetching && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isFetching" }), isLoading && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isLoading" }), isPending && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isPending" }), isError && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isError" }), jsxRuntime.jsx(react.Text, { children: `Search Result: ${count}, Showing ${limit}` }), jsxRuntime.jsx(Button, { onClick: async () => {
1551
1702
  setOpenSearchResult(false);
1552
1703
  }, children: "close" }),
1553
1704
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1554
1705
  getItemList(dataList).map((item) => (jsxRuntime.jsx(RadioCardItem, { label: item.label, description: item.description, value: item.value, onClick: () => {
1555
- setSelectedId(item.key);
1556
- setValue(column, item.key);
1706
+ const ids = watch(column);
1707
+ setSelectedIds((state) => [...state, item.key]);
1708
+ setValue(column, [...(ids ?? []), item.key]);
1557
1709
  setOpenSearchResult(false);
1558
1710
  }, indicator: false }, item.key))), isDirty && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [dataList.length <= 0 && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Empty Search Result" }), " ", count > dataList.length && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(Button, { onClick: async () => {
1559
1711
  setLimit((limit) => limit + 10);
@@ -1699,8 +1851,8 @@ const monthNamesShort = [
1699
1851
  "Nov",
1700
1852
  "Dec",
1701
1853
  ];
1702
- const weekdayNamesShort$1 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1703
- const Calendar$1 = ({ calendars, getBackProps, getForwardProps, getDateProps, firstDayOfWeek = 0, }) => {
1854
+ const weekdayNamesShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1855
+ const Calendar = ({ calendars, getBackProps, getForwardProps, getDateProps, firstDayOfWeek = 0, }) => {
1704
1856
  if (calendars.length) {
1705
1857
  return (jsxRuntime.jsxs(react.Grid, { children: [jsxRuntime.jsxs(react.Grid, { templateColumns: "repeat(4, auto)", justifyContent: "center", children: [jsxRuntime.jsx(react.Button, { variant: "ghost", ...getBackProps({
1706
1858
  calendars,
@@ -1710,7 +1862,7 @@ const Calendar$1 = ({ calendars, getBackProps, getForwardProps, getDateProps, fi
1710
1862
  offset: 12,
1711
1863
  }), children: ">>" })] }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(2, auto)", justifyContent: "center", children: calendars.map((calendar) => (jsxRuntime.jsxs(react.Grid, { gap: 4, children: [jsxRuntime.jsxs(react.Grid, { justifyContent: "center", children: [monthNamesShort[calendar.month], " ", calendar.year] }), jsxRuntime.jsxs(react.Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: [[0, 1, 2, 3, 4, 5, 6].map((weekdayNum) => {
1712
1864
  const weekday = (weekdayNum + firstDayOfWeek) % 7;
1713
- return (jsxRuntime.jsx(react.Text, { textAlign: "center", children: weekdayNamesShort$1[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
1865
+ return (jsxRuntime.jsx(react.Text, { textAlign: "center", children: weekdayNamesShort[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
1714
1866
  }), calendar.weeks.map((week, weekIndex) => week.map((dateObj, index) => {
1715
1867
  const key = `${calendar.month}${calendar.year}${weekIndex}${index}`;
1716
1868
  if (!dateObj) {
@@ -1731,13 +1883,13 @@ const Calendar$1 = ({ calendars, getBackProps, getForwardProps, getDateProps, fi
1731
1883
  };
1732
1884
  const getVariant = ({ today, selected, selectable, }) => {
1733
1885
  if (!selectable) {
1734
- return "solid";
1886
+ return "surface";
1735
1887
  }
1736
1888
  if (selected) {
1737
1889
  return "solid";
1738
1890
  }
1739
1891
  if (today) {
1740
- return "solid";
1892
+ return "surface";
1741
1893
  }
1742
1894
  return "ghost";
1743
1895
  };
@@ -1750,7 +1902,7 @@ const Calendar$1 = ({ calendars, getBackProps, getForwardProps, getDateProps, fi
1750
1902
  };
1751
1903
  let DatePicker$1 = class DatePicker extends React.Component {
1752
1904
  render() {
1753
- return (jsxRuntime.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) => (jsxRuntime.jsx(Calendar$1, { ...dayzedData, firstDayOfWeek: this.props.firstDayOfWeek })) }));
1905
+ return (jsxRuntime.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) => (jsxRuntime.jsx(Calendar, { ...dayzedData, firstDayOfWeek: this.props.firstDayOfWeek })) }));
1754
1906
  }
1755
1907
  };
1756
1908
 
@@ -1834,8 +1986,164 @@ const ObjectInput = ({ column }) => {
1834
1986
  }, children: addNew ?? "Add New" }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
1835
1987
  };
1836
1988
 
1989
+ const TagPicker = ({ column }) => {
1990
+ const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
1991
+ const { schema, serverUrl } = useSchemaContext();
1992
+ if (schema.properties == undefined) {
1993
+ throw new Error("schema properties undefined when using DatePicker");
1994
+ }
1995
+ const { gridColumn, gridRow, in_table, object_id_column } = schema.properties[column];
1996
+ if (in_table === undefined) {
1997
+ throw new Error("in_table is undefined when using TagPicker");
1998
+ }
1999
+ if (object_id_column === undefined) {
2000
+ throw new Error("object_id_column is undefined when using TagPicker");
2001
+ }
2002
+ const query = reactQuery.useQuery({
2003
+ queryKey: [`tagpicker`, in_table],
2004
+ queryFn: async () => {
2005
+ return await getTableData({
2006
+ serverUrl,
2007
+ in_table: "tables_tags_view",
2008
+ where: [
2009
+ {
2010
+ id: "table_name",
2011
+ value: [in_table],
2012
+ },
2013
+ ],
2014
+ limit: 100,
2015
+ });
2016
+ },
2017
+ staleTime: 10000,
2018
+ });
2019
+ const object_id = watch(object_id_column);
2020
+ const existingTagsQuery = reactQuery.useQuery({
2021
+ queryKey: [`existing`, in_table, object_id_column, object_id],
2022
+ queryFn: async () => {
2023
+ return await getTableData({
2024
+ serverUrl,
2025
+ in_table: in_table,
2026
+ where: [
2027
+ {
2028
+ id: object_id_column,
2029
+ value: [object_id],
2030
+ },
2031
+ ],
2032
+ limit: 100,
2033
+ });
2034
+ },
2035
+ enabled: object_id != undefined,
2036
+ staleTime: 10000,
2037
+ });
2038
+ const { isLoading, isFetching, data, isPending, isError } = query;
2039
+ const dataList = data?.data ?? [];
2040
+ const existingTagList = existingTagsQuery.data?.data ?? [];
2041
+ if (!!object_id === false) {
2042
+ return jsxRuntime.jsx(jsxRuntime.Fragment, {});
2043
+ }
2044
+ return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 4, gridColumn,
2045
+ gridRow, children: [isFetching && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isFetching" }), isLoading && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isLoading" }), isPending && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isPending" }), isError && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isError" }), dataList.map(({ parent_tag_name, all_tags, is_mutually_exclusive }) => {
2046
+ return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 2, children: [jsxRuntime.jsx(react.Text, { children: parent_tag_name }), is_mutually_exclusive && (jsxRuntime.jsx(RadioCardRoot, { defaultValue: "next", variant: "surface", onValueChange: (tagIds) => {
2047
+ const existedTags = Object.values(all_tags)
2048
+ .filter(({ id }) => {
2049
+ return existingTagList.some(({ tag_id }) => tag_id === id);
2050
+ })
2051
+ .map(({ id }) => {
2052
+ return id;
2053
+ });
2054
+ setValue(`${column}.${parent_tag_name}.current`, [
2055
+ tagIds.value,
2056
+ ]);
2057
+ setValue(`${column}.${parent_tag_name}.old`, existedTags);
2058
+ }, children: jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
2059
+ if (existingTagList.some(({ tag_id }) => tag_id === id)) {
2060
+ return (jsxRuntime.jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", disabled: true }, `${tagName}-${id}`));
2061
+ }
2062
+ return (jsxRuntime.jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", colorPalette: "blue" }, `${tagName}-${id}`));
2063
+ }) }) })), !is_mutually_exclusive && (jsxRuntime.jsx(react.CheckboxGroup, { onValueChange: (tagIds) => {
2064
+ setValue(`${column}.${parent_tag_name}.current`, tagIds);
2065
+ }, children: jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
2066
+ if (existingTagList.some(({ tag_id }) => tag_id === id)) {
2067
+ return (jsxRuntime.jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%", disabled: true, colorPalette: "blue" }, `${tagName}-${id}`));
2068
+ }
2069
+ return (jsxRuntime.jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%" }, `${tagName}-${id}`));
2070
+ }) }) }))] }));
2071
+ }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
2072
+ };
2073
+
2074
+ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }, placeholder = "Drop files here or click to upload", }) => {
2075
+ const ref = React.useRef(null);
2076
+ const [isDraggedOver, setIsDraggedOver] = React.useState(false);
2077
+ React.useEffect(() => {
2078
+ const el = ref.current;
2079
+ invariant(el);
2080
+ return adapter$1.dropTargetForExternal({
2081
+ element: el,
2082
+ onDragEnter: () => setIsDraggedOver(true),
2083
+ onDragLeave: () => setIsDraggedOver(false),
2084
+ // canDrop: some(containsFiles, containsText),
2085
+ onDrop: ({ source }) => {
2086
+ const files = file.getFiles({ source });
2087
+ const text$1 = text.getText({ source });
2088
+ console.log(files, text$1, "dfposa");
2089
+ onDrop({ files, text: text$1 });
2090
+ },
2091
+ });
2092
+ }, [onDrop]);
2093
+ // const isDark = (location + location) % 2 === 1;
2094
+ function getColor(isDraggedOver) {
2095
+ if (isDraggedOver) {
2096
+ return {
2097
+ backgroundColor: "blue.400",
2098
+ _dark: {
2099
+ backgroundColor: "blue.400",
2100
+ },
2101
+ };
2102
+ }
2103
+ // return isDark ? "lightgrey" : "white";
2104
+ return {
2105
+ backgroundColor: undefined,
2106
+ _dark: {
2107
+ backgroundColor: undefined,
2108
+ },
2109
+ };
2110
+ }
2111
+ const fileInput = React.useRef(null);
2112
+ const handleClick = () => {
2113
+ fileInput.current?.click();
2114
+ };
2115
+ const handleChange = (event) => {
2116
+ // @ts-expect-error find appropriate types for event target files
2117
+ const filesArray = [...event.target.files];
2118
+ onDrop({ files: filesArray });
2119
+ };
2120
+ return (jsxRuntime.jsxs(react.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 && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.Flex, { children: placeholder }), jsxRuntime.jsx(react.Input, { type: "file", multiple: true, style: { display: "none" }, ref: fileInput, onChange: handleChange })] }))] }));
2121
+ };
2122
+
2123
+ const FilePicker = ({ column }) => {
2124
+ const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
2125
+ const { schema, displayText } = useSchemaContext();
2126
+ const { fieldRequired } = displayText;
2127
+ const { required } = schema;
2128
+ const isRequired = required?.some((columnId) => columnId === column);
2129
+ if (schema.properties == undefined) {
2130
+ throw new Error("schema properties when using String Input Field");
2131
+ }
2132
+ const { gridColumn, gridRow, title } = schema.properties[column];
2133
+ const currentFiles = (watch(column) ?? []);
2134
+ return (jsxRuntime.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: [jsxRuntime.jsx(FileDropzone, { onDrop: ({ files }) => {
2135
+ const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
2136
+ setValue(column, [...currentFiles, ...newFiles]);
2137
+ } }), jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", alignItems: "start", gap: 1, children: currentFiles.map((file) => {
2138
+ return (jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
2139
+ setValue(column, currentFiles.filter(({ name }) => {
2140
+ return name !== file.name;
2141
+ }));
2142
+ }, children: file.name }));
2143
+ }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
2144
+ };
2145
+
1837
2146
  const idPickerSanityCheck = (column, in_table, column_ref, display_column) => {
1838
- console.log(!!in_table, "okgsd");
1839
2147
  if (!!in_table == false) {
1840
2148
  throw new Error(`The key in_table does not exist in properties of column ${column}.`);
1841
2149
  }
@@ -1869,19 +2177,10 @@ const FormInternal = () => {
1869
2177
  const onSubmitSuccess = () => {
1870
2178
  setIsSuccess(true);
1871
2179
  };
1872
- const defaultOnSubmit = async (data) => {
1873
- const options = {
1874
- method: "POST",
1875
- url: `${serverUrl}/api/g/${schema.title}`,
1876
- headers: {
1877
- Apikey: "YOUR_SECRET_TOKEN",
1878
- "Content-Type": "application/json",
1879
- },
1880
- data: clearEmptyString(data),
1881
- };
2180
+ const defaultOnSubmit = async (promise) => {
1882
2181
  try {
1883
2182
  onBeforeSubmit();
1884
- await axios.request(options);
2183
+ await promise;
1885
2184
  onSubmitSuccess();
1886
2185
  }
1887
2186
  catch (error) {
@@ -1893,13 +2192,25 @@ const FormInternal = () => {
1893
2192
  onAfterSubmit();
1894
2193
  }
1895
2194
  };
2195
+ const defaultSubmitPromise = (data) => {
2196
+ const options = {
2197
+ method: "POST",
2198
+ url: `${serverUrl}/api/g/${schema.title}`,
2199
+ headers: {
2200
+ Apikey: "YOUR_SECRET_TOKEN",
2201
+ "Content-Type": "application/json",
2202
+ },
2203
+ data: clearEmptyString(data),
2204
+ };
2205
+ return axios.request(options);
2206
+ };
1896
2207
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1897
2208
  const onFormSubmit = async (data) => {
1898
2209
  if (onSubmit === undefined) {
1899
- defaultOnSubmit(data);
2210
+ await defaultOnSubmit(defaultSubmitPromise(data));
1900
2211
  return;
1901
2212
  }
1902
- onSubmit(data);
2213
+ await defaultOnSubmit(onSubmit(data));
1903
2214
  };
1904
2215
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1905
2216
  const onValid = (data) => {
@@ -1991,7 +2302,18 @@ const FormInternal = () => {
1991
2302
  return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
1992
2303
  }
1993
2304
  if (type === "array") {
1994
- return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `array ${column}` });
2305
+ if (variant === "tag-picker") {
2306
+ const value = (validatedData ?? {})[column];
2307
+ return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${snakeToLabel(column)}`, ...getDataListProps(JSON.stringify(value)) }, `form-${key}`));
2308
+ }
2309
+ if (variant === "file-picker") {
2310
+ const fileNames = ((validatedData ?? {})[column] ?? []).map((file) => {
2311
+ return file.name;
2312
+ });
2313
+ return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps(JSON.stringify(fileNames)) }, `form-${key}`));
2314
+ }
2315
+ const objectString = JSON.stringify((validatedData ?? {})[column]);
2316
+ return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps(objectString) }, `form-${key}`));
1995
2317
  }
1996
2318
  if (type === "null") {
1997
2319
  return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `null ${column}` });
@@ -2037,6 +2359,16 @@ const FormInternal = () => {
2037
2359
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ObjectInput, { column: key }, `form-${key}`) }));
2038
2360
  }
2039
2361
  if (type === "array") {
2362
+ if (variant === "id-picker") {
2363
+ idPickerSanityCheck(column, in_table, column_ref, display_column);
2364
+ return (jsxRuntime.jsx(IdPicker, { column: key, in_table: in_table, column_ref: column_ref, display_column: display_column, isMultiple: true }, `form-${key}`));
2365
+ }
2366
+ if (variant === "tag-picker") {
2367
+ return jsxRuntime.jsx(TagPicker, { column: key }, `form-${key}`);
2368
+ }
2369
+ if (variant === "file-picker") {
2370
+ return jsxRuntime.jsx(FilePicker, { column: key }, `form-${key}`);
2371
+ }
2040
2372
  return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `array ${column}` });
2041
2373
  }
2042
2374
  if (type === "null") {
@@ -2083,139 +2415,6 @@ const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) =
2083
2415
  }
2084
2416
  };
2085
2417
 
2086
- const getRangeDates = ({ selectable, date, selectedDates, }) => {
2087
- if (!selectable) {
2088
- return;
2089
- }
2090
- const dateTime = date.getTime();
2091
- const newDates = [...selectedDates];
2092
- if (selectedDates.length) {
2093
- if (selectedDates.length === 1) {
2094
- const firstTime = selectedDates[0].getTime();
2095
- if (firstTime < dateTime) {
2096
- newDates.push(date);
2097
- }
2098
- else {
2099
- newDates.unshift(date);
2100
- }
2101
- return newDates;
2102
- }
2103
- else if (newDates.length === 2) {
2104
- return [date];
2105
- }
2106
- }
2107
- else {
2108
- newDates.push(date);
2109
- return newDates;
2110
- }
2111
- };
2112
-
2113
- const monthNamesFull = [
2114
- "January",
2115
- "February",
2116
- "March",
2117
- "April",
2118
- "May",
2119
- "June",
2120
- "July",
2121
- "August",
2122
- "September",
2123
- "October",
2124
- "November",
2125
- "December",
2126
- ];
2127
- const weekdayNamesShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
2128
- function Calendar({ calendars, getBackProps, getForwardProps, getDateProps, selected = [], firstDayOfWeek = 0, }) {
2129
- const [hoveredDate, setHoveredDate] = React.useState();
2130
- const onMouseLeave = () => {
2131
- setHoveredDate(undefined);
2132
- };
2133
- const onMouseEnter = (date) => {
2134
- setHoveredDate(date);
2135
- };
2136
- const isInRange = (date) => {
2137
- if (selected.length) {
2138
- const firstSelected = selected[0].getTime();
2139
- if (selected.length === 2) {
2140
- const secondSelected = selected[1].getTime();
2141
- return (firstSelected < date.getTime() && secondSelected > date.getTime());
2142
- }
2143
- else {
2144
- return !!(hoveredDate &&
2145
- ((firstSelected < date.getTime() &&
2146
- hoveredDate.getTime() >= date.getTime()) ||
2147
- (date.getTime() < firstSelected &&
2148
- date.getTime() >= hoveredDate.getTime())));
2149
- }
2150
- }
2151
- return false;
2152
- };
2153
- if (calendars.length) {
2154
- return (jsxRuntime.jsxs(react.Grid, { onMouseLeave: onMouseLeave, children: [jsxRuntime.jsxs(react.Grid, { templateColumns: "repeat(4, auto)", justifyContent: "center", children: [jsxRuntime.jsx(react.Button, { variant: "ghost", ...getBackProps({
2155
- calendars,
2156
- offset: 12,
2157
- }), children: "<<" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getBackProps({ calendars }), children: "Back" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getForwardProps({ calendars }), children: "Next" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getForwardProps({
2158
- calendars,
2159
- offset: 12,
2160
- }), children: ">>" })] }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(2, auto)", justifyContent: "center", gap: 4, children: calendars.map((calendar) => (jsxRuntime.jsxs(react.Grid, { gap: 4, children: [jsxRuntime.jsxs(react.Grid, { justifyContent: "center", children: [monthNamesFull[calendar.month], " ", calendar.year] }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: [0, 1, 2, 3, 4, 5, 6].map((weekdayNum) => {
2161
- const weekday = (weekdayNum + firstDayOfWeek) % 7;
2162
- return (jsxRuntime.jsx(react.Box, { minWidth: "48px", textAlign: 'center', children: weekdayNamesShort[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
2163
- }) }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: calendar.weeks.map((week, windex) => week.map((dateObj, index) => {
2164
- const key = `${calendar.month}${calendar.year}${windex}${index}`;
2165
- if (!dateObj) {
2166
- return jsxRuntime.jsx(react.Box, {}, key);
2167
- }
2168
- const { date, selected, selectable, today } = dateObj;
2169
- const getStyle = ({ selected, unavailable, today, isInRange, }) => {
2170
- if (unavailable) {
2171
- return {
2172
- colorPalette: "gray",
2173
- variant: "solid",
2174
- };
2175
- }
2176
- if (selected) {
2177
- return {
2178
- colorPalette: "blue",
2179
- variant: "solid",
2180
- };
2181
- }
2182
- if (isInRange) {
2183
- return {
2184
- colorPalette: "blue",
2185
- variant: "subtle",
2186
- };
2187
- }
2188
- if (today) {
2189
- return {
2190
- colorPalette: "green",
2191
- variant: "solid",
2192
- };
2193
- }
2194
- return { variant: "ghost" };
2195
- };
2196
- return (jsxRuntime.jsx(react.Button, { ...getDateProps({
2197
- dateObj,
2198
- onMouseEnter: () => {
2199
- onMouseEnter(date);
2200
- },
2201
- }), ...getStyle({
2202
- selected,
2203
- unavailable: !selectable,
2204
- today,
2205
- isInRange: isInRange(date),
2206
- }), children: selectable ? date.getDate() : "X" }, key));
2207
- })) })] }, `${calendar.month}${calendar.year}`))) })] }));
2208
- }
2209
- return null;
2210
- }
2211
- class RangeDatePicker extends React.Component {
2212
- render() {
2213
- return (jsxRuntime.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) => (jsxRuntime.jsx(Calendar, { ...dayzedData,
2214
- firstDayOfWeek: this.props.firstDayOfWeek,
2215
- selected: this.props.selected })) }));
2216
- }
2217
- }
2218
-
2219
2418
  exports.CardHeader = CardHeader;
2220
2419
  exports.DataDisplay = DataDisplay;
2221
2420
  exports.DataTable = DataTable;