@sphereon/ui-components.ssi-react 0.4.1-unstable.149 → 0.4.1-unstable.151
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,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { JsonForms } from '@jsonforms/react';
|
|
4
4
|
import { materialCells } from '@jsonforms/material-renderers';
|
|
5
5
|
import Ajv from 'ajv';
|
|
6
6
|
import addFormats from "ajv-formats";
|
|
7
7
|
import { formatDate } from '../../../helpers';
|
|
8
|
+
import { createFormViewAjv } from '../../../utils/Ajv';
|
|
8
9
|
import { jsonFormsMaterialRenderers } from '../../../renders/jsonFormsRenders';
|
|
9
10
|
const defaultAjv = new Ajv({ useDefaults: true });
|
|
10
11
|
addFormats(defaultAjv);
|
|
@@ -26,8 +27,13 @@ defaultAjv.addKeyword({
|
|
|
26
27
|
}
|
|
27
28
|
});
|
|
28
29
|
const FormView = (props) => {
|
|
29
|
-
const { schema, uiSchema, validationMode = 'ValidateAndShow', renderers = jsonFormsMaterialRenderers, cells = materialCells, style, middleware,
|
|
30
|
+
const { schema, uiSchema, validationMode = 'ValidateAndShow', renderers = jsonFormsMaterialRenderers, cells = materialCells, style, middleware, onFormStateChange, readonly = false, config, } = props;
|
|
30
31
|
const [data, setData] = useState(props.data);
|
|
32
|
+
const ajvRef = useRef(null);
|
|
33
|
+
if (!ajvRef.current) {
|
|
34
|
+
ajvRef.current = props.ajv ?? createFormViewAjv();
|
|
35
|
+
}
|
|
36
|
+
const ajv = ajvRef.current;
|
|
31
37
|
useEffect(() => {
|
|
32
38
|
const validate = ajv.compile(schema);
|
|
33
39
|
const data = props.data;
|
|
@@ -37,4 +43,4 @@ const FormView = (props) => {
|
|
|
37
43
|
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
44
|
};
|
|
39
45
|
export default FormView;
|
|
40
|
-
export const getFormViewAjv = () =>
|
|
46
|
+
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 isDateFormatAjvKeyword: {
|
|
6
|
+
keyword: string;
|
|
7
|
+
modifying: boolean;
|
|
8
|
+
validate: (schema: DateFormat, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt) => 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(isDateFormatAjvKeyword);
|
|
8
|
+
return ajv;
|
|
9
|
+
};
|
|
10
|
+
export const isDateFormatAjvKeyword = {
|
|
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.151+b3cd72d",
|
|
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.151+b3cd72d",
|
|
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": "b3cd72dcef59c82c8fe454666e0d77f00a98f815"
|
|
76
76
|
}
|