@rjsf/core 6.0.2 → 6.1.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 (35) hide show
  1. package/dist/core.umd.js +63 -40
  2. package/dist/index.cjs +295 -265
  3. package/dist/index.cjs.map +4 -4
  4. package/dist/index.esm.js +173 -140
  5. package/dist/index.esm.js.map +4 -4
  6. package/lib/components/RichHelp.d.ts +20 -0
  7. package/lib/components/RichHelp.d.ts.map +1 -0
  8. package/lib/components/RichHelp.js +17 -0
  9. package/lib/components/fields/ArrayField.d.ts.map +1 -1
  10. package/lib/components/fields/ArrayField.js +6 -1
  11. package/lib/components/fields/ObjectField.js +1 -1
  12. package/lib/components/fields/StringField.d.ts.map +1 -1
  13. package/lib/components/fields/StringField.js +3 -3
  14. package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
  15. package/lib/components/templates/ArrayFieldItemTemplate.js +5 -5
  16. package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
  17. package/lib/components/templates/ButtonTemplates/AddButton.js +1 -1
  18. package/lib/components/templates/FieldHelpTemplate.d.ts.map +1 -1
  19. package/lib/components/templates/FieldHelpTemplate.js +3 -6
  20. package/lib/components/templates/WrapIfAdditionalTemplate.d.ts.map +1 -1
  21. package/lib/components/templates/WrapIfAdditionalTemplate.js +4 -2
  22. package/lib/index.d.ts +3 -2
  23. package/lib/index.d.ts.map +1 -1
  24. package/lib/index.js +2 -1
  25. package/lib/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
  27. package/src/components/RichHelp.tsx +46 -0
  28. package/src/components/fields/ArrayField.tsx +7 -0
  29. package/src/components/fields/ObjectField.tsx +2 -2
  30. package/src/components/fields/StringField.tsx +3 -2
  31. package/src/components/templates/ArrayFieldItemTemplate.tsx +8 -11
  32. package/src/components/templates/ButtonTemplates/AddButton.tsx +3 -1
  33. package/src/components/templates/FieldHelpTemplate.tsx +5 -11
  34. package/src/components/templates/WrapIfAdditionalTemplate.tsx +7 -3
  35. package/src/index.ts +3 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/core",
3
- "version": "6.0.2",
3
+ "version": "6.1.1",
4
4
  "description": "A simple React component capable of building HTML forms out of a JSON schema.",
5
5
  "scripts": {
6
6
  "compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs",
@@ -0,0 +1,46 @@
1
+ import { ReactElement } from 'react';
2
+ import {
3
+ FormContextType,
4
+ Registry,
5
+ RJSFSchema,
6
+ StrictRJSFSchema,
7
+ UiSchema,
8
+ getTestIds,
9
+ getUiOptions,
10
+ } from '@rjsf/utils';
11
+ import Markdown from 'markdown-to-jsx';
12
+
13
+ const TEST_IDS = getTestIds();
14
+
15
+ export interface RichHelpProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
16
+ /** The description text for a field, potentially containing markdown */
17
+ help: string | ReactElement;
18
+ /** The uiSchema object for this base component */
19
+ uiSchema?: UiSchema<T, S, F>;
20
+ /** The `registry` object */
21
+ registry: Registry<T, S, F>;
22
+ }
23
+
24
+ /** Renders the given `description` in the props as
25
+ *
26
+ * @param props - The `RichHelpProps` for this component
27
+ */
28
+ export default function RichHelp<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
29
+ help,
30
+ registry,
31
+ uiSchema = {},
32
+ }: RichHelpProps<T, S, F>) {
33
+ const { globalUiOptions } = registry;
34
+ const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
35
+
36
+ if (uiOptions.enableMarkdownInHelp && typeof help === 'string') {
37
+ return (
38
+ <Markdown options={{ disableParsingRawHTML: true }} data-testid={TEST_IDS.markdown}>
39
+ {help}
40
+ </Markdown>
41
+ );
42
+ }
43
+ return help;
44
+ }
45
+
46
+ RichHelp.TEST_IDS = TEST_IDS;
@@ -406,7 +406,9 @@ function ArrayFieldItem<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
406
406
  handleReorderItems,
407
407
  } = props;
408
408
  const {
409
+ schemaUtils,
409
410
  fields: { ArraySchemaField, SchemaField },
411
+ globalUiOptions,
410
412
  } = registry;
411
413
  const fieldPathId = useDeepCompareMemo<FieldPathId>(itemFieldPathId);
412
414
  const ItemSchemaField = ArraySchemaField || SchemaField;
@@ -415,6 +417,9 @@ function ArrayFieldItem<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
415
417
  registry,
416
418
  uiOptions,
417
419
  );
