@rjsf/utils 6.0.0-beta.9 → 6.0.1

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 (113) hide show
  1. package/dist/{index.js → index.cjs} +563 -200
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/utils.esm.js +562 -199
  4. package/dist/utils.esm.js.map +4 -4
  5. package/dist/utils.umd.js +533 -193
  6. package/lib/ErrorSchemaBuilder.d.ts +2 -2
  7. package/lib/constants.d.ts +3 -0
  8. package/lib/constants.js +3 -0
  9. package/lib/constants.js.map +1 -1
  10. package/lib/createSchemaUtils.js +25 -18
  11. package/lib/createSchemaUtils.js.map +1 -1
  12. package/lib/enums.d.ts +13 -3
  13. package/lib/enums.js +13 -3
  14. package/lib/enums.js.map +1 -1
  15. package/lib/findSchemaDefinition.d.ts +6 -0
  16. package/lib/findSchemaDefinition.js +44 -3
  17. package/lib/findSchemaDefinition.js.map +1 -1
  18. package/lib/getDateElementProps.d.ts +1 -2
  19. package/lib/getTestIds.js +2 -2
  20. package/lib/getTestIds.js.map +1 -1
  21. package/lib/getUiOptions.js +4 -0
  22. package/lib/getUiOptions.js.map +1 -1
  23. package/lib/getWidget.js +3 -3
  24. package/lib/getWidget.js.map +1 -1
  25. package/lib/guessType.d.ts +1 -1
  26. package/lib/idGenerators.d.ts +22 -15
  27. package/lib/idGenerators.js +17 -8
  28. package/lib/idGenerators.js.map +1 -1
  29. package/lib/index.d.ts +16 -6
  30. package/lib/index.js +13 -4
  31. package/lib/index.js.map +1 -1
  32. package/lib/isFormDataAvailable.d.ts +7 -0
  33. package/lib/isFormDataAvailable.js +13 -0
  34. package/lib/isFormDataAvailable.js.map +1 -0
  35. package/lib/isRootSchema.d.ts +13 -0
  36. package/lib/isRootSchema.js +25 -0
  37. package/lib/isRootSchema.js.map +1 -0
  38. package/lib/mergeDefaultsWithFormData.js +14 -2
  39. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  40. package/lib/nameGenerators.d.ts +13 -0
  41. package/lib/nameGenerators.js +30 -0
  42. package/lib/nameGenerators.js.map +1 -0
  43. package/lib/schema/getDefaultFormState.d.ts +17 -3
  44. package/lib/schema/getDefaultFormState.js +66 -26
  45. package/lib/schema/getDefaultFormState.js.map +1 -1
  46. package/lib/schema/getDisplayLabel.js +2 -2
  47. package/lib/schema/getDisplayLabel.js.map +1 -1
  48. package/lib/schema/index.d.ts +1 -2
  49. package/lib/schema/index.js +1 -2
  50. package/lib/schema/index.js.map +1 -1
  51. package/lib/schema/retrieveSchema.d.ts +10 -5
  52. package/lib/schema/retrieveSchema.js +40 -17
  53. package/lib/schema/retrieveSchema.js.map +1 -1
  54. package/lib/shallowEquals.d.ts +8 -0
  55. package/lib/shallowEquals.js +36 -0
  56. package/lib/shallowEquals.js.map +1 -0
  57. package/lib/shouldRender.d.ts +8 -2
  58. package/lib/shouldRender.js +17 -2
  59. package/lib/shouldRender.js.map +1 -1
  60. package/lib/shouldRenderOptionalField.d.ts +18 -0
  61. package/lib/shouldRenderOptionalField.js +47 -0
  62. package/lib/shouldRenderOptionalField.js.map +1 -0
  63. package/lib/toFieldPathId.d.ts +14 -0
  64. package/lib/toFieldPathId.js +26 -0
  65. package/lib/toFieldPathId.js.map +1 -0
  66. package/lib/tsconfig.tsbuildinfo +1 -1
  67. package/lib/types.d.ts +196 -105
  68. package/lib/useAltDateWidgetProps.d.ts +39 -0
  69. package/lib/useAltDateWidgetProps.js +71 -0
  70. package/lib/useAltDateWidgetProps.js.map +1 -0
  71. package/lib/useDeepCompareMemo.d.ts +8 -0
  72. package/lib/useDeepCompareMemo.js +17 -0
  73. package/lib/useDeepCompareMemo.js.map +1 -0
  74. package/lib/useFileWidgetProps.d.ts +29 -0
  75. package/lib/useFileWidgetProps.js +119 -0
  76. package/lib/useFileWidgetProps.js.map +1 -0
  77. package/lib/validationDataMerge.d.ts +2 -1
  78. package/lib/validationDataMerge.js +3 -2
  79. package/lib/validationDataMerge.js.map +1 -1
  80. package/package.json +13 -14
  81. package/src/ErrorSchemaBuilder.ts +2 -2
  82. package/src/constants.ts +3 -0
  83. package/src/createSchemaUtils.ts +25 -26
  84. package/src/enums.ts +13 -3
  85. package/src/findSchemaDefinition.ts +51 -3
  86. package/src/getDateElementProps.ts +1 -1
  87. package/src/getTestIds.ts +2 -2
  88. package/src/getUiOptions.ts +4 -0
  89. package/src/getWidget.tsx +3 -3
  90. package/src/idGenerators.ts +35 -25
  91. package/src/index.ts +36 -5
  92. package/src/isFormDataAvailable.ts +13 -0
  93. package/src/isRootSchema.ts +30 -0
  94. package/src/mergeDefaultsWithFormData.ts +16 -2
  95. package/src/nameGenerators.ts +43 -0
  96. package/src/schema/getDefaultFormState.ts +87 -31
  97. package/src/schema/getDisplayLabel.ts +2 -2
  98. package/src/schema/index.ts +0 -2
  99. package/src/schema/retrieveSchema.ts +43 -7
  100. package/src/shallowEquals.ts +41 -0
  101. package/src/shouldRender.ts +27 -2
  102. package/src/shouldRenderOptionalField.ts +56 -0
  103. package/src/toFieldPathId.ts +34 -0
  104. package/src/types.ts +229 -113
  105. package/src/useAltDateWidgetProps.tsx +163 -0
  106. package/src/useDeepCompareMemo.ts +17 -0
  107. package/src/useFileWidgetProps.ts +155 -0
  108. package/src/validationDataMerge.ts +7 -1
  109. package/dist/index.js.map +0 -7
  110. package/lib/schema/toIdSchema.d.ts +0 -14
  111. package/lib/schema/toIdSchema.js +0 -62
  112. package/lib/schema/toIdSchema.js.map +0 -1
  113. package/src/schema/toIdSchema.ts +0 -131
