@abgov/jsonforms-components 2.1.1 → 2.1.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
CHANGED
|
@@ -8,7 +8,7 @@ import get$1 from 'lodash/get';
|
|
|
8
8
|
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, getControlPath, toDataPath, deriveLabelForUISchemaElement, isEnabled, schemaTypeIs, formatIs, createDefaultValue, or, isObjectArrayControl, isPrimitiveArrayControl, Paths, 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 _$c from 'lodash';
|
|
11
|
-
import { isEqual, isObject as isObject$f } from 'lodash';
|
|
11
|
+
import { isEqual, isEmpty as isEmpty$1, isObject as isObject$f } from 'lodash';
|
|
12
12
|
import merge from 'lodash/merge';
|
|
13
13
|
import isEmpty from 'lodash/isEmpty';
|
|
14
14
|
import range from 'lodash/range';
|
|
@@ -4391,7 +4391,7 @@ const formatSin = value => {
|
|
|
4391
4391
|
return formatVal;
|
|
4392
4392
|
};
|
|
4393
4393
|
const GoAInputText = props => {
|
|
4394
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
4394
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
4395
4395
|
const {
|
|
4396
4396
|
data,
|
|
4397
4397
|
config,
|
|
@@ -4406,14 +4406,15 @@ const GoAInputText = props => {
|
|
|
4406
4406
|
isVisited,
|
|
4407
4407
|
setIsVisited
|
|
4408
4408
|
} = props;
|
|
4409
|
+
const width = (_c = (_b = (_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.componentProps) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : '100%';
|
|
4409
4410
|
const registerCtx = useContext(JsonFormsRegisterContext);
|
|
4410
|
-
const registerConfig = fetchRegisterConfigFromOptions$1((
|
|
4411
|
+
const registerConfig = fetchRegisterConfigFromOptions$1((_e = (_d = props.uischema) === null || _d === void 0 ? void 0 : _d.options) === null || _e === void 0 ? void 0 : _e.register);
|
|
4411
4412
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4412
4413
|
let registerData = [];
|
|
4413
4414
|
if (registerConfig) {
|
|
4414
4415
|
registerData = registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.selectRegisterData(registerConfig);
|
|
4415
4416
|
}
|
|
4416
|
-
const autoCompletion = ((
|
|
4417
|
+
const autoCompletion = ((_g = (_f = props.uischema) === null || _f === void 0 ? void 0 : _f.options) === null || _g === void 0 ? void 0 : _g.autoComplete) === true;
|
|
4417
4418
|
const mergedOptions = useMemo(() => {
|
|
4418
4419
|
const newOptions = [...((registerData === null || registerData === void 0 ? void 0 : registerData.map(d => {
|
|
4419
4420
|
if (typeof d === 'string') {
|
|
@@ -4445,8 +4446,8 @@ const GoAInputText = props => {
|
|
|
4445
4446
|
const appliedUiSchemaOptions = Object.assign(Object.assign({}, config), uischema === null || uischema === void 0 ? void 0 : uischema.options);
|
|
4446
4447
|
const placeholder = (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.placeholder) || (schema === null || schema === void 0 ? void 0 : schema.description) || '';
|
|
4447
4448
|
const isSinField = schema.title === sinTitle;
|
|
4448
|
-
const autoCapitalize = ((
|
|
4449
|
-
const readOnly = (
|
|
4449
|
+
const autoCapitalize = ((_j = (_h = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _h === void 0 ? void 0 : _h.componentProps) === null || _j === void 0 ? void 0 : _j.autoCapitalize) === true || ((_k = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _k === void 0 ? void 0 : _k.autoCapitalize) === true;
|
|
4450
|
+
const readOnly = (_o = (_m = (_l = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _l === void 0 ? void 0 : _l.componentProps) === null || _m === void 0 ? void 0 : _m.readOnly) !== null && _o !== void 0 ? _o : false;
|
|
4450
4451
|
return jsx("div", {
|
|
4451
4452
|
children: mergedOptions.length > 0 ? jsx(Dropdown, {
|
|
4452
4453
|
items: mergedOptions,
|
|
@@ -4463,11 +4464,11 @@ const GoAInputText = props => {
|
|
|
4463
4464
|
type: appliedUiSchemaOptions.format === 'password' ? 'password' : 'text',
|
|
4464
4465
|
disabled: !enabled,
|
|
4465
4466
|
value: data,
|
|
4466
|
-
width:
|
|
4467
|
+
width: width,
|
|
4467
4468
|
readonly: readOnly,
|
|
4468
4469
|
maxLength: isSinField ? 11 : '',
|
|
4469
4470
|
placeholder: placeholder
|
|
4470
|
-
}, (
|
|
4471
|
+
}, (_p = uischema.options) === null || _p === void 0 ? void 0 : _p.componentProps, {
|
|
4471
4472
|
// maxLength={appliedUiSchemaOptions?.maxLength}
|
|
4472
4473
|
name: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.name) || `${id || label}-input`,
|
|
4473
4474
|
testId: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.testId) || `${id}-input`,
|
|
@@ -4495,7 +4496,7 @@ const GoAInputText = props => {
|
|
|
4495
4496
|
value: autoCapitalize ? value.toUpperCase() : value
|
|
4496
4497
|
});
|
|
4497
4498
|
}
|
|
4498
|
-
}, (
|
|
4499
|
+
}, (_q = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _q === void 0 ? void 0 : _q.componentProps))
|
|
4499
4500
|
});
|
|
4500
4501
|
};
|
|
4501
4502
|
const GoATextControl = props => jsx(GoAInputBaseControl, Object.assign({}, props, {
|
|
@@ -4525,7 +4526,7 @@ const MultiLineText = props => {
|
|
|
4525
4526
|
const [textAreaValue, _] = React.useState(data);
|
|
4526
4527
|
const appliedUiSchemaOptions = Object.assign(Object.assign({}, config), uischema === null || uischema === void 0 ? void 0 : uischema.options);
|
|
4527
4528
|
const placeholder = (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.placeholder) || (schema === null || schema === void 0 ? void 0 : schema.description) || '';
|
|
4528
|
-
const width = (_c = (_b = (_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.componentProps) === null || _b === void 0 ? void 0 : _b.
|
|
4529
|
+
const width = (_c = (_b = (_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.componentProps) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : '100%';
|
|
4529
4530
|
const autoCapitalize = ((_e = (_d = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _d === void 0 ? void 0 : _d.componentProps) === null || _e === void 0 ? void 0 : _e.autoCapitalize) === true || ((_f = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _f === void 0 ? void 0 : _f.autoCapitalize) === true;
|
|
4530
4531
|
const readOnly = (_j = (_h = (_g = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _g === void 0 ? void 0 : _g.componentProps) === null || _h === void 0 ? void 0 : _h.readOnly) !== null && _j !== void 0 ? _j : false;
|
|
4531
4532
|
const textAreaName = `${label || path}-text-area` || '';
|
|
@@ -7379,6 +7380,7 @@ const ListContainer = styled.div(_t14 || (_t14 = _$2`
|
|
|
7379
7380
|
`));
|
|
7380
7381
|
const TableTHHeader = styled.th(_t15 || (_t15 = _$2`
|
|
7381
7382
|
background-color: var(--goa-color-greyscale-100) !important;
|
|
7383
|
+
vertical-align: top;
|
|
7382
7384
|
`));
|
|
7383
7385
|
const ObjectArrayWarningIconDiv = styled.div(_t16 || (_t16 = _$2`
|
|
7384
7386
|
display: inline-flex;
|
|
@@ -7483,6 +7485,21 @@ const ObjectArrayToolBar = /*#__PURE__*/React.memo(function TableToolbar({
|
|
|
7483
7485
|
});
|
|
7484
7486
|
});
|
|
7485
7487
|
|
|
7488
|
+
const extractNestedFields = (properties, propertyKeys) => {
|
|
7489
|
+
const nestedItems = {};
|
|
7490
|
+
propertyKeys.forEach(key => {
|
|
7491
|
+
var _a, _b;
|
|
7492
|
+
if (properties[key].type === 'array') {
|
|
7493
|
+
const propItems = properties[key] && ((_a = properties[key].items) === null || _a === void 0 ? void 0 : _a.properties) || [];
|
|
7494
|
+
const propReqItems = properties[key].items && ((_b = properties[key].items) === null || _b === void 0 ? void 0 : _b.required) || [];
|
|
7495
|
+
nestedItems[key] = {
|
|
7496
|
+
properties: [...Object.keys(propItems)],
|
|
7497
|
+
required: [...Object.keys(propReqItems)]
|
|
7498
|
+
};
|
|
7499
|
+
}
|
|
7500
|
+
});
|
|
7501
|
+
return nestedItems;
|
|
7502
|
+
};
|
|
7486
7503
|
/**
|
|
7487
7504
|
* Extract Json data schema name attribute and the ui schema label name.
|
|
7488
7505
|
* @param obj
|
|
@@ -7507,9 +7524,17 @@ const extractNames = (obj, names = {}) => {
|
|
|
7507
7524
|
}
|
|
7508
7525
|
return names;
|
|
7509
7526
|
};
|
|
7527
|
+
const isObjectArrayEmpty = currentData => {
|
|
7528
|
+
const result = isEmpty$1(currentData) || JSON.stringify(currentData) === '[{}]';
|
|
7529
|
+
return result;
|
|
7530
|
+
};
|
|
7510
7531
|
const renderCellColumn = ({
|
|
7511
7532
|
currentData,
|
|
7512
7533
|
error,
|
|
7534
|
+
errors,
|
|
7535
|
+
index,
|
|
7536
|
+
rowPath,
|
|
7537
|
+
element,
|
|
7513
7538
|
isRequired
|
|
7514
7539
|
}) => {
|
|
7515
7540
|
const renderWarningCell = data => {
|
|
@@ -7531,12 +7556,18 @@ const renderCellColumn = ({
|
|
|
7531
7556
|
} else if (currentData !== undefined && isRequired && error) {
|
|
7532
7557
|
return renderWarningCell(currentData);
|
|
7533
7558
|
}
|
|
7559
|
+
const path = `/${rowPath}/${index}/${element}/${index === 0 ? index : index - 1}`;
|
|
7560
|
+
const nestedErrors = errors === null || errors === void 0 ? void 0 : errors.filter(e => e.instancePath.includes(path));
|
|
7534
7561
|
if (typeof currentData === 'string') {
|
|
7535
7562
|
return currentData;
|
|
7536
7563
|
} else if (typeof currentData === 'object' || Array.isArray(currentData)) {
|
|
7537
7564
|
const result = Object.keys(currentData);
|
|
7538
7565
|
if (result.length === 0) {
|
|
7539
7566
|
return renderWarningCell();
|
|
7567
|
+
} else if (result.length > 0 && (isObjectArrayEmpty(currentData) || nestedErrors.length > 0)) {
|
|
7568
|
+
return jsx("pre", {
|
|
7569
|
+
children: renderWarningCell(JSON.stringify(currentData, null, 2))
|
|
7570
|
+
});
|
|
7540
7571
|
} else if (currentData !== undefined && result.length > 0 && error !== '' && error !== undefined) {
|
|
7541
7572
|
const values = Object.values(currentData);
|
|
7542
7573
|
if (values && values.length > 0) {
|
|
@@ -7646,6 +7677,8 @@ const NonEmptyCellComponent$1 = /*#__PURE__*/React.memo(function NonEmptyCellCom
|
|
|
7646
7677
|
} = props;
|
|
7647
7678
|
const properties = (schema === null || schema === void 0 ? void 0 : schema.items) && 'properties' in schema.items && schema.items.properties || {};
|
|
7648
7679
|
const required = (_a = schema.items) === null || _a === void 0 ? void 0 : _a.required;
|
|
7680
|
+
const propertyKeys = Object.keys(properties);
|
|
7681
|
+
const nestedItems = extractNestedFields(properties, propertyKeys);
|
|
7649
7682
|
let tableKeys = extractNames((_b = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _b === void 0 ? void 0 : _b.detail);
|
|
7650
7683
|
if (Object.keys(tableKeys).length === 0) {
|
|
7651
7684
|
Object.keys(properties).forEach(item => {
|
|
@@ -7682,6 +7715,7 @@ const NonEmptyCellComponent$1 = /*#__PURE__*/React.memo(function NonEmptyCellCom
|
|
|
7682
7715
|
children: [jsx("thead", {
|
|
7683
7716
|
children: jsxs("tr", {
|
|
7684
7717
|
children: [Object.entries(tableKeys).map(([value, index]) => {
|
|
7718
|
+
var _a;
|
|
7685
7719
|
if (!isInReview) {
|
|
7686
7720
|
return jsx("th", {
|
|
7687
7721
|
children: jsxs("p", {
|
|
@@ -7693,7 +7727,7 @@ const NonEmptyCellComponent$1 = /*#__PURE__*/React.memo(function NonEmptyCellCom
|
|
|
7693
7727
|
}
|
|
7694
7728
|
return jsx(TableTHHeader, {
|
|
7695
7729
|
children: jsxs("p", {
|
|
7696
|
-
children: [`${convertToSentenceCase(index)}`, (required === null || required === void 0 ? void 0 : required.includes(value)) && jsxs(RequiredSpan, {
|
|
7730
|
+
children: [`${convertToSentenceCase(index)}`, ((required === null || required === void 0 ? void 0 : required.includes(value)) || ((_a = nestedItems[value]) === null || _a === void 0 ? void 0 : _a.required.length) > 0) && jsxs(RequiredSpan, {
|
|
7697
7731
|
children: [jsx("br", {}), " (required)"]
|
|
7698
7732
|
})]
|
|
7699
7733
|
})
|
|
@@ -7729,7 +7763,12 @@ const NonEmptyCellComponent$1 = /*#__PURE__*/React.memo(function NonEmptyCellCom
|
|
|
7729
7763
|
children: renderCellColumn({
|
|
7730
7764
|
currentData,
|
|
7731
7765
|
error: error === null || error === void 0 ? void 0 : error.message,
|
|
7732
|
-
isRequired: required === null || required === void 0 ? void 0 : required.includes(tableKeys[element])
|
|
7766
|
+
isRequired: required === null || required === void 0 ? void 0 : required.includes(tableKeys[element]),
|
|
7767
|
+
errors: errors !== undefined ? errors : [],
|
|
7768
|
+
count: count !== undefined ? count : -1,
|
|
7769
|
+
element,
|
|
7770
|
+
rowPath,
|
|
7771
|
+
index: i
|
|
7733
7772
|
})
|
|
7734
7773
|
})
|
|
7735
7774
|
}, ix);
|
|
@@ -7779,7 +7818,7 @@ const NonEmptyCellComponent$1 = /*#__PURE__*/React.memo(function NonEmptyCellCom
|
|
|
7779
7818
|
})
|
|
7780
7819
|
})
|
|
7781
7820
|
})]
|
|
7782
|
-
}, `${i}-${num}`);
|
|
7821
|
+
}, `${rowPath}-${i}-${num}`);
|
|
7783
7822
|
})
|
|
7784
7823
|
})]
|
|
7785
7824
|
}), hasAnyErrors && isInReview && jsx(GoAFormItem, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.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",
|
|
@@ -11,10 +11,15 @@ export interface DataProperty {
|
|
|
11
11
|
maxLength?: number;
|
|
12
12
|
required?: string[];
|
|
13
13
|
enum: string[];
|
|
14
|
+
items?: Record<string, unknown>;
|
|
14
15
|
}
|
|
15
16
|
export interface DataObject {
|
|
16
17
|
[key: string]: DataProperty;
|
|
17
18
|
}
|
|
19
|
+
export interface NestedItem {
|
|
20
|
+
properties: string[];
|
|
21
|
+
required: string[];
|
|
22
|
+
}
|
|
18
23
|
export interface Items {
|
|
19
24
|
type: string;
|
|
20
25
|
properties: DataObject;
|
|
@@ -96,4 +101,9 @@ export interface RenderCellColumnProps {
|
|
|
96
101
|
error: string | undefined;
|
|
97
102
|
isRequired: boolean;
|
|
98
103
|
tableKeys?: string[];
|
|
104
|
+
errors: ErrorObject[];
|
|
105
|
+
count: number;
|
|
106
|
+
rowPath: string;
|
|
107
|
+
index: number;
|
|
108
|
+
element: string;
|
|
99
109
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { RenderCellColumnProps } from './ObjectListControlTypes';
|
|
1
|
+
import { DataObject, NestedItem, RenderCellColumnProps } from './ObjectListControlTypes';
|
|
2
|
+
export declare const extractNestedFields: (properties: DataObject, propertyKeys: string[]) => Record<string, NestedItem>;
|
|
2
3
|
/**
|
|
3
4
|
* Extract Json data schema name attribute and the ui schema label name.
|
|
4
5
|
* @param obj
|
|
@@ -6,4 +7,5 @@ import { RenderCellColumnProps } from './ObjectListControlTypes';
|
|
|
6
7
|
* @returns A key value of the data attribute name and the uiSchema label value
|
|
7
8
|
*/
|
|
8
9
|
export declare const extractNames: (obj: unknown, names?: Record<string, string>) => Record<string, string>;
|
|
9
|
-
export declare const
|
|
10
|
+
export declare const isObjectArrayEmpty: (currentData: string) => boolean;
|
|
11
|
+
export declare const renderCellColumn: ({ currentData, error, errors, index, rowPath, element, isRequired, }: RenderCellColumnProps) => string | import("react/jsx-runtime").JSX.Element | null;
|