420
+ const displayLabel = schemaUtils.getDisplayLabel(itemSchema, itemUiSchema, globalUiOptions);
421
+ const { description } = getUiOptions(itemUiSchema);
422
+ const hasDescription = !!description || !!itemSchema.description;
418
423
  const { orderable = true, removable = true, copyable = false } = uiOptions;
419
424
  const has: { [key: string]: boolean } = {
420
425
  moveUp: orderable && canMoveUp,
@@ -510,6 +515,8 @@ function ArrayFieldItem<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
510
515
  schema: itemSchema,
511
516
  uiSchema: itemUiSchema,
512
517
  parentUiSchema,
518
+ displayLabel,
519
+ hasDescription,
513
520
  };
514
521
  return <ArrayFieldItemTemplate {...templateProps} />;
515
522
  }
@@ -367,9 +367,9 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
367
367
  required={isRequired<S>(schema, name)}
368
368
  schema={get(schema, [PROPERTIES_KEY, name], {}) as S}
369
369
  uiSchema={fieldUiSchema}
370
- errorSchema={get(errorSchema, name)}
370
+ errorSchema={get(errorSchema, [name])}
371
371
  fieldPathId={childFieldPathId}
372
- formData={get(formData, name)}
372
+ formData={get(formData, [name])}
373
373
  handleKeyRename={handleKeyRename}
374
374
  handleRemoveProperty={handleRemoveProperty}
375
375
  addedByAdditionalProperties={addedByAdditionalProperties}
@@ -34,8 +34,9 @@ function StringField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
34
34
  registry,
35
35
  rawErrors,
36
36
  hideError,
37
+ title,
37
38
  } = props;
38
- const { title, format } = schema;
39
+ const { title: schemaTitle, format } = schema;
39
40
  const { widgets, schemaUtils, globalUiOptions } = registry;
40
41
  const enumOptions = schemaUtils.isSelect(schema) ? optionsList<T, S, F>(schema, uiSchema) : undefined;
41
42
  let defaultWidget = enumOptions ? 'select' : 'text';
@@ -44,7 +45,7 @@ function StringField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
44
45
  }
45
46
  const { widget = defaultWidget, placeholder = '', title: uiTitle, ...options } = getUiOptions<T, S, F>(uiSchema);
46
47
  const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
47
- const label = uiTitle ?? title ?? name;
48
+ const label = uiTitle ?? title ?? schemaTitle ?? name;
48
49
  const Widget = getWidget<T, S, F>(schema, widget, widgets);
