@abgov/jsonforms-components 1.20.1 → 1.21.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 +79 -33
- package/package.json +1 -1
- package/src/lib/Additional/ImageControl.d.ts +18 -0
- package/src/lib/Additional/index.d.ts +1 -0
- package/src/lib/Controls/FormStepper/util/GenerateFormFields.d.ts +3 -2
- package/src/lib/Controls/FormStepper/util/RenderFormReviewFields.d.ts +2 -1
- package/src/lib/Controls/FormStepper/util/renderReviewControl.d.ts +4 -2
- package/src/lib/Controls/FormStepper/util/renderReviewLIstWithDetail.d.ts +2 -2
package/index.esm.js
CHANGED
|
@@ -4,7 +4,7 @@ import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputD
|
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import get$1 from 'lodash/get';
|
|
7
|
-
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
|
|
7
|
+
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl as isControl$1, isCategorization, isLayout as isLayout$1 } from '@jsonforms/core';
|
|
8
8
|
import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
|
|
9
9
|
import merge from 'lodash/merge';
|
|
10
10
|
import isEmpty$1 from 'lodash/isEmpty';
|
|
@@ -4595,7 +4595,6 @@ const flatten = arr => {
|
|
|
4595
4595
|
const flatter = flatten(val[1]);
|
|
4596
4596
|
return acc.concat(flatter);
|
|
4597
4597
|
}
|
|
4598
|
-
// If the current value is a string, add it to the accumulator
|
|
4599
4598
|
if (isNameValuePair(val)) {
|
|
4600
4599
|
return acc.concat([[String(val[0]), getValue(val[1]) || '']]);
|
|
4601
4600
|
}
|
|
@@ -4613,7 +4612,7 @@ const flatten = arr => {
|
|
|
4613
4612
|
* However, we need to decide how to handle these sorts of nested data in the summary
|
|
4614
4613
|
* page before messing with it.
|
|
4615
4614
|
*/
|
|
4616
|
-
const getFormFieldValue = (scope, data) => {
|
|
4615
|
+
const getFormFieldValue = (schema, scope, data) => {
|
|
4617
4616
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4618
4617
|
let currentValue = data;
|
|
4619
4618
|
if (scope) {
|
|
@@ -4660,7 +4659,7 @@ const renderFileLink = (fileUploaderElement, downloadFile) => {
|
|
|
4660
4659
|
children: fileUploaderElement === null || fileUploaderElement === void 0 ? void 0 : fileUploaderElement.filename
|
|
4661
4660
|
});
|
|
4662
4661
|
};
|
|
4663
|
-
const renderReviewControl = (data, element, requiredFields, index,
|
|
4662
|
+
const renderReviewControl = (schema, data, element, requiredFields, index,
|
|
4664
4663
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4665
4664
|
fileList, downloadFile) => {
|
|
4666
4665
|
const fieldName = element.scope.split('/').pop() || '';
|
|
@@ -4668,21 +4667,21 @@ fileList, downloadFile) => {
|
|
|
4668
4667
|
if (!fieldName || !label) return null;
|
|
4669
4668
|
const isFileUploader = element.scope.includes('fileUploader');
|
|
4670
4669
|
const fileUploaderElement = isFileUploader ? fileList && fileList[fieldName] : null;
|
|
4671
|
-
const fieldValues = getFormFieldValue(element.scope, data ? data : {});
|
|
4670
|
+
const fieldValues = getFormFieldValue(schema, element.scope, data ? data : {});
|
|
4672
4671
|
const isRequired = requiredFields.includes(fieldName);
|
|
4673
4672
|
const asterisk = isRequired ? ' *' : '';
|
|
4674
4673
|
const values = fieldValues.value;
|
|
4675
4674
|
return jsxs(React.Fragment, {
|
|
4676
4675
|
children: [fieldValues.type === 'primitive' && renderValue(`${label}${asterisk}: `, `${index}`, fieldValues.value, fileUploaderElement, downloadFile), fieldValues.type === 'object' && values && values.length > 0 && values.map((v, i) => {
|
|
4677
4676
|
return renderValue(`${v[0]}: `, `${index}:${i}`, v[1]);
|
|
4678
|
-
}), fieldValues.type === 'array' && values && values.length > 0 &&
|
|
4677
|
+
}), fieldValues.type === 'array' && values && values.length > 0 && renderList(values)]
|
|
4679
4678
|
}, index);
|
|
4680
4679
|
};
|
|
4681
|
-
const
|
|
4680
|
+
const renderList = items => {
|
|
4682
4681
|
return jsx(React.Fragment, {
|
|
4683
4682
|
children: items.map((item, itemIndex) => {
|
|
4684
4683
|
const details = Array.isArray(item) ? item : [undefined, [undefined, undefined]];
|
|
4685
|
-
return jsxs(
|
|
4684
|
+
return jsxs("div", {
|
|
4686
4685
|
children: [jsx(Grid, {
|
|
4687
4686
|
children: details[1].map((detail, detailIndex) => {
|
|
4688
4687
|
const safeDetail = Array.isArray(detail) ? detail : [undefined, undefined];
|
|
@@ -4696,32 +4695,44 @@ const renderListDetails = items => {
|
|
|
4696
4695
|
});
|
|
4697
4696
|
};
|
|
4698
4697
|
|
|
4699
|
-
const renderReviewListWithDetail = (
|
|
4698
|
+
const renderReviewListWithDetail = (schema, elements,
|
|
4700
4699
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4701
4700
|
data, field, index, requiredFields) => {
|
|
4702
4701
|
const listData = data[field];
|
|
4702
|
+
const detailData = [];
|
|
4703
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4704
|
+
listData.forEach((elementData, i) => {
|
|
4705
|
+
const itemData = [];
|
|
4706
|
+
elements.forEach((element, j) => {
|
|
4707
|
+
const fieldName = element.scope.split('/').pop() || '';
|
|
4708
|
+
const label = resolveLabelFromScope(element.scope);
|
|
4709
|
+
const value = String(elementData[fieldName]);
|
|
4710
|
+
itemData.push([label, value]);
|
|
4711
|
+
});
|
|
4712
|
+
detailData.push([`${i}`, itemData]);
|
|
4713
|
+
});
|
|
4703
4714
|
return jsxs(ListWithDetail, {
|
|
4704
4715
|
children: [jsxs(ListWithDetailHeading, {
|
|
4705
4716
|
children: [field, listData.length > 1 && 's']
|
|
4706
|
-
}),
|
|
4707
|
-
children: listData.map((childData, childIndex) => {
|
|
4708
|
-
var _a, _b;
|
|
4709
|
-
return jsx(React.Fragment, {
|
|
4710
|
-
children: jsx(RenderFormReviewFields, {
|
|
4711
|
-
elements: ((_b = (_a = element === null || element === void 0 ? void 0 : element.options) === null || _a === void 0 ? void 0 : _a.detail) === null || _b === void 0 ? void 0 : _b.elements) || [],
|
|
4712
|
-
data: childData,
|
|
4713
|
-
requiredFields: requiredFields
|
|
4714
|
-
})
|
|
4715
|
-
}, `${index}-${childIndex}`);
|
|
4716
|
-
})
|
|
4717
|
-
})]
|
|
4717
|
+
}), renderList(detailData)]
|
|
4718
4718
|
}, `${index}-${field}`);
|
|
4719
4719
|
};
|
|
4720
4720
|
|
|
4721
|
+
const isControl = type => {
|
|
4722
|
+
return type === 'Control';
|
|
4723
|
+
};
|
|
4724
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4725
|
+
const isListWithDetail$1 = (type, data, fieldName) => {
|
|
4726
|
+
return type === 'ListWithDetail' && typeof data === 'object' && data !== null && fieldName in data && Array.isArray(data[fieldName]) && data[fieldName].length > 0;
|
|
4727
|
+
};
|
|
4728
|
+
const isLayout = schema => {
|
|
4729
|
+
return typeof schema === 'object' && schema !== null && 'elements' in schema;
|
|
4730
|
+
};
|
|
4721
4731
|
const RenderFormReviewFields = ({
|
|
4722
4732
|
elements,
|
|
4723
4733
|
data,
|
|
4724
|
-
requiredFields
|
|
4734
|
+
requiredFields,
|
|
4735
|
+
schema
|
|
4725
4736
|
}) => {
|
|
4726
4737
|
var _a, _b;
|
|
4727
4738
|
const enumerators = useContext(JsonFormContext);
|
|
@@ -4736,25 +4747,38 @@ const RenderFormReviewFields = ({
|
|
|
4736
4747
|
}
|
|
4737
4748
|
};
|
|
4738
4749
|
return elements.map((element, index) => {
|
|
4739
|
-
var _a;
|
|
4750
|
+
var _a, _b, _c;
|
|
4740
4751
|
const clonedElement = JSON.parse(JSON.stringify(element));
|
|
4741
4752
|
const fieldName = (_a = clonedElement.scope) === null || _a === void 0 ? void 0 : _a.split('/').pop();
|
|
4742
|
-
if (clonedElement.type
|
|
4743
|
-
return renderReviewControl(data, clonedElement, requiredFields, index, fileList, downloadFile);
|
|
4744
|
-
} else if (clonedElement.type
|
|
4753
|
+
if (isControl(clonedElement.type)) {
|
|
4754
|
+
return renderReviewControl(schema, data, clonedElement, requiredFields, index, fileList, downloadFile);
|
|
4755
|
+
} else if (isListWithDetail$1(clonedElement.type, data, fieldName)) {
|
|
4756
|
+
const elements = removeLayouts((_c = (_b = clonedElement === null || clonedElement === void 0 ? void 0 : clonedElement.options) === null || _b === void 0 ? void 0 : _b.detail) === null || _c === void 0 ? void 0 : _c.elements) || [];
|
|
4757
|
+
return renderReviewListWithDetail(schema, elements, data, fieldName, index);
|
|
4758
|
+
} else if (isLayout(clonedElement)) {
|
|
4745
4759
|
return jsx(React.Fragment, {
|
|
4746
4760
|
children: jsx(RenderFormReviewFields, {
|
|
4747
4761
|
elements: clonedElement.elements,
|
|
4748
4762
|
data: data,
|
|
4749
|
-
requiredFields: requiredFields
|
|
4763
|
+
requiredFields: requiredFields,
|
|
4764
|
+
schema: schema
|
|
4750
4765
|
})
|
|
4751
4766
|
}, index);
|
|
4752
|
-
} else if (clonedElement.type === 'ListWithDetail' && data && data[fieldName] && data[fieldName].length > 0) {
|
|
4753
|
-
return renderReviewListWithDetail(clonedElement, data, fieldName, index, requiredFields);
|
|
4754
4767
|
}
|
|
4755
4768
|
return null;
|
|
4756
4769
|
});
|
|
4757
4770
|
};
|
|
4771
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4772
|
+
const removeLayouts = elements => {
|
|
4773
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4774
|
+
return elements.reduce((acc, item) => {
|
|
4775
|
+
if (isLayout(item)) {
|
|
4776
|
+
return acc.concat(removeLayouts(item.elements));
|
|
4777
|
+
} else {
|
|
4778
|
+
return acc.concat(item);
|
|
4779
|
+
}
|
|
4780
|
+
}, []);
|
|
4781
|
+
};
|
|
4758
4782
|
|
|
4759
4783
|
const RenderStepElements = props => {
|
|
4760
4784
|
return (
|
|
@@ -5001,7 +5025,8 @@ const FormStepper = props => {
|
|
|
5001
5025
|
children: jsx(RenderFormReviewFields, {
|
|
5002
5026
|
elements: category === null || category === void 0 ? void 0 : category.elements,
|
|
5003
5027
|
data: data,
|
|
5004
|
-
requiredFields: requiredFields
|
|
5028
|
+
requiredFields: requiredFields,
|
|
5029
|
+
schema: schema
|
|
5005
5030
|
})
|
|
5006
5031
|
})]
|
|
5007
5032
|
}, index);
|
|
@@ -5958,6 +5983,24 @@ const HelpContents = ({
|
|
|
5958
5983
|
const HelpContentTester = rankWith(1, uiTypeIs('HelpContent'));
|
|
5959
5984
|
const HelpContent = withJsonFormsControlProps(HelpContentComponent);
|
|
5960
5985
|
|
|
5986
|
+
const ImageComponent = ({
|
|
5987
|
+
uischema
|
|
5988
|
+
}) => {
|
|
5989
|
+
var _a, _b, _c, _d;
|
|
5990
|
+
const url = ((_a = uischema.options) === null || _a === void 0 ? void 0 : _a.url) || '';
|
|
5991
|
+
const width = ((_b = uischema.options) === null || _b === void 0 ? void 0 : _b.width) || '';
|
|
5992
|
+
const height = ((_c = uischema.options) === null || _c === void 0 ? void 0 : _c.height) || '';
|
|
5993
|
+
const alt = ((_d = uischema.options) === null || _d === void 0 ? void 0 : _d.alt) || '';
|
|
5994
|
+
return jsx("img", {
|
|
5995
|
+
src: url,
|
|
5996
|
+
width: width,
|
|
5997
|
+
height: height,
|
|
5998
|
+
alt: alt
|
|
5999
|
+
});
|
|
6000
|
+
};
|
|
6001
|
+
const ImageControlTester = rankWith(1, uiTypeIs('ImageContent'));
|
|
6002
|
+
const ImageControl = withJsonFormsControlProps(ImageComponent);
|
|
6003
|
+
|
|
5961
6004
|
const isNullSchema = schema => {
|
|
5962
6005
|
return schema === undefined || schema === null;
|
|
5963
6006
|
};
|
|
@@ -5984,7 +6027,7 @@ const isLayoutType = schema => {
|
|
|
5984
6027
|
return hasType(schema, 'VerticalLayout') || hasType(schema, 'HorizontalLayout') || hasType(schema, 'Categorization') || hasType(schema, 'Group');
|
|
5985
6028
|
};
|
|
5986
6029
|
const isKnownType = schema => {
|
|
5987
|
-
return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') || isListWithDetail(schema) || hasType(schema, 'Callout');
|
|
6030
|
+
return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') || hasType(schema, 'ImageContent') || isListWithDetail(schema) || hasType(schema, 'Callout');
|
|
5988
6031
|
};
|
|
5989
6032
|
const isListWithDetail = schema => {
|
|
5990
6033
|
return hasType(schema, 'ListWithDetail');
|
|
@@ -6028,7 +6071,7 @@ const getUISchemaErrors = (uiSchema, schema) => {
|
|
|
6028
6071
|
return '';
|
|
6029
6072
|
}
|
|
6030
6073
|
// Check control elements
|
|
6031
|
-
if (isControl(uiSchema) && hasType(uiSchema, 'Control')) {
|
|
6074
|
+
if (isControl$1(uiSchema) && hasType(uiSchema, 'Control')) {
|
|
6032
6075
|
if (!isScopedPrefixed(uiSchema.scope)) {
|
|
6033
6076
|
return errMalformedScope(uiSchema.scope);
|
|
6034
6077
|
}
|
|
@@ -6062,7 +6105,7 @@ const getUISchemaErrors = (uiSchema, schema) => {
|
|
|
6062
6105
|
}
|
|
6063
6106
|
// ensure each element has type Category, and that each category
|
|
6064
6107
|
// has elements
|
|
6065
|
-
if (isLayout(uiSchema)) {
|
|
6108
|
+
if (isLayout$1(uiSchema)) {
|
|
6066
6109
|
const invalidCategorizations = [];
|
|
6067
6110
|
const invalidCategories = [];
|
|
6068
6111
|
uiSchema.elements.forEach(e => {
|
|
@@ -6195,6 +6238,9 @@ const GoABaseRenderers = [
|
|
|
6195
6238
|
}, {
|
|
6196
6239
|
tester: HelpContentTester,
|
|
6197
6240
|
renderer: HelpContent
|
|
6241
|
+
}, {
|
|
6242
|
+
tester: ImageControlTester,
|
|
6243
|
+
renderer: ImageControl
|
|
6198
6244
|
}];
|
|
6199
6245
|
const GoARenderers = [...GoABaseRenderers, {
|
|
6200
6246
|
tester: CategorizationRendererTester,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.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",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ControlElement, ControlProps, RankedTester } from '@jsonforms/core';
|
|
3
|
+
interface OptionProps {
|
|
4
|
+
url?: string;
|
|
5
|
+
width?: string;
|
|
6
|
+
height?: string;
|
|
7
|
+
alt?: string;
|
|
8
|
+
}
|
|
9
|
+
interface ImageCustomControlElement extends ControlElement {
|
|
10
|
+
options?: OptionProps;
|
|
11
|
+
}
|
|
12
|
+
interface ImageCustomControlProps extends ControlProps {
|
|
13
|
+
uischema: ImageCustomControlElement;
|
|
14
|
+
}
|
|
15
|
+
export declare const ImageComponent: ({ uischema }: ImageCustomControlProps) => JSX.Element;
|
|
16
|
+
export declare const ImageControlTester: RankedTester;
|
|
17
|
+
export declare const ImageControl: React.ComponentType<import("@jsonforms/core").OwnPropsOfControl>;
|
|
18
|
+
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { LabelDescription } from '@jsonforms/core';
|
|
1
|
+
import { JsonSchema, LabelDescription } from '@jsonforms/core';
|
|
2
2
|
type jsonformsLabel = string | boolean | LabelDescription | undefined;
|
|
3
3
|
export declare const labelToString: (label: jsonformsLabel, scope: string) => string;
|
|
4
|
+
export declare const resolveLabelFromScope: (scope: string) => string;
|
|
4
5
|
export interface InputValue {
|
|
5
6
|
type: 'primitive' | 'object' | 'array';
|
|
6
7
|
value?: string | NestedStringArray;
|
|
7
8
|
}
|
|
8
9
|
export type NestedStringArray = (string | undefined | NestedStringArray)[];
|
|
9
|
-
export declare const getFormFieldValue: (scope: string, data: unknown) => InputValue;
|
|
10
|
+
export declare const getFormFieldValue: (schema: JsonSchema, scope: string, data: unknown) => InputValue;
|
|
10
11
|
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Categorization, Category, UISchemaElement } from '@jsonforms/core';
|
|
2
|
+
import { Categorization, Category, JsonSchema, UISchemaElement } from '@jsonforms/core';
|
|
3
3
|
interface RenderFormReviewFieldsProps {
|
|
4
4
|
elements: UISchemaElement[] | (Category | Categorization)[];
|
|
5
5
|
data: any;
|
|
6
6
|
requiredFields: string[];
|
|
7
|
+
schema: JsonSchema;
|
|
7
8
|
}
|
|
8
9
|
export declare const RenderFormReviewFields: React.FC<RenderFormReviewFieldsProps>;
|
|
9
10
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ControlElement } from '@jsonforms/core';
|
|
1
|
+
import { ControlElement, JsonSchema } from '@jsonforms/core';
|
|
2
|
+
import { NestedStringArray } from './GenerateFormFields';
|
|
2
3
|
export interface FileElement extends File {
|
|
3
4
|
filename: string;
|
|
4
5
|
propertyId: string;
|
|
5
6
|
}
|
|
6
|
-
export declare const renderReviewControl: (data: unknown, element: ControlElement, requiredFields: string[], index: number, fileList: Record<string, any>, downloadFile: (file: File, propertyId: string) => void) => JSX.Element | null;
|
|
7
|
+
export declare const renderReviewControl: (schema: JsonSchema, data: unknown, element: ControlElement, requiredFields: string[], index: number, fileList: Record<string, any>, downloadFile: (file: File, propertyId: string) => void) => JSX.Element | null;
|
|
8
|
+
export declare const renderList: (items: NestedStringArray) => JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ControlElement } from '@jsonforms/core';
|
|
2
|
-
export declare const renderReviewListWithDetail: (
|
|
1
|
+
import { ControlElement, JsonSchema } from '@jsonforms/core';
|
|
2
|
+
export declare const renderReviewListWithDetail: (schema: JsonSchema, elements: ControlElement[], data: any, field: string, index: number, requiredFields: string[]) => JSX.Element;
|