@@ -0,0 +1,71 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useMemo, useState } from 'react';
3
+ import dateRangeOptions from './dateRangeOptions.js';
4
+ import getDateElementProps from './getDateElementProps.js';
5
+ import { ariaDescribedByIds } from './idGenerators.js';
6
+ import parseDateString from './parseDateString.js';
7
+ import toDateString from './toDateString.js';
8
+ /** Function that checks to see if a `DateObject` is ready for the onChange callback to be triggered
9
+ *
10
+ * @param state - The current `DateObject`
11
+ * @returns - True if the `state` is ready to trigger an onChange
12
+ */
13
+ function readyForChange(state) {
14
+ return Object.values(state).every((value) => value !== -1);
15
+ }
16
+ /** The `DateElement` component renders one of the 6 date element selectors for an `AltDateWidget`, using the `select`
17
+ * widget from the registry.
18
+ *
19
+ * @param props - The `DateElementProps` for the date element
20
+ */
21
+ export function DateElement(props) {
22
+ const { className = 'form-control', type, range, value, select, rootId, name, disabled, readonly, autofocus, registry, onBlur, onFocus, } = props;
23
+ const id = `${rootId}_${type}`;
24
+ const { SelectWidget } = registry.widgets;
25
+ const onChange = useCallback((value) => select(type, value), [select, type]);
26
+ return (_jsx(SelectWidget, { schema: { type: 'integer' }, id: id, name: name, className: className, options: { enumOptions: dateRangeOptions(range[0], range[1]) }, placeholder: type, value: value, disabled: disabled, readonly: readonly, autofocus: autofocus, onChange: onChange, onBlur: onBlur, onFocus: onFocus, registry: registry, label: '', "aria-describedby": ariaDescribedByIds(rootId) }));
27
+ }
28
+ /** Hook which encapsulates the logic needed to render an `AltDateWidget` with optional `time` elements. It contains
29
+ * the `state` of the current date(/time) selections in the widget. It returns a `UseAltDateWidgetResult` object
30
+ * that contains the `elements: DateElementProp[]` and three callbacks needed to change one of the rendered `elements`,
31
+ * and to handle the clicking of the `clear` and `setNow` buttons.
32
+ *
33
+ * @param props - The `WidgetProps` for the `AltDateWidget`
34
+ */
35
+ export default function useAltDateWidgetProps(props) {
36
+ const { time = false, disabled = false, readonly = false, options, onChange, value } = props;
37
+ const [state, setState] = useState(parseDateString(value, time));
38
+ useEffect(() => {
39
+ setState(parseDateString(value, time));
40
+ }, [time, value]);
41
+ const handleChange = useCallback((property, value) => {
42
+ const nextState = {
43
+ ...state,
44
+ [property]: typeof value === 'undefined' ? -1 : value,
45
+ };
46
+ if (readyForChange(nextState)) {
47
+ onChange(toDateString(nextState, time));
48
+ }
49
+ else {
50
+ setState(nextState);
51
+ }
52
+ }, [state, onChange, time]);
53
+ const handleClear = useCallback((event) => {
54
+ event.preventDefault();
55
+ if (disabled || readonly) {
56
+ return;
57
+ }
58
+ onChange(undefined);
59
+ }, [disabled, readonly, onChange]);
60
+ const handleSetNow = useCallback((event) => {
61
+ event.preventDefault();
62
+ if (disabled || readonly) {
63
+ return;
64
+ }
65
+ const nextState = parseDateString(new Date().toJSON(), time);
66
+ onChange(toDateString(nextState, time));
67
+ }, [disabled, readonly, time, onChange]);
68
+ const elements = useMemo(() => getDateElementProps(state, time, options.yearsRange, options.format), [state, time, options.yearsRange, options.format]);
69
+ return { elements, handleChange, handleClear, handleSetNow };
70
+ }
71
+ //# sourceMappingURL=useAltDateWidgetProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAltDateWidgetProps.js","sourceRoot":"","sources":["../src/useAltDateWidgetProps.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAc,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE9E,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,mBAA2D,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAG1C;;;;GAIG;AACH,SAAS,cAAc,CAAC,KAAiB;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAiBD;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,KAAgC;IAEhC,MAAM,EACJ,SAAS,GAAG,cAAc,EAC1B,IAAI,EACJ,KAAK,EACL,KAAK,EACL,MAAM,EACN,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,MAAM,EACN,OAAO,GACR,GA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1C,CAAC,EACD,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CACrC,CAAC;IAEF,MAAM,QAAQ,GAAG,OAAO,CACtB,GAAG,EAAE,CACH,mBAAmB,CACjB,KAAK,EACL,IAAI,EACJ,OAAO,CAAC,UAA0C,EAClD,OAAO,CAAC,MAAuC,CAChD,EACH,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,CAClD,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** Hook that stores and returns a `T` value. If `newValue` is the same as the stored one, then the stored one is
2
+ * returned to avoid having a component rerender due it being a different object. Otherwise, the `newValue` is stored
3
+ * and returned.
4
+ *
5
+ * @param newValue - The potential new `T` value
6
+ * @returns - The latest stored `T` value
7
+ */
8
+ export default function useDeepCompareMemo<T = unknown>(newValue: T): T;
@@ -0,0 +1,17 @@
1
+ import { useRef } from 'react';
2
+ import isEqual from 'lodash-es/isEqual.js';
3
+ /** Hook that stores and returns a `T` value. If `newValue` is the same as the stored one, then the stored one is
4
+ * returned to avoid having a component rerender due it being a different object. Otherwise, the `newValue` is stored
5
+ * and returned.
6
+ *
7
+ * @param newValue - The potential new `T` value
8
+ * @returns - The latest stored `T` value
9
+ */
10
+ export default function useDeepCompareMemo(newValue) {
11
+ const valueRef = useRef(newValue);
12
+ if (!isEqual(newValue, valueRef.current)) {
13
+ valueRef.current = newValue;
14
+ }
15
+ return valueRef.current;
16
+ }
17
+ //# sourceMappingURL=useDeepCompareMemo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDeepCompareMemo.js","sourceRoot":"","sources":["../src/useDeepCompareMemo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAc,QAAW;IACjE,MAAM,QAAQ,GAAG,MAAM,CAAI,QAAQ,CAAC,CAAC;IACrC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC9B,CAAC;IACD,OAAO,QAAQ,CAAC,OAAO,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,29 @@
1
+ /** The information about files used by a FileWidget */
2
+ export type FileInfoType = {
3
+ /** The url of the data containing the file */
4
+ dataURL?: string | null;
5
+ /** The name of the file */
6
+ name: string;
7
+ /** The size of the file */
8
+ size: number;
9
+ /** The type of the file */
10
+ type: string;
11
+ };
12
+ export interface UseFileWidgetPropsResult {
13
+ /** The list of FileInfoType contained within the FileWidget */
14
+ filesInfo: FileInfoType[];
15
+ /** The callback handler to pass to the onChange of the input */
16
+ handleChange: (files: FileList) => void;
17
+ /** The callback handler to pass in order to delete a file */
18
+ handleRemove: (index: number) => void;
19
+ }
20
+ /** Hook which encapsulates the logic needed to read and convert a `value` of `File` or `File[]` into the
21
+ * `filesInfo: FileInfoType[]` and the two callback implementations needed to change the list or to remove a
22
+ * `File` from the list. To be used by theme specific `FileWidget` implementations.
23
+ *
24
+ * @param value - The current value of the `FileWidget`
25
+ * @param onChange - The onChange handler for the `FileWidget`
26
+ * @param [multiple=false] - Flag indicating whether the control supports multiple selections
27
+ * @returns - The `UseFileWidgetPropsResult` to be used within a `FileWidget` implementation
28
+ */
29
+ export default function useFileWidgetProps(value: string | string[] | undefined | null, onChange: (value?: string | null | (string | null)[]) => void, multiple?: boolean): UseFileWidgetPropsResult;
@@ -0,0 +1,119 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import dataURItoBlob from './dataURItoBlob.js';
3
+ /** Updated the given `dataUrl` to add the `name` to it
4
+ *
5
+ * @param dataURL - The url description string
6
+ * @param name - The name of the file to add to the dataUrl
7
+ * @returns - The `dataUrl` updated to include the name
8
+ */
9
+ function addNameToDataURL(dataURL, name) {
10
+ return dataURL.replace(';base64', `;name=${encodeURIComponent(name)};base64`);
11
+ }
12
+ /** Returns a promise that will read the file from the browser and return it as the result of the promise.
13
+ *
14
+ * @param file - The `File` information to read
15
+ * @returns - A promise that resolves to the read file.
16
+ */
17
+ function processFile(file) {
18
+ const { name, size, type } = file;
19
+ return new Promise((resolve, reject) => {
20
+ const reader = new window.FileReader();
21
+ reader.onerror = reject;
22
+ reader.onload = (event) => {
23
+ var _a;
24
+ if (typeof ((_a = event.target) === null || _a === void 0 ? void 0 : _a.result) === 'string') {
25
+ resolve({
26
+ dataURL: addNameToDataURL(event.target.result, name),
27
+ name,
28
+ size,
29
+ type,
30
+ });
31
+ }
32
+ else {
33
+ resolve({
34
+ dataURL: null,
35
+ name,
36
+ size,
37
+ type,
38
+ });
39
+ }
40
+ };
41
+ reader.readAsDataURL(file);
42
+ });
43
+ }
44
+ /** Reads a list of files from the browser, returning the results of the promises of each individual file read.
45
+ *
46
+ * @param files - The list of files to read
47
+ * @returns - The list of read files
48
+ */
49
+ function processFiles(files) {
50
+ return Promise.all(Array.from(files).map(processFile));
51
+ }
52
+ /** Extracts the file information from the data URLs
53
+ *
54
+ * @param dataURLs - The information about the files
55
+ * @returns - The list of `FileInfoType` objects extracted from the data urls
56
+ */
57
+ function extractFileInfo(dataURLs) {
58
+ return dataURLs.reduce((acc, dataURL) => {
59
+ if (!dataURL) {
60
+ return acc;
61
+ }
62
+ try {
63
+ const { blob, name } = dataURItoBlob(dataURL);
64
+ return [
65
+ ...acc,
66
+ {
67
+ dataURL,
68
+ name: name,
69
+ size: blob.size,
70
+ type: blob.type,
71
+ },
72
+ ];
73
+ }
74
+ catch (_a) {
75
+ // Invalid dataURI, so just ignore it.
76
+ return acc;
77
+ }
78
+ }, []);
79
+ }
80
+ /** Hook which encapsulates the logic needed to read and convert a `value` of `File` or `File[]` into the
81
+ * `filesInfo: FileInfoType[]` and the two callback implementations needed to change the list or to remove a
82
+ * `File` from the list. To be used by theme specific `FileWidget` implementations.
83
+ *
84
+ * @param value - The current value of the `FileWidget`
85
+ * @param onChange - The onChange handler for the `FileWidget`
86
+ * @param [multiple=false] - Flag indicating whether the control supports multiple selections
87
+ * @returns - The `UseFileWidgetPropsResult` to be used within a `FileWidget` implementation
88
+ */
89
+ export default function useFileWidgetProps(value, onChange, multiple = false) {
90
+ const values = useMemo(() => {
91
+ if (multiple && value) {
92
+ return Array.isArray(value) ? value : [value];
93
+ }
94
+ return [];
95
+ }, [value, multiple]);
96
+ const filesInfo = useMemo(() => (Array.isArray(value) ? extractFileInfo(value) : extractFileInfo([value || ''])), [value]);
97
+ const handleChange = useCallback((files) => {
98
+ processFiles(files).then((filesInfoEvent) => {
99
+ const newValue = filesInfoEvent.map((fileInfo) => fileInfo.dataURL || null);
100
+ if (multiple) {
101
+ onChange(values.concat(...newValue));
102
+ }
103
+ else {
104
+ onChange(newValue[0]);
105
+ }
106
+ });
107
+ }, [values, multiple, onChange]);
108
+ const handleRemove = useCallback((index) => {
109
+ if (multiple) {
110
+ const newValue = values.filter((_, i) => i !== index);
111
+ onChange(newValue);
112
+ }
113
+ else {
114
+ onChange(undefined);
115
+ }
116
+ }, [values, multiple, onChange]);
117
+ return { filesInfo, handleChange, handleRemove };
118
+ }
119
+ //# sourceMappingURL=useFileWidgetProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFileWidgetProps.js","sourceRoot":"","sources":["../src/useFileWidgetProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAuB5C;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAAe,EAAE,IAAY;IACrD,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,kBAAkB,CAAC,IAAI,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AAE,EAAE,CAAC,QAAQ,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC;YAC5E,IAAI,QAAQ,EAAE,CAAC;gBACb,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACxB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAC7B,CAAC;IACF,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,KAAa,EAAE,EAAE;QAChB,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;YAC9D,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,SAAS,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,EACD,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAC7B,CAAC;IAEF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AACnD,CAAC"}
@@ -6,6 +6,7 @@ import { ErrorSchema, ValidationData } from './types.js';
6
6
  *
