@react-fabric/form 1.0.0-beta.33 → 1.0.0-beta.35

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 (69) hide show
  1. package/dist/cjs/builder/FormField.js +3 -3
  2. package/dist/cjs/builder/SchemaEditor.js +43 -404
  3. package/dist/cjs/builder/components/AddSchemaFields.js +62 -0
  4. package/dist/cjs/builder/components/SchemaArrayForm.js +144 -0
  5. package/dist/cjs/builder/components/SchemaField.js +411 -0
  6. package/dist/cjs/form/Form.js +11 -8
  7. package/dist/cjs/index.js +1 -0
  8. package/dist/cjs/input/ColorInput.js +1 -1
  9. package/dist/cjs/input/DateInput.js +2 -2
  10. package/dist/cjs/input/File.js +1 -1
  11. package/dist/cjs/input/Hidden.js +1 -1
  12. package/dist/cjs/input/Input.js +1 -1
  13. package/dist/cjs/input/Number.js +1 -1
  14. package/dist/cjs/input/Password.js +1 -1
  15. package/dist/cjs/input/RangeSlider.js +1 -1
  16. package/dist/cjs/input/Search.js +1 -1
  17. package/dist/cjs/input/Slider.js +1 -1
  18. package/dist/cjs/input/Textarea.js +1 -1
  19. package/dist/cjs/types/schema.js +2 -0
  20. package/dist/esm/builder/FormField.js +3 -3
  21. package/dist/esm/builder/SchemaEditor.js +45 -406
  22. package/dist/esm/builder/components/AddSchemaFields.js +62 -0
  23. package/dist/esm/builder/components/SchemaArrayForm.js +144 -0
  24. package/dist/esm/builder/components/SchemaField.js +411 -0
  25. package/dist/esm/form/Form.js +11 -8
  26. package/dist/esm/index.js +1 -1
  27. package/dist/esm/input/ColorInput.js +1 -1
  28. package/dist/esm/input/DateInput.js +2 -2
  29. package/dist/esm/input/File.js +1 -1
  30. package/dist/esm/input/Hidden.js +1 -1
  31. package/dist/esm/input/Input.js +1 -1
  32. package/dist/esm/input/Number.js +1 -1
  33. package/dist/esm/input/Password.js +1 -1
  34. package/dist/esm/input/RangeSlider.js +1 -1
  35. package/dist/esm/input/Search.js +1 -1
  36. package/dist/esm/input/Slider.js +1 -1
  37. package/dist/esm/input/Textarea.js +1 -1
  38. package/dist/esm/types/schema.js +2 -1
  39. package/dist/types/builder/SchemaEditor.d.ts +2 -10
  40. package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
  41. package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
  42. package/dist/types/builder/components/SchemaField.d.ts +10 -0
  43. package/dist/types/form/Form.d.ts +1 -5
  44. package/dist/types/index.d.ts +1 -1
  45. package/dist/types/input/ColorInput.d.ts +1 -1
  46. package/dist/types/types/index.d.ts +1 -1
  47. package/dist/types/types/schema.d.ts +26 -0
  48. package/package.json +5 -5
  49. package/src/builder/FormField.tsx +3 -3
  50. package/src/builder/SchemaEditor.tsx +24 -398
  51. package/src/builder/components/AddSchemaFields.tsx +74 -0
  52. package/src/builder/components/SchemaArrayForm.tsx +158 -0
  53. package/src/builder/components/SchemaField.tsx +432 -0
  54. package/src/form/Form.tsx +6 -9
  55. package/src/index.ts +6 -1
  56. package/src/input/ArrayInput.tsx +1 -0
  57. package/src/input/ColorInput.tsx +5 -2
  58. package/src/input/DateInput.tsx +2 -2
  59. package/src/input/File.tsx +1 -1
  60. package/src/input/Hidden.tsx +4 -3
  61. package/src/input/Input.tsx +1 -1
  62. package/src/input/Number.tsx +1 -1
  63. package/src/input/Password.tsx +1 -1
  64. package/src/input/RangeSlider.tsx +1 -1
  65. package/src/input/Search.tsx +1 -1
  66. package/src/input/Slider.tsx +1 -1
  67. package/src/input/Textarea.tsx +1 -1
  68. package/src/types/index.ts +1 -1
  69. package/src/types/schema.ts +30 -0
