@react-fabric/form 1.0.0-beta.3 → 1.0.0-beta.31

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 (66) hide show
  1. package/dist/cjs/form/Form.js +12 -5
  2. package/dist/cjs/input/ArrayInput.js +35 -23
  3. package/dist/cjs/input/ColorInput.js +68 -26
  4. package/dist/cjs/input/ColorPicker.js +0 -33
  5. package/dist/cjs/input/ColorPicker.module.css +1 -1
  6. package/dist/cjs/input/Field.js +3 -2
  7. package/dist/cjs/input/File.module.css +1 -1
  8. package/dist/cjs/input/Hidden.js +3 -1
  9. package/dist/cjs/input/RadioGroup.js +6 -3
  10. package/dist/cjs/input/Switch.js +25 -4
  11. package/dist/cjs/input/Textarea.js +6 -2
  12. package/dist/cjs/internal/FieldWrapper.js +3 -1
  13. package/dist/cjs/internal/InputWrapper.js +7 -10
  14. package/dist/cjs/select/List.js +41 -20
  15. package/dist/cjs/select/Options.js +2 -2
  16. package/dist/cjs/select/Select.js +10 -7
  17. package/dist/cjs/select/useSelect.js +12 -7
  18. package/dist/cjs/utils/getColor.js +6 -0
  19. package/dist/esm/form/Form.js +13 -6
  20. package/dist/esm/input/ArrayInput.js +37 -25
  21. package/dist/esm/input/ColorInput.js +70 -28
  22. package/dist/esm/input/ColorPicker.js +0 -33
  23. package/dist/esm/input/ColorPicker.module.css +1 -1
  24. package/dist/esm/input/Field.js +4 -3
  25. package/dist/esm/input/File.module.css +1 -1
  26. package/dist/esm/input/Hidden.js +3 -1
  27. package/dist/esm/input/RadioGroup.js +7 -4
  28. package/dist/esm/input/Switch.js +27 -6
  29. package/dist/esm/input/Textarea.js +6 -2
  30. package/dist/esm/internal/FieldWrapper.js +3 -1
  31. package/dist/esm/internal/InputWrapper.js +7 -10
  32. package/dist/esm/select/List.js +42 -21
  33. package/dist/esm/select/Options.js +2 -2
  34. package/dist/esm/select/Select.js +10 -7
  35. package/dist/esm/select/useSelect.js +13 -8
  36. package/dist/esm/utils/getColor.js +6 -1
  37. package/dist/types/input/ArrayInput.d.ts +20 -3
  38. package/dist/types/input/RadioGroup.d.ts +18 -2
  39. package/dist/types/input/Switch.d.ts +7 -3
  40. package/dist/types/input/Textarea.d.ts +5 -1
  41. package/dist/types/internal/InputWrapper.d.ts +1 -1
  42. package/dist/types/select/List.d.ts +1 -1
  43. package/dist/types/types/index.d.ts +2 -2
  44. package/package.json +7 -7
  45. package/src/form/Form.tsx +13 -5
  46. package/src/input/ArrayInput.tsx +78 -40
  47. package/src/input/ColorInput.tsx +96 -31
  48. package/src/input/ColorPicker.module.css +19 -5
  49. package/src/input/ColorPicker.tsx +0 -33
  50. package/src/input/Field.tsx +6 -8
  51. package/src/input/File.module.css +18 -4
  52. package/src/input/Hidden.tsx +3 -1
  53. package/src/input/Input.tsx +1 -1
  54. package/src/input/Number.tsx +1 -1
  55. package/src/input/Password.tsx +1 -1
  56. package/src/input/RadioGroup.tsx +27 -4
  57. package/src/input/Search.tsx +1 -1
  58. package/src/input/Switch.tsx +40 -6
  59. package/src/input/Textarea.tsx +10 -2
  60. package/src/internal/FieldWrapper.tsx +2 -1
  61. package/src/internal/InputWrapper.tsx +8 -11
  62. package/src/select/List.tsx +34 -7
  63. package/src/select/Options.tsx +1 -1
  64. package/src/select/Select.tsx +4 -1
  65. package/src/select/useSelect.tsx +27 -18
  66. package/src/types/index.ts +5 -2
@@ -13,26 +13,27 @@ var Options = require('./Options.js');
13
13
  var useSelect = require('./useSelect.js');
14
14
  var jsxRuntime = require('react/jsx-runtime');
15
15
 
16
- var _excluded = ["ref", "name", "value", "readOnly", "disabled", "required", "placeholder", "autoFocus", "options", "height", "groupProperty", "labelProperty", "valueProperty", "multiple", "allowCreate", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed", "invalid", "error", "allowClear", "decorateStart", "decorateEnd", "data-inner", "data-hide-selected"];
16
+ var _excluded = ["ref", "name", "value", "readOnly", "disabled", "required", "placeholder", "autoFocus", "options", "height", "groupProperty", "labelProperty", "valueProperty", "multiple", "allowCreate", "searchable", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed", "invalid", "error", "allowClear", "decorateStart", "decorateEnd", "data-inner", "data-hide-selected"];
17
17
  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; }
18
18
  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; }
