@vaadin/hilla-react-crud 24.4.0-alpha1

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 (172) hide show
  1. package/.lintstagedrc.js +6 -0
  2. package/LICENSE +201 -0
  3. package/README.md +27 -0
  4. package/autocrud-dialog.d.ts +11 -0
  5. package/autocrud-dialog.d.ts.map +1 -0
  6. package/autocrud-dialog.js +24 -0
  7. package/autocrud-dialog.js.map +7 -0
  8. package/autocrud-feature.d.ts +4 -0
  9. package/autocrud-feature.d.ts.map +1 -0
  10. package/autocrud-feature.js +8 -0
  11. package/autocrud-feature.js.map +7 -0
  12. package/autocrud.d.ts +82 -0
  13. package/autocrud.d.ts.map +1 -0
  14. package/autocrud.js +94 -0
  15. package/autocrud.js.map +7 -0
  16. package/autocrud.obj.js +6 -0
  17. package/autocrud.obj.js.map +7 -0
  18. package/autoform-feature.d.ts +4 -0
  19. package/autoform-feature.d.ts.map +1 -0
  20. package/autoform-feature.js +8 -0
  21. package/autoform-feature.js.map +7 -0
  22. package/autoform-field.d.ts +122 -0
  23. package/autoform-field.d.ts.map +1 -0
  24. package/autoform-field.js +118 -0
  25. package/autoform-field.js.map +7 -0
  26. package/autoform.d.ts +228 -0
  27. package/autoform.d.ts.map +1 -0
  28. package/autoform.js +178 -0
  29. package/autoform.js.map +7 -0
  30. package/autoform.obj.js +6 -0
  31. package/autoform.obj.js.map +7 -0
  32. package/autogrid-column-context.d.ts +39 -0
  33. package/autogrid-column-context.d.ts.map +1 -0
  34. package/autogrid-column-context.js +8 -0
  35. package/autogrid-column-context.js.map +7 -0
  36. package/autogrid-columns.d.ts +6 -0
  37. package/autogrid-columns.d.ts.map +1 -0
  38. package/autogrid-columns.js +102 -0
  39. package/autogrid-columns.js.map +7 -0
  40. package/autogrid-feature.d.ts +4 -0
  41. package/autogrid-feature.d.ts.map +1 -0
  42. package/autogrid-feature.js +8 -0
  43. package/autogrid-feature.js.map +7 -0
  44. package/autogrid-renderers.d.ts +28 -0
  45. package/autogrid-renderers.d.ts.map +1 -0
  46. package/autogrid-renderers.js +92 -0
  47. package/autogrid-renderers.js.map +7 -0
  48. package/autogrid.d.ts +130 -0
  49. package/autogrid.d.ts.map +1 -0
  50. package/autogrid.js +234 -0
  51. package/autogrid.js.map +7 -0
  52. package/autogrid.obj.js +6 -0
  53. package/autogrid.obj.js.map +7 -0
  54. package/crud.d.js +1 -0
  55. package/crud.d.js.map +7 -0
  56. package/crud.d.ts +17 -0
  57. package/data-provider.d.ts +56 -0
  58. package/data-provider.d.ts.map +1 -0
  59. package/data-provider.js +121 -0
  60. package/data-provider.js.map +7 -0
  61. package/header-filter.d.ts +54 -0
  62. package/header-filter.d.ts.map +1 -0
  63. package/header-filter.js +258 -0
  64. package/header-filter.js.map +7 -0
  65. package/header-sorter.d.ts +3 -0
  66. package/header-sorter.d.ts.map +1 -0
  67. package/header-sorter.js +28 -0
  68. package/header-sorter.js.map +7 -0
  69. package/i18n.d.ts +2 -0
  70. package/i18n.d.ts.map +1 -0
  71. package/i18n.js +5 -0
  72. package/i18n.js.map +7 -0
  73. package/index.d.ts +5 -0
  74. package/index.d.ts.map +1 -0
  75. package/index.js +13 -0
  76. package/index.js.map +7 -0
  77. package/locale.d.ts +19 -0
  78. package/locale.d.ts.map +1 -0
  79. package/locale.js +123 -0
  80. package/locale.js.map +7 -0
  81. package/media-query.d.ts +2 -0
  82. package/media-query.d.ts.map +1 -0
  83. package/media-query.js +16 -0
  84. package/media-query.js.map +7 -0
  85. package/model-info.d.ts +23 -0
  86. package/model-info.d.ts.map +1 -0
  87. package/model-info.js +137 -0
  88. package/model-info.js.map +7 -0
  89. package/package.json +87 -0
  90. package/types/com/vaadin/hilla/crud/filter/AndFilter.d.js +1 -0
  91. package/types/com/vaadin/hilla/crud/filter/AndFilter.d.js.map +7 -0
  92. package/types/com/vaadin/hilla/crud/filter/AndFilter.d.ts +6 -0
  93. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.d.ts +9 -0
  94. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.d.ts.map +1 -0
  95. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.js +13 -0
  96. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.js.map +7 -0
  97. package/types/com/vaadin/hilla/crud/filter/Filter.d.js +1 -0
  98. package/types/com/vaadin/hilla/crud/filter/Filter.d.js.map +7 -0
  99. package/types/com/vaadin/hilla/crud/filter/Filter.d.ts +3 -0
  100. package/types/com/vaadin/hilla/crud/filter/FilterModel.d.ts +7 -0
  101. package/types/com/vaadin/hilla/crud/filter/FilterModel.d.ts.map +1 -0
  102. package/types/com/vaadin/hilla/crud/filter/FilterModel.js +9 -0
  103. package/types/com/vaadin/hilla/crud/filter/FilterModel.js.map +7 -0
  104. package/types/com/vaadin/hilla/crud/filter/FilterUnion.d.js +1 -0
  105. package/types/com/vaadin/hilla/crud/filter/FilterUnion.d.js.map +7 -0
  106. package/types/com/vaadin/hilla/crud/filter/FilterUnion.d.ts +5 -0
  107. package/types/com/vaadin/hilla/crud/filter/OrFilter.d.js +1 -0
  108. package/types/com/vaadin/hilla/crud/filter/OrFilter.d.js.map +7 -0
  109. package/types/com/vaadin/hilla/crud/filter/OrFilter.d.ts +6 -0
  110. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.d.ts +9 -0
  111. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.d.ts.map +1 -0
  112. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.js +13 -0
  113. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.js.map +7 -0
  114. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.d.ts +8 -0
  115. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.d.ts.map +1 -0
  116. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js +12 -0
  117. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js.map +7 -0
  118. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.d.ts +8 -0
  119. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.d.ts.map +1 -0
  120. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.js +11 -0
  121. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.js.map +7 -0
  122. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter.d.js +1 -0
  123. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter.d.js.map +7 -0
  124. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter.d.ts +9 -0
  125. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.d.ts +12 -0
  126. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.d.ts.map +1 -0
  127. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.js +20 -0
  128. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.js.map +7 -0
  129. package/types/com/vaadin/hilla/mappedtypes/Order.d.js +1 -0
  130. package/types/com/vaadin/hilla/mappedtypes/Order.d.js.map +7 -0
  131. package/types/com/vaadin/hilla/mappedtypes/Order.d.ts +9 -0
  132. package/types/com/vaadin/hilla/mappedtypes/OrderModel.d.ts +13 -0
  133. package/types/com/vaadin/hilla/mappedtypes/OrderModel.d.ts.map +1 -0
  134. package/types/com/vaadin/hilla/mappedtypes/OrderModel.js +23 -0
  135. package/types/com/vaadin/hilla/mappedtypes/OrderModel.js.map +7 -0
  136. package/types/com/vaadin/hilla/mappedtypes/Pageable.d.js +1 -0
  137. package/types/com/vaadin/hilla/mappedtypes/Pageable.d.js.map +7 -0
  138. package/types/com/vaadin/hilla/mappedtypes/Pageable.d.ts +7 -0
  139. package/types/com/vaadin/hilla/mappedtypes/PageableModel.d.ts +11 -0
  140. package/types/com/vaadin/hilla/mappedtypes/PageableModel.d.ts.map +1 -0
  141. package/types/com/vaadin/hilla/mappedtypes/PageableModel.js +19 -0
  142. package/types/com/vaadin/hilla/mappedtypes/PageableModel.js.map +7 -0
  143. package/types/com/vaadin/hilla/mappedtypes/Sort.d.js +1 -0
  144. package/types/com/vaadin/hilla/mappedtypes/Sort.d.js.map +7 -0
  145. package/types/com/vaadin/hilla/mappedtypes/Sort.d.ts +5 -0
  146. package/types/com/vaadin/hilla/mappedtypes/SortModel.d.ts +9 -0
  147. package/types/com/vaadin/hilla/mappedtypes/SortModel.d.ts.map +1 -0
  148. package/types/com/vaadin/hilla/mappedtypes/SortModel.js +13 -0
  149. package/types/com/vaadin/hilla/mappedtypes/SortModel.js.map +7 -0
  150. package/types/org/springframework/data/domain/Sort/Direction.d.ts +6 -0
  151. package/types/org/springframework/data/domain/Sort/Direction.d.ts.map +1 -0
  152. package/types/org/springframework/data/domain/Sort/Direction.js +10 -0
  153. package/types/org/springframework/data/domain/Sort/Direction.js.map +7 -0
  154. package/types/org/springframework/data/domain/Sort/DirectionModel.d.ts +8 -0
  155. package/types/org/springframework/data/domain/Sort/DirectionModel.d.ts.map +1 -0
  156. package/types/org/springframework/data/domain/Sort/DirectionModel.js +11 -0
  157. package/types/org/springframework/data/domain/Sort/DirectionModel.js.map +7 -0
  158. package/types/org/springframework/data/domain/Sort/NullHandling.d.ts +7 -0
  159. package/types/org/springframework/data/domain/Sort/NullHandling.d.ts.map +1 -0
  160. package/types/org/springframework/data/domain/Sort/NullHandling.js +11 -0
  161. package/types/org/springframework/data/domain/Sort/NullHandling.js.map +7 -0
  162. package/types/org/springframework/data/domain/Sort/NullHandlingModel.d.ts +8 -0
  163. package/types/org/springframework/data/domain/Sort/NullHandlingModel.d.ts.map +1 -0
  164. package/types/org/springframework/data/domain/Sort/NullHandlingModel.js +11 -0
  165. package/types/org/springframework/data/domain/Sort/NullHandlingModel.js.map +7 -0
  166. package/types.d.js +1 -0
  167. package/types.d.js.map +7 -0
  168. package/types.d.ts +12 -0
  169. package/util.d.ts +12 -0
  170. package/util.d.ts.map +1 -0
  171. package/util.js +55 -0
  172. package/util.js.map +7 -0
