@abgov/jsonforms-components 1.13.0 → 1.14.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/index.esm.js CHANGED
@@ -1,12 +1,11 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import React, { createContext, useContext, useEffect, useMemo, useState, useCallback } from 'react';
3
- import { GoACallout, GoAInputDate, GoAFormItem, GoAInput, GoATextArea, GoAInputDateTime, GoAInputTime, GoADropdown, GoADropdownItem, GoARadioGroup, GoARadioItem, GoACheckbox, GoAFormStepper, GoAFormStep, GoAPages, GoAGrid, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoADetails } from '@abgov/react-components';
3
+ import { GoACallout, GoAInputDate, GoAFormItem, GoAInput, GoATextArea, GoAInputDateTime, GoAInputTime, GoADropdown, GoADropdownItem, GoARadioGroup, GoARadioItem, GoACheckbox, GoAGrid, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoADetails } from '@abgov/react-components';
4
4
  import styled from 'styled-components';
5
- import { rankWith, uiTypeIs, isDateControl, isStringControl, and, optionIs, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, isDescriptionHidden, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
6
- import { withJsonFormsRendererProps, withJsonFormsControlProps, withJsonFormsEnumProps, withTranslateProps, JsonFormsDispatch, withJsonFormsLayoutProps, useJsonForms, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
5
+ import { rankWith, uiTypeIs, isDateControl, isStringControl, and, optionIs, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, isDescriptionHidden, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
6
+ import { withJsonFormsRendererProps, withJsonFormsControlProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
7
7
  import merge from 'lodash/merge';
8
8
  import axios from 'axios';
9
- import { withAjvProps } from '@jsonforms/material-renderers';
10
9
  import isEmpty$1 from 'lodash/isEmpty';
11
10
  import range from 'lodash/range';
12
11
  import Ajv from 'ajv';
@@ -3684,6 +3683,57 @@ const BooleanRadioControl = props => jsx(GoAInputBaseControl, Object.assign({},
3684
3683
  const GoABooleanRadioControlTester = rankWith(3, and(isBooleanControl, optionIs('radio', true)));
3685
3684
  const GoABooleanRadioControl = withJsonFormsControlProps(BooleanRadioControl);
3686
3685
 
3686
+ const renderLayoutElements = (elements, schema, path, enabled, renderers, cells) => {
3687
+ return elements.map((child, index) => jsx("div", {
3688
+ children: jsx(JsonFormsDispatch, {
3689
+ uischema: child,
3690
+ schema: schema,
3691
+ path: path,
3692
+ enabled: enabled,
3693
+ renderers: renderers,
3694
+ cells: cells
3695
+ }, path)
3696
+ }, index));
3697
+ };
3698
+ const withAjvProps = Component => function WithAjvProps(props) {
3699
+ const ctx = useJsonForms();
3700
+ const ajv = getAjv({
3701
+ jsonforms: Object.assign({}, ctx)
3702
+ });
3703
+ return jsx(Component, Object.assign({}, props, {
3704
+ ajv: ajv
3705
+ }));
3706
+ };
3707
+ const LayoutRenderer = ({
3708
+ elements,
3709
+ schema,
3710
+ path,
3711
+ enabled,
3712
+ direction,
3713
+ renderers,
3714
+ cells,
3715
+ visible
3716
+ }) => {
3717
+ if (isEmpty$1(elements)) {
3718
+ return null;
3719
+ } else {
3720
+ if (direction === 'row') {
3721
+ return jsx(Visible, {
3722
+ visible: visible,
3723
+ children: jsx(GoAGrid, {
3724
+ minChildWidth: "10ch",
3725
+ children: renderLayoutElements(elements, schema, path, enabled, renderers, cells)
3726
+ })
3727
+ });
3728
+ } else {
3729
+ return jsx(Visible, {
3730
+ visible: visible,
3731
+ children: renderLayoutElements(elements, schema, path, enabled, renderers, cells)
3732
+ });
3733
+ }
3734
+ }
3735
+ };
3736
+
3687
3737
  let _$5 = t => t,
3688
3738
  _t$5,
3689
3739
  _t2$3;
@@ -3949,6 +3999,24 @@ const RenderStepElements = props => {
3949
3999
  );
3950
4000
  };
3951
4001
 
4002
+ const validateData = (jsonSchema, data, ajv) => {
4003
+ const newSchema = JSON.parse(JSON.stringify(jsonSchema));
4004
+ Object.keys(newSchema.properties || {}).forEach(propertyName => {
4005
+ var _a;
4006
+ const property = newSchema.properties || {};
4007
+ property[propertyName].enum = getData(propertyName);
4008
+ if (((_a = property[propertyName]) === null || _a === void 0 ? void 0 : _a.format) === 'file-urn') {
4009
+ delete property[propertyName].format;
4010
+ }
4011
+ });
4012
+ try {
4013
+ const validate = ajv.compile(newSchema);
4014
+ return validate(data).valueOf();
4015
+ } catch (e) {
4016
+ return false;
4017
+ }
4018
+ };
4019
+
3952
4020
  const FormStepper = props => {
3953
4021
  var _a, _b, _c, _d;
3954
4022
  const {
@@ -4002,17 +4070,8 @@ const FormStepper = props => {
4002
4070
  setStepStatuses(statuses);
4003
4071
  }, [inputStatuses, categories]);
4004
4072
  useEffect(() => {
4005
- const newSchema = JSON.parse(JSON.stringify(schema));
4006
- Object.keys(newSchema.properties || {}).forEach(propertyName => {
4007
- var _a;
4008
- const property = newSchema.properties || {};
4009
- property[propertyName].enum = getData(propertyName);
4010
- if (((_a = property[propertyName]) === null || _a === void 0 ? void 0 : _a.format) === 'file-urn') {
4011
- delete property[propertyName].format;
4012
- }
4013
- });
4014
- const validate = ajv.compile(newSchema);
4015
- setIsFormValid(validate(data));
4073
+ const isValid = validateData(schema, data, ajv);
4074
+ setIsFormValid(isValid);
4016
4075
  }, [ajv, data, schema]);
4017
4076
  useEffect(() => {
4018
4077
  var _a, _b;
@@ -4176,6 +4235,7 @@ const FormStepper = props => {
4176
4235
  type: "primary",
4177
4236
  onClick: handleSubmit,
4178
4237
  disabled: !isFormValid || !enabled,
4238
+ testId: "stepper-submit-btn",
4179
4239
  children: "Submit"
4180
4240
  })
4181
4241
  })]
@@ -4922,48 +4982,6 @@ const InputCells = [{
4922
4982
  cell: withJsonFormsCellProps(GoAIntegerCell)
4923
4983
  }];
4924
4984
 
4925
- const renderLayoutElements = (elements, schema, path, enabled, renderers, cells) => {
4926
- return elements.map((child, index) => jsx("div", {
4927
- children: jsx(JsonFormsDispatch, {
4928
- uischema: child,
4929
- schema: schema,
4930
- path: path,
4931
- enabled: enabled,
4932
- renderers: renderers,
4933
- cells: cells
4934
- }, path)
4935
- }, index));
4936
- };
4937
- const LayoutRenderer = ({
4938
- elements,
4939
- schema,
4940
- path,
4941
- enabled,
4942
- direction,
4943
- renderers,
4944
- cells,
4945
- visible
4946
- }) => {
4947
- if (isEmpty$1(elements)) {
4948
- return null;
4949
- } else {
4950
- if (direction === 'row') {
4951
- return jsx(Visible, {
4952
- visible: visible,
4953
- children: jsx(GoAGrid, {
4954
- minChildWidth: "10ch",
4955
- children: renderLayoutElements(elements, schema, path, enabled, renderers, cells)
4956
- })
4957
- });
4958
- } else {
4959
- return jsx(Visible, {
4960
- visible: visible,
4961
- children: renderLayoutElements(elements, schema, path, enabled, renderers, cells)
4962
- });
4963
- }
4964
- }
4965
- };
4966
-
4967
4985
  const GoAHorizontalLayoutTester = rankWith(2, uiTypeIs('HorizontalLayout'));
4968
4986
  const GoAHorizontalLayoutComponent = ({
4969
4987
  uischema,
package/package.json CHANGED
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.13.0",
3
+ "version": "1.14.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
6
6
  "repository": "https://github.com/GovAlta/adsp-monorepo",
7
7
  "peerDependencies": {
8
8
  "@abgov/react-components": "^4.18.1",
9
9
  "@jsonforms/core": "^3.1.0",
10
- "@jsonforms/material-renderers": "^3.1.0",
11
10
  "@jsonforms/react": "^3.1.0",
12
- "@mui/material": "^5.15.10",
13
11
  "react": "^18.0.0",
14
12
  "ajv": "^6.12.6",
15
13
  "ajv8": "npm:ajv@^8.6.1"
@@ -1,11 +1,9 @@
1
- import React from 'react';
2
1
  import { StatePropsOfLayout } from '@jsonforms/core';
3
2
  import { TranslateProps } from '@jsonforms/react';
4
- import { AjvProps } from '@jsonforms/material-renderers';
3
+ import { AjvProps } from '../../util/layout';
5
4
  export interface CategorizationStepperLayoutRendererProps extends StatePropsOfLayout, AjvProps, TranslateProps {
6
5
  data: unknown;
7
6
  }
8
7
  export declare const FormStepper: (props: CategorizationStepperLayoutRendererProps) => JSX.Element;
9
- export declare const flattenObject: (obj: Record<string, string>) => Record<string, string>;
10
- export declare const FormStepperControl: (props: CategorizationStepperLayoutRendererProps & import("@jsonforms/core").OwnPropsOfLayout) => React.JSX.Element;
8
+ export declare const FormStepperControl: (props: CategorizationStepperLayoutRendererProps & import("@jsonforms/core").OwnPropsOfLayout) => import("react/jsx-runtime").JSX.Element;
11
9
  export default FormStepper;
@@ -0,0 +1,3 @@
1
+ import { JsonSchema } from '@jsonforms/core';
2
+ import Ajv from 'ajv8';
3
+ export declare const validateData: (jsonSchema: JsonSchema, data: unknown, ajv: Ajv) => boolean;
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { ControlProps, OwnPropsOfEnum, RankedTester } from '@jsonforms/core';
3
3
  import { TranslateProps } from '@jsonforms/react';
4
4
  import { WithInputProps } from './type';
5
- import { WithOptionLabel } from '@jsonforms/material-renderers';
5
+ import { WithOptionLabel } from '../../util';
6
6
  import { EnumCellProps, WithClassname } from '@jsonforms/core';
7
7
  type EnumSelectProp = EnumCellProps & WithClassname & TranslateProps & WithInputProps;
8
8
  export declare const EnumSelect: (props: EnumSelectProp) => JSX.Element;
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { ControlProps, OwnPropsOfEnum, RankedTester } from '@jsonforms/core';
3
3
  import { TranslateProps } from '@jsonforms/react';
4
4
  import { WithInputProps } from './type';
5
- import { WithOptionLabel } from '@jsonforms/material-renderers';
5
+ import { WithOptionLabel } from '../../util';
6
6
  import { EnumCellProps, WithClassname } from '@jsonforms/core';
7
7
  type RadioGroupProp = EnumCellProps & WithClassname & TranslateProps & WithInputProps;
8
8
  export declare const RadioGroup: (props: RadioGroupProp) => JSX.Element;
@@ -1,2 +1,4 @@
1
1
  export * from './inputControlUtils';
2
2
  export * from './style-component';
3
+ export * from './type';
4
+ export * from './stringUtils';
@@ -1,3 +1,4 @@
1
+ import React, { ComponentType } from 'react';
1
2
  import type { UISchemaElement } from '@jsonforms/core';
2
3
  import { JsonFormsCellRendererRegistryEntry, JsonFormsRendererRegistryEntry, JsonSchema, OwnPropsOfRenderer } from '@jsonforms/core';
3
4
  import Ajv from 'ajv8';
@@ -10,4 +11,5 @@ export interface LayoutRendererProps extends OwnPropsOfRenderer {
10
11
  export interface AjvProps {
11
12
  ajv: Ajv;
12
13
  }
14
+ export declare const withAjvProps: <P extends object>(Component: React.ComponentType<AjvProps & P>) => (props: P) => import("react/jsx-runtime").JSX.Element;
13
15
  export declare const LayoutRenderer: ({ elements, schema, path, enabled, direction, renderers, cells, visible, }: LayoutRendererProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,6 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { EnumOption } from '@jsonforms/core';
3
+ export interface WithOptionLabel {
4
+ getOptionLabel?(option: EnumOption): string;
5
+ renderOption?(props: React.HTMLAttributes<HTMLLIElement>, option: EnumOption): ReactNode;
6
+ }