@sphereon/ui-components.ssi-react 0.4.1-unstable.169 → 0.4.1-unstable.171

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.
@@ -7,25 +7,23 @@ import addFormats from 'ajv-formats';
7
7
  import { formatDate } from '../../../helpers';
8
8
  import { createFormViewAjv } from '../../../utils/Ajv';
9
9
  import { jsonFormsMaterialRenderers } from '../../../renders/jsonFormsRenders';
10
- const defaultAjv = new Ajv({ useDefaults: true });
11
- addFormats(defaultAjv);
12
- defaultAjv.addKeyword({
13
- keyword: 'dateFormat',
14
- modifying: true,
15
- validate: (dateFormat, data, parentSchema, dataCxt) => {
16
- if (typeof data === 'string') {
17
- if (!dataCxt?.parentData || dataCxt.parentDataProperty === undefined) {
18
- return true;
19
- }
20
- const formatted = formatDate(data, dateFormat);
21
- if (formatted && formatted !== 'Invalid date') {
22
- dataCxt.parentData[dataCxt.parentDataProperty] = formatted;
23
- }
10
+ const dateFormatValidator = (dateFormat, data, parentSchema, dataCxt) => {
11
+ if (typeof data === 'string') {
12
+ if (!dataCxt?.parentData || dataCxt.parentDataProperty === undefined) {
24
13
  return true;
25
14
  }
26
- return false;
15
+ const formatted = formatDate(data, dateFormat);
16
+ if (formatted && formatted !== 'Invalid date') {
17
+ dataCxt.parentData[dataCxt.parentDataProperty] = formatted;
18
+ }
19
+ return true;
27
20
  }
28
- });
21
+ return false;
22
+ };
23
+ const defaultAjv = new Ajv({ useDefaults: true });
24
+ addFormats(defaultAjv);
25
+ defaultAjv.addKeyword({ keyword: 'dateFormat', modifying: true, validate: dateFormatValidator });
26
+ defaultAjv.addKeyword({ keyword: 'isoDateFormat', modifying: true, validate: dateFormatValidator });
29
27
  const FormView = (props) => {
30
28
  const { schema, uiSchema, validationMode = 'ValidateAndShow', renderers = jsonFormsMaterialRenderers, cells = materialCells, style, middleware, onFormStateChange, readonly = false, config, } = props;
31
29
  const [data, setData] = useState(props.data);
@@ -1,2 +1,3 @@
1
1
  export type DateFormat = 'date-time' | 'date' | 'time' | 'iso-date-time' | 'iso-date' | 'iso-time' | undefined;
2
2
  export declare const formatDate: (dateString?: string, format?: DateFormat | string) => string;
3
+ export declare const formatDateToISO: (dateString?: string, format?: DateFormat) => string;
@@ -26,6 +26,11 @@ const applyCustomFormat = (date, format) => {
26
26
  i = closeIdx + 1;
27
27
  continue;
28
28
  }
29
+ else {
30
+ result += char;
31
+ i += 1;
32
+ continue;
33
+ }
29
34
  }
30
35
  const token = orderedTokens.find((t) => format.startsWith(t, i));
31
36
  if (token) {
@@ -84,3 +89,12 @@ export const formatDate = (dateString, format = 'date-time') => {
84
89
  return date.toString();
85
90
  }
86
91
  };
92
+ export const formatDateToISO = (dateString, format = 'date-time') => {
93
+ if (format === 'date-time')
94
+ return formatDate(dateString, 'iso-date-time');
95
+ if (format === 'date')
96
+ return formatDate(dateString, 'iso-date');
97
+ if (format === 'time')
98
+ return formatDate(dateString, 'iso-time');
99
+ return formatDate(dateString, format);
100
+ };
@@ -1,9 +1,14 @@
1
1
  import { DateFormat } from '../helpers';
2
2
  import Ajv, { AnySchemaObject } from 'ajv';
3
3
  import { DataValidationCxt } from 'ajv/dist/types';
4
- export declare const createFormViewAjv: () => Ajv;
4
+ export declare const dateFormatAjvKeyword: {
5
+ keyword: string;
6
+ modifying: boolean;
7
+ validate: (schema: DateFormat | string, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt) => boolean;
8
+ };
5
9
  export declare const isDateFormatAjvKeyword: {
6
10
  keyword: string;
7
11
  modifying: boolean;
8
- validate: (schema: DateFormat, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt) => boolean;
12
+ validate: (schema: DateFormat | string, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt) => boolean;
9
13
  };
14
+ export declare const createFormViewAjv: () => Ajv;
package/dist/utils/Ajv.js CHANGED
@@ -1,26 +1,33 @@
1
1
  import { formatDate } from '../helpers';
2
2
  import Ajv from 'ajv';
3
3
  import addFormats from 'ajv-formats';
4
+ const dateFormatValidator = (schema, data, parentSchema, dataCxt) => {
5
+ if (typeof data === 'string') {
6
+ if (!dataCxt?.parentData || dataCxt.parentDataProperty === undefined) {
7
+ return true;
8
+ }
9
+ const formatted = formatDate(data, schema);
10
+ if (formatted && formatted !== 'Invalid date') {
11
+ dataCxt.parentData[dataCxt.parentDataProperty] = formatted;
12
+ }
13
+ return true;
14
+ }
15
+ return false;
16
+ };
17
+ export const dateFormatAjvKeyword = {
18
+ keyword: 'dateFormat',
19
+ modifying: true,
20
+ validate: dateFormatValidator,
21
+ };
22
+ export const isDateFormatAjvKeyword = {
23
+ keyword: 'isoDateFormat',
24
+ modifying: true,
25
+ validate: dateFormatValidator,
26
+ };
4
27
  export const createFormViewAjv = () => {
5
28
  const ajv = new Ajv({ useDefaults: true });
6
29
  addFormats(ajv);
30
+ ajv.addKeyword(dateFormatAjvKeyword);
7
31
  ajv.addKeyword(isDateFormatAjvKeyword);
8
32
  return ajv;
9
33
  };
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.169+31255b3",
4
+ "version": "0.4.1-unstable.171+f7cbb44",
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-types": "0.36.1-next.159",
52
52
  "@sphereon/ssi-types": "0.36.1-next.159",
53
- "@sphereon/ui-components.core": "0.4.1-unstable.169+31255b3",
53
+ "@sphereon/ui-components.core": "0.4.1-unstable.171+f7cbb44",
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": "31255b3215b56170050a1e6cd85c4a279b57625a"
75
+ "gitHead": "f7cbb440c40f1dcb7fe3e28b3888a403cefd9900"
76
76
  }