@rjsf/utils 6.0.0-beta.14 → 6.0.0-beta.16
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/{index.js → index.cjs} +10 -9
- package/dist/index.cjs.map +7 -0
- package/dist/utils.esm.js +9 -8
- package/dist/utils.esm.js.map +2 -2
- package/dist/utils.umd.js +12 -11
- package/lib/getTestIds.js +2 -2
- package/lib/getTestIds.js.map +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.js +1 -1
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/schema/getDefaultFormState.js +1 -1
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +4 -16
- package/package.json +9 -10
- package/src/getTestIds.ts +2 -2
- package/src/getWidget.tsx +3 -3
- package/src/mergeDefaultsWithFormData.ts +1 -1
- package/src/schema/getDefaultFormState.ts +1 -1
- package/src/types.ts +4 -16
- package/dist/index.js.map +0 -7
package/lib/types.d.ts
CHANGED
|
@@ -212,8 +212,6 @@ export type ErrorListProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
212
212
|
errorSchema: ErrorSchema<T>;
|
|
213
213
|
/** An array of the errors */
|
|
214
214
|
errors: RJSFValidationError[];
|
|
215
|
-
/** The `formContext` object that was passed to `Form` */
|
|
216
|
-
formContext?: F;
|
|
217
215
|
};
|
|
218
216
|
/** The properties that are passed to an `FieldErrorTemplate` implementation */
|
|
219
217
|
export type FieldErrorProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
|
|
@@ -363,7 +361,7 @@ export interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
363
361
|
/** The component update strategy used by the Form and its fields for performance optimization */
|
|
364
362
|
experimental_componentUpdateStrategy?: 'customDeep' | 'shallow' | 'always';
|
|
365
363
|
}
|
|
366
|
-
/** The properties that are passed to a Field implementation */
|
|
364
|
+
/** The properties that are passed to a `Field` implementation */
|
|
367
365
|
export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, RJSFBaseProps<T, S, F>, Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
|
|
368
366
|
/** The tree of unique ids for every child field */
|
|
369
367
|
idSchema: IdSchema<T>;
|
|
@@ -379,8 +377,6 @@ export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
379
377
|
onBlur: (id: string, value: any) => void;
|
|
380
378
|
/** The input focus event handler; call it with the field id and value */
|
|
381
379
|
onFocus: (id: string, value: any) => void;
|
|
382
|
-
/** The `formContext` object that you passed to `Form` */
|
|
383
|
-
formContext?: F;
|
|
384
380
|
/** A boolean value stating if the field should autofocus */
|
|
385
381
|
autofocus?: boolean;
|
|
386
382
|
/** A boolean value stating if the field is disabled */
|
|
@@ -409,7 +405,7 @@ export type Field<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
409
405
|
/** The optional TEST_IDS block that some fields contain, exported for testing purposes */
|
|
410
406
|
TEST_IDS?: TestIdShape;
|
|
411
407
|
};
|
|
412
|
-
/** The properties that are passed to a FieldTemplate implementation */
|
|
408
|
+
/** The properties that are passed to a `FieldTemplate` implementation */
|
|
413
409
|
export type FieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
|
|
414
410
|
/** The id of the field in the hierarchy. You can use it to render a label targeting the wrapped widget */
|
|
415
411
|
id: string;
|
|
@@ -451,8 +447,6 @@ export type FieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
451
447
|
* you don't want to clutter the UI
|
|
452
448
|
*/
|
|
453
449
|
displayLabel?: boolean;
|
|
454
|
-
/** The `formContext` object that was passed to `Form` */
|
|
455
|
-
formContext?: F;
|
|
456
450
|
/** The formData for this field */
|
|
457
451
|
formData?: T;
|
|
458
452
|
/** The value change event handler; Can be called with a new value to change the value for this field */
|
|
@@ -559,7 +553,7 @@ export type ArrayFieldItemTemplateType<T = any, S extends StrictRJSFSchema = RJS
|
|
|
559
553
|
* @deprecated - Use `ArrayFieldItemTemplateType` instead
|
|
560
554
|
*/
|
|
561
555
|
export type ArrayFieldTemplateItemType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = ArrayFieldItemTemplateType<T, S, F>;
|
|
562
|
-
/** The properties that are passed to an ArrayFieldTemplate implementation */
|
|
556
|
+
/** The properties that are passed to an `ArrayFieldTemplate` implementation */
|
|
563
557
|
export type ArrayFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
|
|
564
558
|
/** A boolean value stating whether new elements can be added to the array */
|
|
565
559
|
canAdd?: boolean;
|
|
@@ -581,8 +575,6 @@ export type ArrayFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
581
575
|
hideError?: boolean;
|
|
582
576
|
/** A string value containing the title for the array */
|
|
583
577
|
title: string;
|
|
584
|
-
/** The `formContext` object that was passed to Form */
|
|
585
|
-
formContext?: F;
|
|
586
578
|
/** The formData for this array */
|
|
587
579
|
formData?: T;
|
|
588
580
|
/** The tree of errors for this field and its children */
|
|
@@ -627,8 +619,6 @@ export type ObjectFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
627
619
|
errorSchema?: ErrorSchema<T>;
|
|
628
620
|
/** The form data for the object */
|
|
629
621
|
formData?: T;
|
|
630
|
-
/** The `formContext` object that was passed to Form */
|
|
631
|
-
formContext?: F;
|
|
632
622
|
};
|
|
633
623
|
/** The properties that are passed to a WrapIfAdditionalTemplate implementation */
|
|
634
624
|
export type WrapIfAdditionalTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
|
|
@@ -642,7 +632,7 @@ export interface MultiSchemaFieldTemplateProps<T = any, S extends StrictRJSFSche
|
|
|
642
632
|
/** The rendered SchemaField for the selected schema option */
|
|
643
633
|
optionSchemaField: ReactNode;
|
|
644
634
|
}
|
|
645
|
-
/** The properties that are passed to a Widget implementation */
|
|
635
|
+
/** The properties that are passed to a `Widget` implementation */
|
|
646
636
|
export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, RJSFBaseProps<T, S, F>, Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
|
|
647
637
|
/** The generated id for this widget, used to provide unique `name`s and `id`s for the HTML field elements rendered by
|
|
648
638
|
* widgets
|
|
@@ -673,8 +663,6 @@ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
673
663
|
/** The enum options list for a type that supports them */
|
|
674
664
|
enumOptions?: EnumOptionsType<S>[];
|
|
675
665
|
};
|
|
676
|
-
/** The `formContext` object that you passed to `Form` */
|
|
677
|
-
formContext?: F;
|
|
678
666
|
/** The input blur event handler; call it with the widget id and value */
|
|
679
667
|
onBlur: (id: string, value: any) => void;
|
|
680
668
|
/** The value change event handler; call it with the new value every time it changes */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/utils",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.16",
|
|
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.
|
|
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.
|
|
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/*.
|
|
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.
|
|
27
|
+
"require": "./dist/index.cjs",
|
|
28
28
|
"import": "./lib/index.js"
|
|
29
29
|
},
|
|
30
|
-
"./dist/*.
|
|
30
|
+
"./dist/*.cjs": {
|
|
31
31
|
"types": "./lib/*.d.ts",
|
|
32
|
-
"require": "./dist/*.
|
|
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.
|
|
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,12 +65,11 @@
|
|
|
65
65
|
"react": ">=18"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"fast-uri": "^3.0
|
|
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
73
|
"react-is": "^18.3.1"
|
|
75
74
|
},
|
|
76
75
|
"devDependencies": {
|
package/src/getTestIds.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { nanoid } from 'nanoid';
|
|
2
1
|
import get from 'lodash/get';
|
|
2
|
+
import uniqueId from 'lodash/uniqueId';
|
|
3
3
|
|
|
4
4
|
import { TestIdShape } from './types';
|
|
5
5
|
|
|
@@ -31,7 +31,7 @@ export default function getTestIds(): TestIdShape {
|
|
|
31
31
|
{
|
|
32
32
|
get(_obj, prop) {
|
|
33
33
|
if (!ids.has(prop)) {
|
|
34
|
-
ids.set(prop,
|
|
34
|
+
ids.set(prop, uniqueId('test-id-'));
|
|
35
35
|
}
|
|
36
36
|
return ids.get(prop);
|
|
37
37
|
},
|
package/src/getWidget.tsx
CHANGED
|
@@ -110,7 +110,7 @@ export default function getWidget<T = any, S extends StrictRJSFSchema = RJSFSche
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
if (typeof widget !== 'string') {
|
|
113
|
-
throw new Error(`Unsupported widget definition: ${typeof widget}`);
|
|
113
|
+
throw new Error(`Unsupported widget definition: ${typeof widget} in schema: ${JSON.stringify(schema)}`);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
if (widget in registeredWidgets) {
|
|
@@ -120,7 +120,7 @@ export default function getWidget<T = any, S extends StrictRJSFSchema = RJSFSche
|
|
|
120
120
|
|
|
121
121
|
if (typeof type === 'string') {
|
|
122
122
|
if (!(type in widgetMap)) {
|
|
123
|
-
throw new Error(`No widget for type '${type}'`);
|
|
123
|
+
throw new Error(`No widget for type '${type}' in schema: ${JSON.stringify(schema)}`);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
if (widget in widgetMap[type]) {
|
|
@@ -129,5 +129,5 @@ export default function getWidget<T = any, S extends StrictRJSFSchema = RJSFSche
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
throw new Error(`No widget '${widget}' for type '${type}'`);
|
|
132
|
+
throw new Error(`No widget '${widget}' for type '${type}' in schema: ${JSON.stringify(schema)}`);
|
|
133
133
|
}
|
|
@@ -102,7 +102,7 @@ export default function mergeDefaultsWithFormData<T = any>(
|
|
|
102
102
|
*/
|
|
103
103
|
if (
|
|
104
104
|
(defaultSupercedesUndefined &&
|
|
105
|
-
((!
|
|
105
|
+
((!(defaults === undefined) && isNil(formData)) || (typeof formData === 'number' && isNaN(formData)))) ||
|
|
106
106
|
(overrideFormDataWithDefaults && !isNil(formData))
|
|
107
107
|
) {
|
|
108
108
|
return defaults;
|
|
@@ -650,7 +650,7 @@ export function getArrayDefaults<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
650
650
|
const fillerDefault = fillerSchema.default;
|
|
651
651
|
|
|
652
652
|
// Calculate filler entries for remaining items (minItems - existing raw data/defaults)
|
|
653
|
-
const fillerEntries: T[] =
|
|
653
|
+
const fillerEntries: T[] = Array.from({ length: schema.minItems - defaultsLength }, () =>
|
|
654
654
|
computeDefaults<any, S, F>(validator, fillerSchema, {
|
|
655
655
|
parentDefaults: fillerDefault,
|
|
656
656
|
rootSchema,
|
package/src/types.ts
CHANGED
|
@@ -263,8 +263,6 @@ export type ErrorListProps<
|
|
|
263
263
|
errorSchema: ErrorSchema<T>;
|
|
264
264
|
/** An array of the errors */
|
|
265
265
|
errors: RJSFValidationError[];
|
|
266
|
-
/** The `formContext` object that was passed to `Form` */
|
|
267
|
-
formContext?: F;
|
|
268
266
|
};
|
|
269
267
|
|
|
270
268
|
/** The properties that are passed to an `FieldErrorTemplate` implementation */
|
|
@@ -429,7 +427,7 @@ export interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
429
427
|
experimental_componentUpdateStrategy?: 'customDeep' | 'shallow' | 'always';
|
|
430
428
|
}
|
|
431
429
|
|
|
432
|
-
/** The properties that are passed to a Field implementation */
|
|
430
|
+
/** The properties that are passed to a `Field` implementation */
|
|
433
431
|
export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>
|
|
434
432
|
extends GenericObjectType,
|
|
435
433
|
RJSFBaseProps<T, S, F>,
|
|
@@ -448,8 +446,6 @@ export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
448
446
|
onBlur: (id: string, value: any) => void;
|
|
449
447
|
/** The input focus event handler; call it with the field id and value */
|
|
450
448
|
onFocus: (id: string, value: any) => void;
|
|
451
|
-
/** The `formContext` object that you passed to `Form` */
|
|
452
|
-
formContext?: F;
|
|
453
449
|
/** A boolean value stating if the field should autofocus */
|
|
454
450
|
autofocus?: boolean;
|
|
455
451
|
/** A boolean value stating if the field is disabled */
|
|
@@ -482,7 +478,7 @@ export type Field<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
|
|
|
482
478
|
TEST_IDS?: TestIdShape;
|
|
483
479
|
};
|
|
484
480
|
|
|
485
|
-
/** The properties that are passed to a FieldTemplate implementation */
|
|
481
|
+
/** The properties that are passed to a `FieldTemplate` implementation */
|
|
486
482
|
export type FieldTemplateProps<
|
|
487
483
|
T = any,
|
|
488
484
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
@@ -528,8 +524,6 @@ export type FieldTemplateProps<
|
|
|
528
524
|
* you don't want to clutter the UI
|
|
529
525
|
*/
|
|
530
526
|
displayLabel?: boolean;
|
|
531
|
-
/** The `formContext` object that was passed to `Form` */
|
|
532
|
-
formContext?: F;
|
|
533
527
|
/** The formData for this field */
|
|
534
528
|
formData?: T;
|
|
535
529
|
/** The value change event handler; Can be called with a new value to change the value for this field */
|
|
@@ -677,7 +671,7 @@ export type ArrayFieldTemplateItemType<
|
|
|
677
671
|
F extends FormContextType = any,
|
|
678
672
|
> = ArrayFieldItemTemplateType<T, S, F>;
|
|
679
673
|
|
|
680
|
-
/** The properties that are passed to an ArrayFieldTemplate implementation */
|
|
674
|
+
/** The properties that are passed to an `ArrayFieldTemplate` implementation */
|
|
681
675
|
export type ArrayFieldTemplateProps<
|
|
682
676
|
T = any,
|
|
683
677
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
@@ -703,8 +697,6 @@ export type ArrayFieldTemplateProps<
|
|
|
703
697
|
hideError?: boolean;
|
|
704
698
|
/** A string value containing the title for the array */
|
|
705
699
|
title: string;
|
|
706
|
-
/** The `formContext` object that was passed to Form */
|
|
707
|
-
formContext?: F;
|
|
708
700
|
/** The formData for this array */
|
|
709
701
|
formData?: T;
|
|
710
702
|
/** The tree of errors for this field and its children */
|
|
@@ -755,8 +747,6 @@ export type ObjectFieldTemplateProps<
|
|
|
755
747
|
errorSchema?: ErrorSchema<T>;
|
|
756
748
|
/** The form data for the object */
|
|
757
749
|
formData?: T;
|
|
758
|
-
/** The `formContext` object that was passed to Form */
|
|
759
|
-
formContext?: F;
|
|
760
750
|
};
|
|
761
751
|
|
|
762
752
|
/** The properties that are passed to a WrapIfAdditionalTemplate implementation */
|
|
@@ -797,7 +787,7 @@ export interface MultiSchemaFieldTemplateProps<
|
|
|
797
787
|
optionSchemaField: ReactNode;
|
|
798
788
|
}
|
|
799
789
|
|
|
800
|
-
/** The properties that are passed to a Widget implementation */
|
|
790
|
+
/** The properties that are passed to a `Widget` implementation */
|
|
801
791
|
export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>
|
|
802
792
|
extends GenericObjectType,
|
|
803
793
|
RJSFBaseProps<T, S, F>,
|
|
@@ -831,8 +821,6 @@ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
831
821
|
/** The enum options list for a type that supports them */
|
|
832
822
|
enumOptions?: EnumOptionsType<S>[];
|
|
833
823
|
};
|
|
834
|
-
/** The `formContext` object that you passed to `Form` */
|
|
835
|
-
formContext?: F;
|
|
836
824
|
/** The input blur event handler; call it with the widget id and value */
|
|
837
825
|
onBlur: (id: string, value: any) => void;
|
|
838
826
|
/** The value change event handler; call it with the new value every time it changes */
|