@react-fabric/form 1.0.0-beta.6 → 1.0.0-beta.61

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} +66 -30
  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 +40 -28
  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 +63 -0
  10. package/dist/cjs/builder/components/SchemaArrayForm.js +145 -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 +71 -13
  14. package/dist/cjs/hooks/useFileUploader.js +16 -0
  15. package/dist/cjs/hooks/useFormBuilder.js +67 -18
  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 +12 -2
  19. package/dist/cjs/input/ArrayInput.js +128 -38
  20. package/dist/cjs/input/AvatarInput.js +43 -23
  21. package/dist/cjs/input/Checkbox.js +18 -8
  22. package/dist/cjs/input/ColorInput.js +114 -59
  23. package/dist/cjs/input/ColorPicker.js +60 -76
  24. package/dist/cjs/input/DateInput.js +197 -0
  25. package/dist/cjs/input/Field.js +10 -4
  26. package/dist/cjs/input/File.js +15 -8
  27. package/dist/cjs/input/Hidden.js +13 -2
  28. package/dist/cjs/input/Input.js +24 -10
  29. package/dist/cjs/input/Number.js +22 -10
  30. package/dist/cjs/input/Password.js +23 -13
  31. package/dist/cjs/input/Radio.js +14 -5
  32. package/dist/cjs/input/RadioGroup.js +10 -1
  33. package/dist/cjs/input/{Range.js → RangeSlider.js} +16 -8
  34. package/dist/cjs/input/Search.js +32 -22
  35. package/dist/cjs/input/Slider.js +12 -6
  36. package/dist/cjs/input/Switch.js +20 -9
  37. package/dist/cjs/input/Textarea.js +29 -8
  38. package/dist/cjs/internal/ErrorIcon.js +2 -2
  39. package/dist/cjs/internal/FieldWrapper.js +11 -4
  40. package/dist/cjs/internal/InputWrapper.js +29 -22
  41. package/dist/cjs/select/AutoComplete.js +22 -13
  42. package/dist/cjs/select/DualList.js +34 -12
  43. package/dist/cjs/select/List.js +49 -21
  44. package/dist/cjs/select/Options.js +49 -42
  45. package/dist/cjs/select/Select.js +21 -10
  46. package/dist/cjs/select/useSelect.js +22 -11
  47. package/dist/cjs/types/schema.js +43 -0
  48. package/dist/cjs/utils/eventHandlers.js +15 -5
  49. package/dist/esm/builder/FileField.js +42 -30
  50. package/dist/esm/builder/FormField.js +50 -34
  51. package/dist/esm/builder/SchemaEditor.js +72 -0
  52. package/dist/esm/builder/components/AddSchemaFields.js +63 -0
  53. package/dist/esm/builder/components/SchemaArrayForm.js +145 -0
  54. package/dist/esm/builder/components/SchemaField.js +414 -0
  55. package/dist/esm/form/Controller.js +46 -1
  56. package/dist/esm/form/Form.js +73 -16
  57. package/dist/esm/hooks/useFileUploader.js +16 -0
  58. package/dist/esm/hooks/useFormBuilder.js +65 -16
  59. package/dist/esm/i18n/ar.json.js +5 -4
  60. package/dist/esm/i18n/en.json.js +5 -5
  61. package/dist/esm/index.js +6 -2
  62. package/dist/esm/input/ArrayInput.js +128 -38
  63. package/dist/esm/input/AvatarInput.js +43 -23
  64. package/dist/esm/input/Checkbox.js +19 -9
  65. package/dist/esm/input/ColorInput.js +116 -61
  66. package/dist/esm/input/ColorPicker.js +60 -76
  67. package/dist/esm/input/DateInput.js +197 -0
  68. package/dist/esm/input/Field.js +11 -5
  69. package/dist/esm/input/File.js +18 -11
  70. package/dist/esm/input/Hidden.js +13 -2
  71. package/dist/esm/input/Input.js +26 -12
  72. package/dist/esm/input/Number.js +24 -12
  73. package/dist/esm/input/Password.js +26 -16
  74. package/dist/esm/input/Radio.js +15 -6
  75. package/dist/esm/input/RadioGroup.js +11 -2
  76. package/dist/esm/input/{Range.js → RangeSlider.js} +16 -8
  77. package/dist/esm/input/Search.js +35 -25
  78. package/dist/esm/input/Slider.js +12 -6
  79. package/dist/esm/input/Switch.js +20 -9
  80. package/dist/esm/input/Textarea.js +30 -9
  81. package/dist/esm/internal/ErrorIcon.js +3 -3
  82. package/dist/esm/internal/FieldWrapper.js +11 -4
  83. package/dist/esm/internal/InputWrapper.js +30 -23
  84. package/dist/esm/select/AutoComplete.js +23 -14
  85. package/dist/esm/select/DualList.js +35 -13
  86. package/dist/esm/select/List.js +50 -22
  87. package/dist/esm/select/Options.js +49 -42
  88. package/dist/esm/select/Select.js +22 -11
  89. package/dist/esm/select/useSelect.js +23 -12
  90. package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
  91. package/dist/esm/utils/eventHandlers.js +15 -5
  92. package/dist/types/builder/FileField.d.ts +4 -2
  93. package/dist/types/builder/FormField.d.ts +3 -1
  94. package/dist/types/builder/SchemaEditor.d.ts +9 -0
  95. package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
  96. package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
  97. package/dist/types/builder/components/SchemaField.d.ts +10 -0
  98. package/dist/types/form/Controller.d.ts +47 -2
  99. package/dist/types/form/Form.d.ts +49 -6
  100. package/dist/types/hooks/useFileUploader.d.ts +16 -0
  101. package/dist/types/hooks/useFormBuilder.d.ts +38 -1
  102. package/dist/types/index.d.ts +6 -3
  103. package/dist/types/input/ArrayInput.d.ts +69 -12
  104. package/dist/types/input/AvatarInput.d.ts +23 -3
  105. package/dist/types/input/Checkbox.d.ts +13 -4
  106. package/dist/types/input/ColorInput.d.ts +15 -2
  107. package/dist/types/input/ColorPicker.d.ts +11 -1
  108. package/dist/types/input/DateInput.d.ts +28 -0
  109. package/dist/types/input/Field.d.ts +5 -1
  110. package/dist/types/input/File.d.ts +9 -0
  111. package/dist/types/input/Hidden.d.ts +13 -1
  112. package/dist/types/input/Input.d.ts +9 -1
  113. package/dist/types/input/Number.d.ts +9 -1
  114. package/dist/types/input/Password.d.ts +7 -1
  115. package/dist/types/input/Radio.d.ts +9 -1
  116. package/dist/types/input/RadioGroup.d.ts +8 -1
  117. package/dist/types/input/RangeSlider.d.ts +67 -0
  118. package/dist/types/input/Search.d.ts +14 -1
  119. package/dist/types/input/Slider.d.ts +8 -2
  120. package/dist/types/input/Switch.d.ts +10 -2
  121. package/dist/types/input/Textarea.d.ts +15 -1
  122. package/dist/types/internal/FieldWrapper.d.ts +1 -1
  123. package/dist/types/internal/InputWrapper.d.ts +1 -1
  124. package/dist/types/ranger/index.d.ts +2 -2
  125. package/dist/types/select/AutoComplete.d.ts +8 -1
  126. package/dist/types/select/DualList.d.ts +21 -7
  127. package/dist/types/select/List.d.ts +9 -1
  128. package/dist/types/select/Options.d.ts +4 -3
  129. package/dist/types/select/Select.d.ts +9 -1
  130. package/dist/types/select/useSelect.d.ts +10 -6
  131. package/dist/types/types/index.d.ts +38 -10
  132. package/dist/types/types/schema.d.ts +78 -33
  133. package/dist/types/utils/eventHandlers.d.ts +2 -2
  134. package/package.json +22 -20
  135. package/src/builder/FileField.tsx +56 -30
  136. package/src/builder/FormField.tsx +52 -32
  137. package/src/builder/SchemaEditor.tsx +79 -0
  138. package/src/builder/components/AddSchemaFields.tsx +75 -0
  139. package/src/builder/components/SchemaArrayForm.tsx +155 -0
  140. package/src/builder/components/SchemaField.tsx +435 -0
  141. package/src/form/Controller.tsx +48 -3
  142. package/src/form/Form.tsx +84 -13
  143. package/src/hooks/useFileUploader.ts +16 -0
  144. package/src/hooks/useFormBuilder.tsx +70 -19
  145. package/src/i18n/ar.json +5 -4
  146. package/src/i18n/en.json +5 -5
  147. package/src/index.ts +12 -3
  148. package/src/input/ArrayInput.tsx +195 -66
  149. package/src/input/AvatarInput.tsx +66 -18
  150. package/src/input/Checkbox.tsx +22 -9
  151. package/src/input/ColorInput.tsx +128 -72
  152. package/src/input/ColorPicker.tsx +54 -72
  153. package/src/input/DateInput.tsx +260 -0
  154. package/src/input/Field.tsx +15 -11
  155. package/src/input/File.tsx +18 -16
  156. package/src/input/Hidden.tsx +17 -2
  157. package/src/input/Input.tsx +27 -13
  158. package/src/input/Number.tsx +22 -13
  159. package/src/input/Password.tsx +28 -18
  160. package/src/input/Radio.tsx +15 -6
  161. package/src/input/RadioGroup.tsx +12 -3
  162. package/src/input/{Range.tsx → RangeSlider.tsx} +17 -9
  163. package/src/input/Search.tsx +36 -25
  164. package/src/input/Slider.tsx +20 -11
  165. package/src/input/Switch.tsx +17 -6
  166. package/src/input/Textarea.tsx +34 -9
  167. package/src/internal/ErrorIcon.tsx +3 -3
  168. package/src/internal/FieldWrapper.tsx +8 -4
  169. package/src/internal/InputWrapper.tsx +56 -30
  170. package/src/select/AutoComplete.tsx +16 -6
  171. package/src/select/DualList.tsx +40 -22
  172. package/src/select/List.tsx +52 -8
  173. package/src/select/Options.tsx +50 -46
  174. package/src/select/Select.tsx +29 -10
  175. package/src/select/useSelect.tsx +26 -9
  176. package/src/types/index.ts +42 -10
  177. package/src/types/schema.ts +96 -41
  178. package/src/utils/eventHandlers.ts +14 -4
  179. package/dist/cjs/input/ArrayInput.module.css +0 -1
  180. package/dist/cjs/input/ColorPicker.module.css +0 -1
  181. package/dist/cjs/input/File.module.css +0 -1
  182. package/dist/cjs/internal/Field.module.css +0 -1
  183. package/dist/esm/input/ArrayInput.module.css +0 -1
  184. package/dist/esm/input/ColorPicker.module.css +0 -1
  185. package/dist/esm/input/File.module.css +0 -1
  186. package/dist/esm/internal/Field.module.css +0 -1
  187. package/dist/types/input/Range.d.ts +0 -59
