@react-fabric/form 1.0.0-beta.31 → 1.0.0-beta.33
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/FileField.js +4 -4
- package/dist/cjs/builder/FormField.js +41 -31
- package/dist/cjs/builder/SchemaEditor.js +428 -0
- package/dist/cjs/form/Controller.js +1 -1
- package/dist/cjs/form/Form.js +3 -4
- package/dist/cjs/hooks/useFormBuilder.js +27 -15
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/input/Checkbox.js +4 -3
- package/dist/cjs/input/DateInput.js +183 -0
- package/dist/cjs/input/Field.js +1 -1
- package/dist/cjs/input/{Range.js → RangeSlider.js} +2 -2
- package/dist/cjs/input/Switch.js +4 -3
- package/dist/cjs/internal/Field.module.css +1 -1
- package/dist/cjs/internal/InputWrapper.js +6 -4
- package/dist/cjs/types/schema.js +40 -0
- package/dist/esm/builder/FileField.js +4 -4
- package/dist/esm/builder/FormField.js +41 -31
- package/dist/esm/builder/SchemaEditor.js +428 -0
- package/dist/esm/form/Controller.js +1 -1
- package/dist/esm/form/Form.js +4 -5
- package/dist/esm/hooks/useFormBuilder.js +25 -13
- package/dist/esm/index.js +4 -1
- package/dist/esm/input/Checkbox.js +4 -3
- package/dist/esm/input/DateInput.js +183 -0
- package/dist/esm/input/Field.js +1 -1
- package/dist/esm/input/{Range.js → RangeSlider.js} +2 -2
- package/dist/esm/input/Switch.js +4 -3
- package/dist/esm/internal/Field.module.css +1 -1
- package/dist/esm/internal/InputWrapper.js +6 -4
- package/dist/esm/types/schema.js +40 -0
- package/dist/types/builder/FileField.d.ts +2 -2
- package/dist/types/builder/FormField.d.ts +3 -1
- package/dist/types/builder/SchemaEditor.d.ts +10 -0
- package/dist/types/form/Controller.d.ts +1 -1
- package/dist/types/form/Form.d.ts +5 -1
- package/dist/types/hooks/useFormBuilder.d.ts +3 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/input/Checkbox.d.ts +4 -3
- package/dist/types/input/DateInput.d.ts +19 -0
- package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +1 -1
- package/dist/types/input/Switch.d.ts +1 -1
- package/dist/types/internal/InputWrapper.d.ts +1 -1
- package/dist/types/types/index.d.ts +6 -2
- package/dist/types/types/schema.d.ts +52 -33
- package/package.json +5 -4
- package/src/builder/FileField.tsx +5 -4
- package/src/builder/FormField.tsx +42 -29
- package/src/builder/SchemaEditor.tsx +441 -0
- package/src/form/Controller.tsx +2 -2
- package/src/form/Form.tsx +6 -4
- package/src/hooks/useFormBuilder.tsx +29 -15
- package/src/index.ts +5 -2
- package/src/input/Checkbox.tsx +4 -3
- package/src/input/DateInput.tsx +248 -0
- package/src/input/Field.tsx +2 -1
- package/src/input/{Range.tsx → RangeSlider.tsx} +1 -1
- package/src/input/Switch.tsx +2 -0
- package/src/internal/Field.module.css +12 -1
- package/src/internal/InputWrapper.tsx +7 -2
- package/src/types/index.ts +8 -4
- package/src/types/schema.ts +65 -41
|
@@ -12,7 +12,7 @@ var Field = require('../input/Field.js');
|
|
|
12
12
|
var Hidden = require('../input/Hidden.js');
|
|
13
13
|
var jsxRuntime = require('react/jsx-runtime');
|
|
14
14
|
|
|
15
|
-
var _excluded = ["uploadHandler", "inline", "label", "accept", "
|
|
15
|
+
var _excluded = ["uploadHandler", "inline", "label", "accept", "value", "fileUrl", "multiple"];
|
|
16
16
|
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; }
|
|
17
17
|
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; }
|
|
18
18
|
var FileField = function FileField(_ref) {
|
|
@@ -20,9 +20,9 @@ var FileField = function FileField(_ref) {
|
|
|
20
20
|
inline = _ref.inline,
|
|
21
21
|
label = _ref.label,
|
|
22
22
|
accept = _ref.accept,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
value = _ref.value;
|
|
24
|
+
_ref.fileUrl;
|
|
25
|
+
var multiple = _ref.multiple,
|
|
26
26
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
27
27
|
var _useFileUploader = useFileUploader.useFileUploader( /*#__PURE__*/function () {
|
|
28
28
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(data, config) {
|
|
@@ -2,22 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
4
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
5
|
+
var utilities = require('@react-fabric/utilities');
|
|
5
6
|
var react = require('react');
|
|
6
7
|
var reactI18next = require('react-i18next');
|
|
7
8
|
var Controller = require('../form/Controller.js');
|
|
8
9
|
var ArrayInput = require('../input/ArrayInput.js');
|
|
9
10
|
var AvatarInput = require('../input/AvatarInput.js');
|
|
10
11
|
var ColorInput = require('../input/ColorInput.js');
|
|
12
|
+
var DateInput = require('../input/DateInput.js');
|
|
11
13
|
var Input = require('../input/Input.js');
|
|
12
14
|
var Number = require('../input/Number.js');
|
|
13
|
-
var
|
|
15
|
+
var RangeSlider = require('../input/RangeSlider.js');
|
|
14
16
|
var Switch = require('../input/Switch.js');
|
|
15
17
|
var Textarea = require('../input/Textarea.js');
|
|
16
18
|
var Select = require('../select/Select.js');
|
|
19
|
+
var schema = require('../types/schema.js');
|
|
17
20
|
var FileField = require('./FileField.js');
|
|
18
21
|
var jsxRuntime = require('react/jsx-runtime');
|
|
19
22
|
|
|
20
|
-
var _excluded = ["id", "label", "required", "inline", "prefix", "autoFocus", "
|
|
23
|
+
var _excluded = ["id", "label", "required", "inline", "prefix", "autoFocus", "optionLists", "fileUrl", "uploadHandler"];
|
|
21
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; }
|
|
22
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; }
|
|
23
26
|
var FormField = function FormField(_ref) {
|
|
@@ -26,9 +29,9 @@ var FormField = function FormField(_ref) {
|
|
|
26
29
|
required = _ref.required,
|
|
27
30
|
inline = _ref.inline,
|
|
28
31
|
prefix = _ref.prefix,
|
|
29
|
-
autoFocus = _ref.autoFocus
|
|
30
|
-
_ref.
|
|
31
|
-
|
|
32
|
+
autoFocus = _ref.autoFocus,
|
|
33
|
+
optionLists = _ref.optionLists,
|
|
34
|
+
fileUrl = _ref.fileUrl,
|
|
32
35
|
uploadHandler = _ref.uploadHandler,
|
|
33
36
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
34
37
|
var _useTranslation = reactI18next.useTranslation(),
|
|
@@ -36,48 +39,55 @@ var FormField = function FormField(_ref) {
|
|
|
36
39
|
var fieldName = react.useMemo(function () {
|
|
37
40
|
return [prefix, id].filter(Boolean).join(".");
|
|
38
41
|
}, [id, prefix]);
|
|
42
|
+
var hasOptions = react.useMemo(function () {
|
|
43
|
+
var _rest$optionList;
|
|
44
|
+
return rest.datatype === schema.DATA_TYPES.STRING && (rest.optionList === "--CUSTOM--" && !utilities.isEmpty(rest.options) || !utilities.isEmpty(optionLists === null || optionLists === void 0 ? void 0 : optionLists[(_rest$optionList = rest.optionList) !== null && _rest$optionList !== void 0 ? _rest$optionList : ""]));
|
|
45
|
+
}, [rest]);
|
|
39
46
|
var E = react.useMemo(function () {
|
|
40
|
-
if (rest.datatype ===
|
|
41
|
-
if (rest.datatype ===
|
|
42
|
-
if (rest.datatype ===
|
|
43
|
-
if (rest.datatype ===
|
|
44
|
-
if (rest.datatype ===
|
|
45
|
-
if (rest.datatype ===
|
|
47
|
+
if (rest.datatype === schema.DATA_TYPES.NUMBER) return Number.Number;
|
|
48
|
+
if (rest.datatype === schema.DATA_TYPES.RANGE) return RangeSlider.RangeSlider;
|
|
49
|
+
if (rest.datatype === schema.DATA_TYPES.BOOL) return Switch.Switch;
|
|
50
|
+
if (rest.datatype === schema.DATA_TYPES.TEXT) return Textarea.Textarea;
|
|
51
|
+
if (rest.datatype === schema.DATA_TYPES.DATE) return DateInput.DateInput;
|
|
52
|
+
if (rest.datatype === schema.DATA_TYPES.COLOR) return ColorInput.ColorInput;
|
|
53
|
+
if (hasOptions) return Select.Select;
|
|
46
54
|
return Input.Input;
|
|
47
|
-
}, [rest.datatype]);
|
|
55
|
+
}, [rest.datatype, hasOptions]);
|
|
48
56
|
var props = react.useMemo(function () {
|
|
49
|
-
var _rest$step, _rest$
|
|
50
|
-
if (rest.datatype ===
|
|
57
|
+
var _rest$step, _rest$min, _rest$max, _rest$step2, _optionLists, _rest$optionList2;
|
|
58
|
+
if (rest.datatype === schema.DATA_TYPES.NUMBER) return {
|
|
51
59
|
min: rest.min,
|
|
52
60
|
max: rest.max,
|
|
53
61
|
step: (_rest$step = rest.step) !== null && _rest$step !== void 0 ? _rest$step : 1
|
|
54
62
|
};
|
|
55
|
-
if (rest.datatype ===
|
|
56
|
-
min: rest.min,
|
|
57
|
-
max: rest.max,
|
|
58
|
-
step: (_rest$step2 = rest.step) !== null && _rest$step2 !== void 0 ? _rest$step2 : 0.1
|
|
59
|
-
};
|
|
60
|
-
if (rest.datatype === "range") return {
|
|
63
|
+
if (rest.datatype === schema.DATA_TYPES.RANGE) return {
|
|
61
64
|
min: (_rest$min = rest.min) !== null && _rest$min !== void 0 ? _rest$min : 1,
|
|
62
65
|
max: (_rest$max = rest.max) !== null && _rest$max !== void 0 ? _rest$max : 99,
|
|
63
|
-
step: (_rest$
|
|
66
|
+
step: (_rest$step2 = rest.step) !== null && _rest$step2 !== void 0 ? _rest$step2 : 1,
|
|
64
67
|
showValue: true,
|
|
65
68
|
showLabels: true
|
|
66
69
|
};
|
|
67
|
-
if (rest.datatype ===
|
|
70
|
+
if (rest.datatype === schema.DATA_TYPES.DATE) return {
|
|
71
|
+
min: rest.min,
|
|
72
|
+
max: rest.max,
|
|
73
|
+
type: rest.type
|
|
74
|
+
};
|
|
75
|
+
if (rest.datatype === schema.DATA_TYPES.TEXT) return {
|
|
68
76
|
rows: 3
|
|
69
77
|
};
|
|
70
|
-
if (rest.datatype ===
|
|
78
|
+
if (rest.datatype === schema.DATA_TYPES.COLOR) return {
|
|
71
79
|
showPicker: true
|
|
72
80
|
};
|
|
73
|
-
if (rest.datatype ===
|
|
74
|
-
options: rest.options,
|
|
81
|
+
if (rest.datatype === schema.DATA_TYPES.STRING && hasOptions) return _objectSpread({
|
|
75
82
|
multiple: rest.multiple,
|
|
83
|
+
allowCreate: rest.allowCustom,
|
|
76
84
|
searchable: true
|
|
77
|
-
}
|
|
85
|
+
}, (_optionLists = optionLists === null || optionLists === void 0 ? void 0 : optionLists[(_rest$optionList2 = rest.optionList) !== null && _rest$optionList2 !== void 0 ? _rest$optionList2 : ""]) !== null && _optionLists !== void 0 ? _optionLists : {
|
|
86
|
+
options: rest.options
|
|
87
|
+
});
|
|
78
88
|
return {};
|
|
79
|
-
}, [rest]);
|
|
80
|
-
if (rest.datatype ===
|
|
89
|
+
}, [rest, hasOptions, optionLists]);
|
|
90
|
+
if (rest.datatype === schema.DATA_TYPES.AVATAR) return uploadHandler && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
81
91
|
name: fieldName,
|
|
82
92
|
children: /*#__PURE__*/jsxRuntime.jsx(AvatarInput.AvatarInput, {
|
|
83
93
|
uploadHandler: uploadHandler,
|
|
@@ -85,7 +95,7 @@ var FormField = function FormField(_ref) {
|
|
|
85
95
|
name: fieldName
|
|
86
96
|
})
|
|
87
97
|
});
|
|
88
|
-
if (rest.datatype ===
|
|
98
|
+
if (rest.datatype === schema.DATA_TYPES.FILE) return uploadHandler && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
89
99
|
name: fieldName,
|
|
90
100
|
children: /*#__PURE__*/jsxRuntime.jsx(FileField.FileField, _objectSpread({
|
|
91
101
|
uploadHandler: uploadHandler,
|
|
@@ -94,12 +104,12 @@ var FormField = function FormField(_ref) {
|
|
|
94
104
|
id: id
|
|
95
105
|
}, rest))
|
|
96
106
|
});
|
|
97
|
-
return rest.multiple && !
|
|
107
|
+
return rest.multiple && !hasOptions ? /*#__PURE__*/jsxRuntime.jsx(ArrayInput.ArrayInput, {
|
|
98
108
|
name: fieldName,
|
|
99
109
|
label: t(label, label),
|
|
100
110
|
required: required,
|
|
101
111
|
onAdd: function onAdd() {
|
|
102
|
-
return "";
|
|
112
|
+
return String("");
|
|
103
113
|
},
|
|
104
114
|
children: /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
105
115
|
children: /*#__PURE__*/jsxRuntime.jsx(E, _objectSpread({}, props))
|
|
@@ -0,0 +1,428 @@
|
|
|
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 core = require('@react-fabric/core');
|
|
7
|
+
var utilities = require('@react-fabric/utilities');
|
|
8
|
+
var react = require('react');
|
|
9
|
+
var Controller = require('../form/Controller.js');
|
|
10
|
+
var Form = require('../form/Form.js');
|
|
11
|
+
var ArrayInput = require('../input/ArrayInput.js');
|
|
12
|
+
var Checkbox = require('../input/Checkbox.js');
|
|
13
|
+
var DateInput = require('../input/DateInput.js');
|
|
14
|
+
var Field = require('../input/Field.js');
|
|
15
|
+
var Input = require('../input/Input.js');
|
|
16
|
+
var Number = require('../input/Number.js');
|
|
17
|
+
var Select = require('../select/Select.js');
|
|
18
|
+
var schema = require('../types/schema.js');
|
|
19
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
20
|
+
|
|
21
|
+
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; }
|
|
22
|
+
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; }
|
|
23
|
+
var CUSTOM_LIST = "--CUSTOM--";
|
|
24
|
+
var SchemaField = function SchemaField(_ref) {
|
|
25
|
+
var field = _ref.field,
|
|
26
|
+
getModel = _ref.getModel,
|
|
27
|
+
_ref$optionLists = _ref.optionLists,
|
|
28
|
+
optionLists = _ref$optionLists === void 0 ? utilities.EMPTY_ARRAY : _ref$optionLists,
|
|
29
|
+
allowRemove = _ref.allowRemove,
|
|
30
|
+
onTypeChange = _ref.onTypeChange,
|
|
31
|
+
acceptableTypes = _ref.acceptableTypes;
|
|
32
|
+
var _useState = react.useState(),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
+
type = _useState2[0],
|
|
35
|
+
setType = _useState2[1];
|
|
36
|
+
var _useState3 = react.useState(false),
|
|
37
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
38
|
+
multiple = _useState4[0],
|
|
39
|
+
setMultiple = _useState4[1];
|
|
40
|
+
var _useState5 = react.useState(false),
|
|
41
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
42
|
+
hasOptions = _useState6[0],
|
|
43
|
+
setHasOptions = _useState6[1];
|
|
44
|
+
var _useState7 = react.useState(false),
|
|
45
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
46
|
+
customOptions = _useState8[0],
|
|
47
|
+
setCustomOptions = _useState8[1];
|
|
48
|
+
var _useOverlayService = core.useOverlayService(function (props) {
|
|
49
|
+
return /*#__PURE__*/jsxRuntime.jsxs(core.Modal, _objectSpread(_objectSpread({}, props), {}, {
|
|
50
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Content, {
|
|
51
|
+
children: /*#__PURE__*/jsxRuntime.jsx(ArrayInput.ArrayInput, {
|
|
52
|
+
name: "".concat(field, ".options"),
|
|
53
|
+
onAdd: function onAdd() {
|
|
54
|
+
return String("");
|
|
55
|
+
},
|
|
56
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
57
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Footer, {
|
|
61
|
+
flex: true,
|
|
62
|
+
justify: "end",
|
|
63
|
+
className: "sticky bottom-0 border-t bg-base px-6 py-2",
|
|
64
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
65
|
+
variant: "link",
|
|
66
|
+
onClick: props.onClose,
|
|
67
|
+
children: "Close"
|
|
68
|
+
})
|
|
69
|
+
})]
|
|
70
|
+
}));
|
|
71
|
+
}),
|
|
72
|
+
_useOverlayService2 = _slicedToArray(_useOverlayService, 2),
|
|
73
|
+
OptionModal = _useOverlayService2[0],
|
|
74
|
+
openOptionModal = _useOverlayService2[1];
|
|
75
|
+
react.useEffect(function () {
|
|
76
|
+
setTimeout(function () {
|
|
77
|
+
var model = getModel();
|
|
78
|
+
setType(model.datatype);
|
|
79
|
+
setMultiple(model.multiple);
|
|
80
|
+
setHasOptions(!!model.optionList);
|
|
81
|
+
setCustomOptions(model.optionList === CUSTOM_LIST);
|
|
82
|
+
}, 10);
|
|
83
|
+
}, []);
|
|
84
|
+
react.useEffect(function () {
|
|
85
|
+
if (type) {
|
|
86
|
+
var modelRef = getModel();
|
|
87
|
+
var reset = {
|
|
88
|
+
datatype: type,
|
|
89
|
+
id: field,
|
|
90
|
+
label: modelRef.label,
|
|
91
|
+
defaultValue: modelRef.defaultValue,
|
|
92
|
+
required: modelRef.required,
|
|
93
|
+
multiple: type === schema.DATA_TYPES.AVATAR ? false : modelRef.multiple,
|
|
94
|
+
minItems: modelRef.minItems,
|
|
95
|
+
maxItems: modelRef.maxItems
|
|
96
|
+
};
|
|
97
|
+
if (type === schema.DATA_TYPES.STRING) {
|
|
98
|
+
reset = Object.assign(reset, {
|
|
99
|
+
optionList: modelRef.optionList,
|
|
100
|
+
options: modelRef.options,
|
|
101
|
+
regex: modelRef.regex
|
|
102
|
+
});
|
|
103
|
+
} else if (type === schema.DATA_TYPES.DATE) {
|
|
104
|
+
reset = Object.assign(reset, {
|
|
105
|
+
type: "date"
|
|
106
|
+
});
|
|
107
|
+
} else if (type === schema.DATA_TYPES.NUMBER || type === schema.DATA_TYPES.RANGE) {
|
|
108
|
+
reset = Object.assign(reset, {
|
|
109
|
+
min: modelRef.min,
|
|
110
|
+
max: modelRef.max,
|
|
111
|
+
step: modelRef.step
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (type === schema.DATA_TYPES.AVATAR) {
|
|
115
|
+
setMultiple(false);
|
|
116
|
+
}
|
|
117
|
+
onTypeChange(reset);
|
|
118
|
+
}
|
|
119
|
+
}, [type]);
|
|
120
|
+
return /*#__PURE__*/jsxRuntime.jsxs(core.Collapsable, {
|
|
121
|
+
open: true,
|
|
122
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
123
|
+
className: "flex flex-nowrap group/field",
|
|
124
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
125
|
+
className: "flex-1 truncate",
|
|
126
|
+
children: field
|
|
127
|
+
}), allowRemove && /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
128
|
+
size: "sm",
|
|
129
|
+
color: "danger",
|
|
130
|
+
variant: "link",
|
|
131
|
+
"aria-label": "Delete",
|
|
132
|
+
stopPropagation: true,
|
|
133
|
+
icon: core.CoreIcons.trash,
|
|
134
|
+
className: "invisible group-hover/field:visible"
|
|
135
|
+
})]
|
|
136
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
137
|
+
className: "flex flex-col gap-1 pb-4",
|
|
138
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
139
|
+
name: "".concat(field, ".datatype"),
|
|
140
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Select.Select, {
|
|
141
|
+
inline: true,
|
|
142
|
+
label: "Type",
|
|
143
|
+
placeholder: "Data type",
|
|
144
|
+
options: acceptableTypes,
|
|
145
|
+
onChange: function onChange(val) {
|
|
146
|
+
return setType(val);
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
150
|
+
name: "".concat(field, ".label"),
|
|
151
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {
|
|
152
|
+
inline: true,
|
|
153
|
+
label: "Label",
|
|
154
|
+
allowClear: true,
|
|
155
|
+
placeholder: "Label...",
|
|
156
|
+
decorateEndShowWhenEmpty: true,
|
|
157
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
158
|
+
className: "text-sm text-muted/50 px-1",
|
|
159
|
+
children: "OPTIONAL"
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
}), type === schema.DATA_TYPES.STRING && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
|
|
163
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
164
|
+
name: "".concat(field, ".regex"),
|
|
165
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {
|
|
166
|
+
inline: true,
|
|
167
|
+
label: "Regex validation",
|
|
168
|
+
allowClear: true,
|
|
169
|
+
placeholder: "Regex value...",
|
|
170
|
+
decorateEndShowWhenEmpty: true,
|
|
171
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
172
|
+
className: "text-sm text-muted/50 px-1",
|
|
173
|
+
children: "OPTIONAL"
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(Field.Field, {
|
|
177
|
+
inline: true,
|
|
178
|
+
label: "Option list",
|
|
179
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
180
|
+
name: "".concat(field, ".optionList"),
|
|
181
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Select.Select, {
|
|
182
|
+
allowClear: true,
|
|
183
|
+
options: [CUSTOM_LIST].concat(_toConsumableArray(optionLists)),
|
|
184
|
+
onChange: function onChange(v) {
|
|
185
|
+
return setCustomOptions(v === CUSTOM_LIST);
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
}), customOptions && /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
189
|
+
icon: core.CoreIcons.list,
|
|
190
|
+
"aria-label": "Custom options",
|
|
191
|
+
onClick: function onClick() {
|
|
192
|
+
void openOptionModal();
|
|
193
|
+
}
|
|
194
|
+
})]
|
|
195
|
+
}), OptionModal]
|
|
196
|
+
}), type === schema.DATA_TYPES.FILE && /*#__PURE__*/jsxRuntime.jsx(react.Fragment, {
|
|
197
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
198
|
+
name: "".concat(field, ".accept"),
|
|
199
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {
|
|
200
|
+
inline: true,
|
|
201
|
+
label: "Accept types",
|
|
202
|
+
allowClear: true,
|
|
203
|
+
placeholder: "Accept value...",
|
|
204
|
+
decorateEndShowWhenEmpty: true,
|
|
205
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
206
|
+
className: "text-sm text-muted/50 px-1",
|
|
207
|
+
children: "OPTIONAL"
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
}), [schema.DATA_TYPES.NUMBER, schema.DATA_TYPES.RANGE].includes(type) && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
|
|
212
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
213
|
+
name: "".concat(field, ".min"),
|
|
214
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
215
|
+
inline: true,
|
|
216
|
+
label: "Min value",
|
|
217
|
+
allowClear: true,
|
|
218
|
+
placeholder: "Minimum value...",
|
|
219
|
+
decorateEndShowWhenEmpty: true,
|
|
220
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
221
|
+
className: "text-sm text-muted/50 px-1",
|
|
222
|
+
children: "OPTIONAL"
|
|
223
|
+
})
|
|
224
|
+
})
|
|
225
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
226
|
+
name: "".concat(field, ".max"),
|
|
227
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
228
|
+
inline: true,
|
|
229
|
+
label: "Max value",
|
|
230
|
+
allowClear: true,
|
|
231
|
+
placeholder: "Maximum value...",
|
|
232
|
+
decorateEndShowWhenEmpty: true,
|
|
233
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
234
|
+
className: "text-sm text-muted/50 px-1",
|
|
235
|
+
children: "OPTIONAL"
|
|
236
|
+
})
|
|
237
|
+
})
|
|
238
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
239
|
+
name: "".concat(field, ".step"),
|
|
240
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
241
|
+
inline: true,
|
|
242
|
+
label: "Step value",
|
|
243
|
+
allowClear: true,
|
|
244
|
+
placeholder: "Step value...",
|
|
245
|
+
decorateEndShowWhenEmpty: true,
|
|
246
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
247
|
+
className: "text-sm text-muted/50 px-1",
|
|
248
|
+
children: "OPTIONAL"
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
})]
|
|
252
|
+
}), type === schema.DATA_TYPES.DATE && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
|
|
253
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Field.Field, {
|
|
254
|
+
inline: true,
|
|
255
|
+
label: "Type",
|
|
256
|
+
plain: true,
|
|
257
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
258
|
+
name: "".concat(field, ".type"),
|
|
259
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(core.ToggleButtonGroup, {
|
|
260
|
+
value: "",
|
|
261
|
+
fullWidth: true,
|
|
262
|
+
className: "flex-1",
|
|
263
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
264
|
+
className: "flex-1",
|
|
265
|
+
value: "date",
|
|
266
|
+
children: "Date"
|
|
267
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
268
|
+
className: "flex-1",
|
|
269
|
+
value: "datetime",
|
|
270
|
+
children: "Date Time"
|
|
271
|
+
})]
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
275
|
+
name: "".concat(field, ".min"),
|
|
276
|
+
children: /*#__PURE__*/jsxRuntime.jsx(DateInput.DateInput, {
|
|
277
|
+
inline: true,
|
|
278
|
+
label: "Min value",
|
|
279
|
+
allowClear: true,
|
|
280
|
+
placeholder: "Minimum value...",
|
|
281
|
+
decorateEndShowWhenEmpty: true,
|
|
282
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
283
|
+
className: "text-sm text-muted/50 px-1",
|
|
284
|
+
children: "OPTIONAL"
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
288
|
+
name: "".concat(field, ".max"),
|
|
289
|
+
children: /*#__PURE__*/jsxRuntime.jsx(DateInput.DateInput, {
|
|
290
|
+
inline: true,
|
|
291
|
+
label: "Max value",
|
|
292
|
+
allowClear: true,
|
|
293
|
+
placeholder: "Maximum value...",
|
|
294
|
+
decorateEndShowWhenEmpty: true,
|
|
295
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
296
|
+
className: "text-sm text-muted/50 px-1",
|
|
297
|
+
children: "OPTIONAL"
|
|
298
|
+
})
|
|
299
|
+
})
|
|
300
|
+
})]
|
|
301
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(Field.Field, {
|
|
302
|
+
label: " ",
|
|
303
|
+
inline: true,
|
|
304
|
+
plain: true,
|
|
305
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
306
|
+
name: "".concat(field, ".required"),
|
|
307
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Checkbox.Checkbox, {
|
|
308
|
+
label: "Required"
|
|
309
|
+
})
|
|
310
|
+
}), type !== schema.DATA_TYPES.AVATAR && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
311
|
+
name: "".concat(field, ".multiple"),
|
|
312
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Checkbox.Checkbox, {
|
|
313
|
+
label: "Multiple",
|
|
314
|
+
onChange: setMultiple
|
|
315
|
+
})
|
|
316
|
+
}), hasOptions && /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
317
|
+
name: "".concat(field, ".allowCustom"),
|
|
318
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Checkbox.Checkbox, {
|
|
319
|
+
label: "Allow custom value"
|
|
320
|
+
})
|
|
321
|
+
})]
|
|
322
|
+
}), multiple && /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
|
|
323
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
324
|
+
name: "".concat(field, ".minItems"),
|
|
325
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
326
|
+
inline: true,
|
|
327
|
+
label: "Min items",
|
|
328
|
+
allowClear: true,
|
|
329
|
+
placeholder: "Minimum items...",
|
|
330
|
+
decorateEndShowWhenEmpty: true,
|
|
331
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
332
|
+
className: "text-sm text-muted/50 px-1",
|
|
333
|
+
children: "OPTIONAL"
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
337
|
+
name: "".concat(field, ".maxItems"),
|
|
338
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Number.Number, {
|
|
339
|
+
inline: true,
|
|
340
|
+
label: "Max items",
|
|
341
|
+
allowClear: true,
|
|
342
|
+
placeholder: "Maximum items...",
|
|
343
|
+
decorateEndShowWhenEmpty: true,
|
|
344
|
+
decorateEnd: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
345
|
+
className: "text-sm text-muted/50 px-1",
|
|
346
|
+
children: "OPTIONAL"
|
|
347
|
+
})
|
|
348
|
+
})
|
|
349
|
+
})]
|
|
350
|
+
})]
|
|
351
|
+
})]
|
|
352
|
+
}, field);
|
|
353
|
+
};
|
|
354
|
+
var SchemaEditor = function SchemaEditor(_ref2) {
|
|
355
|
+
var schemaDef = _ref2.schemaDef,
|
|
356
|
+
allowRemove = _ref2.allowRemove,
|
|
357
|
+
acceptableTypes = _ref2.acceptableTypes,
|
|
358
|
+
_ref2$optionLists = _ref2.optionLists,
|
|
359
|
+
optionLists = _ref2$optionLists === void 0 ? utilities.EMPTY_ARRAY : _ref2$optionLists,
|
|
360
|
+
onChange = _ref2.onChange;
|
|
361
|
+
var formRef = react.useRef(null);
|
|
362
|
+
var schemaRef = react.useRef({});
|
|
363
|
+
var _useState9 = react.useState({}),
|
|
364
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
365
|
+
schema$1 = _useState10[0],
|
|
366
|
+
setSchema = _useState10[1];
|
|
367
|
+
var _useState11 = react.useState([]),
|
|
368
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
369
|
+
schemaFields = _useState12[0],
|
|
370
|
+
setSchemaFields = _useState12[1];
|
|
371
|
+
react.useEffect(function () {
|
|
372
|
+
var schemaMap = Object.fromEntries(schemaDef.map(function (schema) {
|
|
373
|
+
return [schema.id, schema];
|
|
374
|
+
}));
|
|
375
|
+
var schema = Object.fromEntries(Object.keys(schemaMap).map(function (field) {
|
|
376
|
+
var _schemaRef$current$fi;
|
|
377
|
+
return [field, (_schemaRef$current$fi = schemaRef.current[field]) !== null && _schemaRef$current$fi !== void 0 ? _schemaRef$current$fi : schemaMap[field]];
|
|
378
|
+
}));
|
|
379
|
+
setSchema(schema);
|
|
380
|
+
setSchemaFields(Object.keys(schema));
|
|
381
|
+
}, [schemaDef]);
|
|
382
|
+
var handleChange = react.useCallback(function (model) {
|
|
383
|
+
onChange === null || onChange === void 0 || onChange(Object.values(model));
|
|
384
|
+
}, []);
|
|
385
|
+
var handleTypeChange = react.useCallback(function (field, val) {
|
|
386
|
+
var _formRef$current;
|
|
387
|
+
(_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValue(field, val);
|
|
388
|
+
}, []);
|
|
389
|
+
return /*#__PURE__*/jsxRuntime.jsxs(Form.Form, {
|
|
390
|
+
formRef: formRef,
|
|
391
|
+
values: schema$1,
|
|
392
|
+
defaultValues: schema$1,
|
|
393
|
+
onSubmit: handleChange,
|
|
394
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Content, {
|
|
395
|
+
className: "divide-y",
|
|
396
|
+
children: schemaFields.map(function (field) {
|
|
397
|
+
return /*#__PURE__*/jsxRuntime.jsx(SchemaField, {
|
|
398
|
+
field: field,
|
|
399
|
+
allowRemove: allowRemove,
|
|
400
|
+
optionLists: optionLists,
|
|
401
|
+
getModel: function getModel() {
|
|
402
|
+
var _formRef$current2;
|
|
403
|
+
return (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : _formRef$current2.getValues()[field];
|
|
404
|
+
},
|
|
405
|
+
onTypeChange: function onTypeChange(val) {
|
|
406
|
+
return handleTypeChange(field, val);
|
|
407
|
+
},
|
|
408
|
+
acceptableTypes: acceptableTypes !== null && acceptableTypes !== void 0 ? acceptableTypes : Object.values(schema.DATA_TYPES)
|
|
409
|
+
}, field);
|
|
410
|
+
})
|
|
411
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(core.Footer, {
|
|
412
|
+
flex: true,
|
|
413
|
+
justify: "end",
|
|
414
|
+
className: "sticky bottom-0 border-t bg-base px-6 py-2",
|
|
415
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
416
|
+
type: "reset",
|
|
417
|
+
variant: "link",
|
|
418
|
+
children: "Reset"
|
|
419
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
420
|
+
type: "submit",
|
|
421
|
+
variant: "solid",
|
|
422
|
+
children: "Submit"
|
|
423
|
+
})]
|
|
424
|
+
})]
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
exports.SchemaEditor = SchemaEditor;
|
|
@@ -46,7 +46,7 @@ var Controller = function Controller(_ref) {
|
|
|
46
46
|
(_children$props$onCha = (_children$props = children.props).onChange) === null || _children$props$onCha === void 0 || _children$props$onCha.call(_children$props, v);
|
|
47
47
|
}
|
|
48
48
|
})) : children(_objectSpread(_objectSpread(_objectSpread({}, field), rest), {}, {
|
|
49
|
-
|
|
49
|
+
ref: function ref(el) {
|
|
50
50
|
el && _ref3(el);
|
|
51
51
|
},
|
|
52
52
|
readOnly: isSubmitting,
|
package/dist/cjs/form/Form.js
CHANGED
|
@@ -11,7 +11,7 @@ var react = require('react');
|
|
|
11
11
|
var reactHookForm = require('react-hook-form');
|
|
12
12
|
var jsxRuntime = require('react/jsx-runtime');
|
|
13
13
|
|
|
14
|
-
var _excluded = ["formRef", "schema", "children", "defaultValues", "onSubmit", "onChange"];
|
|
14
|
+
var _excluded = ["formRef", "schema", "children", "values", "defaultValues", "onSubmit", "onChange"];
|
|
15
15
|
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; }
|
|
16
16
|
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; }
|
|
17
17
|
var DEFAULT_SUBMIT = function DEFAULT_SUBMIT() {
|
|
@@ -21,6 +21,7 @@ var Form = function Form(_ref) {
|
|
|
21
21
|
var formRef = _ref.formRef,
|
|
22
22
|
schema = _ref.schema,
|
|
23
23
|
children = _ref.children,
|
|
24
|
+
values = _ref.values,
|
|
24
25
|
defaultValues = _ref.defaultValues,
|
|
25
26
|
_ref$onSubmit = _ref.onSubmit,
|
|
26
27
|
onSubmit = _ref$onSubmit === void 0 ? DEFAULT_SUBMIT : _ref$onSubmit,
|
|
@@ -28,13 +29,11 @@ var Form = function Form(_ref) {
|
|
|
28
29
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
29
30
|
var ref = react.useRef(null);
|
|
30
31
|
var form = reactHookForm.useForm({
|
|
32
|
+
values: values,
|
|
31
33
|
shouldFocusError: true,
|
|
32
34
|
resolver: schema && yup.yupResolver(schema),
|
|
33
35
|
defaultValues: defaultValues
|
|
34
36
|
});
|
|
35
|
-
react.useEffect(function () {
|
|
36
|
-
form.reset();
|
|
37
|
-
}, []);
|
|
38
37
|
var _useTransition = react.useTransition(),
|
|
39
38
|
_useTransition2 = _slicedToArray(_useTransition, 2),
|
|
40
39
|
startTransition = _useTransition2[1];
|