@react-fabric/form 1.0.0-beta.34 → 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.
- package/dist/cjs/builder/SchemaEditor.js +46 -413
- package/dist/cjs/builder/components/AddSchemaFields.js +62 -0
- package/dist/cjs/builder/components/SchemaArrayForm.js +143 -0
- package/dist/cjs/builder/components/SchemaField.js +413 -0
- package/dist/cjs/form/Form.js +7 -11
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/types/schema.js +2 -0
- package/dist/esm/builder/SchemaEditor.js +48 -415
- package/dist/esm/builder/components/AddSchemaFields.js +62 -0
- package/dist/esm/builder/components/SchemaArrayForm.js +143 -0
- package/dist/esm/builder/components/SchemaField.js +413 -0
- package/dist/esm/form/Form.js +7 -11
- package/dist/esm/index.js +1 -1
- package/dist/esm/types/schema.js +2 -1
- package/dist/types/builder/SchemaEditor.d.ts +2 -16
- package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
- package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
- package/dist/types/builder/components/SchemaField.d.ts +10 -0
- package/dist/types/form/Form.d.ts +0 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types/schema.d.ts +27 -0
- package/package.json +5 -5
- package/src/builder/SchemaEditor.tsx +21 -406
- package/src/builder/components/AddSchemaFields.tsx +74 -0
- package/src/builder/components/SchemaArrayForm.tsx +158 -0
- package/src/builder/components/SchemaField.tsx +435 -0
- package/src/form/Form.tsx +4 -5
- package/src/index.ts +6 -1
- package/src/input/ArrayInput.tsx +1 -0
- package/src/types/schema.ts +31 -0
|
@@ -0,0 +1,413 @@
|
|
|
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: id,
|
|
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
|
+
}, [id]);
|
|
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
|
+
title: "".concat(id, " Options")
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
})]
|
|
252
|
+
}), OptionModal]
|
|
253
|
+
}), type === DATA_TYPES.FILE && /*#__PURE__*/jsx(Fragment, {
|
|
254
|
+
children: /*#__PURE__*/jsx(Controller, {
|
|
255
|
+
name: "".concat(field, ".accept"),
|
|
256
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
257
|
+
inline: true,
|
|
258
|
+
label: "Accept types",
|
|
259
|
+
allowClear: true,
|
|
260
|
+
placeholder: "Accept value...",
|
|
261
|
+
decorateEndShowWhenEmpty: true,
|
|
262
|
+
decorateEnd: /*#__PURE__*/jsx("span", {
|
|
263
|
+
className: "text-sm text-muted/50 px-1",
|
|
264
|
+
children: "OPTIONAL"
|
|
265
|
+
})
|
|
266
|
+
})
|
|
267
|
+
})
|
|
268
|
+
}), [DATA_TYPES.NUMBER, DATA_TYPES.RANGE].includes(type) && /*#__PURE__*/jsxs(Fragment, {
|
|
269
|
+
children: [/*#__PURE__*/jsx(Controller, {
|
|
270
|
+
name: "".concat(field, ".min"),
|
|
271
|
+
children: /*#__PURE__*/jsx(Number, {
|
|
272
|
+
inline: true,
|
|
273
|
+
label: "Min value",
|
|
274
|
+
allowClear: true,
|
|
275
|
+
placeholder: "Minimum value...",
|
|
276
|
+
decorateEndShowWhenEmpty: true,
|
|
277
|
+
decorateEnd: /*#__PURE__*/jsx("span", {
|
|
278
|
+
className: "text-sm text-muted/50 px-1",
|
|
279
|
+
children: "OPTIONAL"
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
}), /*#__PURE__*/jsx(Controller, {
|
|
283
|
+
name: "".concat(field, ".max"),
|
|
284
|
+
children: /*#__PURE__*/jsx(Number, {
|
|
285
|
+
inline: true,
|
|
286
|
+
label: "Max value",
|
|
287
|
+
allowClear: true,
|
|
288
|
+
placeholder: "Maximum value...",
|
|
289
|
+
decorateEndShowWhenEmpty: true,
|
|
290
|
+
decorateEnd: /*#__PURE__*/jsx("span", {
|
|
291
|
+
className: "text-sm text-muted/50 px-1",
|
|
292
|
+
children: "OPTIONAL"
|
|
293
|
+
})
|
|
294
|
+
})
|
|
295
|
+
}), /*#__PURE__*/jsx(Controller, {
|
|
296
|
+
name: "".concat(field, ".step"),
|
|
297
|
+
children: /*#__PURE__*/jsx(Number, {
|
|
298
|
+
inline: true,
|
|
299
|
+
label: "Step value",
|
|
300
|
+
allowClear: true,
|
|
301
|
+
placeholder: "Step value...",
|
|
302
|
+
decorateEndShowWhenEmpty: true,
|
|
303
|
+
decorateEnd: /*#__PURE__*/jsx("span", {
|
|
304
|
+
className: "text-sm text-muted/50 px-1",
|
|
305
|
+
children: "OPTIONAL"
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
})]
|
|
309
|
+
}), type === DATA_TYPES.DATE && /*#__PURE__*/jsxs(Fragment, {
|
|
310
|
+
children: [/*#__PURE__*/jsx(Field, {
|
|
311
|
+
inline: true,
|
|
312
|
+
label: "Type",
|
|
313
|
+
plain: true,
|
|
314
|
+
children: /*#__PURE__*/jsx(Controller, {
|
|
315
|
+
name: "".concat(field, ".type"),
|
|
316
|
+
children: /*#__PURE__*/jsxs(ToggleButtonGroup, {
|
|
317
|
+
value: "",
|
|
318
|
+
fullWidth: true,
|
|
319
|
+
className: "flex-1",
|
|
320
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
321
|
+
className: "flex-1",
|
|
322
|
+
value: "date",
|
|
323
|
+
children: "Date"
|
|
324
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
325
|
+
className: "flex-1",
|
|
326
|
+
value: "datetime",
|
|
327
|
+
children: "Date Time"
|
|
328
|
+
})]
|
|
329
|
+
})
|
|
330
|
+
})
|
|
331
|
+
}), /*#__PURE__*/jsx(Controller, {
|
|
332
|
+
name: "".concat(field, ".min"),
|
|
333
|
+
children: /*#__PURE__*/jsx(DateInput, {
|
|
334
|
+
inline: true,
|
|
335
|
+
label: "Min value",
|
|
336
|
+
allowClear: true,
|
|
337
|
+
placeholder: "Minimum value...",
|
|
338
|
+
decorateEndShowWhenEmpty: true,
|
|
339
|
+
decorateEnd: /*#__PURE__*/jsx("span", {
|
|
340
|
+
className: "text-sm text-muted/50 px-1",
|
|
341
|
+
children: "OPTIONAL"
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
}), /*#__PURE__*/jsx(Controller, {
|
|
345
|
+
name: "".concat(field, ".max"),
|
|
346
|
+
children: /*#__PURE__*/jsx(DateInput, {
|
|
347
|
+
inline: true,
|
|
348
|
+
label: "Max value",
|
|
349
|
+
allowClear: true,
|
|
350
|
+
placeholder: "Maximum value...",
|
|
351
|
+
decorateEndShowWhenEmpty: true,
|
|
352
|
+
decorateEnd: /*#__PURE__*/jsx("span", {
|
|
353
|
+
className: "text-sm text-muted/50 px-1",
|
|
354
|
+
children: "OPTIONAL"
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
})]
|
|
358
|
+
}), /*#__PURE__*/jsxs(Field, {
|
|
359
|
+
label: " ",
|
|
360
|
+
inline: true,
|
|
361
|
+
plain: true,
|
|
362
|
+
children: [/*#__PURE__*/jsx(Controller, {
|
|
363
|
+
name: "".concat(field, ".required"),
|
|
364
|
+
children: /*#__PURE__*/jsx(Checkbox, {
|
|
365
|
+
label: "Required"
|
|
366
|
+
})
|
|
367
|
+
}), type !== DATA_TYPES.AVATAR && /*#__PURE__*/jsx(Controller, {
|
|
368
|
+
name: "".concat(field, ".multiple"),
|
|
369
|
+
children: /*#__PURE__*/jsx(Checkbox, {
|
|
370
|
+
label: "Multiple",
|
|
371
|
+
onChange: setMultiple
|
|
372
|
+
})
|
|
373
|
+
}), hasOptions && /*#__PURE__*/jsx(Controller, {
|
|
374
|
+
name: "".concat(field, ".allowCustom"),
|
|
375
|
+
children: /*#__PURE__*/jsx(Checkbox, {
|
|
376
|
+
label: "Allow custom value"
|
|
377
|
+
})
|
|
378
|
+
})]
|
|
379
|
+
}), multiple && /*#__PURE__*/jsxs(Fragment, {
|
|
380
|
+
children: [/*#__PURE__*/jsx(Controller, {
|
|
381
|
+
name: "".concat(field, ".minItems"),
|
|
382
|
+
children: /*#__PURE__*/jsx(Number, {
|
|
383
|
+
inline: true,
|
|
384
|
+
label: "Min items",
|
|
385
|
+
allowClear: true,
|
|
386
|
+
placeholder: "Minimum items...",
|
|
387
|
+
decorateEndShowWhenEmpty: true,
|
|
388
|
+
decorateEnd: /*#__PURE__*/jsx("span", {
|
|
389
|
+
className: "text-sm text-muted/50 px-1",
|
|
390
|
+
children: "OPTIONAL"
|
|
391
|
+
})
|
|
392
|
+
})
|
|
393
|
+
}), /*#__PURE__*/jsx(Controller, {
|
|
394
|
+
name: "".concat(field, ".maxItems"),
|
|
395
|
+
children: /*#__PURE__*/jsx(Number, {
|
|
396
|
+
inline: true,
|
|
397
|
+
label: "Max items",
|
|
398
|
+
allowClear: true,
|
|
399
|
+
placeholder: "Maximum items...",
|
|
400
|
+
decorateEndShowWhenEmpty: true,
|
|
401
|
+
decorateEnd: /*#__PURE__*/jsx("span", {
|
|
402
|
+
className: "text-sm text-muted/50 px-1",
|
|
403
|
+
children: "OPTIONAL"
|
|
404
|
+
})
|
|
405
|
+
})
|
|
406
|
+
})]
|
|
407
|
+
})]
|
|
408
|
+
})]
|
|
409
|
+
}, fieldId)
|
|
410
|
+
});
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
export { SchemaField };
|
package/dist/esm/form/Form.js
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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
|
-
}, [
|
|
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:
|
|
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';
|
package/dist/esm/types/schema.js
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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, onSubmit, onChange, }: 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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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,28 @@ 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
|
+
onSubmit?: (schema: FormSchema) => void;
|
|
104
|
+
}
|
|
78
105
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/form",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
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.
|
|
43
|
-
"@react-fabric/date": "^1.0.0-beta.
|
|
44
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
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": "
|
|
64
|
+
"gitHead": "91a7cce216e21cbc6406226d8c3f56a1a26e410a"
|
|
65
65
|
}
|