49
50
  const onWidgetChange = useCallback(
50
51
  (value: T | undefined, errorSchema?: ErrorSchema, id?: string) => {
@@ -17,7 +17,7 @@ export default function ArrayFieldItemTemplate<
17
17
  S extends StrictRJSFSchema = RJSFSchema,
18
18
  F extends FormContextType = any,
19
19
  >(props: ArrayFieldItemTemplateProps<T, S, F>) {
20
- const { children, className, buttonsProps, hasToolbar, registry, uiSchema } = props;
20
+ const { children, className, buttonsProps, displayLabel, hasDescription, hasToolbar, registry, uiSchema } = props;
21
21
  const uiOptions = getUiOptions<T, S, F>(uiSchema);
22
22
  const ArrayFieldItemButtonsTemplate = getTemplate<'ArrayFieldItemButtonsTemplate', T, S, F>(
23
23
  'ArrayFieldItemButtonsTemplate',
@@ -30,18 +30,15 @@ export default function ArrayFieldItemTemplate<
30
30
  paddingRight: 6,
31
31
  fontWeight: 'bold',
32
32
  };
33
+ const margin = hasDescription ? 31 : 9;
34
+ const containerStyle = { display: 'flex', alignItems: displayLabel ? 'center' : 'baseline' };
35
+ const toolbarStyle = { display: 'flex', justifyContent: 'flex-end', marginTop: displayLabel ? `${margin}px` : 0 };
33
36
  return (
34
- <div className={className}>
35
- <div className={hasToolbar ? 'col-xs-9' : 'col-xs-12'}>{children}</div>
37
+ <div className={className} style={containerStyle}>
38
+ <div className={hasToolbar ? 'col-xs-9 col-md-10 col-xl-11' : 'col-xs-12'}>{children}</div>
36
39
  {hasToolbar && (
37
- <div className='col-xs-3 array-item-toolbox'>
38
- <div
39
- className='btn-group'
40
- style={{
41
- display: 'flex',
42
- justifyContent: 'space-around',
43
- }}
44
- >
40
+ <div className='col-xs-3 col-md-2 col-xl-1 array-item-toolbox'>
41
+ <div className='btn-group' style={toolbarStyle}>
45
42
  <ArrayFieldItemButtonsTemplate {...buttonsProps} style={btnStyle} />
46
43
  </div>
47
44
  </div>
@@ -14,7 +14,9 @@ export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSche
14
14
  const { translateString } = registry;
15
15
  return (
16
16
  <div className='row'>
17
- <p className={`col-xs-3 col-xs-offset-9 text-right ${className}`}>
17
+ <p
18
+ className={`col-xs-4 col-sm-2 col-lg-1 col-xs-offset-8 col-sm-offset-10 col-lg-offset-11 text-right ${className}`}
19
+ >
18
20
  <IconButton
19
21
  id={id}
20
22
  iconType='info'
@@ -1,4 +1,5 @@
1
1
  import { helpId, FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+ import RichHelp from '../RichHelp';
2
3
 
3
4
  /** The `FieldHelpTemplate` component renders any help desired for a field
4
5
  *
@@ -9,21 +10,14 @@ export default function FieldHelpTemplate<
9
10
  S extends StrictRJSFSchema = RJSFSchema,
10
11
  F extends FormContextType = any,
11
12
  >(props: FieldHelpProps<T, S, F>) {
12
- const { fieldPathId, help } = props;
13
+ const { fieldPathId, help, uiSchema, registry } = props;
13
14
  if (!help) {
14
15
  return null;
15
16
  }
16
- const id = helpId(fieldPathId);
17
- if (typeof help === 'string') {
18
- return (
19
- <p id={id} className='help-block'>
20
- {help}
21
- </p>
22
- );
23
- }
17
+
24
18
  return (
25
- <div id={id} className='help-block'>
26
- {help}
19
+ <div id={helpId(fieldPathId)} className='help-block'>
20
+ <RichHelp help={help as string} registry={registry} uiSchema={uiSchema} />
27
21
  </div>
28
22
  );
29
23
  }
@@ -25,9 +25,11 @@ export default function WrapIfAdditionalTemplate<
25
25
  classNames,
26
26
  style,
27
27
  disabled,
28
+ displayLabel,
28
29
  label,
29
30
  onKeyRenameBlur,
30
31
  onRemoveProperty,
32
+ rawDescription,
31
33
  readonly,
32
34
  required,
33
35
  schema,
@@ -42,6 +44,7 @@ export default function WrapIfAdditionalTemplate<
42
44
  const { RemoveButton } = templates.ButtonTemplates;
43
45
  const keyLabel = translateString(TranslatableString.KeyLabel, [label]);
44
46
  const additional = ADDITIONAL_PROPERTY_FLAG in schema;
47
+ const hasDescription = !!rawDescription;
45
48
 
46
49
  const classNamesList = ['form-group', classNames];
47
50
  if (!hideError && rawErrors && rawErrors.length > 0) {
@@ -56,13 +59,14 @@ export default function WrapIfAdditionalTemplate<
56
59
  </div>
57
60
  );
58
61
  }
59
-
62
+ const margin = hasDescription ? 46 : 26;
60
63
  return (
61
64
  <div className={uiClassNames} style={style}>
62
65
  <div className='row'>
63
66
  <div className='col-xs-5 form-additional'>
64
67
  <div className='form-group'>
65
- <Label label={keyLabel} required={required} id={`${id}-key`} />
68
+ {displayLabel && <Label label={keyLabel} required={required} id={`${id}-key`} />}
69
+ {displayLabel && rawDescription && <div>&nbsp;</div>}
66
70
  <input
67
71
  className='form-control'
68
72
  type='text'
@@ -73,7 +77,7 @@ export default function WrapIfAdditionalTemplate<
73
77
  </div>
74
78
  </div>
75
79
  <div className='form-additional form-group col-xs-5'>{children}</div>
76
- <div className='col-xs-2'>
80
+ <div className='col-xs-2' style={{ marginTop: displayLabel ? `${margin}px` : undefined }}>
77
81
  <RemoveButton
78
82
  id={buttonId(id, 'remove')}
79
83
  className='rjsf-object-property-remove btn-block'
package/src/index.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import Form, { FormProps, FormState, IChangeEvent } from './components/Form';
2
2
  import RichDescription, { RichDescriptionProps } from './components/RichDescription';
3
+ import RichHelp, { RichHelpProps } from './components/RichHelp';
3
4
  import withTheme, { ThemeProps } from './withTheme';
4
5
  import getDefaultRegistry from './getDefaultRegistry';
5
6
  import getTestRegistry from './getTestRegistry';
6
7
 
7
- export type { FormProps, FormState, IChangeEvent, ThemeProps, RichDescriptionProps };
8
+ export type { FormProps, FormState, IChangeEvent, ThemeProps, RichDescriptionProps, RichHelpProps };
8
9
 
9
- export { withTheme, getDefaultRegistry, getTestRegistry, RichDescription };
10
+ export { withTheme, getDefaultRegistry, getTestRegistry, RichDescription, RichHelp };
10
11
  export default Form;