@bsol-oss/react-datatable5 11.0.0-beta.5 → 11.0.0-beta.7

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 (35) hide show
  1. package/dist/index.d.ts +4 -3
  2. package/dist/index.js +472 -120
  3. package/dist/index.mjs +474 -122
  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 +1 -1
  7. package/dist/types/components/Form/components/fields/ArrayRenderer.d.ts +7 -0
  8. package/dist/types/components/Form/components/fields/BooleanPicker.d.ts +7 -0
  9. package/dist/types/components/Form/components/fields/ColumnRenderer.d.ts +7 -0
  10. package/dist/types/components/Form/components/fields/DatePicker.d.ts +7 -0
  11. package/dist/types/components/Form/components/fields/EnumPicker.d.ts +8 -0
  12. package/dist/types/components/Form/components/fields/FilePicker.d.ts +5 -0
  13. package/dist/types/components/Form/components/fields/IdPicker.d.ts +8 -0
  14. package/dist/types/components/Form/components/fields/NumberInputField.d.ts +7 -0
  15. package/dist/types/components/Form/components/fields/ObjectInput.d.ts +7 -0
  16. package/dist/types/components/Form/components/fields/RecordInput.d.ts +7 -0
  17. package/dist/types/components/Form/components/fields/SchemaRenderer.d.ts +7 -0
  18. package/dist/types/components/Form/components/fields/StringInputField.d.ts +12 -0
  19. package/dist/types/components/Form/components/fields/TagPicker.d.ts +25 -0
  20. package/dist/types/components/Form/components/types/CustomJSONSchema7.d.ts +15 -0
  21. package/dist/types/components/Form/components/viewers/ArrayViewer.d.ts +7 -0
  22. package/dist/types/components/Form/components/viewers/BooleanViewer.d.ts +7 -0
  23. package/dist/types/components/Form/components/viewers/ColumnViewer.d.ts +7 -0
  24. package/dist/types/components/Form/components/viewers/DateViewer.d.ts +7 -0
  25. package/dist/types/components/Form/components/viewers/EnumViewer.d.ts +8 -0
  26. package/dist/types/components/Form/components/viewers/FileViewer.d.ts +5 -0
  27. package/dist/types/components/Form/components/viewers/IdViewer.d.ts +8 -0
  28. package/dist/types/components/Form/components/viewers/NumberViewer.d.ts +7 -0
  29. package/dist/types/components/Form/components/viewers/ObjectViewer.d.ts +7 -0
  30. package/dist/types/components/Form/components/viewers/RecordViewer.d.ts +7 -0
  31. package/dist/types/components/Form/components/viewers/SchemaViewer.d.ts +7 -0
  32. package/dist/types/components/Form/components/viewers/StringViewer.d.ts +12 -0
  33. package/dist/types/components/Form/components/viewers/TagViewer.d.ts +30 -0
  34. package/dist/types/components/Form/utils/removeIndex.d.ts +1 -0
  35. package/package.json +1 -1
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, Accordion, Field as Field$1, Popover, NumberInput, Show, RadioCard, CheckboxGroup, Heading, Center } from '@chakra-ui/react';
2
+ import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, 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';
@@ -27,7 +27,7 @@ import { GrAscend, GrDescend } from 'react-icons/gr';
27
27
  import { HiColorSwatch } from 'react-icons/hi';
28
28
  import { useTranslation } from 'react-i18next';
29
29
  import axios from 'axios';
30
- import { useFormContext, useFieldArray, FormProvider, useForm as useForm$1 } from 'react-hook-form';
30
+ import { useFormContext, FormProvider, useForm as useForm$1 } from 'react-hook-form';
31
31
  import dayjs from 'dayjs';
32
32
  import { TiDeleteOutline } from 'react-icons/ti';
33
33
 
@@ -2605,8 +2605,8 @@ const RecordDisplay = ({ object, boxProps, translate, prefix = "", }) => {
2605
2605
  }) }));
2606
2606
  };
2607
2607
 
2608
- const DataDisplay = ({ variant = "", translate }) => {
2609
- const { table } = useDataTableContext();
2608
+ const CellRenderer = ({ cell }) => {
2609
+ const { translate } = useDataTableContext();
2610
2610
  const getLabel = ({ columnId }) => {
2611
2611
  if (translate !== undefined) {
2612
2612
  return translate.t(`${columnId}`);
@@ -2631,66 +2631,51 @@ const DataDisplay = ({ variant = "", translate }) => {
2631
2631
  }
2632
2632
  throw new Error(`value is unknown, ${typeof value}`);
2633
2633
  };
2634
- if (variant == "horizontal") {
2635
- return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
2636
- 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) => {
2637
- const showCustomDataDisplay = cell.column.columnDef.meta?.showCustomDisplay ?? false;
2638
- if (showCustomDataDisplay) {
2639
- return (jsx(Flex, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
2640
- }
2641
- const value = cell.getValue();
2642
- if (typeof value === "object") {
2643
- return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: getLabel({ columnId: cell.column.id }) }), jsx(RecordDisplay, { boxProps: {
2644
- borderWidth: 1,
2645
- borderRadius: 4,
2646
- borderColor: "gray.400",
2647
- paddingX: 4,
2648
- paddingY: 2,
2649
- }, object: value })] }, cell.id));
2650
- }
2651
- 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));
2652
- }) }) }) }, `chakra-table-card-${row.id}`));
2653
- }) }));
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));
2654
2643
  }
