@bsol-oss/react-datatable5 11.0.0-beta.1 → 11.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/index.d.ts +12 -5
  2. package/dist/index.js +841 -560
  3. package/dist/index.mjs +844 -564
  4. package/dist/types/components/DataTable/DataDisplay.d.ts +1 -1
  5. package/dist/types/components/DataTable/utils/getColumns.d.ts +2 -1
  6. package/dist/types/components/Form/Form.d.ts +8 -2
  7. package/dist/types/components/Form/SchemaFormContext.d.ts +1 -0
  8. package/dist/types/components/Form/components/ArrayRenderer.d.ts +7 -0
  9. package/dist/types/components/Form/components/BooleanPicker.d.ts +4 -1
  10. package/dist/types/components/Form/components/ColumnRenderer.d.ts +7 -0
  11. package/dist/types/components/Form/components/DatePicker.d.ts +4 -1
  12. package/dist/types/components/Form/components/EnumPicker.d.ts +4 -1
  13. package/dist/types/components/Form/components/FilePicker.d.ts +3 -1
  14. package/dist/types/components/Form/components/IdPicker.d.ts +4 -1
  15. package/dist/types/components/Form/components/NumberInputField.d.ts +4 -1
  16. package/dist/types/components/Form/components/ObjectInput.d.ts +5 -2
  17. package/dist/types/components/Form/components/RecordInput.d.ts +7 -0
  18. package/dist/types/components/Form/components/SchemaRenderer.d.ts +7 -0
  19. package/dist/types/components/Form/components/StringInputField.d.ts +4 -4
  20. package/dist/types/components/Form/components/TagPicker.d.ts +4 -1
  21. package/dist/types/components/Form/components/fields/ArrayRenderer.d.ts +7 -0
  22. package/dist/types/components/Form/components/fields/BooleanPicker.d.ts +7 -0
  23. package/dist/types/components/Form/components/fields/ColumnRenderer.d.ts +7 -0
  24. package/dist/types/components/Form/components/fields/DatePicker.d.ts +7 -0
  25. package/dist/types/components/Form/components/fields/EnumPicker.d.ts +8 -0
  26. package/dist/types/components/Form/components/fields/FilePicker.d.ts +5 -0
  27. package/dist/types/components/Form/components/fields/IdPicker.d.ts +8 -0
  28. package/dist/types/components/Form/components/fields/NumberInputField.d.ts +7 -0
  29. package/dist/types/components/Form/components/fields/ObjectInput.d.ts +7 -0
  30. package/dist/types/components/Form/components/fields/RecordInput.d.ts +7 -0
  31. package/dist/types/components/Form/components/fields/SchemaRenderer.d.ts +7 -0
  32. package/dist/types/components/Form/components/fields/StringInputField.d.ts +12 -0
  33. package/dist/types/components/Form/components/fields/TagPicker.d.ts +25 -0
  34. package/dist/types/components/Form/components/types/CustomJSONSchema7.d.ts +15 -0
  35. package/dist/types/components/Form/components/viewers/ArrayViewer.d.ts +7 -0
  36. package/dist/types/components/Form/components/viewers/BooleanViewer.d.ts +7 -0
  37. package/dist/types/components/Form/components/viewers/ColumnViewer.d.ts +7 -0
  38. package/dist/types/components/Form/components/viewers/DateViewer.d.ts +7 -0
  39. package/dist/types/components/Form/components/viewers/EnumViewer.d.ts +8 -0
  40. package/dist/types/components/Form/components/viewers/FileViewer.d.ts +5 -0
  41. package/dist/types/components/Form/components/viewers/IdViewer.d.ts +8 -0
  42. package/dist/types/components/Form/components/viewers/NumberViewer.d.ts +7 -0
  43. package/dist/types/components/Form/components/viewers/ObjectViewer.d.ts +7 -0
  44. package/dist/types/components/Form/components/viewers/RecordViewer.d.ts +7 -0
  45. package/dist/types/components/Form/components/viewers/SchemaViewer.d.ts +7 -0
  46. package/dist/types/components/Form/components/viewers/StringViewer.d.ts +12 -0
  47. package/dist/types/components/Form/components/viewers/TagViewer.d.ts +30 -0
  48. package/dist/types/components/Form/useSchemaContext.d.ts +2 -14
  49. package/dist/types/components/Form/utils/removeIndex.d.ts +1 -0
  50. package/package.json +3 -4
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, RadioGroup as RadioGroup$1, Grid, Box, Slider as Slider$1, HStack, For, Flex, Text, Tag as Tag$1, Input, useDisclosure, DialogBackdrop, CheckboxCard as CheckboxCard$1, Menu, createRecipeContext, createContext as createContext$1, Pagination as Pagination$1, usePaginationContext, Image, Card, DataList, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Group, InputElement, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$2, VStack, List, Alert, Popover, Field as Field$1, HoverCard, NumberInput, Accordion, Show, RadioCard, CheckboxGroup, Heading, Center } from '@chakra-ui/react';
2
+ import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, RadioGroup as RadioGroup$1, Grid, Box, Slider as Slider$1, HStack, For, Flex, Text, Tag as Tag$1, Input, useDisclosure, DialogBackdrop, CheckboxCard as CheckboxCard$1, Menu, createRecipeContext, createContext as createContext$1, Pagination as Pagination$1, usePaginationContext, Image, Card, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Group, InputElement, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$2, VStack, List, Alert, Accordion, Field as Field$1, Popover, NumberInput, Show, RadioCard, CheckboxGroup, Heading, Center } from '@chakra-ui/react';
3
3
  import { AiOutlineColumnWidth } from 'react-icons/ai';
4
4
  import * as React from 'react';
5
5
  import React__default, { createContext, useContext, useState, useEffect, useRef } from 'react';
@@ -7,7 +7,7 @@ import { MdFilterAlt, MdArrowUpward, MdArrowDownward, MdOutlineMoveDown, MdOutli
7
7
  import { LuX, LuCheck, LuChevronRight, LuChevronDown } from 'react-icons/lu';
8
8
  import Dayzed from '@bsol-oss/dayzed-react19';
9
9
  import { FaUpDown, FaGripLinesVertical } from 'react-icons/fa6';
10
- import { BiDownArrow, BiUpArrow } from 'react-icons/bi';
10
+ import { BiDownArrow, BiUpArrow, BiError } from 'react-icons/bi';
11
11
  import { CgClose } from 'react-icons/cg';
12
12
  import { IoMdEye, IoMdCheckbox } from 'react-icons/io';
13
13
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
@@ -24,7 +24,7 @@ import { useDebounce } from '@uidotdev/usehooks';
24
24
  import { useQueryClient, useQuery } from '@tanstack/react-query';
25
25
  import { IoReload } from 'react-icons/io5';
26
26
  import { GrAscend, GrDescend } from 'react-icons/gr';
27
- import { HiColorSwatch, HiOutlineInformationCircle } from 'react-icons/hi';
27
+ import { HiColorSwatch } from 'react-icons/hi';
28
28
  import { useTranslation } from 'react-i18next';
29
29
  import axios from 'axios';
30
30
  import { useFormContext, FormProvider, useForm as useForm$1 } from 'react-hook-form';
@@ -2360,7 +2360,7 @@ function ColumnCard({ columnId }) {
2360
2360
  onDrop: () => setDragging(false), // NEW
2361
2361
  });
2362
2362
  }, [columnId, table]);
2363
- return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", children: jsx(FaGripLinesVertical, { color: "gray.400" }) }), jsx(Flex, { justifyContent: "space-between", alignItems: "center", children: jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
2363
+ return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", cursor: 'grab', children: jsx(FaGripLinesVertical, { color: "gray.400" }) }), jsx(Flex, { justifyContent: "space-between", alignItems: "center", children: jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
2364
2364
  }
2365
2365
  function CardContainer({ location, children }) {
2366
2366
  const ref = useRef(null);
@@ -2398,9 +2398,11 @@ function CardContainer({ location, children }) {
2398
2398
  }
2399
2399
  const TableViewer = () => {
2400
2400
  const { table } = useDataTableContext();
2401
- const [order, setOrder] = useState(table.getAllLeafColumns().map((column) => {
2402
- return column.id;
2403
- }));
2401
+ const order = table.getState().columnOrder.length > 0
2402
+ ? table.getState().columnOrder
2403
+ : table.getAllLeafColumns().map(({ id }) => {
2404
+ return id;
2405
+ });
2404
2406
  useEffect(() => {
2405
2407
  return monitorForElements({
2406
2408
  onDrop({ source, location }) {
@@ -2425,11 +2427,10 @@ const TableViewer = () => {
2425
2427
  ...columnAfter,
2426
2428
  ].filter((id) => id != "<marker>");
2427
2429
  table.setColumnOrder(newOrder);
2428
- setOrder(newOrder);
2429
2430
  },
2430
2431
  });
2431
- }, [order, table]);
2432
- return (jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: table.getState().columnOrder.map((columnId, index) => {
2432
+ }, [table]);
2433
+ return (jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: order.map((columnId, index) => {
2433
2434
  return (jsx(CardContainer, { location: index, children: jsx(ColumnCard, { columnId: columnId }) }));
2434
2435
  }) }));
2435
2436
  };
@@ -2604,89 +2605,77 @@ const RecordDisplay = ({ object, boxProps, translate, prefix = "", }) => {
2604
2605
  }) }));
2605
2606
  };
2606
2607
 
