@douglasneuroinformatics/libui 3.7.3 → 3.7.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.
@@ -1249,7 +1249,7 @@ type FormProps<TSchema extends z.ZodType<FormDataType>, TData extends z.TypeOf<T
1249
1249
  submitBtnLabel?: string;
1250
1250
  validationSchema: z.ZodType<TData>;
1251
1251
  };
1252
- declare const Form: <TSchema extends z.ZodType<FormDataType>, TData extends z.TypeOf<TSchema> = z.TypeOf<TSchema>>({ additionalButtons, className, content, fieldsFooter, id, initialValues, onError, onSubmit, preventResetValuesOnReset, readOnly, resetBtn, revalidateOnBlur, submitBtnLabel, validationSchema, ...props }: FormProps<TSchema, TData>) => react_jsx_runtime.JSX.Element | null;
1252
+ declare const Form: <TSchema extends z.ZodType<FormDataType>, TData extends z.TypeOf<TSchema> = z.TypeOf<TSchema>>({ additionalButtons, className, content, fieldsFooter, id, initialValues, onError, onSubmit, preventResetValuesOnReset, readOnly, resetBtn, revalidateOnBlur, submitBtnLabel, validationSchema, ...props }: FormProps<TSchema, TData>) => react_jsx_runtime.JSX.Element;
1253
1253
 
1254
1254
  type HeadingProps = {
1255
1255
  children: string;
@@ -2118,7 +2118,7 @@ import "react";
2118
2118
  import { match as match7 } from "ts-pattern";
2119
2119
 
2120
2120
  // src/components/Form/NumberRecordField.tsx
2121
- import { useEffect as useEffect4 } from "react";
2121
+ import { useEffect as useEffect4, useRef as useRef3 } from "react";
2122
2122
 
2123
2123
  // src/components/Form/NumberField/NumberField.tsx
2124
2124
  import { match as match2 } from "ts-pattern";
@@ -2633,8 +2633,12 @@ var NumberRecordField = ({
2633
2633
  setValue: setRecordValue,
2634
2634
  value: recordValue
2635
2635
  }) => {
2636
+ const isFirstRenderRef = useRef3(true);
2636
2637
  useEffect4(() => {
2637
- setRecordValue({});
2638
+ if (isFirstRenderRef.current && !recordValue || !isFirstRenderRef.current) {
2639
+ setRecordValue({});
2640
+ }
2641
+ isFirstRenderRef.current = false;
2638
2642
  }, [options]);
2639
2643
  if (!recordValue) {
2640
2644
  return null;
@@ -2664,7 +2668,7 @@ var NumberRecordField = ({
2664
2668
  };
2665
2669
 
2666
2670
  // src/components/Form/RecordArrayField.tsx
2667
- import { memo, useEffect as useEffect8 } from "react";
2671
+ import { memo, useEffect as useEffect8, useRef as useRef4 } from "react";
2668
2672
  import { MinusCircleIcon, PlusCircleIcon } from "lucide-react";
2669
2673
 
2670
2674
  // src/components/Form/BooleanField/BooleanField.tsx
@@ -2686,7 +2690,7 @@ var BooleanFieldCheckbox = ({
2686
2690
  /* @__PURE__ */ jsx117(
2687
2691
  Checkbox,
2688
2692
  {
2689
- checked: value,
2693
+ checked: Boolean(value),
2690
2694
  disabled: disabled || readOnly,
2691
2695
  id: name,
2692
2696
  name,
@@ -3223,10 +3227,14 @@ var RecordArrayField = memo(function RecordArrayField2({
3223
3227
  setValue: setArrayValue,
3224
3228
  value: arrayValue
3225
3229
  }) {
3230
+ const isFirstRenderRef = useRef4(true);
3226
3231
  const { t } = useTranslation("libui");
3227
3232
  const createNewRecord = () => Object.fromEntries(Object.keys(fieldset).map((fieldName) => [fieldName, void 0]));
3228
3233
  useEffect8(() => {
3229
- setArrayValue([createNewRecord()]);
3234
+ if (isFirstRenderRef.current && !arrayValue || !isFirstRenderRef.current) {
3235
+ setArrayValue([createNewRecord()]);
3236
+ }
3237
+ isFirstRenderRef.current = false;
3230
3238
  }, [fieldset]);
3231
3239
  if (!arrayValue) {
3232
3240
  return null;
@@ -3433,8 +3441,9 @@ var Form = ({
3433
3441
  const { resolvedLanguage, t } = useTranslation("libui");
3434
3442
  const [rootErrors, setRootErrors] = useState8([]);
3435
3443
  const [errors, setErrors] = useState8({});
3436
- const [values, setValues] = useState8({});
3437
- const [isInitialSetValuesComplete, setIsInitialSetValuesComplete] = useState8(false);
3444
+ const [values, setValues] = useState8(
3445
+ initialValues ? getInitialValues(initialValues) : {}
3446
+ );
3438
3447
  const handleError = (error) => {
3439
3448
  const fieldErrors = {};
3440
3449
  for (const issue of error.issues) {
@@ -3486,15 +3495,6 @@ var Form = ({
3486
3495
  useEffect10(() => {
3487
3496
  revalidate();
3488
3497
  }, [resolvedLanguage]);
3489
- useEffect10(() => {
3490
- if (initialValues) {
3491
- setValues(getInitialValues(initialValues));
3492
- }
3493
- setIsInitialSetValuesComplete(true);
3494
- }, [initialValues]);
3495
- if (!isInitialSetValuesComplete) {
3496
- return null;
3497
- }
3498
3498
  return /* @__PURE__ */ jsxs47(
3499
3499
  "form",
3500
3500
  {