@rjsf/core 6.0.0-beta.13 → 6.0.0-beta.14

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 (46) hide show
  1. package/dist/core.umd.js +235 -121
  2. package/dist/index.esm.js +277 -157
  3. package/dist/index.esm.js.map +3 -3
  4. package/dist/index.js +301 -182
  5. package/dist/index.js.map +3 -3
  6. package/lib/components/Form.d.ts +43 -12
  7. package/lib/components/Form.d.ts.map +1 -1
  8. package/lib/components/Form.js +70 -22
  9. package/lib/components/fields/ArrayField.d.ts +14 -4
  10. package/lib/components/fields/ArrayField.d.ts.map +1 -1
  11. package/lib/components/fields/ArrayField.js +74 -28
  12. package/lib/components/fields/BooleanField.d.ts.map +1 -1
  13. package/lib/components/fields/BooleanField.js +6 -1
  14. package/lib/components/fields/LayoutGridField.d.ts +19 -1
  15. package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
  16. package/lib/components/fields/LayoutGridField.js +62 -12
  17. package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
  18. package/lib/components/fields/LayoutMultiSchemaField.js +2 -1
  19. package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
  20. package/lib/components/fields/MultiSchemaField.js +2 -1
  21. package/lib/components/fields/NullField.js +3 -3
  22. package/lib/components/fields/NumberField.js +2 -2
  23. package/lib/components/fields/ObjectField.d.ts +2 -2
  24. package/lib/components/fields/ObjectField.d.ts.map +1 -1
  25. package/lib/components/fields/ObjectField.js +16 -19
  26. package/lib/components/fields/SchemaField.js +2 -2
  27. package/lib/components/fields/StringField.d.ts.map +1 -1
  28. package/lib/components/fields/StringField.js +6 -1
  29. package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
  30. package/lib/components/widgets/AltDateWidget.js +15 -18
  31. package/lib/components/widgets/CheckboxesWidget.js +2 -2
  32. package/lib/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +11 -11
  34. package/src/components/Form.tsx +85 -22
  35. package/src/components/fields/ArrayField.tsx +75 -29
  36. package/src/components/fields/BooleanField.tsx +10 -1
  37. package/src/components/fields/LayoutGridField.tsx +69 -11
  38. package/src/components/fields/LayoutMultiSchemaField.tsx +2 -1
  39. package/src/components/fields/MultiSchemaField.tsx +2 -1
  40. package/src/components/fields/NullField.tsx +3 -3
  41. package/src/components/fields/NumberField.tsx +2 -2
  42. package/src/components/fields/ObjectField.tsx +16 -26
  43. package/src/components/fields/SchemaField.tsx +2 -2
  44. package/src/components/fields/StringField.tsx +10 -1
  45. package/src/components/widgets/AltDateWidget.tsx +20 -22
  46. package/src/components/widgets/CheckboxesWidget.tsx +2 -2
@@ -1,7 +1,7 @@
1
1
  import { createElement as _createElement } from "react";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { PureComponent } from 'react';
4
- import { ANY_OF_KEY, getDiscriminatorFieldFromSchema, getTemplate, getTestIds, getUiOptions, hashObject, ID_KEY, lookupFromFormContext, mergeObjects, ONE_OF_KEY, PROPERTIES_KEY, READONLY_KEY, UI_OPTIONS_KEY, UI_GLOBAL_OPTIONS_KEY, } from '@rjsf/utils';
4
+ import { ANY_OF_KEY, getDiscriminatorFieldFromSchema, getTemplate, getTestIds, getUiOptions, hashObject, ID_KEY, lookupFromFormContext, mergeObjects, ONE_OF_KEY, PROPERTIES_KEY, READONLY_KEY, UI_OPTIONS_KEY, UI_GLOBAL_OPTIONS_KEY, ITEMS_KEY, } from '@rjsf/utils';
5
5
  import cloneDeep from 'lodash-es/cloneDeep.js';
6
6
  import each from 'lodash-es/each.js';
7
7
  import flatten from 'lodash-es/flatten.js';
