@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.
- package/dist/cjs/builder/SchemaEditor.js +41 -413
- package/dist/cjs/builder/components/AddSchemaFields.js +62 -0
- package/dist/cjs/builder/components/SchemaArrayForm.js +144 -0
- package/dist/cjs/builder/components/SchemaField.js +411 -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 +43 -415
- package/dist/esm/builder/components/AddSchemaFields.js +62 -0
- package/dist/esm/builder/components/SchemaArrayForm.js +144 -0
- package/dist/esm/builder/components/SchemaField.js +411 -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 +26 -0
- package/package.json +5 -5
- package/src/builder/SchemaEditor.tsx +17 -407
- package/src/builder/components/AddSchemaFields.tsx +74 -0
- package/src/builder/components/SchemaArrayForm.tsx +158 -0
- package/src/builder/components/SchemaField.tsx +432 -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 +30 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
4
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
5
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
6
|
+
var sortable = require('@dnd-kit/sortable');
|
|
7
|
+
var utilities = require('@dnd-kit/utilities');
|
|
8
|
+
var core = require('@react-fabric/core');
|
|
9
|
+
var utilities$1 = require('@react-fabric/utilities');
|
|
10
|
+
var classNames = require('classnames');
|
|
11
|
+
var react = require('react');
|
|
12
|
+
var Controller = require('../../form/Controller.js');
|
|
13
|
+
var ArrayInput = require('../../input/ArrayInput.js');
|
|
14
|
+
var Checkbox = require('../../input/Checkbox.js');
|
|
15
|
+
var DateInput = require('../../input/DateInput.js');
|
|
16
|
+
var Field = require('../../input/Field.js');
|
|
17
|
+
var Hidden = require('../../input/Hidden.js');
|
|
18
|
+
var Input = require('../../input/Input.js');
|
|
19
|
+
var Number = require('../../input/Number.js');
|
|
20
|
+
var Select = require('../../select/Select.js');
|
|
21
|
+
var schema = require('../../types/schema.js');
|
|
22
|
+
var jsxRuntime = require('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 ? utilities$1.EMPTY_ARRAY : _ref$optionLists,
|
|
36
|
+
dynamic = _ref.dynamic,
|
|
37
|
+
onTypeChange = _ref.onTypeChange,
|
|
38
|
+
acceptableTypes = _ref.acceptableTypes;
|
|
39
|
+
var _useState = react.useState(),
|
|
40
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
41
|
+
type = _useState2[0],
|
|
42
|
+
setType = _useState2[1];
|
|
43
|
+
var _useState3 = react.useState(false),
|
|
44
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
45
|
+
multiple = _useState4[0],
|
|
46
|
+
setMultiple = _useState4[1];
|
|
47
|
+
var _useState5 = react.useState(false),
|
|
48
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
49
|
+
hasOptions = _useState6[0],
|
|
50
|
+
setHasOptions = _useState6[1];
|
|
51
|
+
var _useState7 = react.useState(false),
|
|
52
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
53
|
+
customOptions = _useState8[0],
|
|
54
|
+
setCustomOptions = _useState8[1];
|
|
55
|
+
var SortableItem = react.useCallback(function (_ref2) {
|
|
56
|
+
var id = _ref2.id,
|
|
57
|
+
children = _ref2.children,
|
|
58
|
+
className = _ref2.className;
|
|
59
|
+
if (dynamic) {
|
|
60
|
+
var _useSortable = sortable.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__*/jsxRuntime.jsxs("div", {
|
|
70
|
+
className: className,
|
|
71
|
+
ref: setNodeRef,
|
|
72
|
+
style: {
|
|
73
|
+
transform: utilities.CSS.Transform.toString(transform),
|
|
74
|
+
transition: transition
|
|
75
|
+
},
|
|
76
|
+
children: [/*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsx("div", {
|
|
86
|
+
className: className,
|
|
87
|
+
children: children
|
|
88
|
+
});
|
|
89
|
+
}, [dynamic]);
|
|
90
|
+
// @ts-expect-error ignore
|
|
91
|
+
SortableItem.displayName = "SortableItem";
|
|
92
|
+
var _useOverlayService = core.useOverlayService(function (props) {
|
|
93
|
+
return /*#__PURE__*/jsxRuntime.jsxs(core.Modal, _objectSpread(_objectSpread({}, props), {}, {
|
|
94
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Content, {
|
|
95
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ArrayInput.ArrayInput, {
|
|
96
|
+
name: "".concat(field, ".options"),
|
|
97
|
+
onAdd: function onAdd() {
|
|
98
|
+
return String("");
|
|
99
|
+
},
|
|
100
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
101
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Footer, {
|
|
105
|
+
flex: true,
|
|
106
|
+
justify: "end",
|
|
107
|
+
className: "sticky bottom-0 border-t bg-base px-6 py-2",
|
|
108
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.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
|
+
react.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.SCHEMA_CUSTOM_LIST);
|
|
126
|
+
}, 10);
|
|
127
|
+
}, []);
|
|
128
|
+
var handleTypeChange = react.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 === schema.DATA_TYPES.AVATAR ? false : modelRef.multiple,
|
|
138
|
+
minItems: modelRef.minItems,
|
|
139
|
+
maxItems: modelRef.maxItems
|
|
140
|
+
};
|
|
141
|
+
if (type === schema.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 === schema.DATA_TYPES.DATE) {
|
|
148
|
+
reset = Object.assign(reset, {
|
|
149
|
+
type: "date"
|
|
150
|
+
});
|
|
151
|
+
} else if (type === schema.DATA_TYPES.NUMBER || type === schema.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 === schema.DATA_TYPES.AVATAR) {
|
|
159
|
+
setMultiple(false);
|
|
160
|
+
}
|
|
161
|
+
onTypeChange(reset);
|
|
162
|
+
setType(type);
|
|
163
|
+
}
|
|
164
|
+
}, []);
|
|
165
|
+
return /*#__PURE__*/jsxRuntime.jsx(SortableItem, {
|
|
166
|
+
id: fieldId,
|
|
167
|
+
className: "flex flex-nowrap gap-1 group/field",
|
|
168
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(core.Collapsable, {
|
|
169
|
+
open: defaultOpen,
|
|
170
|
+
className: "flex-1",
|
|
171
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
172
|
+
className: "flex flex-nowrap items-center",
|
|
173
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
174
|
+
className: "flex-1 truncate",
|
|
175
|
+
children: id
|
|
176
|
+
}), dynamic && /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
177
|
+
size: "sm",
|
|
178
|
+
color: "danger",
|
|
179
|
+
variant: "link",
|
|
180
|
+
"aria-label": "Delete",
|
|
181
|
+
stopPropagation: true,
|
|
182
|
+
icon: core.CoreIcons.trash,
|
|
183
|
+
onClick: onRemove,
|
|
184
|
+
className: "invisible group-hover/field:visible"
|
|
185
|
+
})]
|
|
186
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
187
|
+
className: "flex flex-col gap-1 pb-4",
|
|
188
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
189
|
+
name: "".concat(field, ".id"),
|
|
190
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Hidden.HiddenInput, {
|
|
191
|
+
hiddenValue: id
|
|
192
|
+
})
|
|
193
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
194
|
+
name: "".concat(field, ".datatype"),
|
|
195
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Select.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__*/jsxRuntime.jsx(Controller.Controller, {
|
|
205
|
+
name: "".concat(field, ".label"),
|
|
206
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {
|
|
207
|
+
inline: true,
|
|
208
|
+
label: "Label",
|
|
209
|
+
allowClear: true,
|
|
210
|
+
placeholder: "Label...",
|
|
211
|
+
decorateEndShowWhenEmpty: true,
|
|
212
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
213
|
+
className: "text-sm text-muted/50 px-1",
|
|
214
|
+
children: "OPTIONAL"
|
|
215
|
+
})
|
|
216
|
+
})
|
|
217
|
+
}), type === schema.DATA_TYPES.STRING && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
|
|
218
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
219
|
+
name: "".concat(field, ".regex"),
|
|
220
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {
|
|
221
|
+
inline: true,
|
|
222
|
+
label: "Regex validation",
|
|
223
|
+
allowClear: true,
|
|
224
|
+
placeholder: "Regex value...",
|
|
225
|
+
decorateEndShowWhenEmpty: true,
|
|
226
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
227
|
+
className: "text-sm text-muted/50 px-1",
|
|
228
|
+
children: "OPTIONAL"
|
|
229
|
+
})
|
|
230
|
+
})
|
|
231
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(Field.Field, {
|
|
232
|
+
inline: true,
|
|
233
|
+
label: "Option list",
|
|
234
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
235
|
+
name: "".concat(field, ".optionList"),
|
|
236
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Select.Select, {
|
|
237
|
+
allowClear: true,
|
|
238
|
+
options: [schema.SCHEMA_CUSTOM_LIST].concat(_toConsumableArray(optionLists)),
|
|
239
|
+
onChange: function onChange(v) {
|
|
240
|
+
return setCustomOptions(v === schema.SCHEMA_CUSTOM_LIST);
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
}), customOptions && /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
244
|
+
icon: core.CoreIcons.list,
|
|
245
|
+
"aria-label": "Custom options",
|
|
246
|
+
onClick: function onClick() {
|
|
247
|
+
void openOptionModal();
|
|
248
|
+
}
|
|
249
|
+
})]
|
|
250
|
+
}), OptionModal]
|
|
251
|
+
}), type === schema.DATA_TYPES.FILE && /*#__PURE__*/jsxRuntime.jsx(react.Fragment, {
|
|
252
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
253
|
+
name: "".concat(field, ".accept"),
|
|
254
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {
|
|
255
|
+
inline: true,
|
|
256
|
+
label: "Accept types",
|
|
257
|
+
allowClear: true,
|
|
258
|
+
placeholder: "Accept value...",
|
|
259
|
+
decorateEndShowWhenEmpty: true,
|
|
260
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
261
|
+
className: "text-sm text-muted/50 px-1",
|
|
262
|
+
children: "OPTIONAL"
|
|
263
|
+
})
|
|
264
|
+
})
|
|
265
|
+
})
|
|
266
|
+
}), [schema.DATA_TYPES.NUMBER, schema.DATA_TYPES.RANGE].includes(type) && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
|
|
267
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
268
|
+
name: "".concat(field, ".min"),
|
|
269
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
270
|
+
inline: true,
|
|
271
|
+
label: "Min value",
|
|
272
|
+
allowClear: true,
|
|
273
|
+
placeholder: "Minimum value...",
|
|
274
|
+
decorateEndShowWhenEmpty: true,
|
|
275
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
276
|
+
className: "text-sm text-muted/50 px-1",
|
|
277
|
+
children: "OPTIONAL"
|
|
278
|
+
})
|
|
279
|
+
})
|
|
280
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
281
|
+
name: "".concat(field, ".max"),
|
|
282
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
283
|
+
inline: true,
|
|
284
|
+
label: "Max value",
|
|
285
|
+
allowClear: true,
|
|
286
|
+
placeholder: "Maximum value...",
|
|
287
|
+
decorateEndShowWhenEmpty: true,
|
|
288
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
289
|
+
className: "text-sm text-muted/50 px-1",
|
|
290
|
+
children: "OPTIONAL"
|
|
291
|
+
})
|
|
292
|
+
})
|
|
293
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
294
|
+
name: "".concat(field, ".step"),
|
|
295
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
296
|
+
inline: true,
|
|
297
|
+
label: "Step value",
|
|
298
|
+
allowClear: true,
|
|
299
|
+
placeholder: "Step value...",
|
|
300
|
+
decorateEndShowWhenEmpty: true,
|
|
301
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
302
|
+
className: "text-sm text-muted/50 px-1",
|
|
303
|
+
children: "OPTIONAL"
|
|
304
|
+
})
|
|
305
|
+
})
|
|
306
|
+
})]
|
|
307
|
+
}), type === schema.DATA_TYPES.DATE && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
|
|
308
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Field.Field, {
|
|
309
|
+
inline: true,
|
|
310
|
+
label: "Type",
|
|
311
|
+
plain: true,
|
|
312
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
313
|
+
name: "".concat(field, ".type"),
|
|
314
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(core.ToggleButtonGroup, {
|
|
315
|
+
value: "",
|
|
316
|
+
fullWidth: true,
|
|
317
|
+
className: "flex-1",
|
|
318
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
319
|
+
className: "flex-1",
|
|
320
|
+
value: "date",
|
|
321
|
+
children: "Date"
|
|
322
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
323
|
+
className: "flex-1",
|
|
324
|
+
value: "datetime",
|
|
325
|
+
children: "Date Time"
|
|
326
|
+
})]
|
|
327
|
+
})
|
|
328
|
+
})
|
|
329
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
330
|
+
name: "".concat(field, ".min"),
|
|
331
|
+
children: /*#__PURE__*/jsxRuntime.jsx(DateInput.DateInput, {
|
|
332
|
+
inline: true,
|
|
333
|
+
label: "Min value",
|
|
334
|
+
allowClear: true,
|
|
335
|
+
placeholder: "Minimum value...",
|
|
336
|
+
decorateEndShowWhenEmpty: true,
|
|
337
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
338
|
+
className: "text-sm text-muted/50 px-1",
|
|
339
|
+
children: "OPTIONAL"
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
343
|
+
name: "".concat(field, ".max"),
|
|
344
|
+
children: /*#__PURE__*/jsxRuntime.jsx(DateInput.DateInput, {
|
|
345
|
+
inline: true,
|
|
346
|
+
label: "Max value",
|
|
347
|
+
allowClear: true,
|
|
348
|
+
placeholder: "Maximum value...",
|
|
349
|
+
decorateEndShowWhenEmpty: true,
|
|
350
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
351
|
+
className: "text-sm text-muted/50 px-1",
|
|
352
|
+
children: "OPTIONAL"
|
|
353
|
+
})
|
|
354
|
+
})
|
|
355
|
+
})]
|
|
356
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(Field.Field, {
|
|
357
|
+
label: " ",
|
|
358
|
+
inline: true,
|
|
359
|
+
plain: true,
|
|
360
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
361
|
+
name: "".concat(field, ".required"),
|
|
362
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Checkbox.Checkbox, {
|
|
363
|
+
label: "Required"
|
|
364
|
+
})
|
|
365
|
+
}), type !== schema.DATA_TYPES.AVATAR && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
366
|
+
name: "".concat(field, ".multiple"),
|
|
367
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Checkbox.Checkbox, {
|
|
368
|
+
label: "Multiple",
|
|
369
|
+
onChange: setMultiple
|
|
370
|
+
})
|
|
371
|
+
}), hasOptions && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
372
|
+
name: "".concat(field, ".allowCustom"),
|
|
373
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Checkbox.Checkbox, {
|
|
374
|
+
label: "Allow custom value"
|
|
375
|
+
})
|
|
376
|
+
})]
|
|
377
|
+
}), multiple && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
|
|
378
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
379
|
+
name: "".concat(field, ".minItems"),
|
|
380
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
381
|
+
inline: true,
|
|
382
|
+
label: "Min items",
|
|
383
|
+
allowClear: true,
|
|
384
|
+
placeholder: "Minimum items...",
|
|
385
|
+
decorateEndShowWhenEmpty: true,
|
|
386
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
387
|
+
className: "text-sm text-muted/50 px-1",
|
|
388
|
+
children: "OPTIONAL"
|
|
389
|
+
})
|
|
390
|
+
})
|
|
391
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
392
|
+
name: "".concat(field, ".maxItems"),
|
|
393
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
394
|
+
inline: true,
|
|
395
|
+
label: "Max items",
|
|
396
|
+
allowClear: true,
|
|
397
|
+
placeholder: "Maximum items...",
|
|
398
|
+
decorateEndShowWhenEmpty: true,
|
|
399
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.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
|
+
exports.SchemaField = SchemaField;
|
package/dist/cjs/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 ? utilities.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 = react.useRef(null);
|
|
32
32
|
var form = reactHookForm.useForm({
|
|
33
33
|
shouldFocusError: true,
|
|
34
|
-
shouldUnregister: true,
|
|
35
34
|
resolver: schema && yup.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 = react.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/cjs/index.js
CHANGED
|
@@ -38,6 +38,7 @@ exports.SchemaEditor = SchemaEditor.SchemaEditor;
|
|
|
38
38
|
exports.useFileUploader = useFileUploader.useFileUploader;
|
|
39
39
|
exports.useFormBuilder = useFormBuilder.useFormBuilder;
|
|
40
40
|
exports.DATA_TYPES = schema.DATA_TYPES;
|
|
41
|
+
exports.SCHEMA_CUSTOM_LIST = schema.SCHEMA_CUSTOM_LIST;
|
|
41
42
|
exports.ArrayInput = ArrayInput.ArrayInput;
|
|
42
43
|
exports.Checkbox = Checkbox.Checkbox;
|
|
43
44
|
exports.ColorInput = ColorInput.ColorInput;
|
package/dist/cjs/types/schema.js
CHANGED