@react-fabric/form 1.0.0-beta.8 → 1.0.1
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/{src/input/ArrayInput.module.css → css/_arrayInput.css} +8 -8
- package/css/_colorPicker.css +95 -0
- package/{src/internal/Field.module.css → css/_field.css} +94 -33
- package/{src/input/File.module.css → css/_file.css} +21 -6
- package/css/styles.css +27 -0
- package/dist/cjs/builder/FileField.js +107 -78
- package/dist/cjs/builder/FormField.js +60 -39
- package/dist/cjs/builder/SchemaEditor.js +72 -0
- package/dist/cjs/builder/components/AddSchemaFields.js +64 -0
- package/dist/cjs/builder/components/SchemaArrayForm.js +146 -0
- package/dist/cjs/builder/components/SchemaField.js +423 -0
- package/dist/cjs/form/Controller.js +66 -19
- package/dist/cjs/form/Form.js +97 -39
- package/dist/cjs/form/useForm.js +32 -0
- package/dist/cjs/hooks/useFileUploader.js +74 -45
- package/dist/cjs/hooks/useFormBuilder.js +85 -31
- package/dist/cjs/i18n/{ar.json.js → ar/form.json.js} +5 -4
- package/dist/cjs/i18n/{en.json.js → en/form.json.js} +5 -5
- package/dist/cjs/i18n/index.js +4 -4
- package/dist/cjs/index.js +41 -2
- package/dist/cjs/input/ArrayInput.js +259 -135
- package/dist/cjs/input/AvatarInput.js +99 -63
- package/dist/cjs/input/Checkbox.js +24 -25
- package/dist/cjs/input/ColorInput.js +138 -81
- package/dist/cjs/input/ColorPicker.js +78 -95
- package/dist/cjs/input/DateInput.js +192 -0
- package/dist/cjs/input/Field.js +21 -20
- package/dist/cjs/input/File.js +85 -80
- package/dist/cjs/input/Hidden.js +27 -13
- package/dist/cjs/input/Input.js +49 -48
- package/dist/cjs/input/Number.js +46 -44
- package/dist/cjs/input/Password.js +51 -49
- package/dist/cjs/input/Radio.js +26 -16
- package/dist/cjs/input/RadioGroup.js +26 -11
- package/dist/cjs/input/{Range.js → RangeSlider.js} +61 -66
- package/dist/cjs/input/Search.js +58 -64
- package/dist/cjs/input/Slider.js +57 -66
- package/dist/cjs/input/Switch.js +29 -27
- package/dist/cjs/input/Textarea.js +65 -53
- package/dist/cjs/internal/ErrorIcon.js +9 -9
- package/dist/cjs/internal/FieldWrapper.js +23 -13
- package/dist/cjs/internal/InputWrapper.js +85 -87
- package/dist/cjs/ranger/index.js +7 -7
- package/dist/cjs/ranger/utils.js +9 -4
- package/dist/cjs/select/AutoComplete.js +93 -76
- package/dist/cjs/select/DualList.js +235 -154
- package/dist/cjs/select/List.js +122 -89
- package/dist/cjs/select/Options.js +58 -54
- package/dist/cjs/select/Select.js +119 -89
- package/dist/cjs/select/helpers.js +5 -5
- package/dist/cjs/select/useSelect.js +83 -58
- package/dist/cjs/types/schema.js +43 -0
- package/dist/cjs/utils/eventHandlers.js +16 -6
- package/dist/cjs/utils/getColor.js +6 -6
- package/dist/cjs/utils/getProps.js +49 -0
- package/dist/esm/builder/FileField.js +109 -80
- package/dist/esm/builder/FormField.js +60 -39
- package/dist/esm/builder/SchemaEditor.js +72 -0
- package/dist/esm/builder/components/AddSchemaFields.js +64 -0
- package/dist/esm/builder/components/SchemaArrayForm.js +146 -0
- package/dist/esm/builder/components/SchemaField.js +423 -0
- package/dist/esm/form/Controller.js +66 -19
- package/dist/esm/form/Form.js +97 -39
- package/dist/esm/form/useForm.js +32 -0
- package/dist/esm/hooks/useFileUploader.js +75 -46
- package/dist/esm/hooks/useFormBuilder.js +84 -30
- package/dist/esm/i18n/{ar.json.js → ar/form.json.js} +5 -4
- package/dist/esm/i18n/{en.json.js → en/form.json.js} +5 -5
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/index.js +36 -1
- package/dist/esm/input/ArrayInput.js +260 -136
- package/dist/esm/input/AvatarInput.js +99 -63
- package/dist/esm/input/Checkbox.js +26 -27
- package/dist/esm/input/ColorInput.js +141 -84
- package/dist/esm/input/ColorPicker.js +80 -97
- package/dist/esm/input/DateInput.js +192 -0
- package/dist/esm/input/Field.js +21 -20
- package/dist/esm/input/File.js +89 -84
- package/dist/esm/input/Hidden.js +28 -14
- package/dist/esm/input/Input.js +51 -50
- package/dist/esm/input/Number.js +48 -46
- package/dist/esm/input/Password.js +54 -52
- package/dist/esm/input/Radio.js +27 -17
- package/dist/esm/input/RadioGroup.js +27 -12
- package/dist/esm/input/{Range.js → RangeSlider.js} +62 -67
- package/dist/esm/input/Search.js +61 -67
- package/dist/esm/input/Slider.js +58 -67
- package/dist/esm/input/Switch.js +31 -29
- package/dist/esm/input/Textarea.js +67 -55
- package/dist/esm/internal/ErrorIcon.js +11 -11
- package/dist/esm/internal/FieldWrapper.js +23 -13
- package/dist/esm/internal/InputWrapper.js +88 -90
- package/dist/esm/ranger/index.js +7 -7
- package/dist/esm/ranger/utils.js +9 -4
- package/dist/esm/select/AutoComplete.js +95 -78
- package/dist/esm/select/DualList.js +233 -152
- package/dist/esm/select/List.js +125 -92
- package/dist/esm/select/Options.js +58 -54
- package/dist/esm/select/Select.js +122 -92
- package/dist/esm/select/helpers.js +5 -5
- package/dist/esm/select/useSelect.js +84 -59
- package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
- package/dist/esm/utils/eventHandlers.js +16 -6
- package/dist/esm/utils/getColor.js +6 -6
- package/dist/esm/utils/getProps.js +49 -0
- package/dist/types/builder/FileField.d.ts +7 -4
- package/dist/types/builder/FormField.d.ts +4 -2
- package/dist/types/builder/SchemaEditor.d.ts +6 -0
- 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 +12 -0
- package/dist/types/form/Controller.d.ts +45 -3
- package/dist/types/form/Form.d.ts +38 -7
- package/dist/types/form/useForm.d.ts +6 -0
- package/dist/types/hooks/useFileUploader.d.ts +24 -3
- package/dist/types/hooks/useFormBuilder.d.ts +41 -3
- package/dist/types/index.d.ts +32 -2
- package/dist/types/input/ArrayInput.d.ts +68 -13
- package/dist/types/input/AvatarInput.d.ts +23 -6
- package/dist/types/input/Checkbox.d.ts +12 -10
- package/dist/types/input/ColorInput.d.ts +15 -5
- package/dist/types/input/ColorPicker.d.ts +10 -2
- package/dist/types/input/DateInput.d.ts +21 -0
- package/dist/types/input/Field.d.ts +9 -36
- package/dist/types/input/File.d.ts +16 -4
- package/dist/types/input/Hidden.d.ts +7 -6
- package/dist/types/input/Input.d.ts +11 -4
- package/dist/types/input/Number.d.ts +9 -4
- package/dist/types/input/Password.d.ts +9 -4
- package/dist/types/input/Radio.d.ts +9 -4
- package/dist/types/input/RadioGroup.d.ts +14 -6
- package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +11 -6
- package/dist/types/input/Search.d.ts +14 -4
- package/dist/types/input/Slider.d.ts +9 -6
- package/dist/types/input/Switch.d.ts +13 -8
- package/dist/types/input/Textarea.d.ts +15 -4
- package/dist/types/internal/ErrorIcon.d.ts +4 -1
- package/dist/types/internal/FieldWrapper.d.ts +10 -1
- package/dist/types/internal/InputWrapper.d.ts +19 -1
- package/dist/types/ranger/index.d.ts +7 -3
- package/dist/types/ranger/utils.d.ts +2 -2
- package/dist/types/select/AutoComplete.d.ts +7 -2
- package/dist/types/select/DualList.d.ts +11 -37
- package/dist/types/select/List.d.ts +7 -2
- package/dist/types/select/Options.d.ts +8 -7
- package/dist/types/select/Select.d.ts +7 -2
- package/dist/types/select/helpers.d.ts +2 -2
- package/dist/types/select/useSelect.d.ts +10 -28
- package/dist/types/types/index.d.ts +73 -39
- package/dist/types/types/schema.d.ts +78 -32
- package/dist/types/utils/eventHandlers.d.ts +4 -4
- package/dist/types/utils/getColor.d.ts +4 -4
- package/dist/types/utils/getProps.d.ts +26 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +25 -25
- package/src/builder/FileField.tsx +73 -56
- package/src/builder/FormField.tsx +66 -58
- package/src/builder/SchemaEditor.tsx +78 -0
- package/src/builder/components/AddSchemaFields.tsx +64 -0
- package/src/builder/components/SchemaArrayForm.tsx +146 -0
- package/src/builder/components/SchemaField.tsx +405 -0
- package/src/form/Controller.tsx +61 -24
- package/src/form/Form.tsx +74 -50
- package/src/form/useForm.ts +53 -0
- package/src/hooks/useFileUploader.ts +115 -84
- package/src/hooks/useFormBuilder.tsx +80 -41
- package/src/i18n/{ar.json → ar/form.json} +5 -4
- package/src/i18n/{en.json → en/form.json} +5 -5
- package/src/i18n/index.ts +2 -2
- package/src/index.ts +34 -20
- package/src/input/ArrayInput.tsx +255 -173
- package/src/input/AvatarInput.tsx +82 -39
- package/src/input/Checkbox.tsx +30 -54
- package/src/input/ColorInput.tsx +146 -105
- package/src/input/ColorPicker.tsx +76 -102
- package/src/input/DateInput.tsx +225 -0
- package/src/input/Field.tsx +23 -65
- package/src/input/File.tsx +76 -98
- package/src/input/Hidden.tsx +36 -24
- package/src/input/Input.tsx +55 -53
- package/src/input/Number.tsx +49 -54
- package/src/input/Password.tsx +61 -66
- package/src/input/Radio.tsx +28 -37
- package/src/input/RadioGroup.tsx +30 -25
- package/src/input/{Range.tsx → RangeSlider.tsx} +81 -109
- package/src/input/Search.tsx +64 -77
- package/src/input/Slider.tsx +80 -109
- package/src/input/Switch.tsx +39 -53
- package/src/input/Textarea.tsx +72 -59
- package/src/internal/ErrorIcon.tsx +22 -21
- package/src/internal/FieldWrapper.tsx +33 -23
- package/src/internal/InputWrapper.tsx +132 -143
- package/src/ranger/index.tsx +37 -117
- package/src/ranger/utils.ts +12 -11
- package/src/select/AutoComplete.tsx +113 -123
- package/src/select/DualList.tsx +218 -204
- package/src/select/List.tsx +130 -97
- package/src/select/Options.tsx +59 -57
- package/src/select/Select.tsx +148 -122
- package/src/select/helpers.ts +13 -8
- package/src/select/useSelect.tsx +110 -127
- package/src/types/index.ts +76 -45
- package/src/types/schema.ts +97 -40
- package/src/utils/eventHandlers.ts +24 -26
- package/src/utils/getColor.ts +9 -8
- package/src/utils/getProps.ts +47 -0
- package/src/utils/index.ts +1 -0
- package/dist/cjs/input/ArrayInput.module.css +0 -1
- package/dist/cjs/input/ColorPicker.module.css +0 -1
- package/dist/cjs/input/File.module.css +0 -1
- package/dist/cjs/internal/Field.module.css +0 -1
- package/dist/esm/input/ArrayInput.module.css +0 -1
- package/dist/esm/input/ColorPicker.module.css +0 -1
- package/dist/esm/input/File.module.css +0 -1
- package/dist/esm/internal/Field.module.css +0 -1
|
@@ -4,36 +4,42 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
|
4
4
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
5
5
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
6
6
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
7
|
-
import { Button, Icon, ProgressBar } from '@react-fabric/core';
|
|
8
|
-
import { FileUtil, Format } from '@react-fabric/utilities';
|
|
7
|
+
import { Tooltip, Button, Badge, Icon, ProgressBar } from '@react-fabric/core';
|
|
8
|
+
import { isObject, isString, FileUtil, Format } from '@react-fabric/utilities';
|
|
9
9
|
import { Fragment } from 'react';
|
|
10
|
+
import { useTranslation } from 'react-i18next';
|
|
10
11
|
import { useFileUploader } from '../hooks/useFileUploader.js';
|
|
11
12
|
import { Field } from '../input/Field.js';
|
|
12
13
|
import { HiddenInput } from '../input/Hidden.js';
|
|
13
14
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
15
|
|
|
15
|
-
var _excluded = ["uploadHandler", "inline", "label", "accept", "multiple", "
|
|
16
|
+
var _excluded = ["uploadHandler", "inline", "label", "accept", "value", "onChange", "multiple", "error", "invalid"];
|
|
16
17
|
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
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
18
|
-
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).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; }
|
|
19
|
+
function FileField(_ref) {
|
|
20
|
+
var _error$values$label;
|
|
19
21
|
var uploadHandler = _ref.uploadHandler,
|
|
20
22
|
inline = _ref.inline,
|
|
21
23
|
label = _ref.label,
|
|
22
24
|
accept = _ref.accept,
|
|
23
|
-
_ref$multiple = _ref.multiple,
|
|
24
|
-
multiple = _ref$multiple === void 0 ? false : _ref$multiple,
|
|
25
25
|
value = _ref.value,
|
|
26
|
+
onChange = _ref.onChange,
|
|
27
|
+
multiple = _ref.multiple,
|
|
28
|
+
error = _ref.error,
|
|
29
|
+
invalid = _ref.invalid,
|
|
26
30
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
var _useTranslation = useTranslation(),
|
|
32
|
+
t = _useTranslation.t;
|
|
33
|
+
var _useFileUploader = useFileUploader(/*#__PURE__*/function () {
|
|
34
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(data, config) {
|
|
35
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
30
36
|
while (1) switch (_context.prev = _context.next) {
|
|
31
37
|
case 0:
|
|
32
|
-
_context.next =
|
|
38
|
+
_context.next = 1;
|
|
33
39
|
return uploadHandler === null || uploadHandler === void 0 ? void 0 : uploadHandler(data, config);
|
|
34
|
-
case
|
|
40
|
+
case 1:
|
|
35
41
|
return _context.abrupt("return", _context.sent);
|
|
36
|
-
case
|
|
42
|
+
case 2:
|
|
37
43
|
case "end":
|
|
38
44
|
return _context.stop();
|
|
39
45
|
}
|
|
@@ -42,90 +48,113 @@ var FileField = function FileField(_ref) {
|
|
|
42
48
|
return function (_x, _x2) {
|
|
43
49
|
return _ref2.apply(this, arguments);
|
|
44
50
|
};
|
|
45
|
-
}(), value,
|
|
51
|
+
}(), value, {
|
|
52
|
+
multiple: multiple,
|
|
53
|
+
onChange: onChange
|
|
54
|
+
}),
|
|
46
55
|
pending = _useFileUploader.pending,
|
|
47
56
|
files = _useFileUploader.files,
|
|
48
|
-
list = _useFileUploader.list,
|
|
49
57
|
upload = _useFileUploader.upload,
|
|
50
58
|
remove = _useFileUploader.remove;
|
|
51
59
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
52
|
-
children: [/*#__PURE__*/
|
|
60
|
+
children: [/*#__PURE__*/jsx(Field, {
|
|
53
61
|
plain: true,
|
|
54
62
|
inline: inline,
|
|
55
63
|
label: label,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
children: /*#__PURE__*/jsx(HiddenInput, _objectSpread({
|
|
65
|
+
hiddenValue: multiple ? files : files === null || files === void 0 ? void 0 : files[0]
|
|
66
|
+
}, rest))
|
|
67
|
+
}), /*#__PURE__*/jsx(Tooltip, {
|
|
68
|
+
color: "danger",
|
|
69
|
+
content: isObject(error) ? t(error.key, isObject(error.values) ? _objectSpread(_objectSpread({}, error.values), {}, {
|
|
70
|
+
label: t((_error$values$label = error.values.label) !== null && _error$values$label !== void 0 ? _error$values$label : "form:badkey", error.values.path)
|
|
71
|
+
}) : {}) : isString(error) ? error : "",
|
|
72
|
+
disabled: !error,
|
|
73
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
74
|
+
altIcon: pending > 0 ? /*#__PURE__*/jsx(Badge, {
|
|
75
|
+
inline: true,
|
|
76
|
+
children: pending
|
|
77
|
+
}) : undefined,
|
|
78
|
+
color: invalid ? "danger" : undefined,
|
|
79
|
+
variant: invalid ? "soft" : undefined,
|
|
80
|
+
"data-ref": "filebtn",
|
|
81
|
+
children: /*#__PURE__*/jsxs(Fragment, {
|
|
82
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
83
|
+
children: "Add file"
|
|
84
|
+
}), /*#__PURE__*/jsx("input", {
|
|
85
|
+
type: "file",
|
|
86
|
+
accept: accept,
|
|
87
|
+
multiple: multiple,
|
|
88
|
+
className: "absolute inset-0 opacity-0 z-5",
|
|
89
|
+
onChange: function onChange(e) {
|
|
90
|
+
return [upload(e.target.files), e.target.value = ""];
|
|
91
|
+
}
|
|
92
|
+
})]
|
|
76
93
|
})
|
|
77
|
-
})
|
|
94
|
+
})
|
|
78
95
|
}), /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsx("div", {
|
|
79
96
|
className: "bg-alternate",
|
|
80
97
|
children: files.map(function (file, idx) {
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
return (
|
|
99
|
+
/*#__PURE__*/
|
|
100
|
+
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
101
|
+
jsxs("div", {
|
|
102
|
+
className: "px-2 py-1",
|
|
85
103
|
children: [/*#__PURE__*/jsxs("div", {
|
|
86
|
-
className: "flex-1
|
|
87
|
-
children: [
|
|
88
|
-
className: "
|
|
89
|
-
children:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
104
|
+
className: "flex flex-nowrap gap-1 items-start",
|
|
105
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
106
|
+
className: "flex-1 truncate pe-2",
|
|
107
|
+
children: [file.filename, /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsx("span", {
|
|
108
|
+
className: "text-xs",
|
|
109
|
+
children: FileUtil.mime(file.mime)
|
|
110
|
+
}), /*#__PURE__*/jsx("span", {
|
|
111
|
+
className: "text-xs px-1",
|
|
112
|
+
children: Format.bytes(file.size)
|
|
113
|
+
})]
|
|
114
|
+
}), /*#__PURE__*/jsx("div", {
|
|
115
|
+
className: "flex-initial truncate px-2",
|
|
116
|
+
children: file.error && /*#__PURE__*/jsx("span", {
|
|
117
|
+
className: "text-danger-600",
|
|
118
|
+
children: file.error
|
|
119
|
+
})
|
|
120
|
+
}), file.progress && /*#__PURE__*/jsx("button", {
|
|
121
|
+
type: "button",
|
|
122
|
+
className: "size-fit leading-0 cursor-pointer",
|
|
123
|
+
onClick: function onClick() {
|
|
124
|
+
var _file$abort;
|
|
125
|
+
return (_file$abort = file.abort) === null || _file$abort === void 0 ? void 0 : _file$abort.call(file);
|
|
126
|
+
},
|
|
127
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
128
|
+
icon: "icon-[mdi--stop]",
|
|
129
|
+
bg: "danger",
|
|
130
|
+
color: "white",
|
|
131
|
+
size: "sm",
|
|
132
|
+
className: "p-0.5",
|
|
133
|
+
"aria-label": "abort"
|
|
134
|
+
})
|
|
135
|
+
}), !file.progress && /*#__PURE__*/jsx("button", {
|
|
136
|
+
type: "button",
|
|
137
|
+
className: "size-fit leading-0 cursor-pointer",
|
|
138
|
+
onClick: function onClick() {
|
|
139
|
+
return remove(file.key);
|
|
140
|
+
},
|
|
141
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
142
|
+
icon: "icon-[mdi--trash-can-outline]",
|
|
143
|
+
color: "danger",
|
|
144
|
+
size: "sm",
|
|
145
|
+
"aria-label": "remove"
|
|
146
|
+
})
|
|
93
147
|
})]
|
|
94
|
-
}), /*#__PURE__*/jsx(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
children: file.error
|
|
99
|
-
})
|
|
100
|
-
}), file.progress && /*#__PURE__*/jsx(Icon, {
|
|
101
|
-
icon: "mdi mdi-stop-circle",
|
|
102
|
-
bg: "danger",
|
|
103
|
-
color: "white",
|
|
104
|
-
size: "sm",
|
|
105
|
-
className: "p-[2px]",
|
|
106
|
-
"aria-label": "abort",
|
|
107
|
-
onClick: function onClick() {
|
|
108
|
-
var _file$abort;
|
|
109
|
-
return (_file$abort = file.abort) === null || _file$abort === void 0 ? void 0 : _file$abort.call(file);
|
|
110
|
-
}
|
|
111
|
-
}), !file.progress && /*#__PURE__*/jsx(Icon, {
|
|
112
|
-
icon: "mdi mdi-trash-can",
|
|
113
|
-
color: "danger",
|
|
114
|
-
size: "sm",
|
|
115
|
-
"aria-label": "remove",
|
|
116
|
-
onClick: function onClick() {
|
|
117
|
-
return remove(file.key);
|
|
118
|
-
}
|
|
148
|
+
}), file.progress && /*#__PURE__*/jsx(ProgressBar, {
|
|
149
|
+
animate: true,
|
|
150
|
+
value: file.progress * 100,
|
|
151
|
+
size: "xxs"
|
|
119
152
|
})]
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
value: file.progress * 100,
|
|
123
|
-
size: "xxs"
|
|
124
|
-
})]
|
|
125
|
-
}, idx);
|
|
153
|
+
}, idx)
|
|
154
|
+
);
|
|
126
155
|
})
|
|
127
156
|
})]
|
|
128
157
|
});
|
|
129
|
-
}
|
|
158
|
+
}
|
|
130
159
|
|
|
131
160
|
export { FileField };
|
|
@@ -2,33 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
4
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
|
+
import { isEmpty } from '@react-fabric/utilities';
|
|
5
6
|
import { useMemo } from 'react';
|
|
6
7
|
import { useTranslation } from 'react-i18next';
|
|
7
8
|
import { Controller } from '../form/Controller.js';
|
|
8
9
|
import { ArrayInput } from '../input/ArrayInput.js';
|
|
9
10
|
import { AvatarInput } from '../input/AvatarInput.js';
|
|
10
11
|
import { ColorInput } from '../input/ColorInput.js';
|
|
12
|
+
import { DateInput } from '../input/DateInput.js';
|
|
11
13
|
import { Input } from '../input/Input.js';
|
|
12
14
|
import { Number } from '../input/Number.js';
|
|
13
|
-
import {
|
|
15
|
+
import { RangeSlider } from '../input/RangeSlider.js';
|
|
14
16
|
import { Switch } from '../input/Switch.js';
|
|
15
17
|
import { Textarea } from '../input/Textarea.js';
|
|
16
18
|
import { Select } from '../select/Select.js';
|
|
19
|
+
import { DATA_TYPES } from '../types/schema.js';
|
|
17
20
|
import { FileField } from './FileField.js';
|
|
18
21
|
import { jsx } from '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
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
23
|
-
var
|
|
25
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).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 getField = function getField(datatype, hasOptions) {
|
|
27
|
+
if (datatype === DATA_TYPES.NUMBER) return Number;
|
|
28
|
+
if (datatype === DATA_TYPES.RANGE) return RangeSlider;
|
|
29
|
+
if (datatype === DATA_TYPES.BOOL) return Switch;
|
|
30
|
+
if (datatype === DATA_TYPES.TEXT) return Textarea;
|
|
31
|
+
if (datatype === DATA_TYPES.DATE) return DateInput;
|
|
32
|
+
if (datatype === DATA_TYPES.DATETIME) return DateInput;
|
|
33
|
+
if (datatype === DATA_TYPES.COLOR) return ColorInput;
|
|
34
|
+
if (hasOptions) return Select;
|
|
35
|
+
return Input;
|
|
36
|
+
};
|
|
37
|
+
function FormField(_ref) {
|
|
24
38
|
var id = _ref.id,
|
|
25
39
|
label = _ref.label,
|
|
26
40
|
required = _ref.required,
|
|
27
41
|
inline = _ref.inline,
|
|
28
42
|
prefix = _ref.prefix,
|
|
29
|
-
autoFocus = _ref.autoFocus
|
|
30
|
-
_ref.
|
|
31
|
-
|
|
43
|
+
autoFocus = _ref.autoFocus,
|
|
44
|
+
optionLists = _ref.optionLists,
|
|
45
|
+
fileUrl = _ref.fileUrl,
|
|
32
46
|
uploadHandler = _ref.uploadHandler,
|
|
33
47
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
34
48
|
var _useTranslation = useTranslation(),
|
|
@@ -36,48 +50,55 @@ var FormField = function FormField(_ref) {
|
|
|
36
50
|
var fieldName = useMemo(function () {
|
|
37
51
|
return [prefix, id].filter(Boolean).join(".");
|
|
38
52
|
}, [id, prefix]);
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (rest.datatype === "text") return Textarea;
|
|
44
|
-
if (rest.datatype === "color") return ColorInput;
|
|
45
|
-
if (rest.datatype === "string" && rest.options) return Select;
|
|
46
|
-
return Input;
|
|
47
|
-
}, [rest.datatype]);
|
|
53
|
+
var hasOptions = useMemo(function () {
|
|
54
|
+
var _rest$optionList;
|
|
55
|
+
return rest.datatype === DATA_TYPES.STRING && (rest.optionList === "--CUSTOM--" && !isEmpty(rest.options) || !isEmpty(optionLists === null || optionLists === void 0 ? void 0 : optionLists[(_rest$optionList = rest.optionList) !== null && _rest$optionList !== void 0 ? _rest$optionList : ""]));
|
|
56
|
+
}, [rest, optionLists]);
|
|
48
57
|
var props = useMemo(function () {
|
|
49
|
-
var _rest$step, _rest$
|
|
50
|
-
if (rest.datatype ===
|
|
58
|
+
var _rest$step, _rest$min, _rest$max, _rest$step2, _optionLists, _rest$optionList2;
|
|
59
|
+
if (rest.datatype === DATA_TYPES.NUMBER) return {
|
|
51
60
|
min: rest.min,
|
|
52
61
|
max: rest.max,
|
|
53
62
|
step: (_rest$step = rest.step) !== null && _rest$step !== void 0 ? _rest$step : 1
|
|
54
63
|
};
|
|
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 {
|
|
64
|
+
if (rest.datatype === DATA_TYPES.RANGE) return {
|
|
61
65
|
min: (_rest$min = rest.min) !== null && _rest$min !== void 0 ? _rest$min : 1,
|
|
62
66
|
max: (_rest$max = rest.max) !== null && _rest$max !== void 0 ? _rest$max : 99,
|
|
63
|
-
step: (_rest$
|
|
67
|
+
step: (_rest$step2 = rest.step) !== null && _rest$step2 !== void 0 ? _rest$step2 : 1,
|
|
64
68
|
showValue: true,
|
|
65
69
|
showLabels: true
|
|
66
70
|
};
|
|
67
|
-
if (rest.datatype ===
|
|
71
|
+
if (rest.datatype === DATA_TYPES.DATE) return {
|
|
72
|
+
min: rest.min,
|
|
73
|
+
max: rest.max,
|
|
74
|
+
type: "date"
|
|
75
|
+
};
|
|
76
|
+
if (rest.datatype === DATA_TYPES.DATETIME) return {
|
|
77
|
+
min: rest.min,
|
|
78
|
+
max: rest.max,
|
|
79
|
+
type: "datetime"
|
|
80
|
+
};
|
|
81
|
+
if (rest.datatype === DATA_TYPES.TEXT) return {
|
|
68
82
|
rows: 3
|
|
69
83
|
};
|
|
70
|
-
if (rest.datatype ===
|
|
84
|
+
if (rest.datatype === DATA_TYPES.COLOR) return {
|
|
71
85
|
showPicker: true
|
|
72
86
|
};
|
|
73
|
-
if (rest.datatype ===
|
|
74
|
-
options: rest.options,
|
|
87
|
+
if (rest.datatype === DATA_TYPES.STRING && hasOptions) return _objectSpread({
|
|
75
88
|
multiple: rest.multiple,
|
|
89
|
+
allowCreate: rest.allowCustom,
|
|
76
90
|
searchable: true
|
|
77
|
-
}
|
|
91
|
+
}, (_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 : {
|
|
92
|
+
options: rest.options
|
|
93
|
+
});
|
|
78
94
|
return {};
|
|
79
|
-
}, [rest]);
|
|
80
|
-
|
|
95
|
+
}, [rest, hasOptions, optionLists]);
|
|
96
|
+
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
98
|
+
var E = useMemo(function () {
|
|
99
|
+
return getField(rest.datatype, hasOptions);
|
|
100
|
+
}, [rest.datatype, hasOptions]);
|
|
101
|
+
if (rest.datatype === DATA_TYPES.AVATAR) return uploadHandler && /*#__PURE__*/jsx(Controller, {
|
|
81
102
|
name: fieldName,
|
|
82
103
|
children: /*#__PURE__*/jsx(AvatarInput, {
|
|
83
104
|
uploadHandler: uploadHandler,
|
|
@@ -85,7 +106,7 @@ var FormField = function FormField(_ref) {
|
|
|
85
106
|
name: fieldName
|
|
86
107
|
})
|
|
87
108
|
});
|
|
88
|
-
if (rest.datatype ===
|
|
109
|
+
if (rest.datatype === DATA_TYPES.FILE) return uploadHandler && /*#__PURE__*/jsx(Controller, {
|
|
89
110
|
name: fieldName,
|
|
90
111
|
children: /*#__PURE__*/jsx(FileField, _objectSpread({
|
|
91
112
|
uploadHandler: uploadHandler,
|
|
@@ -94,12 +115,12 @@ var FormField = function FormField(_ref) {
|
|
|
94
115
|
id: id
|
|
95
116
|
}, rest))
|
|
96
117
|
});
|
|
97
|
-
return rest.multiple && !
|
|
118
|
+
return rest.multiple && !hasOptions ? /*#__PURE__*/jsx(ArrayInput, {
|
|
98
119
|
name: fieldName,
|
|
99
|
-
label: t(
|
|
120
|
+
label: t("fb.".concat(id), label || id),
|
|
100
121
|
required: required,
|
|
101
122
|
onAdd: function onAdd() {
|
|
102
|
-
return "";
|
|
123
|
+
return String("");
|
|
103
124
|
},
|
|
104
125
|
children: /*#__PURE__*/jsx(Controller, {
|
|
105
126
|
children: /*#__PURE__*/jsx(E, _objectSpread({}, props))
|
|
@@ -108,12 +129,12 @@ var FormField = function FormField(_ref) {
|
|
|
108
129
|
name: fieldName,
|
|
109
130
|
children: /*#__PURE__*/jsx(E, _objectSpread(_objectSpread({}, props), {}, {
|
|
110
131
|
autoFocus: autoFocus,
|
|
111
|
-
label: t(
|
|
112
|
-
placeholder: t(
|
|
132
|
+
label: t("fb.".concat(id), label || id),
|
|
133
|
+
placeholder: t("fb.".concat(id), label || id),
|
|
113
134
|
required: required,
|
|
114
135
|
inline: inline
|
|
115
136
|
}))
|
|
116
137
|
});
|
|
117
|
-
}
|
|
138
|
+
}
|
|
118
139
|
|
|
119
140
|
export { FormField };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Footer } from '@react-fabric/core';
|
|
4
|
+
import { EMPTY_ARRAY } from '@react-fabric/utilities';
|
|
5
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
6
|
+
import { Form } from '../form/Form.js';
|
|
7
|
+
import { DATA_TYPES } from '../types/schema.js';
|
|
8
|
+
import { SchemaArrayForm } from './components/SchemaArrayForm.js';
|
|
9
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
10
|
+
|
|
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
|
+
function SchemaEditor(_ref) {
|
|
35
|
+
var schemaDef = _ref.schemaDef,
|
|
36
|
+
dynamic = _ref.dynamic,
|
|
37
|
+
acceptableTypes = _ref.acceptableTypes,
|
|
38
|
+
_ref$optionLists = _ref.optionLists,
|
|
39
|
+
optionLists = _ref$optionLists === void 0 ? EMPTY_ARRAY : _ref$optionLists,
|
|
40
|
+
children = _ref.children,
|
|
41
|
+
onSubmit = _ref.onSubmit,
|
|
42
|
+
onChange = _ref.onChange;
|
|
43
|
+
var formRef = useRef(null);
|
|
44
|
+
var handleChange = useCallback(function (model) {
|
|
45
|
+
onChange === null || onChange === void 0 || onChange(model.schema);
|
|
46
|
+
}, [onChange]);
|
|
47
|
+
var handleSubmit = useCallback(function (model) {
|
|
48
|
+
onSubmit === null || onSubmit === void 0 || onSubmit(model.schema);
|
|
49
|
+
}, [onSubmit]);
|
|
50
|
+
useEffect(function () {
|
|
51
|
+
var _formRef$current;
|
|
52
|
+
(_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValues({
|
|
53
|
+
schema: schemaDef
|
|
54
|
+
});
|
|
55
|
+
}, [schemaDef]);
|
|
56
|
+
return /*#__PURE__*/jsxs(Form, {
|
|
57
|
+
formRef: formRef,
|
|
58
|
+
onChange: handleChange,
|
|
59
|
+
onSubmit: handleSubmit,
|
|
60
|
+
children: [/*#__PURE__*/jsx(SchemaArrayForm, {
|
|
61
|
+
dynamic: dynamic,
|
|
62
|
+
optionLists: optionLists,
|
|
63
|
+
acceptableTypes: acceptableTypes !== null && acceptableTypes !== void 0 ? acceptableTypes : Object.values(DATA_TYPES)
|
|
64
|
+
}), children && /*#__PURE__*/jsx(Footer, {
|
|
65
|
+
flex: true,
|
|
66
|
+
className: "border-t bg-default px-6 py-2",
|
|
67
|
+
children: children
|
|
68
|
+
})]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { SchemaEditor };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import { yupResolver } from '@hookform/resolvers/yup';
|
|
5
|
+
import { Modal, Content, Footer, Button } from '@react-fabric/core';
|
|
6
|
+
import { yup } from '@react-fabric/utilities';
|
|
7
|
+
import { useCallback } from 'react';
|
|
8
|
+
import { Controller } from '../../form/Controller.js';
|
|
9
|
+
import { Form } from '../../form/Form.js';
|
|
10
|
+
import { ArrayInput } from '../../input/ArrayInput.js';
|
|
11
|
+
import { Input } from '../../input/Input.js';
|
|
12
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).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; }
|
|
16
|
+
var fieldSchema = yup.object({
|
|
17
|
+
fields: yup.array(yup.string().trim().required()).required().min(1)
|
|
18
|
+
});
|
|
19
|
+
function AddSchemaFields(props) {
|
|
20
|
+
var handleSubmit = useCallback(function (model) {
|
|
21
|
+
var _props$onClose;
|
|
22
|
+
(_props$onClose = props.onClose) === null || _props$onClose === void 0 || _props$onClose.call(props, model.fields.map(function (f) {
|
|
23
|
+
return f.split(",").map(function (ff) {
|
|
24
|
+
return ff.trim();
|
|
25
|
+
});
|
|
26
|
+
}).flat(2));
|
|
27
|
+
}, [props]);
|
|
28
|
+
return /*#__PURE__*/jsx(Modal, _objectSpread(_objectSpread({}, props), {}, {
|
|
29
|
+
children: /*#__PURE__*/jsxs(Form, {
|
|
30
|
+
resolver: yupResolver(fieldSchema),
|
|
31
|
+
defaultValues: {
|
|
32
|
+
fields: [" "]
|
|
33
|
+
},
|
|
34
|
+
onSubmit: handleSubmit,
|
|
35
|
+
children: [/*#__PURE__*/jsxs(Content, {
|
|
36
|
+
children: [/*#__PURE__*/jsx(ArrayInput, {
|
|
37
|
+
minItems: 1,
|
|
38
|
+
name: "fields",
|
|
39
|
+
onAdd: function onAdd() {
|
|
40
|
+
return String("");
|
|
41
|
+
},
|
|
42
|
+
children: /*#__PURE__*/jsx(Controller, {
|
|
43
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
44
|
+
autoFocus: true
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}), /*#__PURE__*/jsx("p", {
|
|
48
|
+
className: "text-sm text-muted",
|
|
49
|
+
children: "Provide list of fields or comma-separated value"
|
|
50
|
+
})]
|
|
51
|
+
}), /*#__PURE__*/jsx(Footer, {
|
|
52
|
+
flex: true,
|
|
53
|
+
justify: "end",
|
|
54
|
+
className: "px-2 py-1",
|
|
55
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
56
|
+
type: "submit",
|
|
57
|
+
children: "Add"
|
|
58
|
+
})
|
|
59
|
+
})]
|
|
60
|
+
})
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { AddSchemaFields };
|