@@ -42,7 +42,7 @@ var Input = function Input(_ref) {
42
42
  var handleChange = useCallback(function (e) {
43
43
  var value = e === null || e === void 0 ? void 0 : e.target.value;
44
44
  setActualValue(value !== null && value !== void 0 ? value : "");
45
- onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : undefined);
45
+ onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
46
46
  }, [onchange]);
47
47
  return /*#__PURE__*/jsx(InputWrapper, _objectSpread(_objectSpread({
48
48
  showClear: !!actualValue,
@@ -42,7 +42,7 @@ var Number = function Number(_ref) {
42
42
  var handleChange = useCallback(function (e) {
43
43
  var number = e === null || e === void 0 ? void 0 : e.target.valueAsNumber;
44
44
  setActualValue(number !== null && number !== void 0 ? number : "");
45
- onChange === null || onChange === void 0 || onChange(number !== null && number !== void 0 ? number : undefined);
45
+ onChange === null || onChange === void 0 || onChange(number !== null && number !== void 0 ? number : null);
46
46
  }, [onChange]);
47
47
  return /*#__PURE__*/jsx(InputWrapper, _objectSpread(_objectSpread({
48
48
  showClear: !!actualValue,
@@ -50,7 +50,7 @@ var Password = function Password(_ref) {
50
50
  var handleChange = useCallback(function (e) {
51
51
  var value = e === null || e === void 0 ? void 0 : e.target.value;
52
52
  setActualValue(value !== null && value !== void 0 ? value : "");
53
- onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : undefined);
53
+ onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
54
54
  }, [onChange]);
55
55
  return /*#__PURE__*/jsxs(InputWrapper, _objectSpread(_objectSpread({
56
56
  showClear: !!actualValue,
@@ -71,7 +71,7 @@ var RangeSlider = function RangeSlider(_ref) {
71
71
  }, [showValue]);
72
72
  var handleChange = useCallback(function (val) {
73
73
  setActualValue(val !== null && val !== void 0 ? val : [min, max]);
74
- onChange === null || onChange === void 0 || onChange(val !== null && val !== void 0 ? val : undefined);
74
+ onChange === null || onChange === void 0 || onChange(val !== null && val !== void 0 ? val : null);
75
75
  }, [onChange, min, max]);
76
76
  var minDisplay = useMemo(function () {
77
77
  return /*#__PURE__*/jsx("span", {
@@ -53,7 +53,7 @@ var Search = function Search(_ref) {
53
53
  var value = e === null || e === void 0 ? void 0 : e.target.value;
54
54
  refValue.current = value !== null && value !== void 0 ? value : "";
55
55
  setActualValue(value !== null && value !== void 0 ? value : "");
56
- onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : undefined);
56
+ onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
57
57
 
58
58
  // value was cleared so force fire onSearch
59
59
  if (searchOnChange) {
@@ -73,7 +73,7 @@ var Slider = function Slider(_ref) {
73
73
  var handleChange = useCallback(function (value) {
74
74
  var val = useInfinity && value === max ? Infinity : value;
75
75
  setActualValue(val !== null && val !== void 0 ? val : 0);
76
- onChange === null || onChange === void 0 || onChange(val !== null && val !== void 0 ? val : undefined);
76
+ onChange === null || onChange === void 0 || onChange(val !== null && val !== void 0 ? val : null);
77
77
  }, [onChange, max, useInfinity]);
78
78
  var minDisplay = useMemo(function () {
79
79
  return /*#__PURE__*/jsx("span", {
@@ -47,7 +47,7 @@ var Textarea = function Textarea(_ref) {
47
47
  var handleChange = useCallback(function (e) {
48
48
  var value = e === null || e === void 0 ? void 0 : e.target.value;
49
49
  setActualValue(value !== null && value !== void 0 ? value : "");
50
- onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : undefined);
50
+ onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
51
51
  }, [onChange]);
52
52
  useEffect(function () {
53
53
  if (variableRows) {
@@ -36,5 +36,6 @@ var DATA_TYPES = /*#__PURE__*/function (DATA_TYPES) {
36
36
  DATA_TYPES["SCHEMA"] = "schema";
37
37
  return DATA_TYPES;
38
38
  }({});
39
+ var SCHEMA_CUSTOM_LIST = "--CUSTOM--";
39
40
 
40
- export { DATA_TYPES };
41
+ export { DATA_TYPES, SCHEMA_CUSTOM_LIST };
@@ -1,10 +1,2 @@
1
- import { DATA_TYPES, type FormSchema } from "../types/schema";
2
- interface Props {
3
- schemaDef: FormSchema;
4
- allowRemove?: boolean;
5
- acceptableTypes?: DATA_TYPES[];
6
- optionLists?: string[];
7
- onChange: (schema: FormSchema) => void;
8
- }
9
- export declare const SchemaEditor: ({ schemaDef, allowRemove, acceptableTypes, optionLists, onChange, }: Props) => import("react/jsx-runtime").JSX.Element;
10
- export {};
1
+ import { type SchemaEditorProps } from "../types/schema";
2
+ export declare const SchemaEditor: ({ schemaDef, dynamic, acceptableTypes, optionLists, children, onChange, }: SchemaEditorProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { type ModalProps } from "@react-fabric/core";
2
+ export declare const AddSchemaFields: (props: ModalProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { type SchemaEditorProps } from "../../types/schema";
2
+ export declare const SchemaArrayForm: ({ dynamic, acceptableTypes, optionLists, }: Partial<SchemaEditorProps>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { type SchemaEditorProps } from "../../types/schema";
2
+ export declare const SchemaField: ({ id, field, fieldId, getModel, onRemove, defaultOpen, optionLists, dynamic, onTypeChange, acceptableTypes, }: {
3
+ id: string;
4
+ field: string;
5
+ fieldId: string;
6
+ defaultOpen?: boolean;
7
+ onRemove: () => void;
8
+ getModel: () => KeyValue;
9
+ onTypeChange: (val: KeyValue) => void;
10
+ } & Omit<SchemaEditorProps, "schemaDef" | "onChange">) => import("react/jsx-runtime").JSX.Element;
@@ -17,10 +17,6 @@ export interface FormProps<K extends KeyValue = KeyValue> {
17
17
  * form data schema
18
18
  */
19
19
  schema?: yup.ObjectSchema<K>;
20
- /**
21
- * current form model
22
- */
23
- values?: K;
24
20
  /**
25
21
  * default data values
26
22
  */
@@ -34,4 +30,4 @@ export interface FormProps<K extends KeyValue = KeyValue> {
34
30
  */
35
31
  onSubmit?: (values: K) => void;
36
32
  }
37
- export declare const Form: <K extends KeyValue<any>>({ formRef, schema, children, values, defaultValues, onSubmit, onChange, ...rest }: PropsWithChildren<FormProps<K>>) => import("react/jsx-runtime").JSX.Element;
33
+ export declare const Form: <K extends KeyValue<any>>({ formRef, schema, children, defaultValues, onSubmit, onChange, ...rest }: PropsWithChildren<FormProps<K>>) => import("react/jsx-runtime").JSX.Element;
@@ -4,7 +4,7 @@ export { Form, type FormRef } from "./form/Form";
4
4
  export { SchemaEditor } from "./builder/SchemaEditor";
5
5
  export { useFileUploader } from "./hooks/useFileUploader";
6
6
  export { useFormBuilder } from "./hooks/useFormBuilder";
7
- export { DATA_TYPES, type FormSchema, type SchemaDef } from "./types/schema";
7
+ export { DATA_TYPES, SCHEMA_CUSTOM_LIST, type FormSchema, type SchemaDef, } from "./types/schema";
8
8
  export { ArrayInput } from "./input/ArrayInput";
9
9
  export { Checkbox } from "./input/Checkbox";
10
10
  export { ColorInput } from "./input/ColorInput";
@@ -1,7 +1,7 @@
1
1
  import { type RefProp } from "@react-fabric/core/dist/types/types";
2
2
  import { type InputProps } from "../types";
3
3
  import { type ColorProps } from "./ColorPicker";
4
- export interface ColorInputProps extends InputProps, ColorProps, RefProp {
4
+ export interface ColorInputProps extends InputProps, Omit<ColorProps, "onChange">, RefProp {
5
5
  /**
6
6
  * show eydrop picker
7
7
  */
@@ -8,7 +8,7 @@ export interface InputProps<V = string> extends TestProps {
8
8
  /**
9
9
  * change handler
10
10
  */
11
- onChange?: (value?: V) => void;
11
+ onChange?: (value?: V | null) => void;
12
12
  /**
13
13
  * on focus event handler
14
14
  */
@@ -1,3 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { type Elements } from "@react-fabric/core/dist/types/types";
1
3
  import { type DateLike } from "@react-fabric/date";
2
4
  export declare enum DATA_TYPES {
3
5
  TEXT = "text",
@@ -11,6 +13,7 @@ export declare enum DATA_TYPES {
11
13
  AVATAR = "avatar",
12
14
  SCHEMA = "schema"
13
15
  }
16
+ export declare const SCHEMA_CUSTOM_LIST = "--CUSTOM--";
14
17
  interface SingleValue {
15
18
  multiple?: false;
16
19
  minItems?: never;
@@ -75,4 +78,27 @@ export interface ChildSchema extends BaseSchema {
75
78
  }
76
79
  export type SchemaDef = SchemaType | (ChildSchema & ValueType);
77
80
  export type FormSchema = SchemaDef[];
81
+ export interface SchemaEditorProps {
82
+ /**
83
+ * default form schema
84
+ */
85
+ schemaDef: FormSchema;
86
+ /**
87
+ * is dynamic schema (allow add/remove)
88
+ */
89
+ dynamic?: boolean;
90
+ /**
91
+ * acceptable list of data types
92
+ */
93
+ acceptableTypes?: DATA_TYPES[];
94
+ /**
95
+ * available option lists in application
96
+ */
97
+ optionLists?: string[];
98
+ /**
99
+ * footer actions
100
+ */
101
+ children?: Elements<JSX.Element> | Array<Elements<JSX.Element>>;
102
+ onChange: (schema: FormSchema) => void;
103
+ }
78
104
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/form",
3
- "version": "1.0.0-beta.33",
3
+ "version": "1.0.0-beta.35",
4
4
  "description": "RUF: Form package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -39,9 +39,9 @@
39
39
  "@dnd-kit/utilities": "^3.2.2",
40
40
  "@floating-ui/react": "^0.26.24",
41
41
  "@hookform/resolvers": "^3.9.0",
42
- "@react-fabric/core": "^1.0.0-beta.33",
43
- "@react-fabric/date": "^1.0.0-beta.33",
44
- "@react-fabric/utilities": "^1.0.0-beta.33",
42
+ "@react-fabric/core": "^1.0.0-beta.35",
43
+ "@react-fabric/date": "^1.0.0-beta.35",
44
+ "@react-fabric/utilities": "^1.0.0-beta.35",
45
45
  "classnames": "^2.5.1",
46
46
  "color": "^4.2.3",
47
47
  "react-color": "^2.19.3",
@@ -61,5 +61,5 @@
61
61
  "node": ">=18.12.0",
62
62
  "npm": ">=8.19.0"
63
63
  },
64
- "gitHead": "3b7ffc99aac7b8fdc72c7122c39db55d1104297f"
64
+ "gitHead": "4a5cb87557f8c7c88cac937e3bd71fd6eeb07113"
65
65
  }
@@ -151,7 +151,7 @@ export const FormField = ({
151
151
  return rest.multiple && !hasOptions ? (
152
152
  <ArrayInput
153
153
  name={fieldName}
154
- label={t(label, label)}
154
+ label={t(`fb.${id}`, label || id)}
155
155
  required={required}
156
156
  onAdd={() => String("")}
157
157
  >
@@ -164,8 +164,8 @@ export const FormField = ({
164
164
  <E
165
165
  {...props}
166
166
  autoFocus={autoFocus}
167
- label={t(label, label)}
168
- placeholder={t(label, label)}
167
+ label={t(`fb.${id}`, label || id)}
168
+ placeholder={t(`fb.${id}`, label || id)}
169
169
  required={required}
170
170
  inline={inline}
171
171
  />