@abgov/jsonforms-components 1.53.0 → 1.53.2
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 +102 -29
- package/package.json +1 -1
- package/src/lib/Controls/FormStepper/context/StepperContext.d.ts +0 -3
- package/src/lib/Controls/FormStepper/context/index.d.ts +1 -0
- package/src/lib/Controls/FormStepper/context/util.d.ts +4 -0
- package/src/lib/Controls/Inputs/InputBaseReviewControl.d.ts +2 -2
- package/src/lib/Controls/Inputs/style-component.d.ts +2 -0
package/index.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as runtime from 'react/jsx-runtime';
|
|
2
2
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputDateTime, GoAInputTime, GoARadioGroup, GoARadioItem, GoACheckbox, GoAGrid, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoATable, GoADropdown, GoADropdownItem, GoADetails, GoASpinner } from '@abgov/react-components';
|
|
3
|
+
import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputDateTime, GoAInputTime, GoARadioGroup, GoARadioItem, GoACheckbox, GoAIcon, GoAGrid, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoATable, GoADropdown, GoADropdownItem, GoADetails, GoASpinner } from '@abgov/react-components';
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
import React, { createContext, useContext, useReducer, useMemo, useEffect, useState, useRef, useCallback } from 'react';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import get$1 from 'lodash/get';
|
|
8
|
-
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible,
|
|
8
|
+
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, getControlPath, toDataPath, deriveLabelForUISchemaElement, isEnabled, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, schemaMatches, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
|
|
9
9
|
import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
|
|
10
10
|
import * as _$b from 'lodash';
|
|
11
11
|
import { isEqual, isObject as isObject$f } from 'lodash';
|
|
@@ -3081,14 +3081,14 @@ const onChangeForCheckboxData = (data, name, value) => data ? !value ? data ===
|
|
|
3081
3081
|
|
|
3082
3082
|
let _$a = t => t,
|
|
3083
3083
|
_t$a,
|
|
3084
|
-
_t2$
|
|
3084
|
+
_t2$7;
|
|
3085
3085
|
styled.div(_t$a || (_t$a = _$a`
|
|
3086
3086
|
height: 70vh;
|
|
3087
3087
|
overflow-y: auto;
|
|
3088
3088
|
padding-left: var(--goa-space-2xs);
|
|
3089
3089
|
padding-right: var(--goa-space-2xs);
|
|
3090
3090
|
`));
|
|
3091
|
-
const Visible = styled.div(_t2$
|
|
3091
|
+
const Visible = styled.div(_t2$7 || (_t2$7 = _$a`
|
|
3092
3092
|
display: ${0};
|
|
3093
3093
|
`), p => p.visible ? 'initial' : 'none');
|
|
3094
3094
|
|
|
@@ -3849,10 +3849,26 @@ const JsonFormRegisterProvider = ({
|
|
|
3849
3849
|
};
|
|
3850
3850
|
|
|
3851
3851
|
let _$9 = t => t,
|
|
3852
|
-
_t$9
|
|
3852
|
+
_t$9,
|
|
3853
|
+
_t2$6,
|
|
3854
|
+
_t3$5;
|
|
3853
3855
|
const FormFieldWrapper = styled.div(_t$9 || (_t$9 = _$9`
|
|
3854
3856
|
margin-bottom: var(--goa-space-l);
|
|
3855
3857
|
`));
|
|
3858
|
+
const WarningIconDiv = styled.div(_t2$6 || (_t2$6 = _$9`
|
|
3859
|
+
display: inline-flex;
|
|
3860
|
+
align-items: flex-start;
|
|
3861
|
+
gap: 0.25rem;
|
|
3862
|
+
font-size: var(--goa-font-size-2);
|
|
3863
|
+
color: var(--goa-color-interactive-error);
|
|
3864
|
+
`));
|
|
3865
|
+
const RequiredTextLabel = styled.label(_t3$5 || (_t3$5 = _$9`
|
|
3866
|
+
color: var(--goa-color-greyscale-700);
|
|
3867
|
+
font-weight: var(--goa-font-weight-regular);
|
|
3868
|
+
font-size: var(--goa-font-size-2);
|
|
3869
|
+
line-height: var(--goa-line-height-1);
|
|
3870
|
+
font-style: normal;
|
|
3871
|
+
`));
|
|
3856
3872
|
|
|
3857
3873
|
const GoAInputBaseControl = props => {
|
|
3858
3874
|
var _a, _b;
|
|
@@ -5234,24 +5250,57 @@ const EnumCheckboxControl = props => {
|
|
|
5234
5250
|
const GoAEnumCheckboxGroupControl = withJsonFormsEnumProps(withTranslateProps(EnumCheckboxControl), true);
|
|
5235
5251
|
const GoACheckoutGroupControlTester = rankWith(18, and(isEnumControl, optionIs('format', 'checkbox')));
|
|
5236
5252
|
|
|
5253
|
+
const warningIcon = errorMessage => {
|
|
5254
|
+
return jsxs(WarningIconDiv, {
|
|
5255
|
+
children: [jsx(GoAIcon, {
|
|
5256
|
+
type: "warning",
|
|
5257
|
+
size: "small",
|
|
5258
|
+
theme: "filled",
|
|
5259
|
+
mt: "2xs"
|
|
5260
|
+
}), errorMessage]
|
|
5261
|
+
});
|
|
5262
|
+
};
|
|
5237
5263
|
const GoABaseInputReviewComponent = props => {
|
|
5264
|
+
var _a, _b, _c, _d, _e;
|
|
5238
5265
|
// eslint-disable-next-line
|
|
5239
5266
|
const {
|
|
5240
5267
|
data,
|
|
5241
|
-
id
|
|
5268
|
+
id,
|
|
5269
|
+
uischema,
|
|
5270
|
+
schema,
|
|
5271
|
+
required
|
|
5242
5272
|
} = props;
|
|
5243
5273
|
let reviewText = data;
|
|
5244
5274
|
const isBoolean = typeof data === 'boolean';
|
|
5275
|
+
const requiredText = `${((_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.text) ? (_b = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _b === void 0 ? void 0 : _b.text : (schema === null || schema === void 0 ? void 0 : schema.title) ? schema === null || schema === void 0 ? void 0 : schema.title : schema === null || schema === void 0 ? void 0 : schema.description}${required ? ' is required.' : ''}`;
|
|
5276
|
+
const renderRequiredLabel = () => {
|
|
5277
|
+
return data !== undefined && schema.type === 'boolean' && required ? jsx(RequiredTextLabel, {
|
|
5278
|
+
children: ` (required)`
|
|
5279
|
+
}) : null;
|
|
5280
|
+
};
|
|
5281
|
+
const renderWarningMessage = () => {
|
|
5282
|
+
var _a;
|
|
5283
|
+
if ((_a = uischema.options) === null || _a === void 0 ? void 0 : _a.radio) return null;
|
|
5284
|
+
if (schema.type === 'boolean' && required && data === undefined) {
|
|
5285
|
+
return warningIcon(requiredText.trim());
|
|
5286
|
+
}
|
|
5287
|
+
return null;
|
|
5288
|
+
};
|
|
5245
5289
|
if (isBoolean) {
|
|
5246
|
-
|
|
5290
|
+
const label = (_d = (_c = uischema.options) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d.trim();
|
|
5291
|
+
if (((_e = uischema.options) === null || _e === void 0 ? void 0 : _e.radio) === true) {
|
|
5292
|
+
reviewText = data ? `Yes` : `No`;
|
|
5293
|
+
} else {
|
|
5294
|
+
reviewText = data ? `Yes (${label})` : `No (${label})`;
|
|
5295
|
+
}
|
|
5247
5296
|
}
|
|
5248
|
-
return
|
|
5297
|
+
return jsxs("div", {
|
|
5249
5298
|
style: {
|
|
5250
5299
|
textWrap: 'wrap',
|
|
5251
5300
|
wordBreak: 'break-word'
|
|
5252
5301
|
},
|
|
5253
5302
|
"data-testid": `review-control-${id}`,
|
|
5254
|
-
children: reviewText
|
|
5303
|
+
children: [reviewText, renderRequiredLabel(), renderWarningMessage()]
|
|
5255
5304
|
});
|
|
5256
5305
|
};
|
|
5257
5306
|
const GoInputBaseReview = props => jsx(GoAInputBaseControl, Object.assign({}, props, {
|
|
@@ -5854,6 +5903,48 @@ const FormStepperReviewer = props => {
|
|
|
5854
5903
|
};
|
|
5855
5904
|
const FormStepperReviewControl = withAjvProps(withTranslateProps(withJsonFormsLayoutProps(FormStepperReviewer)));
|
|
5856
5905
|
|
|
5906
|
+
const isErrorPathIncluded = (errorPaths, path) => {
|
|
5907
|
+
return errorPaths.some(ePath => {
|
|
5908
|
+
/**
|
|
5909
|
+
* case A: errorPaths: [name] path: [name]
|
|
5910
|
+
*
|
|
5911
|
+
* case B: errorPath: [name] path: [name.firstName]
|
|
5912
|
+
* */
|
|
5913
|
+
return ePath === path || path.startsWith(ePath + '.');
|
|
5914
|
+
});
|
|
5915
|
+
};
|
|
5916
|
+
function isNumber(value) {
|
|
5917
|
+
return value != null && value !== '' && !isNaN(Number(value.toString()));
|
|
5918
|
+
}
|
|
5919
|
+
const getIncompletePaths = (ajv, scopes) => {
|
|
5920
|
+
var _a;
|
|
5921
|
+
const requiredErrorPaths = (_a = ajv === null || ajv === void 0 ? void 0 : ajv.errors) === null || _a === void 0 ? void 0 : _a.filter(e => e.keyword === 'required').map(e => {
|
|
5922
|
+
return getControlPath(e);
|
|
5923
|
+
});
|
|
5924
|
+
const _scopes = scopes.map(scope => toDataPath(scope)).filter(path => requiredErrorPaths && isErrorPathIncluded(requiredErrorPaths, path));
|
|
5925
|
+
return _scopes;
|
|
5926
|
+
};
|
|
5927
|
+
const subErrorInParent = (error, paths) => {
|
|
5928
|
+
/*
|
|
5929
|
+
Detect is there sub error in an object array.
|
|
5930
|
+
For example: error with instance path /roadmap/0/when belongs to /roadmap
|
|
5931
|
+
*/
|
|
5932
|
+
const errorPaths = error.instancePath.split('/');
|
|
5933
|
+
if (errorPaths.length < 3) return false;
|
|
5934
|
+
if (isNumber(errorPaths[errorPaths.length - 2])) {
|
|
5935
|
+
const parentPath = errorPaths.slice(0, errorPaths.length - 2).join('/');
|
|
5936
|
+
return paths.includes(parentPath);
|
|
5937
|
+
}
|
|
5938
|
+
return false;
|
|
5939
|
+
};
|
|
5940
|
+
const getErrorsInScopes = (errors, scopes) => {
|
|
5941
|
+
return errors.filter(e => {
|
|
5942
|
+
// transfer scope #properties/value to data path /value
|
|
5943
|
+
const dataPaths = scopes.map(s => '/' + toDataPath(s));
|
|
5944
|
+
return dataPaths.includes(e.instancePath) || subErrorInParent(e, dataPaths);
|
|
5945
|
+
});
|
|
5946
|
+
};
|
|
5947
|
+
|
|
5857
5948
|
const stepperReducer = (state, action) => {
|
|
5858
5949
|
const {
|
|
5859
5950
|
activeId,
|
|
@@ -5921,7 +6012,7 @@ const stepperReducer = (state, action) => {
|
|
|
5921
6012
|
ctx.core.errors only includes required errors when the fields are touched. In this case, we still ajv to figure out the required errors at the very beginning.
|
|
5922
6013
|
*/
|
|
5923
6014
|
const incompletePaths = getIncompletePaths(ajv, state.categories[id].scopes);
|
|
5924
|
-
const errorsInCategory = errors.
|
|
6015
|
+
const errorsInCategory = getErrorsInScopes(errors, state.categories[id].scopes || []);
|
|
5925
6016
|
state.categories[id].isCompleted = (incompletePaths === null || incompletePaths === void 0 ? void 0 : incompletePaths.length) === 0;
|
|
5926
6017
|
state.categories[id].isValid = errorsInCategory.length === 0;
|
|
5927
6018
|
return Object.assign({}, state);
|
|
@@ -5939,24 +6030,6 @@ const stepperReducer = (state, action) => {
|
|
|
5939
6030
|
}
|
|
5940
6031
|
};
|
|
5941
6032
|
|
|
5942
|
-
const isErrorPathIncluded = (errorPaths, path) => {
|
|
5943
|
-
return errorPaths.some(ePath => {
|
|
5944
|
-
/**
|
|
5945
|
-
* case A: errorPaths: [name] path: [name]
|
|
5946
|
-
*
|
|
5947
|
-
* case B: errorPath: [name] path: [name.firstName]
|
|
5948
|
-
* */
|
|
5949
|
-
return ePath === path || path.startsWith(ePath + '.');
|
|
5950
|
-
});
|
|
5951
|
-
};
|
|
5952
|
-
const getIncompletePaths = (ajv, scopes) => {
|
|
5953
|
-
var _a;
|
|
5954
|
-
const requiredErrorPaths = (_a = ajv === null || ajv === void 0 ? void 0 : ajv.errors) === null || _a === void 0 ? void 0 : _a.filter(e => e.keyword === 'required').map(e => {
|
|
5955
|
-
return getControlPath(e);
|
|
5956
|
-
});
|
|
5957
|
-
const _scopes = scopes.map(scope => toDataPath(scope)).filter(path => requiredErrorPaths && isErrorPathIncluded(requiredErrorPaths, path));
|
|
5958
|
-
return _scopes;
|
|
5959
|
-
};
|
|
5960
6033
|
const createStepperContextInitData = props => {
|
|
5961
6034
|
var _a;
|
|
5962
6035
|
const {
|
|
@@ -6156,7 +6229,7 @@ const FormStepperView = props => {
|
|
|
6156
6229
|
return jsx(GoAFormStep, {
|
|
6157
6230
|
"data-testid": `stepper-tab-${index}`,
|
|
6158
6231
|
text: `${c.label}`,
|
|
6159
|
-
status: c.
|
|
6232
|
+
status: c.isVisited ? c.isCompleted && c.isValid ? 'complete' : 'incomplete' : undefined
|
|
6160
6233
|
}, `stepper-tab-${index}`);
|
|
6161
6234
|
}), jsx(GoAFormStep, {
|
|
6162
6235
|
text: "Review"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.53.
|
|
3
|
+
"version": "1.53.2",
|
|
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",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ReactNode, Dispatch } from 'react';
|
|
2
2
|
import { CategorizationStepperLayoutRendererProps } from '../types';
|
|
3
3
|
import { StepperContextDataType, CategoryState } from './types';
|
|
4
|
-
import Ajv from 'ajv';
|
|
5
4
|
import { JsonFormStepperDispatch } from './reducer';
|
|
6
5
|
export interface JsonFormsStepperContextProviderProps {
|
|
7
6
|
children: ReactNode;
|
|
@@ -21,7 +20,5 @@ export interface JsonFormsStepperContextProps {
|
|
|
21
20
|
goToPage: (id: number, updateCategoryId?: number) => void;
|
|
22
21
|
isProvided?: boolean;
|
|
23
22
|
}
|
|
24
|
-
export declare const isErrorPathIncluded: (errorPaths: string[], path: string) => boolean;
|
|
25
|
-
export declare const getIncompletePaths: (ajv: Ajv, scopes: string[]) => string[];
|
|
26
23
|
export declare const JsonFormsStepperContext: import("react").Context<JsonFormsStepperContextProps | undefined>;
|
|
27
24
|
export declare const JsonFormsStepperContextProvider: ({ children, StepperProps, }: JsonFormsStepperContextProviderProps) => JSX.Element;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Ajv, { ErrorObject } from 'ajv';
|
|
2
|
+
export declare const isErrorPathIncluded: (errorPaths: string[], path: string) => boolean;
|
|
3
|
+
export declare const getIncompletePaths: (ajv: Ajv, scopes: string[]) => string[];
|
|
4
|
+
export declare const getErrorsInScopes: (errors: ErrorObject[], scopes: string[]) => ErrorObject[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CellProps, WithClassname, ControlProps } from '@jsonforms/core';
|
|
2
|
+
import { CellProps, WithClassname, ControlProps, StatePropsOfControl } from '@jsonforms/core';
|
|
3
3
|
import { WithInputProps } from './type';
|
|
4
|
-
export type WithBaseInputReviewProps = CellProps & WithClassname & WithInputProps;
|
|
4
|
+
export type WithBaseInputReviewProps = CellProps & WithClassname & WithInputProps & StatePropsOfControl;
|
|
5
5
|
export declare const GoABaseInputReviewComponent: (props: WithBaseInputReviewProps) => JSX.Element;
|
|
6
6
|
export declare const GoInputBaseReview: (props: ControlProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export declare const GoInputBaseReviewControl: import("react").ComponentType<import("@jsonforms/core").OwnPropsOfControl>;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare const FormFieldWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
3
|
+
export declare const WarningIconDiv: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
4
|
+
export declare const RequiredTextLabel: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, never>> & string;
|