@abgov/jsonforms-components 1.21.1 → 1.22.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 +102 -27
- package/package.json +1 -1
- package/src/lib/Additional/HelpContent.d.ts +4 -0
- package/src/lib/Additional/index.d.ts +0 -1
- package/src/lib/Context/register/util.d.ts +5 -0
- package/src/lib/Controls/Link/LinkControl.d.ts +9 -0
- package/src/lib/Additional/ImageControl.d.ts +0 -18
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 as isControl$1, isCategorization, isLayout as isLayout$1 } 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, scopeEndsWith, 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';
|
|
@@ -2871,6 +2871,20 @@ const fetchRegister = props => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
2871
2871
|
}
|
|
2872
2872
|
return undefined;
|
|
2873
2873
|
});
|
|
2874
|
+
const validateUrl = props => __awaiter(void 0, void 0, void 0, function* () {
|
|
2875
|
+
const {
|
|
2876
|
+
url
|
|
2877
|
+
} = props;
|
|
2878
|
+
if (url) {
|
|
2879
|
+
try {
|
|
2880
|
+
yield axios.get(url);
|
|
2881
|
+
return true;
|
|
2882
|
+
} catch (err) {
|
|
2883
|
+
console.warn(`Error in fetching data from remote: ${err}`);
|
|
2884
|
+
return false;
|
|
2885
|
+
}
|
|
2886
|
+
} else return false;
|
|
2887
|
+
});
|
|
2874
2888
|
|
|
2875
2889
|
const JsonFormsRegisterContext = /*#__PURE__*/createContext(undefined);
|
|
2876
2890
|
const JsonFormRegisterProvider = ({
|
|
@@ -5749,6 +5763,72 @@ const GoAArrayControlTester = rankWith(3, or(isObjectArrayControl, isPrimitiveAr
|
|
|
5749
5763
|
const GoAArrayControlRenderer = withJsonFormsArrayLayoutProps(ArrayControl);
|
|
5750
5764
|
const GoAListWithDetailsTester = rankWith(3, and(uiTypeIs('ListWithDetail')));
|
|
5751
5765
|
|
|
5766
|
+
const linkLength = 40;
|
|
5767
|
+
const invalidExtensions = ['exe'];
|
|
5768
|
+
const LinkSelect = props => {
|
|
5769
|
+
var _a, _b;
|
|
5770
|
+
const componentProps = (_b = (_a = props === null || props === void 0 ? void 0 : props.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.componentProps;
|
|
5771
|
+
const {
|
|
5772
|
+
link,
|
|
5773
|
+
label,
|
|
5774
|
+
heading,
|
|
5775
|
+
description
|
|
5776
|
+
} = componentProps;
|
|
5777
|
+
const [linkValid, setLinkValid] = useState(null);
|
|
5778
|
+
let error = undefined;
|
|
5779
|
+
let linkLabel = (link === null || link === void 0 ? void 0 : link.length) > linkLength ? `${link === null || link === void 0 ? void 0 : link.slice(0, linkLength)}...` : link;
|
|
5780
|
+
let linkUrl = link;
|
|
5781
|
+
if (label) {
|
|
5782
|
+
linkLabel = label;
|
|
5783
|
+
}
|
|
5784
|
+
const count = link === null || link === void 0 ? void 0 : link.split('.').length;
|
|
5785
|
+
const extension = link === null || link === void 0 ? void 0 : link.split('.')[count - 1];
|
|
5786
|
+
if (invalidExtensions.includes(extension)) {
|
|
5787
|
+
linkUrl = null;
|
|
5788
|
+
linkLabel = '';
|
|
5789
|
+
error = `Invalid extension: ${extension}`;
|
|
5790
|
+
}
|
|
5791
|
+
useEffect(() => {
|
|
5792
|
+
function validateLink(linkUrl) {
|
|
5793
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5794
|
+
if (linkUrl) {
|
|
5795
|
+
const response = yield validateUrl({
|
|
5796
|
+
url: linkUrl
|
|
5797
|
+
});
|
|
5798
|
+
setLinkValid(response);
|
|
5799
|
+
}
|
|
5800
|
+
});
|
|
5801
|
+
}
|
|
5802
|
+
validateLink(linkUrl);
|
|
5803
|
+
}, [linkUrl]);
|
|
5804
|
+
if (!linkLabel && !error) {
|
|
5805
|
+
linkLabel = 'Link';
|
|
5806
|
+
}
|
|
5807
|
+
if (linkValid === false) {
|
|
5808
|
+
linkLabel = '';
|
|
5809
|
+
error = 'Invalid Link';
|
|
5810
|
+
}
|
|
5811
|
+
return jsx(GoAFormItem, {
|
|
5812
|
+
error: error,
|
|
5813
|
+
label: heading,
|
|
5814
|
+
children: jsxs("div", {
|
|
5815
|
+
"data-testid": "link-jsonform",
|
|
5816
|
+
children: [description && jsx("div", {
|
|
5817
|
+
children: description
|
|
5818
|
+
}), linkUrl && linkValid ? jsx("a", {
|
|
5819
|
+
href: link,
|
|
5820
|
+
target: "_blank",
|
|
5821
|
+
rel: "noreferrer",
|
|
5822
|
+
children: linkLabel
|
|
5823
|
+
}) : linkLabel]
|
|
5824
|
+
})
|
|
5825
|
+
});
|
|
5826
|
+
};
|
|
5827
|
+
const linkControl = props => {
|
|
5828
|
+
return jsx(LinkSelect, Object.assign({}, props));
|
|
5829
|
+
};
|
|
5830
|
+
const GoALinkControlTester = rankWith(2, scopeEndsWith('link'));
|
|
5831
|
+
|
|
5752
5832
|
const GoATextCell = props => jsx(GoAInputText, Object.assign({}, props));
|
|
5753
5833
|
const GoATextCellTester = rankWith(1, isStringControl);
|
|
5754
5834
|
withJsonFormsCellProps(GoATextCell);
|
|
@@ -5910,7 +5990,7 @@ const HelpContentDiv = styled.div(_t || (_t = _`
|
|
|
5910
5990
|
`));
|
|
5911
5991
|
|
|
5912
5992
|
const HelpContentComponent = _a => {
|
|
5913
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
5993
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
5914
5994
|
var {
|
|
5915
5995
|
isParent = true
|
|
5916
5996
|
} = _a,
|
|
@@ -5934,6 +6014,19 @@ const HelpContentComponent = _a => {
|
|
|
5934
6014
|
children: (_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.help
|
|
5935
6015
|
});
|
|
5936
6016
|
};
|
|
6017
|
+
const renderImage = ({
|
|
6018
|
+
height,
|
|
6019
|
+
width,
|
|
6020
|
+
alt,
|
|
6021
|
+
img
|
|
6022
|
+
}) => {
|
|
6023
|
+
return jsx("img", {
|
|
6024
|
+
src: img,
|
|
6025
|
+
width: width,
|
|
6026
|
+
height: height,
|
|
6027
|
+
alt: alt
|
|
6028
|
+
});
|
|
6029
|
+
};
|
|
5937
6030
|
return jsx(Visible, {
|
|
5938
6031
|
visible: visible,
|
|
5939
6032
|
children: jsx(HelpContentDiv, {
|
|
@@ -5944,14 +6037,14 @@ const HelpContentComponent = _a => {
|
|
|
5944
6037
|
className: labelClass,
|
|
5945
6038
|
"data-testid": label,
|
|
5946
6039
|
children: [label, jsx("br", {})]
|
|
5947
|
-
}), (
|
|
6040
|
+
}), ((_e = uischema.options) === null || _e === void 0 ? void 0 : _e.img) && ((_f = uischema.options) === null || _f === void 0 ? void 0 : _f.img) !== '' && renderImage(uischema.options), (!((_g = uischema.options) === null || _g === void 0 ? void 0 : _g.variant) || ((_h = uischema.options) === null || _h === void 0 ? void 0 : _h.variant) !== 'details') && renderHelp(), ((_j = uischema.options) === null || _j === void 0 ? void 0 : _j.variant) && ((_k = uischema.options) === null || _k === void 0 ? void 0 : _k.variant) === 'details' && jsxs(GoADetails, {
|
|
5948
6041
|
heading: label ? label : '',
|
|
5949
6042
|
mt: "3xs",
|
|
5950
6043
|
mb: "none",
|
|
5951
|
-
children: [renderHelp(), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && ((
|
|
6044
|
+
children: [renderHelp(), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && ((_l = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _l === void 0 ? void 0 : _l.length) > 0 && jsx(HelpContents, {
|
|
5952
6045
|
elements: uischema === null || uischema === void 0 ? void 0 : uischema.elements
|
|
5953
6046
|
})]
|
|
5954
|
-
}), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && (uischema === null || uischema === void 0 ? void 0 : uischema.elements.length) > 0 && ((
|
|
6047
|
+
}), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && (uischema === null || uischema === void 0 ? void 0 : uischema.elements.length) > 0 && ((_m = uischema.options) === null || _m === void 0 ? void 0 : _m.variant) !== 'details' && jsx(HelpContents, {
|
|
5955
6048
|
elements: uischema.elements,
|
|
5956
6049
|
isParent: false
|
|
5957
6050
|
})]
|
|
@@ -5983,24 +6076,6 @@ const HelpContents = ({
|
|
|
5983
6076
|
const HelpContentTester = rankWith(1, uiTypeIs('HelpContent'));
|
|
5984
6077
|
const HelpContent = withJsonFormsControlProps(HelpContentComponent);
|
|
5985
6078
|
|
|
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
|
-
|
|
6004
6079
|
const isNullSchema = schema => {
|
|
6005
6080
|
return schema === undefined || schema === null;
|
|
6006
6081
|
};
|
|
@@ -6027,7 +6102,7 @@ const isLayoutType = schema => {
|
|
|
6027
6102
|
return hasType(schema, 'VerticalLayout') || hasType(schema, 'HorizontalLayout') || hasType(schema, 'Categorization') || hasType(schema, 'Group');
|
|
6028
6103
|
};
|
|
6029
6104
|
const isKnownType = schema => {
|
|
6030
|
-
return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') ||
|
|
6105
|
+
return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') || isListWithDetail(schema) || hasType(schema, 'Callout');
|
|
6031
6106
|
};
|
|
6032
6107
|
const isListWithDetail = schema => {
|
|
6033
6108
|
return hasType(schema, 'ListWithDetail');
|
|
@@ -6180,6 +6255,9 @@ const GoABaseRenderers = [
|
|
|
6180
6255
|
{
|
|
6181
6256
|
tester: GoAEnumControlTester,
|
|
6182
6257
|
renderer: GoAEnumControl
|
|
6258
|
+
}, {
|
|
6259
|
+
tester: GoALinkControlTester,
|
|
6260
|
+
renderer: linkControl
|
|
6183
6261
|
}, {
|
|
6184
6262
|
tester: GoAIntegerControlTester,
|
|
6185
6263
|
renderer: GoAInputIntegerControl
|
|
@@ -6238,9 +6316,6 @@ const GoABaseRenderers = [
|
|
|
6238
6316
|
}, {
|
|
6239
6317
|
tester: HelpContentTester,
|
|
6240
6318
|
renderer: HelpContent
|
|
6241
|
-
}, {
|
|
6242
|
-
tester: ImageControlTester,
|
|
6243
|
-
renderer: ImageControl
|
|
6244
6319
|
}];
|
|
6245
6320
|
const GoARenderers = [...GoABaseRenderers, {
|
|
6246
6321
|
tester: CategorizationRendererTester,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.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,9 @@
|
|
|
1
|
+
import { ControlProps, RankedTester } from '@jsonforms/core';
|
|
2
|
+
import { TranslateProps } from '@jsonforms/react';
|
|
3
|
+
import { WithInputProps } from '../Inputs/type';
|
|
4
|
+
import { WithOptionLabel } from '../../util';
|
|
5
|
+
import { WithClassname } from '@jsonforms/core';
|
|
6
|
+
export type LinkSelectProps = WithClassname & TranslateProps & WithInputProps & ControlProps;
|
|
7
|
+
export declare const LinkSelect: (props: LinkSelectProps) => JSX.Element;
|
|
8
|
+
export declare const linkControl: (props: ControlProps & WithOptionLabel & TranslateProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare const GoALinkControlTester: RankedTester;
|
|
@@ -1,18 +0,0 @@
|
|
|
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 {};
|