@react-fabric/form 1.0.0-beta.9 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/{src/input/ArrayInput.module.css → css/_arrayInput.css} +8 -8
  2. package/css/_colorPicker.css +95 -0
  3. package/{src/internal/Field.module.css → css/_field.css} +94 -33
  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 +107 -78
  7. package/dist/cjs/builder/FormField.js +60 -39
  8. package/dist/cjs/builder/SchemaEditor.js +72 -0
  9. package/dist/cjs/builder/components/AddSchemaFields.js +64 -0
  10. package/dist/cjs/builder/components/SchemaArrayForm.js +146 -0
  11. package/dist/cjs/builder/components/SchemaField.js +423 -0
  12. package/dist/cjs/form/Controller.js +66 -19
  13. package/dist/cjs/form/Form.js +97 -39
  14. package/dist/cjs/form/useForm.js +32 -0
  15. package/dist/cjs/hooks/useFileUploader.js +74 -45
  16. package/dist/cjs/hooks/useFormBuilder.js +85 -31
  17. package/dist/cjs/i18n/{ar.json.js → ar/form.json.js} +5 -4
  18. package/dist/cjs/i18n/{en.json.js → en/form.json.js} +5 -5
  19. package/dist/cjs/i18n/index.js +4 -4
  20. package/dist/cjs/index.js +41 -2
  21. package/dist/cjs/input/ArrayInput.js +259 -135
  22. package/dist/cjs/input/AvatarInput.js +99 -63
  23. package/dist/cjs/input/Checkbox.js +24 -25
  24. package/dist/cjs/input/ColorInput.js +138 -81
  25. package/dist/cjs/input/ColorPicker.js +78 -95
  26. package/dist/cjs/input/DateInput.js +192 -0
  27. package/dist/cjs/input/Field.js +21 -20
  28. package/dist/cjs/input/File.js +85 -80
  29. package/dist/cjs/input/Hidden.js +27 -13
  30. package/dist/cjs/input/Input.js +49 -48
  31. package/dist/cjs/input/Number.js +46 -44
  32. package/dist/cjs/input/Password.js +51 -49
  33. package/dist/cjs/input/Radio.js +26 -16
  34. package/dist/cjs/input/RadioGroup.js +26 -11
  35. package/dist/cjs/input/{Range.js → RangeSlider.js} +61 -66
  36. package/dist/cjs/input/Search.js +58 -64
  37. package/dist/cjs/input/Slider.js +57 -66
  38. package/dist/cjs/input/Switch.js +29 -27
  39. package/dist/cjs/input/Textarea.js +65 -53
  40. package/dist/cjs/internal/ErrorIcon.js +9 -9
  41. package/dist/cjs/internal/FieldWrapper.js +23 -13
  42. package/dist/cjs/internal/InputWrapper.js +85 -87
  43. package/dist/cjs/ranger/index.js +7 -7
  44. package/dist/cjs/ranger/utils.js +9 -4
  45. package/dist/cjs/select/AutoComplete.js +93 -76
  46. package/dist/cjs/select/DualList.js +235 -154
  47. package/dist/cjs/select/List.js +122 -89
  48. package/dist/cjs/select/Options.js +58 -54
  49. package/dist/cjs/select/Select.js +119 -89
  50. package/dist/cjs/select/helpers.js +5 -5
  51. package/dist/cjs/select/useSelect.js +83 -58
  52. package/dist/cjs/types/schema.js +43 -0
  53. package/dist/cjs/utils/eventHandlers.js +16 -6
  54. package/dist/cjs/utils/getColor.js +6 -6
  55. package/dist/cjs/utils/getProps.js +49 -0
  56. package/dist/esm/builder/FileField.js +109 -80
  57. package/dist/esm/builder/FormField.js +60 -39
  58. package/dist/esm/builder/SchemaEditor.js +72 -0
  59. package/dist/esm/builder/components/AddSchemaFields.js +64 -0
  60. package/dist/esm/builder/components/SchemaArrayForm.js +146 -0
  61. package/dist/esm/builder/components/SchemaField.js +423 -0
  62. package/dist/esm/form/Controller.js +66 -19
  63. package/dist/esm/form/Form.js +97 -39
  64. package/dist/esm/form/useForm.js +32 -0
  65. package/dist/esm/hooks/useFileUploader.js +75 -46
  66. package/dist/esm/hooks/useFormBuilder.js +84 -30
  67. package/dist/esm/i18n/{ar.json.js → ar/form.json.js} +5 -4
  68. package/dist/esm/i18n/{en.json.js → en/form.json.js} +5 -5
  69. package/dist/esm/i18n/index.js +2 -2
  70. package/dist/esm/index.js +36 -1
  71. package/dist/esm/input/ArrayInput.js +260 -136
  72. package/dist/esm/input/AvatarInput.js +99 -63
  73. package/dist/esm/input/Checkbox.js +26 -27
  74. package/dist/esm/input/ColorInput.js +141 -84
  75. package/dist/esm/input/ColorPicker.js +80 -97
  76. package/dist/esm/input/DateInput.js +192 -0
  77. package/dist/esm/input/Field.js +21 -20
  78. package/dist/esm/input/File.js +89 -84
  79. package/dist/esm/input/Hidden.js +28 -14
  80. package/dist/esm/input/Input.js +51 -50
  81. package/dist/esm/input/Number.js +48 -46
  82. package/dist/esm/input/Password.js +54 -52
  83. package/dist/esm/input/Radio.js +27 -17
  84. package/dist/esm/input/RadioGroup.js +27 -12
  85. package/dist/esm/input/{Range.js → RangeSlider.js} +62 -67
  86. package/dist/esm/input/Search.js +61 -67
  87. package/dist/esm/input/Slider.js +58 -67
  88. package/dist/esm/input/Switch.js +31 -29
  89. package/dist/esm/input/Textarea.js +67 -55
  90. package/dist/esm/internal/ErrorIcon.js +11 -11
  91. package/dist/esm/internal/FieldWrapper.js +23 -13
  92. package/dist/esm/internal/InputWrapper.js +88 -90
  93. package/dist/esm/ranger/index.js +7 -7
  94. package/dist/esm/ranger/utils.js +9 -4
  95. package/dist/esm/select/AutoComplete.js +95 -78
  96. package/dist/esm/select/DualList.js +233 -152
  97. package/dist/esm/select/List.js +125 -92
  98. package/dist/esm/select/Options.js +58 -54
  99. package/dist/esm/select/Select.js +122 -92
  100. package/dist/esm/select/helpers.js +5 -5
  101. package/dist/esm/select/useSelect.js +84 -59
  102. package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
  103. package/dist/esm/utils/eventHandlers.js +16 -6
  104. package/dist/esm/utils/getColor.js +6 -6
  105. package/dist/esm/utils/getProps.js +49 -0
  106. package/dist/types/builder/FileField.d.ts +7 -4
  107. package/dist/types/builder/FormField.d.ts +4 -2
  108. package/dist/types/builder/SchemaEditor.d.ts +6 -0
  109. package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
  110. package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
  111. package/dist/types/builder/components/SchemaField.d.ts +12 -0
  112. package/dist/types/form/Controller.d.ts +45 -3
  113. package/dist/types/form/Form.d.ts +38 -7
  114. package/dist/types/form/useForm.d.ts +6 -0
  115. package/dist/types/hooks/useFileUploader.d.ts +24 -3
  116. package/dist/types/hooks/useFormBuilder.d.ts +41 -3
  117. package/dist/types/index.d.ts +32 -2
  118. package/dist/types/input/ArrayInput.d.ts +68 -13
  119. package/dist/types/input/AvatarInput.d.ts +23 -6
  120. package/dist/types/input/Checkbox.d.ts +12 -10
  121. package/dist/types/input/ColorInput.d.ts +15 -5
  122. package/dist/types/input/ColorPicker.d.ts +10 -2
  123. package/dist/types/input/DateInput.d.ts +21 -0
  124. package/dist/types/input/Field.d.ts +9 -36
  125. package/dist/types/input/File.d.ts +16 -4
  126. package/dist/types/input/Hidden.d.ts +7 -6
  127. package/dist/types/input/Input.d.ts +11 -4
  128. package/dist/types/input/Number.d.ts +9 -4
  129. package/dist/types/input/Password.d.ts +9 -4
  130. package/dist/types/input/Radio.d.ts +9 -4
  131. package/dist/types/input/RadioGroup.d.ts +14 -6
  132. package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +11 -6
  133. package/dist/types/input/Search.d.ts +14 -4
  134. package/dist/types/input/Slider.d.ts +9 -6
  135. package/dist/types/input/Switch.d.ts +13 -8
  136. package/dist/types/input/Textarea.d.ts +15 -4
  137. package/dist/types/internal/ErrorIcon.d.ts +4 -1
  138. package/dist/types/internal/FieldWrapper.d.ts +10 -1
  139. package/dist/types/internal/InputWrapper.d.ts +19 -1
  140. package/dist/types/ranger/index.d.ts +7 -3
  141. package/dist/types/ranger/utils.d.ts +2 -2
  142. package/dist/types/select/AutoComplete.d.ts +7 -2
  143. package/dist/types/select/DualList.d.ts +11 -37
  144. package/dist/types/select/List.d.ts +7 -2
  145. package/dist/types/select/Options.d.ts +8 -7
  146. package/dist/types/select/Select.d.ts +7 -2
  147. package/dist/types/select/helpers.d.ts +2 -2
  148. package/dist/types/select/useSelect.d.ts +10 -28
  149. package/dist/types/types/index.d.ts +73 -39
  150. package/dist/types/types/schema.d.ts +78 -32
  151. package/dist/types/utils/eventHandlers.d.ts +4 -4
  152. package/dist/types/utils/getColor.d.ts +4 -4
  153. package/dist/types/utils/getProps.d.ts +26 -0
  154. package/dist/types/utils/index.d.ts +1 -0
  155. package/package.json +25 -25
  156. package/src/builder/FileField.tsx +73 -56
  157. package/src/builder/FormField.tsx +66 -58
  158. package/src/builder/SchemaEditor.tsx +78 -0
  159. package/src/builder/components/AddSchemaFields.tsx +64 -0
  160. package/src/builder/components/SchemaArrayForm.tsx +146 -0
  161. package/src/builder/components/SchemaField.tsx +405 -0
  162. package/src/form/Controller.tsx +61 -24
  163. package/src/form/Form.tsx +74 -50
  164. package/src/form/useForm.ts +53 -0
  165. package/src/hooks/useFileUploader.ts +115 -84
  166. package/src/hooks/useFormBuilder.tsx +80 -41
  167. package/src/i18n/{ar.json → ar/form.json} +5 -4
  168. package/src/i18n/{en.json → en/form.json} +5 -5
  169. package/src/i18n/index.ts +2 -2
  170. package/src/index.ts +34 -20
  171. package/src/input/ArrayInput.tsx +255 -173
  172. package/src/input/AvatarInput.tsx +82 -39
  173. package/src/input/Checkbox.tsx +30 -54
  174. package/src/input/ColorInput.tsx +146 -105
  175. package/src/input/ColorPicker.tsx +76 -102
  176. package/src/input/DateInput.tsx +225 -0
  177. package/src/input/Field.tsx +23 -65
  178. package/src/input/File.tsx +76 -98
  179. package/src/input/Hidden.tsx +36 -24
  180. package/src/input/Input.tsx +55 -53
  181. package/src/input/Number.tsx +49 -54
  182. package/src/input/Password.tsx +61 -66
  183. package/src/input/Radio.tsx +28 -37
  184. package/src/input/RadioGroup.tsx +30 -25
  185. package/src/input/{Range.tsx → RangeSlider.tsx} +81 -109
  186. package/src/input/Search.tsx +64 -77
  187. package/src/input/Slider.tsx +80 -109
  188. package/src/input/Switch.tsx +39 -53
  189. package/src/input/Textarea.tsx +72 -59
  190. package/src/internal/ErrorIcon.tsx +22 -21
  191. package/src/internal/FieldWrapper.tsx +33 -23
  192. package/src/internal/InputWrapper.tsx +132 -143
  193. package/src/ranger/index.tsx +37 -117
  194. package/src/ranger/utils.ts +12 -11
  195. package/src/select/AutoComplete.tsx +113 -123
  196. package/src/select/DualList.tsx +218 -204
  197. package/src/select/List.tsx +130 -97
  198. package/src/select/Options.tsx +59 -57
  199. package/src/select/Select.tsx +148 -122
  200. package/src/select/helpers.ts +13 -8
  201. package/src/select/useSelect.tsx +110 -127
  202. package/src/types/index.ts +76 -45
  203. package/src/types/schema.ts +97 -40
  204. package/src/utils/eventHandlers.ts +24 -26
  205. package/src/utils/getColor.ts +9 -8
  206. package/src/utils/getProps.ts +47 -0
  207. package/src/utils/index.ts +1 -0
  208. package/dist/cjs/input/ArrayInput.module.css +0 -1
  209. package/dist/cjs/input/ColorPicker.module.css +0 -1
  210. package/dist/cjs/input/File.module.css +0 -1
  211. package/dist/cjs/internal/Field.module.css +0 -1
  212. package/dist/esm/input/ArrayInput.module.css +0 -1
  213. package/dist/esm/input/ColorPicker.module.css +0 -1
  214. package/dist/esm/input/File.module.css +0 -1
  215. package/dist/esm/internal/Field.module.css +0 -1
