@rjsf/utils 6.0.0-beta.2 → 6.0.0-beta.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.
Files changed (79) hide show
  1. package/dist/{index.js → index.cjs} +241 -205
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/utils.esm.js +240 -204
  4. package/dist/utils.esm.js.map +4 -4
  5. package/dist/utils.umd.js +235 -200
  6. package/lib/canExpand.d.ts +1 -1
  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 +19 -14
  11. package/lib/createSchemaUtils.js.map +1 -1
  12. package/lib/enums.d.ts +3 -3
  13. package/lib/enums.js +3 -3
  14. package/lib/findSchemaDefinition.d.ts +7 -1
  15. package/lib/findSchemaDefinition.js +48 -6
  16. package/lib/findSchemaDefinition.js.map +1 -1
  17. package/lib/getTestIds.js +2 -2
  18. package/lib/getTestIds.js.map +1 -1
  19. package/lib/getUiOptions.js +4 -0
  20. package/lib/getUiOptions.js.map +1 -1
  21. package/lib/getWidget.js +3 -3
  22. package/lib/getWidget.js.map +1 -1
  23. package/lib/idGenerators.d.ts +15 -15
  24. package/lib/idGenerators.js +8 -8
  25. package/lib/idGenerators.js.map +1 -1
  26. package/lib/index.d.ts +4 -1
  27. package/lib/index.js +3 -1
  28. package/lib/index.js.map +1 -1
  29. package/lib/mergeDefaultsWithFormData.js +14 -2
  30. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  31. package/lib/schema/findFieldInSchema.d.ts +1 -1
  32. package/lib/schema/findFieldInSchema.js +1 -1
  33. package/lib/schema/getDefaultFormState.d.ts +11 -2
  34. package/lib/schema/getDefaultFormState.js +59 -22
  35. package/lib/schema/getDefaultFormState.js.map +1 -1
  36. package/lib/schema/getDisplayLabel.js +2 -2
  37. package/lib/schema/getDisplayLabel.js.map +1 -1
  38. package/lib/schema/index.d.ts +1 -2
  39. package/lib/schema/index.js +1 -2
  40. package/lib/schema/index.js.map +1 -1
  41. package/lib/schema/retrieveSchema.d.ts +1 -1
  42. package/lib/schema/retrieveSchema.js +6 -6
  43. package/lib/schema/retrieveSchema.js.map +1 -1
  44. package/lib/shallowEquals.d.ts +8 -0
  45. package/lib/shallowEquals.js +36 -0
  46. package/lib/shallowEquals.js.map +1 -0
  47. package/lib/shouldRender.d.ts +8 -2
  48. package/lib/shouldRender.js +17 -2
  49. package/lib/shouldRender.js.map +1 -1
  50. package/lib/toFieldPathId.d.ts +12 -0
  51. package/lib/toFieldPathId.js +19 -0
  52. package/lib/toFieldPathId.js.map +1 -0
  53. package/lib/tsconfig.tsbuildinfo +1 -1
  54. package/lib/types.d.ts +97 -66
  55. package/package.json +13 -14
  56. package/src/constants.ts +3 -0
  57. package/src/createSchemaUtils.ts +19 -25
  58. package/src/enums.ts +3 -3
  59. package/src/findSchemaDefinition.ts +55 -6
  60. package/src/getTestIds.ts +2 -2
  61. package/src/getUiOptions.ts +4 -0
  62. package/src/getWidget.tsx +3 -3
  63. package/src/idGenerators.ts +25 -25
  64. package/src/index.ts +6 -0
  65. package/src/mergeDefaultsWithFormData.ts +16 -2
  66. package/src/schema/findFieldInSchema.ts +1 -1
  67. package/src/schema/getDefaultFormState.ts +76 -32
  68. package/src/schema/getDisplayLabel.ts +2 -2
  69. package/src/schema/index.ts +0 -2
  70. package/src/schema/retrieveSchema.ts +7 -5
  71. package/src/shallowEquals.ts +41 -0
  72. package/src/shouldRender.ts +27 -2
  73. package/src/toFieldPathId.ts +24 -0
  74. package/src/types.ts +107 -70
  75. package/dist/index.js.map +0 -7
  76. package/lib/schema/toIdSchema.d.ts +0 -14
  77. package/lib/schema/toIdSchema.js +0 -62
  78. package/lib/schema/toIdSchema.js.map +0 -1
  79. package/src/schema/toIdSchema.ts +0 -131
@@ -1,10 +1,16 @@
1
1
  import React from 'react';
2
+ /** The supported component update strategies */
3
+ export type ComponentUpdateStrategy = 'customDeep' | 'shallow' | 'always';
2
4
  /** Determines whether the given `component` should be rerendered by comparing its current set of props and state
3
- * against the next set. If either of those two sets are not the same, then the component should be rerendered.
5
+ * against the next set. The comparison strategy can be controlled via the `updateStrategy` parameter.
4
6
  *
5
7
  * @param component - A React component being checked
6
8
  * @param nextProps - The next set of props against which to check
7
9
  * @param nextState - The next set of state against which to check
10
+ * @param updateStrategy - The strategy to use for comparison:
11
+ * - 'customDeep': Uses RJSF's custom deep equality checks (default)
12
+ * - 'shallow': Uses shallow comparison of props and state
13
+ * - 'always': Always returns true (React's default behavior)
8
14
  * @returns - True if the component should be re-rendered, false otherwise
9
15
  */
10
- export default function shouldRender(component: React.Component, nextProps: any, nextState: any): boolean;
16
+ export default function shouldRender(component: React.Component, nextProps: any, nextState: any, updateStrategy?: ComponentUpdateStrategy): boolean;
@@ -1,13 +1,28 @@
1
1
  import deepEquals from './deepEquals.js';