2607
- const formatValue = (value) => {
2608
- if (typeof value === "object") {
2609
- return JSON.stringify(value);
2610
- }
2611
- if (typeof value === "string") {
2612
- return value;
2613
- }
2614
- if (typeof value === "number" || typeof value === "boolean") {
2615
- return `${value}`;
2616
- }
2617
- if (value === undefined) {
2618
- return `undefined`;
2619
- }
2620
- throw new Error(`value is unknown, ${typeof value}`);
2621
- };
2622
- const DataDisplay = ({ variant = "", translate }) => {
2623
- const { table } = useDataTableContext();
2608
+ const CellRenderer = ({ cell }) => {
2609
+ const { translate } = useDataTableContext();
2624
2610
  const getLabel = ({ columnId }) => {
2625
2611
  if (translate !== undefined) {
2626
2612
  return translate.t(`${columnId}`);
2627
2613
  }
2628
2614
  return snakeToLabel(columnId);
2629
2615
  };
2630
- if (variant == "horizontal") {
2631
- return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
2632
- 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) => {
2633
- const showCustomDataDisplay = cell.column.columnDef.meta?.showCustomDisplay ?? false;
2634
- if (showCustomDataDisplay) {
2635
- return (jsx(Flex, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
2636
- }
2637
- const value = cell.getValue();
2638
- if (typeof value === "object") {
2639
- return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: getLabel({ columnId: cell.column.id }) }), jsx(RecordDisplay, { boxProps: {
2640
- borderWidth: 1,
2641
- borderRadius: 4,
2642
- borderColor: "gray.400",
2643
- paddingX: 4,
2644
- paddingY: 2,
2645
- }, object: value })] }, cell.id));
2646
- }
2647
- return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: getLabel({ columnId: cell.column.id }) }), jsx(DataList.ItemValue, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
2648
- }) }) }) }, `chakra-table-card-${row.id}`));
2649
- }) }));
2616
+ const formatValue = (value) => {
2617
+ if (typeof value === "object") {
2618
+ return JSON.stringify(value);
2619
+ }
2620
+ if (typeof value === "string") {
2621
+ return value;
2622
+ }
2623
+ if (typeof value === "number" || typeof value === "boolean") {
2624
+ return `${value}`;
2625
+ }
2626
+ if (value === undefined) {
2627
+ if (translate !== undefined) {
2628
+ return translate.t(`undefined`);
2629
+ }
2630
+ return `undefined`;
2631
+ }
2632
+ throw new Error(`value is unknown, ${typeof value}`);
2633
+ };
2634
+ const showCustomDataDisplay = cell.column.columnDef.meta?.showCustomDisplay ?? false;
2635
+ const gridColumn = cell.column.columnDef.meta?.gridColumn ?? [
2636
+ "span 12",
2637
+ "span 6",
2638
+ "span 3",
2639
+ ];
2640
+ const gridRow = cell.column.columnDef.meta?.gridRow ?? {};
2641
+ if (showCustomDataDisplay) {
2642
+ return (jsx(Flex, { gridColumn, gridRow, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
2650
2643
  }
2651
- if (variant == "stats") {
2652
- return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
2653
- 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) => {
2654
- const showCustomDataDisplay = cell.column.columnDef.meta?.showCustomDisplay ?? false;
2655
- if (showCustomDataDisplay) {
2656
- return (jsx(Flex, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
2657
- }
2658
- const value = cell.getValue();
2659
- if (typeof value === "object") {
2660
- return (jsxs(DataList.Item, { display: "inline-flex", flexFlow: "column", justifyContent: "center", alignItems: "center", flex: "1 0 0%", children: [jsx(DataList.ItemLabel, { children: getLabel({ columnId: cell.column.id }) }), jsx(RecordDisplay, { boxProps: {
2661
- borderWidth: 1,
2662
- borderRadius: 4,
2663
- borderColor: "gray.400",
2664
- paddingX: 4,
2665
- paddingY: 2,
2666
- }, object: value })] }));
2667
- }
2668
- return (jsxs(DataList.Item, { display: "flex", justifyContent: "center", alignItems: "center", flex: "1 0 0%", children: [jsx(DataList.ItemLabel, { children: getLabel({ columnId: cell.column.id }) }), jsx(DataList.ItemValue, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
2669
- }) }) }) }, `chakra-table-card-${row.id}`));
2670
- }) }));
2644
+ const value = cell.getValue();
2645
+ if (typeof value === "object") {
2646
+ return (jsxs(Box, { gridColumn, gridRow, children: [jsx(Box, { children: getLabel({ columnId: cell.column.id }) }), jsx(RecordDisplay, { boxProps: {
2647
+ borderWidth: 1,
2648
+ borderRadius: 4,
2649
+ borderColor: "gray.400",
2650
+ paddingX: 4,
2651
+ paddingY: 2,
2652
+ }, object: value })] }, cell.id));
2671
2653
  }
2654
+ return (jsxs(Box, { gridColumn, gridRow, children: [jsx(Box, { color: 'gray.400', children: getLabel({ columnId: cell.column.id }) }), jsx(Box, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
2655
+ };
2656
+ const DataDisplay = ({ variant = "" }) => {
2657
+ const { table, translate } = useDataTableContext();
2672
2658
  return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
2673
- 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) => {
2674
- const showCustomDataDisplay = cell.column.columnDef.meta?.showCustomDisplay ?? false;
2675
- if (showCustomDataDisplay) {
2676
- return (jsx(Flex, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
2677
- }
2678
- const value = cell.getValue();
2679
- if (typeof value === "object") {
2680
- return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: getLabel({ columnId: cell.column.id }) }), jsx(RecordDisplay, { boxProps: {
2681
- borderWidth: 1,
2682
- borderRadius: 4,
2683
- borderColor: "gray.400",
2684
- paddingX: 4,
2685
- paddingY: 2,
2686
- }, object: value })] }, cell.id));
2687
- }
2688
- return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: getLabel({ columnId: cell.column.id }) }), jsx(DataList.ItemValue, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
2689
- }) }) }) }, `chakra-table-card-${row.id}`));
2659
+ const rowId = row.id;
2660
+ return (jsx(Card.Root, { children: jsx(Card.Body, { display: "grid", gap: 4, padding: 4, gridTemplateColumns: "repeat(12, 1fr)", children: table.getAllColumns().map((column) => {
2661
+ const childCell = row.getAllCells().find((cell) => {
2662
+ return cell.id === `${rowId}_${column.id}`;
2663
+ });
2664
+ if (column.columns.length > 0) {
2665
+ return (jsxs(Card.Root, { margin: "1", gridColumn: "span 12", children: [jsx(Card.Header, { color: "gray.400", children: translate.t(column.id) }), jsx(Card.Body, { display: "grid", gap: "4", gridTemplateColumns: "repeat(12, 1fr)", children: column.columns.map((column) => {
2666
+ if (!column.getIsVisible()) {
2667
+ return jsx(Fragment, {});
2668
+ }
2669
+ const foundCell = row
2670
+ .getVisibleCells()
2671
+ .find((cell) => {
2672
+ return cell.id === `${rowId}_${column.id}`;
2673
+ });
2674
+ return jsx(CellRenderer, { cell: foundCell });
2675
+ }) })] }, `chakra-table-card-${childCell?.id}`));
2676
+ }
2677
+ return jsx(CellRenderer, { cell: childCell });
2678
+ }) }) }, `chakra-table-card-${rowId}`));
2690
2679
  }) }));
2691
2680
  };
2692
2681
 
@@ -3474,7 +3463,7 @@ const widthSanityCheck = (widthList, ignoreList, properties) => {
3474
3463
  throw new Error(`The width list is too long given from the number of remaining properties after ignore some.`);
3475
3464
  }
3476
3465
  };
