@react-fabric/form 1.0.0-beta.34 → 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.
@@ -0,0 +1,411 @@
1
+ 'use client';
2
+
3
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
4
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
5
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
+ import { useSortable } from '@dnd-kit/sortable';
7
+ import { CSS } from '@dnd-kit/utilities';
8
+ import { useOverlayService, Modal, Content, Footer, Button, Collapsable, CoreIcons, ToggleButtonGroup } from '@react-fabric/core';
9
+ import { EMPTY_ARRAY } from '@react-fabric/utilities';
10
+ import classNames from 'classnames';
11
+ import { useState, useCallback, useEffect, Fragment } from 'react';
12
+ import { Controller } from '../../form/Controller.js';
13
+ import { ArrayInput } from '../../input/ArrayInput.js';
14
+ import { Checkbox } from '../../input/Checkbox.js';
15
+ import { DateInput } from '../../input/DateInput.js';
16
+ import { Field } from '../../input/Field.js';
17
+ import { HiddenInput } from '../../input/Hidden.js';
18
+ import { Input } from '../../input/Input.js';
19
+ import { Number } from '../../input/Number.js';
20
+ import { Select } from '../../select/Select.js';
21
+ import { SCHEMA_CUSTOM_LIST, DATA_TYPES } from '../../types/schema.js';
22
+ import { jsxs, jsx } from 'react/jsx-runtime';
23
+
24
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
25
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
26
+ var SchemaField = function SchemaField(_ref) {
27
+ var id = _ref.id,
28
+ field = _ref.field,
29
+ fieldId = _ref.fieldId,
30
+ getModel = _ref.getModel,
31
+ onRemove = _ref.onRemove,
32
+ _ref$defaultOpen = _ref.defaultOpen,
33
+ defaultOpen = _ref$defaultOpen === void 0 ? true : _ref$defaultOpen,
34
+ _ref$optionLists = _ref.optionLists,
35
+ optionLists = _ref$optionLists === void 0 ? EMPTY_ARRAY : _ref$optionLists,
36
+ dynamic = _ref.dynamic,
37
+ onTypeChange = _ref.onTypeChange,
38
+ acceptableTypes = _ref.acceptableTypes;
39
+ var _useState = useState(),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ type = _useState2[0],
42
+ setType = _useState2[1];
43
+ var _useState3 = useState(false),
44
+ _useState4 = _slicedToArray(_useState3, 2),
45
+ multiple = _useState4[0],
46
+ setMultiple = _useState4[1];
47
+ var _useState5 = useState(false),
48
+ _useState6 = _slicedToArray(_useState5, 2),
49
+ hasOptions = _useState6[0],
50
+ setHasOptions = _useState6[1];
51
+ var _useState7 = useState(false),
52
+ _useState8 = _slicedToArray(_useState7, 2),
53
+ customOptions = _useState8[0],
54
+ setCustomOptions = _useState8[1];
55
+ var SortableItem = useCallback(function (_ref2) {
56
+ var id = _ref2.id,
57
+ children = _ref2.children,
58
+ className = _ref2.className;
59
+ if (dynamic) {
60
+ var _useSortable = useSortable({
61
+ id: id
62
+ }),
63
+ attributes = _useSortable.attributes,
64
+ listeners = _useSortable.listeners,
65
+ setNodeRef = _useSortable.setNodeRef,
66
+ transform = _useSortable.transform,
67
+ transition = _useSortable.transition,
68
+ isDragging = _useSortable.isDragging;
69
+ return /*#__PURE__*/jsxs("div", {
70
+ className: className,
71
+ ref: setNodeRef,
72
+ style: {
73
+ transform: CSS.Transform.toString(transform),
74
+ transition: transition
75
+ },
76
+ children: [/*#__PURE__*/jsx("div", _objectSpread(_objectSpread(_objectSpread({
77
+ className: classNames("invisible group-hover/field:visible my-2 w-4", isDragging ? "cursor-grabbing" : "cursor-grab")
78
+ }, attributes), listeners), {}, {
79
+ style: {
80
+ backgroundImage: "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='4' width='4'%3E%3Ccircle cx='2' cy='2' r='1' fill='%238888' /%3E%3C/svg%3E \")"
81
+ }
82
+ })), children]
83
+ });
84
+ }
85
+ return /*#__PURE__*/jsx("div", {
86
+ className: className,
87
+ children: children
88
+ });
89
+ }, [dynamic]);
90
+ // @ts-expect-error ignore
91
+ SortableItem.displayName = "SortableItem";
92
+ var _useOverlayService = useOverlayService(function (props) {
93
+ return /*#__PURE__*/jsxs(Modal, _objectSpread(_objectSpread({}, props), {}, {
94
+ children: [/*#__PURE__*/jsx(Content, {
95
+ children: /*#__PURE__*/jsx(ArrayInput, {
96
+ name: "".concat(field, ".options"),
97
+ onAdd: function onAdd() {
98
+ return String("");
99
+ },
100
+ children: /*#__PURE__*/jsx(Controller, {
101
+ children: /*#__PURE__*/jsx(Input, {})
102
+ })
103
+ })
104
+ }), /*#__PURE__*/jsx(Footer, {
105
+ flex: true,
106
+ justify: "end",
107
+ className: "sticky bottom-0 border-t bg-base px-6 py-2",
108
+ children: /*#__PURE__*/jsx(Button, {
109
+ variant: "link",
110
+ onClick: props.onClose,
111
+ children: "Close"
112
+ })
113
+ })]
114
+ }));
115
+ }),
116
+ _useOverlayService2 = _slicedToArray(_useOverlayService, 2),
117
+ OptionModal = _useOverlayService2[0],
118
+ openOptionModal = _useOverlayService2[1];
119
+ useEffect(function () {
120
+ setTimeout(function () {
121
+ var model = getModel();
122
+ setType(model.datatype);
123
+ setMultiple(model.multiple);
124
+ setHasOptions(!!model.optionList);
125
+ setCustomOptions(model.optionList === SCHEMA_CUSTOM_LIST);
126
+ }, 10);
127
+ }, []);
128
+ var handleTypeChange = useCallback(function (type) {
129
+ if (type) {
130
+ var modelRef = getModel();
131
+ var reset = {
132
+ datatype: type,
133
+ id: field,
134
+ label: modelRef.label,
135
+ defaultValue: modelRef.defaultValue,
136
+ required: modelRef.required,
137
+ multiple: type === DATA_TYPES.AVATAR ? false : modelRef.multiple,
138
+ minItems: modelRef.minItems,
139
+ maxItems: modelRef.maxItems
140
+ };
141
+ if (type === DATA_TYPES.STRING) {
142
+ reset = Object.assign(reset, {
143
+ optionList: modelRef.optionList,
144
+ options: modelRef.options,
145
+ regex: modelRef.regex
146
+ });
147
+ } else if (type === DATA_TYPES.DATE) {
148
+ reset = Object.assign(reset, {
149
+ type: "date"
150
+ });
151
+ } else if (type === DATA_TYPES.NUMBER || type === DATA_TYPES.RANGE) {
152
+ reset = Object.assign(reset, {
153
+ min: modelRef.min,
154
+ max: modelRef.max,
155
+ step: modelRef.step
156
+ });
157
+ }
158
+ if (type === DATA_TYPES.AVATAR) {
159
+ setMultiple(false);
160
+ }
161
+ onTypeChange(reset);
162
+ setType(type);
163
+ }
164
+ }, []);
165
+ return /*#__PURE__*/jsx(SortableItem, {
166
+ id: fieldId,
167
+ className: "flex flex-nowrap gap-1 group/field",
168
+ children: /*#__PURE__*/jsxs(Collapsable, {
169
+ open: defaultOpen,
170
+ className: "flex-1",
171
+ children: [/*#__PURE__*/jsxs("div", {
172
+ className: "flex flex-nowrap items-center",
173
+ children: [/*#__PURE__*/jsx("span", {
174
+ className: "flex-1 truncate",
175
+ children: id
176
+ }), dynamic && /*#__PURE__*/jsx(Button, {
177
+ size: "sm",
178
+ color: "danger",
179
+ variant: "link",
180
+ "aria-label": "Delete",
181
+ stopPropagation: true,
182
+ icon: CoreIcons.trash,
183
+ onClick: onRemove,
184
+ className: "invisible group-hover/field:visible"
185
+ })]
186
+ }), /*#__PURE__*/jsxs("div", {
187
+ className: "flex flex-col gap-1 pb-4",
188
+ children: [/*#__PURE__*/jsx(Controller, {
189
+ name: "".concat(field, ".id"),
190
+ children: /*#__PURE__*/jsx(HiddenInput, {
191
+ hiddenValue: id
192
+ })
193
+ }), /*#__PURE__*/jsx(Controller, {
194
+ name: "".concat(field, ".datatype"),
195
+ children: /*#__PURE__*/jsx(Select, {
196
+ inline: true,
197
+ label: "Type",
198
+ placeholder: "Data type",
199
+ options: acceptableTypes,
200
+ onChange: function onChange(val) {
201
+ return handleTypeChange(val);
202
+ }
203
+ })
204
+ }), /*#__PURE__*/jsx(Controller, {
205
+ name: "".concat(field, ".label"),
206
+ children: /*#__PURE__*/jsx(Input, {
207
+ inline: true,
208
+ label: "Label",
209
+ allowClear: true,
210
+ placeholder: "Label...",
211
+ decorateEndShowWhenEmpty: true,
212
+ decorateEnd: /*#__PURE__*/jsx("span", {
213
+ className: "text-sm text-muted/50 px-1",
214
+ children: "OPTIONAL"
215
+ })
216
+ })
217
+ }), type === DATA_TYPES.STRING && /*#__PURE__*/jsxs(Fragment, {
218
+ children: [/*#__PURE__*/jsx(Controller, {
219
+ name: "".concat(field, ".regex"),
220
+ children: /*#__PURE__*/jsx(Input, {
221
+ inline: true,
222
+ label: "Regex validation",
223
+ allowClear: true,
224
+ placeholder: "Regex value...",
225
+ decorateEndShowWhenEmpty: true,
226
+ decorateEnd: /*#__PURE__*/jsx("span", {
227
+ className: "text-sm text-muted/50 px-1",
228
+ children: "OPTIONAL"
229
+ })
230
+ })
231
+ }), /*#__PURE__*/jsxs(Field, {
232
+ inline: true,
233
+ label: "Option list",
234
+ children: [/*#__PURE__*/jsx(Controller, {
235
+ name: "".concat(field, ".optionList"),
236
+ children: /*#__PURE__*/jsx(Select, {
237
+ allowClear: true,
238
+ options: [SCHEMA_CUSTOM_LIST].concat(_toConsumableArray(optionLists)),
239
+ onChange: function onChange(v) {
240
+ return setCustomOptions(v === SCHEMA_CUSTOM_LIST);
241
+ }
242
+ })
243
+ }), customOptions && /*#__PURE__*/jsx(Button, {
244
+ icon: CoreIcons.list,
245
+ "aria-label": "Custom options",
246
+ onClick: function onClick() {
247
+ void openOptionModal();
248
+ }
249
+ })]
250
+ }), OptionModal]
251
+ }), type === DATA_TYPES.FILE && /*#__PURE__*/jsx(Fragment, {
252
+ children: /*#__PURE__*/jsx(Controller, {
253
+ name: "".concat(field, ".accept"),
254
+ children: /*#__PURE__*/jsx(Input, {
255
+ inline: true,
256
+ label: "Accept types",
257
+ allowClear: true,
258
+ placeholder: "Accept value...",
259
+ decorateEndShowWhenEmpty: true,
260
+ decorateEnd: /*#__PURE__*/jsx("span", {
261
+ className: "text-sm text-muted/50 px-1",
262
+ children: "OPTIONAL"
263
+ })
264
+ })
265
+ })
266
+ }), [DATA_TYPES.NUMBER, DATA_TYPES.RANGE].includes(type) && /*#__PURE__*/jsxs(Fragment, {
267
+ children: [/*#__PURE__*/jsx(Controller, {
268
+ name: "".concat(field, ".min"),
269
+ children: /*#__PURE__*/jsx(Number, {
270
+ inline: true,
271
+ label: "Min value",
272
+ allowClear: true,
273
+ placeholder: "Minimum value...",
274
+ decorateEndShowWhenEmpty: true,
275
+ decorateEnd: /*#__PURE__*/jsx("span", {
276
+ className: "text-sm text-muted/50 px-1",
277
+ children: "OPTIONAL"
278
+ })
279
+ })
280
+ }), /*#__PURE__*/jsx(Controller, {
281
+ name: "".concat(field, ".max"),
282
+ children: /*#__PURE__*/jsx(Number, {
283
+ inline: true,
284
+ label: "Max value",
285
+ allowClear: true,
286
+ placeholder: "Maximum value...",
287
+ decorateEndShowWhenEmpty: true,
288
+ decorateEnd: /*#__PURE__*/jsx("span", {
289
+ className: "text-sm text-muted/50 px-1",
290
+ children: "OPTIONAL"
291
+ })
292
+ })
293
+ }), /*#__PURE__*/jsx(Controller, {
294
+ name: "".concat(field, ".step"),
295
+ children: /*#__PURE__*/jsx(Number, {
296
+ inline: true,
297
+ label: "Step value",
298
+ allowClear: true,
299
+ placeholder: "Step value...",
300
+ decorateEndShowWhenEmpty: true,
301
+ decorateEnd: /*#__PURE__*/jsx("span", {
302
+ className: "text-sm text-muted/50 px-1",
303
+ children: "OPTIONAL"
304
+ })
305
+ })
306
+ })]
307
+ }), type === DATA_TYPES.DATE && /*#__PURE__*/jsxs(Fragment, {
308
+ children: [/*#__PURE__*/jsx(Field, {
309
+ inline: true,
310
+ label: "Type",
311
+ plain: true,
312
+ children: /*#__PURE__*/jsx(Controller, {
313
+ name: "".concat(field, ".type"),
314
+ children: /*#__PURE__*/jsxs(ToggleButtonGroup, {
315
+ value: "",
316
+ fullWidth: true,
317
+ className: "flex-1",
318
+ children: [/*#__PURE__*/jsx(Button, {
319
+ className: "flex-1",
320
+ value: "date",
321
+ children: "Date"
322
+ }), /*#__PURE__*/jsx(Button, {
323
+ className: "flex-1",
324
+ value: "datetime",
325
+ children: "Date Time"
326
+ })]
327
+ })
328
+ })
329
+ }), /*#__PURE__*/jsx(Controller, {
330
+ name: "".concat(field, ".min"),
331
+ children: /*#__PURE__*/jsx(DateInput, {
332
+ inline: true,
333
+ label: "Min value",
334
+ allowClear: true,
335
+ placeholder: "Minimum value...",
336
+ decorateEndShowWhenEmpty: true,
337
+ decorateEnd: /*#__PURE__*/jsx("span", {
338
+ className: "text-sm text-muted/50 px-1",
339
+ children: "OPTIONAL"
340
+ })
341
+ })
342
+ }), /*#__PURE__*/jsx(Controller, {
343
+ name: "".concat(field, ".max"),
344
+ children: /*#__PURE__*/jsx(DateInput, {
345
+ inline: true,
346
+ label: "Max value",
347
+ allowClear: true,
348
+ placeholder: "Maximum value...",
349
+ decorateEndShowWhenEmpty: true,
350
+ decorateEnd: /*#__PURE__*/jsx("span", {
351
+ className: "text-sm text-muted/50 px-1",
352
+ children: "OPTIONAL"
353
+ })
354
+ })
355
+ })]
356
+ }), /*#__PURE__*/jsxs(Field, {
357
+ label: " ",
358
+ inline: true,
359
+ plain: true,
360
+ children: [/*#__PURE__*/jsx(Controller, {
361
+ name: "".concat(field, ".required"),
362
+ children: /*#__PURE__*/jsx(Checkbox, {
363
+ label: "Required"
364
+ })
365
+ }), type !== DATA_TYPES.AVATAR && /*#__PURE__*/jsx(Controller, {
366
+ name: "".concat(field, ".multiple"),
367
+ children: /*#__PURE__*/jsx(Checkbox, {
368
+ label: "Multiple",
369
+ onChange: setMultiple
370
+ })
371
+ }), hasOptions && /*#__PURE__*/jsx(Controller, {
372
+ name: "".concat(field, ".allowCustom"),
373
+ children: /*#__PURE__*/jsx(Checkbox, {
374
+ label: "Allow custom value"
375
+ })
376
+ })]
377
+ }), multiple && /*#__PURE__*/jsxs(Fragment, {
378
+ children: [/*#__PURE__*/jsx(Controller, {
379
+ name: "".concat(field, ".minItems"),
380
+ children: /*#__PURE__*/jsx(Number, {
381
+ inline: true,
382
+ label: "Min items",
383
+ allowClear: true,
384
+ placeholder: "Minimum items...",
385
+ decorateEndShowWhenEmpty: true,
386
+ decorateEnd: /*#__PURE__*/jsx("span", {
387
+ className: "text-sm text-muted/50 px-1",
388
+ children: "OPTIONAL"
389
+ })
390
+ })
391
+ }), /*#__PURE__*/jsx(Controller, {
392
+ name: "".concat(field, ".maxItems"),
393
+ children: /*#__PURE__*/jsx(Number, {
394
+ inline: true,
395
+ label: "Max items",
396
+ allowClear: true,
397
+ placeholder: "Maximum items...",
398
+ decorateEndShowWhenEmpty: true,
399
+ decorateEnd: /*#__PURE__*/jsx("span", {
400
+ className: "text-sm text-muted/50 px-1",
401
+ children: "OPTIONAL"
402
+ })
403
+ })
404
+ })]
405
+ })]
406
+ })]
407
+ }, fieldId)
408
+ });
409
+ };
410
+
411
+ export { SchemaField };
@@ -25,13 +25,12 @@ var Form = function Form(_ref) {
25
25
  _ref$defaultValues = _ref.defaultValues,
26
26
  defaultValues = _ref$defaultValues === void 0 ? EMPTY_OBJECT : _ref$defaultValues,
27
27
  _ref$onSubmit = _ref.onSubmit,
28
- onSubmit = _ref$onSubmit === void 0 ? DEFAULT_SUBMIT : _ref$onSubmit,
28
+ _onSubmit = _ref$onSubmit === void 0 ? DEFAULT_SUBMIT : _ref$onSubmit,
29
29
  onChange = _ref.onChange,
30
30
  rest = _objectWithoutProperties(_ref, _excluded);
31
31
  var ref = useRef(null);
32
32
  var form = useForm({
33
33
  shouldFocusError: true,
34
- shouldUnregister: true,
35
34
  resolver: schema && yupResolver(schema),
36
35
  defaultValues: defaultValues
37
36
  });
@@ -66,7 +65,7 @@ var Form = function Form(_ref) {
66
65
  return handleReset();
67
66
  },
68
67
  submit: function submit() {
69
- return form.handleSubmit(onSubmit);
68
+ return form.handleSubmit(_onSubmit);
70
69
  },
71
70
  validate: function () {
72
71
  var _validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
@@ -96,12 +95,6 @@ var Form = function Form(_ref) {
96
95
  return form.reset(v);
97
96
  }, 50);
98
97
  },