@@ -0,0 +1,414 @@
1
+ 'use client';
2
+
3
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
4
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
5
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
+ import { useSortable } from '@dnd-kit/sortable';
7
+ import { CSS } from '@dnd-kit/utilities';
8
+ import { useOverlayService, Modal, Content, Footer, Button, Collapsable, ToggleButtonGroup } from '@react-fabric/core';
9
+ import { EMPTY_ARRAY } from '@react-fabric/utilities';
10
+ import classNames from 'classnames';
11
+ import { useState, useCallback, useEffect, Fragment } from 'react';
12
+ import { Controller } from '../../form/Controller.js';
13
+ import { ArrayInput } from '../../input/ArrayInput.js';
14
+ import { Checkbox } from '../../input/Checkbox.js';
15
+ import { DateInput } from '../../input/DateInput.js';
16
+ import { Field } from '../../input/Field.js';
17
+ import { HiddenInput } from '../../input/Hidden.js';
18
+ import { Input } from '../../input/Input.js';
19
+ import { Number } from '../../input/Number.js';
20
+ import { Select } from '../../select/Select.js';
21
+ import { SCHEMA_CUSTOM_LIST, DATA_TYPES } from '../../types/schema.js';
22
+ import { jsxs, jsx } from 'react/jsx-runtime';
23
+
24
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
25
+ 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; }
26
+ var SchemaField = function SchemaField(_ref) {
27
+ var id = _ref.id,
28
+ field = _ref.field,
29
+ fieldId = _ref.fieldId,
30
+ getModel = _ref.getModel,
31
+ onRemove = _ref.onRemove,
32
+ _ref$defaultOpen = _ref.defaultOpen,
33
+ defaultOpen = _ref$defaultOpen === void 0 ? true : _ref$defaultOpen,
34
+ _ref$optionLists = _ref.optionLists,
35
+ optionLists = _ref$optionLists === void 0 ? EMPTY_ARRAY : _ref$optionLists,
36
+ dynamic = _ref.dynamic,
37
+ onTypeChange = _ref.onTypeChange,
38
+ acceptableTypes = _ref.acceptableTypes;
39
+ var _useState = useState(),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ type = _useState2[0],
42
+ setType = _useState2[1];
43
+ var _useState3 = useState(false),
44
+ _useState4 = _slicedToArray(_useState3, 2),
45
+ multiple = _useState4[0],
46
+ setMultiple = _useState4[1];
47
+ var _useState5 = useState(false),
48
+ _useState6 = _slicedToArray(_useState5, 2),
49
+ hasOptions = _useState6[0],
50
+ setHasOptions = _useState6[1];
51
+ var _useState7 = useState(false),
52
+ _useState8 = _slicedToArray(_useState7, 2),
53
+ customOptions = _useState8[0],
54
+ setCustomOptions = _useState8[1];
55
+ var SortableItem = useCallback(function (_ref2) {
56
+ var id = _ref2.id,
57
+ children = _ref2.children,
58
+ className = _ref2.className;
59
+ if (dynamic) {
60
+ var _useSortable = useSortable({
61
+ id: id
62
+ }),
63
+ attributes = _useSortable.attributes,
64
+ listeners = _useSortable.listeners,
65
+ setNodeRef = _useSortable.setNodeRef,
66
+ transform = _useSortable.transform,
67
+ transition = _useSortable.transition,
68
+ isDragging = _useSortable.isDragging;
69
+ return /*#__PURE__*/jsxs("div", {
70
+ className: className,
71
+ ref: setNodeRef,
72
+ style: {
73
+ transform: CSS.Transform.toString(transform),
74
+ transition: transition
75
+ },
76
+ children: [/*#__PURE__*/jsx("div", _objectSpread(_objectSpread(_objectSpread({
77
+ className: classNames("invisible group-hover/field:visible my-2 w-4", isDragging ? "cursor-grabbing" : "cursor-grab")
78
+ }, attributes), listeners), {}, {
79
+ style: {
80
+ backgroundImage: "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='4' width='4'%3E%3Ccircle cx='2' cy='2' r='1' fill='%238888' /%3E%3C/svg%3E \")"
81
+ }
82
+ })), children]
83
+ });
84
+ }
85
+ return /*#__PURE__*/jsx("div", {
86
+ className: className,
87
+ children: children
88
+ });
89
+ }, [dynamic]);
90
+ // @ts-expect-error ignore
91
+ SortableItem.displayName = "SortableItem";
92
+ var _useOverlayService = useOverlayService(function (props) {
93
+ return /*#__PURE__*/jsxs(Modal, _objectSpread(_objectSpread({}, props), {}, {
94
+ children: [/*#__PURE__*/jsx(Content, {
95
+ children: /*#__PURE__*/jsx(ArrayInput, {
96
+ name: "".concat(field, ".options"),
97
+ onAdd: function onAdd() {
98
+ return String("");
99
+ },
100
+ children: /*#__PURE__*/jsx(Controller, {
101
+ children: /*#__PURE__*/jsx(Input, {})
102
+ })
103
+ })
104
+ }), /*#__PURE__*/jsx(Footer, {
105
+ flex: true,
106
+ justify: "end",
107
+ className: "sticky bottom-0 border-t bg-base px-6 py-2",
108
+ children: /*#__PURE__*/jsx(Button, {
109
+ variant: "link",
110
+ onClick: props.onClose,
111
+ children: "Close"
112
+ })
113
+ })]
114
+ }));
115
+ }),
116
+ _useOverlayService2 = _slicedToArray(_useOverlayService, 2),
117
+ OptionModal = _useOverlayService2[0],
118
+ openOptionModal = _useOverlayService2[1];
119
+ useEffect(function () {
120
+ setTimeout(function () {
121
+ var model = getModel();
122
+ setType(model.datatype);
123
+ setMultiple(model.multiple);
124
+ setHasOptions(!!model.optionList);
125
+ setCustomOptions(model.optionList === SCHEMA_CUSTOM_LIST);
126
+ }, 10);
127
+ }, []);
128
+ var handleTypeChange = useCallback(function (type) {
129
+ if (type) {
130
+ var modelRef = getModel();
131
+ var reset = {
132
+ datatype: type,
133
+ id: id,
134
+ label: modelRef.label,
135
+ defaultValue: modelRef.defaultValue,
136
+ required: modelRef.required,
137
+ multiple: type === DATA_TYPES.AVATAR ? false : modelRef.multiple,
138
+ minItems: modelRef.minItems,
139
+ maxItems: modelRef.maxItems
140
+ };
141
+ if (type === DATA_TYPES.STRING) {
142
+ reset = Object.assign(reset, {
143
+ optionList: modelRef.optionList,
144
+ options: modelRef.options,
145
+ regex: modelRef.regex
146
+ });
147
+ } else if (type === DATA_TYPES.DATE) {
148
+ reset = Object.assign(reset, {
149
+ min: modelRef.min,
150
+ max: modelRef.max
151
+ });
152
+ } else if (type === DATA_TYPES.NUMBER || type === DATA_TYPES.RANGE) {
153
+ reset = Object.assign(reset, {
154
+ min: modelRef.min,
155
+ max: modelRef.max,
156
+ step: modelRef.step
157
+ });
158
+ }
159
+ if (type === DATA_TYPES.AVATAR) {
160
+ setMultiple(false);
161
+ }
162
+ onTypeChange(reset);
163
+ setType(type);
164
+ }
165
+ }, [id]);
166
+ return /*#__PURE__*/jsx(SortableItem, {
167
+ id: fieldId,
168
+ className: "flex flex-nowrap gap-1 group/field",
169
+ children: /*#__PURE__*/jsxs(Collapsable, {
170
+ open: defaultOpen,
171
+ className: "flex-1",
172
+ children: [/*#__PURE__*/jsxs("div", {
173
+ className: "flex flex-nowrap items-center",
174
+ children: [/*#__PURE__*/jsx("span", {
175
+ className: "flex-1 truncate",
176
+ children: id
177
+ }), dynamic && /*#__PURE__*/jsx(Button, {
178
+ size: "sm",
179
+ color: "danger",
180
+ variant: "link",
181
+ "aria-label": "Delete",
182
+ stopPropagation: true,
183
+ icon: "icon-[mdi--trash-can-outline]",
184
+ onClick: onRemove,
185
+ className: "invisible group-hover/field:visible"
186
+ })]
187
+ }), /*#__PURE__*/jsxs("div", {
188
+ className: "flex flex-col gap-1 pb-4",
189
+ children: [/*#__PURE__*/jsx(Controller, {
190
+ name: "".concat(field, ".id"),
191
+ children: /*#__PURE__*/jsx(HiddenInput, {
192
+ hiddenValue: id
193
+ })
194
+ }), /*#__PURE__*/jsx(Controller, {
195
+ name: "".concat(field, ".datatype"),
196
+ children: /*#__PURE__*/jsx(Select, {
197
+ inline: true,
198
+ label: "Type",
199
+ placeholder: "Data type",
200
+ options: acceptableTypes,
201
+ onChange: function onChange(val) {
202
+ return handleTypeChange(val);
203
+ }
204
+ })
205
+ }), /*#__PURE__*/jsx(Controller, {
206
+ name: "".concat(field, ".label"),
207
+ children: /*#__PURE__*/jsx(Input, {
208
+ inline: true,
209
+ label: "Label",
210
+ allowClear: true,
211
+ placeholder: "Label...",
212
+ decorateEndShowWhenEmpty: true,
213
+ decorateEnd: /*#__PURE__*/jsx("span", {
214
+ className: "text-sm text-tint-300 px-1",
215
+ children: "OPTIONAL"
216
+ })
217
+ })
218
+ }), type === DATA_TYPES.STRING && /*#__PURE__*/jsxs(Fragment, {
219
+ children: [/*#__PURE__*/jsx(Controller, {
220
+ name: "".concat(field, ".regex"),
221
+ children: /*#__PURE__*/jsx(Input, {
222
+ inline: true,
223
+ label: "Regex validation",
224
+ allowClear: true,
225
+ placeholder: "Regex value...",
226
+ decorateEndShowWhenEmpty: true,
227
+ decorateEnd: /*#__PURE__*/jsx("span", {
228
+ className: "text-sm text-tint-300 px-1",
229
+ children: "OPTIONAL"
230
+ })
231
+ })
232
+ }), /*#__PURE__*/jsxs(Field, {
233
+ inline: true,
234
+ label: "Option list",
235
+ children: [/*#__PURE__*/jsx(Controller, {
236
+ name: "".concat(field, ".optionList"),
237
+ children: /*#__PURE__*/jsx(Select, {
238
+ allowClear: true,
239
+ options: [SCHEMA_CUSTOM_LIST].concat(_toConsumableArray(optionLists)),
240
+ onChange: function onChange(v) {
241
+ return setCustomOptions(v === SCHEMA_CUSTOM_LIST);
242
+ }
243
+ })
244
+ }), customOptions && /*#__PURE__*/jsx(Button, {
245
+ icon: "icon-[mdi--list-box-outline]",
246
+ "aria-label": "Custom options",
247
+ onClick: function onClick() {
248
+ void openOptionModal({
249
+ title: "".concat(id, " Options")
250
+ });
251
+ }
252
+ })]
253
+ }), OptionModal]
254
+ }), type === DATA_TYPES.FILE && /*#__PURE__*/jsx(Fragment, {
255
+ children: /*#__PURE__*/jsx(Controller, {
256
+ name: "".concat(field, ".accept"),
257
+ children: /*#__PURE__*/jsx(Input, {
258
+ inline: true,
259
+ label: "Accept types",
260
+ allowClear: true,
261
+ placeholder: "Accept value...",
262
+ decorateEndShowWhenEmpty: true,
263
+ decorateEnd: /*#__PURE__*/jsx("span", {
264
+ className: "text-sm text-tint-300 px-1",
265
+ children: "OPTIONAL"
266
+ })
267
+ })
268
+ })
269
+ }), [DATA_TYPES.NUMBER, DATA_TYPES.RANGE].includes(type) && /*#__PURE__*/jsxs(Fragment, {
270
+ children: [/*#__PURE__*/jsx(Controller, {
271
+ name: "".concat(field, ".min"),
272
+ children: /*#__PURE__*/jsx(Number, {
273
+ inline: true,
274
+ label: "Min value",
275
+ allowClear: true,
276
+ placeholder: "Minimum value...",
277
+ decorateEndShowWhenEmpty: true,
278
+ decorateEnd: /*#__PURE__*/jsx("span", {
279
+ className: "text-sm text-tint-300 px-1",
280
+ children: "OPTIONAL"
281
+ })
282
+ })
283
+ }), /*#__PURE__*/jsx(Controller, {
284
+ name: "".concat(field, ".max"),
285
+ children: /*#__PURE__*/jsx(Number, {
286
+ inline: true,
287
+ label: "Max value",
288
+ allowClear: true,
289
+ placeholder: "Maximum value...",
290
+ decorateEndShowWhenEmpty: true,
291
+ decorateEnd: /*#__PURE__*/jsx("span", {
292
+ className: "text-sm text-tint-300 px-1",
293
+ children: "OPTIONAL"
294
+ })
295
+ })
296
+ }), /*#__PURE__*/jsx(Controller, {
297
+ name: "".concat(field, ".step"),
298
+ children: /*#__PURE__*/jsx(Number, {
299
+ inline: true,
300
+ label: "Step value",
301
+ allowClear: true,
302
+ placeholder: "Step value...",
303
+ decorateEndShowWhenEmpty: true,
304
+ decorateEnd: /*#__PURE__*/jsx("span", {
305
+ className: "text-sm text-tint-300 px-1",
306
+ children: "OPTIONAL"
307
+ })
308
+ })
309
+ })]
310
+ }), type === DATA_TYPES.DATE && /*#__PURE__*/jsxs(Fragment, {
311
+ children: [/*#__PURE__*/jsx(Field, {
312
+ inline: true,
313
+ label: "Type",
314
+ plain: true,
315
+ children: /*#__PURE__*/jsx(Controller, {
316
+ name: "".concat(field, ".type"),
317
+ children: /*#__PURE__*/jsxs(ToggleButtonGroup, {
318
+ value: "",
319
+ fullWidth: true,
320
+ className: "flex-1",
321
+ children: [/*#__PURE__*/jsx(Button, {
322
+ className: "flex-1",
323
+ value: "date",
324
+ children: "Date"
325
+ }), /*#__PURE__*/jsx(Button, {
326
+ className: "flex-1",
327
+ value: "datetime",
328
+ children: "Date Time"
329
+ })]
330
+ })
331
+ })
332
+ }), /*#__PURE__*/jsx(Controller, {
333
+ name: "".concat(field, ".min"),
334
+ children: /*#__PURE__*/jsx(DateInput, {
335
+ inline: true,
336
+ label: "Min value",
337
+ allowClear: true,
338
+ placeholder: "Minimum value...",
339
+ decorateEndShowWhenEmpty: true,
340
+ decorateEnd: /*#__PURE__*/jsx("span", {
341
+ className: "text-sm text-tint-300 px-1",
342
+ children: "OPTIONAL"
343
+ })
344
+ })
345
+ }), /*#__PURE__*/jsx(Controller, {
346
+ name: "".concat(field, ".max"),
347
+ children: /*#__PURE__*/jsx(DateInput, {
348
+ inline: true,
349
+ label: "Max value",
350
+ allowClear: true,
351
+ placeholder: "Maximum value...",
352
+ decorateEndShowWhenEmpty: true,
353
+ decorateEnd: /*#__PURE__*/jsx("span", {
354
+ className: "text-sm text-tint-300 px-1",
355
+ children: "OPTIONAL"
356
+ })
357
+ })
358
+ })]
359
+ }), /*#__PURE__*/jsxs(Field, {
360
+ label: " ",
361
+ inline: true,
362
+ plain: true,
363
+ children: [/*#__PURE__*/jsx(Controller, {
364
+ name: "".concat(field, ".required"),
365
+ children: /*#__PURE__*/jsx(Checkbox, {
366
+ label: "Required"
367
+ })
368
+ }), type !== DATA_TYPES.AVATAR && /*#__PURE__*/jsx(Controller, {
369
+ name: "".concat(field, ".multiple"),
370
+ children: /*#__PURE__*/jsx(Checkbox, {
371
+ label: "Multiple",
372
+ onChange: setMultiple
373
+ })
374
+ }), hasOptions && /*#__PURE__*/jsx(Controller, {
375
+ name: "".concat(field, ".allowCustom"),
376
+ children: /*#__PURE__*/jsx(Checkbox, {
377
+ label: "Allow custom value"
378
+ })
379
+ })]
380
+ }), multiple && /*#__PURE__*/jsxs(Fragment, {
381
+ children: [/*#__PURE__*/jsx(Controller, {
382
+ name: "".concat(field, ".minItems"),
383
+ children: /*#__PURE__*/jsx(Number, {
384
+ inline: true,
385
+ label: "Min items",
386
+ allowClear: true,
387
+ placeholder: "Minimum items...",
388
+ decorateEndShowWhenEmpty: true,
389
+ decorateEnd: /*#__PURE__*/jsx("span", {
390
+ className: "text-sm text-tint-300 px-1",
391
+ children: "OPTIONAL"
392
+ })
393
+ })
394
+ }), /*#__PURE__*/jsx(Controller, {
395
+ name: "".concat(field, ".maxItems"),
396
+ children: /*#__PURE__*/jsx(Number, {
397
+ inline: true,
398
+ label: "Max items",
399
+ allowClear: true,
400
+ placeholder: "Maximum items...",
401
+ decorateEndShowWhenEmpty: true,
402
+ decorateEnd: /*#__PURE__*/jsx("span", {
403
+ className: "text-sm text-tint-300 px-1",
404
+ children: "OPTIONAL"
405
+ })
406
+ })
407
+ })]
408
+ })]
409
+ })]
410
+ }, fieldId)
411
+ });
412
+ };
413
+
414
+ export { SchemaField };
@@ -10,6 +10,51 @@ var _excluded = ["name", "children"],
10
10
  _excluded2 = ["ref", "onChange"];