@@ -16,6 +16,7 @@ import isObject from 'lodash-es/isObject.js';
16
16
  import isPlainObject from 'lodash-es/isPlainObject.js';
17
17
  import isString from 'lodash-es/isString.js';
18
18
  import isUndefined from 'lodash-es/isUndefined.js';
19
+ import last from 'lodash-es/last.js';
19
20
  import set from 'lodash-es/set.js';
20
21
  /** The enumeration of the three different Layout GridTemplate type values
21
22
  */
@@ -52,6 +53,14 @@ export const LAYOUT_GRID_OPTION = `ui:${LAYOUT_GRID_UI_OPTION}`;
52
53
  function getNonNullishValue(value, fallback) {
53
54
  return value ?? fallback;
54
55
  }
56
+ /** Detects if a `str` is made up entirely of numeric characters
57
+ *
58
+ * @param str - The string to check to see if it is a numeric index
59
+ * @return - True if the string consists entirely of numeric characters
60
+ */
61
+ function isNumericIndex(str) {
62
+ return /^\d+?$/.test(str); // Matches positive integers
63
+ }
55
64
  /** The `LayoutGridField` will render a schema, uiSchema and formData combination out into a GridTemplate in the shape
56
65
  * described in the uiSchema. To define the grid to use to render the elements within a field in the schema, provide in
57
66
  * the uiSchema for that field the object contained under a `ui:layoutGrid` element. E.g. (as a JSON object):
@@ -395,6 +404,40 @@ export default class LayoutGridField extends PureComponent {
395
404
  const baseId = get(baseIdSchema, ID_KEY);
396
405
  return schemaUtils.toIdSchema(schema, baseId, formData, baseId, idSeparator);
397
406
  }
407
+ /** Computes the `rawSchema` and `idSchema` for a `schema` and a `potentialIndex`. If the `schema` is of type array,
408
+ * has an `ITEMS_KEY` element and `potentialIndex` represents a numeric value, the element at `ITEMS_KEY` is checked
409
+ * to see if it is an array. If it is AND the `potentialIndex`th element is available, it is used as the `rawSchema`,
410
+ * otherwise the last value of the element is used. If it is not, then the element is used as the `rawSchema`. In
411
+ * either case, an `idSchema` is computed for the array index. If the `schema` does not represent an array or the
412
+ * `potentialIndex` is not a numeric value, then `rawSchema` is returned as undefined and given `idSchema` is returned
413
+ * as is.
414
+ *
415
+ * @param schema - The schema to generate the idSchema for
416
+ * @param idSchema - The IdSchema for the schema
417
+ * @param potentialIndex - A string containing a potential index
418
+ * @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
419
+ * @returns - An object containing the `rawSchema` and `idSchema` of an array item, otherwise an undefined `rawSchema`
420
+ */
421
+ static computeArraySchemasIfPresent(schema, idSchema, potentialIndex, idSeparator) {
422
+ let rawSchema;
423
+ if (isNumericIndex(potentialIndex) && schema && schema?.type === 'array' && has(schema, ITEMS_KEY)) {
424
+ const index = Number(potentialIndex);
425
+ const items = schema[ITEMS_KEY];
426
+ if (Array.isArray(items)) {
427
+ if (index > items.length) {
428
+ rawSchema = last(items);
429
+ }
430
+ else {
431
+ rawSchema = items[index];
432
+ }
433
+ }
434
+ else {
435
+ rawSchema = items;
436
+ }
437
+ idSchema = { [ID_KEY]: `${idSchema[ID_KEY]}${idSeparator ?? '_'}${index}` };
438
+ }
439
+ return { rawSchema, idSchema };
440
+ }
398
441
  /** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
399
442
  * the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
400
443
  * element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
@@ -433,7 +476,9 @@ export default class LayoutGridField extends PureComponent {
433
476
  idSchema = get(selectedIdSchema, part, {});
434
477
  }
435
478
  else {
436
- rawSchema = {};
479
+ const result = LayoutGridField.computeArraySchemasIfPresent(schema, idSchema, part, idSeparator);
480
+ rawSchema = result.rawSchema ?? {};
481
+ idSchema = result.idSchema;
437
482
  }
438
483
  // Now drill into the innerData for the part, returning an empty object by default if it doesn't exist
439
484
  innerData = get(innerData, part, {});
@@ -458,11 +503,18 @@ export default class LayoutGridField extends PureComponent {
458
503
  idSchema = mergeObjects(rawIdSchema, idSchema);
459
504
  }
460
505
  isRequired = schema !== undefined && Array.isArray(schema.required) && includes(schema.required, leafPath);
461
- // Now grab the schema from the leafPath of the current schema properties
462
- schema = get(schema, [PROPERTIES_KEY, leafPath]);
463
- // Resolve any `$ref`s for the current schema
464
- schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
465
- idSchema = get(idSchema, leafPath, {});
506
+ const result = LayoutGridField.computeArraySchemasIfPresent(schema, idSchema, leafPath, idSeparator);
507
+ if (result.rawSchema) {
508
+ schema = result.rawSchema;
509
+ idSchema = result.idSchema;
510
+ }
511
+ else {
512
+ // Now grab the schema from the leafPath of the current schema properties
513
+ schema = get(schema, [PROPERTIES_KEY, leafPath]);
514
+ // Resolve any `$ref`s for the current schema
515
+ schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
516
+ idSchema = get(idSchema, leafPath, {});
517
+ }
466
518
  isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
467
519
  if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
468
520
  const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
@@ -545,16 +597,14 @@ export default class LayoutGridField extends PureComponent {
545
597
  * @returns - The `onChange` handling function for the `dottedPath` field
546
598
  */
