@sphereon/ui-components.ssi-react 0.4.1-unstable.62 → 0.4.1-unstable.65

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.
@@ -2,45 +2,32 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { JsonForms } from '@jsonforms/react';
3
3
  import { materialCells } from '@jsonforms/material-renderers';
4
4
  import { jsonFormsMaterialRenderers } from '../../../renders/jsonFormsRenders';
5
- import { formatDateToISO } from '../../../helpers';
6
- const initializeDefaultValues = (schema, currentData = {}) => {
7
- const result = { ...currentData };
8
- if (!schema.properties) {
9
- return result;
10
- }
11
- Object.entries(schema.properties).forEach(([key, property]) => {
12
- if (typeof property === 'object') {
13
- if (property.const && (!(key in result) || !result[key])) {
14
- result[key] = property.const;
15
- }
16
- if (property.default !== undefined && !(key in result)) {
17
- if (property.format?.startsWith('date') || property.format?.startsWith('time')) {
18
- result[key] = formatDateToISO(property.default, property.format);
19
- }
20
- else if (typeof property.default === 'object') {
21
- result[key] = Array.isArray(property.default)
22
- ? [...property.default]
23
- : { ...property.default };
24
- }
25
- else {
26
- result[key] = property.default;
27
- }
28
- }
29
- if (property.properties) {
30
- if (!result[key]) {
31
- result[key] = {};
32
- }
33
- result[key] = initializeDefaultValues(property, result[key]);
5
+ import Ajv from 'ajv';
6
+ const defaultAjv = new Ajv({ useDefaults: true });
7
+ defaultAjv.addKeyword({
8
+ keyword: 'isoDateFormat',
9
+ modifying: true,
10
+ validate: function (schema, data, parentSchema, dataCxt) {
11
+ if (typeof data === 'string') {
12
+ const date = data === 'now' ? new Date() : new Date(data);
13
+ if (!isNaN(date.getTime()) && dataCxt?.parentData && dataCxt.parentDataProperty !== undefined) {
14
+ dataCxt.parentData[dataCxt.parentDataProperty] =
15
+ schema === 'date-time'
16
+ ? date.toISOString().slice(0, 19).replace('T', ' ')
17
+ : schema === 'date'
18
+ ? date.toISOString().slice(0, 10)
19
+ : date.toISOString().slice(11, 19);
34
20
  }
21
+ return true;
35
22
  }
36
- });
37
- return result;
38
- };
23
+ return false;
24
+ }
25
+ });
39
26
  const FormView = (props) => {
40
- const { data, schema, uiSchema, validationMode = 'ValidateAndShow', renderers = jsonFormsMaterialRenderers, cells = materialCells, style, middleware, ajv, onFormStateChange, readonly = false, config, } = props;
27
+ const { data, schema, uiSchema, validationMode = 'ValidateAndShow', renderers = jsonFormsMaterialRenderers, cells = materialCells, style, middleware, ajv = defaultAjv, onFormStateChange, readonly = false, config, } = props;
41
28
  const onFormStateChanged = (state) => {
42
29
  void onFormStateChange?.(state);
43
30
  };
44
- return (_jsx("div", { style: style, children: _jsx(JsonForms, { schema: schema, uischema: uiSchema, data: data, renderers: renderers, onChange: onFormStateChanged }) }));
31
+ return (_jsx("div", { style: style, children: _jsx(JsonForms, { schema: schema, uischema: uiSchema, data: data, renderers: renderers, onChange: onFormStateChanged, ajv: ajv }) }));
45
32
  };
46
33
  export default FormView;
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.62+bb961c4",
4
+ "version": "0.4.1-unstable.65+dcd820e",
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": "^6.19.5",
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.62+bb961c4",
53
+ "@sphereon/ui-components.core": "0.4.1-unstable.65+dcd820e",
54
54
  "@tanstack/react-table": "^8.9.3",
55
55
  "react-dom": "npm:react-dom@18.3.1",
56
56
  "react-json-tree": "^0.18.0",
@@ -70,5 +70,5 @@
70
70
  "peerDependencies": {
71
71
  "react": ">= 18"
72
72
  },
73
- "gitHead": "bb961c42496a4acb2551ff66186ec2db44a41f84"
73
+ "gitHead": "dcd820eb985d5f34747dc784678d7d5739a87fe9"
74
74
  }