@overmap-ai/forms 1.0.32-react-flow-david-fixes.18 → 1.0.32-react-flow-david-fixes.20

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/forms.js CHANGED
@@ -34621,7 +34621,6 @@ const deserializeConditions = (serializedConditions, fields) => {
34621
34621
  );
34622
34622
  };
34623
34623
  const applyConditions = (conditions, values) => {
34624
- console.debug("apply conditions", values);
34625
34624
  return conditions.length > 0 ? conditions.every((condition) => {
34626
34625
  return condition.apply(values[condition.field.identifier]);
34627
34626
  }) : true;
@@ -34741,6 +34740,7 @@ const FieldSectionLayout = memo((props) => {
34741
34740
  }, [fieldSections, section.identifier]);
34742
34741
  const conditionMet = useMemo(() => {
34743
34742
  if (conditionalSections.length === 0) return true;
34743
+ console.debug("apply conditions section layout", values);
34744
34744
  return conditionalSections.some(
34745
34745
  (conditionalSection) => applyConditions(conditionalSection.getConditions(section.identifier), values)
34746
34746
  );
@@ -36139,6 +36139,7 @@ const validateFields = (fields, values) => {
36139
36139
  for (const field of fields) {
36140
36140
  if (field instanceof FieldSection) {
36141
36141
  const conditionalSections = sectionElements.filter((section) => field.identifier in section.conditions);
36142
+ console.debug("apply conditions validate fields", values);
36142
36143
  const conditionMet = conditionalSections.length > 0 ? conditionalSections.some(
36143
36144
  (conditionalSection) => applyConditions(conditionalSection.getConditions(field.identifier), values)
36144
36145
  ) : true;
@@ -36240,6 +36241,15 @@ async function awaitPromisesFromFieldValues(values) {
36240
36241
  }
36241
36242
  return valuesWithoutFiles;
36242
36243
  }
36244
+ const EXTRA_KEY = "__EXTRA_KEY__";
36245
+ const addExtraKey = (values) => {
36246
+ return { ...values, [EXTRA_KEY]: v4() };
36247
+ };
36248
+ const stripExtraKey = (values) => {
36249
+ const valuesCopy = { ...values };
36250
+ delete valuesCopy[EXTRA_KEY];
36251
+ return valuesCopy;
36252
+ };
36243
36253
  const FormRenderer = memo(
36244
36254
  forwardRef((props, ref) => {
36245
36255
  const {
@@ -36263,9 +36273,8 @@ const FormRenderer = memo(
36263
36273
  const { readonly } = schema.meta;
36264
36274
  const formId2 = useId$1();
36265
36275
  const initialValues = useMemo(() => {
36266
- return initializeFieldValues(flattenFields(schema.fields), values);
36276
+ return addExtraKey(initializeFieldValues(flattenFields(schema.fields), values));
36267
36277
  }, [schema.fields, values]);
36268
- console.debug("initialValues", initialValues);
36269
36278
  const handleSubmit = useCallback(
36270
36279
  (values2) => {
36271
36280
  onSubmit == null ? void 0 : onSubmit(
@@ -36276,26 +36285,19 @@ const FormRenderer = memo(
36276
36285
  );
36277
36286
  const formik = useFormik({
36278
36287
  initialValues,
36279
- onSubmit: handleSubmit,
36280
- validate: (form) => validateFields(schema.fields, form),
36288
+ onSubmit: (values2) => handleSubmit(stripExtraKey(values2)),
36289
+ validate: (values2) => validateFields(schema.fields, stripExtraKey(values2)),
36281
36290
  // only validate the entire form on submit
36282
36291
  validateOnBlur: false,
36283
36292
  validateOnChange: false,
36284
- enableReinitialize: false
36293
+ enableReinitialize
36285
36294
  });
36286
- useLayoutEffect(() => {
36287
- if (enableReinitialize) {
36288
- formik.resetForm({
36289
- values: initialValues
36290
- });
36291
- }
36292
- }, [enableReinitialize, initialValues]);
36293
36295
  const { dirty } = formik;
36294
36296
  const handleValuesChange = useCallback(
36295
36297
  (identifier, value) => {
36296
36298
  const field = getFieldsMapping(schema.fields)[identifier];
36297
36299
  if (field.areValuesEqual(initialValues[identifier], value)) return;
36298
- onValuesChange == null ? void 0 : onValuesChange({ ...formik.values, [identifier]: value }, { [identifier]: value });
36300
+ onValuesChange == null ? void 0 : onValuesChange({ ...stripExtraKey(formik.values), [identifier]: value }, { [identifier]: value });
36299
36301
  },
36300
36302
  [formik.values, initialValues, onValuesChange, schema.fields]
36301
36303
  );
@@ -34623,7 +34623,6 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
34623
34623
  );
34624
34624
  };
34625
34625
  const applyConditions = (conditions, values) => {
34626
- console.debug("apply conditions", values);
34627
34626
  return conditions.length > 0 ? conditions.every((condition) => {
34628
34627
  return condition.apply(values[condition.field.identifier]);
34629
34628
  }) : true;
@@ -34743,6 +34742,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
34743
34742
  }, [fieldSections, section.identifier]);
34744
34743
  const conditionMet = React.useMemo(() => {
34745
34744
  if (conditionalSections.length === 0) return true;
34745
+ console.debug("apply conditions section layout", values);
34746
34746
  return conditionalSections.some(
34747
34747
  (conditionalSection) => applyConditions(conditionalSection.getConditions(section.identifier), values)
34748
34748
  );
@@ -36141,6 +36141,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
36141
36141
  for (const field of fields) {
36142
36142
  if (field instanceof FieldSection) {
36143
36143
  const conditionalSections = sectionElements.filter((section) => field.identifier in section.conditions);
36144
+ console.debug("apply conditions validate fields", values);
36144
36145
  const conditionMet = conditionalSections.length > 0 ? conditionalSections.some(
36145
36146
  (conditionalSection) => applyConditions(conditionalSection.getConditions(field.identifier), values)
36146
36147
  ) : true;
@@ -36242,6 +36243,15 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
36242
36243
  }
36243
36244
  return valuesWithoutFiles;
36244
36245
  }
36246
+ const EXTRA_KEY = "__EXTRA_KEY__";
36247
+ const addExtraKey = (values) => {
36248
+ return { ...values, [EXTRA_KEY]: uuid.v4() };
36249
+ };
36250
+ const stripExtraKey = (values) => {
36251
+ const valuesCopy = { ...values };
36252
+ delete valuesCopy[EXTRA_KEY];
36253
+ return valuesCopy;
36254
+ };
36245
36255
  const FormRenderer = React.memo(
36246
36256
  React.forwardRef((props, ref) => {
36247
36257
  const {
@@ -36265,9 +36275,8 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
36265
36275
  const { readonly } = schema.meta;
36266
36276
  const formId2 = React.useId();
36267
36277
  const initialValues = React.useMemo(() => {
36268
- return initializeFieldValues(flattenFields(schema.fields), values);
36278
+ return addExtraKey(initializeFieldValues(flattenFields(schema.fields), values));
36269
36279
  }, [schema.fields, values]);
36270
- console.debug("initialValues", initialValues);
36271
36280
  const handleSubmit = React.useCallback(
36272
36281
  (values2) => {
36273
36282
  onSubmit == null ? void 0 : onSubmit(
@@ -36278,26 +36287,19 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
36278
36287
  );
36279
36288
  const formik$1 = formik.useFormik({
36280
36289
  initialValues,
36281
- onSubmit: handleSubmit,
36282
- validate: (form) => validateFields(schema.fields, form),
36290
+ onSubmit: (values2) => handleSubmit(stripExtraKey(values2)),
36291
+ validate: (values2) => validateFields(schema.fields, stripExtraKey(values2)),
36283
36292
  // only validate the entire form on submit
36284
36293
  validateOnBlur: false,
36285
36294
  validateOnChange: false,
36286
- enableReinitialize: false
36295
+ enableReinitialize
36287
36296
  });
36288
- React.useLayoutEffect(() => {
36289
- if (enableReinitialize) {
36290
- formik$1.resetForm({
36291
- values: initialValues
36292
- });
36293
- }
36294
- }, [enableReinitialize, initialValues]);
36295
36297
  const { dirty } = formik$1;
36296
36298
  const handleValuesChange = React.useCallback(
36297
36299
  (identifier, value) => {
36298
36300
  const field = getFieldsMapping(schema.fields)[identifier];
36299
36301
  if (field.areValuesEqual(initialValues[identifier], value)) return;
36300
- onValuesChange == null ? void 0 : onValuesChange({ ...formik$1.values, [identifier]: value }, { [identifier]: value });
36302
+ onValuesChange == null ? void 0 : onValuesChange({ ...stripExtraKey(formik$1.values), [identifier]: value }, { [identifier]: value });
36301
36303
  },
36302
36304
  [formik$1.values, initialValues, onValuesChange, schema.fields]
36303
36305
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overmap-ai/forms",
3
- "version": "1.0.32-react-flow-david-fixes.18",
3
+ "version": "1.0.32-react-flow-david-fixes.20",
4
4
  "license": "UNLICENSED",
5
5
  "main": "dist/forms.umd.cjs",
6
6
  "module": "dist/forms.js",