@react-fabric/form 1.0.0-beta.32 → 1.0.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/FileField.js +4 -4
- package/dist/cjs/builder/FormField.js +41 -31
- package/dist/cjs/builder/SchemaEditor.js +428 -0
- package/dist/cjs/form/Controller.js +1 -1
- package/dist/cjs/form/Form.js +3 -4
- package/dist/cjs/hooks/useFormBuilder.js +27 -15
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/input/Checkbox.js +4 -3
- package/dist/cjs/input/DateInput.js +183 -0
- package/dist/cjs/input/Field.js +1 -1
- package/dist/cjs/input/{Range.js → RangeSlider.js} +2 -2
- package/dist/cjs/input/Switch.js +4 -3
- package/dist/cjs/internal/Field.module.css +1 -1
- package/dist/cjs/internal/InputWrapper.js +4 -2
- package/dist/cjs/types/schema.js +40 -0
- package/dist/esm/builder/FileField.js +4 -4
- package/dist/esm/builder/FormField.js +41 -31
- package/dist/esm/builder/SchemaEditor.js +428 -0
- package/dist/esm/form/Controller.js +1 -1
- package/dist/esm/form/Form.js +4 -5
- package/dist/esm/hooks/useFormBuilder.js +25 -13
- package/dist/esm/index.js +4 -1
- package/dist/esm/input/Checkbox.js +4 -3
- package/dist/esm/input/DateInput.js +183 -0
- package/dist/esm/input/Field.js +1 -1
- package/dist/esm/input/{Range.js → RangeSlider.js} +2 -2
- package/dist/esm/input/Switch.js +4 -3
- package/dist/esm/internal/Field.module.css +1 -1
- package/dist/esm/internal/InputWrapper.js +4 -2
- package/dist/esm/types/schema.js +40 -0
- package/dist/types/builder/FileField.d.ts +2 -2
- package/dist/types/builder/FormField.d.ts +3 -1
- package/dist/types/builder/SchemaEditor.d.ts +10 -0
- package/dist/types/form/Controller.d.ts +1 -1
- package/dist/types/form/Form.d.ts +5 -1
- package/dist/types/hooks/useFormBuilder.d.ts +3 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/input/Checkbox.d.ts +4 -3
- package/dist/types/input/DateInput.d.ts +19 -0
- package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +1 -1
- package/dist/types/input/Switch.d.ts +1 -1
- package/dist/types/internal/InputWrapper.d.ts +1 -1
- package/dist/types/types/index.d.ts +6 -2
- package/dist/types/types/schema.d.ts +52 -33
- package/package.json +5 -4
- package/src/builder/FileField.tsx +5 -4
- package/src/builder/FormField.tsx +42 -29
- package/src/builder/SchemaEditor.tsx +441 -0
- package/src/form/Controller.tsx +2 -2
- package/src/form/Form.tsx +6 -4
- package/src/hooks/useFormBuilder.tsx +29 -15
- package/src/index.ts +5 -2
- package/src/input/Checkbox.tsx +4 -3
- package/src/input/DateInput.tsx +248 -0
- package/src/input/Field.tsx +2 -1
- package/src/input/{Range.tsx → RangeSlider.tsx} +1 -1
- package/src/input/Switch.tsx +2 -0
- package/src/internal/Field.module.css +12 -1
- package/src/internal/InputWrapper.tsx +5 -0
- package/src/types/index.ts +8 -4
- package/src/types/schema.ts +65 -41
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
6
|
+
import { useFloating, autoUpdate, shift, flip, offset, arrow, useFocus, useClick, useDismiss, useInteractions, FloatingArrow } from '@floating-ui/react';
|
|
7
|
+
import { DateUtil, DatePanel } from '@react-fabric/date';
|
|
8
|
+
import { mergeRefs } from '@react-fabric/utilities';
|
|
9
|
+
import { useState, useDeferredValue, useMemo, useEffect, useCallback, startTransition, useRef } from 'react';
|
|
10
|
+
import { InputWrapper } from '../internal/InputWrapper.js';
|
|
11
|
+
import { handleEnter } from '../utils/eventHandlers.js';
|
|
12
|
+
import classNames from 'classnames';
|
|
13
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
|
+
|
|
15
|
+
var _excluded = ["ref", "name", "value", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "error", "type", "onChange", "onEnterPressed", "format", "min", "max"];
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
var DateInput = function DateInput(_ref) {
|
|
19
|
+
var ref = _ref.ref,
|
|
20
|
+
name = _ref.name,
|
|
21
|
+
value = _ref.value,
|
|
22
|
+
invalid = _ref.invalid,
|
|
23
|
+
readOnly = _ref.readOnly,
|
|
24
|
+
disabled = _ref.disabled,
|
|
25
|
+
required = _ref.required,
|
|
26
|
+
placeholder = _ref.placeholder,
|
|
27
|
+
autoFocus = _ref.autoFocus,
|
|
28
|
+
error = _ref.error,
|
|
29
|
+
_ref$type = _ref.type,
|
|
30
|
+
type = _ref$type === void 0 ? "date" : _ref$type,
|
|
31
|
+
onChange = _ref.onChange,
|
|
32
|
+
onEnterPressed = _ref.onEnterPressed;
|
|
33
|
+
_ref.format;
|
|
34
|
+
var min = _ref.min,
|
|
35
|
+
max = _ref.max,
|
|
36
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
37
|
+
var _useState = useState(""),
|
|
38
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
+
actualValue = _useState2[0],
|
|
40
|
+
setActualValue = _useState2[1];
|
|
41
|
+
var _useState3 = useState(""),
|
|
42
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
43
|
+
inputValue = _useState4[0],
|
|
44
|
+
setInputValue = _useState4[1];
|
|
45
|
+
var deferred = useDeferredValue(value);
|
|
46
|
+
var inputFormat = useMemo(function () {
|
|
47
|
+
return type === "datetime" ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd";
|
|
48
|
+
}, [type]);
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
setActualValue(deferred !== null && deferred !== void 0 ? deferred : "");
|
|
51
|
+
setInputValue(deferred ? DateUtil.format(deferred, inputFormat) : "");
|
|
52
|
+
}, [deferred, inputFormat]);
|
|
53
|
+
var handleEnterPressed = useMemo(function () {
|
|
54
|
+
return handleEnter(onEnterPressed);
|
|
55
|
+
}, [onEnterPressed]);
|
|
56
|
+
var handleChange = useCallback(function (e) {
|
|
57
|
+
var value = e === null || e === void 0 ? void 0 : e.currentTarget.value;
|
|
58
|
+
if (value) {
|
|
59
|
+
var _parsed$toISOString;
|
|
60
|
+
var parsed = DateUtil.parseDate(value);
|
|
61
|
+
setActualValue(parsed === null || parsed === void 0 || (_parsed$toISOString = parsed.toISOString) === null || _parsed$toISOString === void 0 ? void 0 : _parsed$toISOString.call(parsed));
|
|
62
|
+
setInputValue(DateUtil.format(parsed, inputFormat));
|
|
63
|
+
onChange != null && startTransition(function () {
|
|
64
|
+
var _parsed$toISOString2;
|
|
65
|
+
return onChange(parsed === null || parsed === void 0 || (_parsed$toISOString2 = parsed.toISOString) === null || _parsed$toISOString2 === void 0 ? void 0 : _parsed$toISOString2.call(parsed));
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
setActualValue("");
|
|
69
|
+
setInputValue("");
|
|
70
|
+
onChange != null && startTransition(function () {
|
|
71
|
+
return onChange("");
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}, [onChange, inputFormat]);
|
|
75
|
+
var handleDateChange = useCallback(function (value) {
|
|
76
|
+
if (value) {
|
|
77
|
+
var _parsed$toISOString3;
|
|
78
|
+
var parsed = DateUtil.parseDate(value);
|
|
79
|
+
setActualValue(parsed === null || parsed === void 0 || (_parsed$toISOString3 = parsed.toISOString) === null || _parsed$toISOString3 === void 0 ? void 0 : _parsed$toISOString3.call(parsed));
|
|
80
|
+
setInputValue(DateUtil.format(parsed, inputFormat));
|
|
81
|
+
onChange != null && startTransition(function () {
|
|
82
|
+
var _parsed$toISOString4;
|
|
83
|
+
return onChange(parsed === null || parsed === void 0 || (_parsed$toISOString4 = parsed.toISOString) === null || _parsed$toISOString4 === void 0 ? void 0 : _parsed$toISOString4.call(parsed));
|
|
84
|
+
});
|
|
85
|
+
} else {
|
|
86
|
+
setActualValue("");
|
|
87
|
+
setInputValue("");
|
|
88
|
+
onChange != null && startTransition(function () {
|
|
89
|
+
return onChange("");
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}, [onChange, inputFormat]);
|
|
93
|
+
var arrowRef = useRef(null);
|
|
94
|
+
var _useState5 = useState(false),
|
|
95
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
96
|
+
isOpen = _useState6[0],
|
|
97
|
+
setIsOpen = _useState6[1];
|
|
98
|
+
var _useFloating = useFloating({
|
|
99
|
+
open: isOpen,
|
|
100
|
+
onOpenChange: function onOpenChange(open, _, reason) {
|
|
101
|
+
console.log(reason);
|
|
102
|
+
if (reason === "reference-press") return;
|
|
103
|
+
setIsOpen(open);
|
|
104
|
+
},
|
|
105
|
+
strategy: "fixed",
|
|
106
|
+
placement: "bottom-start",
|
|
107
|
+
whileElementsMounted: autoUpdate,
|
|
108
|
+
middleware: [shift({
|
|
109
|
+
padding: 8
|
|
110
|
+
}), flip(), offset(9), arrow({
|
|
111
|
+
element: arrowRef
|
|
112
|
+
})]
|
|
113
|
+
}),
|
|
114
|
+
refs = _useFloating.refs,
|
|
115
|
+
floatingStyles = _useFloating.floatingStyles,
|
|
116
|
+
context = _useFloating.context;
|
|
117
|
+
var focus = useFocus(context, {
|
|
118
|
+
enabled: !disabled
|
|
119
|
+
});
|
|
120
|
+
var click = useClick(context, {
|
|
121
|
+
enabled: !disabled,
|
|
122
|
+
toggle: false
|
|
123
|
+
});
|
|
124
|
+
var dismiss = useDismiss(context, {
|
|
125
|
+
referencePress: true
|
|
126
|
+
});
|
|
127
|
+
var _useInteractions = useInteractions([dismiss, click, focus]),
|
|
128
|
+
getReferenceProps = _useInteractions.getReferenceProps,
|
|
129
|
+
getFloatingProps = _useInteractions.getFloatingProps;
|
|
130
|
+
return /*#__PURE__*/jsxs(InputWrapper, _objectSpread(_objectSpread({
|
|
131
|
+
showClear: !!actualValue,
|
|
132
|
+
onClear: handleChange,
|
|
133
|
+
invalid: invalid,
|
|
134
|
+
readOnly: readOnly,
|
|
135
|
+
disabled: disabled,
|
|
136
|
+
required: required,
|
|
137
|
+
error: error
|
|
138
|
+
}, rest), {}, {
|
|
139
|
+
children: [/*#__PURE__*/jsx("input", _objectSpread(_objectSpread({
|
|
140
|
+
className: classNames("appearance-none bg-transparent py-1 px-2 flex-1 border-none outline-none ring-0 peer", !value && "empty"),
|
|
141
|
+
"aria-invalid": invalid,
|
|
142
|
+
"aria-disabled": disabled,
|
|
143
|
+
"aria-readonly": readOnly,
|
|
144
|
+
"aria-errormessage": error,
|
|
145
|
+
placeholder: placeholder,
|
|
146
|
+
disabled: disabled,
|
|
147
|
+
readOnly: readOnly,
|
|
148
|
+
"data-testid": name,
|
|
149
|
+
name: name,
|
|
150
|
+
size: 1,
|
|
151
|
+
type: type === "datetime" ? "datetime-local" : "date",
|
|
152
|
+
autoComplete: "off",
|
|
153
|
+
autoFocus: autoFocus,
|
|
154
|
+
value: inputValue,
|
|
155
|
+
ref: mergeRefs(ref, refs.setReference)
|
|
156
|
+
}, getReferenceProps()), {}, {
|
|
157
|
+
onChange: handleChange,
|
|
158
|
+
onKeyDown: handleEnterPressed
|
|
159
|
+
})), isOpen && /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
|
|
160
|
+
ref: refs.setFloating,
|
|
161
|
+
style: _objectSpread({
|
|
162
|
+
zIndex: "var(--z-popover)"
|
|
163
|
+
}, floatingStyles),
|
|
164
|
+
className: "shadow-lg bg-base ring-1 ring-tint-100",
|
|
165
|
+
"data-ref": "dropdownBody"
|
|
166
|
+
}, getFloatingProps()), {}, {
|
|
167
|
+
children: [/*#__PURE__*/jsx(DatePanel, {
|
|
168
|
+
withTime: type === "datetime",
|
|
169
|
+
value: actualValue,
|
|
170
|
+
max: max,
|
|
171
|
+
min: min,
|
|
172
|
+
onChange: handleDateChange
|
|
173
|
+
}), /*#__PURE__*/jsx(FloatingArrow, {
|
|
174
|
+
ref: arrowRef,
|
|
175
|
+
context: context,
|
|
176
|
+
strokeWidth: 0.5,
|
|
177
|
+
className: "fill-base stroke-muted"
|
|
178
|
+
})]
|
|
179
|
+
}))]
|
|
180
|
+
}));
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export { DateInput };
|
package/dist/esm/input/Field.js
CHANGED
|
@@ -20,7 +20,7 @@ var Field = function Field(_ref) {
|
|
|
20
20
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
21
21
|
return /*#__PURE__*/jsx(FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
|
|
22
22
|
children: /*#__PURE__*/jsx("div", {
|
|
23
|
-
className: classNames(classes.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", "flex-1 rounded", !vertical && "flex
|
|
23
|
+
className: classNames(classes.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", plain && "flex-wrap", "flex-1 rounded", !vertical && "flex"),
|
|
24
24
|
children: cloneChildren(children, function (child) {
|
|
25
25
|
return /*#__PURE__*/cloneElement(child, {
|
|
26
26
|
"data-inner": true
|
|
@@ -16,7 +16,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
16
16
|
/**
|
|
17
17
|
* Number Range input
|
|
18
18
|
*/
|
|
19
|
-
var
|
|
19
|
+
var RangeSlider = function RangeSlider(_ref) {
|
|
20
20
|
var error = _ref.error;
|
|
21
21
|
_ref.name;
|
|
22
22
|
var value = _ref.value,
|
|
@@ -166,4 +166,4 @@ var Range = function Range(_ref) {
|
|
|
166
166
|
}));
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
-
export {
|
|
169
|
+
export { RangeSlider };
|
package/dist/esm/input/Switch.js
CHANGED
|
@@ -10,7 +10,7 @@ import '@react-fabric/utilities';
|
|
|
10
10
|
import { getBgClass, getColor, getColorClass } from '../utils/getColor.js';
|
|
11
11
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
12
12
|
|
|
13
|
-
var _excluded = ["ref", "label", "checked", "invalid", "disabled", "error", "width", "color", "name", "onLabel", "offLabel", "onLabelColor", "offLabelColor", "defaultColor", "onChange"];
|
|
13
|
+
var _excluded = ["ref", "label", "checked", "invalid", "disabled", "error", "width", "color", "name", "onLabel", "offLabel", "onLabelColor", "offLabelColor", "defaultColor", "required", "onChange"];
|
|
14
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
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; }
|
|
16
16
|
var Switch = function Switch(_ref) {
|
|
@@ -27,8 +27,9 @@ var Switch = function Switch(_ref) {
|
|
|
27
27
|
offLabel = _ref.offLabel,
|
|
28
28
|
onLabelColor = _ref.onLabelColor,
|
|
29
29
|
offLabelColor = _ref.offLabelColor,
|
|
30
|
-
defaultColor = _ref.defaultColor
|
|
31
|
-
|
|
30
|
+
defaultColor = _ref.defaultColor;
|
|
31
|
+
_ref.required;
|
|
32
|
+
var onChange = _ref.onChange,
|
|
32
33
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
33
34
|
var _useState = useState(false),
|
|
34
35
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
@layer comp{}@layer var{.inputWrapper{&:after{inset-inline:50%;transition:all .3s;transition-delay:.1s}& .decorate:has([data-ref=button]){align-self:stretch;display:flex}&:has(input[disabled],textarea[disabled]){background-color:theme(colors.tint.50);cursor:not-allowed;& input,& textarea{cursor:not-allowed}}&:focus-within,&:has([data-open=true]){background-color:var(--fabric-input-focus);outline-color:var(--primary);z-index:1;&:not(:has([aria-readonly=true]:not([hidden]))):after{inset-inline:0}}&:global(.fixed){box-shadow:0 0 2rem .5rem var(--fabric-shadow)}& input,& textarea{max-width:100%}&>input[type=number]+.inputClear{margin-inline:-3rem
|
|
1
|
+
@layer comp{}@layer var{.inputWrapper{&:after{inset-inline:50%;transition:all .3s;transition-delay:.1s}& .decorate:has([data-ref=button]){align-self:stretch;display:flex}&:has(input[disabled],textarea[disabled]){background-color:theme(colors.tint.50);cursor:not-allowed;& input,& textarea{cursor:not-allowed}}&:focus-within,&:has([data-open=true]){background-color:var(--fabric-input-focus);outline-color:var(--primary);z-index:1;&:not(:has([aria-readonly=true]:not([hidden]))):after{inset-inline:0}}&:global(.fixed){box-shadow:0 0 2rem .5rem var(--fabric-shadow)}& input,& textarea{max-width:100%}&>input[type=number]+.inputClear{margin-inline:-3rem 0}& input::-ms-clear,& select::-ms-clear,& textarea::-ms-clear{display:none}& input[type=search]::-webkit-search-cancel-button{display:none}& input[type=password]:not(:placeholder-shown){font-family:caption;letter-spacing:2px}& input[type=date]::-webkit-calendar-picker-indicator,& input[type=datetime-local]::-webkit-calendar-picker-indicator{appearance:none;display:none}& input[type=date]:global(.empty)::-webkit-datetime-edit,& input[type=datetime-local]:global(.empty)::-webkit-datetime-edit{color:theme(colors.tint.400)}& input:-webkit-autofill{box-shadow:0 0 0 999em var(--fabric-input) inset;-webkit-text-fill-color:theme(colors.accent.700)}& input:-webkit-autofill:focus{box-shadow:0 0 0 999em var(--fabric-input-focus) inset;-webkit-text-fill-color:theme(colors.accent.700)}&.invalidWrapper{outline-color:theme(colors.danger.500);&:after{background-color:theme(colors.danger.500)}}}.fieldGroup{>*{line-height:1}>:not(:first-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-start-radius:0;border-start-start-radius:0}}>:not(:last-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-end-radius:0;border-start-end-radius:0}}}}
|
|
@@ -12,7 +12,7 @@ import { ErrorIcon } from './ErrorIcon.js';
|
|
|
12
12
|
import classes from './Field.module.css';
|
|
13
13
|
import { FieldWrapper } from './FieldWrapper.js';
|
|
14
14
|
|
|
15
|
-
var _excluded = ["invalid", "error", "allowClear", "showClear", "decorateStart", "decorateEnd", "children", "onClear", "noOutline", "noBorder", "textarea", "textareaExpandable", "data-inner", "data-open", "floatingExpand", "wrapperRef", "width"];
|
|
15
|
+
var _excluded = ["invalid", "error", "allowClear", "showClear", "decorateStart", "decorateEnd", "decorateEndShowWhenEmpty", "decorateEndHideWhenEmpty", "children", "onClear", "noOutline", "noBorder", "textarea", "textareaExpandable", "data-inner", "data-open", "floatingExpand", "wrapperRef", "width"];
|
|
16
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
18
|
var InputWrapper = function InputWrapper(_ref) {
|
|
@@ -22,6 +22,8 @@ var InputWrapper = function InputWrapper(_ref) {
|
|
|
22
22
|
showClear = _ref.showClear,
|
|
23
23
|
decorateStart = _ref.decorateStart,
|
|
24
24
|
decorateEnd = _ref.decorateEnd,
|
|
25
|
+
decorateEndShowWhenEmpty = _ref.decorateEndShowWhenEmpty,
|
|
26
|
+
decorateEndHideWhenEmpty = _ref.decorateEndHideWhenEmpty,
|
|
25
27
|
children = _ref.children,
|
|
26
28
|
onClear = _ref.onClear,
|
|
27
29
|
noOutline = _ref.noOutline,
|
|
@@ -84,7 +86,7 @@ var InputWrapper = function InputWrapper(_ref) {
|
|
|
84
86
|
className: classNames("text-tint-500 hover:text-tint-700 p-1 z-1 flex-content", classes.inputClear, textarea && "self-start mt-1 me-1")
|
|
85
87
|
}), decorateEnd && /*#__PURE__*/jsx("div", {
|
|
86
88
|
onClickCapture: doFocus,
|
|
87
|
-
className: classNames(classes.decorate, "text-muted leading-none flex-content", isString(decorateEnd) && "px-1"),
|
|
89
|
+
className: classNames(classes.decorate, "text-muted leading-none flex-content", isString(decorateEnd) && "px-1", decorateEndHideWhenEmpty && "peer-placeholder-shown:hidden", decorateEndShowWhenEmpty && "hidden peer-placeholder-shown:inline-block"),
|
|
88
90
|
children: decorateEnd
|
|
89
91
|
}), textareaExpandable && /*#__PURE__*/jsx(Icon, {
|
|
90
92
|
onClick: function onClick() {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* React Fabric
|
|
5
|
+
* @version: 1.0.0
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
12
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
13
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
14
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
* subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
18
|
+
* portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
21
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
var DATA_TYPES = /*#__PURE__*/function (DATA_TYPES) {
|
|
27
|
+
DATA_TYPES["TEXT"] = "text";
|
|
28
|
+
DATA_TYPES["COLOR"] = "color";
|
|
29
|
+
DATA_TYPES["BOOL"] = "bool";
|
|
30
|
+
DATA_TYPES["DATE"] = "date";
|
|
31
|
+
DATA_TYPES["STRING"] = "string";
|
|
32
|
+
DATA_TYPES["NUMBER"] = "number";
|
|
33
|
+
DATA_TYPES["RANGE"] = "range";
|
|
34
|
+
DATA_TYPES["FILE"] = "file";
|
|
35
|
+
DATA_TYPES["AVATAR"] = "avatar";
|
|
36
|
+
DATA_TYPES["SCHEMA"] = "schema";
|
|
37
|
+
return DATA_TYPES;
|
|
38
|
+
}({});
|
|
39
|
+
|
|
40
|
+
export { DATA_TYPES };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type UploadHandler } from "../hooks/useFileUploader";
|
|
2
|
-
import { type FileSchema } from "../types/schema";
|
|
3
|
-
export declare const FileField: ({ uploadHandler, inline, label, accept,
|
|
2
|
+
import { type FileSchema, type ValueType } from "../types/schema";
|
|
3
|
+
export declare const FileField: ({ uploadHandler, inline, label, accept, value, fileUrl, multiple, ...rest }: Partial<FileSchema & ValueType> & {
|
|
4
4
|
value?: AnyObject;
|
|
5
5
|
inline?: boolean;
|
|
6
6
|
fileUrl?: (path: string) => string;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type UploadHandler } from "../hooks/useFileUploader";
|
|
2
|
+
import { type BaseSelectProps } from "../types";
|
|
2
3
|
import { type SchemaType } from "../types/schema";
|
|
3
|
-
export declare const FormField: ({ id, label, required, inline, prefix, autoFocus,
|
|
4
|
+
export declare const FormField: ({ id, label, required, inline, prefix, autoFocus, optionLists, fileUrl, uploadHandler, ...rest }: SchemaType & {
|
|
4
5
|
inline?: boolean;
|
|
5
6
|
prefix?: string;
|
|
6
7
|
autoFocus?: boolean;
|
|
8
|
+
optionLists?: KeyValue<BaseSelectProps<any>>;
|
|
7
9
|
fileUrl?: (path: string) => string;
|
|
8
10
|
uploadHandler?: UploadHandler;
|
|
9
11
|
}) => import("react/jsx-runtime").JSX.Element | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DATA_TYPES, type FormSchema } from "../types/schema";
|
|
2
|
+
interface Props {
|
|
3
|
+
schemaDef: FormSchema;
|
|
4
|
+
allowRemove?: boolean;
|
|
5
|
+
acceptableTypes?: DATA_TYPES[];
|
|
6
|
+
optionLists?: string[];
|
|
7
|
+
onChange: (schema: FormSchema) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const SchemaEditor: ({ schemaDef, allowRemove, acceptableTypes, optionLists, onChange, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -14,7 +14,7 @@ export interface ControllerProps {
|
|
|
14
14
|
disabled?: boolean;
|
|
15
15
|
onBlur: () => void;
|
|
16
16
|
onChange: (value: AnyObject) => void;
|
|
17
|
-
|
|
17
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
18
18
|
}) => ReactElement);
|
|
19
19
|
}
|
|
20
20
|
export declare const Controller: ({ name, children, ...rest }: ControllerProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -17,6 +17,10 @@ export interface FormProps<K extends KeyValue = KeyValue> {
|
|
|
17
17
|
* form data schema
|
|
18
18
|
*/
|
|
19
19
|
schema?: yup.ObjectSchema<K>;
|
|
20
|
+
/**
|
|
21
|
+
* current form model
|
|
22
|
+
*/
|
|
23
|
+
values?: K;
|
|
20
24
|
/**
|
|
21
25
|
* default data values
|
|
22
26
|
*/
|
|
@@ -30,4 +34,4 @@ export interface FormProps<K extends KeyValue = KeyValue> {
|
|
|
30
34
|
*/
|
|
31
35
|
onSubmit?: (values: K) => void;
|
|
32
36
|
}
|
|
33
|
-
export declare const Form: <K extends KeyValue<any>>({ formRef, schema, children, defaultValues, onSubmit, onChange, ...rest }: PropsWithChildren<FormProps<K>>) => import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export declare const Form: <K extends KeyValue<any>>({ formRef, schema, children, values, defaultValues, onSubmit, onChange, ...rest }: PropsWithChildren<FormProps<K>>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { yup } from "@react-fabric/utilities";
|
|
2
|
+
import { type BaseSelectProps } from "../types";
|
|
2
3
|
import { type FormSchema } from "../types/schema";
|
|
3
4
|
import { type UploadHandler } from "./useFileUploader";
|
|
4
|
-
export declare const useFormBuilder: (schema: FormSchema
|
|
5
|
+
export declare const useFormBuilder: <T extends unknown = string>(schema: FormSchema, options?: {
|
|
5
6
|
prefix?: string;
|
|
6
7
|
inline?: boolean;
|
|
7
8
|
fileUrl?: (path: string) => string;
|
|
8
9
|
uploadHandler?: UploadHandler;
|
|
10
|
+
optionLists?: KeyValue<BaseSelectProps<T>>;
|
|
9
11
|
}) => {
|
|
10
12
|
formDef: import("react/jsx-runtime").JSX.Element;
|
|
11
13
|
schemaDef: yup.ObjectSchema<{
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import "./i18n";
|
|
2
2
|
export { Controller } from "./form/Controller";
|
|
3
3
|
export { Form, type FormRef } from "./form/Form";
|
|
4
|
+
export { SchemaEditor } from "./builder/SchemaEditor";
|
|
4
5
|
export { useFileUploader } from "./hooks/useFileUploader";
|
|
5
6
|
export { useFormBuilder } from "./hooks/useFormBuilder";
|
|
6
|
-
export { type FormSchema } from "./types/schema";
|
|
7
|
+
export { DATA_TYPES, type FormSchema, type SchemaDef } from "./types/schema";
|
|
7
8
|
export { ArrayInput } from "./input/ArrayInput";
|
|
8
9
|
export { Checkbox } from "./input/Checkbox";
|
|
9
10
|
export { ColorInput } from "./input/ColorInput";
|
|
10
11
|
export { ColorPicker } from "./input/ColorPicker";
|
|
12
|
+
export { DateInput } from "./input/DateInput";
|
|
11
13
|
export { Field } from "./input/Field";
|
|
12
14
|
export { FileInput } from "./input/File";
|
|
13
15
|
export { HiddenInput } from "./input/Hidden";
|
|
@@ -16,7 +18,7 @@ export { Number } from "./input/Number";
|
|
|
16
18
|
export { Password } from "./input/Password";
|
|
17
19
|
export { Radio } from "./input/Radio";
|
|
18
20
|
export { RadioGroup } from "./input/RadioGroup";
|
|
19
|
-
export {
|
|
21
|
+
export { RangeSlider } from "./input/RangeSlider";
|
|
20
22
|
export { Search } from "./input/Search";
|
|
21
23
|
export { Slider } from "./input/Slider";
|
|
22
24
|
export { Switch } from "./input/Switch";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type RefProp } from "@react-fabric/core/dist/types/types";
|
|
3
|
-
|
|
3
|
+
interface CheckboxProps extends RefProp<HTMLInputElement> {
|
|
4
4
|
/**
|
|
5
5
|
* checkbox label
|
|
6
6
|
*/
|
|
@@ -16,7 +16,7 @@ export interface CheckboxProps extends RefProp<HTMLInputElement> {
|
|
|
16
16
|
/**
|
|
17
17
|
* on checked change
|
|
18
18
|
*/
|
|
19
|
-
onChange?: (checked: boolean
|
|
19
|
+
onChange?: (checked: boolean) => void;
|
|
20
20
|
/**
|
|
21
21
|
* disabled input
|
|
22
22
|
*/
|
|
@@ -43,4 +43,5 @@ export interface CheckboxProps extends RefProp<HTMLInputElement> {
|
|
|
43
43
|
iconChecked?: string;
|
|
44
44
|
name?: string;
|
|
45
45
|
}
|
|
46
|
-
export declare const Checkbox: ({ ref, label, value, name, checked, invalid, disabled, error, width, icon, iconChecked, onChange, ...rest }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
|
|
46
|
+
export declare const Checkbox: ({ ref, label, value, name, checked, invalid, disabled, error, width, icon, iconChecked, required, onChange, ...rest }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RefProp } from "@react-fabric/core/dist/types/types";
|
|
2
|
+
import { type DateLike } from "@react-fabric/date";
|
|
3
|
+
import { type InputProps } from "../types";
|
|
4
|
+
export interface DateProps extends InputProps<string>, RefProp<HTMLInputElement> {
|
|
5
|
+
type?: "date" | "datetime";
|
|
6
|
+
/**
|
|
7
|
+
* date format
|
|
8
|
+
*/
|
|
9
|
+
format?: string;
|
|
10
|
+
/**
|
|
11
|
+
* minimum value
|
|
12
|
+
*/
|
|
13
|
+
min?: DateLike;
|
|
14
|
+
/**
|
|
15
|
+
* maximum value
|
|
16
|
+
*/
|
|
17
|
+
max?: DateLike;
|
|
18
|
+
}
|
|
19
|
+
export declare const DateInput: ({ ref, name, value, invalid, readOnly, disabled, required, placeholder, autoFocus, error, type, onChange, onEnterPressed, format, min, max, ...rest }: DateProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -56,4 +56,4 @@ export interface RangeProps extends Omit<InputProps<[number, number]>, "placehol
|
|
|
56
56
|
/**
|
|
57
57
|
* Number Range input
|
|
58
58
|
*/
|
|
59
|
-
export declare const
|
|
59
|
+
export declare const RangeSlider: ({ error, name, value, step, min, max, height, color, vertical, showLabels, showValue, minLabel, maxLabel, ranges, format, autoFocus, disabled, readOnly, onBlur, onChange, onEnterPressed, onFocus, onSlide, invalid, ...rest }: RangeProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -43,4 +43,4 @@ export interface SwitchProps extends RefProp<HTMLInputElement> {
|
|
|
43
43
|
offLabel?: string;
|
|
44
44
|
offLabelColor?: string | ColorType;
|
|
45
45
|
}
|
|
46
|
-
export declare const Switch: ({ ref, label, checked, invalid, disabled, error, width, color, name, onLabel, offLabel, onLabelColor, offLabelColor, defaultColor, onChange, ...rest }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
|
|
46
|
+
export declare const Switch: ({ ref, label, checked, invalid, disabled, error, width, color, name, onLabel, offLabel, onLabelColor, offLabelColor, defaultColor, required, onChange, ...rest }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const InputWrapper: ({ invalid, error, allowClear, showClear, decorateStart, decorateEnd, children, onClear, noOutline, noBorder, textarea, textareaExpandable, "data-inner": isInner, "data-open": isOpen, floatingExpand, wrapperRef, width, ...rest }: KeyValue) => import("react/jsx-runtime").JSX.Element;
|
|
1
|
+
export declare const InputWrapper: ({ invalid, error, allowClear, showClear, decorateStart, decorateEnd, decorateEndShowWhenEmpty, decorateEndHideWhenEmpty, children, onClear, noOutline, noBorder, textarea, textareaExpandable, "data-inner": isInner, "data-open": isOpen, floatingExpand, wrapperRef, width, ...rest }: KeyValue) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -45,6 +45,8 @@ export interface InputProps<V = string> extends TestProps {
|
|
|
45
45
|
*
|
|
46
46
|
*/
|
|
47
47
|
decorateEnd?: JSX.Element | string | number | boolean;
|
|
48
|
+
decorateEndShowWhenEmpty?: boolean;
|
|
49
|
+
decorateEndHideWhenEmpty?: boolean;
|
|
48
50
|
/**
|
|
49
51
|
* info label at bottom
|
|
50
52
|
*/
|
|
@@ -90,7 +92,7 @@ export interface InputProps<V = string> extends TestProps {
|
|
|
90
92
|
*/
|
|
91
93
|
labelWidth?: string;
|
|
92
94
|
}
|
|
93
|
-
export interface BaseSelectProps<T
|
|
95
|
+
export interface BaseSelectProps<T extends AnyObject = string> {
|
|
94
96
|
/**
|
|
95
97
|
* list options
|
|
96
98
|
*/
|
|
@@ -132,7 +134,8 @@ export interface BaseSelectProps<T> extends RefProp<HTMLInputElement>, Omit<Inpu
|
|
|
132
134
|
*/
|
|
133
135
|
matcher?: (option: T, query: string) => boolean;
|
|
134
136
|
}
|
|
135
|
-
|
|
137
|
+
type BaseSelectType<T> = BaseSelectProps<T> & RefProp<HTMLInputElement> & Omit<InputProps, "value" | "onChange">;
|
|
138
|
+
export type SelectProps<T> = BaseSelectType<T> & ({
|
|
136
139
|
/**
|
|
137
140
|
* is multiple selection
|
|
138
141
|
*/
|
|
@@ -167,3 +170,4 @@ export type SelectProps<T> = BaseSelectProps<T> & ({
|
|
|
167
170
|
*/
|
|
168
171
|
onChange?: (value?: string[]) => void;
|
|
169
172
|
});
|
|
173
|
+
export {};
|
|
@@ -1,59 +1,78 @@
|
|
|
1
|
-
|
|
1
|
+
import { type DateLike } from "@react-fabric/date";
|
|
2
|
+
export declare enum DATA_TYPES {
|
|
3
|
+
TEXT = "text",
|
|
4
|
+
COLOR = "color",
|
|
5
|
+
BOOL = "bool",
|
|
6
|
+
DATE = "date",
|
|
7
|
+
STRING = "string",
|
|
8
|
+
NUMBER = "number",
|
|
9
|
+
RANGE = "range",
|
|
10
|
+
FILE = "file",
|
|
11
|
+
AVATAR = "avatar",
|
|
12
|
+
SCHEMA = "schema"
|
|
13
|
+
}
|
|
14
|
+
interface SingleValue {
|
|
15
|
+
multiple?: false;
|
|
16
|
+
minItems?: never;
|
|
17
|
+
maxItems?: never;
|
|
18
|
+
}
|
|
19
|
+
interface MultipleValue {
|
|
20
|
+
multiple: true;
|
|
21
|
+
minItems?: number;
|
|
22
|
+
maxItems?: number;
|
|
23
|
+
}
|
|
24
|
+
export type ValueType = SingleValue | MultipleValue;
|
|
25
|
+
interface BaseSchema {
|
|
2
26
|
id: string;
|
|
3
27
|
label: string;
|
|
4
28
|
datatype: string;
|
|
5
29
|
required?: boolean;
|
|
6
|
-
multiple?: boolean;
|
|
7
|
-
defaultValue?: AnyObject;
|
|
8
30
|
}
|
|
9
|
-
interface
|
|
10
|
-
datatype:
|
|
31
|
+
export interface DefaultSchema extends BaseSchema {
|
|
32
|
+
datatype: DATA_TYPES.TEXT | DATA_TYPES.COLOR;
|
|
11
33
|
}
|
|
12
|
-
interface BooleanSchema extends
|
|
13
|
-
datatype:
|
|
14
|
-
defaultValue?: boolean;
|
|
34
|
+
export interface BooleanSchema extends BaseSchema {
|
|
35
|
+
datatype: DATA_TYPES.BOOL;
|
|
15
36
|
}
|
|
16
|
-
interface StringSchema extends
|
|
17
|
-
datatype:
|
|
18
|
-
options?: string[];
|
|
37
|
+
export interface StringSchema extends BaseSchema {
|
|
38
|
+
datatype: DATA_TYPES.STRING;
|
|
19
39
|
regex?: string;
|
|
20
|
-
|
|
40
|
+
options?: string[];
|
|
41
|
+
optionList?: string;
|
|
42
|
+
allowCustom?: boolean;
|
|
21
43
|
}
|
|
22
|
-
interface RangeSchema extends
|
|
23
|
-
datatype:
|
|
44
|
+
export interface RangeSchema extends BaseSchema {
|
|
45
|
+
datatype: DATA_TYPES.RANGE;
|
|
24
46
|
min?: number;
|
|
25
47
|
max?: number;
|
|
26
48
|
step?: number;
|
|
27
|
-
defaultValue?: [number, number];
|
|
28
49
|
}
|
|
29
|
-
interface
|
|
30
|
-
datatype:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
defaultValue?: number;
|
|
50
|
+
export interface DateSchema extends BaseSchema {
|
|
51
|
+
datatype: DATA_TYPES.DATE;
|
|
52
|
+
type?: "date" | "datetime";
|
|
53
|
+
min?: DateLike;
|
|
54
|
+
max?: DateLike;
|
|
35
55
|
}
|
|
36
|
-
interface
|
|
37
|
-
datatype:
|
|
56
|
+
export interface NumberSchema extends BaseSchema {
|
|
57
|
+
datatype: DATA_TYPES.NUMBER;
|
|
38
58
|
min?: number;
|
|
39
59
|
max?: number;
|
|
40
60
|
step?: number;
|
|
41
|
-
defaultValue?: number;
|
|
42
61
|
}
|
|
43
|
-
export interface FileSchema extends
|
|
44
|
-
datatype:
|
|
62
|
+
export interface FileSchema extends BaseSchema {
|
|
63
|
+
datatype: DATA_TYPES.FILE;
|
|
45
64
|
accept?: string;
|
|
46
65
|
}
|
|
47
|
-
export interface AvatarSchema extends
|
|
48
|
-
datatype:
|
|
66
|
+
export interface AvatarSchema extends BaseSchema {
|
|
67
|
+
datatype: DATA_TYPES.AVATAR;
|
|
49
68
|
multiple?: false;
|
|
50
69
|
}
|
|
51
|
-
export type SchemaType =
|
|
52
|
-
export interface ChildSchema extends
|
|
53
|
-
datatype:
|
|
70
|
+
export type SchemaType = (DefaultSchema & ValueType) | (BooleanSchema & ValueType) | (StringSchema & ValueType) | (RangeSchema & ValueType) | (DateSchema & ValueType) | (NumberSchema & ValueType) | (FileSchema & ValueType) | (AvatarSchema & ValueType);
|
|
71
|
+
export interface ChildSchema extends BaseSchema {
|
|
72
|
+
datatype: DATA_TYPES.SCHEMA;
|
|
54
73
|
inline?: boolean;
|
|
55
74
|
schema: SchemaType[];
|
|
56
|
-
defaultValue?: never;
|
|
57
75
|
}
|
|
58
|
-
export type
|
|
76
|
+
export type SchemaDef = SchemaType | (ChildSchema & ValueType);
|
|
77
|
+
export type FormSchema = SchemaDef[];
|
|
59
78
|
export {};
|