@react-fabric/form 1.0.0-beta.5 → 1.0.0-beta.52

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.
Files changed (187) hide show
  1. package/{src/input/ArrayInput.module.css → css/_arrayInput.css} +8 -8
  2. package/css/_colorPicker.css +65 -0
  3. package/{src/internal/Field.module.css → css/_field.css} +64 -29
  4. package/{src/input/File.module.css → css/_file.css} +21 -6
  5. package/css/styles.css +27 -0
  6. package/dist/cjs/builder/FileField.js +37 -25
  7. package/dist/cjs/builder/FormField.js +50 -34
  8. package/dist/cjs/builder/SchemaEditor.js +72 -0
  9. package/dist/cjs/builder/components/AddSchemaFields.js +62 -0
  10. package/dist/cjs/builder/components/SchemaArrayForm.js +143 -0
  11. package/dist/cjs/builder/components/SchemaField.js +414 -0
  12. package/dist/cjs/form/Controller.js +46 -1
  13. package/dist/cjs/form/Form.js +43 -6
  14. package/dist/cjs/hooks/useFileUploader.js +16 -0
  15. package/dist/cjs/hooks/useFormBuilder.js +57 -15
  16. package/dist/cjs/i18n/ar.json.js +5 -4
  17. package/dist/cjs/i18n/en.json.js +5 -5
  18. package/dist/cjs/index.js +11 -2
  19. package/dist/cjs/input/ArrayInput.js +100 -33
  20. package/dist/cjs/input/AvatarInput.js +17 -8
  21. package/dist/cjs/input/Checkbox.js +15 -5
  22. package/dist/cjs/input/ColorInput.js +108 -56
  23. package/dist/cjs/input/ColorPicker.js +11 -35
  24. package/dist/cjs/input/DateInput.js +195 -0
  25. package/dist/cjs/input/Field.js +10 -4
  26. package/dist/cjs/input/File.js +14 -7
  27. package/dist/cjs/input/Hidden.js +11 -1
  28. package/dist/cjs/input/Input.js +19 -7
  29. package/dist/cjs/input/Number.js +17 -7
  30. package/dist/cjs/input/Password.js +16 -8
  31. package/dist/cjs/input/Radio.js +11 -2
  32. package/dist/cjs/input/RadioGroup.js +14 -3
  33. package/dist/cjs/input/{Range.js → RangeSlider.js} +14 -6
  34. package/dist/cjs/input/Search.js +25 -16
  35. package/dist/cjs/input/Slider.js +10 -4
  36. package/dist/cjs/input/Switch.js +39 -7
  37. package/dist/cjs/input/Textarea.js +23 -4
  38. package/dist/cjs/internal/ErrorIcon.js +1 -1
  39. package/dist/cjs/internal/FieldWrapper.js +11 -4
  40. package/dist/cjs/internal/InputWrapper.js +19 -16
  41. package/dist/cjs/select/AutoComplete.js +19 -8
  42. package/dist/cjs/select/DualList.js +15 -1
  43. package/dist/cjs/select/List.js +45 -20
  44. package/dist/cjs/select/Options.js +2 -2
  45. package/dist/cjs/select/Select.js +14 -4
  46. package/dist/cjs/select/useSelect.js +10 -6
  47. package/dist/cjs/types/schema.js +43 -0
  48. package/dist/cjs/utils/eventHandlers.js +11 -5
  49. package/dist/cjs/utils/getColor.js +6 -0
  50. package/dist/esm/builder/FileField.js +39 -27
  51. package/dist/esm/builder/FormField.js +50 -34
  52. package/dist/esm/builder/SchemaEditor.js +72 -0
  53. package/dist/esm/builder/components/AddSchemaFields.js +62 -0
  54. package/dist/esm/builder/components/SchemaArrayForm.js +143 -0
  55. package/dist/esm/builder/components/SchemaField.js +414 -0
  56. package/dist/esm/form/Controller.js +46 -1
  57. package/dist/esm/form/Form.js +43 -6
  58. package/dist/esm/hooks/useFileUploader.js +16 -0
  59. package/dist/esm/hooks/useFormBuilder.js +55 -13
  60. package/dist/esm/i18n/ar.json.js +5 -4
  61. package/dist/esm/i18n/en.json.js +5 -5
  62. package/dist/esm/index.js +5 -1
  63. package/dist/esm/input/ArrayInput.js +100 -33
  64. package/dist/esm/input/AvatarInput.js +17 -8
  65. package/dist/esm/input/Checkbox.js +15 -5
  66. package/dist/esm/input/ColorInput.js +110 -58
  67. package/dist/esm/input/ColorPicker.js +11 -35
  68. package/dist/esm/input/DateInput.js +195 -0
  69. package/dist/esm/input/Field.js +11 -5
  70. package/dist/esm/input/File.js +16 -9
  71. package/dist/esm/input/Hidden.js +11 -1
  72. package/dist/esm/input/Input.js +21 -9
  73. package/dist/esm/input/Number.js +19 -9
  74. package/dist/esm/input/Password.js +18 -10
  75. package/dist/esm/input/Radio.js +11 -2
  76. package/dist/esm/input/RadioGroup.js +15 -4
  77. package/dist/esm/input/{Range.js → RangeSlider.js} +14 -6
  78. package/dist/esm/input/Search.js +27 -18
  79. package/dist/esm/input/Slider.js +10 -4
  80. package/dist/esm/input/Switch.js +41 -9
  81. package/dist/esm/input/Textarea.js +24 -5
  82. package/dist/esm/internal/ErrorIcon.js +1 -1
  83. package/dist/esm/internal/FieldWrapper.js +11 -4
  84. package/dist/esm/internal/InputWrapper.js +19 -16
  85. package/dist/esm/select/AutoComplete.js +19 -8
  86. package/dist/esm/select/DualList.js +15 -1
  87. package/dist/esm/select/List.js +46 -21
  88. package/dist/esm/select/Options.js +2 -2
  89. package/dist/esm/select/Select.js +14 -4
  90. package/dist/esm/select/useSelect.js +11 -7
  91. package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
  92. package/dist/esm/utils/eventHandlers.js +11 -5
  93. package/dist/esm/utils/getColor.js +6 -1
  94. package/dist/types/builder/FileField.d.ts +4 -2
  95. package/dist/types/builder/FormField.d.ts +3 -1
  96. package/dist/types/builder/SchemaEditor.d.ts +9 -0
  97. package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
  98. package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
  99. package/dist/types/builder/components/SchemaField.d.ts +10 -0
  100. package/dist/types/form/Controller.d.ts +47 -2
  101. package/dist/types/form/Form.d.ts +37 -2
  102. package/dist/types/hooks/useFileUploader.d.ts +16 -0
  103. package/dist/types/hooks/useFormBuilder.d.ts +32 -1
  104. package/dist/types/index.d.ts +5 -2
  105. package/dist/types/input/ArrayInput.d.ts +78 -6
  106. package/dist/types/input/AvatarInput.d.ts +14 -3
  107. package/dist/types/input/Checkbox.d.ts +13 -4
  108. package/dist/types/input/ColorInput.d.ts +15 -2
  109. package/dist/types/input/ColorPicker.d.ts +11 -1
  110. package/dist/types/input/DateInput.d.ts +28 -0
  111. package/dist/types/input/Field.d.ts +5 -1
  112. package/dist/types/input/File.d.ts +9 -0
  113. package/dist/types/input/Hidden.d.ts +8 -0
  114. package/dist/types/input/Input.d.ts +9 -1
  115. package/dist/types/input/Number.d.ts +9 -1
  116. package/dist/types/input/Password.d.ts +7 -1
  117. package/dist/types/input/Radio.d.ts +9 -1
  118. package/dist/types/input/RadioGroup.d.ts +26 -3
  119. package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +10 -2
  120. package/dist/types/input/Search.d.ts +14 -1
  121. package/dist/types/input/Slider.d.ts +7 -1
  122. package/dist/types/input/Switch.d.ts +16 -4
  123. package/dist/types/input/Textarea.d.ts +15 -1
  124. package/dist/types/internal/FieldWrapper.d.ts +1 -1
  125. package/dist/types/internal/InputWrapper.d.ts +1 -1
  126. package/dist/types/ranger/index.d.ts +2 -2
  127. package/dist/types/select/AutoComplete.d.ts +8 -1
  128. package/dist/types/select/DualList.d.ts +17 -2
  129. package/dist/types/select/List.d.ts +9 -1
  130. package/dist/types/select/Select.d.ts +9 -1
  131. package/dist/types/select/useSelect.d.ts +7 -6
  132. package/dist/types/types/index.d.ts +28 -7
  133. package/dist/types/types/schema.d.ts +78 -33
  134. package/dist/types/utils/eventHandlers.d.ts +1 -1
  135. package/package.json +15 -12
  136. package/src/builder/FileField.tsx +53 -27
  137. package/src/builder/FormField.tsx +52 -32
  138. package/src/builder/SchemaEditor.tsx +79 -0
  139. package/src/builder/components/AddSchemaFields.tsx +74 -0
  140. package/src/builder/components/SchemaArrayForm.tsx +158 -0
  141. package/src/builder/components/SchemaField.tsx +436 -0
  142. package/src/form/Controller.tsx +48 -3
  143. package/src/form/Form.tsx +45 -5
  144. package/src/hooks/useFileUploader.ts +16 -0
  145. package/src/hooks/useFormBuilder.tsx +58 -15
  146. package/src/i18n/ar.json +5 -4
  147. package/src/i18n/en.json +5 -5
  148. package/src/index.ts +11 -2
  149. package/src/input/ArrayInput.tsx +169 -54
  150. package/src/input/AvatarInput.tsx +20 -8
  151. package/src/input/Checkbox.tsx +15 -5
  152. package/src/input/ColorInput.tsx +126 -69
  153. package/src/input/ColorPicker.tsx +12 -36
  154. package/src/input/DateInput.tsx +259 -0
  155. package/src/input/Field.tsx +15 -11
  156. package/src/input/File.tsx +16 -14
  157. package/src/input/Hidden.tsx +12 -1
  158. package/src/input/Input.tsx +23 -10
  159. package/src/input/Number.tsx +18 -10
  160. package/src/input/Password.tsx +19 -12
  161. package/src/input/Radio.tsx +11 -2
  162. package/src/input/RadioGroup.tsx +35 -4
  163. package/src/input/{Range.tsx → RangeSlider.tsx} +13 -5
  164. package/src/input/Search.tsx +29 -19
  165. package/src/input/Slider.tsx +10 -4
  166. package/src/input/Switch.tsx +52 -7
  167. package/src/input/Textarea.tsx +29 -5
  168. package/src/internal/ErrorIcon.tsx +1 -1
  169. package/src/internal/FieldWrapper.tsx +8 -4
  170. package/src/internal/InputWrapper.tsx +36 -20
  171. package/src/select/AutoComplete.tsx +12 -1
  172. package/src/select/DualList.tsx +19 -0
  173. package/src/select/List.tsx +49 -8
  174. package/src/select/Options.tsx +1 -1
  175. package/src/select/Select.tsx +21 -3
  176. package/src/select/useSelect.tsx +13 -5
  177. package/src/types/index.ts +34 -8
  178. package/src/types/schema.ts +96 -41
  179. package/src/utils/eventHandlers.ts +9 -3
  180. package/dist/cjs/input/ArrayInput.module.css +0 -1
  181. package/dist/cjs/input/ColorPicker.module.css +0 -1
  182. package/dist/cjs/input/File.module.css +0 -1
  183. package/dist/cjs/internal/Field.module.css +0 -1
  184. package/dist/esm/input/ArrayInput.module.css +0 -1
  185. package/dist/esm/input/ColorPicker.module.css +0 -1
  186. package/dist/esm/input/File.module.css +0 -1
  187. package/dist/esm/internal/Field.module.css +0 -1
