@formality-ui/react 0.3.0 → 0.4.0

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/README.md CHANGED
@@ -67,8 +67,8 @@ function App() {
67
67
  return (
68
68
  <FormalityProvider inputs={inputs}>
69
69
  <Form config={config} onSubmit={(values) => console.log(values)}>
70
- {({ methods }) => (
71
- <form onSubmit={methods.handleSubmit(console.log)}>
70
+ {({ handleSubmit }) => (
71
+ <form onSubmit={handleSubmit(console.log)}>
72
72
  <Field name="name" />
73
73
  <Field name="email" />
74
74
  <Field name="subscribed" />
package/dist/index.cjs CHANGED
@@ -164,8 +164,15 @@ function Form({
164
164
  return result;
165
165
  }, [providerConfig.inputs, formConfig.inputs]);
166
166
  const defaultValues = react.useMemo(() => {
167
- const resolved = core.resolveAllInitialValues(config, mergedInputs, record ?? {});
168
- const baseline = { ...record ?? {}, ...resolved };
167
+ const resolved = core.resolveAllInitialValues(
168
+ config,
169
+ mergedInputs,
170
+ record ?? {}
171
+ );
172
+ const baseline = {
173
+ ...record ?? {},
174
+ ...resolved
175
+ };
169
176
  for (const fieldName of Object.keys(config)) {
170
177
  if (!(fieldName in baseline)) baseline[fieldName] = void 0;
171
178
  }
@@ -203,11 +210,6 @@ function Form({
203
210
  invertedSubscriptions.current.set(target, /* @__PURE__ */ new Set());
204
211
  }
205
212
  invertedSubscriptions.current.get(target).add(subscriber);
206
- if (process.env.NODE_ENV !== "production") {
207
- console.warn(
208
- `[Formality Subscription] "${subscriber}" added to watch "${target}"`
209
- );
210
- }
211
213
  const setter = watcherSetters.current.get(target);
212
214
  if (setter) {
213
215
  setter((prev) => ({ ...prev, [subscriber]: true }));
@@ -220,20 +222,7 @@ function Form({
220
222
  }, []);
221
223
  const removeSubscription = react.useCallback(
222
224
  (target, subscriber) => {
223
- const subscribers = invertedSubscriptions.current.get(target);
224
- const subscriptionExists = subscribers?.has(subscriber) ?? false;
225
225
  invertedSubscriptions.current.get(target)?.delete(subscriber);
226
- if (process.env.NODE_ENV !== "production") {
227
- if (subscriptionExists) {
228
- console.warn(
229
- `[Formality Subscription] "${subscriber}" removed from watching "${target}"`
230
- );
231
- } else {
232
- console.warn(
233
- `[Formality Subscription] WARNING: Double-cleanup attempt - "${subscriber}" was not watching "${target}"`
234
- );
235
- }
236
- }
237
226
  const setter = watcherSetters.current.get(target);
238
227
  if (setter) {
239
228
  setter((prev) => {
@@ -290,7 +279,11 @@ function Form({
290
279
  for (const field of affected) {
291
280
  pendingAffectedFields.current.add(field);
292
281
  }
293
- const fieldDebounce = inputConfig?.debounce;
282
+ const fieldConfig = config[name];
283
+ const fieldDebounce = core.resolveFieldOverType(
284
+ fieldConfig?.debounce,
285
+ inputConfig?.debounce
286
+ );
294
287
  if (fieldDebounce === false) {
295
288
  executeAutoSaveRef.current?.();
296
289
  } else if (typeof fieldDebounce === "number") {
@@ -300,7 +293,7 @@ function Form({
300
293
  }
301
294
  }
302
295
  },
303
- [autoSave, getAffectedFields]
296
+ [autoSave, getAffectedFields, config]
304
297
  );
305
298
  const setFieldValidating = react.useCallback(
306
299
  (name, isValidating) => {
@@ -604,13 +597,17 @@ function transformValuesForSubmit(values, config, inputs) {
604
597
  const fieldConfig = config[name];
605
598
  const type = fieldConfig?.type ?? "textField";
606
599
  const inputConfig = inputs[type];
607
- if (inputConfig) {
608
- const submitName = core.transformFieldName(name, inputConfig.getSubmitField);
609
- const submitValue = core.extractValueField(value, inputConfig.valueField);
610
- result[submitName] = submitValue;
611
- } else {
612
- result[name] = value;
613
- }
600
+ const effectiveGetSubmitField = core.resolveFieldOverType(
601
+ fieldConfig?.getSubmitField,
602
+ inputConfig?.getSubmitField
603
+ );
604
+ const effectiveValueField = core.resolveFieldOverType(
605
+ fieldConfig?.valueField,
606
+ inputConfig?.valueField
607
+ );
608
+ const submitName = core.transformFieldName(name, effectiveGetSubmitField);
609
+ const submitValue = core.extractValueField(value, effectiveValueField);
610
+ result[submitName] = submitValue;
614
611
  }
615
612
  return result;
616
613
  }
@@ -920,20 +917,10 @@ function useSubscriptions(fieldName, subscriptions) {
920
917
  runSubscriptionsRef.current.set(currentRunId, [...subscriptions]);
921
918
  subscriptions.forEach((target) => {
922
919
  addSubscription(target, fieldName);
923
- if (process.env.NODE_ENV !== "production") {
924
- console.warn(
925
- `[Formality Subscription] Run ${currentRunId}: "${fieldName}" subscribing to "${target}"`
926
- );
927
- }
928
920
  });
929
921
  return () => {
930
922
  const thisRunSubscriptions = runSubscriptionsRef.current.get(currentRunId);
931
923
  if (thisRunSubscriptions) {
932
- if (process.env.NODE_ENV !== "production") {
933
- console.warn(
934
- `[Formality Subscription] Run ${currentRunId}: "${fieldName}" cleaning up [${thisRunSubscriptions.join(", ")}]`
935
- );
936
- }
937
924
  [...thisRunSubscriptions].reverse().forEach((target) => {
938
925
  removeSubscription(target, fieldName);
939
926
  });
@@ -1097,8 +1084,22 @@ function useField({
1097
1084
  groupContext.state.isVisible
1098
1085
  ]);
1099
1086
  const label = react.useMemo(() => {
1100
- return core.resolveLabel(name, fieldConfig, fieldSelectProps, restProps);
1101
- }, [name, fieldConfig, fieldSelectProps, restProps]);
1087
+ return core.resolveLabel(
1088
+ name,
1089
+ fieldConfig,
1090
+ fieldSelectProps,
1091
+ restProps,
1092
+ providerSelectProps,
1093
+ formSelectProps
1094
+ );
1095
+ }, [
1096
+ name,
1097
+ fieldConfig,
1098
+ fieldSelectProps,
1099
+ restProps,
1100
+ providerSelectProps,
1101
+ formSelectProps
1102
+ ]);
1102
1103
  const passSubscriptionsEnabled = fieldConfig.passSubscriptions === true;
1103
1104
  const provideStateEnabled = fieldConfig.provideState === true;
1104
1105
  const subscribedWatchNames = react.useMemo(
@@ -1177,23 +1178,25 @@ function useField({
1177
1178
  name,
1178
1179
  setFieldValidating
1179
1180
  ]);
1181
+ const effectiveParser = react.useMemo(
1182
+ () => core.resolveFieldOverType(fieldConfig.parser, inputConfig.parser),
1183
+ [fieldConfig.parser, inputConfig.parser]
1184
+ );
1185
+ const effectiveFormatter = react.useMemo(
1186
+ () => core.resolveFieldOverType(fieldConfig.formatter, inputConfig.formatter),
1187
+ [fieldConfig.formatter, inputConfig.formatter]
1188
+ );
1180
1189
  const handleChange = react.useCallback(
1181
1190
  (onChange) => (newValue) => {
1182
1191
  const parsedValue = core.parse(
1183
1192
  newValue,
1184
- inputConfig.parser,
1193
+ effectiveParser,
1185
1194
  providerConfig.parsers
1186
1195
  );
1187
1196
  onChange(parsedValue);
1188
1197
  changeField(name, parsedValue, inputConfig);
1189
1198
  },
1190
- [
1191
- inputConfig.parser,
1192
- providerConfig.parsers,
1193
- changeField,
1194
- name,
1195
- inputConfig
1196
- ]
1199
+ [effectiveParser, providerConfig.parsers, changeField, name, inputConfig]
1197
1200
  );
1198
1201
  const fieldStateRef = react.useRef(
1199
1202
  {}
@@ -1211,7 +1214,7 @@ function useField({
1211
1214
  render: ({ field, fieldState, formState }) => {
1212
1215
  const formattedValue = core.format(
1213
1216
  field.value,
1214
- inputConfig.formatter,
1217
+ effectiveFormatter,
1215
1218
  providerConfig.formatters
1216
1219
  );
1217
1220
  const stateInjection = {};