@remoteoss/json-schema-form 0.5.0-dev.20230705114115 → 0.5.0-dev.20230717103306
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.cjs +82 -9
- package/dist/index.js +82 -9
- package/dist/standalone.js +82 -9
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +56 -0
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.5.0-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.5.0-dev.20230717103306
|
|
5
|
+
Generated: Mon, 17 Jul 2023 10:33:17 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -350,6 +350,13 @@ function convertDiskSizeFromTo(from, to) {
|
|
|
350
350
|
return value * Math.pow(1024, units.indexOf(from.toLowerCase())) / Math.pow(1024, units.indexOf(to.toLowerCase()));
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
|
+
function containsHTML(str = "") {
|
|
354
|
+
return /<[a-z][\s\S]*>/i.test(str);
|
|
355
|
+
}
|
|
356
|
+
function wrapWithSpan(html, properties = {}) {
|
|
357
|
+
const attributes = Object.entries(properties).reduce((acc, [key, value]) => `${acc}${key}="${value}" `, "").trim();
|
|
358
|
+
return `<span ${attributes}>${html}</span>`;
|
|
359
|
+
}
|
|
353
360
|
function hasProperty(object2, propertyName) {
|
|
354
361
|
return Object.prototype.hasOwnProperty.call(object2, propertyName);
|
|
355
362
|
}
|
|
@@ -374,6 +381,31 @@ var validateOnlyStrings = (0, import_yup.string)().trim().nullable().test(
|
|
|
374
381
|
return true;
|
|
375
382
|
}
|
|
376
383
|
);
|
|
384
|
+
var compareDates = (d1, d2) => {
|
|
385
|
+
let date1 = new Date(d1).getTime();
|
|
386
|
+
let date2 = new Date(d2).getTime();
|
|
387
|
+
if (date1 < date2) {
|
|
388
|
+
return "LESSER";
|
|
389
|
+
} else if (date1 > date2) {
|
|
390
|
+
return "GREATER";
|
|
391
|
+
} else {
|
|
392
|
+
return "EQUAL";
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
var validateMinDate = (value, minDate) => {
|
|
396
|
+
if (!value) {
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
const compare = compareDates(value, minDate);
|
|
400
|
+
return compare === "GREATER" || compare === "EQUAL" ? true : false;
|
|
401
|
+
};
|
|
402
|
+
var validateMaxDate = (value, minDate) => {
|
|
403
|
+
if (!value) {
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
const compare = compareDates(value, minDate);
|
|
407
|
+
return compare === "LESSER" || compare === "EQUAL" ? true : false;
|
|
408
|
+
};
|
|
377
409
|
var yupSchemas = {
|
|
378
410
|
text: validateOnlyStrings,
|
|
379
411
|
radioOrSelect: (options) => (0, import_yup.string)().nullable().transform((value) => {
|
|
@@ -387,10 +419,46 @@ var yupSchemas = {
|
|
|
387
419
|
}).oneOf(options, ({ value }) => {
|
|
388
420
|
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
389
421
|
}),
|
|
390
|
-
date: (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
422
|
+
date: ({ minDate, maxDate }) => {
|
|
423
|
+
if (minDate && maxDate) {
|
|
424
|
+
return (0, import_yup.string)().nullable().trim().matches(
|
|
425
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
426
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
427
|
+
).test(
|
|
428
|
+
"minDate",
|
|
429
|
+
`The date must be ${minDate} or after`,
|
|
430
|
+
(value) => validateMinDate(value, minDate)
|
|
431
|
+
).test(
|
|
432
|
+
"maxDate",
|
|
433
|
+
`The date must be ${maxDate} or before`,
|
|
434
|
+
(value) => validateMaxDate(value, maxDate)
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
if (minDate) {
|
|
438
|
+
return (0, import_yup.string)().nullable().trim().matches(
|
|
439
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
440
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
441
|
+
).test(
|
|
442
|
+
"minDate",
|
|
443
|
+
`The date must be ${minDate} or after`,
|
|
444
|
+
(value) => validateMinDate(value, minDate)
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
if (maxDate) {
|
|
448
|
+
return (0, import_yup.string)().nullable().trim().matches(
|
|
449
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
450
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
451
|
+
).test(
|
|
452
|
+
"maxDate",
|
|
453
|
+
`The date must be ${maxDate} or before`,
|
|
454
|
+
(value) => validateMaxDate(value, maxDate)
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
return (0, import_yup.string)().nullable().trim().matches(
|
|
458
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
459
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
460
|
+
);
|
|
461
|
+
},
|
|
394
462
|
number: (0, import_yup.number)().typeError("The value must be a number").nullable(),
|
|
395
463
|
file: (0, import_yup.array)().nullable(),
|
|
396
464
|
email: (0, import_yup.string)().trim().email("Please enter a valid email address").nullable(),
|
|
@@ -435,6 +503,9 @@ var getYupSchema = ({ inputType, ...field }) => {
|
|
|
435
503
|
const optionValues = getOptions(field);
|
|
436
504
|
return yupSchemas.radioOrSelect(optionValues);
|
|
437
505
|
}
|
|
506
|
+
if (inputType === "date") {
|
|
507
|
+
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
|
508
|
+
}
|
|
438
509
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
439
510
|
};
|
|
440
511
|
function buildYupSchema(field, config) {
|
|
@@ -871,7 +942,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
871
942
|
const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
|
|
872
943
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
873
944
|
const description = presentation?.description || node.description;
|
|
874
|
-
const statementDescription = presentation.statement?.description;
|
|
945
|
+
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
875
946
|
return (0, import_omitBy.default)(
|
|
876
947
|
{
|
|
877
948
|
label: node.title,
|
|
@@ -907,8 +978,10 @@ function extractParametersFromNode(schemaNode) {
|
|
|
907
978
|
},
|
|
908
979
|
// Handle [name].presentation
|
|
909
980
|
...presentation,
|
|
910
|
-
description,
|
|
911
|
-
|
|
981
|
+
description: containsHTML(description) ? wrapWithSpan(description, {
|
|
982
|
+
class: "jsf-description"
|
|
983
|
+
}) : description,
|
|
984
|
+
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
912
985
|
statement: presentation.statement && {
|
|
913
986
|
...presentation.statement,
|
|
914
987
|
description: statementDescription
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.5.0-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.5.0-dev.20230717103306
|
|
5
|
+
Generated: Mon, 17 Jul 2023 10:33:17 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -314,6 +314,13 @@ function convertDiskSizeFromTo(from, to) {
|
|
|
314
314
|
return value * Math.pow(1024, units.indexOf(from.toLowerCase())) / Math.pow(1024, units.indexOf(to.toLowerCase()));
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
|
+
function containsHTML(str = "") {
|
|
318
|
+
return /<[a-z][\s\S]*>/i.test(str);
|
|
319
|
+
}
|
|
320
|
+
function wrapWithSpan(html, properties = {}) {
|
|
321
|
+
const attributes = Object.entries(properties).reduce((acc, [key, value]) => `${acc}${key}="${value}" `, "").trim();
|
|
322
|
+
return `<span ${attributes}>${html}</span>`;
|
|
323
|
+
}
|
|
317
324
|
function hasProperty(object2, propertyName) {
|
|
318
325
|
return Object.prototype.hasOwnProperty.call(object2, propertyName);
|
|
319
326
|
}
|
|
@@ -338,6 +345,31 @@ var validateOnlyStrings = string().trim().nullable().test(
|
|
|
338
345
|
return true;
|
|
339
346
|
}
|
|
340
347
|
);
|
|
348
|
+
var compareDates = (d1, d2) => {
|
|
349
|
+
let date1 = new Date(d1).getTime();
|
|
350
|
+
let date2 = new Date(d2).getTime();
|
|
351
|
+
if (date1 < date2) {
|
|
352
|
+
return "LESSER";
|
|
353
|
+
} else if (date1 > date2) {
|
|
354
|
+
return "GREATER";
|
|
355
|
+
} else {
|
|
356
|
+
return "EQUAL";
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
var validateMinDate = (value, minDate) => {
|
|
360
|
+
if (!value) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
const compare = compareDates(value, minDate);
|
|
364
|
+
return compare === "GREATER" || compare === "EQUAL" ? true : false;
|
|
365
|
+
};
|
|
366
|
+
var validateMaxDate = (value, minDate) => {
|
|
367
|
+
if (!value) {
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
const compare = compareDates(value, minDate);
|
|
371
|
+
return compare === "LESSER" || compare === "EQUAL" ? true : false;
|
|
372
|
+
};
|
|
341
373
|
var yupSchemas = {
|
|
342
374
|
text: validateOnlyStrings,
|
|
343
375
|
radioOrSelect: (options) => string().nullable().transform((value) => {
|
|
@@ -351,10 +383,46 @@ var yupSchemas = {
|
|
|
351
383
|
}).oneOf(options, ({ value }) => {
|
|
352
384
|
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
353
385
|
}),
|
|
354
|
-
date:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
386
|
+
date: ({ minDate, maxDate }) => {
|
|
387
|
+
if (minDate && maxDate) {
|
|
388
|
+
return string().nullable().trim().matches(
|
|
389
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
390
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
391
|
+
).test(
|
|
392
|
+
"minDate",
|
|
393
|
+
`The date must be ${minDate} or after`,
|
|
394
|
+
(value) => validateMinDate(value, minDate)
|
|
395
|
+
).test(
|
|
396
|
+
"maxDate",
|
|
397
|
+
`The date must be ${maxDate} or before`,
|
|
398
|
+
(value) => validateMaxDate(value, maxDate)
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
if (minDate) {
|
|
402
|
+
return string().nullable().trim().matches(
|
|
403
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
404
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
405
|
+
).test(
|
|
406
|
+
"minDate",
|
|
407
|
+
`The date must be ${minDate} or after`,
|
|
408
|
+
(value) => validateMinDate(value, minDate)
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
if (maxDate) {
|
|
412
|
+
return string().nullable().trim().matches(
|
|
413
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
414
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
415
|
+
).test(
|
|
416
|
+
"maxDate",
|
|
417
|
+
`The date must be ${maxDate} or before`,
|
|
418
|
+
(value) => validateMaxDate(value, maxDate)
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
return string().nullable().trim().matches(
|
|
422
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
423
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
424
|
+
);
|
|
425
|
+
},
|
|
358
426
|
number: number().typeError("The value must be a number").nullable(),
|
|
359
427
|
file: array().nullable(),
|
|
360
428
|
email: string().trim().email("Please enter a valid email address").nullable(),
|
|
@@ -399,6 +467,9 @@ var getYupSchema = ({ inputType, ...field }) => {
|
|
|
399
467
|
const optionValues = getOptions(field);
|
|
400
468
|
return yupSchemas.radioOrSelect(optionValues);
|
|
401
469
|
}
|
|
470
|
+
if (inputType === "date") {
|
|
471
|
+
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
|
472
|
+
}
|
|
402
473
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
403
474
|
};
|
|
404
475
|
function buildYupSchema(field, config) {
|
|
@@ -835,7 +906,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
835
906
|
const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
|
|
836
907
|
const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
837
908
|
const description = presentation?.description || node.description;
|
|
838
|
-
const statementDescription = presentation.statement?.description;
|
|
909
|
+
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
839
910
|
return omitBy(
|
|
840
911
|
{
|
|
841
912
|
label: node.title,
|
|
@@ -871,8 +942,10 @@ function extractParametersFromNode(schemaNode) {
|
|
|
871
942
|
},
|
|
872
943
|
// Handle [name].presentation
|
|
873
944
|
...presentation,
|
|
874
|
-
description,
|
|
875
|
-
|
|
945
|
+
description: containsHTML(description) ? wrapWithSpan(description, {
|
|
946
|
+
class: "jsf-description"
|
|
947
|
+
}) : description,
|
|
948
|
+
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
876
949
|
statement: presentation.statement && {
|
|
877
950
|
...presentation.statement,
|
|
878
951
|
description: statementDescription
|
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.5.0-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.5.0-dev.20230717103306
|
|
5
|
+
Generated: Mon, 17 Jul 2023 10:33:17 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11291,6 +11291,13 @@ function convertDiskSizeFromTo(from2, to) {
|
|
|
11291
11291
|
return value * Math.pow(1024, units.indexOf(from2.toLowerCase())) / Math.pow(1024, units.indexOf(to.toLowerCase()));
|
|
11292
11292
|
};
|
|
11293
11293
|
}
|
|
11294
|
+
function containsHTML(str = "") {
|
|
11295
|
+
return /<[a-z][\s\S]*>/i.test(str);
|
|
11296
|
+
}
|
|
11297
|
+
function wrapWithSpan(html, properties = {}) {
|
|
11298
|
+
const attributes = Object.entries(properties).reduce((acc, [key, value]) => `${acc}${key}="${value}" `, "").trim();
|
|
11299
|
+
return `<span ${attributes}>${html}</span>`;
|
|
11300
|
+
}
|
|
11294
11301
|
function hasProperty(object2, propertyName) {
|
|
11295
11302
|
return Object.prototype.hasOwnProperty.call(object2, propertyName);
|
|
11296
11303
|
}
|
|
@@ -11314,6 +11321,31 @@ var validateOnlyStrings = StringSchema().trim().nullable().test(
|
|
|
11314
11321
|
return true;
|
|
11315
11322
|
}
|
|
11316
11323
|
);
|
|
11324
|
+
var compareDates = (d1, d2) => {
|
|
11325
|
+
let date1 = new Date(d1).getTime();
|
|
11326
|
+
let date2 = new Date(d2).getTime();
|
|
11327
|
+
if (date1 < date2) {
|
|
11328
|
+
return "LESSER";
|
|
11329
|
+
} else if (date1 > date2) {
|
|
11330
|
+
return "GREATER";
|
|
11331
|
+
} else {
|
|
11332
|
+
return "EQUAL";
|
|
11333
|
+
}
|
|
11334
|
+
};
|
|
11335
|
+
var validateMinDate = (value, minDate) => {
|
|
11336
|
+
if (!value) {
|
|
11337
|
+
return true;
|
|
11338
|
+
}
|
|
11339
|
+
const compare = compareDates(value, minDate);
|
|
11340
|
+
return compare === "GREATER" || compare === "EQUAL" ? true : false;
|
|
11341
|
+
};
|
|
11342
|
+
var validateMaxDate = (value, minDate) => {
|
|
11343
|
+
if (!value) {
|
|
11344
|
+
return true;
|
|
11345
|
+
}
|
|
11346
|
+
const compare = compareDates(value, minDate);
|
|
11347
|
+
return compare === "LESSER" || compare === "EQUAL" ? true : false;
|
|
11348
|
+
};
|
|
11317
11349
|
var yupSchemas = {
|
|
11318
11350
|
text: validateOnlyStrings,
|
|
11319
11351
|
radioOrSelect: (options) => StringSchema().nullable().transform((value) => {
|
|
@@ -11327,10 +11359,46 @@ var yupSchemas = {
|
|
|
11327
11359
|
}).oneOf(options, ({ value }) => {
|
|
11328
11360
|
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
11329
11361
|
}),
|
|
11330
|
-
date:
|
|
11331
|
-
|
|
11332
|
-
|
|
11333
|
-
|
|
11362
|
+
date: ({ minDate, maxDate }) => {
|
|
11363
|
+
if (minDate && maxDate) {
|
|
11364
|
+
return StringSchema().nullable().trim().matches(
|
|
11365
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
11366
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
11367
|
+
).test(
|
|
11368
|
+
"minDate",
|
|
11369
|
+
`The date must be ${minDate} or after`,
|
|
11370
|
+
(value) => validateMinDate(value, minDate)
|
|
11371
|
+
).test(
|
|
11372
|
+
"maxDate",
|
|
11373
|
+
`The date must be ${maxDate} or before`,
|
|
11374
|
+
(value) => validateMaxDate(value, maxDate)
|
|
11375
|
+
);
|
|
11376
|
+
}
|
|
11377
|
+
if (minDate) {
|
|
11378
|
+
return StringSchema().nullable().trim().matches(
|
|
11379
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
11380
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
11381
|
+
).test(
|
|
11382
|
+
"minDate",
|
|
11383
|
+
`The date must be ${minDate} or after`,
|
|
11384
|
+
(value) => validateMinDate(value, minDate)
|
|
11385
|
+
);
|
|
11386
|
+
}
|
|
11387
|
+
if (maxDate) {
|
|
11388
|
+
return StringSchema().nullable().trim().matches(
|
|
11389
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
11390
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
11391
|
+
).test(
|
|
11392
|
+
"maxDate",
|
|
11393
|
+
`The date must be ${maxDate} or before`,
|
|
11394
|
+
(value) => validateMaxDate(value, maxDate)
|
|
11395
|
+
);
|
|
11396
|
+
}
|
|
11397
|
+
return StringSchema().nullable().trim().matches(
|
|
11398
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
11399
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
11400
|
+
);
|
|
11401
|
+
},
|
|
11334
11402
|
number: NumberSchema().typeError("The value must be a number").nullable(),
|
|
11335
11403
|
file: array_default().nullable(),
|
|
11336
11404
|
email: StringSchema().trim().email("Please enter a valid email address").nullable(),
|
|
@@ -11375,6 +11443,9 @@ var getYupSchema = ({ inputType, ...field }) => {
|
|
|
11375
11443
|
const optionValues = getOptions(field);
|
|
11376
11444
|
return yupSchemas.radioOrSelect(optionValues);
|
|
11377
11445
|
}
|
|
11446
|
+
if (inputType === "date") {
|
|
11447
|
+
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
|
11448
|
+
}
|
|
11378
11449
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
11379
11450
|
};
|
|
11380
11451
|
function buildYupSchema(field, config) {
|
|
@@ -11811,7 +11882,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
11811
11882
|
const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
|
|
11812
11883
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
11813
11884
|
const description = presentation?.description || node.description;
|
|
11814
|
-
const statementDescription = presentation.statement?.description;
|
|
11885
|
+
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
11815
11886
|
return (0, import_omitBy.default)(
|
|
11816
11887
|
{
|
|
11817
11888
|
label: node.title,
|
|
@@ -11847,8 +11918,10 @@ function extractParametersFromNode(schemaNode) {
|
|
|
11847
11918
|
},
|
|
11848
11919
|
// Handle [name].presentation
|
|
11849
11920
|
...presentation,
|
|
11850
|
-
description,
|
|
11851
|
-
|
|
11921
|
+
description: containsHTML(description) ? wrapWithSpan(description, {
|
|
11922
|
+
class: "jsf-description"
|
|
11923
|
+
}) : description,
|
|
11924
|
+
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
11852
11925
|
statement: presentation.statement && {
|
|
11853
11926
|
...presentation.statement,
|
|
11854
11927
|
description: statementDescription
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
3
|
+
"version": "0.5.0-dev.20230717103306",
|
|
4
4
|
"description": "Headless UI form powered by JSON Schemas",
|
|
5
5
|
"author": "Remote.com <engineering@remote.com> (https://remote.com/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1035,6 +1035,62 @@ describe('createHeadlessForm', () => {
|
|
|
1035
1035
|
);
|
|
1036
1036
|
});
|
|
1037
1037
|
|
|
1038
|
+
it('support "date" field type with a minDate', () => {
|
|
1039
|
+
const result = createHeadlessForm(schemaInputTypeDate);
|
|
1040
|
+
|
|
1041
|
+
expect(result).toMatchObject({
|
|
1042
|
+
fields: [
|
|
1043
|
+
{
|
|
1044
|
+
label: 'Birthdate',
|
|
1045
|
+
name: 'birthdate',
|
|
1046
|
+
required: true,
|
|
1047
|
+
schema: expect.any(Object),
|
|
1048
|
+
type: 'date',
|
|
1049
|
+
maxLength: 10,
|
|
1050
|
+
minDate: '1922-03-01',
|
|
1051
|
+
maxDate: '2022-03-01',
|
|
1052
|
+
},
|
|
1053
|
+
],
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
const fieldValidator = result.fields[0].schema;
|
|
1057
|
+
const todayDateHint = new Date().toISOString().substring(0, 10);
|
|
1058
|
+
expect(fieldValidator.isValidSync('1922-02-01')).toBe(false);
|
|
1059
|
+
expect(fieldValidator.isValidSync('1922-03-01')).toBe(true);
|
|
1060
|
+
expect(fieldValidator.isValidSync('2021-03-01')).toBe(true);
|
|
1061
|
+
expect(() => fieldValidator.validateSync('')).toThrowError(
|
|
1062
|
+
`Must be a valid date in yyyy-mm-dd format. e.g. ${todayDateHint}`
|
|
1063
|
+
);
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
it('support "date" field type with a maxDate', () => {
|
|
1067
|
+
const result = createHeadlessForm(schemaInputTypeDate);
|
|
1068
|
+
|
|
1069
|
+
expect(result).toMatchObject({
|
|
1070
|
+
fields: [
|
|
1071
|
+
{
|
|
1072
|
+
label: 'Birthdate',
|
|
1073
|
+
name: 'birthdate',
|
|
1074
|
+
required: true,
|
|
1075
|
+
schema: expect.any(Object),
|
|
1076
|
+
type: 'date',
|
|
1077
|
+
maxLength: 10,
|
|
1078
|
+
minDate: '1922-03-01',
|
|
1079
|
+
maxDate: '2022-03-01',
|
|
1080
|
+
},
|
|
1081
|
+
],
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
const fieldValidator = result.fields[0].schema;
|
|
1085
|
+
const todayDateHint = new Date().toISOString().substring(0, 10);
|
|
1086
|
+
expect(fieldValidator.isValidSync('2022-02-01')).toBe(true);
|
|
1087
|
+
expect(fieldValidator.isValidSync('2022-03-01')).toBe(true);
|
|
1088
|
+
expect(fieldValidator.isValidSync('2022-04-01')).toBe(false);
|
|
1089
|
+
expect(() => fieldValidator.validateSync('')).toThrowError(
|
|
1090
|
+
`Must be a valid date in yyyy-mm-dd format. e.g. ${todayDateHint}`
|
|
1091
|
+
);
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1038
1094
|
it('supports "file" field type', () => {
|
|
1039
1095
|
const result = createHeadlessForm(
|
|
1040
1096
|
JSONSchemaBuilder()
|