7
7
  * @param validationData - The current `ValidationData` into which to merge the additional errors
8
8
  * @param [additionalErrorSchema] - The optional additional set of errors in an `ErrorSchema`
9
+ * @param [preventDuplicates=false] - Optional flag, if true, will call `mergeObjects()` with `preventDuplicates`
9
10
  * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
10
11
  */
11
- export default function validationDataMerge<T = any>(validationData: ValidationData<T>, additionalErrorSchema?: ErrorSchema<T>): ValidationData<T>;
12
+ export default function validationDataMerge<T = any>(validationData: ValidationData<T>, additionalErrorSchema?: ErrorSchema<T>, preventDuplicates?: boolean): ValidationData<T>;
@@ -8,9 +8,10 @@ import toErrorList from './toErrorList.js';
8
8
  *
9
9
  * @param validationData - The current `ValidationData` into which to merge the additional errors
10
10
  * @param [additionalErrorSchema] - The optional additional set of errors in an `ErrorSchema`
11
+ * @param [preventDuplicates=false] - Optional flag, if true, will call `mergeObjects()` with `preventDuplicates`
11
12
  * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
12
13
  */
13
- export default function validationDataMerge(validationData, additionalErrorSchema) {
14
+ export default function validationDataMerge(validationData, additionalErrorSchema, preventDuplicates = false) {
14
15
  if (!additionalErrorSchema) {
15
16
  return validationData;
16
17
  }
@@ -18,7 +19,7 @@ export default function validationDataMerge(validationData, additionalErrorSchem
18
19
  let errors = toErrorList(additionalErrorSchema);
19
20
  let errorSchema = additionalErrorSchema;
20
21
  if (!isEmpty(oldErrorSchema)) {
21
- errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
22
+ errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, preventDuplicates ? 'preventDuplicates' : true);
22
23
  errors = [...oldErrors].concat(errors);
23
24
  }
24
25
  return { errorSchema, errors };
@@ -1 +1 @@
1
- {"version":3,"file":"validationDataMerge.js","sourceRoot":"","sources":["../src/validationDataMerge.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,WAAW,MAAM,eAAe,CAAC;AAGxC;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,cAAiC,EACjC,qBAAsC;IAEtC,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,cAAc,CAAC;IAC1E,IAAI,MAAM,GAAG,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAChD,IAAI,WAAW,GAAG,qBAAqB,CAAC;IACxC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAC7B,WAAW,GAAG,YAAY,CAAC,cAAc,EAAE,qBAAqB,EAAE,IAAI,CAAmB,CAAC;QAC1F,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACjC,CAAC"}
1
+ {"version":3,"file":"validationDataMerge.js","sourceRoot":"","sources":["../src/validationDataMerge.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,WAAW,MAAM,eAAe,CAAC;AAGxC;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,cAAiC,EACjC,qBAAsC,EACtC,iBAAiB,GAAG,KAAK;IAEzB,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,cAAc,CAAC;IAC1E,IAAI,MAAM,GAAG,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAChD,IAAI,WAAW,GAAG,qBAAqB,CAAC;IACxC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAC7B,WAAW,GAAG,YAAY,CACxB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,IAAI,CAC7B,CAAC;QACpB,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/utils",
3
- "version": "6.0.0-beta.9",
3
+ "version": "6.0.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -9,27 +9,27 @@
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./lib/index.d.ts",
12
- "require": "./dist/index.js",
12
+ "require": "./dist/index.cjs",
13
13
  "import": "./lib/index.js"
14
14
  },
15
15
  "./lib": {
16
16
  "types": "./lib/index.d.ts",
17
- "require": "./dist/index.js",
17
+ "require": "./dist/index.cjs",
18
18
  "import": "./lib/index.js"
19
19
  },
20
20
  "./lib/*.js": {
21
21
  "types": "./lib/*.d.ts",
22
- "require": "./dist/*.js",
22
+ "require": "./dist/*.cjs",
23
23
  "import": "./lib/*.js"
24
24
  },
25
25
  "./dist": {
26
26
  "types": "./lib/index.d.ts",
27
- "require": "./dist/index.js",
27
+ "require": "./dist/index.cjs",
28
28
  "import": "./lib/index.js"
29
29
  },
30
- "./dist/*.js": {
30
+ "./dist/*.cjs": {
31
31
  "types": "./lib/*.d.ts",
32
- "require": "./dist/*.js",
32
+ "require": "./dist/*.cjs",
33
33
  "import": "./lib/*.js"
34
34
  }
35
35
  },
@@ -45,7 +45,7 @@
45
45
  "scripts": {
46
46
  "compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs",
47
47
  "build:ts": "npm run compileReplacer && rimraf ./lib && tsc -b tsconfig.build.json && tsc-alias -p tsconfig.build.json",
48
- "build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.js --sourcemap --packages=external --format=cjs",
48
+ "build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.cjs --sourcemap --packages=external --format=cjs",
49
49
  "build:esm": "esbuild ./src/index.ts --bundle --outfile=dist/utils.esm.js --sourcemap --packages=external --format=esm",
50
50
  "build:umd": "rollup dist/utils.esm.js --format=umd --file=dist/utils.umd.js --name=@rjsf/utils",
51
51
  "build": "npm run build:ts && npm run build:cjs && npm run build:esm && npm run build:umd",
@@ -65,20 +65,19 @@
65
65
  "react": ">=18"
66
66
  },
67
67
  "dependencies": {
68
- "fast-uri": "^3.0.6",
68
+ "fast-uri": "^3.1.0",
69
69
  "json-schema-merge-allof": "^0.8.1",
70
70
  "jsonpointer": "^5.0.1",
71
71
  "lodash": "^4.17.21",
72
72
  "lodash-es": "^4.17.21",
73
- "nanoid": "^5.1.5",
74
- "react-is": "^18.2.0"
73
+ "react-is": "^18.3.1"
75
74
  },
76
75
  "devDependencies": {
77
76
  "@types/json-schema": "^7.0.15",
78
77
  "@types/json-schema-merge-allof": "^0.6.5",
79
- "@types/react-is": "^18.2.4",
80
- "deep-freeze-es6": "^1.4.1",
81
- "eslint": "^8.56.0"
78
+ "@types/react-is": "^18.3.1",
79
+ "deep-freeze-es6": "^4.0.1",
80
+ "eslint": "^8.57.1"
82
81
  },
83
82
  "publishConfig": {
84
83
  "access": "public"
@@ -3,13 +3,13 @@ import get from 'lodash/get';
3
3
  import set from 'lodash/set';
4
4
  import setWith from 'lodash/setWith';
5
5
 
6
- import { ErrorSchema } from './types';
6
+ import { ErrorSchema, FieldPathList } from './types';
7
7
  import { ERRORS_KEY } from './constants';
8
8
 
9
9
  /** Represents the type of the path which can be a string of dotted path values or a list of string or numbers where
10
10
  * numbers represent array indexes/
11
11
  */
12
- export type PathType = string | (string | number)[];
12
+ export type PathType = string | FieldPathList;
13
13
 
14
14
  /** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
15
15
  * designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
package/src/constants.ts CHANGED
@@ -26,6 +26,8 @@ export const REQUIRED_KEY = 'required';
26
26
  export const SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
27
27
  export const REF_KEY = '$ref';
28
28
  export const SCHEMA_KEY = '$schema';
29
+ export const DEFAULT_ID_PREFIX = 'root';
30
+ export const DEFAULT_ID_SEPARATOR = '_';
29
31
  /** The path of the discriminator value returned by the schema endpoint.
30
32
  * The discriminator is the value in a `oneOf` that determines which option is selected.
31
33
  */
@@ -46,4 +48,5 @@ export const UI_GLOBAL_OPTIONS_KEY = 'ui:globalOptions';
46
48
 
47
49
  /** The JSON Schema version strings
48
50
  */
51
+ export const JSON_SCHEMA_DRAFT_2019_09 = 'https://json-schema.org/draft/2019-09/schema';
49
52
  export const JSON_SCHEMA_DRAFT_2020_12 = 'https://json-schema.org/draft/2020-12/schema';
@@ -5,7 +5,6 @@ import {
5
5
  FormContextType,
6
6
  FoundFieldType,
7
7
  GlobalUISchemaOptions,
8
- IdSchema,
9
8
  PathSchema,
10
9
  RJSFSchema,
11
10
  SchemaUtilsType,
@@ -26,9 +25,11 @@ import {
26
25
  isSelect,
27
26
  retrieveSchema,
28
27
  sanitizeDataForNewSchema,
29
- toIdSchema,
30
28
  toPathSchema,
31
29
  } from './schema';
30
+ import { makeAllReferencesAbsolute } from './findSchemaDefinition';
31
+ import { ID_KEY, JSON_SCHEMA_DRAFT_2020_12, SCHEMA_KEY } from './constants';
32
+ import get from 'lodash/get';
32
33
 
33
34
  /** The `SchemaUtils` class provides a wrapper around the publicly exported APIs in the `utils/schema` directory such
34
35
  * that one does not have to explicitly pass the `validator`, `rootSchema`, `experimental_defaultFormStateBehavior` or
@@ -57,12 +58,24 @@ class SchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
57
58
  experimental_defaultFormStateBehavior: Experimental_DefaultFormStateBehavior,
58
59
  experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
59
60
  ) {
60
- this.rootSchema = rootSchema;
61
+ if (rootSchema && rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
62
+ this.rootSchema = makeAllReferencesAbsolute(rootSchema, get(rootSchema, ID_KEY, '#'));
63
+ } else {
64
+ this.rootSchema = rootSchema;
65
+ }
61
66
  this.validator = validator;
62
67
  this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
63
68
  this.experimental_customMergeAllOf = experimental_customMergeAllOf;
64
69
  }
65
70
 
71
+ /** Returns the `rootSchema` in the `SchemaUtilsType`
72
+ *
73
+ * @returns - The `rootSchema`
74
+ */
75
+ getRootSchema() {
76
+ return this.rootSchema;
77
+ }
78
+
66
79
  /** Returns the `ValidatorType` in the `SchemaUtilsType`
67
80
  *
68
81
  * @returns - The `ValidatorType`
@@ -87,9 +100,12 @@ class SchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
87
100
  experimental_defaultFormStateBehavior = {},
88
101
  experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
89
102
  ): boolean {
103
+ // If either validator or rootSchema are falsy, return false to prevent the creation
104
+ // of a new SchemaUtilsType with incomplete properties.
90
105
  if (!validator || !rootSchema) {
91
106
  return false;
92
107
  }
108
+
93
109
  return (
94
110
  this.validator !== validator ||
95
111
  !deepEquals(this.rootSchema, rootSchema) ||
@@ -149,12 +165,14 @@ class SchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
149
165
  * @param [includeUndefinedValues=false] - Optional flag, if true, cause undefined values to be added as defaults.
150
166
  * If "excludeObjectChildren", pass `includeUndefinedValues` as false when computing defaults for any nested
151
167
  * object properties.
168
+ * @param initialDefaultsGenerated - Indicates whether or not initial defaults have been generated
152
169
  * @returns - The resulting `formData` with all the defaults provided
153
170
  */
154
171
  getDefaultFormState(
155
172
  schema: S,
156
173
  formData?: T,
157
174
  includeUndefinedValues: boolean | 'excludeObjectChildren' = false,
175
+ initialDefaultsGenerated?: boolean,
158
176
  ): T | T[] | undefined {
159
177
  return getDefaultFormState<T, S, F>(
160
178
  this.validator,
@@ -164,6 +182,7 @@ class SchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
164
182
  includeUndefinedValues,
165
183
  this.experimental_defaultFormStateBehavior,
166
184
  this.experimental_customMergeAllOf,
185
+ initialDefaultsGenerated,
167
186
  );
168
187
  }
169
188
 
@@ -285,15 +304,17 @@ class SchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
285
304
  *
286
305
  * @param schema - The schema for which retrieving a schema is desired
287
306
  * @param [rawFormData] - The current formData, if any, to assist retrieving a schema
307
+ * @param [resolveAnyOfOrOneOfRefs] - Optional flag indicating whether to resolved refs in anyOf/oneOf lists
288
308
  * @returns - The schema having its conditions, additional properties, references and dependencies resolved
289
309
  */
290
- retrieveSchema(schema: S, rawFormData?: T) {
310
+ retrieveSchema(schema: S, rawFormData?: T, resolveAnyOfOrOneOfRefs?: boolean) {
291
311
  return retrieveSchema<T, S, F>(
292
312
  this.validator,
293
313
  schema,
294
314
  this.rootSchema,
295
315
  rawFormData,
296
316
  this.experimental_customMergeAllOf,
317
+ resolveAnyOfOrOneOfRefs,
297
318
  );
298
319
  }
299
320
 
@@ -319,28 +340,6 @@ class SchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
319
340
  );
320
341
  }
321
342
 
322
- /** Generates an `IdSchema` object for the `schema`, recursively
323
- *
324
- * @param schema - The schema for which the display label flag is desired
325
- * @param [id] - The base id for the schema
326
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
327
- * @param [idPrefix='root'] - The prefix to use for the id
328
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
329
- * @returns - The `IdSchema` object for the `schema`
330
- */
331
- toIdSchema(schema: S, id?: string | null, formData?: T, idPrefix = 'root', idSeparator = '_'): IdSchema<T> {
332
- return toIdSchema<T, S, F>(
333
- this.validator,
334
- schema,
335
- id,
336
- this.rootSchema,
337
- formData,
338
- idPrefix,
339
- idSeparator,
340
- this.experimental_customMergeAllOf,
341
- );
342
- }
343
-
344
343
  /** Generates an `PathSchema` object for the `schema`, recursively
345
344
  *
346
345
  * @param schema - The schema for which the display label flag is desired
package/src/enums.ts CHANGED
@@ -45,6 +45,16 @@ export enum TranslatableString {
45
45
  DecrementAriaLabel = 'Decrease value by 1',
46
46
  /** Increment button aria label, used by UpDownWidget */
47
47
  IncrementAriaLabel = 'Increase value by 1',
48
+ /** The label for the Add button in for an optional object field */
49
+ OptionalObjectAdd = 'Add data for optional field',
50
+ /** The label for the Remove button in for an optional object field */
51
+ OptionalObjectRemove = 'Remove data for optional field',
52
+ /** The label for when displaying a non-editable form with missing optional field data */
53
+ OptionalObjectEmptyMsg = 'No data for optional field',
54
+ /** Label for the schema type selector, used by FallbackField */
55
+ Type = 'Type',
56
+ /** Label for the 'value' field, used by FallbackField */
57
+ Value = 'Value',
48
58
  // Strings with replaceable parameters
49
59
  /** Unknown field type reason, where %1 will be replaced with the type as provided by SchemaField */
50
60
  UnknownFieldType = 'Unknown field type %1',
@@ -63,7 +73,7 @@ export enum TranslatableString {
63
73
  InvalidObjectField = 'Invalid "%1" object field configuration: _%2_.',
64
74
  /** Unsupported field schema, used by UnsupportedField */
65
75
  UnsupportedField = 'Unsupported field schema.',
66
- /** Unsupported field schema, where %1 will be replaced by the idSchema.$id as provided by UnsupportedField.
76
+ /** Unsupported field schema, where %1 will be replaced by the FieldPathId.$id as provided by UnsupportedField.
67
77
  * NOTE: Use markdown notation rather than html tags.
68
78
  */
69
79
  UnsupportedFieldWithId = 'Unsupported field schema for field `%1`.',
@@ -71,8 +81,8 @@ export enum TranslatableString {
71
81
  * NOTE: Use markdown notation rather than html tags.
72
82
  */
73
83
  UnsupportedFieldWithReason = 'Unsupported field schema: _%1_.',
74
- /** Unsupported field schema, where %1 and %2 will be replaced by the idSchema.$id and reason strings, respectively,
75
- * as provided by UnsupportedField.
84
+ /** Unsupported field schema, where %1 and %2 will be replaced by the FieldPathId.$id and reason strings,
85
+ * respectively, as provided by UnsupportedField.
76
86
  * NOTE: Use markdown notation rather than html tags.
77
87
  */
78
88
  UnsupportedFieldWithIdAndReason = 'Unsupported field schema for field `%1`: _%2_.',