@sphereon/ui-components.ssi-react 0.4.1-unstable.143 → 0.4.1-unstable.145
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CSSProperties, ReactElement } from 'react';
|
|
2
2
|
import { JsonFormsCellRendererRegistryEntry, JsonFormsRendererRegistryEntry, JsonSchema, Middleware, UISchemaElement, ValidationMode } from '@jsonforms/core';
|
|
3
|
-
import { JSONFormState } from '../../../types';
|
|
4
3
|
import Ajv from 'ajv';
|
|
4
|
+
import { JSONFormState } from '../../../types';
|
|
5
5
|
type Props<DataType = Record<any, any>> = {
|
|
6
6
|
schema: JsonSchema;
|
|
7
7
|
uiSchema: UISchemaElement;
|
|
@@ -3,30 +3,9 @@ import { useEffect, useState } from 'react';
|
|
|
3
3
|
import { JsonForms } from '@jsonforms/react';
|
|
4
4
|
import { materialCells } from '@jsonforms/material-renderers';
|
|
5
5
|
import { jsonFormsMaterialRenderers } from '../../../renders/jsonFormsRenders';
|
|
6
|
-
import
|
|
7
|
-
import addFormats from "ajv-formats";
|
|
8
|
-
import { formatDate } from '../../../helpers';
|
|
9
|
-
const defaultAjv = new Ajv({ useDefaults: true });
|
|
10
|
-
addFormats(defaultAjv);
|
|
11
|
-
defaultAjv.addKeyword({
|
|
12
|
-
keyword: 'isoDateFormat',
|
|
13
|
-
modifying: true,
|
|
14
|
-
validate: (schema, data, parentSchema, dataCxt) => {
|
|
15
|
-
if (typeof data === 'string') {
|
|
16
|
-
if (!dataCxt?.parentData || dataCxt.parentDataProperty === undefined) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
const formatted = formatDate(data, schema);
|
|
20
|
-
if (formatted && formatted !== 'Invalid date') {
|
|
21
|
-
dataCxt.parentData[dataCxt.parentDataProperty] = formatted;
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
6
|
+
import { createFormViewAjv } from '../../../utils/Ajv';
|
|
28
7
|
const FormView = (props) => {
|
|
29
|
-
const { schema, uiSchema, validationMode = 'ValidateAndShow', renderers = jsonFormsMaterialRenderers, cells = materialCells, style, middleware, ajv =
|
|
8
|
+
const { schema, uiSchema, validationMode = 'ValidateAndShow', renderers = jsonFormsMaterialRenderers, cells = materialCells, style, middleware, ajv = createFormViewAjv(), onFormStateChange, readonly = false, config, } = props;
|
|
30
9
|
const [data, setData] = useState(props.data);
|
|
31
10
|
useEffect(() => {
|
|
32
11
|
const validate = ajv.compile(schema);
|
|
@@ -37,4 +16,4 @@ const FormView = (props) => {
|
|
|
37
16
|
return (_jsx("div", { style: style, children: _jsx(JsonForms, { schema: schema, uischema: uiSchema, data: data, renderers: renderers, cells: cells, onChange: onFormStateChange, validationMode: validationMode, middleware: middleware, ajv: ajv, readonly: readonly, config: config }) }));
|
|
38
17
|
};
|
|
39
18
|
export default FormView;
|
|
40
|
-
export const getFormViewAjv = () =>
|
|
19
|
+
export const getFormViewAjv = () => createFormViewAjv();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateFormat } from '../helpers';
|
|
2
|
+
import Ajv, { AnySchemaObject } from 'ajv';
|
|
3
|
+
import { DataValidationCxt } from 'ajv/dist/types';
|
|
4
|
+
export declare const createFormViewAjv: () => Ajv;
|
|
5
|
+
export declare const isDateFormatKeyword: {
|
|
6
|
+
keyword: string;
|
|
7
|
+
modifying: boolean;
|
|
8
|
+
validate: (schema: DateFormat, data: any, parentSchema: AnySchemaObject | undefined, dataCxt: DataValidationCxt<string | number> | undefined) => boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { formatDate } from '../helpers';
|
|
2
|
+
import Ajv from 'ajv';
|
|
3
|
+
import addFormats from 'ajv-formats';
|
|
4
|
+
export const createFormViewAjv = () => {
|
|
5
|
+
const ajv = new Ajv({ useDefaults: true });
|
|
6
|
+
addFormats(ajv);
|
|
7
|
+
ajv.addKeyword(isDateFormatKeyword);
|
|
8
|
+
return ajv;
|
|
9
|
+
};
|
|
10
|
+
export const isDateFormatKeyword = {
|
|
11
|
+
keyword: 'isoDateFormat',
|
|
12
|
+
modifying: true,
|
|
13
|
+
validate: (schema, data, parentSchema, dataCxt) => {
|
|
14
|
+
if (typeof data === 'string') {
|
|
15
|
+
if (!dataCxt?.parentData || dataCxt.parentDataProperty === undefined) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
const formatted = formatDate(data, schema);
|
|
19
|
+
if (formatted && formatted !== 'Invalid date') {
|
|
20
|
+
dataCxt.parentData[dataCxt.parentDataProperty] = formatted;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ui-components.ssi-react",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.4.1-unstable.
|
|
4
|
+
"version": "0.4.1-unstable.145+a269d2a",
|
|
5
5
|
"description": "SSI UI components for React",
|
|
6
6
|
"repository": "git@github.com:Sphereon-Opensource/UI-Components.git",
|
|
7
7
|
"author": "Sphereon <dev@sphereon.com>",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@mui/x-date-pickers": "^8.18.0",
|
|
51
51
|
"@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.45.94",
|
|
52
52
|
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.45.94",
|
|
53
|
-
"@sphereon/ui-components.core": "0.4.1-unstable.
|
|
53
|
+
"@sphereon/ui-components.core": "0.4.1-unstable.145+a269d2a",
|
|
54
54
|
"@tanstack/react-table": "^8.9.3",
|
|
55
55
|
"ajv": "^8.17.1",
|
|
56
56
|
"ajv-formats": "^3.0.1",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"react": ">= 18"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "a269d2ac92bc763a502f84a0b125d6d931b0501f"
|
|
76
76
|
}
|