@@ -0,0 +1,122 @@
1
+ import { type Validator } from '@vaadin/hilla-lit-form';
2
+ import type { FieldDirectiveResult, UseFormResult } from '@vaadin/hilla-react-form';
3
+ import { type CSSProperties, type JSX } from 'react';
4
+ import type { PropertyInfo } from './model-info.js';
5
+ export type AutoFormFieldProps = Readonly<{
6
+ propertyInfo: PropertyInfo;
7
+ form: UseFormResult<any>;
8
+ options: FieldOptions;
9
+ disabled?: boolean;
10
+ }>;
11
+ type CustomFormFieldProps = FieldDirectiveResult & Readonly<{
12
+ label?: string;
13
+ disabled?: boolean;
14
+ }>;
15
+ export type FieldOptions = Readonly<{
16
+ /**
17
+ * The id to apply to the field.
18
+ */
19
+ id?: string;
20
+ /**
21
+ * The class names to add to the field.
22
+ */
23
+ className?: string;
24
+ /**
25
+ * The style to apply to the field.
26
+ */
27
+ style?: CSSProperties;
28
+ /**
29
+ * The label to show for the field. If not specified, a human-readable label
30
+ * is generated from the property name.
31
+ */
32
+ label?: string;
33
+ /**
34
+ * The placeholder to when the field is empty.
35
+ *
36
+ * Note that some field types, such as checkbox, do not support a placeholder.
37
+ */
38
+ placeholder?: string;
39
+ /**
40
+ * The helper text to display below the field.
41
+ *
42
+ * Note that some field types, such as checkbox, do not support a helper text.
43
+ */
44
+ helperText?: string;
45
+ /**
46
+ * The number of columns to span. This value is passed to the underlying
47
+ * FormLayout, unless a custom layout is used. In that case, the value is
48
+ * ignored.
49
+ */
50
+ colspan?: number;
51
+ /**
52
+ * Whether the field should be disabled.
53
+ */
54
+ disabled?: boolean;
55
+ /**
56
+ * Whether the field should be readonly.
57
+ */
58
+ readonly?: boolean;
59
+ /**
60
+ * The element to render for the field. This allows customizing field props
61
+ * that are not supported by the field options, or to render a different field
62
+ * component. Other field options are automatically applied to the element,
63
+ * and the element is automatically bound to the form. If not specified, a
64
+ * default field element is rendered based on the property type.
65
+ *
66
+ * The element must be a field component, such as TextField, TextArea,
67
+ * NumberField, etc., otherwise form binding will not work. For more
68
+ * sophisticated customizations, use the `renderer` option.
69
+ *
70
+ * If the field options also specify a renderer function, then the element is
71
+ * ignored.
72
+ *
73
+ * Example enabling the clear button for a text field:
74
+ * ```tsx
75
+ * {
76
+ * element: <TextField clearButtonVisible />
77
+ * }
78
+ * ```
79
+ *
80
+ * Example rendering a text area instead of a text field:
81
+ * ```tsx
82
+ * {
83
+ * element: <TextArea />
84
+ * }
85
+ * ```
86
+ */
87
+ element?: JSX.Element;
88
+ /**
89
+ * Allows to specify a custom renderer for the field, for example to render a
90
+ * custom type of field or apply an additional layout around the field. The
91
+ * renderer receives field props that must be applied to the custom field
92
+ * component in order to connect it to the form.
93
+ *
94
+ * In order to customize one of the default fields, or render a different type
95
+ * of field, consider using the `element` option instead.
96
+ *
97
+ * Example:
98
+ * ```tsx
99
+ * {
100
+ * renderer: ({ field }) => (
101
+ * <div>
102
+ * <TextArea {...field} />
103
+ * <p>Number of words: {calculateNumberOfWords()}</p>
104
+ * </div>
105
+ * )
106
+ * }
107
+ * ```
108
+ */
109
+ renderer?(props: {
110
+ field: CustomFormFieldProps;
111
+ }): JSX.Element;
112
+ /**
113
+ * Validators to apply to the field. The validators are added to the form
114
+ * when the field is rendered.
115
+ * UseMemo is recommended for the validators, so that they are not recreated
116
+ * on every render.
117
+ */
118
+ validators?: Validator[];
119
+ }>;
120
+ export declare function AutoFormField(props: AutoFormFieldProps): JSX.Element | null;
121
+ export {};
122
+ //# sourceMappingURL=autoform-field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoform-field.d.ts","sourceRoot":"","sources":["src/autoform-field.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6C,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAWpF,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,GAAG,EAGT,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,YAAY,EAAE,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AG,CAAC,OAAO,GAAG,IAAI,CAsD3E"}
@@ -0,0 +1,118 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { _enum } from "@vaadin/hilla-lit-form";
3
+ import { useFormPart } from "@vaadin/hilla-react-form";
4
+ import { Checkbox } from "@vaadin/react-components/Checkbox.js";
5
+ import { DatePicker } from "@vaadin/react-components/DatePicker.js";
6
+ import { DateTimePicker } from "@vaadin/react-components/DateTimePicker.js";
7
+ import { IntegerField } from "@vaadin/react-components/IntegerField.js";
8
+ import { NumberField } from "@vaadin/react-components/NumberField.js";
9
+ import { Select } from "@vaadin/react-components/Select.js";
10
+ import { TextArea } from "@vaadin/react-components/TextArea.js";
11
+ import { TextField } from "@vaadin/react-components/TextField.js";
12
+ import { TimePicker } from "@vaadin/react-components/TimePicker.js";
13
+ import {
14
+ cloneElement,
15
+ createElement,
16
+ useEffect,
17
+ useMemo
18
+ } from "react";
19
+ import { useDatePickerI18n, useDateTimePickerI18n } from "./locale.js";
20
+ import { convertToTitleCase } from "./util.js";
21
+ function getPropertyModel(form, propertyInfo) {
22
+ const pathParts = propertyInfo.name.split(".");
23
+ return pathParts.reduce((model, property) => model ? model[property] : void 0, form.model);
24
+ }
25
+ function renderFieldElement(defaultComponentType, { element, field, fieldProps }, additionalProps = {}) {
26
+ const fieldElement = element ?? createElement(defaultComponentType);
27
+ return cloneElement(fieldElement, { ...fieldProps, ...additionalProps, ...fieldElement.props, ...field });
28
+ }
29
+ function AutoFormTextField(props) {
30
+ return renderFieldElement(TextField, props);
31
+ }
32
+ function AutoFormIntegerField(props) {
33
+ return renderFieldElement(IntegerField, props);
34
+ }
35
+ function AutoFormDecimalField(props) {
36
+ return renderFieldElement(NumberField, props);
37
+ }
38
+ function AutoFormDateField(props) {
39
+ const i18n = useDatePickerI18n();
40
+ return renderFieldElement(DatePicker, props, { i18n });
41
+ }
42
+ function AutoFormTimeField(props) {
43
+ return renderFieldElement(TimePicker, props);
44
+ }
45
+ function AutoFormDateTimeField(props) {
46
+ const i18n = useDateTimePickerI18n();
47
+ return renderFieldElement(DateTimePicker, props, { i18n });
48
+ }
49
+ function AutoFormEnumField(props) {
50
+ const enumModel = props.model;
51
+ const items = Object.keys(enumModel[_enum]).map((value) => ({
52
+ label: convertToTitleCase(value),
53
+ value
54
+ }));
55
+ return renderFieldElement(Select, props, { items });
56
+ }
57
+ function AutoFormBooleanField(props) {
58
+ return renderFieldElement(Checkbox, props);
59
+ }
60
+ function AutoFormObjectField({ model, fieldProps }) {
61
+ const part = useFormPart(model);
62
+ const jsonString = part.value ? JSON.stringify(part.value) : "";
63
+ return /* @__PURE__ */ jsx(TextArea, { ...fieldProps, value: jsonString, readonly: true });
64
+ }
65
+ function AutoFormField(props) {
66
+ const { form, propertyInfo, options } = props;
67
+ const label = options.label ?? propertyInfo.humanReadableName;
68
+ const model = getPropertyModel(form, propertyInfo);
69
+ const field = form.field(model);
70
+ const formPart = useFormPart(model);
71
+ const defaultValidators = useMemo(() => formPart.validators, []);
72
+ const { validators } = options;
73
+ useEffect(() => {
74
+ formPart.setValidators([...defaultValidators, ...validators ?? []]);
75
+ }, [validators]);
76
+ if (options.renderer) {
77
+ const customFieldProps = { ...field, disabled: props.disabled, label };
78
+ return options.renderer({ field: customFieldProps });
79
+ }
80
+ const fieldProps = {
81
+ id: options.id,
82
+ className: options.className,
83
+ style: options.style,
84
+ label,
85
+ placeholder: options.placeholder,
86
+ helperText: options.helperText,
87
+ colspan: options.colspan,
88
+ disabled: options.disabled ?? props.disabled,
89
+ readonly: options.readonly
90
+ };
91
+ const rendererProps = { model, field, element: options.element, fieldProps };
92
+ switch (props.propertyInfo.type) {
93
+ case "string":
94
+ return /* @__PURE__ */ jsx(AutoFormTextField, { ...rendererProps });
95
+ case "integer":
96
+ return /* @__PURE__ */ jsx(AutoFormIntegerField, { ...rendererProps });
97
+ case "decimal":
98
+ return /* @__PURE__ */ jsx(AutoFormDecimalField, { ...rendererProps });
99
+ case "date":
100
+ return /* @__PURE__ */ jsx(AutoFormDateField, { ...rendererProps });
101
+ case "time":
102
+ return /* @__PURE__ */ jsx(AutoFormTimeField, { ...rendererProps });
103
+ case "datetime":
104
+ return /* @__PURE__ */ jsx(AutoFormDateTimeField, { ...rendererProps });
105
+ case "enum":
106
+ return /* @__PURE__ */ jsx(AutoFormEnumField, { ...rendererProps });
107
+ case "boolean":
108
+ return /* @__PURE__ */ jsx(AutoFormBooleanField, { ...rendererProps });
109
+ case "object":
110
+ return /* @__PURE__ */ jsx(AutoFormObjectField, { ...rendererProps });
111
+ default:
112
+ return null;
113
+ }
114
+ }
115
+ export {
116
+ AutoFormField
117
+ };
118
+ //# sourceMappingURL=autoform-field.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/autoform-field.tsx"],
4
+ "sourcesContent": ["import { _enum, type AbstractModel, type EnumModel, type Validator } from '@vaadin/hilla-lit-form';\nimport type { FieldDirectiveResult, UseFormResult } from '@vaadin/hilla-react-form';\nimport { useFormPart } from '@vaadin/hilla-react-form';\nimport { Checkbox } from '@vaadin/react-components/Checkbox.js';\nimport { DatePicker } from '@vaadin/react-components/DatePicker.js';\nimport { DateTimePicker } from '@vaadin/react-components/DateTimePicker.js';\nimport { IntegerField } from '@vaadin/react-components/IntegerField.js';\nimport { NumberField } from '@vaadin/react-components/NumberField.js';\nimport { Select } from '@vaadin/react-components/Select.js';\nimport { TextArea } from '@vaadin/react-components/TextArea.js';\nimport { TextField } from '@vaadin/react-components/TextField.js';\nimport { TimePicker } from '@vaadin/react-components/TimePicker.js';\nimport {\n cloneElement,\n type ComponentType,\n createElement,\n type CSSProperties,\n type JSX,\n useEffect,\n useMemo,\n} from 'react';\nimport { useDatePickerI18n, useDateTimePickerI18n } from './locale.js';\nimport type { PropertyInfo } from './model-info.js';\nimport { convertToTitleCase } from './util.js';\n\nexport type AutoFormFieldProps = Readonly<{\n propertyInfo: PropertyInfo;\n form: UseFormResult<any>;\n options: FieldOptions;\n disabled?: boolean;\n}>;\n\ntype CustomFormFieldProps = FieldDirectiveResult & Readonly<{ label?: string; disabled?: boolean }>;\n\nexport type FieldOptions = Readonly<{\n /**\n * The id to apply to the field.\n */\n id?: string;\n /**\n * The class names to add to the field.\n */\n className?: string;\n /**\n * The style to apply to the field.\n */\n style?: CSSProperties;\n /**\n * The label to show for the field. If not specified, a human-readable label\n * is generated from the property name.\n */\n label?: string;\n /**\n * The placeholder to when the field is empty.\n *\n * Note that some field types, such as checkbox, do not support a placeholder.\n */\n placeholder?: string;\n /**\n * The helper text to display below the field.\n *\n * Note that some field types, such as checkbox, do not support a helper text.\n */\n helperText?: string;\n /**\n * The number of columns to span. This value is passed to the underlying\n * FormLayout, unless a custom layout is used. In that case, the value is\n * ignored.\n */\n colspan?: number;\n /**\n * Whether the field should be disabled.\n */\n disabled?: boolean;\n /**\n * Whether the field should be readonly.\n */\n readonly?: boolean;\n /**\n * The element to render for the field. This allows customizing field props\n * that are not supported by the field options, or to render a different field\n * component. Other field options are automatically applied to the element,\n * and the element is automatically bound to the form. If not specified, a\n * default field element is rendered based on the property type.\n *\n * The element must be a field component, such as TextField, TextArea,\n * NumberField, etc., otherwise form binding will not work. For more\n * sophisticated customizations, use the `renderer` option.\n *\n * If the field options also specify a renderer function, then the element is\n * ignored.\n *\n * Example enabling the clear button for a text field:\n * ```tsx\n * {\n * element: <TextField clearButtonVisible />\n * }\n * ```\n *\n * Example rendering a text area instead of a text field:\n * ```tsx\n * {\n * element: <TextArea />\n * }\n * ```\n */\n element?: JSX.Element;\n /**\n * Allows to specify a custom renderer for the field, for example to render a\n * custom type of field or apply an additional layout around the field. The\n * renderer receives field props that must be applied to the custom field\n * component in order to connect it to the form.\n *\n * In order to customize one of the default fields, or render a different type\n * of field, consider using the `element` option instead.\n *\n * Example:\n * ```tsx\n * {\n * renderer: ({ field }) => (\n * <div>\n * <TextArea {...field} />\n * <p>Number of words: {calculateNumberOfWords()}</p>\n * </div>\n * )\n * }\n * ```\n */\n renderer?(props: { field: CustomFormFieldProps }): JSX.Element;\n /**\n * Validators to apply to the field. The validators are added to the form\n * when the field is rendered.\n * UseMemo is recommended for the validators, so that they are not recreated\n * on every render.\n */\n validators?: Validator[];\n}>;\n\ntype CommonFieldProps = Pick<\n FieldOptions,\n 'className' | 'colspan' | 'disabled' | 'helperText' | 'id' | 'label' | 'placeholder' | 'readonly' | 'style'\n>;\n\ntype FieldRendererProps = Readonly<{\n model: AbstractModel;\n field: FieldDirectiveResult;\n element?: JSX.Element;\n fieldProps: CommonFieldProps;\n}>;\n\nfunction getPropertyModel(form: UseFormResult<any>, propertyInfo: PropertyInfo) {\n const pathParts = propertyInfo.name.split('.');\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return pathParts.reduce<any>((model, property) => (model ? model[property] : undefined), form.model);\n}\n\nfunction renderFieldElement(\n defaultComponentType: ComponentType,\n { element, field, fieldProps }: FieldRendererProps,\n additionalProps: any = {},\n) {\n const fieldElement = element ?? createElement(defaultComponentType);\n return cloneElement(fieldElement, { ...fieldProps, ...additionalProps, ...fieldElement.props, ...field });\n}\n\nfunction AutoFormTextField(props: FieldRendererProps) {\n return renderFieldElement(TextField, props);\n}\n\nfunction AutoFormIntegerField(props: FieldRendererProps) {\n return renderFieldElement(IntegerField, props);\n}\n\nfunction AutoFormDecimalField(props: FieldRendererProps) {\n return renderFieldElement(NumberField, props);\n}\n\nfunction AutoFormDateField(props: FieldRendererProps) {\n const i18n = useDatePickerI18n();\n return renderFieldElement(DatePicker, props, { i18n });\n}\n\nfunction AutoFormTimeField(props: FieldRendererProps) {\n return renderFieldElement(TimePicker, props);\n}\n\nfunction AutoFormDateTimeField(props: FieldRendererProps) {\n const i18n = useDateTimePickerI18n();\n return renderFieldElement(DateTimePicker, props, { i18n });\n}\n\nfunction AutoFormEnumField(props: FieldRendererProps) {\n const enumModel = props.model as EnumModel;\n const items = Object.keys(enumModel[_enum]).map((value) => ({\n label: convertToTitleCase(value),\n value,\n }));\n return renderFieldElement(Select, props, { items });\n}\n\nfunction AutoFormBooleanField(props: FieldRendererProps) {\n return renderFieldElement(Checkbox, props);\n}\n\nfunction AutoFormObjectField({ model, fieldProps }: FieldRendererProps) {\n const part = useFormPart(model);\n const jsonString = part.value ? JSON.stringify(part.value) : '';\n return <TextArea {...fieldProps} value={jsonString} readonly />;\n}\n\nexport function AutoFormField(props: AutoFormFieldProps): JSX.Element | null {\n const { form, propertyInfo, options } = props;\n const label = options.label ?? propertyInfo.humanReadableName;\n const model = getPropertyModel(form, propertyInfo);\n const field = form.field(model);\n\n const formPart = useFormPart(model);\n const defaultValidators = useMemo(() => formPart.validators, []);\n const { validators } = options;\n useEffect(() => {\n formPart.setValidators([...defaultValidators, ...(validators ?? [])]);\n }, [validators]);\n\n if (options.renderer) {\n const customFieldProps = { ...field, disabled: props.disabled, label };\n return options.renderer({ field: customFieldProps });\n }\n\n const fieldProps: CommonFieldProps = {\n id: options.id,\n className: options.className,\n style: options.style,\n label,\n placeholder: options.placeholder,\n helperText: options.helperText,\n colspan: options.colspan,\n disabled: options.disabled ?? props.disabled,\n readonly: options.readonly,\n };\n\n const rendererProps: FieldRendererProps = { model, field, element: options.element, fieldProps };\n\n switch (props.propertyInfo.type) {\n case 'string':\n return <AutoFormTextField {...rendererProps}></AutoFormTextField>;\n case 'integer':\n return <AutoFormIntegerField {...rendererProps}></AutoFormIntegerField>;\n case 'decimal':\n return <AutoFormDecimalField {...rendererProps}></AutoFormDecimalField>;\n case 'date':\n return <AutoFormDateField {...rendererProps}></AutoFormDateField>;\n case 'time':\n return <AutoFormTimeField {...rendererProps}></AutoFormTimeField>;\n case 'datetime':\n return <AutoFormDateTimeField {...rendererProps}></AutoFormDateTimeField>;\n case 'enum':\n return <AutoFormEnumField {...rendererProps}></AutoFormEnumField>;\n case 'boolean':\n return <AutoFormBooleanField {...rendererProps}></AutoFormBooleanField>;\n case 'object':\n return <AutoFormObjectField {...rendererProps}></AutoFormObjectField>;\n default:\n return null;\n }\n}\n"],
5
+ "mappings": "AA+MS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A,IACrB,YAAY,QAAQ;AAAA,IACpB,SAAS,QAAQ;AAAA,IACjB,UAAU,QAAQ,YAAY,MAAM;AAAA,IACpC,UAAU,QAAQ;AAAA,EACpB;AAEA,QAAM,gBAAoC,EAAE,OAAO,OAAO,SAAS,QAAQ,SAAS,WAAW;AAE/F,UAAQ,MAAM,aAAa,MAAM;AAAA,IAC/B,KAAK;AACH,aAAO,oBAAC,qBAAmB,GAAG,eAAe;AAAA,IAC/C,KAAK;AACH,aAAO,oBAAC,wBAAsB,GAAG,eAAe;AAAA,IAClD,KAAK;AACH,aAAO,oBAAC,wBAAsB,GAAG,eAAe;AAAA,IAClD,KAAK;AACH,aAAO,oBAAC,qBAAmB,GAAG,eAAe;AAAA,IAC/C,KAAK;AACH,aAAO,oBAAC,qBAAmB,GAAG,eAAe;AAAA,IAC/C,KAAK;AACH,aAAO,oBAAC,yBAAuB,GAAG,eAAe;AAAA,IACnD,KAAK;AACH,aAAO,oBAAC,qBAAmB,GAAG,eAAe;AAAA,IAC/C,KAAK;AACH,aAAO,oBAAC,wBAAsB,GAAG,eAAe;AAAA,IAClD,KAAK;AACH,aAAO,oBAAC,uBAAqB,GAAG,eAAe;AAAA,IACjD;AACE,aAAO;AAAA,EACX;AACF;",
6
+ "names": []
7
+ }
package/autoform.d.ts ADDED
@@ -0,0 +1,228 @@
1
+ import { EndpointError } from '@vaadin/hilla-core';
2
+ import { type AbstractModel, type DetachedModelConstructor, type Value } from '@vaadin/hilla-lit-form';
3
+ import { type UseFormResult } from '@vaadin/hilla-react-form';
4
+ import { FormLayout } from '@vaadin/react-components/FormLayout';
5
+ import { type ComponentType, type JSX, type ReactElement } from 'react';
6
+ import { type AutoFormFieldProps, type FieldOptions } from './autoform-field.js';
7
+ import type { FormService } from './crud.js';
8
+ import { type ComponentStyleProps } from './util.js';
9
+ export declare const emptyItem: unique symbol;
10
+ /**
11
+ * An event that is fired when an error occurs while submitting the form.
12
+ */
13
+ export type SubmitErrorEvent = {
14
+ /**
15
+ * The error that occurred.
16
+ */
17
+ error: EndpointError;
18
+ /**
19
+ * A function that can be used to set a custom error message. This will be
20
+ * shown in the form at the same position as the default error message.
21
+ * You are not required to call this function if you want to handle the
22
+ * error differently.
23
+ */
24
+ setMessage(message: string): void;
25
+ };
26
+ /**
27
+ * An event that is fired when the form has been successfully submitted.
28
+ */
29
+ export type SubmitEvent<TItem> = {
30
+ /**
31
+ * The item that was submitted, as returned by the service.
32
+ */
33
+ item: TItem;
34
+ };
35
+ /**
36
+ * An event that is fired when an error occurs while deleting an item.
37
+ */
38
+ export type DeleteErrorEvent = {
39
+ /**
40
+ * The error that occurred.
41
+ */
42
+ error: EndpointError;
43
+ /**
44
+ * A function that can be used to set a custom error message. This will be
45
+ * shown in the form at the same position as the default error message.
46
+ * You are not required to call this function if you want to handle the
47
+ * error differently.
48
+ */
49
+ setMessage(message: string): void;
50
+ };
51
+ /**
52
+ * An event that is fired when the form has been successfully deleted.
53
+ */
54
+ export type DeleteEvent<TItem> = {
55
+ /**
56
+ * The item that was deleted, as returned by the service.
57
+ */
58
+ item: TItem;
59
+ };
60
+ export type AutoFormLayoutRendererProps<M extends AbstractModel> = Readonly<{
61
+ form: UseFormResult<M>;
62
+ children: ReadonlyArray<ReactElement<AutoFormFieldProps>>;
63
+ }>;
64
+ export type AutoFormProps<M extends AbstractModel = AbstractModel> = ComponentStyleProps & Readonly<{
65
+ /**
66
+ * The service to use for saving and deleting items. This must be a
67
+ * TypeScript service that has been generated by Hilla from a backend Java
68
+ * service that implements the `com.vaadin.hilla.crud.FormService` interface.
69
+ */
70
+ service: FormService<Value<M>>;
71
+ /**
72
+ * The entity model to use, which determines which fields to show in the
73
+ * form. This must be a Typescript model class that has been generated by
74
+ * Hilla from a backend Java class. The model must match with the type of
75
+ * the items handled by the service. For example, a `PersonModel` can be
76
+ * used with a service that handles `Person` instances.
77
+ *
78
+ * By default, the form shows fields for all properties of the model which
79
+ * have a type that is supported. Use the `visibleFields` option to customize
80
+ * which fields to show and in which order.
81
+ */
82
+ model: DetachedModelConstructor<M>;
83
+ /**
84
+ * The property to use to detect an item's ID. The item ID is required for
85
+ * deleting items via the `FormService.delete` method. The delete button
86
+ * will not be shown if no item ID can be found.
87
+ *
88
+ * By default, the component uses the property annotated with
89
+ * `jakarta.persistence.Id`, or a property named `id`, in that order.
90
+ * This option can be used to override the default behavior, or define the ID
91
+ * property in case a class doesn't have a property matching the defaults.
92
+ */
93
+ itemIdProperty?: string;
94
+ /**
95
+ * The item to edit in the form. The form fields are automatically populated
96
+ * with values from the item's properties. In order to create a new item,
97
+ * either pass `null`, or leave this prop as undefined.
98
+ *
99
+ * Use the `onSubmitSuccess` callback to get notified when the item has been
100
+ * saved.
101
+ *
102
+ * When submitting a new item (i.e. when `item` is null or undefined), the
103
+ * form will be automatically cleared, allowing to submit another new item.
104
+ * In order to keep editing the same item after submitting, set the `item`
105
+ * prop to the new item.
106
+ */
107
+ item?: Value<M> | typeof emptyItem | null;
108
+ /**
109
+ * Whether the form should be disabled. This disables all form fields and
110
+ * all buttons.
111
+ */
112
+ disabled?: boolean;
113
+ /**
114
+ * Allows to customize the layout of the form by providing a custom
115
+ * renderer. The renderer receives the form instance and the pre-rendered
116
+ * fields as props. The renderer can either reuse the pre-rendered fields in
117
+ * the custom layout, or render custom fields and connect them to the form
118
+ * manually.
119
+ *
120
+ * Check the component documentation for details and examples.
121
+ *
122
+ * Example using pre-rendered fields:
123
+ * ```tsx
124
+ * <AutoForm layoutRenderer={({ children }) =>
125
+ * <VerticalLayout>
126
+ * {children}
127
+ * <p>All data is collected anonymously.</p>
128
+ * </VerticalLayout>
129
+ * } />
130
+ * ```
131
+ *
132
+ * Example rendering custom fields:
133
+ * ```tsx
134
+ * <AutoForm layoutRenderer={({ form }) =>
135
+ * <VerticalLayout>
136
+ * <TextField {...form.field(form.model.name)} />
137
+ * ...
138
+ * </VerticalLayout>
139
+ * } />
140
+ * ```
141
+ */
142
+ layoutRenderer?: ComponentType<AutoFormLayoutRendererProps<M>>;
143
+ /**
144
+ * Defines the fields to show in the form, and in which order. This takes
145
+ * an array of property names. Properties that are not included in this
146
+ * array will not be shown in the form, and properties that are included,
147
+ * but don't exist in the model, will be ignored.
148
+ */
149
+ visibleFields?: string[];
150
+ /**
151
+ * Allows to customize the FormLayout used by default. This is especially useful
152
+ * to define the `responsiveSteps`. See the
153
+ * {@link https://hilla.dev/docs/react/components/form-layout | FormLayout documentation}
154
+ * for details.
155
+ */
156
+ formLayoutProps?: ComponentStyleProps & Pick<Parameters<typeof FormLayout>[0], 'responsiveSteps'>;
157
+ /**
158
+ * Allows to customize individual fields of the form. This takes an object
159
+ * where the keys are property names, and the values are options for the
160
+ * respective field for editing that property.
161
+ */
162
+ fieldOptions?: Record<string, FieldOptions>;
163
+ /**
164
+ * Whether to show the delete button in the form. This is disabled by
165
+ * default. If enabled, the delete button will only be shown when editing
166
+ * an existing item, which means that `item` is not null. The delete button
167
+ * will also only be shown if an item has a discernible ID. See the
168
+ * `itemIdProperty` prop for details how the item ID is detected.
169
+ *
170
+ * Use the `onDeleteSuccess` callback to get notified when the item has been
171
+ * deleted.
172
+ *
173
+ * NOTE: This only hides the button, it does not prevent from calling the
174
+ * delete method on the service. To completely disable deleting, you must
175
+ * override the `delete` method in the backend Java service to either throw
176
+ * an exception or annotate it with `@DenyAll` to prevent access.
177
+ */
178
+ deleteButtonVisible?: boolean;
179
+ /**
180
+ * A callback that will be called if an unexpected error occurs while
181
+ * submitting the form.
182
+ *
183
+ * Note that this will not be called for validation errors, which are
184
+ * handled automatically.
185
+ */
186
+ onSubmitError?({ error }: SubmitErrorEvent): void;
187
+ /**
188
+ * A callback that will be called after the form has been successfully
189
+ * submitted and the item has been saved.
190
+ *
191
+ * When submitting a new item (i.e. when `item` is null or undefined), the
192
+ * form will be automatically cleared, allowing to submit another new item.
193
+ * In order to keep editing the same item after submitting, set the `item`
194
+ * prop to the new item.
195
+ */
196
+ onSubmitSuccess?({ item }: SubmitEvent<Value<M>>): void;
197
+ /**
198
+ * A callback that will be called if an unexpected error occurs while
199
+ * deleting an item.
200
+ */
201
+ onDeleteError?({ error }: DeleteErrorEvent): void;
202
+ /**
203
+ * A callback that will be called after the form has been successfully
204
+ * deleted.
205
+ */
206
+ onDeleteSuccess?({ item }: DeleteEvent<Value<M>>): void;
207
+ }>;
208
+ /**
209
+ * Auto Form is a component that automatically generates a form for editing,
210
+ * updating and deleting items from a backend service.
211
+ *
212
+ * Example usage:
213
+ * ```tsx
214
+ * import { AutoForm } from '@hilla/react-crud';
215
+ * import PersonService from 'Frontend/generated/endpoints';
216
+ * import PersonModel from 'Frontend/generated/com/example/application/Person';
217
+ *
218
+ * <AutoForm
219
+ * service={PersonService}
220
+ * model={PersonModel}
221
+ * onSubmitSuccess={({ item }) => {
222
+ * console.log('Submitted item:', item);
223
+ * }}
224
+ * />
225
+ * ```
226
+ */
227
+ export declare function AutoForm<M extends AbstractModel>({ service, model, itemIdProperty, item, onSubmitError, onSubmitSuccess, disabled, layoutRenderer: LayoutRenderer, visibleFields, formLayoutProps, fieldOptions, style, id, className, deleteButtonVisible, onDeleteSuccess, onDeleteError, }: AutoFormProps<M>): JSX.Element;
228
+ //# sourceMappingURL=autoform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoform.d.ts","sourceRoot":"","sources":["src/autoform.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,wBAAwB,EAAmB,KAAK,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACxH,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGvE,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAEjE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,GAAG,EAER,KAAK,YAAY,EAIlB,MAAM,OAAO,CAAC;AACf,OAAO,EAAiB,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAA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