19
19
  var List = function List(_ref) {
20
20
  var _state$query;
21
- _ref.ref;
22
- var name = _ref.name,
21
+ var ref = _ref.ref,
22
+ name = _ref.name,
23
23
  value = _ref.value,
24
24
  readOnly = _ref.readOnly,
25
25
  disabled = _ref.disabled,
26
26
  required = _ref.required,
27
- placeholder = _ref.placeholder;
28
- _ref.autoFocus;
29
- var options = _ref.options,
27
+ placeholder = _ref.placeholder,
28
+ autoFocus = _ref.autoFocus,
29
+ options = _ref.options,
30
30
  height = _ref.height,
31
31
  groupProperty = _ref.groupProperty,
32
32
  labelProperty = _ref.labelProperty,
33
33
  valueProperty = _ref.valueProperty,
34
34
  multiple = _ref.multiple,
35
35
  allowCreate = _ref.allowCreate,
36
+ searchable = _ref.searchable,
36
37
  createOption = _ref.createOption,
37
38
  matcher = _ref.matcher,
38
39
  renderer = _ref.renderer,
@@ -138,9 +139,10 @@ var List = function List(_ref) {
138
139
  }
139
140
  } else if (evt.key === "Backspace") {
140
141
  !state.query && handleRemove();
141
- } else if (["ArrowUp", "ArrowDown"].includes(evt.key)) {
142
- if (state.activeIndex === null) {
143
- setActiveIndex(state.selectedIndex);
142
+ } else if (!searchable || ["ArrowUp", "ArrowDown"].includes(evt.key)) {
143
+ if (["ArrowUp", "ArrowDown"].includes(evt.key) && state.activeIndex === null) {
144
+ var _state$selectedIndex;
145
+ setActiveIndex((_state$selectedIndex = state.selectedIndex) !== null && _state$selectedIndex !== void 0 ? _state$selectedIndex : 0);
144
146
  }
145
147
  setTimeout(function () {
146
148
  var _props$onKeyDown;
@@ -185,6 +187,14 @@ var List = function List(_ref) {
185
187
  });
186
188
  }
187
189
  }, [state.value, state.query, placeholder, renderer]);
190
+ react.useLayoutEffect(function () {
191
+ setTimeout(function () {
192
+ var _listRef$current$stat;
193
+ state.selectedIndex && ((_listRef$current$stat = listRef.current[state.selectedIndex]) === null || _listRef$current$stat === void 0 ? void 0 : _listRef$current$stat.scrollIntoView({
194
+ block: "center"
195
+ }));
196
+ }, 100);
197
+ }, [state.selectedIndex]);
188
198
  return /*#__PURE__*/jsxRuntime.jsxs(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
189
199
  children: [/*#__PURE__*/jsxRuntime.jsx(InputWrapper.InputWrapper, {
190
200
  showClear: !utilities.isEmpty(state.value),
@@ -197,23 +207,32 @@ var List = function List(_ref) {
197
207
  className: "z-1 rounded-b-none",
198
208
  "data-inner": true,
199
209
  wrapperRef: refs.setReference,
200
- children: /*#__PURE__*/jsxRuntime.jsxs("div", {
210
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({
211
+ role: "none",
201
212
  "data-select-display": "true",
202
- className: "group flex-1 py-1 px-2 truncate text-start flex gap-1 flex-wrap",
203
- children: [!hideSelected && displayValue, /*#__PURE__*/jsxRuntime.jsx("input", _objectSpread(_objectSpread({
213
+ className: classNames("group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start", multiple ? "flex-wrap" : "flex-nowrap overflow-hidden")
214
+ }, referenceProps), {}, {
215
+ onMouseUp: function onMouseUp(e) {
216
+ var _e$currentTarget$quer;
217
+ return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
218
+ },
219
+ children: [!hideSelected && displayValue, /*#__PURE__*/jsxRuntime.jsx("input", {
220
+ readOnly: !searchable || readOnly,
204
221
  disabled: disabled,
205
222
  value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
206
223
  "aria-invalid": invalid,
207
224
  "data-testid": name,
208
225
  name: name,
209
- className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 min-w-24", disabled && "cursor-not-allowed pointer-events-none"),
210
- placeholder: utilities.isEmpty(state.value) ? placeholder : ""
211
- }, referenceProps), {}, {
226
+ size: 1,
227
+ ref: ref,
228
+ autoFocus: autoFocus,
229
+ className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 min-w-24", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24"),
230
+ placeholder: utilities.isEmpty(state.value) ? placeholder : "",
212
231
  onChange: function onChange(evt) {
213
232
  return handleQuery(evt.target.value);
214
233
  }
215
- }))]
216
- })
234
+ })]
235
+ }))
217
236
  }), /*#__PURE__*/jsxRuntime.jsx(react$1.FloatingFocusManager, {
218
237
  context: context,
219
238
  initialFocus: -1,
@@ -227,11 +246,13 @@ var List = function List(_ref) {
227
246
  }, floatingProps), {}, {
228
247
  items: state.items,
229
248
  active: state.activeIndex,
249
+ valueProperty: valueProperty,
250
+ labelProperty: labelProperty,
230
251
  itemRef: setItemRef,
231
252
  itemProps: makeItemProps,
232
- children: function children(item) {
233
- var _ref4, _renderer3;
234
- return (_ref4 = (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : item[labelProperty]) !== null && _ref4 !== void 0 ? _ref4 : item;
253
+ children: function children(item, label) {
254
+ var _renderer3;
255
+ return (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : label;
235
256
  }
236
257
  }))
237
258
  })]
