@rjsf/core 5.13.2 → 5.13.3
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/core.umd.js +47 -10
- package/dist/index.esm.js +47 -10
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +47 -10
- package/dist/index.js.map +2 -2
- package/lib/components/Form.d.ts +44 -6
- package/lib/components/Form.js +48 -11
- package/lib/components/Form.js.map +1 -1
- package/lib/components/fields/ArrayField.js +2 -2
- package/lib/components/fields/ArrayField.js.map +1 -1
- package/package.json +5 -5
- package/src/components/Form.tsx +60 -14
- package/src/components/fields/ArrayField.tsx +2 -2
package/dist/core.umd.js
CHANGED
|
@@ -636,7 +636,7 @@
|
|
|
636
636
|
const { key, item } = keyedItem;
|
|
637
637
|
const itemCast = item;
|
|
638
638
|
const additional = index >= itemSchemas.length;
|
|
639
|
-
const itemSchema = additional && isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index];
|
|
639
|
+
const itemSchema = (additional && isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index]) || {};
|
|
640
640
|
const itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
641
641
|
const itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
642
642
|
const itemUiSchema = additional ? uiSchema.additionalItems || {} : Array.isArray(uiSchema.items) ? uiSchema.items[index] : uiSchema.items || {};
|
|
@@ -3126,18 +3126,55 @@
|
|
|
3126
3126
|
}
|
|
3127
3127
|
this.formElement = react.createRef();
|
|
3128
3128
|
}
|
|
3129
|
-
/**
|
|
3130
|
-
*
|
|
3131
|
-
*
|
|
3129
|
+
/**
|
|
3130
|
+
* `getSnapshotBeforeUpdate` is a React lifecycle method that is invoked right before the most recently rendered
|
|
3131
|
+
* output is committed to the DOM. It enables your component to capture current values (e.g., scroll position) before
|
|
3132
|
+
* they are potentially changed.
|
|
3133
|
+
*
|
|
3134
|
+
* In this case, it checks if the props have changed since the last render. If they have, it computes the next state
|
|
3135
|
+
* of the component using `getStateFromProps` method and returns it along with a `shouldUpdate` flag set to `true` IF
|
|
3136
|
+
* the `nextState` and `prevState` are different, otherwise `false`. This ensures that we have the most up-to-date
|
|
3137
|
+
* state ready to be applied in `componentDidUpdate`.
|
|
3138
|
+
*
|
|
3139
|
+
* If `formData` hasn't changed, it simply returns an object with `shouldUpdate` set to `false`, indicating that a
|
|
3140
|
+
* state update is not necessary.
|
|
3141
|
+
*
|
|
3142
|
+
* @param prevProps - The previous set of props before the update.
|
|
3143
|
+
* @param prevState - The previous state before the update.
|
|
3144
|
+
* @returns Either an object containing the next state and a flag indicating that an update should occur, or an object
|
|
3145
|
+
* with a flag indicating that an update is not necessary.
|
|
3146
|
+
*/
|
|
3147
|
+
getSnapshotBeforeUpdate(prevProps, prevState) {
|
|
3148
|
+
if (!utils.deepEquals(this.props, prevProps)) {
|
|
3149
|
+
const nextState = this.getStateFromProps(this.props, this.props.formData);
|
|
3150
|
+
const shouldUpdate = !utils.deepEquals(nextState, prevState);
|
|
3151
|
+
return { nextState, shouldUpdate };
|
|
3152
|
+
}
|
|
3153
|
+
return { shouldUpdate: false };
|
|
3154
|
+
}
|
|
3155
|
+
/**
|
|
3156
|
+
* `componentDidUpdate` is a React lifecycle method that is invoked immediately after updating occurs. This method is
|
|
3157
|
+
* not called for the initial render.
|
|
3158
|
+
*
|
|
3159
|
+
* Here, it checks if an update is necessary based on the `shouldUpdate` flag received from `getSnapshotBeforeUpdate`.
|
|
3160
|
+
* If an update is required, it applies the next state and, if needed, triggers the `onChange` handler to inform about
|
|
3161
|
+
* changes.
|
|
3132
3162
|
*
|
|
3133
|
-
*
|
|
3163
|
+
* This method effectively replaces the deprecated `UNSAFE_componentWillReceiveProps`, providing a safer alternative
|
|
3164
|
+
* to handle prop changes and state updates.
|
|
3165
|
+
*
|
|
3166
|
+
* @param _ - The previous set of props.
|
|
3167
|
+
* @param prevState - The previous state of the component before the update.
|
|
3168
|
+
* @param snapshot - The value returned from `getSnapshotBeforeUpdate`.
|
|
3134
3169
|
*/
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3170
|
+
componentDidUpdate(_, prevState, snapshot) {
|
|
3171
|
+
if (snapshot.shouldUpdate) {
|
|
3172
|
+
const { nextState } = snapshot;
|
|
3173
|
+
if (!utils.deepEquals(nextState.formData, this.props.formData) && !utils.deepEquals(nextState.formData, prevState.formData) && this.props.onChange) {
|
|
3174
|
+
this.props.onChange(nextState);
|
|
3175
|
+
}
|
|
3176
|
+
this.setState(nextState);
|
|
3139
3177
|
}
|
|
3140
|
-
this.setState(nextState);
|
|
3141
3178
|
}
|
|
3142
3179
|
/** Extracts the updated state from the given `props` and `inputFormData`. As part of this process, the
|
|
3143
3180
|
* `inputFormData` is first processed to add any missing required defaults. After that, the data is run through the
|
package/dist/index.esm.js
CHANGED
|
@@ -674,7 +674,7 @@ var ArrayField = class extends Component {
|
|
|
674
674
|
const { key, item } = keyedItem;
|
|
675
675
|
const itemCast = item;
|
|
676
676
|
const additional = index >= itemSchemas.length;
|
|
677
|
-
const itemSchema = additional && isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index];
|
|
677
|
+
const itemSchema = (additional && isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index]) || {};
|
|
678
678
|
const itemIdPrefix = idSchema.$id + idSeparator + index;
|
|
679
679
|
const itemIdSchema = schemaUtils.toIdSchema(itemSchema, itemIdPrefix, itemCast, idPrefix, idSeparator);
|
|
680
680
|
const itemUiSchema = additional ? uiSchema.additionalItems || {} : Array.isArray(uiSchema.items) ? uiSchema.items[index] : uiSchema.items || {};
|
|
@@ -3472,18 +3472,55 @@ var Form = class extends Component5 {
|
|
|
3472
3472
|
}
|
|
3473
3473
|
this.formElement = createRef();
|
|
3474
3474
|
}
|
|
3475
|
-
/**
|
|
3476
|
-
*
|
|
3477
|
-
*
|
|
3475
|
+
/**
|
|
3476
|
+
* `getSnapshotBeforeUpdate` is a React lifecycle method that is invoked right before the most recently rendered
|
|
3477
|
+
* output is committed to the DOM. It enables your component to capture current values (e.g., scroll position) before
|
|
3478
|
+
* they are potentially changed.
|
|
3479
|
+
*
|
|
3480
|
+
* In this case, it checks if the props have changed since the last render. If they have, it computes the next state
|
|
3481
|
+
* of the component using `getStateFromProps` method and returns it along with a `shouldUpdate` flag set to `true` IF
|
|
3482
|
+
* the `nextState` and `prevState` are different, otherwise `false`. This ensures that we have the most up-to-date
|
|
3483
|
+
* state ready to be applied in `componentDidUpdate`.
|
|
3484
|
+
*
|
|
3485
|
+
* If `formData` hasn't changed, it simply returns an object with `shouldUpdate` set to `false`, indicating that a
|
|
3486
|
+
* state update is not necessary.
|
|
3487
|
+
*
|
|
3488
|
+
* @param prevProps - The previous set of props before the update.
|
|
3489
|
+
* @param prevState - The previous state before the update.
|
|
3490
|
+
* @returns Either an object containing the next state and a flag indicating that an update should occur, or an object
|
|
3491
|
+
* with a flag indicating that an update is not necessary.
|
|
3492
|
+
*/
|
|
3493
|
+
getSnapshotBeforeUpdate(prevProps, prevState) {
|
|
3494
|
+
if (!deepEquals3(this.props, prevProps)) {
|
|
3495
|
+
const nextState = this.getStateFromProps(this.props, this.props.formData);
|
|
3496
|
+
const shouldUpdate = !deepEquals3(nextState, prevState);
|
|
3497
|
+
return { nextState, shouldUpdate };
|
|
3498
|
+
}
|
|
3499
|
+
return { shouldUpdate: false };
|
|
3500
|
+
}
|
|
3501
|
+
/**
|
|
3502
|
+
* `componentDidUpdate` is a React lifecycle method that is invoked immediately after updating occurs. This method is
|
|
3503
|
+
* not called for the initial render.
|
|
3504
|
+
*
|
|
3505
|
+
* Here, it checks if an update is necessary based on the `shouldUpdate` flag received from `getSnapshotBeforeUpdate`.
|
|
3506
|
+
* If an update is required, it applies the next state and, if needed, triggers the `onChange` handler to inform about
|
|
3507
|
+
* changes.
|
|
3478
3508
|
*
|
|
3479
|
-
*
|
|
3509
|
+
* This method effectively replaces the deprecated `UNSAFE_componentWillReceiveProps`, providing a safer alternative
|
|
3510
|
+
* to handle prop changes and state updates.
|
|
3511
|
+
*
|
|
3512
|
+
* @param _ - The previous set of props.
|
|
3513
|
+
* @param prevState - The previous state of the component before the update.
|
|
3514
|
+
* @param snapshot - The value returned from `getSnapshotBeforeUpdate`.
|
|
3480
3515
|
*/
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3516
|
+
componentDidUpdate(_, prevState, snapshot) {
|
|
3517
|
+
if (snapshot.shouldUpdate) {
|
|
3518
|
+
const { nextState } = snapshot;
|
|
3519
|
+
if (!deepEquals3(nextState.formData, this.props.formData) && !deepEquals3(nextState.formData, prevState.formData) && this.props.onChange) {
|
|
3520
|
+
this.props.onChange(nextState);
|
|
3521
|
+
}
|
|
3522
|
+
this.setState(nextState);
|
|
3485
3523
|
}
|
|
3486
|
-
this.setState(nextState);
|
|
3487
3524
|
}
|
|
3488
3525
|
/** Extracts the updated state from the given `props` and `inputFormData`. As part of this process, the
|
|
3489
3526
|
* `inputFormData` is first processed to add any missing required defaults. After that, the data is run through the
|