@react-fabric/form 1.0.0-beta.33 → 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/FormField.js +3 -3
- package/dist/cjs/builder/SchemaEditor.js +43 -404
- 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 +11 -8
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/input/ColorInput.js +1 -1
- package/dist/cjs/input/DateInput.js +2 -2
- package/dist/cjs/input/File.js +1 -1
- package/dist/cjs/input/Hidden.js +1 -1
- package/dist/cjs/input/Input.js +1 -1
- package/dist/cjs/input/Number.js +1 -1
- package/dist/cjs/input/Password.js +1 -1
- package/dist/cjs/input/RangeSlider.js +1 -1
- package/dist/cjs/input/Search.js +1 -1
- package/dist/cjs/input/Slider.js +1 -1
- package/dist/cjs/input/Textarea.js +1 -1
- package/dist/cjs/types/schema.js +2 -0
- package/dist/esm/builder/FormField.js +3 -3
- package/dist/esm/builder/SchemaEditor.js +45 -406
- 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 +11 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/input/ColorInput.js +1 -1
- package/dist/esm/input/DateInput.js +2 -2
- package/dist/esm/input/File.js +1 -1
- package/dist/esm/input/Hidden.js +1 -1
- package/dist/esm/input/Input.js +1 -1
- package/dist/esm/input/Number.js +1 -1
- package/dist/esm/input/Password.js +1 -1
- package/dist/esm/input/RangeSlider.js +1 -1
- package/dist/esm/input/Search.js +1 -1
- package/dist/esm/input/Slider.js +1 -1
- package/dist/esm/input/Textarea.js +1 -1
- package/dist/esm/types/schema.js +2 -1
- package/dist/types/builder/SchemaEditor.d.ts +2 -10
- 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 +1 -5
- package/dist/types/index.d.ts +1 -1
- package/dist/types/input/ColorInput.d.ts +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/schema.d.ts +26 -0
- package/package.json +5 -5
- package/src/builder/FormField.tsx +3 -3
- package/src/builder/SchemaEditor.tsx +24 -398
- 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 +6 -9
- package/src/index.ts +6 -1
- package/src/input/ArrayInput.tsx +1 -0
- package/src/input/ColorInput.tsx +5 -2
- package/src/input/DateInput.tsx +2 -2
- package/src/input/File.tsx +1 -1
- package/src/input/Hidden.tsx +4 -3
- package/src/input/Input.tsx +1 -1
- package/src/input/Number.tsx +1 -1
- package/src/input/Password.tsx +1 -1
- package/src/input/RangeSlider.tsx +1 -1
- package/src/input/Search.tsx +1 -1
- package/src/input/Slider.tsx +1 -1
- package/src/input/Textarea.tsx +1 -1
- package/src/types/index.ts +1 -1
- package/src/types/schema.ts +30 -0
|
@@ -106,7 +106,7 @@ var FormField = function FormField(_ref) {
|
|
|
106
106
|
});
|
|
107
107
|
return rest.multiple && !hasOptions ? /*#__PURE__*/jsxRuntime.jsx(ArrayInput.ArrayInput, {
|
|
108
108
|
name: fieldName,
|
|
109
|
-
label: t(
|
|
109
|
+
label: t("fb.".concat(id), label || id),
|
|
110
110
|
required: required,
|
|
111
111
|
onAdd: function onAdd() {
|
|
112
112
|
return String("");
|
|
@@ -118,8 +118,8 @@ var FormField = function FormField(_ref) {
|
|
|
118
118
|
name: fieldName,
|
|
119
119
|
children: /*#__PURE__*/jsxRuntime.jsx(E, _objectSpread(_objectSpread({}, props), {}, {
|
|
120
120
|
autoFocus: autoFocus,
|
|
121
|
-
label: t(
|
|
122
|
-
placeholder: t(
|
|
121
|
+
label: t("fb.".concat(id), label || id),
|
|
122
|
+
placeholder: t("fb.".concat(id), label || id),
|
|
123
123
|
required: required,
|
|
124
124
|
inline: inline
|
|
125
125
|
}))
|
|
@@ -1,426 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
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
3
|
var core = require('@react-fabric/core');
|
|
7
4
|
var utilities = require('@react-fabric/utilities');
|
|
8
5
|
var react = require('react');
|
|
9
|
-
var Controller = require('../form/Controller.js');
|
|
10
6
|
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
7
|
var schema = require('../types/schema.js');
|
|
8
|
+
var SchemaArrayForm = require('./components/SchemaArrayForm.js');
|
|
19
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
20
10
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
/*
|
|
12
|
+
* React Fabric
|
|
13
|
+
* @version: 1.0.0
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* The MIT License (MIT)
|
|
17
|
+
* Copyright (c) 2025 Adarsh Pastakia
|
|
18
|
+
*
|
|
19
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
20
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
21
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
22
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
23
|
+
* subject to the following conditions:
|
|
24
|
+
*
|
|
25
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
26
|
+
* portions of the Software.
|
|
27
|
+
*
|
|
28
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
29
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
30
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
31
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
var SchemaEditor = function SchemaEditor(_ref) {
|
|
35
|
+
var schemaDef = _ref.schemaDef,
|
|
36
|
+
dynamic = _ref.dynamic,
|
|
37
|
+
acceptableTypes = _ref.acceptableTypes,
|
|
27
38
|
_ref$optionLists = _ref.optionLists,
|
|
28
39
|
optionLists = _ref$optionLists === void 0 ? utilities.EMPTY_ARRAY : _ref$optionLists,
|
|
29
|
-
|
|
30
|
-
|
|
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;
|
|
40
|
+
children = _ref.children,
|
|
41
|
+
onChange = _ref.onChange;
|
|
361
42
|
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
43
|
var handleChange = react.useCallback(function (model) {
|
|
383
|
-
onChange === null || onChange === void 0 || onChange(
|
|
44
|
+
onChange === null || onChange === void 0 || onChange(model.schema);
|
|
384
45
|
}, []);
|
|
385
|
-
|
|
46
|
+
react.useEffect(function () {
|
|
386
47
|
var _formRef$current;
|
|
387
|
-
(_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.
|
|
388
|
-
|
|
48
|
+
(_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValues({
|
|
49
|
+
schema: schemaDef
|
|
50
|
+
});
|
|
51
|
+
}, [schemaDef]);
|
|
389
52
|
return /*#__PURE__*/jsxRuntime.jsxs(Form.Form, {
|
|
390
53
|
formRef: formRef,
|
|
391
|
-
values: schema$1,
|
|
392
|
-
defaultValues: schema$1,
|
|
393
54
|
onSubmit: handleChange,
|
|
394
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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, {
|
|
55
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(SchemaArrayForm.SchemaArrayForm, {
|
|
56
|
+
dynamic: dynamic,
|
|
57
|
+
optionLists: optionLists,
|
|
58
|
+
acceptableTypes: acceptableTypes !== null && acceptableTypes !== void 0 ? acceptableTypes : Object.values(schema.DATA_TYPES)
|
|
59
|
+
}), children && /*#__PURE__*/jsxRuntime.jsx(core.Footer, {
|
|
412
60
|
flex: true,
|
|
413
|
-
|
|
414
|
-
|
|
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
|
-
})]
|
|
61
|
+
className: "border-t bg-base px-6 py-2",
|
|
62
|
+
children: children
|
|
424
63
|
})]
|
|
425
64
|
});
|
|
426
65
|
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var core = require('@react-fabric/core');
|
|
5
|
+
var utilities = require('@react-fabric/utilities');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var Controller = require('../../form/Controller.js');
|
|
8
|
+
var Form = require('../../form/Form.js');
|
|
9
|
+
var ArrayInput = require('../../input/ArrayInput.js');
|
|
10
|
+
var Input = require('../../input/Input.js');
|
|
11
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
12
|
+
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
var fieldSchema = utilities.yup.object({
|
|
16
|
+
fields: utilities.yup.array(utilities.yup.string().trim().required()).required().min(1)
|
|
17
|
+
});
|
|
18
|
+
var AddSchemaFields = function AddSchemaFields(props) {
|
|
19
|
+
var handleSubmit = react.useCallback(function (model) {
|
|
20
|
+
props.onClose(model.fields.map(function (f) {
|
|
21
|
+
return f.split(",").map(function (ff) {
|
|
22
|
+
return ff.trim();
|
|
23
|
+
});
|
|
24
|
+
}).flat(2));
|
|
25
|
+
}, []);
|
|
26
|
+
return /*#__PURE__*/jsxRuntime.jsx(core.Modal, _objectSpread(_objectSpread({}, props), {}, {
|
|
27
|
+
children: /*#__PURE__*/jsxRuntime.jsxs(Form.Form, {
|
|
28
|
+
schema: fieldSchema,
|
|
29
|
+
defaultValues: {
|
|
30
|
+
fields: [" "]
|
|
31
|
+
},
|
|
32
|
+
onSubmit: handleSubmit,
|
|
33
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs(core.Content, {
|
|
34
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(ArrayInput.ArrayInput, {
|
|
35
|
+
minItems: 1,
|
|
36
|
+
name: "fields",
|
|
37
|
+
onAdd: function onAdd() {
|
|
38
|
+
return String("");
|
|
39
|
+
},
|
|
40
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Controller.Controller, {
|
|
41
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {
|
|
42
|
+
autoFocus: true
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
}), /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
46
|
+
className: "text-sm text-muted",
|
|
47
|
+
children: "Provide list of fields or comma-separated value"
|
|
48
|
+
})]
|
|
49
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Footer, {
|
|
50
|
+
flex: true,
|
|
51
|
+
justify: "end",
|
|
52
|
+
className: "px-2 py-1",
|
|
53
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
54
|
+
type: "submit",
|
|
55
|
+
children: "Add"
|
|
56
|
+
})
|
|
57
|
+
})]
|
|
58
|
+
})
|
|
59
|
+
}));
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
exports.AddSchemaFields = AddSchemaFields;
|