@react-fabric/form 1.0.0-beta.3 → 1.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/form/Form.js +9 -5
- package/dist/cjs/select/Select.js +7 -7
- package/dist/cjs/select/useSelect.js +7 -3
- package/dist/esm/form/Form.js +9 -5
- package/dist/esm/select/Select.js +7 -7
- package/dist/esm/select/useSelect.js +8 -4
- package/package.json +4 -4
- package/src/form/Form.tsx +9 -5
- package/src/select/Select.tsx +1 -1
- package/src/select/useSelect.tsx +23 -16
package/dist/cjs/form/Form.js
CHANGED
|
@@ -89,13 +89,17 @@ var Form = function Form(_ref) {
|
|
|
89
89
|
return form.getValues();
|
|
90
90
|
},
|
|
91
91
|
setValues: function setValues(v) {
|
|
92
|
-
return
|
|
92
|
+
return setTimeout(function () {
|
|
93
|
+
return form.reset(v);
|
|
94
|
+
}, 50);
|
|
93
95
|
},
|
|
94
96
|
setValue: function setValue(k, v) {
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
return setTimeout(function () {
|
|
98
|
+
return form.setValue(k, v, {
|
|
99
|
+
shouldDirty: false,
|
|
100
|
+
shouldTouch: false
|
|
101
|
+
});
|
|
102
|
+
}, 50);
|
|
99
103
|
}
|
|
100
104
|
};
|
|
101
105
|
}, [onSubmit, form, form.formState, defaultValues]);
|
|
@@ -217,15 +217,16 @@ var Select = function Select(_ref) {
|
|
|
217
217
|
wrapperRef: refs.setReference,
|
|
218
218
|
className: state.open ? "!z-[99]" : ""
|
|
219
219
|
}, rest), {}, {
|
|
220
|
-
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
220
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({
|
|
221
221
|
role: "none",
|
|
222
222
|
"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")
|
|
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")
|
|
224
|
+
}, referenceProps), {}, {
|
|
224
225
|
onMouseUp: function onMouseUp(e) {
|
|
225
226
|
var _e$currentTarget$quer;
|
|
226
227
|
return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
|
|
227
228
|
},
|
|
228
|
-
children: [displayValue, /*#__PURE__*/jsxRuntime.jsx("input",
|
|
229
|
+
children: [displayValue, /*#__PURE__*/jsxRuntime.jsx("input", {
|
|
229
230
|
readOnly: !searchable || readOnly,
|
|
230
231
|
disabled: disabled,
|
|
231
232
|
value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
|
|
@@ -236,13 +237,12 @@ var Select = function Select(_ref) {
|
|
|
236
237
|
ref: ref,
|
|
237
238
|
autoFocus: autoFocus,
|
|
238
239
|
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), {}, {
|
|
240
|
+
placeholder: utilities.isEmpty(state.value) ? placeholder : "",
|
|
241
241
|
onChange: function onChange(evt) {
|
|
242
242
|
return handleQuery(evt.target.value);
|
|
243
243
|
}
|
|
244
|
-
})
|
|
245
|
-
}), !state.loading && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
244
|
+
})]
|
|
245
|
+
})), !state.loading && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
246
246
|
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
247
|
onClick: function onClick() {
|
|
248
248
|
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
|
|
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;
|
|
@@ -206,7 +206,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
206
206
|
}
|
|
207
207
|
if (multiple) {
|
|
208
208
|
optionsRef.current = [];
|
|
209
|
-
var _value = (deferred
|
|
209
|
+
var _value = (utilities.isArray(deferred) ? deferred : []).map(function (item) {
|
|
210
210
|
var _ref5;
|
|
211
211
|
var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
|
|
212
212
|
var hasValue = options.find(function (opt) {
|
|
@@ -285,7 +285,11 @@ var useSelect = function useSelect(_ref) {
|
|
|
285
285
|
value: value !== null && value !== void 0 && value.___create___ ? value.value : value
|
|
286
286
|
});
|
|
287
287
|
if (value !== null && value !== void 0 && value.___create___) {
|
|
288
|
-
|
|
288
|
+
var val = [value.value];
|
|
289
|
+
if (multiple) {
|
|
290
|
+
val = value.value.split(/,\s?/);
|
|
291
|
+
}
|
|
292
|
+
optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(val.map(createOption)));
|
|
289
293
|
}
|
|
290
294
|
if (autoComplete) {
|
|
291
295
|
optionsRef.current = utilities.dedupe([].concat(_toConsumableArray(utilities.isArray(values) ? values : [values]), _toConsumableArray(optionsRef.current)));
|
package/dist/esm/form/Form.js
CHANGED
|
@@ -89,13 +89,17 @@ var Form = function Form(_ref) {
|
|
|
89
89
|
return form.getValues();
|
|
90
90
|
},
|
|
91
91
|
setValues: function setValues(v) {
|
|
92
|
-
return
|
|
92
|
+
return setTimeout(function () {
|
|
93
|
+
return form.reset(v);
|
|
94
|
+
}, 50);
|
|
93
95
|
},
|
|
94
96
|
setValue: function setValue(k, v) {
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
return setTimeout(function () {
|
|
98
|
+
return form.setValue(k, v, {
|
|
99
|
+
shouldDirty: false,
|
|
100
|
+
shouldTouch: false
|
|
101
|
+
});
|
|
102
|
+
}, 50);
|
|
99
103
|
}
|
|
100
104
|
};
|
|
101
105
|
}, [onSubmit, form, form.formState, defaultValues]);
|
|
@@ -217,15 +217,16 @@ var Select = function Select(_ref) {
|
|
|
217
217
|
wrapperRef: refs.setReference,
|
|
218
218
|
className: state.open ? "!z-[99]" : ""
|
|
219
219
|
}, rest), {}, {
|
|
220
|
-
children: [/*#__PURE__*/jsxs("div", {
|
|
220
|
+
children: [/*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
|
|
221
221
|
role: "none",
|
|
222
222
|
"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")
|
|
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")
|
|
224
|
+
}, referenceProps), {}, {
|
|
224
225
|
onMouseUp: function onMouseUp(e) {
|
|
225
226
|
var _e$currentTarget$quer;
|
|
226
227
|
return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
|
|
227
228
|
},
|
|
228
|
-
children: [displayValue, /*#__PURE__*/jsx("input",
|
|
229
|
+
children: [displayValue, /*#__PURE__*/jsx("input", {
|
|
229
230
|
readOnly: !searchable || readOnly,
|
|
230
231
|
disabled: disabled,
|
|
231
232
|
value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
|
|
@@ -236,13 +237,12 @@ var Select = function Select(_ref) {
|
|
|
236
237
|
ref: ref,
|
|
237
238
|
autoFocus: autoFocus,
|
|
238
239
|
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: isEmpty(state.value) ? placeholder : ""
|
|
240
|
-
}, referenceProps), {}, {
|
|
240
|
+
placeholder: isEmpty(state.value) ? placeholder : "",
|
|
241
241
|
onChange: function onChange(evt) {
|
|
242
242
|
return handleQuery(evt.target.value);
|
|
243
243
|
}
|
|
244
|
-
})
|
|
245
|
-
}), !state.loading && /*#__PURE__*/jsx(Icon, {
|
|
244
|
+
})]
|
|
245
|
+
})), !state.loading && /*#__PURE__*/jsx(Icon, {
|
|
246
246
|
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
247
|
onClick: function onClick() {
|
|
248
248
|
return !disabled && openDropdown();
|
|
@@ -4,7 +4,7 @@ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
|
4
4
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
5
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
6
|
import { useDebounce } from '@react-fabric/core';
|
|
7
|
-
import { matchString, dedupe, groupBy, isArray, EMPTY_ARRAY } from '@react-fabric/utilities';
|
|
7
|
+
import { matchString, isString, dedupe, groupBy, isArray, EMPTY_ARRAY } from '@react-fabric/utilities';
|
|
8
8
|
import { useMemo, useDeferredValue, useRef, useCallback, useReducer, useEffect } from 'react';
|
|
9
9
|
import { getSelectedValue, makeOption } from './helpers.js';
|
|
10
10
|
|
|
@@ -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
|
|
91
|
+
if (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;
|
|
@@ -206,7 +206,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
206
206
|
}
|
|
207
207
|
if (multiple) {
|
|
208
208
|
optionsRef.current = [];
|
|
209
|
-
var _value = (deferred
|
|
209
|
+
var _value = (isArray(deferred) ? deferred : []).map(function (item) {
|
|
210
210
|
var _ref5;
|
|
211
211
|
var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
|
|
212
212
|
var hasValue = options.find(function (opt) {
|
|
@@ -285,7 +285,11 @@ var useSelect = function useSelect(_ref) {
|
|
|
285
285
|
value: value !== null && value !== void 0 && value.___create___ ? value.value : value
|
|
286
286
|
});
|
|
287
287
|
if (value !== null && value !== void 0 && value.___create___) {
|
|
288
|
-
|
|
288
|
+
var val = [value.value];
|
|
289
|
+
if (multiple) {
|
|
290
|
+
val = value.value.split(/,\s?/);
|
|
291
|
+
}
|
|
292
|
+
optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(val.map(createOption)));
|
|
289
293
|
}
|
|
290
294
|
if (autoComplete) {
|
|
291
295
|
optionsRef.current = dedupe([].concat(_toConsumableArray(isArray(values) ? values : [values]), _toConsumableArray(optionsRef.current)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/form",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "RUF: Form package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@dnd-kit/utilities": "^3.2.2",
|
|
40
40
|
"@floating-ui/react": "0.26.24",
|
|
41
41
|
"@hookform/resolvers": "^3.9.0",
|
|
42
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
43
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
42
|
+
"@react-fabric/core": "^1.0.0-beta.5",
|
|
43
|
+
"@react-fabric/utilities": "^1.0.0-beta.5",
|
|
44
44
|
"classnames": "^2.5.1",
|
|
45
45
|
"color": "^4.2.3",
|
|
46
46
|
"react-color": "^2.19.3",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"node": ">=18.12.0",
|
|
61
61
|
"npm": ">=8.19.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "7d4a7ed1ea9890652826bef58d01c31280d761c8"
|
|
64
64
|
}
|
package/src/form/Form.tsx
CHANGED
|
@@ -118,12 +118,16 @@ export const Form = <K extends KeyValue>({
|
|
|
118
118
|
submit: () => form.handleSubmit(onSubmit),
|
|
119
119
|
validate: async () => await form.trigger(),
|
|
120
120
|
getValues: () => form.getValues(),
|
|
121
|
-
setValues: (v) => form.reset(v),
|
|
121
|
+
setValues: (v) => setTimeout(() => form.reset(v), 50),
|
|
122
122
|
setValue: (k, v) =>
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
setTimeout(
|
|
124
|
+
() =>
|
|
125
|
+
form.setValue(k as AnyObject, v, {
|
|
126
|
+
shouldDirty: false,
|
|
127
|
+
shouldTouch: false,
|
|
128
|
+
}),
|
|
129
|
+
50,
|
|
130
|
+
),
|
|
127
131
|
}),
|
|
128
132
|
[onSubmit, form, form.formState, defaultValues],
|
|
129
133
|
);
|
package/src/select/Select.tsx
CHANGED
|
@@ -273,6 +273,7 @@ export const Select = <T extends AnyObject = string>({
|
|
|
273
273
|
"group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start",
|
|
274
274
|
multiple ? "flex-wrap" : "flex-nowrap overflow-hidden",
|
|
275
275
|
)}
|
|
276
|
+
{...referenceProps}
|
|
276
277
|
onMouseUp={(e) =>
|
|
277
278
|
e.currentTarget.querySelector<HTMLElement>("input")?.focus()
|
|
278
279
|
}
|
|
@@ -294,7 +295,6 @@ export const Select = <T extends AnyObject = string>({
|
|
|
294
295
|
multiple && "min-w-24",
|
|
295
296
|
)}
|
|
296
297
|
placeholder={isEmpty(state.value) ? placeholder : ""}
|
|
297
|
-
{...referenceProps}
|
|
298
298
|
onChange={(evt) => handleQuery(evt.target.value)}
|
|
299
299
|
/>
|
|
300
300
|
</div>
|
package/src/select/useSelect.tsx
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
EMPTY_ARRAY,
|
|
28
28
|
groupBy,
|
|
29
29
|
isArray,
|
|
30
|
+
isString,
|
|
30
31
|
matchString,
|
|
31
32
|
} from "@react-fabric/utilities";
|
|
32
33
|
import {
|
|
@@ -173,9 +174,9 @@ export const useSelect = ({
|
|
|
173
174
|
if (action.value !== undefined) {
|
|
174
175
|
if (multiple) {
|
|
175
176
|
const values = [];
|
|
176
|
-
if (action.value
|
|
177
|
+
if (isString(action.value))
|
|
177
178
|
values.push(...action.value.split(/,\s?/));
|
|
178
|
-
else
|
|
179
|
+
else values.push(action.value);
|
|
179
180
|
newState.value = [...state.value];
|
|
180
181
|
values.forEach((value: AnyObject) => {
|
|
181
182
|
newState.value = newState.value.includes?.(value)
|
|
@@ -287,19 +288,21 @@ export const useSelect = ({
|
|
|
287
288
|
}
|
|
288
289
|
if (multiple) {
|
|
289
290
|
optionsRef.current = [];
|
|
290
|
-
const value = (deferred
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
291
|
+
const value = (isArray(deferred) ? deferred : []).map(
|
|
292
|
+
(item: AnyObject) => {
|
|
293
|
+
const newOption =
|
|
294
|
+
(allowCreate || autoComplete) && item
|
|
295
|
+
? createOption(item)
|
|
296
|
+
: undefined;
|
|
297
|
+
const hasValue = options.find(
|
|
298
|
+
(opt: AnyObject) => (opt[valueProperty] ?? opt) === deferred,
|
|
299
|
+
);
|
|
300
|
+
if (!hasValue && newOption) {
|
|
301
|
+
optionsRef.current.push(newOption);
|
|
302
|
+
}
|
|
303
|
+
return hasValue ?? newOption ?? "";
|
|
304
|
+
},
|
|
305
|
+
);
|
|
303
306
|
optionsRef.current = [...optionsRef.current, ...(options ?? [])];
|
|
304
307
|
dispatch({ type: "options", options: optionsRef.current });
|
|
305
308
|
dispatch({
|
|
@@ -367,7 +370,11 @@ export const useSelect = ({
|
|
|
367
370
|
value: value?.___create___ ? value.value : value,
|
|
368
371
|
});
|
|
369
372
|
if (value?.___create___) {
|
|
370
|
-
|
|
373
|
+
let val = [value.value];
|
|
374
|
+
if (multiple) {
|
|
375
|
+
val = value.value.split(/,\s?/);
|
|
376
|
+
}
|
|
377
|
+
optionsRef.current = [...optionsRef.current, ...val.map(createOption)];
|
|
371
378
|
}
|
|
372
379
|
if (autoComplete) {
|
|
373
380
|
optionsRef.current = dedupe([
|