2655
- if (variant == "stats") {
2656
- return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
2657
- 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) => {
2658
- const showCustomDataDisplay = cell.column.columnDef.meta?.showCustomDisplay ?? false;
2659
- if (showCustomDataDisplay) {
2660
- return (jsx(Flex, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
2661
- }
2662
- const value = cell.getValue();
2663
- if (typeof value === "object") {
2664
- 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: {
2665
- borderWidth: 1,
2666
- borderRadius: 4,
2667
- borderColor: "gray.400",
2668
- paddingX: 4,
2669
- paddingY: 2,
2670
- }, object: value })] }));
2671
- }
2672
- 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));
2673
- }) }) }) }, `chakra-table-card-${row.id}`));
2674
- }) }));
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));
2675
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();
2676
2658
  return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
2677
- 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) => {
2678
- const showCustomDataDisplay = cell.column.columnDef.meta?.showCustomDisplay ?? false;
2679
- if (showCustomDataDisplay) {
2680
- return (jsx(Flex, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
2681
- }
2682
- const value = cell.getValue();
2683
- if (typeof value === "object") {
2684
- return (jsxs(DataList.Item, { children: [jsx(DataList.ItemLabel, { children: getLabel({ columnId: cell.column.id }) }), jsx(RecordDisplay, { boxProps: {
2685
- borderWidth: 1,
2686
- borderRadius: 4,
2687
- borderColor: "gray.400",
2688
- paddingX: 4,
2689
- paddingY: 2,
2690
- }, object: value })] }, cell.id));
2691
- }
2692
- 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));
2693
- }) }) }) }, `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}`));
2694
2679
  }) }));
2695
2680
  };
2696
2681
 
@@ -3478,7 +3463,7 @@ const widthSanityCheck = (widthList, ignoreList, properties) => {
3478
3463
  throw new Error(`The width list is too long given from the number of remaining properties after ignore some.`);
3479
3464
  }
3480
3465
  };
3481
- const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth = 400, translate, }) => {
3466
+ const getColumns = ({ schema, include = [], ignore = [], width = [], meta = {}, defaultWidth = 400, translate, }) => {
3482
3467
  const { properties } = schema;
3483
3468
  idListSanityCheck("ignore", ignore, properties);
3484
3469
  widthSanityCheck(width, ignore, properties);
@@ -3490,7 +3475,8 @@ const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth =
3490
3475
  return snakeToLabel(column);
3491
3476
  };
3492
3477
  const keys = Object.keys(properties);
3493
- const ignored = keys.filter((key) => {
3478
+ const included = include.length > 0 ? include : keys;
3479
+ const ignored = included.filter((key) => {
3494
3480
  return !ignore.some((shouldIgnoreKey) => key === shouldIgnoreKey);
3495
3481
  });
3496
3482
  const columnHelper = createColumnHelper();
@@ -3578,23 +3564,40 @@ const AccordionItemContent = React.forwardRef(function AccordionItemContent(prop
3578
3564
  const AccordionRoot = Accordion.Root;
3579
3565
  const AccordionItem = Accordion.Item;
3580
3566
 
3567
+ function removeIndex(str) {
3568
+ return str.replace(/\.\d+\./g, '.');
3569
+ }
3570
+
3581
3571
  const ArrayRenderer = ({ schema, column, prefix, }) => {
3582
3572
  const { gridRow, gridColumn = "1/span 12", required, items } = schema;
3573
+ // @ts-expect-error TODO: find suitable types
3574
+ const { type } = items;
3583
3575
  const { translate } = useSchemaContext();
3584
3576
  const colLabel = `${prefix}${column}`;
3585
3577
  const isRequired = required?.some((columnId) => columnId === column);
3586
- const { formState: { errors }, control, } = useFormContext();
3587
- const { fields, append, prepend, remove, swap, move, insert } = useFieldArray({
3588
- control, // control props comes from useForm (optional: if you are using FormContext)
3589
- name: "test", // unique name for your Field Array
3590
- });
3591
- return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(`${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: `${column}.${index}`,
3592
- prefix: `${prefix}`,
3593
- schema: items }, `form-${column}`) }), jsx(Flex, { justifyContent: "end", children: jsx(Button$1, { variant: "ghost", onClick: () => {
3594
- remove(index);
3595
- }, children: translate.t(`${colLabel}.remove`) }) })] }))), jsx(Flex, { children: jsx(Button$1, { onClick: () => {
3596
- append({});
3597
- }, children: translate.t(`${colLabel}.add`) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
3578
+ const { formState: { errors }, setValue, watch, } = useFormContext();
3579
+ const fields = (watch(colLabel) ?? []);
3580
+ 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}`,
3581
+ prefix: `${colLabel}.`,
3582
+ schema: items }) }), jsx(Flex, { justifyContent: "end", children: jsx(Button$1, { variant: "ghost", onClick: () => {
3583
+ setValue(colLabel, fields.filter((_, curIndex) => {
3584
+ return curIndex === index;
3585
+ }));
3586
+ }, children: translate.t(removeIndex(`${colLabel}.remove`)) }) })] }, `${colLabel}.${index}`))), jsx(Flex, { children: jsx(Button$1, { onClick: () => {
3587
+ if (type === "number") {
3588
+ setValue(colLabel, [...fields, 0]);
3589
+ return;
3590
+ }
3591
+ if (type === "string") {
3592
+ setValue(colLabel, [...fields, ""]);
3593
+ return;
3594
+ }
3595
+ if (type === "boolean") {
3596
+ setValue(colLabel, [...fields, false]);
3597
+ return;
3598
+ }
3599
+ setValue(colLabel, [...fields, {}]);
3600
+ }, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
3598
3601
  };
3599
3602
 
3600
3603
  const Field = React.forwardRef(function Field(props, ref) {
@@ -3609,10 +3612,10 @@ const BooleanPicker = ({ schema, column, prefix }) => {
3609
3612
  const isRequired = required?.some((columnId) => columnId === column);
3610
3613
  const colLabel = `${prefix}${column}`;
3611
3614
  const value = watch(colLabel);
3612
- return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
3613
- gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface", onSelect: () => {
3615
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
3616
+ gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface", onChange: () => {
3614
3617
  setValue(colLabel, !value);
3615
- } }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
3618
+ } }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
3616
3619
  };
3617
3620
 
3618
3621
  const monthNamesShort = [
@@ -3710,7 +3713,7 @@ const DatePicker = ({ column, schema, prefix }) => {
3710
3713
  const colLabel = `${prefix}${column}`;
3711
3714
  const [open, setOpen] = useState(false);
3712
3715
  const selectedDate = watch(colLabel);
3713
- return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
3716
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
3714
3717
  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: () => {
3715
3718
  setOpen(true);
3716
3719
  }, children: selectedDate !== undefined ? selectedDate : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
@@ -3720,9 +3723,9 @@ const DatePicker = ({ column, schema, prefix }) => {
3720
3723
  selected: new Date(selectedDate),
3721
3724
  // @ts-expect-error TODO: find appropriate types
3722
3725
  onDateSelected: ({ date }) => {
3723
- setValue(column, dayjs(date).format("YYYY-MM-DD"));
3726
+ setValue(colLabel, dayjs(date).format("YYYY-MM-DD"));
3724
3727
  setOpen(false);
3725
- } })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
3728
+ } })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
3726
3729
  };
