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

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.
@@ -38,11 +38,15 @@ var SchemaEditor = function SchemaEditor(_ref) {
38
38
  _ref$optionLists = _ref.optionLists,
39
39
  optionLists = _ref$optionLists === void 0 ? utilities.EMPTY_ARRAY : _ref$optionLists,
40
40
  children = _ref.children,
41
+ onSubmit = _ref.onSubmit,
41
42
  onChange = _ref.onChange;
42
43
  var formRef = react.useRef(null);
43
44
  var handleChange = react.useCallback(function (model) {
44
45
  onChange === null || onChange === void 0 || onChange(model.schema);
45
46
  }, []);
47
+ var handleSubmit = react.useCallback(function (model) {
48
+ onSubmit === null || onSubmit === void 0 || onSubmit(model.schema);
49
+ }, []);
46
50
  react.useEffect(function () {
47
51
  var _formRef$current;
48
52
  (_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValues({
@@ -51,7 +55,8 @@ var SchemaEditor = function SchemaEditor(_ref) {
51
55
  }, [schemaDef]);
52
56
  return /*#__PURE__*/jsxRuntime.jsxs(Form.Form, {
53
57
  formRef: formRef,
54
- onSubmit: handleChange,
58
+ onChange: handleChange,
59
+ onSubmit: handleSubmit,
55
60
  children: [/*#__PURE__*/jsxRuntime.jsx(SchemaArrayForm.SchemaArrayForm, {
56
61
  dynamic: dynamic,
57
62
  optionLists: optionLists,
@@ -29,10 +29,9 @@ var SchemaArrayForm = function SchemaArrayForm(_ref) {
29
29
  fields = _useFieldArray.fields,
30
30
  append = _useFieldArray.append,
31
31
  remove = _useFieldArray.remove,
32
- update = _useFieldArray.update,
33
32
  move = _useFieldArray.move;
34
33
  var handleTypeChange = react.useCallback(function (index, val) {
35
- update(index, val);
34
+ form.setValue("schema.".concat(index), val);
36
35
  }, []);
37
36
  var handleRemove = react.useCallback(function (index) {
38
37
  remove(index);
@@ -130,7 +130,7 @@ var SchemaField = function SchemaField(_ref) {
130
130
  var modelRef = getModel();
131
131
  var reset = {
132
132
  datatype: type,
133
- id: field,
133
+ id: id,
134
134
  label: modelRef.label,
135
135
  defaultValue: modelRef.defaultValue,
136
136
  required: modelRef.required,
@@ -161,7 +161,7 @@ var SchemaField = function SchemaField(_ref) {
161
161
  onTypeChange(reset);
162
162
  setType(type);
163
163
  }
164
- }, []);
164
+ }, [id]);
165
165
  return /*#__PURE__*/jsxRuntime.jsx(SortableItem, {
166
166
  id: fieldId,
167
167
  className: "flex flex-nowrap gap-1 group/field",
@@ -244,7 +244,9 @@ var SchemaField = function SchemaField(_ref) {
244
244
  icon: core.CoreIcons.list,
245
245
  "aria-label": "Custom options",
246
246
  onClick: function onClick() {
247
- void openOptionModal();
247
+ void openOptionModal({
248
+ title: "".concat(id, " Options")
249
+ });
248
250
  }
249
251
  })]
250
252
  }), OptionModal]
@@ -38,11 +38,15 @@ var SchemaEditor = function SchemaEditor(_ref) {
38
38
  _ref$optionLists = _ref.optionLists,
39
39
  optionLists = _ref$optionLists === void 0 ? EMPTY_ARRAY : _ref$optionLists,
40
40
  children = _ref.children,
41
+ onSubmit = _ref.onSubmit,
41
42
  onChange = _ref.onChange;
42
43
  var formRef = useRef(null);
43
44
  var handleChange = useCallback(function (model) {
44
45
  onChange === null || onChange === void 0 || onChange(model.schema);
45
46
  }, []);
47
+ var handleSubmit = useCallback(function (model) {
48
+ onSubmit === null || onSubmit === void 0 || onSubmit(model.schema);
49
+ }, []);
46
50
  useEffect(function () {
47
51
  var _formRef$current;
48
52
  (_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValues({
@@ -51,7 +55,8 @@ var SchemaEditor = function SchemaEditor(_ref) {
51
55
  }, [schemaDef]);
52
56
  return /*#__PURE__*/jsxs(Form, {
53
57
  formRef: formRef,
54
- onSubmit: handleChange,
58
+ onChange: handleChange,
59
+ onSubmit: handleSubmit,
55
60
  children: [/*#__PURE__*/jsx(SchemaArrayForm, {
56
61
  dynamic: dynamic,
57
62
  optionLists: optionLists,
@@ -29,10 +29,9 @@ var SchemaArrayForm = function SchemaArrayForm(_ref) {
29
29
  fields = _useFieldArray.fields,
30
30
  append = _useFieldArray.append,
31
31
  remove = _useFieldArray.remove,
32
- update = _useFieldArray.update,
33
32
  move = _useFieldArray.move;
34
33
  var handleTypeChange = useCallback(function (index, val) {
35
- update(index, val);
34
+ form.setValue("schema.".concat(index), val);
36
35
  }, []);
37
36
  var handleRemove = useCallback(function (index) {
38
37
  remove(index);
@@ -130,7 +130,7 @@ var SchemaField = function SchemaField(_ref) {
130
130
  var modelRef = getModel();
131
131
  var reset = {
132
132
  datatype: type,
133
- id: field,
133
+ id: id,
134
134
  label: modelRef.label,
135
135
  defaultValue: modelRef.defaultValue,
136
136
  required: modelRef.required,
@@ -161,7 +161,7 @@ var SchemaField = function SchemaField(_ref) {
161
161
  onTypeChange(reset);
162
162
  setType(type);
163
163
  }
164
- }, []);
164
+ }, [id]);
165
165
  return /*#__PURE__*/jsx(SortableItem, {
166
166
  id: fieldId,
167
167
  className: "flex flex-nowrap gap-1 group/field",
@@ -244,7 +244,9 @@ var SchemaField = function SchemaField(_ref) {
244
244
  icon: CoreIcons.list,
245
245
  "aria-label": "Custom options",
246
246
  onClick: function onClick() {
247
- void openOptionModal();
247
+ void openOptionModal({
248
+ title: "".concat(id, " Options")
249
+ });
248
250
  }
249
251
  })]
250
252
  }), OptionModal]
@@ -1,2 +1,2 @@
1
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;
2
+ export declare const SchemaEditor: ({ schemaDef, dynamic, acceptableTypes, optionLists, children, onSubmit, onChange, }: SchemaEditorProps) => import("react/jsx-runtime").JSX.Element;
@@ -99,6 +99,7 @@ export interface SchemaEditorProps {
99
99
  * footer actions
100
100
  */
101
101
  children?: Elements<JSX.Element> | Array<Elements<JSX.Element>>;
102
- onChange: (schema: FormSchema) => void;
102
+ onChange?: (schema: FormSchema) => void;
103
+ onSubmit?: (schema: FormSchema) => void;
103
104
  }
104
105
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/form",
3
- "version": "1.0.0-beta.35",
3
+ "version": "1.0.0-beta.36",
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.35",
43
- "@react-fabric/date": "^1.0.0-beta.35",
44
- "@react-fabric/utilities": "^1.0.0-beta.35",
42
+ "@react-fabric/core": "^1.0.0-beta.36",
43
+ "@react-fabric/date": "^1.0.0-beta.36",
44
+ "@react-fabric/utilities": "^1.0.0-beta.36",
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": "4a5cb87557f8c7c88cac937e3bd71fd6eeb07113"
64
+ "gitHead": "91a7cce216e21cbc6406226d8c3f56a1a26e410a"
65
65
  }
@@ -38,6 +38,7 @@ export const SchemaEditor = ({
38
38
  acceptableTypes,
39
39
  optionLists = EMPTY_ARRAY,
40
40
  children,
41
+ onSubmit,
41
42
  onChange,
42
43
  }: SchemaEditorProps) => {
43
44
  const formRef = useRef<FormRef<{ schema: FormSchema }>>(null);
@@ -46,12 +47,16 @@ export const SchemaEditor = ({
46
47
  onChange?.(model.schema);
47
48
  }, []);
48
49
 
50
+ const handleSubmit = useCallback((model: { schema: FormSchema }) => {
51
+ onSubmit?.(model.schema);
52
+ }, []);
53
+
49
54
  useEffect(() => {
50
55
  formRef.current?.setValues({ schema: schemaDef });
51
56
  }, [schemaDef]);
52
57
 
53
58
  return (
54
- <Form formRef={formRef} onSubmit={handleChange}>
59
+ <Form formRef={formRef} onChange={handleChange} onSubmit={handleSubmit}>
55
60
  <SchemaArrayForm
56
61
  dynamic={dynamic}
57
62
  optionLists={optionLists}
@@ -45,13 +45,13 @@ export const SchemaArrayForm = ({
45
45
  }: Partial<SchemaEditorProps>) => {
46
46
  const form = useFormContext();
47
47
  const [defaultOpen, setDefaultOpen] = useState(true);
48
- const { fields, append, remove, update, move } = useFieldArray({
48
+ const { fields, append, remove, move } = useFieldArray({
49
49
  name: "schema",
50
50
  control: form.control,
51
51
  });
52
52
 
53
53
  const handleTypeChange = useCallback((index: number, val: KeyValue) => {
54
- update(index, val);
54
+ form.setValue(`schema.${index}`, val);
55
55
  }, []);
56
56
 
57
57
  const handleRemove = useCallback((index: number) => {
@@ -168,43 +168,46 @@ export const SchemaField = ({
168
168
  }, 10);
169
169
  }, []);
170
170
 
171
- const handleTypeChange = useCallback((type: DATA_TYPES) => {
172
- if (type) {
173
- const modelRef = getModel();
174
- let reset = {
175
- datatype: type,
176
- id: field,
177
- label: modelRef.label,
178
- defaultValue: modelRef.defaultValue,
179
- required: modelRef.required,
180
- multiple: type === DATA_TYPES.AVATAR ? false : modelRef.multiple,
181
- minItems: modelRef.minItems,
182
- maxItems: modelRef.maxItems,
183
- } as DefaultSchema & ValueType;
184
- if (type === DATA_TYPES.STRING) {
185
- reset = Object.assign(reset, {
186
- optionList: modelRef.optionList,
187
- options: modelRef.options,
188
- regex: modelRef.regex,
189
- } as StringSchema);
190
- } else if (type === DATA_TYPES.DATE) {
191
- reset = Object.assign(reset, {
192
- type: "date",
193
- } as DateSchema);
194
- } else if (type === DATA_TYPES.NUMBER || type === DATA_TYPES.RANGE) {
195
- reset = Object.assign(reset, {
196
- min: modelRef.min,
197
- max: modelRef.max,
198
- step: modelRef.step,
199
- } as NumberSchema);
171
+ const handleTypeChange = useCallback(
172
+ (type: DATA_TYPES) => {
173
+ if (type) {
174
+ const modelRef = getModel();
175
+ let reset = {
176
+ datatype: type,
177
+ id,
178
+ label: modelRef.label,
179
+ defaultValue: modelRef.defaultValue,
180
+ required: modelRef.required,
181
+ multiple: type === DATA_TYPES.AVATAR ? false : modelRef.multiple,
182
+ minItems: modelRef.minItems,
183
+ maxItems: modelRef.maxItems,
184
+ } as DefaultSchema & ValueType;
185
+ if (type === DATA_TYPES.STRING) {
186
+ reset = Object.assign(reset, {
187
+ optionList: modelRef.optionList,
188
+ options: modelRef.options,
189
+ regex: modelRef.regex,
190
+ } as StringSchema);
191
+ } else if (type === DATA_TYPES.DATE) {
192
+ reset = Object.assign(reset, {
193
+ type: "date",
194
+ } as DateSchema);
195
+ } else if (type === DATA_TYPES.NUMBER || type === DATA_TYPES.RANGE) {
196
+ reset = Object.assign(reset, {
197
+ min: modelRef.min,
198
+ max: modelRef.max,
199
+ step: modelRef.step,
200
+ } as NumberSchema);
201
+ }
202
+ if (type === DATA_TYPES.AVATAR) {
203
+ setMultiple(false);
204
+ }
205
+ onTypeChange(reset);
206
+ setType(type);
200
207
  }
201
- if (type === DATA_TYPES.AVATAR) {
202
- setMultiple(false);
203
- }
204
- onTypeChange(reset);
205
- setType(type);
206
- }
207
- }, []);
208
+ },
209
+ [id],
210
+ );
208
211
 
209
212
  return (
210
213
  <SortableItem id={fieldId} className="flex flex-nowrap gap-1 group/field">
@@ -276,7 +279,7 @@ export const SchemaField = ({
276
279
  icon={CoreIcons.list}
277
280
  aria-label="Custom options"
278
281
  onClick={() => {
279
- void openOptionModal();
282
+ void openOptionModal({ title: `${id} Options` });
280
283
  }}
281
284
  />
282
285
  )}
@@ -150,5 +150,6 @@ export interface SchemaEditorProps {
150
150
  */
151
151
  children?: Elements<JSX.Element> | Array<Elements<JSX.Element>>;
152
152
 
153
- onChange: (schema: FormSchema) => void;
153
+ onChange?: (schema: FormSchema) => void;
154
+ onSubmit?: (schema: FormSchema) => void;
154
155
  }