@abgov/jsonforms-components 1.22.0 → 1.22.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 +79 -98
- package/package.json +1 -1
- package/src/lib/Additional/HelpContent.d.ts +5 -0
- package/src/lib/Additional/LinkControl.d.ts +11 -0
- package/src/lib/Additional/index.d.ts +0 -1
- package/src/lib/Additional/ImageControl.d.ts +0 -18
- package/src/lib/Controls/Link/LinkControl.d.ts +0 -9
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,
|
|
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';
|
|
@@ -5763,72 +5763,6 @@ const GoAArrayControlTester = rankWith(3, or(isObjectArrayControl, isPrimitiveAr
|
|
|
5763
5763
|
const GoAArrayControlRenderer = withJsonFormsArrayLayoutProps(ArrayControl);
|
|
5764
5764
|
const GoAListWithDetailsTester = rankWith(3, and(uiTypeIs('ListWithDetail')));
|
|
5765
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
|
-
|
|
5832
5766
|
const GoATextCell = props => jsx(GoAInputText, Object.assign({}, props));
|
|
5833
5767
|
const GoATextCellTester = rankWith(1, isStringControl);
|
|
5834
5768
|
withJsonFormsCellProps(GoATextCell);
|
|
@@ -5989,8 +5923,65 @@ const HelpContentDiv = styled.div(_t || (_t = _`
|
|
|
5989
5923
|
}
|
|
5990
5924
|
`));
|
|
5991
5925
|
|
|
5926
|
+
const linkLength = 40;
|
|
5927
|
+
const invalidExtensions = ['exe'];
|
|
5928
|
+
const RenderLink = props => {
|
|
5929
|
+
var _a;
|
|
5930
|
+
const {
|
|
5931
|
+
link,
|
|
5932
|
+
help
|
|
5933
|
+
} = props;
|
|
5934
|
+
const [linkValid, setLinkValid] = useState(null);
|
|
5935
|
+
let error = undefined;
|
|
5936
|
+
let linkLabel = link && (link === null || link === void 0 ? void 0 : link.length) > linkLength ? `${link === null || link === void 0 ? void 0 : link.slice(0, linkLength)}...` : link;
|
|
5937
|
+
let linkUrl = link;
|
|
5938
|
+
if (help) {
|
|
5939
|
+
linkLabel = help;
|
|
5940
|
+
}
|
|
5941
|
+
const count = ((_a = link === null || link === void 0 ? void 0 : link.split('.')) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
5942
|
+
const extension = link === null || link === void 0 ? void 0 : link.split('.')[count - 1];
|
|
5943
|
+
if (invalidExtensions.includes(extension || '')) {
|
|
5944
|
+
linkUrl = '';
|
|
5945
|
+
linkLabel = '';
|
|
5946
|
+
error = `Invalid extension: ${extension}`;
|
|
5947
|
+
}
|
|
5948
|
+
useEffect(() => {
|
|
5949
|
+
function validateLink(linkUrl) {
|
|
5950
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5951
|
+
if (linkUrl) {
|
|
5952
|
+
const response = yield validateUrl({
|
|
5953
|
+
url: linkUrl
|
|
5954
|
+
});
|
|
5955
|
+
setLinkValid(response);
|
|
5956
|
+
}
|
|
5957
|
+
});
|
|
5958
|
+
}
|
|
5959
|
+
validateLink(linkUrl);
|
|
5960
|
+
}, [linkUrl]);
|
|
5961
|
+
if (!linkLabel && !error) {
|
|
5962
|
+
linkLabel = 'Link';
|
|
5963
|
+
}
|
|
5964
|
+
if (linkValid === false) {
|
|
5965
|
+
linkLabel = '';
|
|
5966
|
+
error = 'Invalid Link';
|
|
5967
|
+
}
|
|
5968
|
+
return jsx(GoAFormItem, {
|
|
5969
|
+
error: error,
|
|
5970
|
+
label: "",
|
|
5971
|
+
children: jsx("div", {
|
|
5972
|
+
"data-testid": "link-jsonform",
|
|
5973
|
+
children: linkUrl && linkValid ? jsx("a", {
|
|
5974
|
+
href: link,
|
|
5975
|
+
target: "_blank",
|
|
5976
|
+
rel: "noreferrer",
|
|
5977
|
+
children: linkLabel
|
|
5978
|
+
}) : linkLabel
|
|
5979
|
+
})
|
|
5980
|
+
});
|
|
5981
|
+
};
|
|
5982
|
+
|
|
5992
5983
|
const HelpContentComponent = _a => {
|
|
5993
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
5984
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
5994
5985
|
var {
|
|
5995
5986
|
isParent = true
|
|
5996
5987
|
} = _a,
|
|
@@ -6003,6 +5994,7 @@ const HelpContentComponent = _a => {
|
|
|
6003
5994
|
visible,
|
|
6004
5995
|
label
|
|
6005
5996
|
} = props;
|
|
5997
|
+
const link = (_b = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _b === void 0 ? void 0 : _b.link;
|
|
6006
5998
|
const renderHelp = () => {
|
|
6007
5999
|
var _a, _b, _c;
|
|
6008
6000
|
return Array.isArray((_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.help) ? jsx("ul", {
|
|
@@ -6014,24 +6006,37 @@ const HelpContentComponent = _a => {
|
|
|
6014
6006
|
children: (_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.help
|
|
6015
6007
|
});
|
|
6016
6008
|
};
|
|
6009
|
+
const renderImage = ({
|
|
6010
|
+
height,
|
|
6011
|
+
width,
|
|
6012
|
+
alt,
|
|
6013
|
+
img
|
|
6014
|
+
}) => {
|
|
6015
|
+
return jsx("img", {
|
|
6016
|
+
src: img,
|
|
6017
|
+
width: width,
|
|
6018
|
+
height: height,
|
|
6019
|
+
alt: alt
|
|
6020
|
+
});
|
|
6021
|
+
};
|
|
6017
6022
|
return jsx(Visible, {
|
|
6018
6023
|
visible: visible,
|
|
6019
6024
|
children: jsx(HelpContentDiv, {
|
|
6020
|
-
"aria-label": (
|
|
6025
|
+
"aria-label": (_c = uischema.options) === null || _c === void 0 ? void 0 : _c.ariaLabel,
|
|
6021
6026
|
children: jsxs("div", {
|
|
6022
6027
|
className: marginClass,
|
|
6023
|
-
children: [label && !((
|
|
6028
|
+
children: [label && !((_d = uischema.options) === null || _d === void 0 ? void 0 : _d.variant) && ((_e = uischema.options) === null || _e === void 0 ? void 0 : _e.variant) !== 'details' && jsxs("div", {
|
|
6024
6029
|
className: labelClass,
|
|
6025
6030
|
"data-testid": label,
|
|
6026
6031
|
children: [label, jsx("br", {})]
|
|
6027
|
-
}), (!((
|
|
6032
|
+
}), ((_f = uischema.options) === null || _f === void 0 ? void 0 : _f.img) && ((_g = uischema.options) === null || _g === void 0 ? void 0 : _g.img) !== '' && renderImage(uischema.options), ((_h = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _h === void 0 ? void 0 : _h.link) && link !== '' && RenderLink(uischema === null || uischema === void 0 ? void 0 : uischema.options), (!((_j = uischema.options) === null || _j === void 0 ? void 0 : _j.variant) || ((_k = uischema.options) === null || _k === void 0 ? void 0 : _k.variant) !== 'details') && !link && renderHelp(), ((_l = uischema.options) === null || _l === void 0 ? void 0 : _l.variant) && ((_m = uischema.options) === null || _m === void 0 ? void 0 : _m.variant) === 'details' && jsxs(GoADetails, {
|
|
6028
6033
|
heading: label ? label : '',
|
|
6029
6034
|
mt: "3xs",
|
|
6030
6035
|
mb: "none",
|
|
6031
|
-
children: [renderHelp(), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && ((
|
|
6036
|
+
children: [renderHelp(), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && ((_o = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _o === void 0 ? void 0 : _o.length) > 0 && jsx(HelpContents, {
|
|
6032
6037
|
elements: uischema === null || uischema === void 0 ? void 0 : uischema.elements
|
|
6033
6038
|
})]
|
|
6034
|
-
}), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && (uischema === null || uischema === void 0 ? void 0 : uischema.elements.length) > 0 && ((
|
|
6039
|
+
}), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && (uischema === null || uischema === void 0 ? void 0 : uischema.elements.length) > 0 && ((_p = uischema.options) === null || _p === void 0 ? void 0 : _p.variant) !== 'details' && jsx(HelpContents, {
|
|
6035
6040
|
elements: uischema.elements,
|
|
6036
6041
|
isParent: false
|
|
6037
6042
|
})]
|
|
@@ -6063,24 +6068,6 @@ const HelpContents = ({
|
|
|
6063
6068
|
const HelpContentTester = rankWith(1, uiTypeIs('HelpContent'));
|
|
6064
6069
|
const HelpContent = withJsonFormsControlProps(HelpContentComponent);
|
|
6065
6070
|
|
|
6066
|
-
const ImageComponent = ({
|
|
6067
|
-
uischema
|
|
6068
|
-
}) => {
|
|
6069
|
-
var _a, _b, _c, _d;
|
|
6070
|
-
const url = ((_a = uischema.options) === null || _a === void 0 ? void 0 : _a.url) || '';
|
|
6071
|
-
const width = ((_b = uischema.options) === null || _b === void 0 ? void 0 : _b.width) || '';
|
|
6072
|
-
const height = ((_c = uischema.options) === null || _c === void 0 ? void 0 : _c.height) || '';
|
|
6073
|
-
const alt = ((_d = uischema.options) === null || _d === void 0 ? void 0 : _d.alt) || '';
|
|
6074
|
-
return jsx("img", {
|
|
6075
|
-
src: url,
|
|
6076
|
-
width: width,
|
|
6077
|
-
height: height,
|
|
6078
|
-
alt: alt
|
|
6079
|
-
});
|
|
6080
|
-
};
|
|
6081
|
-
const ImageControlTester = rankWith(1, uiTypeIs('ImageContent'));
|
|
6082
|
-
const ImageControl = withJsonFormsControlProps(ImageComponent);
|
|
6083
|
-
|
|
6084
6071
|
const isNullSchema = schema => {
|
|
6085
6072
|
return schema === undefined || schema === null;
|
|
6086
6073
|
};
|
|
@@ -6107,7 +6094,7 @@ const isLayoutType = schema => {
|
|
|
6107
6094
|
return hasType(schema, 'VerticalLayout') || hasType(schema, 'HorizontalLayout') || hasType(schema, 'Categorization') || hasType(schema, 'Group');
|
|
6108
6095
|
};
|
|
6109
6096
|
const isKnownType = schema => {
|
|
6110
|
-
return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') ||
|
|
6097
|
+
return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') || isListWithDetail(schema) || hasType(schema, 'Callout');
|
|
6111
6098
|
};
|
|
6112
6099
|
const isListWithDetail = schema => {
|
|
6113
6100
|
return hasType(schema, 'ListWithDetail');
|
|
@@ -6260,9 +6247,6 @@ const GoABaseRenderers = [
|
|
|
6260
6247
|
{
|
|
6261
6248
|
tester: GoAEnumControlTester,
|
|
6262
6249
|
renderer: GoAEnumControl
|
|
6263
|
-
}, {
|
|
6264
|
-
tester: GoALinkControlTester,
|
|
6265
|
-
renderer: linkControl
|
|
6266
6250
|
}, {
|
|
6267
6251
|
tester: GoAIntegerControlTester,
|
|
6268
6252
|
renderer: GoAInputIntegerControl
|
|
@@ -6321,9 +6305,6 @@ const GoABaseRenderers = [
|
|
|
6321
6305
|
}, {
|
|
6322
6306
|
tester: HelpContentTester,
|
|
6323
6307
|
renderer: HelpContent
|
|
6324
|
-
}, {
|
|
6325
|
-
tester: ImageControlTester,
|
|
6326
|
-
renderer: ImageControl
|
|
6327
6308
|
}];
|
|
6328
6309
|
const GoARenderers = [...GoABaseRenderers, {
|
|
6329
6310
|
tester: CategorizationRendererTester,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.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",
|
|
@@ -5,6 +5,11 @@ interface OptionProps {
|
|
|
5
5
|
ariaLabel?: string;
|
|
6
6
|
help?: string | string[];
|
|
7
7
|
variant?: string;
|
|
8
|
+
img?: string;
|
|
9
|
+
alt?: string;
|
|
10
|
+
height?: string;
|
|
11
|
+
width?: string;
|
|
12
|
+
link?: string;
|
|
8
13
|
}
|
|
9
14
|
interface CustomControlElement extends ControlElement {
|
|
10
15
|
options?: OptionProps;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface OptionProps {
|
|
2
|
+
ariaLabel?: string;
|
|
3
|
+
help?: string | string[];
|
|
4
|
+
variant?: string;
|
|
5
|
+
img?: string;
|
|
6
|
+
alt?: string;
|
|
7
|
+
height?: string;
|
|
8
|
+
width?: string;
|
|
9
|
+
link?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const RenderLink: (props: OptionProps) => JSX.Element;
|
|
@@ -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 {};
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|