3727
3730
 
3728
3731
  function filterArray(array, searchTerm) {
@@ -3745,8 +3748,9 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
3745
3748
  const [limit, setLimit] = useState(10);
3746
3749
  const [openSearchResult, setOpenSearchResult] = useState();
3747
3750
  const ref = useRef(null);
3748
- const watchEnum = watch(column);
3749
- const watchEnums = (watch(column) ?? []);
3751
+ const colLabel = `${prefix}${column}`;
3752
+ const watchEnum = watch(colLabel);
3753
+ const watchEnums = (watch(colLabel) ?? []);
3750
3754
  const dataList = schema.enum ?? [];
3751
3755
  const count = schema.enum?.length ?? 0;
3752
3756
  const isDirty = (searchText?.length ?? 0) > 0;
@@ -3754,8 +3758,7 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
3754
3758
  setSearchText(event.target.value);
3755
3759
  setLimit(10);
3756
3760
  };
3757
- const col = `${prefix}${column}`;
3758
- return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
3761
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
3759
3762
  gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
3760
3763
  const item = enumValue;
3761
3764
  if (item === undefined) {
@@ -3764,12 +3767,16 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
3764
3767
  return (jsx(Tag, { closable: true, onClick: () => {
3765
3768
  // setSelectedEnums((state) => state.filter((id) => id != item));
3766
3769
  setValue(column, watchEnums.filter((id) => id != item));
3767
- }, children: !!renderDisplay === true ? renderDisplay(item) : item }));
3770
+ }, children: !!renderDisplay === true
3771
+ ? renderDisplay(item)
3772
+ : translate.t(removeIndex(`${colLabel}.${item}`)) }));
3768
3773
  }), jsx(Tag, { cursor: "pointer", onClick: () => {
3769
3774
  setOpenSearchResult(true);
3770
- }, children: "Add" })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
3775
+ }, children: translate.t(removeIndex(`${colLabel}.addMore`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
3771
3776
  setOpenSearchResult(true);
3772
- }, 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) => {
3777
+ }, children: watchEnum === undefined
3778
+ ? ""
3779
+ : 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) => {
3773
3780
  onSearchChange(event);
3774
3781
  setOpenSearchResult(true);
3775
3782
  }, 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) => {
@@ -3779,15 +3786,15 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
3779
3786
  return (jsx(Box, { cursor: "pointer", onClick: () => {
3780
3787
  if (!isMultiple) {
3781
3788
  setOpenSearchResult(false);
3782
- setValue(column, item);
3789
+ setValue(colLabel, item);
3783
3790
  return;
3784
3791
  }
3785
3792
  const newSet = new Set([...(watchEnums ?? []), item]);
3786
- setValue(column, [...newSet]);
3793
+ setValue(colLabel, [...newSet]);
3787
3794
  }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
3788
3795
  ? renderDisplay(item)
3789
- : translate.t(`${col}.${item}`) }, `${column}-${item}`));
3790
- }) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Fragment, { children: translate.t(`${col}.emptySearchResult`) })) }))] })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${col}.fieldRequired`) }))] }));
3796
+ : translate.t(removeIndex(`${colLabel}.${item}`)) }, `${colLabel}-${item}`));
3797
+ }) }), 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`)) }))] }));
3791
3798
  };
3792
3799
 