547
599
  onFieldChange = (dottedPath) => {
548
- return (value, errSchema, id) => {
549
- const { onChange, errorSchema, formData } = this.props;
550
- const newFormData = cloneDeep(formData || {});
600
+ return (value, path, errSchema, id) => {
601
+ const { onChange, errorSchema } = this.props;
551
602
  let newErrorSchema = errorSchema;
552
603
  if (errSchema && errorSchema) {
553
604
  newErrorSchema = cloneDeep(errorSchema);
554
605
  set(newErrorSchema, dottedPath, errSchema);
555
606
  }
556
- set(newFormData, dottedPath, value);
557
- onChange(newFormData, newErrorSchema, id);
607
+ onChange(value, dottedPath.split('.'), newErrorSchema, id);
558
608
  };
559
609
  };
560
610
  /** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
@@ -1 +1 @@
1
- {"version":3,"file":"LayoutMultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/LayoutMultiSchemaField.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,eAAe,EAEf,UAAU,EACV,eAAe,EAOf,UAAU,EAIV,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACT,MAAM,aAAa,CAAC;AAQrB;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,gBAAgB,GAAG,UAAU,EACvE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,EAC7B,aAAa,EAAE,MAAM,EACrB,KAAK,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GAAG,GAAG,EAClH,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,CAAC,EAAE,EACZ,WAAW,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACrC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,QAAQ,CAAC,EAAE,CAAC,GACX,eAAe,CAAC,CAAC,CAAC,EAAE,CAatB;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,CAAC,GAAG,GAAG,EACP,CAAC,SAAS,gBAAgB,GAAG,UAAU,EACvC,CAAC,SAAS,eAAe,GAAG,GAAG,EAC/B,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CAwI3B"}
@@ -104,7 +104,8 @@ export default function LayoutMultiSchemaField(props) {
104
104
  if (newFormData) {
105
105
  set(newFormData, selectorField, opt);
106
106
  }
107
- onChange(newFormData, undefined, id);
107
+ // Pass the component name in the path
108
+ onChange(newFormData, [name], undefined, id);
108
109
  };
109
110
  // filtering the options based on the type of widget because `selectField` does not recognize the `convertOther` prop
110
111
  const widgetOptions = { enumOptions, ...uiOptions };
@@ -1 +1 @@
1
- {"version":3,"file":"MultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/MultiSchemaField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,OAAO,EAIL,UAAU,EACV,eAAe,EAOf,UAAU,EACV,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAErB,4DAA4D;AAC5D,KAAK,eAAe,CAAC,CAAC,SAAS,gBAAgB,GAAG,UAAU,IAAI;IAC9D,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,gBAAgB,EAAE,CAAC,EAAE,CAAC;CACvB,CAAC;AAEF;;;;GAIG;AACH,cAAM,UAAU,CAAC,CA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CAAE,SAAQ,SAAS,CACnH,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACnB,eAAe,CAAC,CAAC,CAAC,CACnB;IACC;;;OAGG;gBACS,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAiBtC;;;;;OAKG;IACH,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,eAAe,CAAC;IAyBjG;;;;;OAKG;IACH,iBAAiB,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE;IAW/E;;;;;OAKG;IACH,cAAc,GAAI,SAAS,MAAM,UAsB/B;IAEF,UAAU;IAKV;OACG;IACH,MAAM;CAyHP;AAED,eAAe,UAAU,CAAC"}
@@ -86,7 +86,8 @@ class AnyOfField extends Component {
86
86
  newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, 'excludeObjectChildren');
87
87
  }
88
88
  this.setState({ selectedOption: intOption }, () => {
89
- onChange(newFormData, undefined, this.getFieldId());
89
+ // Changing the option will pass an empty path array to the parent field which will add the appropriate path
90
+ onChange(newFormData, [], undefined, this.getFieldId());
90
91
  });
91
92
  };
92
93
  getFieldId() {
@@ -5,12 +5,12 @@ import { useEffect } from 'react';
5
5
  * @param props - The `FieldProps` for this template
6
6
  */
7
7
  function NullField(props) {
8
- const { formData, onChange } = props;
8
+ const { name, formData, onChange } = props;
9
9
  useEffect(() => {
10
10
  if (formData === undefined) {
11
- onChange(null);
11
+ onChange(null, [name]);
12
12
  }
13
- }, [formData, onChange]);
13
+ }, [name, formData, onChange]);
14
14
  return null;
