@react-fabric/form 1.0.0-beta.45 → 1.0.0-beta.47
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/css/_field.css +38 -14
- package/dist/cjs/form/Form.js +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/input/ArrayInput.js +27 -10
- package/dist/cjs/input/ColorInput.js +23 -31
- package/dist/cjs/input/DateInput.js +1 -1
- package/dist/cjs/input/Field.js +1 -0
- package/dist/cjs/input/File.js +1 -1
- package/dist/cjs/input/Input.js +5 -3
- package/dist/cjs/input/Number.js +1 -1
- package/dist/cjs/input/Password.js +1 -1
- package/dist/cjs/input/RangeSlider.js +2 -2
- package/dist/cjs/input/Search.js +1 -1
- package/dist/cjs/input/Slider.js +2 -2
- package/dist/cjs/input/Textarea.js +1 -1
- package/dist/cjs/internal/InputWrapper.js +2 -2
- package/dist/cjs/select/useSelect.js +1 -1
- package/dist/esm/form/Form.js +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/input/ArrayInput.js +24 -7
- package/dist/esm/input/ColorInput.js +23 -31
- package/dist/esm/input/DateInput.js +1 -1
- package/dist/esm/input/Field.js +1 -0
- package/dist/esm/input/File.js +1 -1
- package/dist/esm/input/Input.js +5 -3
- package/dist/esm/input/Number.js +1 -1
- package/dist/esm/input/Password.js +1 -1
- package/dist/esm/input/RangeSlider.js +2 -2
- package/dist/esm/input/Search.js +1 -1
- package/dist/esm/input/Slider.js +2 -2
- package/dist/esm/input/Textarea.js +1 -1
- package/dist/esm/internal/InputWrapper.js +2 -2
- package/dist/esm/select/useSelect.js +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/input/ArrayInput.d.ts +20 -4
- package/dist/types/input/ColorInput.d.ts +1 -1
- package/dist/types/input/Input.d.ts +1 -1
- package/dist/types/types/index.d.ts +1 -0
- package/package.json +5 -5
- package/src/form/Form.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/input/ArrayInput.tsx +50 -12
- package/src/input/ColorInput.tsx +13 -42
- package/src/input/DateInput.tsx +1 -1
- package/src/input/Field.tsx +1 -0
- package/src/input/File.tsx +1 -1
- package/src/input/Input.tsx +7 -2
- package/src/input/Number.tsx +1 -1
- package/src/input/Password.tsx +1 -1
- package/src/input/RangeSlider.tsx +2 -2
- package/src/input/Search.tsx +1 -1
- package/src/input/Slider.tsx +2 -2
- package/src/input/Textarea.tsx +1 -1
- package/src/internal/InputWrapper.tsx +6 -3
- package/src/select/useSelect.tsx +1 -0
- package/src/types/index.ts +2 -0
package/css/_field.css
CHANGED
|
@@ -127,23 +127,47 @@
|
|
|
127
127
|
line-height: 1;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
130
|
+
&[data-vertical="false"] {
|
|
131
|
+
> :not(:first-child) {
|
|
132
|
+
&,
|
|
133
|
+
& > div,
|
|
134
|
+
& > [role="button"],
|
|
135
|
+
& > [data-ref="button"] > [role="button"] {
|
|
136
|
+
border-start-start-radius: 0;
|
|
137
|
+
border-end-start-radius: 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
> :not(:last-child) {
|
|
142
|
+
&,
|
|
143
|
+
& > div,
|
|
144
|
+
& > [role="button"],
|
|
145
|
+
& > [data-ref="button"] > [role="button"] {
|
|
146
|
+
border-start-end-radius: 0;
|
|
147
|
+
border-end-end-radius: 0;
|
|
148
|
+
}
|
|
137
149
|
}
|
|
138
150
|
}
|
|
139
151
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
&[data-vertical="true"] {
|
|
153
|
+
> :not(:first-child) {
|
|
154
|
+
&,
|
|
155
|
+
& > div,
|
|
156
|
+
& > [role="button"],
|
|
157
|
+
& > [data-ref="button"] > [role="button"] {
|
|
158
|
+
border-start-start-radius: 0;
|
|
159
|
+
border-start-end-radius: 0;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
> :not(:last-child) {
|
|
164
|
+
&,
|
|
165
|
+
& > div,
|
|
166
|
+
& > [role="button"],
|
|
167
|
+
& > [data-ref="button"] > [role="button"] {
|
|
168
|
+
border-end-start-radius: 0;
|
|
169
|
+
border-end-end-radius: 0;
|
|
170
|
+
}
|
|
147
171
|
}
|
|
148
172
|
}
|
|
149
173
|
}
|
package/dist/cjs/form/Form.js
CHANGED
|
@@ -37,7 +37,7 @@ var Form = function Form(_ref) {
|
|
|
37
37
|
var _useTransition = react.useTransition(),
|
|
38
38
|
_useTransition2 = _slicedToArray(_useTransition, 2),
|
|
39
39
|
startTransition = _useTransition2[1];
|
|
40
|
-
var changeHandler = core.useDebounce(onChange, [onChange]);
|
|
40
|
+
var changeHandler = core.useDebounce(onChange, [onChange], 300);
|
|
41
41
|
react.useEffect(function () {
|
|
42
42
|
var subscription = form.watch(function (value) {
|
|
43
43
|
startTransition(function () {
|
package/dist/cjs/index.js
CHANGED
|
@@ -8,6 +8,7 @@ var useFileUploader = require('./hooks/useFileUploader.js');
|
|
|
8
8
|
var useFormBuilder = require('./hooks/useFormBuilder.js');
|
|
9
9
|
var schema = require('./types/schema.js');
|
|
10
10
|
var ArrayInput = require('./input/ArrayInput.js');
|
|
11
|
+
var AvatarInput = require('./input/AvatarInput.js');
|
|
11
12
|
var Checkbox = require('./input/Checkbox.js');
|
|
12
13
|
var ColorInput = require('./input/ColorInput.js');
|
|
13
14
|
var ColorPicker = require('./input/ColorPicker.js');
|
|
@@ -40,6 +41,7 @@ exports.useFormBuilder = useFormBuilder.useFormBuilder;
|
|
|
40
41
|
exports.DATA_TYPES = schema.DATA_TYPES;
|
|
41
42
|
exports.SCHEMA_CUSTOM_LIST = schema.SCHEMA_CUSTOM_LIST;
|
|
42
43
|
exports.ArrayInput = ArrayInput.ArrayInput;
|
|
44
|
+
exports.AvatarInput = AvatarInput.AvatarInput;
|
|
43
45
|
exports.Checkbox = Checkbox.Checkbox;
|
|
44
46
|
exports.ColorInput = ColorInput.ColorInput;
|
|
45
47
|
exports.ColorPicker = ColorPicker.ColorPicker;
|
|
@@ -5,17 +5,17 @@ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProp
|
|
|
5
5
|
var core = require('@dnd-kit/core');
|
|
6
6
|
var sortable = require('@dnd-kit/sortable');
|
|
7
7
|
var core$1 = require('@react-fabric/core');
|
|
8
|
-
var utilities
|
|
8
|
+
var utilities = require('@react-fabric/utilities');
|
|
9
9
|
var classNames = require('classnames');
|
|
10
10
|
var react = require('react');
|
|
11
11
|
var reactHookForm = require('react-hook-form');
|
|
12
12
|
var reactI18next = require('react-i18next');
|
|
13
13
|
var FieldWrapper = require('../internal/FieldWrapper.js');
|
|
14
14
|
var modifiers = require('@dnd-kit/modifiers');
|
|
15
|
-
var utilities = require('@dnd-kit/utilities');
|
|
15
|
+
var utilities$1 = require('@dnd-kit/utilities');
|
|
16
16
|
var jsxRuntime = require('react/jsx-runtime');
|
|
17
17
|
|
|
18
|
-
var _excluded = ["name", "children", "addLabel", "fixedList", "focusName", "buttonPosition", "onAdd", "arrayRef", "enableSorting", "disabled", "readOnly", "minItems", "maxItems"];
|
|
18
|
+
var _excluded = ["name", "children", "addLabel", "fixedList", "focusName", "buttonPosition", "onAdd", "onRemove", "onBeforeRemove", "canRemove", "arrayRef", "enableSorting", "disabled", "readOnly", "minItems", "maxItems"];
|
|
19
19
|
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; }
|
|
20
20
|
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; }
|
|
21
21
|
var ArrayInput = function ArrayInput(_ref) {
|
|
@@ -28,6 +28,9 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
28
28
|
_ref$buttonPosition = _ref.buttonPosition,
|
|
29
29
|
buttonPosition = _ref$buttonPosition === void 0 ? "bottom" : _ref$buttonPosition,
|
|
30
30
|
onAdd = _ref.onAdd,
|
|
31
|
+
onRemove = _ref.onRemove,
|
|
32
|
+
onBeforeRemove = _ref.onBeforeRemove,
|
|
33
|
+
canRemove = _ref.canRemove,
|
|
31
34
|
arrayRef = _ref.arrayRef,
|
|
32
35
|
enableSorting = _ref.enableSorting,
|
|
33
36
|
_ref$disabled = _ref.disabled,
|
|
@@ -45,6 +48,7 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
45
48
|
if (!(form !== null && form !== void 0 && form.control)) throw new Error("ArrayInput must be contained within a Form element");
|
|
46
49
|
var _useFieldArray = reactHookForm.useFieldArray({
|
|
47
50
|
name: name,
|
|
51
|
+
keyName: "__ID__",
|
|
48
52
|
control: form.control
|
|
49
53
|
}),
|
|
50
54
|
fields = _useFieldArray.fields,
|
|
@@ -61,6 +65,15 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
61
65
|
form.setFocus("".concat(name, ".").concat(fields.length).concat(focusName ? "." + focusName : ""));
|
|
62
66
|
}, 100);
|
|
63
67
|
}, [name, fields, focusName]);
|
|
68
|
+
var handleRemove = react.useCallback(function (item, index) {
|
|
69
|
+
var ret = onBeforeRemove === null || onBeforeRemove === void 0 ? void 0 : onBeforeRemove(item, index);
|
|
70
|
+
void Promise.resolve(ret).then(function (b) {
|
|
71
|
+
if (!utilities.isFalse(b)) {
|
|
72
|
+
remove(index);
|
|
73
|
+
onRemove === null || onRemove === void 0 || onRemove(item, index);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}, [remove, onRemove, onBeforeRemove]);
|
|
64
77
|
react.useImperativeHandle(arrayRef, function () {
|
|
65
78
|
return {
|
|
66
79
|
addItem: handleAdd,
|
|
@@ -72,7 +85,7 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
72
85
|
if (enableSorting) {
|
|
73
86
|
// pass id list to dnd context
|
|
74
87
|
var idMap = fields.map(function (item) {
|
|
75
|
-
return item.
|
|
88
|
+
return item.__ID__;
|
|
76
89
|
});
|
|
77
90
|
var handleDragEnd = function handleDragEnd(e) {
|
|
78
91
|
if (e.over && e.active.id !== e.over.id) {
|
|
@@ -113,7 +126,7 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
113
126
|
className: className,
|
|
114
127
|
ref: setNodeRef,
|
|
115
128
|
style: {
|
|
116
|
-
transform: utilities.CSS.Transform.toString(transform),
|
|
129
|
+
transform: utilities$1.CSS.Transform.toString(transform),
|
|
117
130
|
transition: transition
|
|
118
131
|
},
|
|
119
132
|
children: [/*#__PURE__*/jsxRuntime.jsx(core$1.Icon, _objectSpread(_objectSpread({
|
|
@@ -135,7 +148,7 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
135
148
|
className: "flex justify-end",
|
|
136
149
|
children: /*#__PURE__*/jsxRuntime.jsx(core$1.Tooltip, {
|
|
137
150
|
color: "danger-200",
|
|
138
|
-
content: utilities
|
|
151
|
+
content: utilities.isString(error) ? "".concat(error) : t(error === null || error === void 0 ? void 0 : error.key, error !== null && error !== void 0 && error.values ? _objectSpread(_objectSpread({}, error === null || error === void 0 ? void 0 : error.values), {}, {
|
|
139
152
|
label: t((_error$values$label = (_error$values = error.values) === null || _error$values === void 0 ? void 0 : _error$values.label) !== null && _error$values$label !== void 0 ? _error$values$label : "form:badkey", (_error$values2 = error.values) === null || _error$values2 === void 0 ? void 0 : _error$values2.path)
|
|
140
153
|
}) : {}),
|
|
141
154
|
children: /*#__PURE__*/jsxRuntime.jsx(core$1.Button, {
|
|
@@ -163,7 +176,7 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
163
176
|
children: /*#__PURE__*/jsxRuntime.jsx(Wrapper, {
|
|
164
177
|
children: fields.map(function (item, index) {
|
|
165
178
|
return /*#__PURE__*/jsxRuntime.jsxs(SortableItem, {
|
|
166
|
-
id: item.
|
|
179
|
+
id: item.__ID__,
|
|
167
180
|
className: "flex items-center flex-nowrap gap-2 mb-1",
|
|
168
181
|
children: [typeof children === "function" ? children({
|
|
169
182
|
index: index,
|
|
@@ -185,12 +198,16 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
185
198
|
color: "danger",
|
|
186
199
|
variant: "link",
|
|
187
200
|
className: "self-end",
|
|
188
|
-
disabled: disabled || readOnly || fields.length <= minItems
|
|
201
|
+
disabled: disabled || readOnly || fields.length <= minItems || (canRemove === null || canRemove === void 0 ? void 0 : canRemove({
|
|
202
|
+
item: item,
|
|
203
|
+
index: index,
|
|
204
|
+
lastItem: index + 1 === fields.length
|
|
205
|
+
})) !== false,
|
|
189
206
|
onClick: function onClick() {
|
|
190
|
-
return
|
|
207
|
+
return handleRemove(item, index);
|
|
191
208
|
}
|
|
192
209
|
})]
|
|
193
|
-
}, item.
|
|
210
|
+
}, item.__ID__);
|
|
194
211
|
})
|
|
195
212
|
})
|
|
196
213
|
})), !fixedList && onAdd && buttonPosition !== "top" && addButton]
|
|
@@ -5,33 +5,30 @@ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
|
5
5
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
6
6
|
var react$1 = require('@floating-ui/react');
|
|
7
7
|
var core = require('@react-fabric/core');
|
|
8
|
-
var utilities = require('@react-fabric/utilities');
|
|
9
|
-
var classNames = require('classnames');
|
|
10
8
|
var react = require('react');
|
|
9
|
+
var InputWrapper = require('../internal/InputWrapper.js');
|
|
11
10
|
var ColorPicker = require('./ColorPicker.js');
|
|
12
11
|
var jsxRuntime = require('react/jsx-runtime');
|
|
13
12
|
|
|
14
|
-
var _excluded = ["ref", "required", "disabled", "
|
|
13
|
+
var _excluded = ["ref", "required", "disabled", "readOnly", "invalid", "error", "value", "showPicker", "defaultColor", "onBlur", "onFocus", "onChange", "noOutline"];
|
|
15
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; }
|
|
16
15
|
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
16
|
var ColorInput = function ColorInput(_ref) {
|
|
18
17
|
_ref.ref;
|
|
19
|
-
_ref.required
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
_ref.invalid
|
|
23
|
-
_ref.error
|
|
24
|
-
|
|
18
|
+
var required = _ref.required,
|
|
19
|
+
disabled = _ref.disabled,
|
|
20
|
+
readOnly = _ref.readOnly,
|
|
21
|
+
invalid = _ref.invalid,
|
|
22
|
+
error = _ref.error,
|
|
23
|
+
value = _ref.value,
|
|
25
24
|
showPicker = _ref.showPicker,
|
|
26
25
|
_ref$defaultColor = _ref.defaultColor,
|
|
27
26
|
defaultColor = _ref$defaultColor === void 0 ? "" : _ref$defaultColor,
|
|
28
|
-
decorateEnd = _ref.decorateEnd,
|
|
29
|
-
decorateStart = _ref.decorateStart,
|
|
30
27
|
onBlur = _ref.onBlur,
|
|
31
28
|
onFocus = _ref.onFocus,
|
|
32
|
-
onChange = _ref.onChange
|
|
33
|
-
|
|
34
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
+
onChange = _ref.onChange;
|
|
30
|
+
_ref.noOutline;
|
|
31
|
+
var rest = _objectWithoutProperties(_ref, _excluded);
|
|
35
32
|
var _useState = react.useState(""),
|
|
36
33
|
_useState2 = _slicedToArray(_useState, 2),
|
|
37
34
|
actualValue = _useState2[0],
|
|
@@ -70,7 +67,7 @@ var ColorInput = function ColorInput(_ref) {
|
|
|
70
67
|
floatingStyles = _useFloating.floatingStyles,
|
|
71
68
|
context = _useFloating.context;
|
|
72
69
|
var click = react$1.useClick(context, {
|
|
73
|
-
enabled: !disabled
|
|
70
|
+
enabled: !disabled && !readOnly
|
|
74
71
|
});
|
|
75
72
|
var dismiss = react$1.useDismiss(context, {
|
|
76
73
|
referencePress: true
|
|
@@ -78,12 +75,16 @@ var ColorInput = function ColorInput(_ref) {
|
|
|
78
75
|
var _useInteractions = react$1.useInteractions([dismiss, click]),
|
|
79
76
|
getReferenceProps = _useInteractions.getReferenceProps,
|
|
80
77
|
getFloatingProps = _useInteractions.getFloatingProps;
|
|
81
|
-
return /*#__PURE__*/jsxRuntime.jsxs(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
return /*#__PURE__*/jsxRuntime.jsxs(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
|
|
79
|
+
showClear: actualValue !== defaultColor && !disabled && !readOnly,
|
|
80
|
+
onClear: handleChange,
|
|
81
|
+
invalid: invalid,
|
|
82
|
+
readOnly: readOnly,
|
|
83
|
+
disabled: disabled,
|
|
84
|
+
required: required,
|
|
85
|
+
error: error
|
|
86
|
+
}, rest), {}, {
|
|
87
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("button", _objectSpread(_objectSpread({
|
|
87
88
|
"data-ref": "button",
|
|
88
89
|
className: "flex-1 flex items-center",
|
|
89
90
|
ref: refs.setReference
|
|
@@ -131,17 +132,8 @@ var ColorInput = function ColorInput(_ref) {
|
|
|
131
132
|
return handleChange(resp.sRGBHex);
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
|
-
}), decorateEnd && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
135
|
-
className: classNames("text-muted leading-none flex-content", utilities.isString(decorateEnd) && "px-2"),
|
|
136
|
-
children: decorateEnd
|
|
137
|
-
}), !disabled && allowClear && actualValue !== defaultColor && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
138
|
-
icon: core.CoreIcons.close,
|
|
139
|
-
onClick: function onClick() {
|
|
140
|
-
return handleChange();
|
|
141
|
-
},
|
|
142
|
-
className: classNames("text-tint-500 hover:text-tint-700 p-[0.25em] flex-content")
|
|
143
135
|
})]
|
|
144
|
-
});
|
|
136
|
+
}));
|
|
145
137
|
};
|
|
146
138
|
|
|
147
139
|
exports.ColorInput = ColorInput;
|
|
@@ -130,7 +130,7 @@ var DateInput = function DateInput(_ref) {
|
|
|
130
130
|
getReferenceProps = _useInteractions.getReferenceProps,
|
|
131
131
|
getFloatingProps = _useInteractions.getFloatingProps;
|
|
132
132
|
return /*#__PURE__*/jsxRuntime.jsxs(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
|
|
133
|
-
showClear: !!actualValue,
|
|
133
|
+
showClear: !!actualValue && !disabled && !readOnly,
|
|
134
134
|
onClear: handleChange,
|
|
135
135
|
invalid: invalid,
|
|
136
136
|
readOnly: readOnly,
|
package/dist/cjs/input/Field.js
CHANGED
|
@@ -20,6 +20,7 @@ var Field = function Field(_ref) {
|
|
|
20
20
|
return /*#__PURE__*/jsxRuntime.jsx(FieldWrapper.FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
|
|
21
21
|
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
22
22
|
className: classNames("fabric-fieldGroup", !plain && !noOutline && "outline", !plain && "bg-base", plain && "flex-wrap", "flex-1 rounded", !vertical && "flex"),
|
|
23
|
+
"data-vertical": !!vertical,
|
|
23
24
|
children: core.cloneChildren(children, function (child) {
|
|
24
25
|
return /*#__PURE__*/react.cloneElement(child, {
|
|
25
26
|
"data-inner": true
|
package/dist/cjs/input/File.js
CHANGED
|
@@ -99,7 +99,7 @@ var FileInput = function FileInput(_ref) {
|
|
|
99
99
|
onChange === null || onChange === void 0 || onChange(listRef.current);
|
|
100
100
|
}, [onChange]);
|
|
101
101
|
return /*#__PURE__*/jsxRuntime.jsx(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
|
|
102
|
-
showClear: !utilities.isEmpty(actualValue),
|
|
102
|
+
showClear: !utilities.isEmpty(actualValue) && !disabled && !readOnly,
|
|
103
103
|
onClear: handleChange,
|
|
104
104
|
invalid: invalid,
|
|
105
105
|
readOnly: readOnly,
|
package/dist/cjs/input/Input.js
CHANGED
|
@@ -7,9 +7,10 @@ var react = require('react');
|
|
|
7
7
|
var InputWrapper = require('../internal/InputWrapper.js');
|
|
8
8
|
var eventHandlers = require('../utils/eventHandlers.js');
|
|
9
9
|
require('@react-fabric/utilities');
|
|
10
|
+
var classNames = require('classnames');
|
|
10
11
|
var jsxRuntime = require('react/jsx-runtime');
|
|
11
12
|
|
|
12
|
-
var _excluded = ["ref", "name", "value", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "error", "type", "onBlur", "onFocus", "onChange", "onEnterPressed"];
|
|
13
|
+
var _excluded = ["ref", "name", "value", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "error", "monospace", "type", "onBlur", "onFocus", "onChange", "onEnterPressed"];
|
|
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; }
|
|
14
15
|
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
16
|
var Input = function Input(_ref) {
|
|
@@ -23,6 +24,7 @@ var Input = function Input(_ref) {
|
|
|
23
24
|
placeholder = _ref.placeholder,
|
|
24
25
|
autoFocus = _ref.autoFocus,
|
|
25
26
|
error = _ref.error,
|
|
27
|
+
monospace = _ref.monospace,
|
|
26
28
|
_ref$type = _ref.type,
|
|
27
29
|
type = _ref$type === void 0 ? "text" : _ref$type,
|
|
28
30
|
onBlur = _ref.onBlur,
|
|
@@ -47,7 +49,7 @@ var Input = function Input(_ref) {
|
|
|
47
49
|
onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
|
|
48
50
|
}, [onchange]);
|
|
49
51
|
return /*#__PURE__*/jsxRuntime.jsx(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
|
|
50
|
-
showClear: !!actualValue,
|
|
52
|
+
showClear: !!actualValue && !disabled && !readOnly,
|
|
51
53
|
onClear: handleChange,
|
|
52
54
|
invalid: invalid,
|
|
53
55
|
readOnly: readOnly,
|
|
@@ -56,7 +58,7 @@ var Input = function Input(_ref) {
|
|
|
56
58
|
error: error
|
|
57
59
|
}, rest), {}, {
|
|
58
60
|
children: /*#__PURE__*/jsxRuntime.jsx("input", {
|
|
59
|
-
className: "appearance-none bg-transparent py-1 px-2 flex-1 border-none outline-none ring-0 peer",
|
|
61
|
+
className: classNames("appearance-none bg-transparent py-1 px-2 flex-1 border-none outline-none ring-0 peer", monospace && "font-mono text-sm"),
|
|
60
62
|
"aria-invalid": invalid,
|
|
61
63
|
"aria-disabled": disabled,
|
|
62
64
|
"aria-readonly": readOnly,
|
package/dist/cjs/input/Number.js
CHANGED
|
@@ -47,7 +47,7 @@ var Number = function Number(_ref) {
|
|
|
47
47
|
onChange === null || onChange === void 0 || onChange(number !== null && number !== void 0 ? number : null);
|
|
48
48
|
}, [onChange]);
|
|
49
49
|
return /*#__PURE__*/jsxRuntime.jsx(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
|
|
50
|
-
showClear: !!actualValue,
|
|
50
|
+
showClear: !!actualValue && !disabled && !readOnly,
|
|
51
51
|
onClear: handleChange,
|
|
52
52
|
invalid: invalid,
|
|
53
53
|
readOnly: readOnly,
|
|
@@ -55,7 +55,7 @@ var Password = function Password(_ref) {
|
|
|
55
55
|
onChange === null || onChange === void 0 || onChange(value !== null && value !== void 0 ? value : null);
|
|
56
56
|
}, [onChange]);
|
|
57
57
|
return /*#__PURE__*/jsxRuntime.jsxs(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
|
|
58
|
-
showClear: !!actualValue,
|
|
58
|
+
showClear: !!actualValue && !disabled && !readOnly,
|
|
59
59
|
onClear: handleChange,
|
|
60
60
|
invalid: invalid,
|
|
61
61
|
readOnly: readOnly,
|
|
@@ -114,14 +114,14 @@ var RangeSlider = function RangeSlider(_ref) {
|
|
|
114
114
|
isReadOnly: readOnly,
|
|
115
115
|
canClear: !!actualValue,
|
|
116
116
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
117
|
-
className: classNames("flex-
|
|
117
|
+
className: classNames("flex-1 order-3 flex items-center select-none z-0", vertical && "flex-col w-8", invalid ? "text-danger-500" : "text-primary-600"),
|
|
118
118
|
"data-vertical": !!vertical,
|
|
119
119
|
style: invalid ? undefined : {
|
|
120
120
|
color: color
|
|
121
121
|
},
|
|
122
122
|
children: [showLabels && (vertical ? maxDisplay : minDisplay), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
123
123
|
ref: rangerInstance.trackElRef,
|
|
124
|
-
className: classNames("flex-
|
|
124
|
+
className: classNames("flex-1 relative flex items-center", vertical ? "my-2 w-8" : "mx-2 h-8"),
|
|
125
125
|
style: {
|
|
126
126
|
height: vertical ? height : undefined
|
|
127
127
|
},
|
package/dist/cjs/input/Search.js
CHANGED
|
@@ -62,7 +62,7 @@ var Search = function Search(_ref) {
|
|
|
62
62
|
}
|
|
63
63
|
}, [onChange, searchOnChange, handleSearch]);
|
|
64
64
|
return /*#__PURE__*/jsxRuntime.jsx(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
|
|
65
|
-
showClear: !!actualValue,
|
|
65
|
+
showClear: !!actualValue && !disabled && !readOnly,
|
|
66
66
|
onClear: handleChange,
|
|
67
67
|
allowClear: allowClear,
|
|
68
68
|
invalid: invalid,
|
package/dist/cjs/input/Slider.js
CHANGED
|
@@ -116,14 +116,14 @@ var Slider = function Slider(_ref) {
|
|
|
116
116
|
isReadOnly: readOnly,
|
|
117
117
|
canClear: !!actualValue,
|
|
118
118
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
119
|
-
className: classNames("flex-
|
|
119
|
+
className: classNames("flex-1 order-3 flex items-center select-none relative z-0", vertical && "flex-col w-8", invalid ? "text-danger-500" : "text-primary-600"),
|
|
120
120
|
"data-vertical": !!vertical,
|
|
121
121
|
style: invalid ? undefined : {
|
|
122
122
|
color: color
|
|
123
123
|
},
|
|
124
124
|
children: [showLabels && (vertical ? maxDisplay : minDisplay), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
125
125
|
ref: rangerInstance.trackElRef,
|
|
126
|
-
className: classNames("flex-
|
|
126
|
+
className: classNames("flex-1 relative flex items-center", vertical ? "my-2 w-8" : "mx-2 h-8"),
|
|
127
127
|
style: {
|
|
128
128
|
height: vertical ? height : undefined
|
|
129
129
|
},
|
|
@@ -61,7 +61,7 @@ var Textarea = function Textarea(_ref) {
|
|
|
61
61
|
}
|
|
62
62
|
}, [actualValue, variableRows, rows, maxRows]);
|
|
63
63
|
return /*#__PURE__*/jsxRuntime.jsx(InputWrapper.InputWrapper, _objectSpread(_objectSpread({
|
|
64
|
-
showClear: !!actualValue,
|
|
64
|
+
showClear: !!actualValue && !disabled && !readOnly,
|
|
65
65
|
onClear: handleChange,
|
|
66
66
|
invalid: invalid,
|
|
67
67
|
readOnly: readOnly,
|
|
@@ -69,7 +69,7 @@ var InputWrapper = function InputWrapper(_ref) {
|
|
|
69
69
|
var el = /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
70
70
|
role: "none",
|
|
71
71
|
ref: wrapperRef,
|
|
72
|
-
className: classNames("fabric-inputWrapper", invalid && "fabric-invalidWrapper", !noOutline && !noBorder && "bg-(--fabric-input) outline
|
|
72
|
+
className: classNames("fabric-inputWrapper", invalid && "fabric-invalidWrapper", !noOutline && !noBorder && "bg-(--fabric-input) outline overflow-hidden", "flex flex-nowrap items-center flex-1", textarea ? "rounded-capped group" : "rounded", isExpanded ? "fixed inset-4 z-[99]" : floatingExpand ? "absolute inset-x-0" : "relative", !noOutline && "after:absolute after:bottom-0 after:h-px after:bg-primary-500 after:mx-auto"),
|
|
73
73
|
onKeyDown: function onKeyDown(e) {
|
|
74
74
|
return e.key === "Escape" && isExpanded && (setExpanded(false), e.stopPropagation());
|
|
75
75
|
},
|
|
@@ -103,7 +103,7 @@ var InputWrapper = function InputWrapper(_ref) {
|
|
|
103
103
|
return /*#__PURE__*/jsxRuntime.jsx(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
|
|
104
104
|
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
105
105
|
ref: elRef,
|
|
106
|
-
className: "
|
|
106
|
+
className: classNames("relative min-h-8 flex flex-col flex-nowrap", width ? "flex-auto" : "flex-1"),
|
|
107
107
|
style: {
|
|
108
108
|
width: width,
|
|
109
109
|
flexBasis: width
|
package/dist/esm/form/Form.js
CHANGED
|
@@ -37,7 +37,7 @@ var Form = function Form(_ref) {
|
|
|
37
37
|
var _useTransition = useTransition(),
|
|
38
38
|
_useTransition2 = _slicedToArray(_useTransition, 2),
|
|
39
39
|
startTransition = _useTransition2[1];
|
|
40
|
-
var changeHandler = useDebounce(onChange, [onChange]);
|
|
40
|
+
var changeHandler = useDebounce(onChange, [onChange], 300);
|
|
41
41
|
useEffect(function () {
|
|
42
42
|
var subscription = form.watch(function (value) {
|
|
43
43
|
startTransition(function () {
|
package/dist/esm/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { useFileUploader } from './hooks/useFileUploader.js';
|
|
|
8
8
|
export { useFormBuilder } from './hooks/useFormBuilder.js';
|
|
9
9
|
export { DATA_TYPES, SCHEMA_CUSTOM_LIST } from './types/schema.js';
|
|
10
10
|
export { ArrayInput } from './input/ArrayInput.js';
|
|
11
|
+
export { AvatarInput } from './input/AvatarInput.js';
|
|
11
12
|
export { Checkbox } from './input/Checkbox.js';
|
|
12
13
|
export { ColorInput } from './input/ColorInput.js';
|
|
13
14
|
export { ColorPicker } from './input/ColorPicker.js';
|
|
@@ -5,7 +5,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
|
|
|
5
5
|
import { DndContext } from '@dnd-kit/core';
|
|
6
6
|
import { SortableContext, useSortable } from '@dnd-kit/sortable';
|
|
7
7
|
import { Icon, CoreIcons, Tooltip, Button, cloneChildren } from '@react-fabric/core';
|
|
8
|
-
import { isString } from '@react-fabric/utilities';
|
|
8
|
+
import { isFalse, isString } from '@react-fabric/utilities';
|
|
9
9
|
import classNames from 'classnames';
|
|
10
10
|
import { useMemo, useCallback, useImperativeHandle, cloneElement } from 'react';
|
|
11
11
|
import { useFormContext, useFieldArray } from 'react-hook-form';
|
|
@@ -15,7 +15,7 @@ import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
|
|
|
15
15
|
import { CSS } from '@dnd-kit/utilities';
|
|
16
16
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
17
17
|
|
|
18
|
-
var _excluded = ["name", "children", "addLabel", "fixedList", "focusName", "buttonPosition", "onAdd", "arrayRef", "enableSorting", "disabled", "readOnly", "minItems", "maxItems"];
|
|
18
|
+
var _excluded = ["name", "children", "addLabel", "fixedList", "focusName", "buttonPosition", "onAdd", "onRemove", "onBeforeRemove", "canRemove", "arrayRef", "enableSorting", "disabled", "readOnly", "minItems", "maxItems"];
|
|
19
19
|
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; }
|
|
20
20
|
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; }
|
|
21
21
|
var ArrayInput = function ArrayInput(_ref) {
|
|
@@ -28,6 +28,9 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
28
28
|
_ref$buttonPosition = _ref.buttonPosition,
|
|
29
29
|
buttonPosition = _ref$buttonPosition === void 0 ? "bottom" : _ref$buttonPosition,
|
|
30
30
|
onAdd = _ref.onAdd,
|
|
31
|
+
onRemove = _ref.onRemove,
|
|
32
|
+
onBeforeRemove = _ref.onBeforeRemove,
|
|
33
|
+
canRemove = _ref.canRemove,
|
|
31
34
|
arrayRef = _ref.arrayRef,
|
|
32
35
|
enableSorting = _ref.enableSorting,
|
|
33
36
|
_ref$disabled = _ref.disabled,
|
|
@@ -45,6 +48,7 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
45
48
|
if (!(form !== null && form !== void 0 && form.control)) throw new Error("ArrayInput must be contained within a Form element");
|
|
46
49
|
var _useFieldArray = useFieldArray({
|
|
47
50
|
name: name,
|
|
51
|
+
keyName: "__ID__",
|
|
48
52
|
control: form.control
|
|
49
53
|
}),
|
|
50
54
|
fields = _useFieldArray.fields,
|
|
@@ -61,6 +65,15 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
61
65
|
form.setFocus("".concat(name, ".").concat(fields.length).concat(focusName ? "." + focusName : ""));
|
|
62
66
|
}, 100);
|
|
63
67
|
}, [name, fields, focusName]);
|
|
68
|
+
var handleRemove = useCallback(function (item, index) {
|
|
69
|
+
var ret = onBeforeRemove === null || onBeforeRemove === void 0 ? void 0 : onBeforeRemove(item, index);
|
|
70
|
+
void Promise.resolve(ret).then(function (b) {
|
|
71
|
+
if (!isFalse(b)) {
|
|
72
|
+
remove(index);
|
|
73
|
+
onRemove === null || onRemove === void 0 || onRemove(item, index);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}, [remove, onRemove, onBeforeRemove]);
|
|
64
77
|
useImperativeHandle(arrayRef, function () {
|
|
65
78
|
return {
|
|
66
79
|
addItem: handleAdd,
|
|
@@ -72,7 +85,7 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
72
85
|
if (enableSorting) {
|
|
73
86
|
// pass id list to dnd context
|
|
74
87
|
var idMap = fields.map(function (item) {
|
|
75
|
-
return item.
|
|
88
|
+
return item.__ID__;
|
|
76
89
|
});
|
|
77
90
|
var handleDragEnd = function handleDragEnd(e) {
|
|
78
91
|
if (e.over && e.active.id !== e.over.id) {
|
|
@@ -163,7 +176,7 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
163
176
|
children: /*#__PURE__*/jsx(Wrapper, {
|
|
164
177
|
children: fields.map(function (item, index) {
|
|
165
178
|
return /*#__PURE__*/jsxs(SortableItem, {
|
|
166
|
-
id: item.
|
|
179
|
+
id: item.__ID__,
|
|
167
180
|
className: "flex items-center flex-nowrap gap-2 mb-1",
|
|
168
181
|
children: [typeof children === "function" ? children({
|
|
169
182
|
index: index,
|
|
@@ -185,12 +198,16 @@ var ArrayInput = function ArrayInput(_ref) {
|
|
|
185
198
|
color: "danger",
|
|
186
199
|
variant: "link",
|
|
187
200
|
className: "self-end",
|
|
188
|
-
disabled: disabled || readOnly || fields.length <= minItems
|
|
201
|
+
disabled: disabled || readOnly || fields.length <= minItems || (canRemove === null || canRemove === void 0 ? void 0 : canRemove({
|
|
202
|
+
item: item,
|
|
203
|
+
index: index,
|
|
204
|
+
lastItem: index + 1 === fields.length
|
|
205
|
+
})) !== false,
|
|
189
206
|
onClick: function onClick() {
|
|
190
|
-
return
|
|
207
|
+
return handleRemove(item, index);
|
|
191
208
|
}
|
|
192
209
|
})]
|
|
193
|
-
}, item.
|
|
210
|
+
}, item.__ID__);
|
|
194
211
|
})
|
|
195
212
|
})
|
|
196
213
|
})), !fixedList && onAdd && buttonPosition !== "top" && addButton]
|