3793
3800
  function isEnteringWindow(_ref) {
@@ -4148,17 +4155,17 @@ const FilePicker = ({ column, schema, prefix }) => {
4148
4155
  const { required, gridColumn, gridRow } = schema;
4149
4156
  const isRequired = required?.some((columnId) => columnId === column);
4150
4157
  const currentFiles = (watch(column) ?? []);
4151
- const col = `${prefix}${column}`;
4152
- return (jsxs(Field, { label: `${translate.t(`${col}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: [jsx(FileDropzone, { onDrop: ({ files }) => {
4158
+ const colLabel = `${prefix}${column}`;
4159
+ 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 }) => {
4153
4160
  const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
4154
- setValue(col, [...currentFiles, ...newFiles]);
4155
- }, placeholder: translate.t(`${col}.fileDropzone`) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
4161
+ setValue(colLabel, [...currentFiles, ...newFiles]);
4162
+ }, placeholder: translate.t(removeIndex(`${colLabel}.fileDropzone`)) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
4156
4163
  return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
4157
4164
  setValue(column, currentFiles.filter(({ name }) => {
4158
4165
  return name !== file.name;
4159
4166
  }));
4160
4167
  }, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
4161
- }) }), errors[`${col}`] && (jsx(Text, { color: "red.400", children: translate.t(`${col}.fieldRequired`) }))] }));
4168
+ }) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4162
4169
  };
4163
4170
 
4164
4171
  const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
@@ -4200,7 +4207,6 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4200
4207
  const [openSearchResult, setOpenSearchResult] = useState();
4201
4208
  const [page, setPage] = useState(0);
4202
4209
  const ref = useRef(null);
4203
- const selectedIds = watch(column) ?? [];
4204
4210
  const colLabel = `${prefix}${column}`;
4205
4211
  const query = useQuery({
4206
4212
  queryKey: [`idpicker`, { column, searchText, limit, page }],
@@ -4237,8 +4243,8 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4237
4243
  setPage(0);
4238
4244
  setLimit(10);
4239
4245
  };
4240
- const watchId = watch(column);
4241
- const watchIds = (watch(column) ?? []);
4246
+ const watchId = watch(colLabel);
4247
+ const watchIds = (watch(colLabel) ?? []);
4242
4248
  const getPickedValue = () => {
4243
4249
  if (Object.keys(idMap).length <= 0) {
4244
4250
  return "";
@@ -4249,11 +4255,11 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4249
4255
  }
4250
4256
  return record[display_column];
4251
4257
  };
4252
- return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
4253
- gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
4258
+ return (jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.fieldLabel`)))}`, required: isRequired, alignItems: "stretch", gridColumn,
4259
+ gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchIds.map((id) => {
4254
4260
  const item = idMap[id];
4255
4261
  if (item === undefined) {
4256
- return (jsxs(Text, { children: [" ", translate.t(`${colLabel}.undefined`)] }, id));
4262
+ return (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
4257
4263
  }
4258
4264
  return (jsx(Tag, { closable: true, onClick: () => {
4259
4265
  setValue(column, watchIds.filter((id) => id != item[column_ref]));
@@ -4262,12 +4268,12 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4262
4268
  : item[display_column] }, id));
4263
4269
  }), jsx(Tag, { cursor: "pointer", onClick: () => {
4264
4270
  setOpenSearchResult(true);
4265
- }, children: translate.t(`${colLabel}.addMore`) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
4271
+ }, children: translate.t(removeIndex(`${colLabel}.addMore`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
4266
4272
  setOpenSearchResult(true);
4267
- }, 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(`${colLabel}.typeToSearch`), onChange: (event) => {
4273
+ }, 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) => {
4268
4274
  onSearchChange(event);
4269
4275
  setOpenSearchResult(true);
4270
- }, 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(`${colLabel}.total`)} ${count}, ${translate.t(`${colLabel}.showing`)} ${limit}` }), jsxs(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsx(Flex, { flexFlow: "column wrap", children:
4276
+ }, 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(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:
4271
4277
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4272
4278
  dataList.map((item) => {
4273
4279
  const selected = isMultiple
@@ -4283,11 +4289,11 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
4283
4289
  ...(watchIds ?? []),
4284
4290
  item[column_ref],
4285
4291
  ]);
4286
- setValue(column, [...newSet]);
4292
+ setValue(colLabel, [...newSet]);
4287
4293
  }, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
4288
4294
  ? renderDisplay(item)
4289
4295
  : item[display_column] }, item[column_ref]));
4290
- }) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Text, { children: translate.t(`${colLabel}.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[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
4296
+ }) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.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[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4291
4297
  };
4292
4298
 
4293
4299
  const NumberInputRoot = React.forwardRef(function NumberInput$1(props, ref) {
@@ -4299,12 +4305,12 @@ NumberInput.Scrubber;
4299
4305
  NumberInput.Label;
4300
4306
 
4301
4307
  const NumberInputField = ({ schema, column, prefix, }) => {
4302
- const { register, formState: { errors }, } = useFormContext();
4308
+ const { register, formState: { errors }, watch } = useFormContext();
4303
4309
  const { translate } = useSchemaContext();
4304
4310
  const { required, gridColumn, gridRow } = schema;
4305
4311
  const isRequired = required?.some((columnId) => columnId === column);
4306
4312
  const colLabel = `${prefix}${column}`;
4307
- return (jsxs(Field, { label: `${translate.t(`${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(`${colLabel}.fieldRequired`) }))] }));
4313
+ 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`)) }))] }));
4308
4314
  };
4309
4315
 
4310
4316
  const ObjectInput = ({ schema, column, prefix }) => {
@@ -4312,20 +4318,20 @@ const ObjectInput = ({ schema, column, prefix }) => {
4312
4318
  const { translate } = useSchemaContext();
4313
4319
  const colLabel = `${prefix}${column}`;
4314
4320
  const isRequired = required?.some((columnId) => columnId === column);
4315
- const { watch, formState: { errors }, setValue, control, } = useFormContext();
4321
+ const { formState: { errors }, } = useFormContext();
4316
4322
  if (properties === undefined) {
4317
4323
  throw new Error(`properties is undefined when using ObjectInput`);
4318
4324
  }
4319
- return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(`${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) => {
4325
+ 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) => {
4320
4326
  return (
4321
4327
  // @ts-expect-error find suitable types
4322
4328
  jsx(ColumnRenderer, { column: `${key}`,
4323
4329
  prefix: `${prefix}${column}.`,
4324
- properties }, `form-${column}`));
4325
- }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
4330
+ properties }, `form-${colLabel}-${key}`));
4331
+ }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4326
4332
  };