@@ -9,28 +9,34 @@ var react = require('react');
9
9
  var helpers = require('./helpers.js');
10
10
 
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
- 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
- var useSelect = function useSelect(_ref) {
14
- var _ref$options = _ref.options,
15
- options = _ref$options === void 0 ? utilities.EMPTY_ARRAY : _ref$options,
16
- value = _ref.value,
17
- autoComplete = _ref.autoComplete,
18
- _ref$multiple = _ref.multiple,
19
- multiple = _ref$multiple === void 0 ? false : _ref$multiple,
20
- _ref$allowCreate = _ref.allowCreate,
21
- allowCreate = _ref$allowCreate === void 0 ? false : _ref$allowCreate,
22
- _ref$groupProperty = _ref.groupProperty,
23
- groupProperty = _ref$groupProperty === void 0 ? "" : _ref$groupProperty,
24
- _ref$valueProperty = _ref.valueProperty,
25
- valueProperty = _ref$valueProperty === void 0 ? "id" : _ref$valueProperty,
26
- _ref$labelProperty = _ref.labelProperty,
27
- labelProperty = _ref$labelProperty === void 0 ? "label" : _ref$labelProperty,
28
- _ref$createOption = _ref.createOption,
29
- createOption = _ref$createOption === void 0 ? helpers.makeOption : _ref$createOption,
30
- matcher = _ref.matcher,
31
- onQuery = _ref.onQuery,
32
- onChange = _ref.onChange,
33
- onSelect = _ref.onSelect;
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
+ function useSelect(props) {
14
+ var _props$options = props.options,
15
+ options = _props$options === void 0 ? utilities.EMPTY_ARRAY : _props$options,
16
+ value = props.value,
17
+ autoComplete = props.autoComplete,
18
+ _props$alwaysOpen = props.alwaysOpen,
19
+ alwaysOpen = _props$alwaysOpen === void 0 ? false : _props$alwaysOpen,
20
+ _props$defaultOpen = props.defaultOpen,
21
+ defaultOpen = _props$defaultOpen === void 0 ? false : _props$defaultOpen,
22
+ _props$multiple = props.multiple,
23
+ multiple = _props$multiple === void 0 ? false : _props$multiple,
24
+ _props$allowCreate = props.allowCreate,
25
+ allowCreate = _props$allowCreate === void 0 ? false : _props$allowCreate,
26
+ _props$groupProperty = props.groupProperty,
27
+ groupProperty = _props$groupProperty === void 0 ? "" : _props$groupProperty,
28
+ _props$valueProperty = props.valueProperty,
29
+ valueProperty = _props$valueProperty === void 0 ? "value" : _props$valueProperty,
30
+ _props$labelProperty = props.labelProperty,
31
+ labelProperty = _props$labelProperty === void 0 ? "label" : _props$labelProperty,
32
+ sortProperty = props.sortProperty,
33
+ _props$createOption = props.createOption,
34
+ createOption = _props$createOption === void 0 ? helpers.makeOption : _props$createOption,
35
+ matcher = props.matcher,
36
+ onQuery = props.onQuery,
37
+ onChange = props.onChange,
38
+ onSelect = props.onSelect;
39
+
34
40
  // value state
35
41
  var emptyValue = react.useMemo(function () {
36
42
  return multiple ? [] : "";
@@ -42,16 +48,17 @@ var useSelect = function useSelect(_ref) {
42
48
  var focusableRef = react.useRef(null);
43
49
  var listContentRef = react.useRef([]);
44
50
  var optionsRef = react.useRef([]);
45
- var macthOption = react.useCallback(function (item, query) {
51
+ var matchOption = react.useCallback(function (item, query) {
46
52
  var _matcher, _item$labelProperty;
47
53
  return (_matcher = matcher === null || matcher === void 0 ? void 0 : matcher(item, query)) !== null && _matcher !== void 0 ? _matcher : utilities.matchString((_item$labelProperty = item[labelProperty]) !== null && _item$labelProperty !== void 0 ? _item$labelProperty : item, query);
48
- }, [matcher]);
54
+ }, [labelProperty, matcher]);
49
55
  var fireChange = react.useCallback(function (value) {
50
56
  setTimeout(function () {
51
57
  onSelect === null || onSelect === void 0 || onSelect(value !== null && value !== void 0 ? value : emptyValue);
58
+ // @ts-expect-error ignore
52
59
  onChange === null || onChange === void 0 || onChange(helpers.getSelectedValue(value, emptyValue, valueProperty));
53
60
  }, 50);
54
- }, [emptyValue, onSelect, onChange]);
61
+ }, [onSelect, emptyValue, onChange, valueProperty]);
55
62
  var _useReducer = react.useReducer(function (state, action) {
56
63
  if (action.type === "open") {
57
64
  var index = state.items.indexOf(state.multiple ? state.value[0] : state.value);
@@ -63,13 +70,15 @@ var useSelect = function useSelect(_ref) {
63
70
  if (action.type === "close") {
64
71
  return _objectSpread(_objectSpread({}, state), {}, {
65
72
  activeIndex: null,
73
+ activeItem: null,
66
74
  open: false
67
75
  });
68
76
  }
69
77
  if (action.type === "active" && state.open) {
70
78
  if (autoComplete && action.index !== null) state.query = state.items[action.index];
71
79
  return _objectSpread(_objectSpread({}, state), {}, {
72
- activeIndex: action.index
80
+ activeIndex: action.index,
81
+ activeItem: action.index !== null ? state.items[action.index] : null
73
82
  });
74
83
  }
75
84
  if (action.type === "setValue") {
@@ -83,6 +92,7 @@ var useSelect = function useSelect(_ref) {
83
92
  var newState = _objectSpread(_objectSpread({}, state), {}, {
84
93
  value: state.emptyValue,
85
94
  activeIndex: null,
95
+ activeItem: null,
86
96
  selectedIndex: autoComplete ? state.multiple ? (_action$value = action.value) === null || _action$value === void 0 ? void 0 : _action$value.length : 0 : state.items.indexOf(action.value)
87
97
  });
88
98
  if (action.value !== undefined) {
@@ -100,7 +110,7 @@ var useSelect = function useSelect(_ref) {
100
110
  newState.value = action.value;
101
111
  }
102
112
  }
103
- if (!state.multiple) newState.open = false;
113
+ if (!state.multiple) newState.open = alwaysOpen;
104
114
  fireChange(newState.value);
105
115
  return newState;
106
116
  }
@@ -133,19 +143,20 @@ var useSelect = function useSelect(_ref) {
133
143
  if (autoComplete && action.query !== undefined) {
134
144
  optionList = utilities.dedupe([action.query].concat(_toConsumableArray(optionList)));
135
145
  }
146
+ if (sortProperty) optionList = optionList.sort(utilities.compareValues("asc", sortProperty !== true ? sortProperty : undefined));
136
147
  var grouped = utilities.groupBy(optionList, groupProperty, "");
137
148
  if (action.open) _newState.open = true;
138
149
  _newState.items = [];
139
150
  // add new item if allowCreate
140
151
  if (allowCreate && action.query) _newState.items.push({
141
152
  ___create___: true,
142
- value: createOption(action.query)
153
+ value: action.query
143
154
  });
144
- Object.entries(grouped).forEach(function (_ref2) {
155
+ Object.entries(grouped).forEach(function (_ref) {
145
156
  var _newState$items;
146
- var _ref3 = _slicedToArray(_ref2, 2),
147
- key = _ref3[0],
148
- list = _ref3[1];
157
+ var _ref2 = _slicedToArray(_ref, 2),
158
+ key = _ref2[0],
159
+ list = _ref2[1];
149
160
  if (key) {
150
161
  _newState.items.push({
151
162
  ___group___: true,
@@ -159,32 +170,38 @@ var useSelect = function useSelect(_ref) {
159
170
  return !opt.___group___;
160
171
  });
161
172
  _newState.activeIndex = _index >= 0 ? _index : null;
173
+ _newState.activeItem = _index >= 0 ? _newState.items[_index] : null;
162
174
  } else {
163
175
  _newState.activeIndex = null;
176
+ _newState.activeItem = null;
164
177
  }
165
178
  listContentRef.current = _newState.items;
166
179
  return _newState;
167
180
  }
168
181
  return state;
169
- }, {
170
- multiple: multiple,
171
- emptyValue: emptyValue,
172
- open: false,
173
- loading: false,
174
- activeIndex: null,
175
- selectedIndex: null,
176
- value: emptyValue,
177
- // filter
178
- query: undefined,
179
- // dropdown items
180
- items: []
182
+ }, {}, function () {
183
+ return {
184
+ multiple: multiple,
185
+ emptyValue: emptyValue,
186
+ open: alwaysOpen || defaultOpen,
187
+ loading: false,
188
+ activeIndex: null,
189
+ activeItem: null,
190
+ selectedIndex: null,
191
+ value: emptyValue,
192
+ // filter
193
+ query: undefined,
194
+ // dropdown items
195
+ items: []
196
+ };
181
197
  }),
182
198
  _useReducer2 = _slicedToArray(_useReducer, 2),
183
199
  state = _useReducer2[0],
184
200
  dispatch = _useReducer2[1];
185
201
  react.useEffect(function () {
186
202
  if (!multiple) {
187
- var _ref4;
203
+ var _ref3;
204
+ // @ts-expect-error ignore
188
205
  var newOption = (allowCreate || autoComplete) && deferred ? createOption(deferred) : undefined;
189
206
  var hasValue = options.find(function (opt) {
190
207
  var _opt$valueProperty;
@@ -201,22 +218,22 @@ var useSelect = function useSelect(_ref) {
201
218
  });
202
219
  dispatch({
203
220
  type: "setValue",
204
- value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : ""
221
+ value: (_ref3 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref3 !== void 0 ? _ref3 : deferred
205
222
  });
206
223
  }
207
224
  if (multiple) {
208
225
  optionsRef.current = [];
209
226
  var _value = (utilities.isArray(deferred) ? deferred : []).map(function (item) {
210
- var _ref5;
227
+ var _ref4;
211
228
  var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
212
229
  var hasValue = options.find(function (opt) {
213
230
  var _opt$valueProperty2;
214
- return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === deferred;
231
+ return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === item;
215
232
  });
216
233
  if (!hasValue && newOption) {
217
234
  optionsRef.current.push(newOption);
218
235
  }
219
- return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 : "";
236
+ return (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : item;
220
237
  });
221
238
  optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(options !== null && options !== void 0 ? options : []));
222
239
  dispatch({
@@ -228,14 +245,15 @@ var useSelect = function useSelect(_ref) {
228
245
  value: _value
229
246
  });
230
247
  }
231
- }, [deferred, options, multiple, allowCreate, autoComplete, createOption]);
248
+ }, [deferred, options, multiple, allowCreate, autoComplete, createOption, valueProperty]);
232
249
  var fireQuery = core.useDebounce(function (query) {
233
250
  void Promise.resolve(onQuery === null || onQuery === void 0 ? void 0 : onQuery(query)).then(function (options) {
251
+ // @ts-expect-error ignore
234
252
  var newOptions = _toConsumableArray(options);
235
253
  // if autocomplete inject other filtered options from history
236
254
  if (autoComplete) {
237
255
  newOptions.push.apply(newOptions, _toConsumableArray(optionsRef.current.filter(function (opt) {
238
- return macthOption === null || macthOption === void 0 ? void 0 : macthOption(opt, query);
256
+ return matchOption === null || matchOption === void 0 ? void 0 : matchOption(opt, query);
239
257
  })));
240
258
  }
241
259
  dispatch({
@@ -246,7 +264,7 @@ var useSelect = function useSelect(_ref) {
246
264
  setActive: true
247
265
  });
248
266
  });
249
- }, [onQuery]);
267
+ }, [onQuery], 300);
250
268
 
251
269
  // handlers
252
270
  var handleQuery = react.useCallback(function (query) {
@@ -270,11 +288,11 @@ var useSelect = function useSelect(_ref) {
270
288
  open: true,
271
289
  setActive: true,
272
290
  options: optionsRef.current.filter(function (opt) {
273
- return macthOption === null || macthOption === void 0 ? void 0 : macthOption(opt, query);
291
+ return matchOption === null || matchOption === void 0 ? void 0 : matchOption(opt, query);
274
292
  })
275
293
  });
276
294
  }
277
- }, [macthOption, onQuery]);
295
+ }, [fireQuery, matchOption, onQuery]);
278
296
  var handleChange = react.useCallback(function (value) {
279
297
  var values = value;
280
298
  if (autoComplete && multiple && value) {
@@ -298,7 +316,7 @@ var useSelect = function useSelect(_ref) {
298
316
  type: "options",
299
317
  options: optionsRef.current
300
318
  });
301
- }, []);
319
+ }, [autoComplete, createOption, multiple]);
302
320
  var handleRemove = react.useCallback(function (index) {
303
321
  dispatch({
304
322
  type: "removeItem",
@@ -316,11 +334,17 @@ var useSelect = function useSelect(_ref) {
316
334
  });
317
335
  }, []);
318
336
  var setActiveIndex = react.useCallback(function (index) {
319
- dispatch({
337
+ if (index && index > -1) dispatch({
320
338
  type: "active",
321
339
  index: index
322
340
  });
323
341
  }, []);
342
+ var clearActiveIndex = react.useCallback(function () {
343
+ dispatch({
344
+ type: "active",
345
+ index: null
346
+ });
347
+ }, []);
324
348
  return {
325
349
  state: state,
326
350
  listRef: listRef,
@@ -329,13 +353,14 @@ var useSelect = function useSelect(_ref) {
329
353
  handleChange: handleChange,
330
354
  handleRemove: handleRemove,
331
355
  handleQuery: handleQuery,
332
- macthOption: macthOption,
356
+ clearActiveIndex: clearActiveIndex,
357
+ macthOption: matchOption,
333
358
  setActiveIndex: setActiveIndex,
334
359
  setOpen: setOpen,
335
360
  setItemRef: function setItemRef(index, node) {
336
361
  listRef.current[index] = node;
337
362
  }
338
363
  };
339
- };
364
+ }
340
365
 
341
366
  exports.useSelect = useSelect;
@@ -0,0 +1,43 @@
1
+ 'use strict';
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["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--";
41
+
42
+ exports.DATA_TYPES = DATA_TYPES;
43
+ exports.SCHEMA_CUSTOM_LIST = SCHEMA_CUSTOM_LIST;
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var utilities = require('@react-fabric/utilities');
3
+ var react = require('@floating-ui/react');
4
+ var core = require('@react-fabric/core');
4
5
 
5
6
  /*
6
7
  * React Fabric
@@ -26,16 +27,25 @@ var utilities = require('@react-fabric/utilities');
26
27
  */
27
28
 
28
29
  /** ***************** common handler for enter press *******************/
29
- var handleEnter = function handleEnter(callback) {
30
+ 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 = utilities.debounce(callback !== null && callback !== void 0 ? callback : function () {
36
+ var cbHandle = core.useDebounce(callback !== null && callback !== void 0 ? callback : function () {
36
37
  return undefined;
37
- }, 100);
38
+ }, [callback], 100);
39
+ var tree = react.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
+ }
45
+ // blur input on escape key press
46
+ if (e.key === "Escape") {
47
+ e.currentTarget.blur();
48
+ }
39
49
  if (!e.shiftKey && !e.altKey && !e.metaKey && e.key === "Enter" && callback) {
40
50
  if (stopPropagation) e === null || e === void 0 || e.stopPropagation();
41
51
  cbHandle(e);
@@ -45,6 +55,6 @@ var handleEnter = function handleEnter(callback) {
45
55
  }
46
56
  }
47
57
  };
48
- };
58
+ }
49
59
 
50
- exports.handleEnter = handleEnter;
60
+ exports.useHandleEnter = useHandleEnter;
@@ -25,21 +25,21 @@ var utilities = require('@react-fabric/utilities');
25
25
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
26
  */
27
27
 
28
- var getColor = function getColor(color) {
28
+ function getColor(color) {
29
29
  if (color && utilities.isColor(color)) {
30
30
  return color;
31
31
  }
32
- };
33
- var getBgClass = function getBgClass(bg) {
32
+ }
33
+ function getBgClass(bg) {
34
34
  if (bg && !utilities.isColor(bg)) {
35
35
  return "bg-".concat(bg);
36
36
  }
37
- };
38
- var getColorClass = function getColorClass(color) {
37
+ }
38
+ function getColorClass(color) {
39
39
  if (color && !utilities.isColor(color)) {
40
40
  return "text-".concat(color);
41
41
  }
42
- };
42
+ }
43
43
 
44
44
  exports.getBgClass = getBgClass;
45
45
  exports.getColor = getColor;
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * React Fabric
5
+ * @version 1.0.0
6
+ * @license MIT
7
+ * @copyright 2024 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ function getWrapperProps(props) {
29
+ return {
30
+ appendLabel: props.appendLabel,
31
+ name: props.name,
32
+ info: props.info,
33
+ inline: props.inline,
34
+ label: props.label,
35
+ labelWidth: props.labelWidth,
36
+ required: props.required,
37
+ disabled: props.disabled,
38
+ width: props.width,
39
+ error: props.error,
40
+ invalid: props.invalid,
41
+ borderless: props.borderless,
42
+ decorateEnd: props.decorateEnd,
43
+ decorateEndHideWhenEmpty: props.decorateEndHideWhenEmpty,
44
+ decorateEndShowWhenEmpty: props.decorateEndShowWhenEmpty,
45
+ decorateStart: props.decorateStart
46
+ };
47
+ }
48
+
49
+ exports.getWrapperProps = getWrapperProps;