99
- removeField: function removeField(field) {
100
- return form.unregister(field, {
101
- keepDefaultValue: false,
102
- keepValue: false
103
- });
104
- },
105
98
  setValue: function setValue(k, v) {
106
99
  return setTimeout(function () {
107
100
  return form.setValue(k, v, {
@@ -111,7 +104,7 @@ var Form = function Form(_ref) {
111
104
  }, 50);
112
105
  }
113
106
  };
114
- }, [onSubmit, form, form.formState, defaultValues]);
107
+ }, [_onSubmit, form, form.formState, defaultValues]);
115
108
  var onInvalid = useCallback(function (_, e) {
116
109
  var el = e.target;
117
110
  setTimeout(function () {
@@ -125,7 +118,10 @@ var Form = function Form(_ref) {
125
118
  onReset: function onReset() {
126
119
  return handleReset(defaultValues);
127
120
  },
128
- onSubmit: form.handleSubmit(onSubmit, onInvalid),
121
+ onSubmit: function onSubmit(e) {
122
+ e.stopPropagation();
123
+ void form.handleSubmit(_onSubmit, onInvalid)(e);
124
+ },
129
125
  "data-loading": form.formState.isSubmitting,
130
126
  className: "contents",
131
127
  autoComplete: "off"
package/dist/esm/index.js CHANGED
@@ -6,7 +6,7 @@ export { Form } from './form/Form.js';
6
6
  export { SchemaEditor } from './builder/SchemaEditor.js';
7
7
  export { useFileUploader } from './hooks/useFileUploader.js';
8
8
  export { useFormBuilder } from './hooks/useFormBuilder.js';
9
- export { DATA_TYPES } from './types/schema.js';
9
+ export { DATA_TYPES, SCHEMA_CUSTOM_LIST } from './types/schema.js';
10
10
  export { ArrayInput } from './input/ArrayInput.js';
11
11
  export { Checkbox } from './input/Checkbox.js';
12
12
  export { ColorInput } from './input/ColorInput.js';
@@ -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,16 +1,2 @@
1
- /// <reference types="react" />
2
- import { type Elements } from "@react-fabric/core/dist/types/types";
3
- import { DATA_TYPES, type FormSchema } from "../types/schema";
4
- interface Props {
5
- schemaDef: FormSchema;
6
- allowRemove?: boolean;
7
- acceptableTypes?: DATA_TYPES[];
8
- optionLists?: string[];
9
- /**
10
- * Footer actions
11
- */
12
- children?: Elements<JSX.Element> | Array<Elements<JSX.Element>>;
13
- onChange: (schema: FormSchema) => void;
14
- }
15
- export declare const SchemaEditor: ({ schemaDef, allowRemove, acceptableTypes, optionLists, children, onChange, }: Props) => import("react/jsx-runtime").JSX.Element;
16
- 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;
@@ -8,7 +8,6 @@ export interface FormRef<K extends KeyValue> {
8
8
  submit: () => void;
9
9
  validate: () => Promise<boolean>;
10
10
  getValues: () => K;
11
- removeField: (field: string) => void;
12
11
  setValue: (key: keyof K, value: AnyObject) => void;
13
12
  setValues: (values: K) => void;
14
13
  }
@@ -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,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.34",
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.34",
43
- "@react-fabric/date": "^1.0.0-beta.34",
44
- "@react-fabric/utilities": "^1.0.0-beta.34",
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": "dcd1c1b247b6597b168a0649d2b3a53463b9c37e"
64
+ "gitHead": "4a5cb87557f8c7c88cac937e3bd71fd6eeb07113"
65
65
  }