@rjsf/utils 5.15.0 → 5.16.0
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/dist/index.js +29 -0
- package/dist/index.js.map +3 -3
- package/dist/utils.esm.js +29 -0
- package/dist/utils.esm.js.map +3 -3
- package/dist/utils.umd.js +29 -0
- package/lib/getDateElementProps.d.ts +19 -0
- package/lib/getDateElementProps.js +31 -0
- package/lib/getDateElementProps.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -19
- package/src/getDateElementProps.ts +56 -0
- package/src/index.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.16.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -43,29 +43,29 @@
|
|
|
43
43
|
"react-is": "^18.2.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@babel/core": "^7.
|
|
46
|
+
"@babel/core": "^7.23.7",
|
|
47
47
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
48
48
|
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
49
|
-
"@babel/preset-env": "^7.
|
|
50
|
-
"@babel/preset-react": "^7.
|
|
51
|
-
"@babel/preset-typescript": "^7.
|
|
52
|
-
"@types/jest": "^29.5.
|
|
53
|
-
"@types/json-schema": "^7.0.
|
|
54
|
-
"@types/json-schema-merge-allof": "^0.6.
|
|
55
|
-
"@types/lodash": "^4.14.
|
|
56
|
-
"@types/react": "^17.0.
|
|
57
|
-
"@types/react-is": "^17.0.
|
|
58
|
-
"@types/react-test-renderer": "^17.0.
|
|
59
|
-
"babel-jest": "^29.
|
|
49
|
+
"@babel/preset-env": "^7.23.7",
|
|
50
|
+
"@babel/preset-react": "^7.23.3",
|
|
51
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
52
|
+
"@types/jest": "^29.5.11",
|
|
53
|
+
"@types/json-schema": "^7.0.15",
|
|
54
|
+
"@types/json-schema-merge-allof": "^0.6.5",
|
|
55
|
+
"@types/lodash": "^4.14.202",
|
|
56
|
+
"@types/react": "^17.0.74",
|
|
57
|
+
"@types/react-is": "^17.0.7",
|
|
58
|
+
"@types/react-test-renderer": "^17.0.9",
|
|
59
|
+
"babel-jest": "^29.7.0",
|
|
60
60
|
"deep-freeze-es6": "^1.4.1",
|
|
61
61
|
"esbuild": "^0.18.20",
|
|
62
|
-
"eslint": "^8.
|
|
63
|
-
"jest": "^29.
|
|
64
|
-
"jest-environment-jsdom": "^29.
|
|
62
|
+
"eslint": "^8.56.0",
|
|
63
|
+
"jest": "^29.7.0",
|
|
64
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
65
65
|
"react": "^17.0.2",
|
|
66
66
|
"react-test-renderer": "^17.0.2",
|
|
67
|
-
"rimraf": "^5.0.
|
|
68
|
-
"rollup": "^3.29.
|
|
67
|
+
"rimraf": "^5.0.5",
|
|
68
|
+
"rollup": "^3.29.4",
|
|
69
69
|
"typescript": "^4.9.5"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"url": "git+https://github.com/rjsf-team/react-jsonschema-form.git"
|
|
87
87
|
},
|
|
88
88
|
"license": "Apache-2.0",
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "c7ed12043fdd91bc1344ffd7c9404deac31374a7"
|
|
90
90
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type DateObject } from './types';
|
|
2
|
+
|
|
3
|
+
/** Available options for re-ordering date input element */
|
|
4
|
+
export type DateElementFormat = 'DMY' | 'MDY' | 'YMD';
|
|
5
|
+
|
|
6
|
+
/** Type describing format of DateElement prop */
|
|
7
|
+
type DateElementProp = {
|
|
8
|
+
type: string;
|
|
9
|
+
range: [number, number];
|
|
10
|
+
value: number | undefined;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Given date & time information with optional yearRange & format, returns props for DateElement
|
|
14
|
+
*
|
|
15
|
+
* @param date - Object containing date with optional time information
|
|
16
|
+
* @param time - Determines whether to include time or not
|
|
17
|
+
* @param [yearRange=[1900, new Date().getFullYear() + 2]] - Controls the list of years to be displayed
|
|
18
|
+
* @param [format='YMD'] - Controls the order in which day, month and year input element will be displayed
|
|
19
|
+
* @returns Array of props for DateElement
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export default function getDateElementProps(
|
|
23
|
+
date: DateObject,
|
|
24
|
+
time: boolean,
|
|
25
|
+
yearRange: [number, number] = [1900, new Date().getFullYear() + 2],
|
|
26
|
+
format: DateElementFormat = 'YMD'
|
|
27
|
+
) {
|
|
28
|
+
const { day, month, year, hour, minute, second } = date;
|
|
29
|
+
|
|
30
|
+
const dayObj: DateElementProp = { type: 'day', range: [1, 31], value: day };
|
|
31
|
+
const monthObj: DateElementProp = { type: 'month', range: [1, 12], value: month };
|
|
32
|
+
const yearObj: DateElementProp = { type: 'year', range: yearRange, value: year };
|
|
33
|
+
|
|
34
|
+
const dateElementProp: DateElementProp[] = [];
|
|
35
|
+
switch (format) {
|
|
36
|
+
case 'MDY':
|
|
37
|
+
dateElementProp.push(monthObj, dayObj, yearObj);
|
|
38
|
+
break;
|
|
39
|
+
case 'DMY':
|
|
40
|
+
dateElementProp.push(dayObj, monthObj, yearObj);
|
|
41
|
+
break;
|
|
42
|
+
case 'YMD':
|
|
43
|
+
default:
|
|
44
|
+
dateElementProp.push(yearObj, monthObj, dayObj);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (time) {
|
|
48
|
+
dateElementProp.push(
|
|
49
|
+
{ type: 'hour', range: [0, 23], value: hour },
|
|
50
|
+
{ type: 'minute', range: [0, 59], value: minute },
|
|
51
|
+
{ type: 'second', range: [0, 59], value: second }
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return dateElementProp;
|
|
56
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import enumOptionsSelectValue from './enumOptionsSelectValue';
|
|
|
13
13
|
import enumOptionsValueForIndex from './enumOptionsValueForIndex';
|
|
14
14
|
import ErrorSchemaBuilder from './ErrorSchemaBuilder';
|
|
15
15
|
import findSchemaDefinition from './findSchemaDefinition';
|
|
16
|
+
import getDateElementProps, { type DateElementFormat } from './getDateElementProps';
|
|
16
17
|
import getDiscriminatorFieldFromSchema from './getDiscriminatorFieldFromSchema';
|
|
17
18
|
import getInputProps from './getInputProps';
|
|
18
19
|
import getSchemaType from './getSchemaType';
|
|
@@ -65,6 +66,7 @@ export {
|
|
|
65
66
|
canExpand,
|
|
66
67
|
createErrorHandler,
|
|
67
68
|
createSchemaUtils,
|
|
69
|
+
DateElementFormat,
|
|
68
70
|
dataURItoBlob,
|
|
69
71
|
deepEquals,
|
|
70
72
|
descriptionId,
|
|
@@ -78,6 +80,7 @@ export {
|
|
|
78
80
|
examplesId,
|
|
79
81
|
ErrorSchemaBuilder,
|
|
80
82
|
findSchemaDefinition,
|
|
83
|
+
getDateElementProps,
|
|
81
84
|
getDiscriminatorFieldFromSchema,
|
|
82
85
|
getInputProps,
|
|
83
86
|
getOptionMatchingSimpleDiscriminator,
|