@@ -4,7 +4,7 @@ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
4
4
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
5
5
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
6
  import { useDebounce } from '@react-fabric/core';
7
- import { matchString, isString, dedupe, groupBy, isArray, EMPTY_ARRAY } from '@react-fabric/utilities';
7
+ import { matchString, isString, dedupe, compareValues, groupBy, isArray, EMPTY_ARRAY } from '@react-fabric/utilities';
8
8
  import { useMemo, useDeferredValue, useRef, useCallback, useReducer, useEffect } from 'react';
9
9
  import { getSelectedValue, makeOption } from './helpers.js';
10
10
 
@@ -14,6 +14,8 @@ var useSelect = function useSelect(_ref) {
14
14
  var _ref$options = _ref.options,
15
15
  options = _ref$options === void 0 ? EMPTY_ARRAY : _ref$options,
16
16
  value = _ref.value,
17
+ _ref$defaultOpen = _ref.defaultOpen,
18
+ defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
17
19
  autoComplete = _ref.autoComplete,
18
20
  _ref$multiple = _ref.multiple,
19
21
  multiple = _ref$multiple === void 0 ? false : _ref$multiple,
@@ -25,6 +27,7 @@ var useSelect = function useSelect(_ref) {
25
27
  valueProperty = _ref$valueProperty === void 0 ? "id" : _ref$valueProperty,
26
28
  _ref$labelProperty = _ref.labelProperty,
27
29
  labelProperty = _ref$labelProperty === void 0 ? "label" : _ref$labelProperty,
30
+ sortProperty = _ref.sortProperty,
28
31
  _ref$createOption = _ref.createOption,
29
32
  createOption = _ref$createOption === void 0 ? makeOption : _ref$createOption,
30
33
  matcher = _ref.matcher,
@@ -133,13 +136,14 @@ var useSelect = function useSelect(_ref) {
133
136
  if (autoComplete && action.query !== undefined) {
134
137
  optionList = dedupe([action.query].concat(_toConsumableArray(optionList)));
135
138
  }
139
+ if (sortProperty) optionList = optionList.sort(compareValues("asc", sortProperty));
136
140
  var grouped = groupBy(optionList, groupProperty, "");
137
141
  if (action.open) _newState.open = true;
138
142
  _newState.items = [];
139
143
  // add new item if allowCreate
140
144
  if (allowCreate && action.query) _newState.items.push({
141
145
  ___create___: true,
142
- value: createOption(action.query)
146
+ value: action.query
143
147
  });
144
148
  Object.entries(grouped).forEach(function (_ref2) {
145
149
  var _newState$items;
@@ -169,7 +173,7 @@ var useSelect = function useSelect(_ref) {
169
173
  }, {
170
174
  multiple: multiple,
171
175
  emptyValue: emptyValue,
172
- open: false,
176
+ open: defaultOpen,
173
177
  loading: false,
174
178
  activeIndex: null,
175
179
  selectedIndex: null,
@@ -201,7 +205,7 @@ var useSelect = function useSelect(_ref) {
201
205
  });
202
206
  dispatch({
203
207
  type: "setValue",
204
- value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : ""
208
+ value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : deferred
205
209
  });
206
210
  }
207
211
  if (multiple) {
@@ -211,12 +215,12 @@ var useSelect = function useSelect(_ref) {
211
215
  var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
212
216
  var hasValue = options.find(function (opt) {
213
217
  var _opt$valueProperty2;
214
- return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === deferred;
218
+ return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === item;
215
219
  });
216
220
  if (!hasValue && newOption) {
217
221
  optionsRef.current.push(newOption);
218
222
  }
219
- return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 : "";
223
+ return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 : item;
220
224
  });
221
225
  optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(options !== null && options !== void 0 ? options : []));
222
226
  dispatch({
@@ -246,7 +250,7 @@ var useSelect = function useSelect(_ref) {
246
250
  setActive: true
247
251
  });
248
252
  });
249
- }, [onQuery]);
253
+ }, [onQuery], 300);
250
254
 