3477
- const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth = 400, translate, }) => {
3466
+ const getColumns = ({ schema, include = [], ignore = [], width = [], meta = {}, defaultWidth = 400, translate, }) => {
3478
3467
  const { properties } = schema;
3479
3468
  idListSanityCheck("ignore", ignore, properties);
3480
3469
  widthSanityCheck(width, ignore, properties);
@@ -3486,7 +3475,8 @@ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth =
3486
3475
  return snakeToLabel(column);
3487
3476
  };
3488
3477
  const keys = Object.keys(properties);
3489
- const ignored = keys.filter((key) => {
3478
+ const included = include.length > 0 ? include : keys;
3479
+ const ignored = included.filter((key) => {
3490
3480
  return !ignore.some((shouldIgnoreKey) => key === shouldIgnoreKey);
3491
3481
  });
3492
3482
  const columnHelper = createColumnHelper();
@@ -3538,239 +3528,14 @@ const SchemaFormContext = createContext({
3538
3528
  requestUrl: "",
3539
3529
  order: [],
3540
3530
  ignore: [],
3531
+ include: [],
3541
3532
  onSubmit: async () => { },
3542
3533
  rowNumber: 0,
3543
3534
  requestOptions: {},
3544
3535
  });
3545
3536
 
3546
- const PopoverContent = React.forwardRef(function PopoverContent(props, ref) {
3547
- const { portalled = true, portalRef, ...rest } = props;
3548
- return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(Popover.Positioner, { children: jsx(Popover.Content, { ref: ref, ...rest }) }) }));
3549
- });
3550
- React.forwardRef(function PopoverArrow(props, ref) {
3551
- return (jsx(Popover.Arrow, { ...props, ref: ref, children: jsx(Popover.ArrowTip, {}) }));
3552
- });
3553
- React.forwardRef(function PopoverCloseTrigger(props, ref) {
3554
- return (jsx(Popover.CloseTrigger, { position: "absolute", top: "1", insetEnd: "1", ...props, asChild: true, ref: ref, children: jsx(CloseButton, { size: "sm" }) }));
3555
- });
3556
- const PopoverTitle = Popover.Title;
3557
- Popover.Description;
3558
- Popover.Footer;
3559
- Popover.Header;
3560
- const PopoverRoot = Popover.Root;
3561
- const PopoverBody = Popover.Body;
3562
- const PopoverTrigger = Popover.Trigger;
3563
-
3564
- const Field = React.forwardRef(function Field(props, ref) {
3565
- const { label, children, helperText, errorText, optionalText, ...rest } = props;
3566
- return (jsxs(Field$1.Root, { ref: ref, ...rest, children: [label && (jsxs(Field$1.Label, { children: [label, jsx(Field$1.RequiredIndicator, { fallback: optionalText })] })), children, helperText && (jsx(Field$1.HelperText, { children: helperText })), errorText && (jsx(Field$1.ErrorText, { children: errorText }))] }));
3567
- });
3568
-
3569
3537
  const useSchemaContext = () => {
3570
- const { schema, serverUrl, requestUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, requestOptions, } = useContext(SchemaFormContext);
3571
- return {
3572
- schema,
3573
- serverUrl,
3574
- requestUrl,
3575
- order,
3576
- ignore,
3577
- onSubmit,
3578
- rowNumber,
3579
- idMap,
3580
- setIdMap,
3581
- translate,
3582
- requestOptions,
3583
- };
3584
- };
3585
-
3586
- const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
3587
- if (serverUrl === undefined || serverUrl.length == 0) {
3588
- throw new Error("The serverUrl is missing");
3589
- }
3590
- if (in_table === undefined || in_table.length == 0) {
3591
- throw new Error("The in_table is missing");
3592
- }
3593
- const options = {
3594
- method: "GET",
3595
- url: `${serverUrl}/api/g/${in_table}`,
3596
- params: {
3597
- searching,
3598
- where,
3599
- limit,
3600
- offset
3601
- },
3602
- };
3603
- try {
3604
- const { data } = await axios.request(options);
3605
- console.log(data);
3606
- return data;
3607
- }
3608
- catch (error) {
3609
- console.error(error);
3610
- throw error;
3611
- }
3612
- };
3613
-
3614
- const IdPicker = ({ column, isMultiple = false }) => {
3615
- const { watch, formState: { errors }, setValue, } = useFormContext();
3616
- const { schema, serverUrl, idMap, setIdMap, translate } = useSchemaContext();
3617
- const { required } = schema;
3618
- const isRequired = required?.some((columnId) => columnId === column);
3619
- if (schema.properties == undefined) {
3620
- throw new Error("schema properties is undefined when using DatePicker");
3621
- }
3622
- const { gridColumn, gridRow, renderDisplay, foreign_key } = schema.properties[column];
3623
- const { table, column: column_ref, display_column, } = foreign_key;
3624
- const [searchText, setSearchText] = useState();
3625
- const [limit, setLimit] = useState(10);
3626
- const [openSearchResult, setOpenSearchResult] = useState();
3627
- const [page, setPage] = useState(0);
3628
- const ref = useRef(null);
3629
- const selectedIds = watch(column) ?? [];
3630
- const query = useQuery({
3631
- queryKey: [`idpicker`, { column, searchText, limit, page }],
3632
- queryFn: async () => {
3633
- const data = await getTableData({
3634
- serverUrl,
3635
- searching: searchText ?? "",
3636
- in_table: table,
3637
- limit: limit,
3638
- offset: page * 10,
3639
- });
3640
- const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
3641
- return [
3642
- item[column_ref],
3643
- {
3644
- ...item,
3645
- },
3646
- ];
3647
- }));
3648
- setIdMap((state) => {
3649
- return { ...state, ...newMap };
3650
- });
3651
- return data;
3652
- },
3653
- enabled: (searchText ?? "")?.length > 0,
3654
- staleTime: 300000,
3655
- });
3656
- const { isLoading, isFetching, data, isPending, isError } = query;
3657
- const dataList = data?.data ?? [];
3658
- const count = data?.count ?? 0;
3659
- const isDirty = (searchText?.length ?? 0) > 0;
3660
- const onSearchChange = async (event) => {
3661
- setSearchText(event.target.value);
3662
- setPage(0);
3663
- setLimit(10);
3664
- };
3665
- const watchId = watch(column);
3666
- const watchIds = (watch(column) ?? []);
3667
- const getPickedValue = () => {
3668
- if (Object.keys(idMap).length <= 0) {
3669
- return "";
3670
- }
3671
- const record = idMap[watchId];
3672
- if (record === undefined) {
3673
- return "";
3674
- }
3675
- return record[display_column];
3676
- };
3677
- return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
3678
- gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
3679
- const item = idMap[id];
3680
- if (item === undefined) {
3681
- return jsx(Text, { children: "undefined" }, id);
3682
- }
3683
- return (jsx(Tag, { closable: true, onClick: () => {
3684
- setValue(column, watchIds.filter((id) => id != item[column_ref]));
3685
- }, children: !!renderDisplay === true
3686
- ? renderDisplay(item)
3687
- : item[display_column] }, id));
3688
- }), jsx(Tag, { cursor: "pointer", onClick: () => {
3689
- setOpenSearchResult(true);
3690
- }, children: "Add" })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
3691
- setOpenSearchResult(true);
3692
- }, children: getPickedValue() })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(`${column}.typeToSearch`), onChange: (event) => {
3693
- onSearchChange(event);
3694
- setOpenSearchResult(true);
3695
- }, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), (searchText?.length ?? 0) > 0 && (jsxs(Fragment, { children: [isFetching && jsx(Fragment, { children: "isFetching" }), isLoading && jsx(Fragment, { children: "isLoading" }), isPending && jsx(Fragment, { children: "isPending" }), isError && jsx(Fragment, { children: "isError" }), jsx(Text, { justifySelf: "center", children: `${translate.t(`${column}.total`)} ${count}, ${translate.t(`${column}.showing`)} ${limit}` }), jsxs(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsx(Flex, { flexFlow: "column wrap", children:
3696
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3697
- dataList.map((item) => {
3698
- const selected = isMultiple
3699
- ? watchIds.some((id) => item[column_ref] === id)
3700
- : watchId === item[column_ref];
3701
- return (jsx(Box, { cursor: "pointer", onClick: () => {
3702
- if (!isMultiple) {
3703
- setOpenSearchResult(false);
3704
- setValue(column, item[column_ref]);
3705
- return;
3706
- }
3707
- const newSet = new Set([
3708
- ...(watchIds ?? []),
3709
- item[column_ref],
3710
- ]);
3711
- setValue(column, [...newSet]);
3712
- }, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
3713
- ? renderDisplay(item)
3714
- : item[display_column] }, item[column_ref]));
3715
- }) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Text, { children: translate.t(`${column}.emptySearchResult`) })) }))] }), jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxs(HStack, { gap: "4", children: [jsx(PaginationPrevTrigger, {}), jsx(PaginationPageText, {}), jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
3716
- };
3717
-
3718
- const HoverCardContent = React.forwardRef(function HoverCardContent(props, ref) {
3719
- const { portalled = true, portalRef, ...rest } = props;
3720
- return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(HoverCard.Positioner, { children: jsx(HoverCard.Content, { ref: ref, ...rest }) }) }));
3721
- });
3722
- const HoverCardArrow = React.forwardRef(function HoverCardArrow(props, ref) {
3723
- return (jsx(HoverCard.Arrow, { ref: ref, ...props, children: jsx(HoverCard.ArrowTip, {}) }));
3724
- });
3725
- const HoverCardRoot = HoverCard.Root;
3726
- const HoverCardTrigger = HoverCard.Trigger;
3727
-
3728
- const IdViewer = ({ value, column }) => {
3729
- const { schema, idMap, translate } = useSchemaContext();
3730
- if (schema.properties == undefined) {
3731
- throw new Error("schema properties when using DatePicker");
3732
- }
3733
- const { foreign_key } = schema.properties[column];
3734
- if (foreign_key === undefined) {
3735
- throw new Error("foreign_key when variant is id-picker");
3736
- }
3737
- const { display_column } = foreign_key;
3738
- if (value === undefined) {
3739
- return (jsxs(Flex, { flexFlow: "column", children: [jsx(Text, { children: translate.t(`${column}.fieldLabel`) }), jsx(Text, { children: translate.t(`empty`) })] }));
3740
- }
3741
- return (jsxs(Flex, { flexFlow: "column", children: [jsx(Text, { children: translate.t(`${column}.fieldLabel`) }), jsxs(HoverCardRoot, { children: [jsx(HoverCardTrigger, { asChild: true, children: jsx(Text, { cursor: 'pointer', children: idMap[value][display_column] }) }), jsxs(HoverCardContent, { children: [jsx(HoverCardArrow, {}), jsx(RecordDisplay, { object: idMap[value] })] })] })] }));
3742
- };
3743
-
3744
- const NumberInputRoot = React.forwardRef(function NumberInput$1(props, ref) {
3745
- const { children, ...rest } = props;
3746
- return (jsxs(NumberInput.Root, { ref: ref, variant: "outline", ...rest, children: [children, jsxs(NumberInput.Control, { children: [jsx(NumberInput.IncrementTrigger, {}), jsx(NumberInput.DecrementTrigger, {})] })] }));
3747
- });
3748
- const NumberInputField$1 = NumberInput.Input;
3749
- NumberInput.Scrubber;
3750
- NumberInput.Label;
3751
-
3752
- const NumberInputField = ({ column }) => {
3753
- const { register, formState: { errors }, } = useFormContext();
3754
- const { schema, translate } = useSchemaContext();
3755
- const { required } = schema;
3756
- const isRequired = required?.some((columnId) => columnId === column);
3757
- if (schema.properties == undefined) {
3758
- throw new Error("schema properties when using String Input Field");
3759
- }
3760
- const { gridColumn, gridRow } = schema.properties[column];
3761
- return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, gridColumn, gridRow, children: [jsx(NumberInputRoot, { children: jsx(NumberInputField$1, { ...register(column, { required: isRequired }) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
3762
- };
3763
-
3764
- const StringInputField = ({ column }) => {
3765
- const { register, formState: { errors }, } = useFormContext();
3766
- const { schema, translate } = useSchemaContext();
3767
- const { required } = schema;
3768
- const isRequired = required?.some((columnId) => columnId === column);
3769
- if (schema.properties == undefined) {
3770
- throw new Error("schema properties when using String Input Field");
3771
- }
3772
- const { gridColumn, gridRow } = schema.properties[column];
3773
- return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Input, { ...register(column, { required: isRequired }), autoComplete: "off" }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }) }));
3538
+ return useContext(SchemaFormContext);
3774
3539
  };
3775
3540
 