15
15
  }
16
16
  export default NullField;
@@ -37,7 +37,7 @@ function NumberField(props) {
37
37
  *
38
38
  * @param value - The current value for the change occurring
39
39
  */
40
- const handleChange = useCallback((value, errorSchema, id) => {
40
+ const handleChange = useCallback((value, path, errorSchema, id) => {
41
41
  // Cache the original value in component state
42
42
  setLastValue(value);
43
43
  // Normalize decimals that don't start with a zero character in advance so
@@ -51,7 +51,7 @@ function NumberField(props) {
51
51
  const processed = typeof value === 'string' && value.match(trailingCharMatcherWithPrefix)
52
52
  ? asNumber(value.replace(trailingCharMatcher, ''))
53
53
  : asNumber(value);
54
- onChange(processed, errorSchema, id);
54
+ onChange(processed, path, errorSchema, id);
55
55
  }, [onChange]);
56
56
  if (typeof lastValue === 'string' && typeof value === 'number') {
57
57
  // Construct a regular expression that checks for a string that consists
@@ -32,7 +32,7 @@ declare class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
32
32
  * @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
33
33
  * @returns - The onPropertyChange callback for the `name` property
34
34
  */
35
- onPropertyChange: (name: string, addedByAdditionalProperties?: boolean) => (value: T | undefined, newErrorSchema?: ErrorSchema<T>, id?: string) => void;
35
+ onPropertyChange: (name: string, addedByAdditionalProperties?: boolean) => (value: T | undefined, path?: (number | string)[], newErrorSchema?: ErrorSchema<T>, id?: string) => void;
36
36
  /** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
37
37
  * and calls the `onChange` callback with it
38
38
  *
@@ -54,7 +54,7 @@ declare class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
54
54
  * @param oldValue - The old value of a field
55
55
  * @returns - The key change callback function
56
56
  */
57
- onKeyChange: (oldValue: any) => (value: any, newErrorSchema: ErrorSchema<T>) => void;
57
+ onKeyChange: (oldValue: any) => (value: any) => void;
58
58
  /** Returns a default value to be used for a new additional schema property of the given `type`
59
59
  *
60
60
  * @param type - The type of the new additional schema property
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/ObjectField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;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@@ -36,8 +36,8 @@ class ObjectField extends Component {
36
36
  * @returns - The onPropertyChange callback for the `name` property
37
37
  */
38
38
  onPropertyChange = (name, addedByAdditionalProperties = false) => {
39
- return (value, newErrorSchema, id) => {
40
- const { formData, onChange, errorSchema } = this.props;
39
+ return (value, path, newErrorSchema, id) => {
40
+ const { onChange } = this.props;
41
41
  if (value === undefined && addedByAdditionalProperties) {
42
42
  // Don't set value = undefined for fields added by
43
43
  // additionalProperties. Doing so removes them from the
@@ -48,12 +48,10 @@ class ObjectField extends Component {
48
48
  // set empty values to the empty string.
49
49
  value = '';
50
50
  }
51
- const newFormData = { ...formData, [name]: value };
52
- onChange(newFormData, errorSchema &&
53
- errorSchema && {
54
- ...errorSchema,
55
- [name]: newErrorSchema,
56
- }, id);
51
+ // Copy the current path and insert in the property name into the first location
52
+ const changePath = Array.isArray(path) ? path.slice() : [];
53
+ changePath.unshift(name);
54
+ onChange(value, changePath, newErrorSchema, id);
57
55
  };
58
56
  };
59
57
  /** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
@@ -65,10 +63,11 @@ class ObjectField extends Component {
65
63
  onDropPropertyClick = (key) => {
66
64
  return (event) => {
67
65
  event.preventDefault();
68
- const { onChange, formData } = this.props;
66
+ const { onChange, formData, name } = this.props;
69
67
  const copiedFormData = { ...formData };
70
68
  unset(copiedFormData, key);
71
- onChange(copiedFormData);
69
+ // drop property will pass the name in `path` array
70
+ onChange(copiedFormData, [name]);
72
71
  };
73
72
  };
74
73
  /** Computes the next available key name from the `preferredKey`, indexing through the already existing keys until one
@@ -95,11 +94,11 @@ class ObjectField extends Component {
95
94
  * @returns - The key change callback function
96
95
  */
97
96
  onKeyChange = (oldValue) => {
98
- return (value, newErrorSchema) => {
97
+ return (value) => {
99
98
  if (oldValue === value) {
100
99
  return;
101
100
  }
102
- const { formData, onChange, errorSchema } = this.props;
101
+ const { formData, onChange } = this.props;
103
102
  value = this.getAvailableKey(value, formData);
104
103
  const newFormData = {
105
104
  ...formData,
@@ -111,11 +110,8 @@ class ObjectField extends Component {
111
110
  });
112
111
  const renamedObj = Object.assign({}, ...keyValues);
113
112
  this.setState({ wasPropertyKeyModified: true });
114
- onChange(renamedObj, errorSchema &&
115
- errorSchema && {
116
- ...errorSchema,
117
- [value]: newErrorSchema,
118
- });
113
+ // rename will pass an empty `path` array since the onPropertyChange also gets called
114
+ onChange(renamedObj, []);
119
115
  };
120
116
  };
121
117
  /** Returns a default value to be used for a new additional schema property of the given `type`
@@ -150,7 +146,7 @@ class ObjectField extends Component {
150
146
  if (!(schema.additionalProperties || schema.patternProperties)) {
151
147
  return;
152
148
  }
153
- const { formData, onChange, registry } = this.props;
149
+ const { formData, name, onChange, registry } = this.props;
154
150
  const newFormData = { ...formData };
155
151
  const newKey = this.getAvailableKey('newKey', newFormData);
156
152
  if (schema.patternProperties) {
@@ -181,7 +177,8 @@ class ObjectField extends Component {
181
177
  // Cast this to make the `set` work properly
182
178
  set(newFormData, newKey, newValue);
183
179
  }
184
- onChange(newFormData);
180
+ // add will pass the name in `path` array
181
+ onChange(newFormData, [name]);
185
182
  };
186
183
  /** Renders the `ObjectField` from the given props
187
184
  */
@@ -71,9 +71,9 @@ function SchemaFieldRender(props) {
71
71
  /** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
72
72
  * `onChange` chain if it is not already being provided from a deeper level in the hierarchy
73
73
  */
74
- const handleFieldComponentChange = useCallback((formData, newErrorSchema, id) => {
74
+ const handleFieldComponentChange = useCallback((formData, path, newErrorSchema, id) => {
75
75
  const theId = id || fieldId;
76
- return onChange(formData, newErrorSchema, theId);
76
+ return onChange(formData, path, newErrorSchema, theId);
77
77
  }, [fieldId, onChange]);
78
78
  const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
79
79
  const disabled = Boolean(uiOptions.disabled ?? props.disabled);
@@ -1 +1 @@
1
- {"version":3,"file":"StringField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/StringField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,EACV,eAAe,EACf,UAAU,EACV,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,iBAAS,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EACpG,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CAsD3B;AAED,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"StringField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/StringField.tsx"],"names":[],"mappings":"AACA,OAAO,EAKL,UAAU,EACV,eAAe,EACf,UAAU,EACV,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,iBAAS,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EACpG,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CA6D3B;AAED,eAAe,WAAW,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback } from 'react';
2
3
  import { getWidget, getUiOptions, optionsList, hasWidget, } from '@rjsf/utils';
3
4
  /** The `StringField` component is used to render a schema field that represents a string type
4
5
  *
@@ -17,6 +18,10 @@ function StringField(props) {
17
18
  const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
18
19
  const label = uiTitle ?? title ?? name;
19
20
  const Widget = getWidget(schema, widget, widgets);
20
- return (_jsx(Widget, { options: { ...options, enumOptions }, schema: schema, uiSchema: uiSchema, id: idSchema.$id, name: name, label: label, hideLabel: !displayLabel, hideError: hideError, value: formData, onChange: onChange, onBlur: onBlur, onFocus: onFocus, required: required, disabled: disabled, readonly: readonly, formContext: formContext, autofocus: autofocus, registry: registry, placeholder: placeholder, rawErrors: rawErrors }));
21
+ const onWidgetChange = useCallback((value, errorSchema, id) => {
22
+ // String field change passes an empty path array to the parent field which adds the appropriate path
23
+ return onChange(value, [], errorSchema, id);
24
+ }, [onChange]);
25
+ return (_jsx(Widget, { options: { ...options, enumOptions }, schema: schema, uiSchema: uiSchema, id: idSchema.$id, name: name, label: label, hideLabel: !displayLabel, hideError: hideError, value: formData, onChange: onWidgetChange, onBlur: onBlur, onFocus: onFocus, required: required, disabled: disabled, readonly: readonly, formContext: formContext, autofocus: autofocus, registry: registry, placeholder: placeholder, rawErrors: rawErrors }));
21
26
  }
22
27
  export default StringField;
@@ -1 +1 @@
1
- {"version":3,"file":"AltDateWidget.d.ts","sourceRoot":"","sources":["../../../src/components/widgets/AltDateWidget.tsx"],"names":[],"mappings":"AACA,OAAO,EAOL,eAAe,EACf,UAAU,EACV,gBAAgB,EAEhB,WAAW,EAEZ,MAAM,aAAa,CAAC;AAsDrB;;GAEG;AACH,iBAAS,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EAAE,EACxG,IAAY,EACZ,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,OAAO,EACP,EAAE,EACF,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,QAAQ,EACR,KAAK,GACN,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CAwFtB;AAED,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"AltDateWidget.d.ts","sourceRoot":"","sources":["../../../src/components/widgets/AltDateWidget.tsx"],"names":[],"mappings":"AACA,OAAO,EAOL,eAAe,EACf,UAAU,EACV,gBAAgB,EAEhB,WAAW,EAEZ,MAAM,aAAa,CAAC;AAsDrB;;GAEG;AACH,iBAAS,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EAAE,EACxG,IAAY,EACZ,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,OAAO,EACP,EAAE,EACF,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,QAAQ,EACR,KAAK,GACN,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CAsFtB;AAED,eAAe,aAAa,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useEffect, useReducer, useState } from 'react';
2
+ import { useCallback, useEffect, useState } from 'react';
3
3
  import { ariaDescribedByIds, dateRangeOptions, parseDateString, toDateString, TranslatableString, getDateElementProps, } from '@rjsf/utils';
4
4
  function readyForChange(state) {
5
5
  return Object.values(state).every((value) => value !== -1);
@@ -14,25 +14,22 @@ function DateElement({ type, range, value, select, rootId, name, disabled, reado
14
14
  */
15
15
  function AltDateWidget({ time = false, disabled = false, readonly = false, autofocus = false, options, id, name, registry, onBlur, onFocus, onChange, value, }) {
16
16
  const { translateString } = registry;
17
- const [lastValue, setLastValue] = useState(value);
18
- const [state, setState] = useReducer((state, action) => {
19
- return { ...state, ...action };
20
- }, parseDateString(value, time));
17
+ const [state, setState] = useState(parseDateString(value, time));
21
18
  useEffect(() => {
22
- const stateValue = toDateString(state, time);
23
- if (readyForChange(state) && stateValue !== value) {
24
- // The user changed the date to a new valid data via the comboboxes, so call onChange
25
- onChange(stateValue);
19
+ setState(parseDateString(value, time));
20
+ }, [time, value]);
21
+ const handleChange = useCallback((property, value) => {
22
+ const nextState = {
23
+ ...state,
24
+ [property]: typeof value === 'undefined' ? -1 : value,
25
+ };
26
+ if (readyForChange(nextState)) {
27
+ onChange(toDateString(nextState, time));
26
28
  }
27
- else if (lastValue !== value) {
28
- // We got a new value in the props
29
- setLastValue(value);
30
- setState(parseDateString(value, time));
29
+ else {
30
+ setState(nextState);
31
31
  }
32
- }, [time, value, onChange, state, lastValue]);
33
- const handleChange = useCallback((property, value) => {
34
- setState({ [property]: value });
35
- }, []);
32
+ }, [state, onChange, time]);
36
33
  const handleSetNow = useCallback((event) => {
37
34
  event.preventDefault();
38
35
  if (disabled || readonly) {
@@ -40,7 +37,7 @@ function AltDateWidget({ time = false, disabled = false, readonly = false, autof
40
37
  }
41
38
  const nextState = parseDateString(new Date().toJSON(), time);
42
39
  onChange(toDateString(nextState, time));
43
- }, [disabled, readonly, time]);
40
+ }, [disabled, readonly, time, onChange]);
44
41
  const handleClear = useCallback((event) => {
45
42
  event.preventDefault();
46
43
  if (disabled || readonly) {
@@ -8,8 +8,8 @@ import { ariaDescribedByIds, enumOptionsDeselectValue, enumOptionsIsSelected, en
8
8
  */
9
9
  function CheckboxesWidget({ id, disabled, options: { inline = false, enumOptions, enumDisabled, emptyValue }, value, autofocus = false, readonly, onChange, onBlur, onFocus, }) {
10
10
  const checkboxesValues = Array.isArray(value) ? value : [value];
11
- const handleBlur = useCallback(({ target }) => onBlur(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)), [onBlur, id]);
12
- const handleFocus = useCallback(({ target }) => onFocus(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)), [onFocus, id]);
11
+ const handleBlur = useCallback(({ target }) => onBlur(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)), [onBlur, id, enumOptions, emptyValue]);
12
+ const handleFocus = useCallback(({ target }) => onFocus(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)), [onFocus, id, enumOptions, emptyValue]);
13
13
  return (_jsx("div", { className: 'checkboxes', id: id, children: Array.isArray(enumOptions) &&
14
14
  enumOptions.map((option, index) => {
15
15
  const checked = enumOptionsIsSelected(option.value, checkboxesValues);