@rjsf/primereact 6.4.2 → 6.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/primereact",
3
- "version": "6.4.2",
3
+ "version": "6.5.1",
4
4
  "description": "PrimeReact theme, fields and widgets for react-jsonschema-form",
5
5
  "main": "dist/index.js",
6
6
  "module": "lib/index.js",
@@ -61,17 +61,17 @@
61
61
  "node": ">=20"
62
62
  },
63
63
  "peerDependencies": {
64
- "@rjsf/core": "^6.4.x",
65
- "@rjsf/utils": "^6.4.x",
64
+ "@rjsf/core": "^6.5.x",
65
+ "@rjsf/utils": "^6.5.x",
66
66
  "primeicons": ">=6.0.0",
67
67
  "primereact": ">=8.0.0",
68
68
  "react": ">=18"
69
69
  },
70
70
  "devDependencies": {
71
- "@rjsf/core": "6.4.2",
72
- "@rjsf/snapshot-tests": "6.4.2",
73
- "@rjsf/utils": "6.4.2",
74
- "@rjsf/validator-ajv8": "6.4.2",
71
+ "@rjsf/core": "6.5.1",
72
+ "@rjsf/snapshot-tests": "6.5.1",
73
+ "@rjsf/utils": "6.5.1",
74
+ "@rjsf/validator-ajv8": "6.5.1",
75
75
  "@rollup/plugin-replace": "^6.0.3",
76
76
  "eslint": "^8.57.1",
77
77
  "primeflex": "^4.0.0",
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  ariaDescribedByIds,
3
+ enumOptionValueDecoder,
4
+ enumOptionValueEncoder,
3
5
  enumOptionsIsSelected,
4
- enumOptionsValueForIndex,
6
+ getOptionValueFormat,
5
7
  optionId,
6
8
  FormContextType,
7
9
  RJSFSchema,
@@ -21,9 +23,10 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
21
23
  const { id, htmlName, value, disabled, readonly, onChange, onBlur, onFocus, options } = props;
22
24
  const primeProps = (options.prime || {}) as object;
23
25
  const { enumOptions, enumDisabled, emptyValue } = options;
26
+ const optionValueFormat = getOptionValueFormat(options);
24
27
 
25
28
  const _onChange = (e: RadioButtonChangeEvent) => {
26
- onChange(enumOptionsValueForIndex<S>(e.value, enumOptions, emptyValue));
29
+ onChange(enumOptionValueDecoder<S>(e.value, enumOptions, optionValueFormat, emptyValue));
27
30
  };
28
31
 
29
32
  const _onBlur = () => onBlur(id, value);
@@ -44,7 +47,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
44
47
  onFocus={_onFocus}
45
48
  onBlur={_onBlur}
46
49
  onChange={_onChange}
47
- value={String(index)}
50
+ value={enumOptionValueEncoder(option.value, index, optionValueFormat)}
48
51
  checked={checked}
49
52
  disabled={disabled || itemDisabled || readonly}
50
53
  aria-describedby={ariaDescribedByIds(id)}
@@ -2,8 +2,10 @@ import { FocusEvent } from 'react';
2
2
  import { Dropdown } from 'primereact/dropdown';
3
3
  import {
4
4
  ariaDescribedByIds,
5
- enumOptionsIndexForValue,
6
- enumOptionsValueForIndex,
5
+ enumOptionSelectedValue,
6
+ enumOptionValueDecoder,
7
+ enumOptionValueEncoder,
8
+ getOptionValueFormat,
7
9
  FormContextType,
8
10
  RJSFSchema,
9
11
  StrictRJSFSchema,
@@ -50,19 +52,19 @@ function SingleSelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F
50
52
  ...dropdownProps
51
53
  }: WidgetProps<T, S, F>) {
52
54
  const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options;
55
+ const optionValueFormat = getOptionValueFormat(options);
53
56
  const primeProps = (options.prime || {}) as object;
54
57
 
55
58
  multiple = typeof multiple === 'undefined' ? false : multiple;
56
59
 
57
60
  const emptyValue = multiple ? [] : '';
58
- const isEmpty = typeof value === 'undefined' || (multiple && value.length < 1) || (!multiple && value === emptyValue);
59
61
 
60
- const _onChange = (e: { value: any }) => onChange(enumOptionsValueForIndex<S>(e.value, enumOptions, optEmptyVal));
62
+ const _onChange = (e: { value: any }) =>
63
+ onChange(enumOptionValueDecoder<S>(e.value, enumOptions, optionValueFormat, optEmptyVal));
61
64
  const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
62
- onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, optEmptyVal));
65
+ onBlur(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, optEmptyVal));
63
66
  const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
64
- onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, optEmptyVal));
65
- const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
67
+ onFocus(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, optEmptyVal));
66
68
  const { ...dropdownRemainingProps } = dropdownProps;
67
69
 
68
70
  return (
@@ -70,10 +72,10 @@ function SingleSelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F
70
72
  id={id}
71
73
  name={htmlName || id}
72
74
  {...primeProps}
73
- value={!isEmpty && typeof selectedIndexes !== 'undefined' ? selectedIndexes : emptyValue}
75
+ value={enumOptionSelectedValue<S>(value, enumOptions, !!multiple, optionValueFormat, emptyValue)}
74
76
  options={(enumOptions ?? []).map(({ value, label }, i: number) => ({
75
77
  label,
76
- value: String(i),
78
+ value: enumOptionValueEncoder(value, i, optionValueFormat),
77
79
  disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(value) !== -1,
78
80
  }))}
79
81
  onChange={_onChange}
@@ -103,27 +105,27 @@ function MultiSelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
103
105
  onFocus,
104
106
  }: WidgetProps<T, S, F>) {
105
107
  const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options;
108
+ const optionValueFormat = getOptionValueFormat(options);
106
109
  const primeProps = (options.prime || {}) as object;
107
110
 
108
111
  const emptyValue = multiple ? [] : '';
109
- const isEmpty = typeof value === 'undefined' || (multiple && value.length < 1) || (!multiple && value === emptyValue);
110
112
 
111
- const _onChange = (e: { value: any }) => onChange(enumOptionsValueForIndex<S>(e.value, enumOptions, optEmptyVal));
113
+ const _onChange = (e: { value: any }) =>
114
+ onChange(enumOptionValueDecoder<S>(e.value, enumOptions, optionValueFormat, optEmptyVal));
112
115
  const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
113
- onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, optEmptyVal));
116
+ onBlur(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, optEmptyVal));
114
117
  const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
115
- onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, optEmptyVal));
116
- const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
118
+ onFocus(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, optEmptyVal));
117
119
 
118
120
  return (
119
121
  <MultiSelect
120
122
  id={id}
121
123
  name={htmlName || id}
122
124
  {...primeProps}
123
- value={!isEmpty && typeof selectedIndexes !== 'undefined' ? selectedIndexes : emptyValue}
125
+ value={enumOptionSelectedValue<S>(value, enumOptions, multiple, optionValueFormat, emptyValue)}
124
126
  options={(enumOptions ?? []).map(({ value, label }, i: number) => ({
125
127
  label,
126
- value: String(i),
128
+ value: enumOptionValueEncoder(value, i, optionValueFormat),
127
129
  disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(value) !== -1,
128
130
  }))}
129
131
  onChange={_onChange}
@@ -62,6 +62,7 @@ export default function WrapIfAdditionalTemplate<
62
62
  </label>
63
63
  )}
64
64
  <InputText
65
+ key={label}
65
66
  id={`${id}-key`}
66
67
  name={`${id}-key`}
67
68
  defaultValue={label}