2
+ import shallowEquals from './shallowEquals.js';
2
3
  /** Determines whether the given `component` should be rerendered by comparing its current set of props and state
3
- * against the next set. If either of those two sets are not the same, then the component should be rerendered.
4
+ * against the next set. The comparison strategy can be controlled via the `updateStrategy` parameter.
4
5
  *
5
6
  * @param component - A React component being checked
6
7
  * @param nextProps - The next set of props against which to check
7
8
  * @param nextState - The next set of state against which to check
9
+ * @param updateStrategy - The strategy to use for comparison:
10
+ * - 'customDeep': Uses RJSF's custom deep equality checks (default)
11
+ * - 'shallow': Uses shallow comparison of props and state
12
+ * - 'always': Always returns true (React's default behavior)
8
13
  * @returns - True if the component should be re-rendered, false otherwise
9
14
  */
10
- export default function shouldRender(component, nextProps, nextState) {
15
+ export default function shouldRender(component, nextProps, nextState, updateStrategy = 'customDeep') {
16
+ if (updateStrategy === 'always') {
17
+ // Use React's default behavior: always update if state or props change (no shouldComponentUpdate optimization)
18
+ return true;
19
+ }
20
+ if (updateStrategy === 'shallow') {
21
+ // Use shallow comparison for props and state
22
+ const { props, state } = component;
23
+ return !shallowEquals(props, nextProps) || !shallowEquals(state, nextState);
24
+ }
25
+ // Use custom deep equality checks (default 'customDeep' strategy)
11
26
  const { props, state } = component;
12
27
  return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
13
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"shouldRender.js","sourceRoot":"","sources":["../src/shouldRender.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,SAA0B,EAAE,SAAc,EAAE,SAAc;IAC7F,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;IACnC,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACxE,CAAC"}
1
+ {"version":3,"file":"shouldRender.js","sourceRoot":"","sources":["../src/shouldRender.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAK5C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,SAA0B,EAC1B,SAAc,EACd,SAAc,EACd,iBAA0C,YAAY;IAEtD,IAAI,cAAc,KAAK,QAAQ,EAAE,CAAC;QAChC,+GAA+G;QAC/G,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QACjC,6CAA6C;QAC7C,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;QACnC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC9E,CAAC;IAED,kEAAkE;IAClE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;IACnC,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { FieldPathId, FieldPathList, GlobalFormOptions } from './types.js';
2
+ /** Constructs the `FieldPathId` for `fieldPath`. If `parentPathId` is provided, the `fieldPath` is appended to the end
3
+ * of the parent path. Then the `ID_KEY` of the resulting `FieldPathId` is constructed from the `idPrefix` and
4
+ * `idSeparator` contained within the `globalFormOptions`. If `fieldPath` is passed as an empty string, it will simply
5
+ * generate the path from the `parentPath` (if provided) and the `idPrefix` and `idSeparator`
6
+ *
7
+ * @param fieldPath - The property name or array index of the current field element
8
+ * @param globalFormOptions - The `GlobalFormOptions` used to get the `idPrefix` and `idSeparator`
9
+ * @param [parentPath] - The optional `FieldPathId` or `FieldPathList` of the parent element for this field element
10
+ * @returns - The `FieldPathId` for the given `fieldPath` and the optional `parentPathId`
11
+ */
12
+ export default function toFieldPathId(fieldPath: string | number, globalFormOptions: GlobalFormOptions, parentPath?: FieldPathId | FieldPathList): FieldPathId;
@@ -0,0 +1,19 @@
1
+ import { ID_KEY } from './constants.js';
2
+ /** Constructs the `FieldPathId` for `fieldPath`. If `parentPathId` is provided, the `fieldPath` is appended to the end
3
+ * of the parent path. Then the `ID_KEY` of the resulting `FieldPathId` is constructed from the `idPrefix` and
4
+ * `idSeparator` contained within the `globalFormOptions`. If `fieldPath` is passed as an empty string, it will simply
5
+ * generate the path from the `parentPath` (if provided) and the `idPrefix` and `idSeparator`
6
+ *
7
+ * @param fieldPath - The property name or array index of the current field element
8
+ * @param globalFormOptions - The `GlobalFormOptions` used to get the `idPrefix` and `idSeparator`
9
+ * @param [parentPath] - The optional `FieldPathId` or `FieldPathList` of the parent element for this field element
10
+ * @returns - The `FieldPathId` for the given `fieldPath` and the optional `parentPathId`
11
+ */
12
+ export default function toFieldPathId(fieldPath, globalFormOptions, parentPath) {
13
+ const basePath = Array.isArray(parentPath) ? parentPath : parentPath === null || parentPath === void 0 ? void 0 : parentPath.path;
14
+ const childPath = fieldPath === '' ? [] : [fieldPath];
15
+ const path = basePath ? basePath.concat(...childPath) : childPath;
16
+ const id = [globalFormOptions.idPrefix, ...path].join(globalFormOptions.idSeparator);
17
+ return { path, [ID_KEY]: id };
18
+ }
19
+ //# sourceMappingURL=toFieldPathId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toFieldPathId.js","sourceRoot":"","sources":["../src/toFieldPathId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,SAA0B,EAC1B,iBAAoC,EACpC,UAAwC;IAExC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,CAAC;IAC3E,MAAM,SAAS,GAAG,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,MAAM,EAAE,GAAG,CAAC,iBAAiB,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACrF,OAAO,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC;AAChC,CAAC"}