3776
3541
  const clearEmptyString = (object) => {
@@ -3787,35 +3552,58 @@ const AccordionItemContent = React.forwardRef(function AccordionItemContent(prop
3787
3552
  const AccordionRoot = Accordion.Root;
3788
3553
  const AccordionItem = Accordion.Item;
3789
3554
 
3790
- const ToggleTip = React.forwardRef(function ToggleTip(props, ref) {
3791
- const { showArrow, children, portalled = true, content, portalRef, ...rest } = props;
3792
- return (jsxs(Popover.Root, { ...rest, positioning: { ...rest.positioning, gutter: 4 }, children: [jsx(Popover.Trigger, { asChild: true, children: children }), jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(Popover.Positioner, { children: jsxs(Popover.Content, { width: "auto", px: "2", py: "1", textStyle: "xs", rounded: "sm", ref: ref, children: [showArrow && (jsx(Popover.Arrow, { children: jsx(Popover.ArrowTip, {}) })), content] }) }) })] }));
3793
- });
3794
- const InfoTip = React.forwardRef(function InfoTip(props, ref) {
3795
- const { children, ...rest } = props;
3796
- return (jsx(ToggleTip, { content: children, ...rest, ref: ref, children: jsx(IconButton, { variant: "ghost", "aria-label": "info", size: "2xs", colorPalette: "gray", children: jsx(HiOutlineInformationCircle, {}) }) }));
3797
- });
3555
+ function removeIndex(str) {
3556
+ return str.replace(/\.\d+\./g, '.');
3557
+ }
3558
+
3559
+ const ArrayRenderer = ({ schema, column, prefix, }) => {
3560
+ const { gridRow, gridColumn = "1/span 12", required, items } = schema;
3561
+ // @ts-expect-error TODO: find suitable types
3562
+ const { type } = items;
3563
+ const { translate } = useSchemaContext();
3564
+ const colLabel = `${prefix}${column}`;
3565
+ const isRequired = required?.some((columnId) => columnId === column);
3566
+ const { formState: { errors }, setValue, watch, } = useFormContext();
3567
+ const fields = (watch(colLabel) ?? []);
3568
+ return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, isRequired && jsx("span", { children: "*" })] }), fields.map((field, index) => (jsxs(Flex, { flexFlow: "column", children: [jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat("auto-fit", auto)`, children: jsx(SchemaRenderer, { column: `${index}`,
3569
+ prefix: `${colLabel}.`,
3570
+ schema: items }) }), jsx(Flex, { justifyContent: "end", children: jsx(Button$1, { variant: "ghost", onClick: () => {
3571
+ setValue(colLabel, fields.filter((_, curIndex) => {
3572
+ return curIndex === index;
3573
+ }));
3574
+ }, children: translate.t(removeIndex(`${colLabel}.remove`)) }) })] }, `${colLabel}.${index}`))), jsx(Flex, { children: jsx(Button$1, { onClick: () => {
3575
+ if (type === "number") {
3576
+ setValue(colLabel, [...fields, 0]);
3577
+ return;
3578
+ }
3579
+ if (type === "string") {
3580
+ setValue(colLabel, [...fields, ""]);
3581
+ return;
3582
+ }
3583
+ if (type === "boolean") {
3584
+ setValue(colLabel, [...fields, false]);
3585
+ return;
3586
+ }
3587
+ setValue(colLabel, [...fields, {}]);
3588
+ }, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
3589
+ };
3798
3590
 
3799
- const DataListRoot = DataList.Root;
3800
- const DataListItem = React.forwardRef(function DataListItem(props, ref) {
3801
- const { label, info, value, children, grow, ...rest } = props;
3802
- return (jsxs(DataList.Item, { ref: ref, ...rest, children: [jsxs(DataList.ItemLabel, { flex: grow ? "1" : undefined, children: [label, info && jsx(InfoTip, { children: info })] }), jsx(DataList.ItemValue, { flex: grow ? "1" : undefined, children: value }), children] }));
3591
+ const Field = React.forwardRef(function Field(props, ref) {
3592
+ const { label, children, helperText, errorText, optionalText, ...rest } = props;
3593
+ return (jsxs(Field$1.Root, { ref: ref, ...rest, children: [label && (jsxs(Field$1.Label, { children: [label, jsx(Field$1.RequiredIndicator, { fallback: optionalText })] })), children, helperText && (jsx(Field$1.HelperText, { children: helperText })), errorText && (jsx(Field$1.ErrorText, { children: errorText }))] }));
3803
3594
  });
3804
3595
 
3805
- const BooleanPicker = ({ column }) => {
3596
+ const BooleanPicker = ({ schema, column, prefix }) => {
3806
3597
  const { watch, formState: { errors }, setValue, } = useFormContext();
3807
- const { schema, translate } = useSchemaContext();
3808
- const { required } = schema;
3598
+ const { translate } = useSchemaContext();
3599
+ const { required, gridColumn, gridRow } = schema;
3809
3600
  const isRequired = required?.some((columnId) => columnId === column);
3810
- const value = watch(column);
3811
- if (schema.properties == undefined) {
3812
- throw new Error("schema properties when using BooleanPicker");
3813
- }
3814
- const { gridColumn, gridRow } = schema.properties[column];
3815
- return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
3816
- gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface", onSelect: () => {
3817
- setValue(column, !value);
3818
- } }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
3601
+ const colLabel = `${prefix}${column}`;
3602
+ const value = watch(colLabel);
3603
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
3604
+ gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface", onChange: () => {
3605
+ setValue(colLabel, !value);
3606
+ } }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
3819
3607
  };
3820
3608
 
3821
3609
  const monthNamesShort = [
@@ -3887,18 +3675,33 @@ let DatePicker$1 = class DatePicker extends React__default.Component {
3887
3675
  }
3888
3676
  };
3889
3677
 
3890
- const DatePicker = ({ column }) => {
3678
+ const PopoverContent = React.forwardRef(function PopoverContent(props, ref) {
3679
+ const { portalled = true, portalRef, ...rest } = props;
3680
+ return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(Popover.Positioner, { children: jsx(Popover.Content, { ref: ref, ...rest }) }) }));
3681
+ });
3682
+ React.forwardRef(function PopoverArrow(props, ref) {
3683
+ return (jsx(Popover.Arrow, { ...props, ref: ref, children: jsx(Popover.ArrowTip, {}) }));
3684
+ });
3685
+ React.forwardRef(function PopoverCloseTrigger(props, ref) {
3686
+ return (jsx(Popover.CloseTrigger, { position: "absolute", top: "1", insetEnd: "1", ...props, asChild: true, ref: ref, children: jsx(CloseButton, { size: "sm" }) }));
3687
+ });
3688
+ const PopoverTitle = Popover.Title;
3689
+ Popover.Description;
3690
+ Popover.Footer;
3691
+ Popover.Header;
3692
+ const PopoverRoot = Popover.Root;
3693
+ const PopoverBody = Popover.Body;
3694
+ const PopoverTrigger = Popover.Trigger;
3695
+
3696
+ const DatePicker = ({ column, schema, prefix }) => {
3891
3697
  const { watch, formState: { errors }, setValue, } = useFormContext();
3892
- const { schema, translate } = useSchemaContext();
3893
- const { required } = schema;
3698
+ const { translate } = useSchemaContext();
3699
+ const { required, gridColumn, gridRow } = schema;
3894
3700
  const isRequired = required?.some((columnId) => columnId === column);
3701
+ const colLabel = `${prefix}${column}`;
3895
3702
  const [open, setOpen] = useState(false);
3896
- const selectedDate = watch(column);
3897
- if (schema.properties == undefined) {
3898
- throw new Error("schema properties when using DatePicker");
3899
- }
3900
- const { gridColumn, gridRow } = schema.properties[column];
3901
- return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
3703
+ const selectedDate = watch(colLabel);
3704
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
3902
3705
  gridRow, children: [jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsx(PopoverTrigger, { asChild: true, children: jsx(Button, { size: "sm", variant: "outline", onClick: () => {
3903
3706
  setOpen(true);
3904
3707
  }, children: selectedDate !== undefined ? selectedDate : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
@@ -3907,10 +3710,10 @@ const DatePicker = ({ column }) => {
3907
3710
  // @ts-expect-error TODO: find appropriate types
3908
3711
  selected: new Date(selectedDate),
3909
3712
  // @ts-expect-error TODO: find appropriate types
3910
- onDateSelected: ({ selected, selectable, date }) => {
3911
- setValue(column, dayjs(date).format("YYYY-MM-DD"));
3713
+ onDateSelected: ({ date }) => {
3714
+ setValue(colLabel, dayjs(date).format("YYYY-MM-DD"));
3912
3715
  setOpen(false);
3913
- } })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
3716
+ } })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
3914
3717
  };
3915
3718
 
3916
3719
  function filterArray(array, searchTerm) {
@@ -3923,30 +3726,27 @@ function filterArray(array, searchTerm) {
3923
3726
  });
3924
3727
  }
3925
3728
 
3926
- const EnumPicker = ({ column, isMultiple = false }) => {
3729
+ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
3927
3730
  const { watch, formState: { errors }, setValue, } = useFormContext();
3928
- const { schema, translate } = useSchemaContext();
3731
+ const { translate } = useSchemaContext();
3929
3732
  const { required } = schema;
3930
3733
  const isRequired = required?.some((columnId) => columnId === column);
3931
- if (schema.properties == undefined) {
3932
- throw new Error("schema properties when using DatePicker");
3933
- }
3934
- const { gridColumn, gridRow, renderDisplay } = schema.properties[column];
3734
+ const { gridColumn, gridRow, renderDisplay } = schema;
3935
3735
  const [searchText, setSearchText] = useState();
3936
3736
  const [limit, setLimit] = useState(10);
3937
3737
  const [openSearchResult, setOpenSearchResult] = useState();
3938
3738
  const ref = useRef(null);
3939
- const watchEnum = watch(column);
3940
- const watchEnums = (watch(column) ?? []);
3941
- const properties = (schema.properties[column] ?? {});
3942
- const dataList = properties.enum ?? [];
3943
- const count = properties.enum?.length ?? 0;
3739
+ const colLabel = `${prefix}${column}`;
3740
+ const watchEnum = watch(colLabel);
3741
+ const watchEnums = (watch(colLabel) ?? []);
3742
+ const dataList = schema.enum ?? [];
3743
+ const count = schema.enum?.length ?? 0;
3944
3744
  const isDirty = (searchText?.length ?? 0) > 0;
3945
3745
  const onSearchChange = async (event) => {
3946
3746
  setSearchText(event.target.value);
3947
3747
  setLimit(10);
3948
3748
  };
3949
- return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
3749
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
3950
3750
  gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
3951
3751
  const item = enumValue;
3952
3752
  if (item === undefined) {
@@ -3955,12 +3755,16 @@ const EnumPicker = ({ column, isMultiple = false }) => {
3955
3755
  return (jsx(Tag, { closable: true, onClick: () => {
3956
3756
  // setSelectedEnums((state) => state.filter((id) => id != item));
3957
3757
  setValue(column, watchEnums.filter((id) => id != item));
3958
- }, children: !!renderDisplay === true ? renderDisplay(item) : item }));
3758
+ }, children: !!renderDisplay === true
3759
+ ? renderDisplay(item)
3760
+ : translate.t(removeIndex(`${colLabel}.${item}`)) }));
3959
3761
  }), jsx(Tag, { cursor: "pointer", onClick: () => {
3960
3762
  setOpenSearchResult(true);
3961
- }, children: "Add" })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
3763
+ }, children: translate.t(removeIndex(`${colLabel}.addMore`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
3962
3764
  setOpenSearchResult(true);
3963
- }, children: watchEnum })), 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, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(`${column}.typeToSearch`), onChange: (event) => {
3765
+ }, children: watchEnum === undefined
3766
+ ? ""
3767
+ : translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), 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, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(`${column}.typeToSearch`), onChange: (event) => {
3964
3768
  onSearchChange(event);
3965
3769
  setOpenSearchResult(true);
3966
3770
  }, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), jsx(Text, { children: `${translate.t(`${column}.total`)}: ${count}, ${translate.t(`${column}.showing`)} ${limit}` }), jsxs(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsx(Flex, { flexFlow: "column wrap", children: filterArray(dataList, searchText ?? "").map((item) => {
@@ -3970,13 +3774,15 @@ const EnumPicker = ({ column, isMultiple = false }) => {
3970
3774
  return (jsx(Box, { cursor: "pointer", onClick: () => {
3971
3775
  if (!isMultiple) {
3972
3776
  setOpenSearchResult(false);
3973
- setValue(column, item);
3777
+ setValue(colLabel, item);
3974
3778
  return;
3975
3779
  }
3976
3780
  const newSet = new Set([...(watchEnums ?? []), item]);
3977
- setValue(column, [...newSet]);
3978
- }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true ? renderDisplay(item) : item }, `${column}-${item}`));
3979
- }) }), isDirty && (jsxs(Fragment, { children: [dataList.length <= 0 && jsx(Fragment, { children: "Empty Search Result" }), " "] }))] })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
3781
+ setValue(colLabel, [...newSet]);
3782
+ }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
3783
+ ? renderDisplay(item)
3784
+ : translate.t(removeIndex(`${colLabel}.${item}`)) }, `${colLabel}-${item}`));
3785
+ }) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Fragment, { children: translate.t(removeIndex(`${colLabel}.emptySearchResult`)) })) }))] })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
3980
3786
  };
3981
3787
 
3982
3788
  function isEnteringWindow(_ref) {
@@ -4331,41 +4137,222 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
4331
4137
  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 })] }))] }));
4332
4138
  };
4333
4139
 
4334
- const FilePicker = ({ column }) => {
4140
+ const FilePicker = ({ column, schema, prefix }) => {
4335
4141
  const { setValue, formState: { errors }, watch, } = useFormContext();
4336
- const { schema, translate } = useSchemaContext();
4337
- const { required } = schema;
4142
+ const { translate } = useSchemaContext();
4143
+ const { required, gridColumn, gridRow } = schema;
4338
4144
  const isRequired = required?.some((columnId) => columnId === column);
4339
- if (schema.properties == undefined) {
4340
- throw new Error("schema properties when using String Input Field");
4341
- }
4342
- const { gridColumn, gridRow } = schema.properties[column];
4343
4145
  const currentFiles = (watch(column) ?? []);
4344
- return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: [jsx(FileDropzone, { onDrop: ({ files }) => {
4146
+ const colLabel = `${prefix}${column}`;
4147
+ return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: [jsx(FileDropzone, { onDrop: ({ files }) => {
4345
4148
  const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
4346
- setValue(column, [...currentFiles, ...newFiles]);
4347
- }, placeholder: translate.t(`${column}.fileDropzone`) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
4149
+ setValue(colLabel, [...currentFiles, ...newFiles]);
4150
+ }, placeholder: translate.t(removeIndex(`${colLabel}.fileDropzone`)) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
4348
4151
  return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
4349
4152
  setValue(column, currentFiles.filter(({ name }) => {
4350
4153
  return name !== file.name;
4351
4154
  }));
4352
- }, display: "flex", flexFlow: 'row', alignItems: 'center', padding: '2', children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
4353
- }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
4155
+ }, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
4156
+ }) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4354
4157
  };
4355
4158
 
4356
- const ObjectInput = ({ column }) => {
4357
- const { formState: { errors }, setValue, getValues, } = useFormContext();
4358
- const { schema, translate } = useSchemaContext();
4359
- const { required } = schema;
4360
- const isRequired = required?.some((columnId) => columnId === column);
4361
- const entries = Object.entries(getValues(column) ?? {});
4159
+ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
4160
+ if (serverUrl === undefined || serverUrl.length == 0) {
4161
+ throw new Error("The serverUrl is missing");
4162
+ }
4163
+ if (in_table === undefined || in_table.length == 0) {
4164
+ throw new Error("The in_table is missing");
4165
+ }
4166
+ const options = {
4167
+ method: "GET",
4168
+ url: `${serverUrl}/api/g/${in_table}`,
4169
+ params: {
4170
+ searching,
4171
+ where,
4172
+ limit,
4173
+ offset
4174
+ },
4175
+ };
4176
+ try {
4177
+ const { data } = await axios.request(options);
4178
+ console.log(data);
4179
+ return data;
4180
+ }
4181
+ catch (error) {
4182
+ console.error(error);
4183
+ throw error;
4184
+ }
4185
+ };
4186
+
4187
+ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4188
+ const { watch, formState: { errors }, setValue, } = useFormContext();
4189
+ const { serverUrl, idMap, setIdMap, translate } = useSchemaContext();
4190
+ const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
4191
+ const isRequired = required?.some((columnId) => columnId === column);
4192
+ const { table, column: column_ref, display_column, } = foreign_key;
4193
+ const [searchText, setSearchText] = useState();
4194
+ const [limit, setLimit] = useState(10);
4195
+ const [openSearchResult, setOpenSearchResult] = useState();
4196
+ const [page, setPage] = useState(0);
4197
+ const ref = useRef(null);
4198
+ const colLabel = `${prefix}${column}`;
4199
+ const query = useQuery({
4200
+ queryKey: [`idpicker`, { column, searchText, limit, page }],
4201
+ queryFn: async () => {
4202
+ const data = await getTableData({
4203
+ serverUrl,
4204
+ searching: searchText ?? "",
4205
+ in_table: table,
4206
+ limit: limit,
4207
+ offset: page * 10,
4208
+ });
4209
+ const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
4210
+ return [
4211
+ item[column_ref],
4212
+ {
4213
+ ...item,
4214
+ },
4215
+ ];
4216
+ }));
4217
+ setIdMap((state) => {
4218
+ return { ...state, ...newMap };
4219
+ });
4220
+ return data;
4221
+ },
4222
+ enabled: (searchText ?? "")?.length > 0,
4223
+ staleTime: 300000,
4224
+ });
4225
+ const { isLoading, isFetching, data, isPending, isError } = query;
4226
+ const dataList = data?.data ?? [];
4227
+ const count = data?.count ?? 0;
4228
+ const isDirty = (searchText?.length ?? 0) > 0;
4229
+ const watchId = watch(colLabel);
4230
+ const watchIds = (watch(colLabel) ?? []);
4231
+ useQuery({
4232
+ queryKey: [`idpicker`, { column, searchText, limit, page }],
4233
+ queryFn: async () => {
4234
+ const data = await getTableData({
4235
+ serverUrl,
4236
+ searching: watchId,
4237
+ in_table: table,
4238
+ limit: limit,
4239
+ offset: page * 10,
4240
+ });
4241
+ const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
4242
+ return [
4243
+ item[column_ref],
4244
+ {
4245
+ ...item,
4246
+ },
4247
+ ];
4248
+ }));
4249
+ setIdMap((state) => {
4250
+ return { ...state, ...newMap };
4251
+ });
4252
+ return data;
4253
+ },
4254
+ staleTime: 300000,
4255
+ });
4256
+ const onSearchChange = async (event) => {
4257
+ setSearchText(event.target.value);
4258
+ setPage(0);
4259
+ setLimit(10);
4260
+ };
4261
+ const getPickedValue = () => {
4262
+ if (Object.keys(idMap).length <= 0) {
4263
+ return "";
4264
+ }
4265
+ const record = idMap[watchId];
4266
+ if (record === undefined) {
4267
+ return "";
4268
+ }
4269
+ return record[display_column];
4270
+ };
4271
+ return (jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.fieldLabel`)))}`, required: isRequired, alignItems: "stretch", gridColumn,
4272
+ gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchIds.map((id) => {
4273
+ const item = idMap[id];
4274
+ if (item === undefined) {
4275
+ return (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
4276
+ }
4277
+ return (jsx(Tag, { closable: true, onClick: () => {
4278
+ setValue(column, watchIds.filter((id) => id != item[column_ref]));
4279
+ }, children: !!renderDisplay === true
4280
+ ? renderDisplay(item)
4281
+ : item[display_column] }, id));
4282
+ }), jsx(Tag, { cursor: "pointer", onClick: () => {
4283
+ setOpenSearchResult(true);
4284
+ }, children: translate.t(removeIndex(`${colLabel}.addMore`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
4285
+ setOpenSearchResult(true);
4286
+ }, children: getPickedValue() })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(removeIndex(`${colLabel}.typeToSearch`)), onChange: (event) => {
4287
+ onSearchChange(event);
4288
+ setOpenSearchResult(true);
4289
+ }, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), (searchText?.length ?? 0) > 0 && (jsxs(Fragment, { children: [isFetching && jsx(Fragment, { children: "isFetching" }), isLoading && jsx(Fragment, { children: "isLoading" }), isPending && jsx(Fragment, { children: "isPending" }), (isFetching || isLoading || isPending) && jsx(Spinner, {}), isError && (jsx(Icon, { color: "red.400", children: jsx(BiError, {}) })), jsx(Text, { justifySelf: "center", children: `${translate.t(removeIndex(`${colLabel}.total`))} ${count}, ${translate.t(removeIndex(`${colLabel}.showing`))} ${limit}` }), jsxs(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsx(Flex, { flexFlow: "column wrap", children:
4290
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4291
+ dataList.map((item) => {
4292
+ const selected = isMultiple
4293
+ ? watchIds.some((id) => item[column_ref] === id)
4294
+ : watchId === item[column_ref];
4295
+ return (jsx(Box, { cursor: "pointer", onClick: () => {
4296
+ if (!isMultiple) {
4297
+ setOpenSearchResult(false);
4298
+ setValue(colLabel, item[column_ref]);
4299
+ return;
4300
+ }
4301
+ const newSet = new Set([
4302
+ ...(watchIds ?? []),
4303
+ item[column_ref],
4304
+ ]);
4305
+ setValue(colLabel, [...newSet]);
4306
+ }, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
4307
+ ? renderDisplay(item)
4308
+ : item[display_column] }, item[column_ref]));
4309
+ }) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.emptySearchResult`)) })) }))] }), jsx(PaginationRoot, { justifySelf: "center", count: count, pageSize: 10, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxs(HStack, { gap: "4", children: [jsx(PaginationPrevTrigger, {}), count > 0 && jsx(PaginationPageText, {}), jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4310
+ };
4311
+
4312
+ const NumberInputRoot = React.forwardRef(function NumberInput$1(props, ref) {
4313
+ const { children, ...rest } = props;
4314
+ return (jsxs(NumberInput.Root, { ref: ref, variant: "outline", ...rest, children: [children, jsxs(NumberInput.Control, { children: [jsx(NumberInput.IncrementTrigger, {}), jsx(NumberInput.DecrementTrigger, {})] })] }));
4315
+ });
4316
+ const NumberInputField$1 = NumberInput.Input;
4317
+ NumberInput.Scrubber;
4318
+ NumberInput.Label;
4319
+
4320
+ const NumberInputField = ({ schema, column, prefix, }) => {
4321
+ const { register, formState: { errors }, watch } = useFormContext();
4322
+ const { translate } = useSchemaContext();
4323
+ const { required, gridColumn, gridRow } = schema;
4324
+ const isRequired = required?.some((columnId) => columnId === column);
4325
+ const colLabel = `${prefix}${column}`;
4326
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, gridColumn, gridRow, children: [jsx(NumberInputRoot, { children: jsx(NumberInputField$1, { ...register(`${colLabel}`, { required: isRequired }) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4327
+ };
4328
+
4329
+ const ObjectInput = ({ schema, column, prefix }) => {
4330
+ const { properties, gridRow, gridColumn = "1/span 12", required } = schema;
4331
+ const { translate } = useSchemaContext();
4332
+ const colLabel = `${prefix}${column}`;
4333
+ const isRequired = required?.some((columnId) => columnId === column);
4334
+ const { formState: { errors }, } = useFormContext();
4335
+ if (properties === undefined) {
4336
+ throw new Error(`properties is undefined when using ObjectInput`);
4337
+ }
4338
+ return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, isRequired && jsx("span", { children: "*" })] }), jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat("auto-fit", auto)`, children: Object.keys(properties ?? {}).map((key) => {
4339
+ return (
4340
+ // @ts-expect-error find suitable types
4341
+ jsx(ColumnRenderer, { column: `${key}`,
4342
+ prefix: `${prefix}${column}.`,
4343
+ properties }, `form-${colLabel}-${key}`));
4344
+ }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4345
+ };
4346
+
4347
+ const RecordInput$1 = ({ column, schema, prefix }) => {
4348
+ const { formState: { errors }, setValue, getValues, } = useFormContext();
4349
+ const { translate } = useSchemaContext();
4350
+ const { required, gridColumn, gridRow } = schema;
4351
+ const isRequired = required?.some((columnId) => columnId === column);
4352
+ const entries = Object.entries(getValues(column) ?? {});
4362
4353
  const [showNewEntries, setShowNewEntries] = useState(false);
4363
4354
  const [newKey, setNewKey] = useState();
4364
4355
  const [newValue, setNewValue] = useState();
4365
- if (schema.properties == undefined) {
4366
- throw new Error("schema properties when using DatePicker");
4367
- }
4368
- const { gridColumn, gridRow } = schema.properties[column];
4369
4356
  return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
4370
4357
  return (jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: key, onChange: (e) => {
4371
4358
  const filtered = entries.filter(([target]) => {
@@ -4409,6 +4396,15 @@ const ObjectInput = ({ column }) => {
4409
4396
  }, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
4410
4397
  };
4411
4398
 
4399
+ const StringInputField = ({ column, schema, prefix, }) => {
4400
+ const { register, formState: { errors }, } = useFormContext();
4401
+ const { translate } = useSchemaContext();
4402
+ const { required, gridColumn, gridRow } = schema;
4403
+ const isRequired = required?.some((columnId) => columnId === column);
4404
+ const colLabel = `${prefix}${column}`;
4405
+ return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Input, { ...register(`${colLabel}`, { required: isRequired }), autoComplete: "off" }), errors[colLabel] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }) }));
4406
+ };
4407
+
4412
4408
  const RadioCardItem = React.forwardRef(function RadioCardItem(props, ref) {
4413
4409
  const { inputProps, label, description, addon, icon, indicator = jsx(RadioCard.ItemIndicator, {}), indicatorPlacement = "end", ...rest } = props;
4414
4410
  const hasContent = label || description || icon;
@@ -4419,13 +4415,344 @@ const RadioCardRoot = RadioCard.Root;
4419
4415
  RadioCard.Label;
4420
4416
  RadioCard.ItemIndicator;
4421
4417
 
4422
- const TagPicker = ({ column }) => {
4418
+ const TagPicker = ({ column, schema, prefix }) => {
4419
+ const { watch, formState: { errors }, setValue, } = useFormContext();
4420
+ const { serverUrl } = useSchemaContext();
4421
+ if (schema.properties == undefined) {
4422
+ throw new Error("schema properties undefined when using DatePicker");
4423
+ }
4424
+ const { gridColumn, gridRow, in_table, object_id_column } = schema;
4425
+ if (in_table === undefined) {
4426
+ throw new Error("in_table is undefined when using TagPicker");
4427
+ }
4428
+ if (object_id_column === undefined) {
4429
+ throw new Error("object_id_column is undefined when using TagPicker");
4430
+ }
4431
+ const query = useQuery({
4432
+ queryKey: [`tagpicker`, in_table],
4433
+ queryFn: async () => {
4434
+ return await getTableData({
4435
+ serverUrl,
4436
+ in_table: "tables_tags_view",
4437
+ where: [
4438
+ {
4439
+ id: "table_name",
4440
+ value: [in_table],
4441
+ },
4442
+ ],
4443
+ limit: 100,
4444
+ });
4445
+ },
4446
+ staleTime: 10000,
4447
+ });
4448
+ const object_id = watch(object_id_column);
4449
+ const existingTagsQuery = useQuery({
4450
+ queryKey: [`existing`, { in_table, object_id_column }, object_id],
4451
+ queryFn: async () => {
4452
+ return await getTableData({
4453
+ serverUrl,
4454
+ in_table: in_table,
4455
+ where: [
4456
+ {
4457
+ id: object_id_column,
4458
+ value: object_id[0],
4459
+ },
4460
+ ],
4461
+ limit: 100,
4462
+ });
4463
+ },
4464
+ enabled: object_id != undefined,
4465
+ staleTime: 10000,
4466
+ });
4467
+ const { isLoading, isFetching, data, isPending, isError } = query;
4468
+ const dataList = data?.data ?? [];
4469
+ const existingTagList = existingTagsQuery.data?.data ?? [];
4470
+ if (!!object_id === false) {
4471
+ return jsx(Fragment, {});
4472
+ }
4473
+ return (jsxs(Flex, { flexFlow: "column", gap: 4, gridColumn,
4474
+ 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 }) => {
4475
+ 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) => {
4476
+ const existedTags = Object.values(all_tags)
4477
+ .filter(({ id }) => {
4478
+ return existingTagList.some(({ tag_id }) => tag_id === id);
4479
+ })
4480
+ .map(({ id }) => {
4481
+ return id;
4482
+ });
4483
+ setValue(`${column}.${parent_tag_name}.current`, [
4484
+ tagIds.value,
4485
+ ]);
4486
+ setValue(`${column}.${parent_tag_name}.old`, existedTags);
4487
+ }, children: jsx(Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
4488
+ if (existingTagList.some(({ tag_id }) => tag_id === id)) {
4489
+ return (jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", disabled: true }, `${tagName}-${id}`));
4490
+ }
4491
+ return (jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", colorPalette: "blue" }, `${tagName}-${id}`));
4492
+ }) }) })), !is_mutually_exclusive && (jsx(CheckboxGroup, { onValueChange: (tagIds) => {
4493
+ setValue(`${column}.${parent_tag_name}.current`, tagIds);
4494
+ }, children: jsx(Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
4495
+ if (existingTagList.some(({ tag_id }) => tag_id === id)) {
4496
+ return (jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%", disabled: true, colorPalette: "blue" }, `${tagName}-${id}`));
4497
+ }
4498
+ return (jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%" }, `${tagName}-${id}`));
4499
+ }) }) }))] }, `tag-${parent_tag_name}`));
4500
+ }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
4501
+ };
4502
+
4503
+ const SchemaRenderer = ({ schema, prefix, column, }) => {
4504
+ const colSchema = schema;
4505
+ const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
4506
+ if (type === "string") {
4507
+ if ((schema.enum ?? []).length > 0) {
4508
+ return jsx(EnumPicker, { schema: colSchema, prefix, column });
4509
+ }
4510
+ if (variant === "id-picker") {
4511
+ idPickerSanityCheck(column, foreign_key);
4512
+ return jsx(IdPicker, { schema: colSchema, prefix, column });
4513
+ }
4514
+ if (variant === "date-picker") {
4515
+ return jsx(DatePicker, { schema: colSchema, prefix, column });
4516
+ }
4517
+ return jsx(StringInputField, { schema: colSchema, prefix, column });
4518
+ }
4519
+ if (type === "number" || type === "integer") {
4520
+ return jsx(NumberInputField, { schema: colSchema, prefix, column });
4521
+ }
4522
+ if (type === "boolean") {
4523
+ return jsx(BooleanPicker, { schema: colSchema, prefix, column });
4524
+ }
4525
+ if (type === "object") {
4526
+ if (innerProperties) {
4527
+ return jsx(ObjectInput, { schema: colSchema, prefix, column });
4528
+ }
4529
+ return jsx(RecordInput$1, { schema: colSchema, prefix, column });
4530
+ }
4531
+ if (type === "array") {
4532
+ if (variant === "id-picker") {
4533
+ idPickerSanityCheck(column, foreign_key);
4534
+ return (jsx(IdPicker, { schema: colSchema, prefix, column, isMultiple: true }));
4535
+ }
4536
+ if (variant === "tag-picker") {
4537
+ return jsx(TagPicker, { schema: colSchema, prefix, column });
4538
+ }
4539
+ if (variant === "file-picker") {
4540
+ return jsx(FilePicker, { schema: colSchema, prefix, column });
4541
+ }
4542
+ if (items) {
4543
+ return jsx(ArrayRenderer, { schema: colSchema, prefix, column });
4544
+ }
4545
+ return jsx(Text, { children: `array ${column}` });
4546
+ }
4547
+ if (type === "null") {
4548
+ return jsx(Text, { children: `null ${column}` });
4549
+ }
4550
+ return jsx(Text, { children: "missing type" });
4551
+ };
4552
+
4553
+ const ColumnRenderer = ({ column, properties, prefix, }) => {
4554
+ const colSchema = properties[column];
4555
+ const colLabel = `${prefix}${column}`;
4556
+ if (colSchema === undefined) {
4557
+ throw new Error(`${colLabel} does not exist when using ColumnRenderer`);
4558
+ }
4559
+ return jsx(SchemaRenderer, { schema: colSchema, prefix, column });
4560
+ };
4561
+
4562
+ const ArrayViewer = ({ schema, column, prefix }) => {
4563
+ const { gridRow, gridColumn = "1/span 12", required, items } = schema;
4564
+ const { translate } = useSchemaContext();
4565
+ const colLabel = `${prefix}${column}`;
4566
+ const isRequired = required?.some((columnId) => columnId === column);
4567
+ const { watch, formState: { errors }, } = useFormContext();
4568
+ const values = watch(colLabel) ?? [];
4569
+ return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, isRequired && jsx("span", { children: "*" })] }), values.map((field, index) => (jsx(Flex, { flexFlow: "column", children: jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat("auto-fit", auto)`, children: jsx(SchemaViewer, { column: `${index}`,
4570
+ prefix: `${colLabel}.`,
4571
+ schema: items }) }) }, `form-${prefix}${column}.${index}`))), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4572
+ };
4573
+
4574
+ const BooleanViewer = ({ schema, column, prefix, }) => {
4575
+ const { watch, formState: { errors }, } = useFormContext();
4576
+ const { translate } = useSchemaContext();
4577
+ const { required, gridColumn, gridRow } = schema;
4578
+ const isRequired = required?.some((columnId) => columnId === column);
4579
+ const colLabel = `${prefix}${column}`;
4580
+ const value = watch(colLabel);
4581
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
4582
+ gridRow, children: [jsx(Text, { children: value
4583
+ ? translate.t(removeIndex(`${colLabel}.true`))
4584
+ : translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4585
+ };
4586
+
4587
+ const DateViewer = ({ column, schema, prefix }) => {
4588
+ const { watch, formState: { errors }, } = useFormContext();
4589
+ const { translate } = useSchemaContext();
4590
+ const { required, gridColumn, gridRow } = schema;
4591
+ const isRequired = required?.some((columnId) => columnId === column);
4592
+ const colLabel = `${prefix}${column}`;
4593
+ const selectedDate = watch(colLabel);
4594
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
4595
+ gridRow, children: [jsxs(Text, { children: [" ", selectedDate !== undefined ? selectedDate : ""] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
4596
+ };
4597
+
4598
+ const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
4599
+ const { watch, formState: { errors }, } = useFormContext();
4600
+ const { translate } = useSchemaContext();
4601
+ const { required } = schema;
4602
+ const isRequired = required?.some((columnId) => columnId === column);
4603
+ const { gridColumn, gridRow, renderDisplay } = schema;
4604
+ const colLabel = `${prefix}${column}`;
4605
+ const watchEnum = watch(colLabel);
4606
+ const watchEnums = (watch(colLabel) ?? []);
4607
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
4608
+ gridRow, children: [isMultiple && (jsx(Flex, { flexFlow: "wrap", gap: 1, children: watchEnums.map((enumValue) => {
4609
+ const item = enumValue;
4610
+ if (item === undefined) {
4611
+ return jsx(Fragment, { children: "undefined" });
4612
+ }
4613
+ return (jsx(Tag, { closable: true, children: !!renderDisplay === true
4614
+ ? renderDisplay(item)
4615
+ : translate.t(removeIndex(`${colLabel}.${item}`)) }));
4616
+ }) })), !isMultiple && (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4617
+ };
4618
+
4619
+ const FileViewer = ({ column, schema, prefix }) => {
4620
+ const { setValue, formState: { errors }, watch, } = useFormContext();
4621
+ const { translate } = useSchemaContext();
4622
+ const { required, gridColumn, gridRow } = schema;
4623
+ const isRequired = required?.some((columnId) => columnId === column);
4624
+ const currentFiles = (watch(column) ?? []);
4625
+ const colLabel = `${prefix}${column}`;
4626
+ return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: [jsx(FileDropzone, { onDrop: ({ files }) => {
4627
+ const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
4628
+ setValue(colLabel, [...currentFiles, ...newFiles]);
4629
+ }, placeholder: translate.t(`${colLabel}.fileDropzone`) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
4630
+ return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
4631
+ setValue(column, currentFiles.filter(({ name }) => {
4632
+ return name !== file.name;
4633
+ }));
4634
+ }, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
4635
+ }) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4636
+ };
4637
+
4638
+ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
4639
+ const { watch, formState: { errors }, } = useFormContext();
4640
+ const { idMap, translate } = useSchemaContext();
4641
+ const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
4642
+ const isRequired = required?.some((columnId) => columnId === column);
4643
+ const { display_column } = foreign_key;
4644
+ const colLabel = `${prefix}${column}`;
4645
+ const watchId = watch(colLabel);
4646
+ const watchIds = (watch(colLabel) ?? []);
4647
+ const getPickedValue = () => {
4648
+ if (Object.keys(idMap).length <= 0) {
4649
+ return "";
4650
+ }
4651
+ const record = idMap[watchId];
4652
+ if (record === undefined) {
4653
+ return "";
4654
+ }
4655
+ return record[display_column];
4656
+ };
4657
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
4658
+ gridRow, children: [isMultiple && (jsx(Flex, { flexFlow: "wrap", gap: 1, children: watchIds.map((id) => {
4659
+ const item = idMap[id];
4660
+ if (item === undefined) {
4661
+ return (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
4662
+ }
4663
+ return (jsx(Tag, { closable: true, children: !!renderDisplay === true
4664
+ ? renderDisplay(item)
4665
+ : item[display_column] }, id));
4666
+ }) })), !isMultiple && jsx(Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4667
+ };
4668
+
4669
+ const NumberViewer = ({ schema, column, prefix, }) => {
4670
+ const { watch, formState: { errors }, } = useFormContext();
4671
+ const { translate } = useSchemaContext();
4672
+ const { required, gridColumn, gridRow } = schema;
4673
+ const isRequired = required?.some((columnId) => columnId === column);
4674
+ const colLabel = `${prefix}${column}`;
4675
+ const value = watch(colLabel);
4676
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, gridColumn, gridRow, children: [jsx(Text, { children: value }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4677
+ };
4678
+
4679
+ const ObjectViewer = ({ schema, column, prefix }) => {
4680
+ const { properties, gridRow, gridColumn = "1/span 12", required } = schema;
4681
+ const { translate } = useSchemaContext();
4682
+ const colLabel = `${prefix}${column}`;
4683
+ const isRequired = required?.some((columnId) => columnId === column);
4684
+ const { formState: { errors }, } = useFormContext();
4685
+ if (properties === undefined) {
4686
+ throw new Error(`properties is undefined when using ObjectInput`);
4687
+ }
4688
+ return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, isRequired && jsx("span", { children: "*" })] }), jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat("auto-fit", auto)`, children: Object.keys(properties ?? {}).map((key) => {
4689
+ return (
4690
+ // @ts-expect-error find suitable types
4691
+ jsx(ColumnViewer, { column: `${key}`,
4692
+ prefix: `${prefix}${column}.`,
4693
+ properties }, `form-objectviewer-${colLabel}-${key}`));
4694
+ }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4695
+ };
4696
+
4697
+ const RecordInput = ({ column, schema, prefix }) => {
4698
+ const { formState: { errors }, setValue, getValues, } = useFormContext();
4699
+ const { translate } = useSchemaContext();
4700
+ const { required, gridColumn, gridRow } = schema;
4701
+ const isRequired = required?.some((columnId) => columnId === column);
4702
+ const entries = Object.entries(getValues(column) ?? {});
4703
+ const [showNewEntries, setShowNewEntries] = useState(false);
4704
+ const [newKey, setNewKey] = useState();
4705
+ const [newValue, setNewValue] = useState();
4706
+ return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
4707
+ return (jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: key, onChange: (e) => {
4708
+ const filtered = entries.filter(([target]) => {
4709
+ return target !== key;
4710
+ });
4711
+ setValue(column, Object.fromEntries([...filtered, [e.target.value, value]]));
4712
+ }, autoComplete: "off" }), jsx(Input, { value: value, onChange: (e) => {
4713
+ setValue(column, {
4714
+ ...getValues(column),
4715
+ [key]: e.target.value,
4716
+ });
4717
+ }, autoComplete: "off" }), jsx(IconButton, { variant: "ghost", onClick: () => {
4718
+ const filtered = entries.filter(([target]) => {
4719
+ return target !== key;
4720
+ });
4721
+ setValue(column, Object.fromEntries([...filtered]));
4722
+ }, children: jsx(CgClose, {}) })] }));
4723
+ }), jsx(Show, { when: showNewEntries, children: jsxs(Card.Root, { children: [jsx(Card.Body, { gap: "2", children: jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: newKey, onChange: (e) => {
4724
+ setNewKey(e.target.value);
4725
+ }, autoComplete: "off" }), jsx(Input, { value: newValue, onChange: (e) => {
4726
+ setNewValue(e.target.value);
4727
+ }, autoComplete: "off" })] }) }), jsxs(Card.Footer, { justifyContent: "flex-end", children: [jsx(IconButton, { variant: "subtle", onClick: () => {
4728
+ setShowNewEntries(false);
4729
+ setNewKey(undefined);
4730
+ setNewValue(undefined);
4731
+ }, children: jsx(CgClose, {}) }), jsx(Button, { onClick: () => {
4732
+ if (!!newKey === false) {
4733
+ setShowNewEntries(false);
4734
+ setNewKey(undefined);
4735
+ setNewValue(undefined);
4736
+ return;
4737
+ }
4738
+ setValue(column, Object.fromEntries([...entries, [newKey, newValue]]));
4739
+ setShowNewEntries(false);
4740
+ setNewKey(undefined);
4741
+ setNewValue(undefined);
4742
+ }, children: translate.t(`${column}.save`) })] })] }) }), jsx(Button, { onClick: () => {
4743
+ setShowNewEntries(true);
4744
+ setNewKey(undefined);
4745
+ setNewValue(undefined);
4746
+ }, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
4747
+ };
4748
+
4749
+ const TagViewer = ({ column, schema, prefix }) => {
4423
4750
  const { watch, formState: { errors }, setValue, } = useFormContext();
4424
- const { schema, serverUrl } = useSchemaContext();
4751
+ const { serverUrl } = useSchemaContext();
4425
4752
  if (schema.properties == undefined) {
4426
4753
  throw new Error("schema properties undefined when using DatePicker");
4427
4754
  }
4428
- const { gridColumn, gridRow, in_table, object_id_column } = schema.properties[column];
4755
+ const { gridColumn, gridRow, in_table, object_id_column } = schema;
4429
4756
  if (in_table === undefined) {
4430
4757
  throw new Error("in_table is undefined when using TagPicker");
4431
4758
  }
@@ -4451,7 +4778,7 @@ const TagPicker = ({ column }) => {
4451
4778
  });
4452
4779
  const object_id = watch(object_id_column);
4453
4780
  const existingTagsQuery = useQuery({
4454
- queryKey: [`existing`, in_table, object_id_column, object_id],
4781
+ queryKey: [`existing`, { in_table, object_id_column }, object_id],
4455
4782
  queryFn: async () => {
4456
4783
  return await getTableData({
4457
4784
  serverUrl,
@@ -4504,6 +4831,77 @@ const TagPicker = ({ column }) => {
4504
4831
  }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
4505
4832
  };
4506
4833
 
4834
+ const StringViewer = ({ column, schema, prefix, }) => {
4835
+ const { watch, formState: { errors }, } = useFormContext();
4836
+ const { translate } = useSchemaContext();
4837
+ const { required, gridColumn, gridRow } = schema;
4838
+ const isRequired = required?.some((columnId) => columnId === column);
4839
+ const colLabel = `${prefix}${column}`;
4840
+ const value = watch(colLabel);
4841
+ return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Text, { children: value }), errors[colLabel] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }) }));
4842
+ };
4843
+
4844
+ const SchemaViewer = ({ schema, prefix, column, }) => {
4845
+ const colSchema = schema;
4846
+ const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
4847
+ if (type === "string") {
4848
+ if ((schema.enum ?? []).length > 0) {
4849
+ return jsx(EnumViewer, { schema: colSchema, prefix, column });
4850
+ }
4851
+ if (variant === "id-picker") {
4852
+ idPickerSanityCheck(column, foreign_key);
4853
+ return jsx(IdViewer, { schema: colSchema, prefix, column });
4854
+ }
4855
+ if (variant === "date-picker") {
4856
+ return jsx(DateViewer, { schema: colSchema, prefix, column });
4857
+ }
4858
+ return jsx(StringViewer, { schema: colSchema, prefix, column });
4859
+ }
4860
+ if (type === "number" || type === "integer") {
4861
+ return jsx(NumberViewer, { schema: colSchema, prefix, column });
4862
+ }
4863
+ if (type === "boolean") {
4864
+ return jsx(BooleanViewer, { schema: colSchema, prefix, column });
4865
+ }
4866
+ if (type === "object") {
4867
+ if (innerProperties) {
4868
+ return jsx(ObjectViewer, { schema: colSchema, prefix, column });
4869
+ }
4870
+ return jsx(RecordInput, { schema: colSchema, prefix, column });
4871
+ }
4872
+ if (type === "array") {
4873
+ if (variant === "id-picker") {
4874
+ idPickerSanityCheck(column, foreign_key);
4875
+ return (jsx(IdViewer, { schema: colSchema, prefix, column, isMultiple: true }));
4876
+ }
4877
+ if (variant === "tag-picker") {
4878
+ return jsx(TagViewer, { schema: colSchema, prefix, column });
4879
+ }
4880
+ if (variant === "file-picker") {
4881
+ return jsx(FileViewer, { schema: colSchema, prefix, column });
4882
+ }
4883
+ if (items) {
4884
+ return jsx(ArrayViewer, { schema: colSchema, prefix, column });
4885
+ }
4886
+ return jsx(Text, { children: `array ${column}` });
4887
+ }
4888
+ if (type === "null") {
4889
+ return jsx(Text, { children: `null ${column}` });
4890
+ }
4891
+ return jsx(Text, { children: "missing type" });
4892
+ };
4893
+
4894
+ const ColumnViewer = ({ column, properties, prefix, }) => {
4895
+ if (properties === undefined) {
4896
+ return jsx(Fragment, {});
4897
+ }
4898
+ const colSchema = properties[column];
4899
+ if (colSchema === undefined) {
4900
+ throw new Error(`${column} does not exist when using ColumnRenderer`);
4901
+ }
4902
+ return jsx(SchemaViewer, { schema: colSchema, prefix, column });
4903
+ };
4904
+
4507
4905
  const idPickerSanityCheck = (column, foreign_key) => {
4508
4906
  if (!!foreign_key == false) {
4509
4907
  throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
@@ -4520,7 +4918,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
4520
4918
  }
4521
4919
  };
4522
4920
  const FormInternal = () => {
4523
- const { schema, requestUrl, order, ignore, onSubmit, rowNumber, idMap, translate, requestOptions, } = useSchemaContext();
4921
+ const { schema, requestUrl, order, ignore, include, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
4524
4922
  const methods = useFormContext();
4525
4923
  const [isSuccess, setIsSuccess] = useState(false);
4526
4924
  const [isError, setIsError] = useState(false);
@@ -4579,184 +4977,64 @@ const FormInternal = () => {
4579
4977
  setIsError(false);
4580
4978
  setIsConfirming(true);
4581
4979
  };
4582
- const renderOrder = (order, origin_list) => {
4583
- const not_exist = origin_list.filter((columnA) => !order.some((columnB) => columnA === columnB));
4584
- return [...order, ...not_exist];
4585
- };
4586
- const ordered = renderOrder(order, Object.keys(properties));
4587
- const getDataListProps = (value) => {
4588
- if (value == undefined || value.length <= 0) {
4589
- return {
4590
- value: `<${translate.t("empty") ?? "Empty"}>`,
4591
- color: "gray.400",
4592
- };
4593
- }
4594
- return {
4595
- value: value,
4596
- };
4980
+ const renderColumns = ({ order, keys, ignore, include, }) => {
4981
+ const included = include.length > 0 ? include : keys;
4982
+ const not_exist = included.filter((columnA) => !order.some((columnB) => columnA === columnB));
4983
+ const ordered = [...order, ...not_exist];
4984
+ const ignored = ordered.filter((column) => !ignore.some((shouldIgnore) => column === shouldIgnore));
4985
+ return ignored;
4597
4986
  };
4987
+ const ordered = renderColumns({
4988
+ order,
4989
+ keys: Object.keys(properties),
4990
+ ignore,
4991
+ include,
4992
+ });
4598
4993
  if (isSuccess) {
4599
- return (jsxs(Grid, { gap: 2, children: [jsx(Heading, { children: translate.t("title") }), jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: translate.t("submitSuccess") })] }), jsx(Button, { onClick: () => {
4600
- setIsError(false);
4601
- setIsSubmiting(false);
4602
- setIsSuccess(false);
4603
- setIsConfirming(false);
4604
- setValidatedData(undefined);
4605
- methods.reset();
4606
- }, formNoValidate: true, children: translate.t("submitAgain") })] }));
4994
+ return (jsxs(Grid, { gap: 2, children: [jsx(Heading, { children: translate.t("title") }), jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: translate.t("submitSuccess") })] }), jsx(Flex, { justifyContent: "end", children: jsx(Button, { onClick: () => {
4995
+ setIsError(false);
4996
+ setIsSubmiting(false);
4997
+ setIsSuccess(false);
4998
+ setIsConfirming(false);
4999
+ setValidatedData(undefined);
5000
+ methods.reset();
5001
+ }, formNoValidate: true, children: translate.t("submitAgain") }) })] }));
4607
5002
  }
4608
5003
  if (isConfirming) {
4609
- return (jsxs(Grid, { gap: 2, children: [jsxs(Heading, { children: [" ", translate.t("title")] }), jsx(DataListRoot, { orientation: "horizontal", gap: 4, display: "grid", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
4610
- if (properties === undefined) {
4611
- return jsx(Fragment, {});
4612
- }
4613
- const key = column;
4614
- const values = properties[column];
4615
- const shouldIgnore = ignore.some((column) => {
4616
- return column == key;
4617
- });
4618
- if (shouldIgnore) {
4619
- return jsx(Fragment, {});
4620
- }
4621
- const { type, variant, gridColumn, gridRow, foreign_key } = values;
4622
- if (type === "string") {
4623
- if (variant === "id-picker") {
4624
- idPickerSanityCheck(column, foreign_key);
4625
- return (jsx(IdViewer, { value: (validatedData ?? {})[column], column,
4626
- dataListItemProps: { gridColumn, gridRow } }, `form-${key}`));
4627
- }
4628
- if (variant === "date-picker") {
4629
- const value = (validatedData ?? {})[column];
4630
- if (!!value === false) {
4631
- return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(undefined) }, `form-${key}`));
4632
- }
4633
- const date = dayjs(value).format("YYYY-MM-DD");
4634
- return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(date) }, `form-${key}`));
4635
- }
4636
- return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
4637
- }
4638
- if (type === "object") {
4639
- const value = (validatedData ?? {})[column];
4640
- if (!!value === false) {
4641
- return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(undefined) }, `form-${key}`));
4642
- }
4643
- return (jsxs(Flex, { flexFlow: "column", gap: 2, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Text, { children: translate.t(`input.${column}`) }), jsx(DataListRoot, { orientation: "horizontal", padding: 4, borderColor: "gray.200", borderWidth: 1, borderRadius: 4, children: Object.entries(value).map(([key, value]) => {
4644
- return (jsx(DataListItem, { label: `${key}`, ...getDataListProps(value) }, `form-${column}-${key}`));
4645
- }) })] }, `form-${key}`));
4646
- }
4647
- if (type === "boolean") {
4648
- return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
4649
- }
4650
- if (type === "number" || type === "integer") {
4651
- return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
4652
- }
4653
- if (type === "array") {
4654
- if (variant === "tag-picker") {
4655
- const value = (validatedData ?? {})[column];
4656
- return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(JSON.stringify(value)) }, `form-${key}`));
4657
- }
4658
- if (variant === "file-picker") {
4659
- const fileNames = ((validatedData ?? {})[column] ?? []).map((file) => {
4660
- return file.name;
4661
- });
4662
- return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(JSON.stringify(fileNames)) }, `form-${key}`));
4663
- }
4664
- if (variant === "id-picker") {
4665
- const value = (validatedData ?? {})[column];
4666
- if (schema.properties == undefined) {
4667
- throw new Error("schema properties when using DatePicker");
4668
- }
4669
- const { foreign_key } = schema.properties[column];
4670
- if (foreign_key === undefined) {
4671
- throw new Error("foreign_key when variant is id-picker");
4672
- }
4673
- const { display_column } = foreign_key;
4674
- const mapped = value.map((item) => {
4675
- return idMap[item][display_column];
4676
- });
4677
- return (jsxs(Grid, { flexFlow: "column", gridColumn,
4678
- gridRow, children: [jsx(Text, { children: translate.t(`input.${column}`) }), jsx(RecordDisplay, { object: mapped })] }, `form-${key}`));
4679
- }
4680
- const objectString = JSON.stringify((validatedData ?? {})[column]);
4681
- return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(objectString) }, `form-${key}`));
4682
- }
4683
- if (type === "null") {
4684
- return jsx(Fragment, { children: `null ${column}` });
4685
- }
4686
- return jsx(Fragment, { children: `unknown type ${column}` });
4687
- }) }), jsx(Button, { onClick: () => {
4688
- onFormSubmit(validatedData);
4689
- }, children: translate.t("confirm") }), jsx(Button, { onClick: () => {
4690
- setIsConfirming(false);
4691
- }, variant: "subtle", children: translate.t("cancel") }), isSubmiting && (jsx(Box, { pos: "absolute", inset: "0", bg: "bg/80", children: jsx(Center, { h: "full", children: jsx(Spinner, { color: "teal.500" }) }) })), isError && (jsx(Fragment, { children: jsx(Alert.Root, { status: "error", children: jsx(Alert.Title, { children: jsx(AccordionRoot, { collapsible: true, defaultValue: ["b"], children: jsxs(AccordionItem, { value: "b", children: [jsxs(AccordionItemTrigger, { children: [jsx(Alert.Indicator, {}), `${error}`] }), jsx(AccordionItemContent, { children: `${JSON.stringify(error)}` })] }) }) }) }) }))] }));
5004
+ return (jsxs(Grid, { gap: 2, children: [jsxs(Heading, { children: [" ", translate.t("title")] }), jsx(Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
5005
+ return (jsx(ColumnViewer
5006
+ // @ts-expect-error find suitable types
5007
+ , {
5008
+ // @ts-expect-error find suitable types
5009
+ properties: properties, prefix: ``, column }, `form-viewer-${column}`));
5010
+ }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
5011
+ setIsConfirming(false);
5012
+ }, variant: "subtle", children: translate.t("cancel") }), jsx(Button, { onClick: () => {
5013
+ onFormSubmit(validatedData);
5014
+ }, children: translate.t("confirm") })] }), isSubmiting && (jsx(Box, { pos: "absolute", inset: "0", bg: "bg/80", children: jsx(Center, { h: "full", children: jsx(Spinner, { color: "teal.500" }) }) })), isError && (jsx(Fragment, { children: jsx(Alert.Root, { status: "error", children: jsx(Alert.Title, { children: jsx(AccordionRoot, { collapsible: true, defaultValue: ["b"], children: jsxs(AccordionItem, { value: "b", children: [jsxs(AccordionItemTrigger, { children: [jsx(Alert.Indicator, {}), `${error}`] }), jsx(AccordionItemContent, { children: `${JSON.stringify(error)}` })] }) }) }) }) }))] }));
4692
5015
  }
4693
- return (jsxs(Fragment, { children: [jsxs(Grid, { gap: 2, children: [jsxs(Heading, { children: [" ", translate.t("title")] }), jsx(Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
4694
- if (properties === undefined) {
4695
- return jsx(Fragment, {});
4696
- }
4697
- const key = column;
4698
- const values = properties[column];
4699
- const shouldIgnore = ignore.some((column) => {
4700
- return column == key;
4701
- });
4702
- if (shouldIgnore) {
4703
- return jsx(Fragment, {});
4704
- }
4705
- //@ts-expect-error TODO: add more fields to support form-creation
4706
- const { type, variant, foreign_key } = values;
4707
- if (type === "string") {
4708
- // @ts-expect-error enum should exists
4709
- if ((values.enum ?? []).length > 0) {
4710
- return jsx(EnumPicker, { column: key }, `form-${key}`);
4711
- }
4712
- if (variant === "id-picker") {
4713
- idPickerSanityCheck(column, foreign_key);
4714
- return jsx(IdPicker, { column: key }, `form-${key}`);
4715
- }
4716
- if (variant === "date-picker") {
4717
- return jsx(DatePicker, { column: key }, `form-${key}`);
4718
- }
4719
- return jsx(StringInputField, { column: key }, `form-${key}`);
4720
- }
4721
- if (type === "number" || type === "integer") {
4722
- return jsx(NumberInputField, { column: key }, `form-${key}`);
4723
- }
4724
- if (type === "boolean") {
4725
- return jsx(BooleanPicker, { column: key }, `form-${key}`);
4726
- }
4727
- if (type === "object") {
4728
- return jsx(ObjectInput, { column: key }, `form-${key}`);
4729
- }
4730
- if (type === "array") {
4731
- if (variant === "id-picker") {
4732
- idPickerSanityCheck(column, foreign_key);
4733
- return jsx(IdPicker, { column: key, isMultiple: true }, `form-${key}`);
4734
- }
4735
- if (variant === "tag-picker") {
4736
- return jsx(TagPicker, { column: key }, `form-${key}`);
4737
- }
4738
- if (variant === "file-picker") {
4739
- return jsx(FilePicker, { column: key }, `form-${key}`);
4740
- }
4741
- return jsx(Text, { children: `array ${column}` }, `form-${key}`);
4742
- }
4743
- if (type === "null") {
4744
- return jsx(Text, { children: `null ${column}` }, `form-${key}`);
4745
- }
4746
- return jsx(Text, { children: "missing type" }, `form-${key}`);
4747
- }) }), jsx(Button, { onClick: () => {
4748
- methods.handleSubmit(onValid)();
4749
- }, formNoValidate: true, children: translate.t("submit") })] }), isError && (jsxs(Fragment, { children: ["isError", jsxs(Fragment, { children: [" ", `${error}`] })] }))] }));
5016
+ return (jsx(Fragment, { children: jsxs(Grid, { gap: "2", children: [jsxs(Heading, { children: [" ", translate.t("title")] }), jsx(Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
5017
+ return (jsx(ColumnRenderer
5018
+ // @ts-expect-error find suitable types
5019
+ , {
5020
+ // @ts-expect-error find suitable types
5021
+ properties: properties, prefix: ``, column }, `form-input-${column}`));
5022
+ }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
5023
+ methods.reset();
5024
+ }, variant: "subtle", children: translate.t("reset") }), jsx(Button, { onClick: () => {
5025
+ methods.handleSubmit(onValid)();
5026
+ }, formNoValidate: true, children: translate.t("submit") })] })] }) }));
4750
5027
  };
4751
- const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, }) => {
4752
- const { properties } = schema;
4753
- idListSanityCheck("order", order, properties);
4754
- idListSanityCheck("ignore", ignore, properties);
5028
+ const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], include = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, }) => {
5029
+ // const { properties } = schema;
5030
+ // idListSanityCheck("order", order, properties as object);
5031
+ // idListSanityCheck("ignore", ignore, properties as object);
4755
5032
  return (jsx(SchemaFormContext.Provider, { value: {
4756
5033
  schema,
4757
5034
  serverUrl,
4758
5035
  order,
4759
5036
  ignore,
5037
+ include,
4760
5038
  // @ts-expect-error TODO: find appropriate types
4761
5039
  onSubmit,
4762
5040
  rowNumber,
@@ -4768,7 +5046,9 @@ const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [],
4768
5046
  };
4769
5047
 
4770
5048
  const useForm = ({ preLoadedValues, keyPrefix }) => {
4771
- const form = useForm$1({ values: preLoadedValues });
5049
+ const form = useForm$1({
5050
+ values: preLoadedValues,
5051
+ });
4772
5052
  const [idMap, setIdMap] = useState({});
4773
5053
  const translate = useTranslation("", { keyPrefix });
4774
5054
  return {
@@ -4795,4 +5075,4 @@ const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) =
4795
5075
  }
4796
5076
  };
4797
5077
 
4798
- export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultTable, DensityToggleButton, EditOrderButton, EditSortingButton, EmptyState, ErrorAlert, FilterDialog, FilterOptions, Form, GlobalFilter, PageSizeControl, Pagination, RecordDisplay, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TableSelector, TableSorter, TableViewer, TextCell, ViewDialog, getColumns, getMultiDates, getRangeDates, useDataTable, useDataTableContext, useDataTableServer, useForm, widthSanityCheck };
5078
+ export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultTable, DensityToggleButton, EditOrderButton, EditSortingButton, EmptyState, ErrorAlert, FilterDialog, FilterOptions, Form, GlobalFilter, PageSizeControl, Pagination, RecordDisplay, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TableSelector, TableSorter, TableViewer, TextCell, ViewDialog, getColumns, getMultiDates, getRangeDates, idPickerSanityCheck, useDataTable, useDataTableContext, useDataTableServer, useForm, widthSanityCheck };