251
255
  // handlers
252
256
  var handleQuery = useCallback(function (query) {
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  /*
2
4
  * React Fabric
3
5
  * @version: 1.0.0
@@ -21,31 +23,20 @@
21
23
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
24
  */
23
25
 
24
- @layer comp {
25
- .colorPicker {
26
- --color-shadow: theme(borderColor.base);
27
-
28
- & input {
29
- @apply bg-base text-base !border !border-solid !rounded-sm !border-base focus:!border-primary !shadow-none;
30
-
31
- padding: 0 4px !important;
32
- line-height: 2;
33
- }
34
-
35
- & label {
36
- @apply !text-base;
37
- }
38
-
39
- & :global(.flexbox-fix) {
40
- @apply !border-t-muted justify-center;
41
-
42
- & > div > div {
43
- @apply text-center;
44
- }
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["DATETIME"] = "datetime";
32
+ DATA_TYPES["STRING"] = "string";
33
+ DATA_TYPES["NUMBER"] = "number";
34
+ DATA_TYPES["RANGE"] = "range";
35
+ DATA_TYPES["FILE"] = "file";
36
+ DATA_TYPES["AVATAR"] = "avatar";
37
+ DATA_TYPES["SCHEMA"] = "schema";
38
+ return DATA_TYPES;
39
+ }({});
40
+ var SCHEMA_CUSTOM_LIST = "--CUSTOM--";
45
41
 
46
- & span > div {
47
- box-shadow: 0 0 1px 1px theme(borderColor.base) inset !important;
48
- }
49
- }
50
- }
51
- }
42
+ export { DATA_TYPES, SCHEMA_CUSTOM_LIST };
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
- import { debounce } from '@react-fabric/utilities';
3
+ import { useFloatingTree } from '@floating-ui/react';
4
+ import { useDebounce } from '@react-fabric/core';
4
5
 
5
6
  /*
6
7
  * React Fabric
@@ -26,16 +27,21 @@ import { debounce } from '@react-fabric/utilities';
26
27
  */
27
28
 
28
29
  /** ***************** common handler for enter press *******************/
29
- var handleEnter = function handleEnter(callback) {
30
+ var useHandleEnter = function useHandleEnter(callback) {
30
31
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
31
32
  _ref$stopPropagation = _ref.stopPropagation,
32
33
  stopPropagation = _ref$stopPropagation === void 0 ? false : _ref$stopPropagation,
33
34
  _ref$preventDefault = _ref.preventDefault,
34
35
  preventDefault = _ref$preventDefault === void 0 ? false : _ref$preventDefault;
35
- var cbHandle = debounce(callback !== null && callback !== void 0 ? callback : function () {
36
+ var cbHandle = useDebounce(callback !== null && callback !== void 0 ? callback : function () {
36
37
  return undefined;
37
- }, 100);
38
+ }, [callback], 100);
39
+ var tree = useFloatingTree();
38
40
  return function (e) {
41
+ // prevent propagation of event if input within dropdown (work around for floating-ui typeahead)
42
+ if (tree && e.key !== "Escape") {
43
+ e === null || e === void 0 || e.stopPropagation();
44
+ }
39
45
  if (!e.shiftKey && !e.altKey && !e.metaKey && e.key === "Enter" && callback) {
40
46
  if (stopPropagation) e === null || e === void 0 || e.stopPropagation();
41
47
  cbHandle(e);
@@ -47,4 +53,4 @@ var handleEnter = function handleEnter(callback) {
47
53
  };
48
54
  };
49
55
 
50
- export { handleEnter };
56
+ export { useHandleEnter };
@@ -35,5 +35,10 @@ var getBgClass = function getBgClass(bg) {
35
35
  return "bg-".concat(bg);
36
36
  }
37
37
  };
38
+ var getColorClass = function getColorClass(color) {
39
+ if (color && !isColor(color)) {
40
+ return "text-".concat(color);
41
+ }
42
+ };
38
43
 
39
- export { getBgClass, getColor };
44
+ export { getBgClass, getColor, getColorClass };
@@ -1,8 +1,10 @@
1
1
  import { type UploadHandler } from "../hooks/useFileUploader";
2
- import { type FileSchema } from "../types/schema";
3
- export declare const FileField: ({ uploadHandler, inline, label, accept, multiple, value, ...rest }: Partial<FileSchema> & {
2
+ import { type FileSchema, type ValueType } from "../types/schema";
3
+ export declare const FileField: ({ uploadHandler, inline, label, accept, value, fileUrl, multiple, invalid, error, ...rest }: Partial<FileSchema & ValueType> & {
4
4
  value?: AnyObject;
5
5
  inline?: boolean;
6
+ invalid?: boolean;
7
+ error?: AnyObject;
6
8
  fileUrl?: (path: string) => string;
7
9
  uploadHandler: UploadHandler;
8
10
  }) => import("react/jsx-runtime").JSX.Element;
@@ -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, defaultValue, fileUrl, uploadHandler, ...rest }: SchemaType & {
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,9 @@
1
+ import { type SchemaEditorProps } from "../types/schema";
2
+ /**
3
+ * SchemaEditor component allows users to edit a schema definition.
4
+ * It provides a form interface to modify schema properties dynamically.
5
+ *
6
+ * @param {SchemaEditorProps} props - The properties for the SchemaEditor component.
7
+ * @returns {JSX.Element} The rendered SchemaEditor component.
8
+ */
9
+ export declare const SchemaEditor: ({ schemaDef, dynamic, acceptableTypes, optionLists, children, onSubmit, onChange, }: SchemaEditorProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { type ModalProps } from "@react-fabric/core";
2
+ export declare const AddSchemaFields: (props: ModalProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { type SchemaEditorProps } from "../../types/schema";
2
+ export declare const SchemaArrayForm: ({ dynamic, acceptableTypes, optionLists, }: Partial<SchemaEditorProps>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { type SchemaEditorProps } from "../../types/schema";
2
+ export declare const SchemaField: ({ id, field, fieldId, getModel, onRemove, defaultOpen, optionLists, dynamic, onTypeChange, acceptableTypes, }: {
3
+ id: string;
4
+ field: string;
5
+ fieldId: string;
6
+ defaultOpen?: boolean;
7
+ onRemove: () => void;
8
+ getModel: () => KeyValue;
9
+ onTypeChange: (val: KeyValue) => void;
10
+ } & Omit<SchemaEditorProps, "schemaDef" | "onChange">) => import("react/jsx-runtime").JSX.Element;
@@ -4,7 +4,7 @@ export interface ControllerProps {
4
4
  * field name
5
5
  */
6
6
  name?: string;
7
- children: ReactElement | ((props: {
7
+ children: ReactElement<KeyValue> | ((props: {
8
8
  name: string;
9
9
  error?: string;
10
10
  checked: boolean;
@@ -14,7 +14,52 @@ export interface ControllerProps {
14
14
  disabled?: boolean;
15
15
  onBlur: () => void;
16
16
  onChange: (value: AnyObject) => void;
17
- inputRef?: React.Ref<HTMLInputElement>;
17
+ ref?: React.Ref<HTMLInputElement>;
18
18
  }) => ReactElement);
19
19
  }
20
+ /**
21
+ * This component is used to wrap form controls
22
+ * and provide them with the necessary props and state management.
23
+ *
24
+ * It uses the `Controller` component from `react-hook-form`
25
+ * to manage the form state and validation.
26
+ *
27
+ * It accepts a `name` prop to identify the form control,
28
+ * and a `children` prop which can either be a React element
29
+ * or a function that receives the necessary props to render the control.
30
+ *
31
+ * The component will pass down the following props to the child:
32
+ * - `name`: the name of the form control
33
+ * - `error`: any validation error message
34
+ * - `checked`: whether the control is checked (for checkboxes/radios)
35
+ * - `value`: the current value of the control
36
+ * - `invalid`: whether the control is invalid
37
+ * - `readOnly`: whether the control is read-only (disabled during submission)
38
+ * - `disabled`: whether the control is disabled
39
+ * - `onBlur`: function to call when the control loses focus
40
+ * - `onChange`: function to call when the control value changes
41
+ * - `ref`: a ref to the control element
42
+ * * The component also handles the `ref` prop to ensure that it is passed correctly
43
+ * to the child component, allowing for proper focus management and DOM access.
44
+ *
45
+ * @param {ControllerProps} props - The properties for the Controller component.
46
+ * @returns {JSX.Element} The rendered Controller component.
47
+ *
48
+ * @example
49
+ * ```jsx
50
+ * <Controller
51
+ * name="username"
52
+ * children={({ name, error, checked, value, invalid, readOnly, onChange }) => (
53
+ * <input
54
+ * type="text"
55
+ * name={name}
56
+ * onChange={onChange}
57
+ * readOnly={readOnly}
58
+ * aria-invalid={invalid}
59
+ * value={value}
60
+ * />
61
+ * )}
62
+ * />
63
+ * ```
64
+ */
20
65
  export declare const Controller: ({ name, children, ...rest }: ControllerProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,9 @@
1
1
  import { type yup } from "@react-fabric/utilities";
2
2
  import { type PropsWithChildren, type Ref } from "react";
3
3
  import { type FormState } from "react-hook-form";
4
+ type NestedKeyOf<T extends object> = {
5
+ [K in keyof T & (string | number)]: T[K] extends object ? `${K}` | `${K}.${NestedKeyOf<T[K]>}` : K;
6
+ }[keyof T & (string | number)];
4
7
  export interface FormRef<K extends KeyValue> {
5
8
  state: FormState<K>;
6
9
  reset: () => void;
@@ -8,7 +11,7 @@ export interface FormRef<K extends KeyValue> {
8
11
  submit: () => void;
9
12
  validate: () => Promise<boolean>;
10
13
  getValues: () => K;
11
- setValue: (key: keyof K, value: AnyObject) => void;
14
+ setValue: (key: NestedKeyOf<K>, value: AnyObject) => void;
12
15
  setValues: (values: K) => void;
13
16
  }
14
17
  export interface FormProps<K extends KeyValue = KeyValue> {
@@ -30,4 +33,36 @@ export interface FormProps<K extends KeyValue = KeyValue> {
30
33
  */
31
34
  onSubmit?: (values: K) => void;
32
35
  }
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;
36
+ /**
37
+ * Form component for managing form state and validation using react-hook-form and yup.
38
+ * It provides a simple interface for form handling, including submission, validation, and value management.
39
+ * It supports nested form structures and allows for custom validation schemas using Yup.
40
+ *
41
+ * @param {FormProps<K>} props - The properties for the Form component.
42
+ * @returns {JSX.Element} The rendered Form component.
43
+ *
44
+ * @example
45
+ * ```jsx
46
+ * <Form
47
+ * formRef={formRef}
48
+ * schema={yup.object().shape({
49
+ * name: yup.string().required("Name is required"),
50
+ * email: yup.string().email("Invalid email").required("Email is required"),
51
+ * })}
52
+ * defaultValues={{ name: "", email: "" }}
53
+ * onSubmit={(values) => {
54
+ * console.log("Form submitted with values:", values);
55
+ * }}
56
+ * >
57
+ * <input name="name" ref={form.register} placeholder="Name" />
58
+ * <input name="email" ref={form.register} placeholder="Email" />
59
+ * <button type="submit">Submit</button>
60
+ * </Form>
61
+ * ```
62
+ *
63
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/form-form--docs} for the properties that can be passed to this component.
64
+ * @see {@link https://react-hook-form.com/docs/useform} for more details on the properties.
65
+ * @see {@link https://github.com/jquense/yup} for more details on the Yup validation schema.
66
+ */
67
+ export declare const Form: <K extends KeyValue>({ formRef, schema, children, defaultValues, onSubmit, onChange, ...rest }: PropsWithChildren<FormProps<K>>) => import("react/jsx-runtime").JSX.Element;
68
+ export {};
@@ -12,6 +12,22 @@ interface FileInfo {
12
12
  progress?: number;
13
13
  abort?: AbortController["abort"];
14
14
  }
15
+ /**
16
+ * useFileUploader hook provides a way to handle file uploads
17
+ * with progress tracking, error handling, and file management.
18
+ * It uses a reducer to manage the state of uploaded files and their statuses.
19
+ *
20
+ * @param uploader - The function that handles the file upload.
21
+ * @param initialList - Initial list of files to be managed by the uploader.
22
+ * @param multiple - Whether to allow multiple file uploads or not.
23
+ * @returns An object containing methods to upload, remove, retry files,
24
+ * and the current state of the uploader including pending uploads and file list.
25
+ *
26
+ * @example
27
+ * ```jsx
28
+ * const { upload, remove, retry, state } = useFileUploader(uploader, initialList, multiple);
29
+ * ```
30
+ */
15
31
  export declare const useFileUploader: (uploader: UploadHandler, initialList?: string | FileInfo | FileInfo[], multiple?: boolean) => {
16
32
  upload: (files: FileList | null) => void;
17
33
  remove: (key: string) => void;
@@ -1,11 +1,42 @@
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[], options?: {
5
+ /**
6
+ * useFormBuilder hook to create a form definition based on a schema.
7
+ * It generates a Yup validation schema and a form definition component.
8
+ *
9
+ * @param {FormSchema} schema - The schema defining the form fields.
10
+ * @param {Object} options - Optional parameters for the form builder.
11
+ * @returns An object containing the form definition and the Yup validation schema.
12
+ *
13
+ * @example
14
+ * ```jsx
15
+ * const { formDef, schemaDef } = useFormBuilder(schema, {
16
+ * prefix: "form",
17
+ * inline: true,
18
+ * fileUrl: (path) => `/files/${path}`,
19
+ * uploadHandler: async (file) => {
20
+ * // handle file upload
21
+ * },
22
+ * optionLists: {
23
+ * // define option lists for select fields
24
+ * }
25
+ * * });
26
+ * <FormBuilder
27
+ * schema={schemaDef}
28
+ * onSubmit={(data) => console.log(data)}
29
+ * >
30
+ * {formDef}
31
+ * </FormBuilder>
32
+ * ```
33
+ */
34
+ export declare const useFormBuilder: <T extends AnyObject = string>(schema: FormSchema, options?: {
5
35
  prefix?: string;
6
36
  inline?: boolean;
7
37
  fileUrl?: (path: string) => string;
8
38
  uploadHandler?: UploadHandler;
39
+ optionLists?: KeyValue<BaseSelectProps<T>>;
9
40
  }) => {
10
41
  formDef: import("react/jsx-runtime").JSX.Element;
11
42
  schemaDef: yup.ObjectSchema<{
@@ -1,13 +1,16 @@
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, SCHEMA_CUSTOM_LIST, type FormSchema, type SchemaDef, } from "./types/schema";
7
8
  export { ArrayInput } from "./input/ArrayInput";
9
+ export { AvatarInput } from "./input/AvatarInput";
8
10
  export { Checkbox } from "./input/Checkbox";
9
11
  export { ColorInput } from "./input/ColorInput";
10
12
  export { ColorPicker } from "./input/ColorPicker";
13
+ export { DateInput } from "./input/DateInput";
11
14
  export { Field } from "./input/Field";
12
15
  export { FileInput } from "./input/File";
13
16
  export { HiddenInput } from "./input/Hidden";
@@ -16,7 +19,7 @@ export { Number } from "./input/Number";
16
19
  export { Password } from "./input/Password";
17
20
  export { Radio } from "./input/Radio";
18
21
  export { RadioGroup } from "./input/RadioGroup";
19
- export { Range } from "./input/Range";
22
+ export { RangeSlider } from "./input/RangeSlider";
20
23
  export { Search } from "./input/Search";
21
24
  export { Slider } from "./input/Slider";
22
25
  export { Switch } from "./input/Switch";
@@ -1,5 +1,5 @@
1
- import { type ReactNode, type RefObject } from "react";
2
- export interface ArrayInputProps {
1
+ import { type ReactNode, type Ref } from "react";
2
+ export interface ArrayInputProps<T extends AnyObject = string> {
3
3
  /**
4
4
  * input label
5
5
  */
@@ -32,6 +32,10 @@ export interface ArrayInputProps {
32
32
  * minimum required length
33
33
  */
34
34
  minItems?: number;
35
+ /**
36
+ * maximum length
37
+ */
38
+ maxItems?: number;
35
39
  /**
36
40
  * field name to focus on add
37
41
  */
@@ -48,17 +52,85 @@ export interface ArrayInputProps {
48
52
  * add item button label
49
53
  */
50
54
  addLabel?: string;
55
+ buttonPosition?: "top" | "bottom" | "both";
51
56
  /**
52
57
  * fixed length list
53
58
  */
54
59
  fixedList?: boolean;
55
- arrayRef?: RefObject<{
56
- addItem: (item: AnyObject) => void;
60
+ arrayRef?: Ref<{
61
+ addItem: (item: T) => void;
57
62
  removeItem: (idx: number) => void;
58
63
  }>;
59
64
  /**
60
- * Add item
65
+ * add new item
61
66
  */
62
67
  onAdd?: () => AnyObject;
68
+ /**
69
+ * on item remove
70
+ */
71
+ onRemove?: (item: T, idx: number) => void;
72
+ /**
73
+ * before item remove
74
+ */
75
+ onBeforeRemove?: (item: T, idx: number) => Promise<boolean> | boolean;
76
+ /**
77
+ * can remove item
78
+ */
79
+ canRemove?: (props: {
80
+ item: T;
81
+ index: number;
82
+ lastItem: boolean;
83
+ }) => boolean;
84
+ /**
85
+ * field width
86
+ */
87
+ width?: number | string;
88
+ /**
89
+ * inline label and input
90
+ */
91
+ inline?: boolean;
92
+ /**
93
+ * label width for inline
94
+ */
95
+ labelWidth?: string;
63
96
  }
64
- export declare const ArrayInput: ({ name, children, addLabel, fixedList, focusName, onAdd, arrayRef, enableSorting, disabled, readOnly, minItems, ...rest }: ArrayInputProps) => import("react/jsx-runtime").JSX.Element;
97
+ /**
98
+ * ArrayInput component for managing an array of items in a form.
99
+ * It allows adding, removing, and sorting items within the array.
100
+ * It integrates with react-hook-form for form state management and validation.
101
+ * It supports fixed-length lists, custom add/remove handlers, and can display validation errors.
102
+ * It also provides options for inline display and custom button positioning.
103
+ *
104
+ * It uses the `useFieldArray` hook from `react-hook-form` to manage the array state and provides a simple interface for adding and removing items.
105
+ *
106
+ * It also supports drag-and-drop sorting using `@dnd-kit/core` and `@dnd-kit/sortable` for a better user experience when reordering items.
107
+ *
108
+ * @param {ArrayInputProps<T>} props - The properties for the ArrayInput component.
109
+ * @returns {JSX.Element} The rendered ArrayInput component.
110
+ *
111
+ * @example
112
+ * ```jsx
113
+ * <ArrayInput
114
+ * name="items"
115
+ * label="Items"
116
+ * addLabel="Add Item"
117
+ * onAdd={() => ({ name: "", value: "" })}
118
+ * onRemove={(item, index) => console.log("Removed item:", item, "at index:", index)}
119
+ * onBeforeRemove={(item, index) => confirm(`Are you sure you want to remove item at index ${index}?`)}
120
+ * canRemove={({ item, index, lastItem }) => !lastItem} // Prevent removing the last item
121
+ * >
122
+ * {({ index, name }) => (
123
+ * <Input
124
+ * name={name}
125
+ * label={`Item ${index + 1}`}
126
+ * placeholder="Enter item value"
127
+ * required={index === 0} // Make the first item required
128
+ * />
129
+ * )}
130
+ * </ArrayInput>
131
+ * ```
132
+ *
133
+ * @see {@link https://react-hook-form.com/api/usefieldarray} for more details on `useFieldArray`.
134
+ * @see {@link https://react-dnd.github.io/react-dnd/about} for more details on DnD context and sorting.
135
+ */
136
+ export declare const ArrayInput: <T extends AnyObject = string>({ name, children, addLabel, fixedList, focusName, buttonPosition, onAdd, onRemove, onBeforeRemove, canRemove, arrayRef, enableSorting, disabled, readOnly, minItems, maxItems, ...rest }: ArrayInputProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -10,14 +10,17 @@ export interface Props extends RefProp {
10
10
  */
11
11
  value?: string;
12
12
  /**
13
- * avatar stream src
13
+ * avatar name
14
14
  */
15
- src?: string;
15
+ avatarName?: string;
16
16
  size?: string | number;
17
17
  /**
18
18
  * upload handler to store file in temp storage
19
19
  */
20
20
  uploadHandler: UploadHandler;
21
+ /**
22
+ * file stream path
23
+ */
21
24
  fileUrl?: (path: string) => string;
22
25
  /**
23
26
  * change handler
@@ -28,4 +31,12 @@ export interface Props extends RefProp {
28
31
  */
29
32
  onChange?: (path: string) => void;
30
33
  }
31
- export declare const AvatarInput: ({ src, size, fileUrl, uploadHandler, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
34
+ /**
35
+ * Avatar input component for uploading and displaying user avatars.
36
+ * It allows users to select an image file, upload it, and display the avatar.
37
+ * It also provides a way to remove the uploaded file and shows upload progress.
38
+ *
39
+ * @param {Props} props - The properties for the AvatarInput component.
40
+ * @returns {JSX.Element} - The rendered AvatarInput component.
41
+ */
42
+ export declare const AvatarInput: ({ size, avatarName, value, fileUrl, uploadHandler, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,5 @@
1
- /// <reference types="react" />
2
1
  import { type RefProp } from "@react-fabric/core/dist/types/types";
3
- export interface CheckboxProps extends RefProp<HTMLInputElement> {
2
+ interface CheckboxProps extends RefProp<HTMLInputElement> {
4
3
  /**
5
4
  * checkbox label
6
5
  */
@@ -16,7 +15,7 @@ export interface CheckboxProps extends RefProp<HTMLInputElement> {
16
15
  /**
17
16
  * on checked change
18
17
  */
19
- onChange?: (checked: boolean | string | number) => void;
18
+ onChange?: (checked: boolean) => void;
20
19
  /**
21
20
  * disabled input
22
21
  */
@@ -43,4 +42,14 @@ export interface CheckboxProps extends RefProp<HTMLInputElement> {
43
42
  iconChecked?: string;
44
43
  name?: string;
45
44
  }
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;
45
+ /**
46
+ * Checkbox component for rendering a checkbox input with label and error handling.
47
+ * It supports custom icons for checked and unchecked states, and handles disabled and invalid states.
48
+ * The component uses a deferred value to manage the checked state, ensuring smooth updates.
49
+ * It also provides an error icon to indicate validation errors.
50
+ *
51
+ * @param {CheckboxProps} props - The properties for the Checkbox component.
52
+ * @returns {JSX.Element} The rendered Checkbox component.
53
+ */
54
+ 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;
55
+ export {};