11
11
  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; }
12
12
  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; }
13
+ /**
14
+ * This component is used to wrap form controls
15
+ * and provide them with the necessary props and state management.
16
+ *
17
+ * It uses the `Controller` component from `react-hook-form`
18
+ * to manage the form state and validation.
19
+ *
20
+ * It accepts a `name` prop to identify the form control,
21
+ * and a `children` prop which can either be a React element
22
+ * or a function that receives the necessary props to render the control.
23
+ *
24
+ * The component will pass down the following props to the child:
25
+ * - `name`: the name of the form control
26
+ * - `error`: any validation error message
27
+ * - `checked`: whether the control is checked (for checkboxes/radios)
28
+ * - `value`: the current value of the control
29
+ * - `invalid`: whether the control is invalid
30
+ * - `readOnly`: whether the control is read-only (disabled during submission)
31
+ * - `disabled`: whether the control is disabled
32
+ * - `onBlur`: function to call when the control loses focus
33
+ * - `onChange`: function to call when the control value changes
34
+ * - `ref`: a ref to the control element
35
+ * * The component also handles the `ref` prop to ensure that it is passed correctly
36
+ * to the child component, allowing for proper focus management and DOM access.
37
+ *
38
+ * @param {ControllerProps} props - The properties for the Controller component.
39
+ * @returns {JSX.Element} The rendered Controller component.
40
+ *
41
+ * @example
42
+ * ```jsx
43
+ * <Controller
44
+ * name="username"
45
+ * children={({ name, error, checked, value, invalid, readOnly, onChange }) => (
46
+ * <input
47
+ * type="text"
48
+ * name={name}
49
+ * onChange={onChange}
50
+ * readOnly={readOnly}
51
+ * aria-invalid={invalid}
52
+ * value={value}
53
+ * />
54
+ * )}
55
+ * />
56
+ * ```
57
+ */
13
58
  var Controller = function Controller(_ref) {
14
59
  var name = _ref.name,
15
60
  children = _ref.children,
@@ -46,7 +91,7 @@ var Controller = function Controller(_ref) {
46
91
  (_children$props$onCha = (_children$props = children.props).onChange) === null || _children$props$onCha === void 0 || _children$props$onCha.call(_children$props, v);
47
92
  }
48
93
  })) : children(_objectSpread(_objectSpread(_objectSpread({}, field), rest), {}, {
49
- inputRef: function inputRef(el) {
94
+ ref: function ref(el) {
50
95
  el && _ref3(el);
51
96
  },
52
97
  readOnly: isSubmitting,
@@ -5,37 +5,67 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
5
5
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
6
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
7
7
  import _regeneratorRuntime from '@babel/runtime/regenerator';
8
- import { yupResolver } from '@hookform/resolvers/yup';
9
8
  import { useDebounce } from '@react-fabric/core';
9
+ import { EMPTY_OBJECT } from '@react-fabric/utilities';
10
10
  import { useRef, useTransition, useEffect, useCallback, useImperativeHandle } from 'react';
11
- import { useForm, FormProvider } from 'react-hook-form';
11
+ import { useForm as useForm$1, FormProvider, useFormContext, useWatch } from 'react-hook-form';
12
12
  import { jsx, jsxs } from 'react/jsx-runtime';
13
13
 
14
- var _excluded = ["formRef", "schema", "children", "defaultValues", "onSubmit", "onChange"];
14
+ var _excluded = ["formRef", "resolver", "children", "defaultValues", "onSubmit", "onChange"];
15
15
  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
16
  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
17
  var DEFAULT_SUBMIT = function DEFAULT_SUBMIT() {
18
18
  return undefined;
19
19
  };
20
+
21
+ /**
22
+ * Form component for managing form state and validation using react-hook-form and yup.
23
+ * It provides a simple interface for form handling, including submission, validation, and value management.
24
+ * It supports nested form structures and allows for custom validation schemas using Yup.
25
+ *
26
+ * @param {FormProps<K>} props - The properties for the Form component.
27
+ * @returns {JSX.Element} The rendered Form component.
28
+ *
29
+ * @example
30
+ * ```jsx
31
+ * <Form
32
+ * formRef={formRef}
33
+ * resolver={hookformResolver(schema)}
34
+ * defaultValues={{ name: "", email: "" }}
35
+ * onSubmit={(values) => {
36
+ * console.log("Form submitted with values:", values);
37
+ * }}
38
+ * >
39
+ * <input name="name" ref={form.register} placeholder="Name" />
40
+ * <input name="email" ref={form.register} placeholder="Email" />
41
+ * <button type="submit">Submit</button>
42
+ * </Form>
43
+ * ```
44
+ *
45
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/form-form--docs} for the properties that can be passed to this component.
46
+ * @see {@link https://react-hook-form.com/docs/useform} for more details on the properties.
47
+ * @see {@link https://github.com/jquense/yup} for more details on the Yup validation schema.
48
+ */
20
49
  var Form = function Form(_ref) {
21
50
  var formRef = _ref.formRef,
22
- schema = _ref.schema,
51
+ resolver = _ref.resolver,
23
52
  children = _ref.children,
24
- defaultValues = _ref.defaultValues,
53
+ _ref$defaultValues = _ref.defaultValues,
54
+ defaultValues = _ref$defaultValues === void 0 ? EMPTY_OBJECT : _ref$defaultValues,
25
55
  _ref$onSubmit = _ref.onSubmit,
26
- onSubmit = _ref$onSubmit === void 0 ? DEFAULT_SUBMIT : _ref$onSubmit,
56
+ _onSubmit = _ref$onSubmit === void 0 ? DEFAULT_SUBMIT : _ref$onSubmit,
27
57
  onChange = _ref.onChange,
28
58
  rest = _objectWithoutProperties(_ref, _excluded);
29
59
  var ref = useRef(null);
30
- var form = useForm({
60
+ var form = useForm$1({
31
61
  shouldFocusError: true,
32
- resolver: schema && yupResolver(schema),
62
+ resolver: resolver,
33
63
  defaultValues: defaultValues
34
64
  });
35
65
  var _useTransition = useTransition(),
36
66
  _useTransition2 = _slicedToArray(_useTransition, 2),
37
67
  startTransition = _useTransition2[1];
38
- var changeHandler = useDebounce(onChange, [onChange]);
68
+ var changeHandler = useDebounce(onChange, [onChange], 300);
39
69
  useEffect(function () {
40
70
  var subscription = form.watch(function (value) {
41
71
  startTransition(function () {
@@ -63,15 +93,15 @@ var Form = function Form(_ref) {
63
93
  return handleReset();
64
94
  },
65
95
  submit: function submit() {
66
- return form.handleSubmit(onSubmit);
96
+ return form.handleSubmit(_onSubmit);
67
97
  },
68
98
  validate: function () {
69
- var _validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
99
+ var _validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(fields) {
70
100
  return _regeneratorRuntime.wrap(function _callee$(_context) {
71
101
  while (1) switch (_context.prev = _context.next) {
72
102
  case 0:
73
103
  _context.next = 2;
74
- return form.trigger();
104
+ return form.trigger(fields);
75
105
  case 2:
76
106
  return _context.abrupt("return", _context.sent);
77
107
  case 3:
@@ -80,7 +110,7 @@ var Form = function Form(_ref) {
80
110
  }
81
111
  }, _callee);
82
112
  }));
83
- function validate() {
113
+ function validate(_x) {
84
114
  return _validate.apply(this, arguments);
85
115
  }
86
116
  return validate;
@@ -102,9 +132,10 @@ var Form = function Form(_ref) {
102
132
  }, 50);
103
133
  }
104
134
  };
105
- }, [onSubmit, form, form.formState, defaultValues]);
135
+ }, [_onSubmit, form, form.formState, defaultValues]);
106
136
  var onInvalid = useCallback(function (_, e) {
107
137
  var el = e.target;
138
+ console.log("Invalid:", _, e);
108
139
  setTimeout(function () {
109
140
  var _el$querySelector;
110
141
  return (_el$querySelector = el.querySelector("input[aria-invalid='true'],textarea[aria-invalid='true']")) === null || _el$querySelector === void 0 ? void 0 : _el$querySelector.focus();
@@ -116,7 +147,10 @@ var Form = function Form(_ref) {
116
147
  onReset: function onReset() {
117
148
  return handleReset(defaultValues);
118
149
  },
119
- onSubmit: form.handleSubmit(onSubmit, onInvalid),
150
+ onSubmit: function onSubmit(e) {
151
+ e.stopPropagation();
152
+ void form.handleSubmit(_onSubmit, onInvalid)(e);
153
+ },
120
154
  "data-loading": form.formState.isSubmitting,
121
155
  className: "contents",
122
156
  autoComplete: "off"
@@ -128,5 +162,28 @@ var Form = function Form(_ref) {
128
162
  }))
129
163
  }));
130
164
  };
165
+ var useForm = function useForm() {
166
+ var _useFormContext = useFormContext(),
167
+ formState = _useFormContext.formState,
168
+ getValues = _useFormContext.getValues,
169
+ setValue = _useFormContext.setValue,
170
+ watch = _useFormContext.watch,
171
+ reset = _useFormContext.reset,
172
+ resetField = _useFormContext.resetField,
173
+ setError = _useFormContext.setError,
174
+ setFocus = _useFormContext.setFocus;
175
+ var values = useWatch();
176
+ return {
177
+ values: _objectSpread(_objectSpread({}, values), getValues()),
178
+ formState: formState,
179
+ getValues: getValues,
180
+ setValue: setValue,
181
+ watch: watch,
182
+ reset: reset,
183
+ resetField: resetField,
184
+ setError: setError,
185
+ setFocus: setFocus
186
+ };
187
+ };
131
188
 
132
- export { Form };
189
+ export { Form, useForm };
@@ -12,6 +12,22 @@ var _excluded = ["progress", "abort"],
12
12
  _excluded2 = ["file", "progress", "abort"];
13
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ /**
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
  var useFileUploader = function useFileUploader(uploader, initialList) {
16
32
  var multiple = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
17
33
  var _useReducer = useReducer(function (state, action) {