4327
4333
 
4328
- const RecordInput = ({ column, schema, prefix }) => {
4334
+ const RecordInput$1 = ({ column, schema, prefix }) => {
4329
4335
  const { formState: { errors }, setValue, getValues, } = useFormContext();
4330
4336
  const { translate } = useSchemaContext();
4331
4337
  const { required, gridColumn, gridRow } = schema;
@@ -4383,7 +4389,7 @@ const StringInputField = ({ column, schema, prefix, }) => {
4383
4389
  const { required, gridColumn, gridRow } = schema;
4384
4390
  const isRequired = required?.some((columnId) => columnId === column);
4385
4391
  const colLabel = `${prefix}${column}`;
4386
- return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(`${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(`${colLabel}.fieldRequired`) }))] }) }));
4392
+ 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`)) }))] }) }));
4387
4393
  };
4388
4394
 
4389
4395
  const RadioCardItem = React.forwardRef(function RadioCardItem(props, ref) {
@@ -4507,7 +4513,7 @@ const SchemaRenderer = ({ schema, prefix, column, }) => {
4507
4513
  if (innerProperties) {
4508
4514
  return jsx(ObjectInput, { schema: colSchema, prefix, column });
4509
4515
  }
4510
- return jsx(RecordInput, { schema: colSchema, prefix, column });
4516
+ return jsx(RecordInput$1, { schema: colSchema, prefix, column });
4511
4517
  }
4512
4518
  if (type === "array") {
4513
4519
  if (variant === "id-picker") {
@@ -4532,15 +4538,355 @@ const SchemaRenderer = ({ schema, prefix, column, }) => {
4532
4538
  };
4533
4539
 
4534
4540
  const ColumnRenderer = ({ column, properties, prefix, }) => {
4541
+ const colSchema = properties[column];
4542
+ const colLabel = `${prefix}${column}`;
4543
+ if (colSchema === undefined) {
4544
+ throw new Error(`${colLabel} does not exist when using ColumnRenderer`);
4545
+ }
4546
+ return jsx(SchemaRenderer, { schema: colSchema, prefix, column });
4547
+ };
4548
+
4549
+ const ArrayViewer = ({ schema, column, prefix }) => {
4550
+ const { gridRow, gridColumn = "1/span 12", required, items } = schema;
4551
+ const { translate } = useSchemaContext();
4552
+ const colLabel = `${prefix}${column}`;
4553
+ const isRequired = required?.some((columnId) => columnId === column);
4554
+ const { watch, formState: { errors }, } = useFormContext();
4555
+ const values = watch(colLabel) ?? [];
4556
+ 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}`,
4557
+ prefix: `${colLabel}.`,
4558
+ schema: items }) }) }, `form-${prefix}${column}.${index}`))), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4559
+ };
4560
+
4561
+ const BooleanViewer = ({ schema, column, prefix, }) => {
4562
+ const { watch, formState: { errors }, } = useFormContext();
4563
+ const { translate } = useSchemaContext();
4564
+ const { required, gridColumn, gridRow } = schema;
4565
+ const isRequired = required?.some((columnId) => columnId === column);
4566
+ const colLabel = `${prefix}${column}`;
4567
+ const value = watch(colLabel);
4568
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
4569
+ gridRow, children: [jsx(Text, { children: value
4570
+ ? translate.t(removeIndex(`${colLabel}.true`))
4571
+ : translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4572
+ };
4573
+
4574
+ const DateViewer = ({ column, schema, 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 selectedDate = watch(colLabel);
4581
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
4582
+ gridRow, children: [jsxs(Text, { children: [" ", selectedDate !== undefined ? selectedDate : ""] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
4583
+ };
4584
+
4585
+ const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
4586
+ const { watch, formState: { errors }, } = useFormContext();
4587
+ const { translate } = useSchemaContext();
4588
+ const { required } = schema;
4589
+ const isRequired = required?.some((columnId) => columnId === column);
4590
+ const { gridColumn, gridRow, renderDisplay } = schema;
4591
+ const colLabel = `${prefix}${column}`;
4592
+ const watchEnum = watch(colLabel);
4593
+ const watchEnums = (watch(colLabel) ?? []);
4594
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
4595
+ gridRow, children: [isMultiple && (jsx(Flex, { flexFlow: "wrap", gap: 1, children: watchEnums.map((enumValue) => {
4596
+ const item = enumValue;
4597
+ if (item === undefined) {
4598
+ return jsx(Fragment, { children: "undefined" });
4599
+ }
4600
+ return (jsx(Tag, { closable: true, children: !!renderDisplay === true
4601
+ ? renderDisplay(item)
4602
+ : translate.t(removeIndex(`${colLabel}.${item}`)) }));
4603
+ }) })), !isMultiple && (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4604
+ };
4605
+
4606
+ const FileViewer = ({ column, schema, prefix }) => {
4607
+ const { setValue, formState: { errors }, watch, } = useFormContext();
4608
+ const { translate } = useSchemaContext();
4609
+ const { required, gridColumn, gridRow } = schema;
4610
+ const isRequired = required?.some((columnId) => columnId === column);
4611
+ const currentFiles = (watch(column) ?? []);
4612
+ const colLabel = `${prefix}${column}`;
4613
+ 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 }) => {
4614
+ const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
4615
+ setValue(colLabel, [...currentFiles, ...newFiles]);
4616
+ }, placeholder: translate.t(`${colLabel}.fileDropzone`) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
4617
+ return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
4618
+ setValue(column, currentFiles.filter(({ name }) => {
4619
+ return name !== file.name;
4620
+ }));
4621
+ }, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
4622
+ }) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4623
+ };
4624
+
4625
+ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
4626
+ const { watch, formState: { errors }, } = useFormContext();
4627
+ const { idMap, translate } = useSchemaContext();
4628
+ const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
4629
+ const isRequired = required?.some((columnId) => columnId === column);
4630
+ const { display_column } = foreign_key;
4631
+ const colLabel = `${prefix}${column}`;
4632
+ const watchId = watch(colLabel);
4633
+ const watchIds = (watch(colLabel) ?? []);
4634
+ const getPickedValue = () => {
4635
+ if (Object.keys(idMap).length <= 0) {
4636
+ return "";
4637
+ }
4638
+ const record = idMap[watchId];
4639
+ if (record === undefined) {
4640
+ return "";
4641
+ }
4642
+ return record[display_column];
4643
+ };
4644
+ return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
4645
+ gridRow, children: [isMultiple && (jsx(Flex, { flexFlow: "wrap", gap: 1, children: watchIds.map((id) => {
4646
+ const item = idMap[id];
4647
+ if (item === undefined) {
4648
+ return (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
4649
+ }
4650
+ return (jsx(Tag, { closable: true, children: !!renderDisplay === true
4651
+ ? renderDisplay(item)
4652
+ : item[display_column] }, id));
4653
+ }) })), !isMultiple && jsx(Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4654
+ };
4655
+
4656
+ const NumberViewer = ({ schema, column, prefix, }) => {
4657
+ const { watch, formState: { errors }, } = useFormContext();
4658
+ const { translate } = useSchemaContext();
4659
+ const { required, gridColumn, gridRow } = schema;
4660
+ const isRequired = required?.some((columnId) => columnId === column);
4661
+ const colLabel = `${prefix}${column}`;
4662
+ const value = watch(colLabel);
4663
+ 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`)) }))] }));
4664
+ };
4665
+
4666
+ const ObjectViewer = ({ schema, column, prefix }) => {
4667
+ const { properties, gridRow, gridColumn = "1/span 12", required } = schema;
4668
+ const { translate } = useSchemaContext();
4669
+ const colLabel = `${prefix}${column}`;
4670
+ const isRequired = required?.some((columnId) => columnId === column);
4671
+ const { formState: { errors }, } = useFormContext();
4672
+ if (properties === undefined) {
4673
+ throw new Error(`properties is undefined when using ObjectInput`);
4674
+ }
4675
+ 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) => {
4676
+ return (
4677
+ // @ts-expect-error find suitable types
4678
+ jsx(ColumnViewer, { column: `${key}`,
4679
+ prefix: `${prefix}${column}.`,
4680
+ properties }, `form-objectviewer-${colLabel}-${key}`));
4681
+ }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
4682
+ };
4683
+
4684
+ const RecordInput = ({ column, schema, prefix }) => {
4685
+ const { formState: { errors }, setValue, getValues, } = useFormContext();
4686
+ const { translate } = useSchemaContext();
4687
+ const { required, gridColumn, gridRow } = schema;
4688
+ const isRequired = required?.some((columnId) => columnId === column);
4689
+ const entries = Object.entries(getValues(column) ?? {});
4690
+ const [showNewEntries, setShowNewEntries] = useState(false);
4691
+ const [newKey, setNewKey] = useState();
4692
+ const [newValue, setNewValue] = useState();
4693
+ return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
4694
+ return (jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: key, onChange: (e) => {
4695
+ const filtered = entries.filter(([target]) => {
4696
+ return target !== key;
4697
+ });
4698
+ setValue(column, Object.fromEntries([...filtered, [e.target.value, value]]));
4699
+ }, autoComplete: "off" }), jsx(Input, { value: value, onChange: (e) => {
4700
+ setValue(column, {
4701
+ ...getValues(column),
4702
+ [key]: e.target.value,
4703
+ });
4704
+ }, autoComplete: "off" }), jsx(IconButton, { variant: "ghost", onClick: () => {
4705
+ const filtered = entries.filter(([target]) => {
4706
+ return target !== key;
4707
+ });
4708
+ setValue(column, Object.fromEntries([...filtered]));
4709
+ }, children: jsx(CgClose, {}) })] }));
4710
+ }), 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) => {
4711
+ setNewKey(e.target.value);
4712
+ }, autoComplete: "off" }), jsx(Input, { value: newValue, onChange: (e) => {
4713
+ setNewValue(e.target.value);
4714
+ }, autoComplete: "off" })] }) }), jsxs(Card.Footer, { justifyContent: "flex-end", children: [jsx(IconButton, { variant: "subtle", onClick: () => {
4715
+ setShowNewEntries(false);
4716
+ setNewKey(undefined);
4717
+ setNewValue(undefined);
4718
+ }, children: jsx(CgClose, {}) }), jsx(Button, { onClick: () => {
4719
+ if (!!newKey === false) {
4720
+ setShowNewEntries(false);
4721
+ setNewKey(undefined);
4722
+ setNewValue(undefined);
4723
+ return;
4724
+ }
4725
+ setValue(column, Object.fromEntries([...entries, [newKey, newValue]]));
4726
+ setShowNewEntries(false);
4727
+ setNewKey(undefined);
4728
+ setNewValue(undefined);
4729
+ }, children: translate.t(`${column}.save`) })] })] }) }), jsx(Button, { onClick: () => {
4730
+ setShowNewEntries(true);
4731
+ setNewKey(undefined);
4732
+ setNewValue(undefined);
4733
+ }, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
4734
+ };
4735
+
4736
+ const TagViewer = ({ column, schema, prefix }) => {
4737
+ const { watch, formState: { errors }, setValue, } = useFormContext();
4738
+ const { serverUrl } = useSchemaContext();
4739
+ if (schema.properties == undefined) {
4740
+ throw new Error("schema properties undefined when using DatePicker");
4741
+ }
4742
+ const { gridColumn, gridRow, in_table, object_id_column } = schema;
4743
+ if (in_table === undefined) {
4744
+ throw new Error("in_table is undefined when using TagPicker");
4745
+ }
4746
+ if (object_id_column === undefined) {
4747
+ throw new Error("object_id_column is undefined when using TagPicker");
4748
+ }
4749
+ const query = useQuery({
4750
+ queryKey: [`tagpicker`, in_table],
4751
+ queryFn: async () => {
4752
+ return await getTableData({
4753
+ serverUrl,
4754
+ in_table: "tables_tags_view",
4755
+ where: [
4756
+ {
4757
+ id: "table_name",
4758
+ value: [in_table],
4759
+ },
4760
+ ],
4761
+ limit: 100,
4762
+ });
4763
+ },
4764
+ staleTime: 10000,
4765
+ });
4766
+ const object_id = watch(object_id_column);
4767
+ const existingTagsQuery = useQuery({
4768
+ queryKey: [`existing`, { in_table, object_id_column }, object_id],
4769
+ queryFn: async () => {
4770
+ return await getTableData({
4771
+ serverUrl,
4772
+ in_table: in_table,
4773
+ where: [
4774
+ {
4775
+ id: object_id_column,
4776
+ value: object_id[0],
4777
+ },
4778
+ ],
4779
+ limit: 100,
4780
+ });
4781
+ },
4782
+ enabled: object_id != undefined,
4783
+ staleTime: 10000,
4784
+ });
4785
+ const { isLoading, isFetching, data, isPending, isError } = query;
4786
+ const dataList = data?.data ?? [];
4787
+ const existingTagList = existingTagsQuery.data?.data ?? [];
4788
+ if (!!object_id === false) {
4789
+ return jsx(Fragment, {});
4790
+ }
4791
+ return (jsxs(Flex, { flexFlow: "column", gap: 4, gridColumn,
4792
+ 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 }) => {
4793
+ 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) => {
4794
+ const existedTags = Object.values(all_tags)
4795
+ .filter(({ id }) => {
4796
+ return existingTagList.some(({ tag_id }) => tag_id === id);
4797
+ })
4798
+ .map(({ id }) => {
4799
+ return id;
4800
+ });
4801
+ setValue(`${column}.${parent_tag_name}.current`, [
4802
+ tagIds.value,
4803
+ ]);
4804
+ setValue(`${column}.${parent_tag_name}.old`, existedTags);
4805
+ }, children: jsx(Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
4806
+ if (existingTagList.some(({ tag_id }) => tag_id === id)) {
4807
+ return (jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", disabled: true }, `${tagName}-${id}`));
4808
+ }
4809
+ return (jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", colorPalette: "blue" }, `${tagName}-${id}`));
4810
+ }) }) })), !is_mutually_exclusive && (jsx(CheckboxGroup, { onValueChange: (tagIds) => {
4811
+ setValue(`${column}.${parent_tag_name}.current`, tagIds);
4812
+ }, children: jsx(Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
4813
+ if (existingTagList.some(({ tag_id }) => tag_id === id)) {
4814
+ return (jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%", disabled: true, colorPalette: "blue" }, `${tagName}-${id}`));
4815
+ }
4816
+ return (jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%" }, `${tagName}-${id}`));
4817
+ }) }) }))] }, `tag-${parent_tag_name}`));
4818
+ }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
4819
+ };
4820
+
4821
+ const StringViewer = ({ column, schema, prefix, }) => {
4822
+ const { watch, formState: { errors }, } = useFormContext();
4823
+ const { translate } = useSchemaContext();
4824
+ const { required, gridColumn, gridRow } = schema;
4825
+ const isRequired = required?.some((columnId) => columnId === column);
4826
+ const colLabel = `${prefix}${column}`;
4827
+ const value = watch(colLabel);
4828
+ 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`)) }))] }) }));
4829
+ };
4830
+
4831
+ const SchemaViewer = ({ schema, prefix, column, }) => {
4832
+ const colSchema = schema;
4833
+ const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
4834
+ if (type === "string") {
4835
+ if ((schema.enum ?? []).length > 0) {
4836
+ return jsx(EnumViewer, { schema: colSchema, prefix, column });
4837
+ }
4838
+ if (variant === "id-picker") {
4839
+ idPickerSanityCheck(column, foreign_key);
4840
+ return jsx(IdViewer, { schema: colSchema, prefix, column });
4841
+ }
4842
+ if (variant === "date-picker") {
4843
+ return jsx(DateViewer, { schema: colSchema, prefix, column });
4844
+ }
4845
+ return jsx(StringViewer, { schema: colSchema, prefix, column });
4846
+ }
4847
+ if (type === "number" || type === "integer") {
4848
+ return jsx(NumberViewer, { schema: colSchema, prefix, column });
4849
+ }
4850
+ if (type === "boolean") {
4851
+ return jsx(BooleanViewer, { schema: colSchema, prefix, column });
4852
+ }
4853
+ if (type === "object") {
4854
+ if (innerProperties) {
4855
+ return jsx(ObjectViewer, { schema: colSchema, prefix, column });
4856
+ }
4857
+ return jsx(RecordInput, { schema: colSchema, prefix, column });
4858
+ }
4859
+ if (type === "array") {
4860
+ if (variant === "id-picker") {
4861
+ idPickerSanityCheck(column, foreign_key);
4862
+ return (jsx(IdViewer, { schema: colSchema, prefix, column, isMultiple: true }));
4863
+ }
4864
+ if (variant === "tag-picker") {
4865
+ return jsx(TagViewer, { schema: colSchema, prefix, column });
4866
+ }
4867
+ if (variant === "file-picker") {
4868
+ return jsx(FileViewer, { schema: colSchema, prefix, column });
4869
+ }
4870
+ if (items) {
4871
+ return jsx(ArrayViewer, { schema: colSchema, prefix, column });
4872
+ }
4873
+ return jsx(Text, { children: `array ${column}` });
4874
+ }
4875
+ if (type === "null") {
4876
+ return jsx(Text, { children: `null ${column}` });
4877
+ }
4878
+ return jsx(Text, { children: "missing type" });
4879
+ };
4880
+
4881
+ const ColumnViewer = ({ column, properties, prefix, }) => {
4535
4882
  if (properties === undefined) {
4536
4883
  return jsx(Fragment, {});
4537
4884
  }
4538
- console.log(`${column} does not exist when using ColumnRenderer`, { properties, column, prefix }, "fdpok");
4539
4885
  const colSchema = properties[column];
4540
4886
  if (colSchema === undefined) {
4541
4887
  throw new Error(`${column} does not exist when using ColumnRenderer`);
4542
4888
  }
4543
- return jsx(SchemaRenderer, { schema: colSchema, prefix, column });
4889
+ return jsx(SchemaViewer, { schema: colSchema, prefix, column });
4544
4890
  };
4545
4891
 
4546
4892
  const idPickerSanityCheck = (column, foreign_key) => {
@@ -4559,7 +4905,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
4559
4905
  }
4560
4906
  };
4561
4907
  const FormInternal = () => {
4562
- const { schema, requestUrl, order, ignore, onSubmit, rowNumber, idMap, translate, requestOptions, } = useSchemaContext();
4908
+ const { schema, requestUrl, order, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
4563
4909
  const methods = useFormContext();
4564
4910
  const [isSuccess, setIsSuccess] = useState(false);
4565
4911
  const [isError, setIsError] = useState(false);
@@ -4634,7 +4980,13 @@ const FormInternal = () => {
4634
4980
  }, formNoValidate: true, children: translate.t("submitAgain") }) })] }));
4635
4981
  }
4636
4982
  if (isConfirming) {
4637
- 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: jsx(RecordDisplay, { object: validatedData ?? {}, boxProps: { gridColumn: "1/span12" } }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
4983
+ 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) => {
4984
+ return (jsx(ColumnViewer
4985
+ // @ts-expect-error find suitable types
4986
+ , {
4987
+ // @ts-expect-error find suitable types
4988
+ properties: properties, prefix: ``, column }, `form-viewer-${column}`));
4989
+ }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
4638
4990
  setIsConfirming(false);
4639
4991
  }, variant: "subtle", children: translate.t("cancel") }), jsx(Button, { onClick: () => {
4640
4992
  onFormSubmit(validatedData);
@@ -4645,7 +4997,7 @@ const FormInternal = () => {
4645
4997
  // @ts-expect-error find suitable types
4646
4998
  , {
4647
4999
  // @ts-expect-error find suitable types
4648
- properties: properties, prefix: ``, column }, `form-${column}`));
5000
+ properties: properties, prefix: ``, column }, `form-input-${column}`));
4649
5001
  }) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
4650
5002
  methods.reset();
4651
5003
  }, variant: "subtle", children: translate.t("reset") }), jsx(Button, { onClick: () => {