@@ -34,7 +34,7 @@ var Options = function Options(_ref) {
34
34
  i18nKey: "form:select.emptyList"
35
35
  })
36
36
  })), items.map(function (item, index) {
37
- var _item$labelProperty;
37
+ var _item$value, _item$labelProperty;
38
38
  if (item.___group___) return /*#__PURE__*/jsxRuntime.jsx("p", {
39
39
  className: "px-2 py-1 text-muted text-xs sticky -top-px z-2 bg-base border-t",
40
40
  children: item.label
@@ -51,7 +51,7 @@ var Options = function Options(_ref) {
51
51
  children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
52
52
  i18nKey: "form:select.createOption",
53
53
  values: {
54
- query: item.value
54
+ query: (_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : item
55
55
  },
56
56
  components: [/*#__PURE__*/jsxRuntime.jsx("strong", {
57
57
  children: "query"
@@ -140,6 +140,9 @@ var Select = function Select(_ref) {
140
140
  return false;
141
141
  } else if (state.query) {
142
142
  handleQuery("");
143
+ evt.preventDefault();
144
+ evt.stopPropagation();
145
+ return false;
143
146
  } else {
144
147
  onEnterPressed === null || onEnterPressed === void 0 || onEnterPressed(evt);
145
148
  }
@@ -217,15 +220,16 @@ var Select = function Select(_ref) {
217
220
  wrapperRef: refs.setReference,
218
221
  className: state.open ? "!z-[99]" : ""
219
222
  }, rest), {}, {
220
- children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
223
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({
221
224
  role: "none",
222
225
  "data-select-display": "true",
223
- className: classNames("group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start", multiple ? "flex-wrap" : "flex-nowrap overflow-hidden"),
226
+ className: classNames("group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start", multiple ? "flex-wrap" : "flex-nowrap overflow-hidden")
227
+ }, referenceProps), {}, {
224
228
  onMouseUp: function onMouseUp(e) {
225
229
  var _e$currentTarget$quer;
226
230
  return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
227
231
  },
228
- children: [displayValue, /*#__PURE__*/jsxRuntime.jsx("input", _objectSpread(_objectSpread({
232
+ children: [displayValue, /*#__PURE__*/jsxRuntime.jsx("input", {
229
233
  readOnly: !searchable || readOnly,
230
234
  disabled: disabled,
231
235
  value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
@@ -236,13 +240,12 @@ var Select = function Select(_ref) {
236
240
  ref: ref,
237
241
  autoFocus: autoFocus,
238
242
  className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24"),
239
- placeholder: utilities.isEmpty(state.value) ? placeholder : ""
240
- }, referenceProps), {}, {
243
+ placeholder: utilities.isEmpty(state.value) ? placeholder : "",
241
244
  onChange: function onChange(evt) {
242
245
  return handleQuery(evt.target.value);
243
246
  }
244
- }))]
245
- }), !state.loading && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
247
+ })]
248
+ })), !state.loading && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
246
249
  className: classNames("flex-content p-2 z-0 order-9 text-muted cursor-pointer self-stretch flex items-center h-auto", state.open && "-scale-y-100 pointer-events-none", disabled && "pointer-events-none"),
247
250
  onClick: function onClick() {
248
251
  return !disabled && openDropdown();
@@ -88,7 +88,7 @@ var useSelect = function useSelect(_ref) {
88
88
  if (action.value !== undefined) {
89
89
  if (multiple) {
90
90
  var values = [];
91
- if (action.value && autoComplete) values.push.apply(values, _toConsumableArray(action.value.split(/,\s?/)));else if (action.value) values.push(action.value);
91
+ if (utilities.isString(action.value)) values.push.apply(values, _toConsumableArray(action.value.split(/,\s?/)));else values.push(action.value);
92
92
  newState.value = _toConsumableArray(state.value);
93
93
  values.forEach(function (value) {
94
94
  var _newState$value$inclu, _newState$value;
@@ -133,13 +133,14 @@ var useSelect = function useSelect(_ref) {
133
133
  if (autoComplete && action.query !== undefined) {
134
134
  optionList = utilities.dedupe([action.query].concat(_toConsumableArray(optionList)));
135
135
  }
136
+ optionList = optionList.sort(utilities.compareValues("asc", labelProperty));
136
137
  var grouped = utilities.groupBy(optionList, groupProperty, "");
137
138
  if (action.open) _newState.open = true;
138
139
  _newState.items = [];
139
140
  // add new item if allowCreate
140
141
  if (allowCreate && action.query) _newState.items.push({
141
142
  ___create___: true,
142
- value: createOption(action.query)
143
+ value: action.query
143
144
  });
144
145
  Object.entries(grouped).forEach(function (_ref2) {
145
146
  var _newState$items;
@@ -201,22 +202,22 @@ var useSelect = function useSelect(_ref) {
201
202
  });
202
203
  dispatch({
203
204
  type: "setValue",
204
- value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : ""
205
+ value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : deferred
205
206
  });
206
207
  }
207
208
  if (multiple) {
208
209
  optionsRef.current = [];
209
- var _value = (deferred !== null && deferred !== void 0 ? deferred : []).map(function (item) {
210
+ var _value = (utilities.isArray(deferred) ? deferred : []).map(function (item) {
210
211
  var _ref5;
211
212
  var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
212
213
  var hasValue = options.find(function (opt) {
213
214
  var _opt$valueProperty2;
214
- return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === deferred;
215
+ return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === item;
215
216
  });
216
217
  if (!hasValue && newOption) {
217
218
  optionsRef.current.push(newOption);
218
219
  }
219
- return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 : "";
220
+ return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 : item;
220
221
  });
221
222
  optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(options !== null && options !== void 0 ? options : []));
222
223
  dispatch({
@@ -285,7 +286,11 @@ var useSelect = function useSelect(_ref) {
285
286
  value: value !== null && value !== void 0 && value.___create___ ? value.value : value
286
287
  });
287
288
  if (value !== null && value !== void 0 && value.___create___) {
288
- optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), [createOption(value.value)]);
289
+ var val = [value.value];
290
+ if (multiple) {
291
+ val = value.value.split(/,\s?/);
292
+ }
293
+ optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(val.map(createOption)));
289
294
  }
290
295
  if (autoComplete) {
291
296
  optionsRef.current = utilities.dedupe([].concat(_toConsumableArray(utilities.isArray(values) ? values : [values]), _toConsumableArray(optionsRef.current)));
@@ -35,6 +35,12 @@ var getBgClass = function getBgClass(bg) {
35
35
  return "bg-".concat(bg);
36
36
  }
37
37
  };
38
+ var getColorClass = function getColorClass(color) {
39
+ if (color && !utilities.isColor(color)) {
40
+ return "text-".concat(color);
41
+ }
42
+ };
38
43
 
39
44
  exports.getBgClass = getBgClass;
40
45
  exports.getColor = getColor;
46
+ exports.getColorClass = getColorClass;
@@ -7,7 +7,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
7
7
  import _regeneratorRuntime from '@babel/runtime/regenerator';
8
8
  import { yupResolver } from '@hookform/resolvers/yup';
9
9
  import { useDebounce } from '@react-fabric/core';
10
- import { useRef, useTransition, useEffect, useCallback, useImperativeHandle } from 'react';
10
+ import { useRef, useEffect, useTransition, useCallback, useImperativeHandle } from 'react';
11
11
  import { useForm, FormProvider } from 'react-hook-form';
12
12
  import { jsx, jsxs } from 'react/jsx-runtime';
13
13
 
@@ -32,6 +32,9 @@ var Form = function Form(_ref) {
32
32
  resolver: schema && yupResolver(schema),
33
33
  defaultValues: defaultValues
34
34
  });
35
+ useEffect(function () {
36
+ form.reset();
37
+ }, []);
35
38
  var _useTransition = useTransition(),
36
39
  _useTransition2 = _slicedToArray(_useTransition, 2),
37
40
  startTransition = _useTransition2[1];
@@ -89,13 +92,17 @@ var Form = function Form(_ref) {
89
92
  return form.getValues();
90
93
  },
91
94
  setValues: function setValues(v) {
92
- return form.reset(v);
95
+ return setTimeout(function () {
96
+ return form.reset(v);
97
+ }, 50);
93
98
  },
94
99
  setValue: function setValue(k, v) {
95
- return form.setValue(k, v, {
96
- shouldDirty: false,
97
- shouldTouch: false
98
- });
100
+ return setTimeout(function () {
101
+ return form.setValue(k, v, {
102
+ shouldDirty: false,
103
+ shouldTouch: false
104
+ });
105
+ }, 50);
99
106
  }
100
107
  };
101
108
  }, [onSubmit, form, form.formState, defaultValues]);
@@ -4,10 +4,10 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
5
  import { DndContext } from '@dnd-kit/core';
6
6
  import { SortableContext, useSortable } from '@dnd-kit/sortable';
7
- import { Icon, CoreIcons, Button, Tooltip } from '@react-fabric/core';
7
+ import { Icon, CoreIcons, Tooltip, Button, cloneChildren } from '@react-fabric/core';
8
8
  import { isString } from '@react-fabric/utilities';
9
9
  import classNames from 'classnames';
10
- import { useMemo, useCallback, useImperativeHandle, Children, cloneElement } from 'react';
10
+ import { useMemo, useCallback, useImperativeHandle, cloneElement } from 'react';
11
11
  import { useFormContext, useFieldArray } from 'react-hook-form';
12
12
  import { useTranslation } from 'react-i18next';
13
13
  import { FieldWrapper } from '../internal/FieldWrapper.js';
@@ -16,17 +16,18 @@ import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
16
16
  import { CSS } from '@dnd-kit/utilities';
17
17
  import { jsx, jsxs } from 'react/jsx-runtime';
18
18
 
19
- var _excluded = ["name", "children", "addLabel", "fixedList", "focusName", "onAdd", "arrayRef", "enableSorting", "disabled", "readOnly", "minItems"];
19
+ var _excluded = ["name", "children", "addLabel", "fixedList", "focusName", "buttonPosition", "onAdd", "arrayRef", "enableSorting", "disabled", "readOnly", "minItems", "maxItems"];
20
20
  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; }
21
21
  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; }
22
22
  var ArrayInput = function ArrayInput(_ref) {
23
- var _error$values$label, _error$values, _error$values2;
24
23
  var name = _ref.name,
25
24
  children = _ref.children,
26
25
  addLabel = _ref.addLabel,
27
26
  fixedList = _ref.fixedList,
28
27
  _ref$focusName = _ref.focusName,
29
28
  focusName = _ref$focusName === void 0 ? "" : _ref$focusName,
29
+ _ref$buttonPosition = _ref.buttonPosition,
30
+ buttonPosition = _ref$buttonPosition === void 0 ? "bottom" : _ref$buttonPosition,
30
31
  onAdd = _ref.onAdd,
31
32
  arrayRef = _ref.arrayRef,
32
33
  enableSorting = _ref.enableSorting,
@@ -36,6 +37,8 @@ var ArrayInput = function ArrayInput(_ref) {
36
37
  readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
37
38
  _ref$minItems = _ref.minItems,
38
39
  minItems = _ref$minItems === void 0 ? 0 : _ref$minItems,
40
+ _ref$maxItems = _ref.maxItems,
41
+ maxItems = _ref$maxItems === void 0 ? Number.MAX_SAFE_INTEGER : _ref$maxItems,
39
42
  rest = _objectWithoutProperties(_ref, _excluded);
40
43
  var _useTranslation = useTranslation("form"),
41
44
  t = _useTranslation.t;
@@ -127,9 +130,37 @@ var ArrayInput = function ArrayInput(_ref) {
127
130
  }, [enableSorting]);
128
131
  // @ts-expect-error ignore
129
132
  SortableItem.displayName = "SortableItem";
133
+ var addButton = useMemo(function () {
134
+ var _error$values$label, _error$values, _error$values2;
135
+ return /*#__PURE__*/jsx("div", {
136
+ className: "flex justify-end",
137
+ children: /*#__PURE__*/jsx(Tooltip, {
138
+ color: "danger",
139
+ content: isString(error) ? "".concat(error) : t(error === null || error === void 0 ? void 0 : error.key, error !== null && error !== void 0 && error.values ? _objectSpread(_objectSpread({}, error === null || error === void 0 ? void 0 : error.values), {}, {
140
+ label: t((_error$values$label = (_error$values = error.values) === null || _error$values === void 0 ? void 0 : _error$values.label) !== null && _error$values$label !== void 0 ? _error$values$label : "form:badkey", (_error$values2 = error.values) === null || _error$values2 === void 0 ? void 0 : _error$values2.path)
141
+ }) : {}),
142
+ children: /*#__PURE__*/jsx(Button, {
143
+ size: "sm",
144
+ "aria-label": "Add item",
145
+ icon: CoreIcons.insert,
146
+ onClick: function onClick() {
147
+ return handleAdd(onAdd === null || onAdd === void 0 ? void 0 : onAdd());
148
+ },
149
+ "data-invalid": !!error,
150
+ disabled: !!disabled || readOnly || fields.length > maxItems,
151
+ className: classNames(classes.addButton, "me-10"),
152
+ children: addLabel !== null && addLabel !== void 0 ? addLabel : t("addArray")
153
+ })
154
+ })
155
+ });
156
+ }, [error, fields, handleAdd, disabled, readOnly, addLabel, maxItems]);
130
157
  return /*#__PURE__*/jsxs("div", {
131
158
  className: classes.arrayInput,
132
159
  children: [/*#__PURE__*/jsx(FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
160
+ appendLabel: /*#__PURE__*/jsx("div", {
161
+ className: "-me-2",
162
+ children: !fixedList && onAdd && buttonPosition !== "bottom" && addButton
163
+ }),
133
164
  children: /*#__PURE__*/jsx(Wrapper, {
134
165
  children: fields.map(function (item, index) {
135
166
  return /*#__PURE__*/jsxs(SortableItem, {
@@ -138,7 +169,7 @@ var ArrayInput = function ArrayInput(_ref) {
138
169
  children: [typeof children === "function" ? children({
139
170
  index: index,
140
171
  name: "".concat(name, ".").concat(index)
141
- }) : Children.map(children, function (child) {
172
+ }) : cloneChildren(children, function (child) {
142
173
  return /*#__PURE__*/cloneElement(child, Object.assign({
143
174
  disabled: disabled,
144
175
  readOnly: readOnly,
@@ -163,26 +194,7 @@ var ArrayInput = function ArrayInput(_ref) {
163
194
  }, item.id);
164
195
  })
165
196
  })
166
- })), !fixedList && onAdd && /*#__PURE__*/jsx("div", {
167
- className: "flex justify-end",
168
- children: /*#__PURE__*/jsx(Tooltip, {
169
- color: "danger",
170
- content: isString(error) ? "".concat(error) : t(error === null || error === void 0 ? void 0 : error.key, error !== null && error !== void 0 && error.values ? _objectSpread(_objectSpread({}, error === null || error === void 0 ? void 0 : error.values), {}, {
171
- label: t((_error$values$label = (_error$values = error.values) === null || _error$values === void 0 ? void 0 : _error$values.label) !== null && _error$values$label !== void 0 ? _error$values$label : "form:badkey", (_error$values2 = error.values) === null || _error$values2 === void 0 ? void 0 : _error$values2.path)
172
- }) : {}),
173
- children: /*#__PURE__*/jsx(Button, {
174
- "aria-label": "Add item",
175
- icon: CoreIcons.insert,
176
- onClick: function onClick() {
177
- return handleAdd(onAdd());
178
- },
179
- "data-invalid": !!error,
180
- disabled: !!disabled || readOnly,
181
- className: classNames(classes.addButton, "me-10"),
182
- children: addLabel !== null && addLabel !== void 0 ? addLabel : t("addArray")
183
- })
184
- })
185
- })]
197
+ })), !fixedList && onAdd && buttonPosition !== "top" && addButton]
186
198
  });
187
199
  };
188
200
 
@@ -3,10 +3,11 @@
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
5
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
6
- import { Dropdown, Icon, CoreIcons } from '@react-fabric/core';
6
+ import { useFloating, autoUpdate, shift, flip, offset, arrow, useClick, useDismiss, useInteractions, FloatingArrow } from '@floating-ui/react';
7
+ import { Icon, CoreIcons } from '@react-fabric/core';
7
8
  import { isString } from '@react-fabric/utilities';
8
9
  import classNames from 'classnames';
9
- import { useState, useDeferredValue, useEffect, useCallback, startTransition } from 'react';
10
+ import { useState, useDeferredValue, useEffect, useCallback, startTransition, useRef } from 'react';
10
11
  import { ColorPicker } from './ColorPicker.js';
11
12
  import { jsxs, jsx } from 'react/jsx-runtime';
12
13
 
@@ -43,41 +44,82 @@ var ColorInput = function ColorInput(_ref) {
43
44
  return onChange(e);
44
45
  });
45
46
  }, [onChange]);
47
+ var arrowRef = useRef(null);
48
+ var _useState3 = useState(false),
49
+ _useState4 = _slicedToArray(_useState3, 2),
50
+ isOpen = _useState4[0],
51
+ setIsOpen = _useState4[1];
52
+ var _useFloating = useFloating({
53
+ open: isOpen,
54
+ onOpenChange: function onOpenChange(open, _, reason) {
55
+ if (reason === "reference-press") return;
56
+ setIsOpen(open);
57
+ },
58
+ strategy: "fixed",
59
+ placement: "bottom",
60
+ whileElementsMounted: autoUpdate,
61
+ middleware: [shift({
62
+ padding: 8
63
+ }), flip(), offset(9), arrow({
64
+ element: arrowRef
65
+ })]
66
+ }),
67
+ refs = _useFloating.refs,
68
+ floatingStyles = _useFloating.floatingStyles,
69
+ context = _useFloating.context;
70
+ var click = useClick(context, {
71
+ enabled: !disabled
72
+ });
73
+ var dismiss = useDismiss(context, {
74
+ referencePress: true
75
+ });
76
+ var _useInteractions = useInteractions([dismiss, click]),
77
+ getReferenceProps = _useInteractions.getReferenceProps,
78
+ getFloatingProps = _useInteractions.getFloatingProps;
46
79
  return /*#__PURE__*/jsxs("div", {
47
80
  className: classNames("flex-content min-h-[1.5em] min-w-[3.5em] self-stretch flex items-center outline-tint-200 rounded", !disabled && "bg-base", !noOutline && "bg-[var(--fabric-input)] outline overflow-hidden"),
48
81
  children: [decorateStart && /*#__PURE__*/jsx("div", {
49
82
  className: classNames("text-muted leading-none flex-content", isString(decorateStart) && "px-2"),
50
83
  children: decorateStart
51
- }), /*#__PURE__*/jsxs(Dropdown, {
52
- showArrow: true,
53
- disabled: disabled,
54
- children: [/*#__PURE__*/jsx("button", {
55
- "data-ref": "button",
56
- className: "flex-1 flex items-center",
57
- children: /*#__PURE__*/jsx("div", {
58
- role: "none",
59
- className: "h-[1.5em] min-w-[1.5em] flex-1 flex items-center justify-center self-stretch cursor-pointer m-[0.25em] rounded outline outline-tint-100",
60
- style: {
61
- backgroundColor: actualValue,
62
- opacity: disabled ? 0.65 : 1,
63
- pointerEvents: disabled ? "none" : undefined
64
- },
65
- onClick: function onClick(e) {
66
- var _e$currentTarget$next;
67
- return (_e$currentTarget$next = e.currentTarget.nextElementSibling) === null || _e$currentTarget$next === void 0 ? void 0 : _e$currentTarget$next.focus();
68
- },
69
- children: !actualValue && /*#__PURE__*/jsx(Icon, {
70
- size: "md",
71
- className: "text-muted",
72
- icon: CoreIcons.colorSwatch
73
- })
84
+ }), /*#__PURE__*/jsx("button", _objectSpread(_objectSpread({
85
+ "data-ref": "button",
86
+ className: "flex-1 flex items-center",
87
+ ref: refs.setReference
88
+ }, getReferenceProps()), {}, {
89
+ "data-inner-clickable": "true",
90
+ "data-dropdown-open": isOpen ? true : undefined,
91
+ children: /*#__PURE__*/jsx("div", {
92
+ role: "none",
93
+ className: "h-[1.5em] min-w-[1.5em] flex-1 flex items-center justify-center self-stretch cursor-pointer m-[0.25em] rounded outline outline-tint-100",
94
+ style: {
95
+ backgroundColor: actualValue,
96
+ opacity: disabled ? 0.65 : 1,
97
+ pointerEvents: disabled ? "none" : undefined
98
+ },
99
+ children: !actualValue && /*#__PURE__*/jsx(Icon, {
100
+ size: "md",
101
+ className: "text-muted",
102
+ icon: CoreIcons.colorSwatch
74
103
  })
75
- }), /*#__PURE__*/jsx(ColorPicker, _objectSpread(_objectSpread({}, rest), {}, {
104
+ })
105
+ })), isOpen && /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
106
+ ref: refs.setFloating,
107
+ style: _objectSpread({
108
+ zIndex: "var(--z-popover)"
109
+ }, floatingStyles),
110
+ "data-ref": "dropdownBody"
111
+ }, getFloatingProps()), {}, {
112
+ children: [/*#__PURE__*/jsx(ColorPicker, _objectSpread(_objectSpread({}, rest), {}, {
76
113
  onChange: handleChange,
77
114
  defaultColor: defaultColor,
78
115
  value: actualValue
79
- }))]
80
- }), !disabled && showPicker && /*#__PURE__*/jsx(Icon, {
116
+ })), /*#__PURE__*/jsx(FloatingArrow, {
117
+ ref: arrowRef,
118
+ context: context,
119
+ strokeWidth: 0.5,
120
+ className: "fill-base stroke-muted"
121
+ })]
122
+ })), !disabled && showPicker && /*#__PURE__*/jsx(Icon, {
81
123
  icon: CoreIcons.colorPicker,
82
124
  onClick: function onClick() {
83
125
  return window.EyeDropper && new window.EyeDropper().open().then(function (resp) {
@@ -41,12 +41,9 @@ var ColorPicker = /*#__PURE__*/memo(function (_ref) {
41
41
  styles: {
42
42
  "default": {
43
43
  hue: {
44
- borderRadius: "99px",
45
44
  boxShadow: "0 0 1px 1px var(--color-shadow)"
46
45
  },
47
46
  alpha: {
48
- height: "1rem",
49
- borderRadius: "99px",
50
47
  backgroundColor: "var(--fabric-bg)",
51
48
  boxShadow: "0 0 1px 1px var(--color-shadow)"
52
49
  },
@@ -63,36 +60,6 @@ var ColorPicker = /*#__PURE__*/memo(function (_ref) {
63
60
  backgroundColor: "var(--fabric-bg)",
64
61
  boxShadow: "0 0 0 1px var(--color-shadow), 0 0 8px var(--fabric-shadow)"
65
62
  },
66
- Alpha: {
67
- alpha: {
68
- paddingRight: "calc(1rem - 2px)"
69
- },
70
- slider: {
71
- width: "calc(1rem - 2px)",
72
- borderRadius: "99px",
73
- height: "calc(1rem - 2px)",
74
- transform: "none"
75
- }
76
- },
77
- Hue: {
78
- hue: {
79
- paddingRight: "calc(1rem - 2px)"
80
- },
81
- slider: {
82
- width: "calc(1rem - 2px)",
83
- borderRadius: "99px",
84
- height: "calc(1rem - 2px)",
85
- transform: "none"
86
- }
87
- },
88
- Saturation: {
89
- circle: {
90
- width: "0.5rem",
91
- borderRadius: "99px",
92
- height: "0.5rem",
93
- transform: "translate(-0.25rem, -0.25rem)"
94
- }
95
- },
96
63
  checkboard: {
97
64
  white: "transparent",
98
65
  black: "red"
@@ -1 +1 @@
1
- @layer comp{.colorPicker{--color-shadow:theme(borderColor.base);& input{@apply bg-base text-base !border !border-solid !rounded-sm !border-base focus:!border-primary !shadow-none;line-height:2;padding:0 4px!important}& label{@apply !text-base}& :global(.flexbox-fix){@apply !border-t-muted justify-center;&>div>div{@apply text-center}& span>div{box-shadow:inset 0 0 1px 1px theme(borderColor.base)!important}}}}
1
+ @layer comp{.colorPicker{--color-shadow:theme(borderColor.base);& input{background-color:theme(backgroundColor.base);border:1px solid theme(borderColor.base);border-radius:theme(borderRadius.sm);box-shadow:none;color:theme(textColor.base);line-height:2;padding:0 4px!important;&:focus{border-color:theme(borderColor.primary.DEFAULT)}}& label{color:theme(textColor.base)}& :global(.flexbox-fix){border-color:theme(borderColor.muted);justify-content:center;&>div>div{text-align:center}& span>div{box-shadow:inset 0 0 1px 1px theme(borderColor.base)!important}}& :global(.saturation-black)~div{pointer-events:none}}}
@@ -2,8 +2,9 @@
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
+ import { cloneChildren } from '@react-fabric/core';
5
6
  import classNames from 'classnames';
6
- import { Children, cloneElement } from 'react';
7
+ import { cloneElement } from 'react';
7
8
  import classes from '../internal/Field.module.css';
8
9
  import { FieldWrapper } from '../internal/FieldWrapper.js';
9
10
  import { jsx } from 'react/jsx-runtime';
@@ -20,8 +21,8 @@ var Field = function Field(_ref) {
20
21
  return /*#__PURE__*/jsx(FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
21
22
  children: /*#__PURE__*/jsx("div", {
22
23
  className: classNames(classes.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", "flex-1 rounded", !vertical && "flex flex-nowrap"),
23
- children: Children.map(children, function (child) {
24
- return child && /*#__PURE__*/cloneElement(child, {
24
+ children: cloneChildren(children, function (child) {
25
+ return /*#__PURE__*/cloneElement(child, {
25
26
  "data-inner": true
26
27
  });
27
28
  })
@@ -1 +1 @@
1
- @layer comp{.fileInput{&::-webkit-file-upload-button{@apply bg-primary-500 opacity-80 hover:opacity-90 text-white rounded border-none py-0 cursor-pointer}&[aria-invalid=true]::-webkit-file-upload-button{@apply bg-danger-500}&:disabled::-webkit-file-upload-button{@apply bg-muted pointer-events-none}&[readOnly]{@apply pointer-events-none}}}
1
+ @layer comp{.fileInput{&::-webkit-file-upload-button{background-color:theme(backgroundColor.primary.500);border:0;border-radius:theme(borderRadius.DEFAULT);color:theme(textColor.white);cursor:pointer;opacity:.8;padding-block:0;&:hover{opacity:.9}}&[aria-invalid=true]::-webkit-file-upload-button{background-color:theme(backgroundColor.danger.500)}&:disabled::-webkit-file-upload-button{background-color:theme(backgroundColor.muted);pointer-events:none}&[readOnly]{pointer-events:none}}}
@@ -36,7 +36,9 @@ var HiddenInput = function HiddenInput(_ref) {
36
36
  value = _ref$value === void 0 ? "" : _ref$value,
37
37
  name = _ref.name;
38
38
  useEffect(function () {
39
- onChange === null || onChange === void 0 || onChange(hiddenValue);
39
+ setTimeout(function () {
40
+ onChange === null || onChange === void 0 || onChange(hiddenValue);
41
+ }, 50);
40
42
  }, [hiddenValue]);
41
43
  return /*#__PURE__*/jsxs(Fragment, {
42
44
  children: [/*#__PURE__*/jsx("input", {