@remoteoss/json-schema-form 0.5.0-dev.20230705114115 → 0.5.0-dev.20230717090149
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 +76 -9
- package/dist/index.js +76 -9
- package/dist/standalone.js +76 -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.20230717090149
|
|
5
|
+
Generated: Mon, 17 Jul 2023 09:02:11 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,25 @@ 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
|
+
const compare = compareDates(value, minDate);
|
|
397
|
+
return compare === "GREATER" || compare === "EQUAL" ? true : false;
|
|
398
|
+
};
|
|
399
|
+
var validateMaxDate = (value, minDate) => {
|
|
400
|
+
const compare = compareDates(value, minDate);
|
|
401
|
+
return compare === "LESSER" || compare === "EQUAL" ? true : false;
|
|
402
|
+
};
|
|
377
403
|
var yupSchemas = {
|
|
378
404
|
text: validateOnlyStrings,
|
|
379
405
|
radioOrSelect: (options) => (0, import_yup.string)().nullable().transform((value) => {
|
|
@@ -387,10 +413,46 @@ var yupSchemas = {
|
|
|
387
413
|
}).oneOf(options, ({ value }) => {
|
|
388
414
|
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
389
415
|
}),
|
|
390
|
-
date: (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
416
|
+
date: ({ minDate, maxDate }) => {
|
|
417
|
+
if (minDate && maxDate) {
|
|
418
|
+
return (0, import_yup.string)().nullable().trim().matches(
|
|
419
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
420
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
421
|
+
).test(
|
|
422
|
+
"minDate",
|
|
423
|
+
`The date must be ${minDate} or after`,
|
|
424
|
+
(value) => validateMinDate(value, minDate)
|
|
425
|
+
).test(
|
|
426
|
+
"maxDate",
|
|
427
|
+
`The date must be ${maxDate} or before`,
|
|
428
|
+
(value) => validateMaxDate(value, maxDate)
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
if (minDate) {
|
|
432
|
+
return (0, import_yup.string)().nullable().trim().matches(
|
|
433
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
434
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
435
|
+
).test(
|
|
436
|
+
"minDate",
|
|
437
|
+
`The date must be ${minDate} or after`,
|
|
438
|
+
(value) => validateMinDate(value, minDate)
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
if (maxDate) {
|
|
442
|
+
return (0, import_yup.string)().nullable().trim().matches(
|
|
443
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
444
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
445
|
+
).test(
|
|
446
|
+
"maxDate",
|
|
447
|
+
`The date must be ${maxDate} or before`,
|
|
448
|
+
(value) => validateMaxDate(value, maxDate)
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
return (0, import_yup.string)().nullable().trim().matches(
|
|
452
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
453
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
454
|
+
);
|
|
455
|
+
},
|
|
394
456
|
number: (0, import_yup.number)().typeError("The value must be a number").nullable(),
|
|
395
457
|
file: (0, import_yup.array)().nullable(),
|
|
396
458
|
email: (0, import_yup.string)().trim().email("Please enter a valid email address").nullable(),
|
|
@@ -435,6 +497,9 @@ var getYupSchema = ({ inputType, ...field }) => {
|
|
|
435
497
|
const optionValues = getOptions(field);
|
|
436
498
|
return yupSchemas.radioOrSelect(optionValues);
|
|
437
499
|
}
|
|
500
|
+
if (inputType === "date") {
|
|
501
|
+
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
|
502
|
+
}
|
|
438
503
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
439
504
|
};
|
|
440
505
|
function buildYupSchema(field, config) {
|
|
@@ -871,7 +936,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
871
936
|
const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
|
|
872
937
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
873
938
|
const description = presentation?.description || node.description;
|
|
874
|
-
const statementDescription = presentation.statement?.description;
|
|
939
|
+
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
875
940
|
return (0, import_omitBy.default)(
|
|
876
941
|
{
|
|
877
942
|
label: node.title,
|
|
@@ -907,8 +972,10 @@ function extractParametersFromNode(schemaNode) {
|
|
|
907
972
|
},
|
|
908
973
|
// Handle [name].presentation
|
|
909
974
|
...presentation,
|
|
910
|
-
description,
|
|
911
|
-
|
|
975
|
+
description: containsHTML(description) ? wrapWithSpan(description, {
|
|
976
|
+
class: "jsf-description"
|
|
977
|
+
}) : description,
|
|
978
|
+
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
912
979
|
statement: presentation.statement && {
|
|
913
980
|
...presentation.statement,
|
|
914
981
|
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.20230717090149
|
|
5
|
+
Generated: Mon, 17 Jul 2023 09:02:11 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,25 @@ 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
|
+
const compare = compareDates(value, minDate);
|
|
361
|
+
return compare === "GREATER" || compare === "EQUAL" ? true : false;
|
|
362
|
+
};
|
|
363
|
+
var validateMaxDate = (value, minDate) => {
|
|
364
|
+
const compare = compareDates(value, minDate);
|
|
365
|
+
return compare === "LESSER" || compare === "EQUAL" ? true : false;
|
|
366
|
+
};
|
|
341
367
|
var yupSchemas = {
|
|
342
368
|
text: validateOnlyStrings,
|
|
343
369
|
radioOrSelect: (options) => string().nullable().transform((value) => {
|
|
@@ -351,10 +377,46 @@ var yupSchemas = {
|
|
|
351
377
|
}).oneOf(options, ({ value }) => {
|
|
352
378
|
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
353
379
|
}),
|
|
354
|
-
date:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
380
|
+
date: ({ minDate, maxDate }) => {
|
|
381
|
+
if (minDate && maxDate) {
|
|
382
|
+
return string().nullable().trim().matches(
|
|
383
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
384
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
385
|
+
).test(
|
|
386
|
+
"minDate",
|
|
387
|
+
`The date must be ${minDate} or after`,
|
|
388
|
+
(value) => validateMinDate(value, minDate)
|
|
389
|
+
).test(
|
|
390
|
+
"maxDate",
|
|
391
|
+
`The date must be ${maxDate} or before`,
|
|
392
|
+
(value) => validateMaxDate(value, maxDate)
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
if (minDate) {
|
|
396
|
+
return string().nullable().trim().matches(
|
|
397
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
398
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
399
|
+
).test(
|
|
400
|
+
"minDate",
|
|
401
|
+
`The date must be ${minDate} or after`,
|
|
402
|
+
(value) => validateMinDate(value, minDate)
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
if (maxDate) {
|
|
406
|
+
return string().nullable().trim().matches(
|
|
407
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
408
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
409
|
+
).test(
|
|
410
|
+
"maxDate",
|
|
411
|
+
`The date must be ${maxDate} or before`,
|
|
412
|
+
(value) => validateMaxDate(value, maxDate)
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
return string().nullable().trim().matches(
|
|
416
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
417
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
418
|
+
);
|
|
419
|
+
},
|
|
358
420
|
number: number().typeError("The value must be a number").nullable(),
|
|
359
421
|
file: array().nullable(),
|
|
360
422
|
email: string().trim().email("Please enter a valid email address").nullable(),
|
|
@@ -399,6 +461,9 @@ var getYupSchema = ({ inputType, ...field }) => {
|
|
|
399
461
|
const optionValues = getOptions(field);
|
|
400
462
|
return yupSchemas.radioOrSelect(optionValues);
|
|
401
463
|
}
|
|
464
|
+
if (inputType === "date") {
|
|
465
|
+
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
|
466
|
+
}
|
|
402
467
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
403
468
|
};
|
|
404
469
|
function buildYupSchema(field, config) {
|
|
@@ -835,7 +900,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
835
900
|
const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
|
|
836
901
|
const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
837
902
|
const description = presentation?.description || node.description;
|
|
838
|
-
const statementDescription = presentation.statement?.description;
|
|
903
|
+
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
839
904
|
return omitBy(
|
|
840
905
|
{
|
|
841
906
|
label: node.title,
|
|
@@ -871,8 +936,10 @@ function extractParametersFromNode(schemaNode) {
|
|
|
871
936
|
},
|
|
872
937
|
// Handle [name].presentation
|
|
873
938
|
...presentation,
|
|
874
|
-
description,
|
|
875
|
-
|
|
939
|
+
description: containsHTML(description) ? wrapWithSpan(description, {
|
|
940
|
+
class: "jsf-description"
|
|
941
|
+
}) : description,
|
|
942
|
+
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
876
943
|
statement: presentation.statement && {
|
|
877
944
|
...presentation.statement,
|
|
878
945
|
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.20230717090149
|
|
5
|
+
Generated: Mon, 17 Jul 2023 09:02:11 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,25 @@ 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
|
+
const compare = compareDates(value, minDate);
|
|
11337
|
+
return compare === "GREATER" || compare === "EQUAL" ? true : false;
|
|
11338
|
+
};
|
|
11339
|
+
var validateMaxDate = (value, minDate) => {
|
|
11340
|
+
const compare = compareDates(value, minDate);
|
|
11341
|
+
return compare === "LESSER" || compare === "EQUAL" ? true : false;
|
|
11342
|
+
};
|
|
11317
11343
|
var yupSchemas = {
|
|
11318
11344
|
text: validateOnlyStrings,
|
|
11319
11345
|
radioOrSelect: (options) => StringSchema().nullable().transform((value) => {
|
|
@@ -11327,10 +11353,46 @@ var yupSchemas = {
|
|
|
11327
11353
|
}).oneOf(options, ({ value }) => {
|
|
11328
11354
|
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
11329
11355
|
}),
|
|
11330
|
-
date:
|
|
11331
|
-
|
|
11332
|
-
|
|
11333
|
-
|
|
11356
|
+
date: ({ minDate, maxDate }) => {
|
|
11357
|
+
if (minDate && maxDate) {
|
|
11358
|
+
return StringSchema().nullable().trim().matches(
|
|
11359
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
11360
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
11361
|
+
).test(
|
|
11362
|
+
"minDate",
|
|
11363
|
+
`The date must be ${minDate} or after`,
|
|
11364
|
+
(value) => validateMinDate(value, minDate)
|
|
11365
|
+
).test(
|
|
11366
|
+
"maxDate",
|
|
11367
|
+
`The date must be ${maxDate} or before`,
|
|
11368
|
+
(value) => validateMaxDate(value, maxDate)
|
|
11369
|
+
);
|
|
11370
|
+
}
|
|
11371
|
+
if (minDate) {
|
|
11372
|
+
return StringSchema().nullable().trim().matches(
|
|
11373
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
11374
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
11375
|
+
).test(
|
|
11376
|
+
"minDate",
|
|
11377
|
+
`The date must be ${minDate} or after`,
|
|
11378
|
+
(value) => validateMinDate(value, minDate)
|
|
11379
|
+
);
|
|
11380
|
+
}
|
|
11381
|
+
if (maxDate) {
|
|
11382
|
+
return StringSchema().nullable().trim().matches(
|
|
11383
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
11384
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
11385
|
+
).test(
|
|
11386
|
+
"maxDate",
|
|
11387
|
+
`The date must be ${maxDate} or before`,
|
|
11388
|
+
(value) => validateMaxDate(value, maxDate)
|
|
11389
|
+
);
|
|
11390
|
+
}
|
|
11391
|
+
return StringSchema().nullable().trim().matches(
|
|
11392
|
+
/(?:\d){4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[0-1])/,
|
|
11393
|
+
`Must be a valid date in ${DEFAULT_DATE_FORMAT.toLocaleLowerCase()} format. e.g. ${todayDateHint}`
|
|
11394
|
+
);
|
|
11395
|
+
},
|
|
11334
11396
|
number: NumberSchema().typeError("The value must be a number").nullable(),
|
|
11335
11397
|
file: array_default().nullable(),
|
|
11336
11398
|
email: StringSchema().trim().email("Please enter a valid email address").nullable(),
|
|
@@ -11375,6 +11437,9 @@ var getYupSchema = ({ inputType, ...field }) => {
|
|
|
11375
11437
|
const optionValues = getOptions(field);
|
|
11376
11438
|
return yupSchemas.radioOrSelect(optionValues);
|
|
11377
11439
|
}
|
|
11440
|
+
if (inputType === "date") {
|
|
11441
|
+
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
|
11442
|
+
}
|
|
11378
11443
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
11379
11444
|
};
|
|
11380
11445
|
function buildYupSchema(field, config) {
|
|
@@ -11811,7 +11876,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
11811
11876
|
const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
|
|
11812
11877
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
11813
11878
|
const description = presentation?.description || node.description;
|
|
11814
|
-
const statementDescription = presentation.statement?.description;
|
|
11879
|
+
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
11815
11880
|
return (0, import_omitBy.default)(
|
|
11816
11881
|
{
|
|
11817
11882
|
label: node.title,
|
|
@@ -11847,8 +11912,10 @@ function extractParametersFromNode(schemaNode) {
|
|
|
11847
11912
|
},
|
|
11848
11913
|
// Handle [name].presentation
|
|
11849
11914
|
...presentation,
|
|
11850
|
-
description,
|
|
11851
|
-
|
|
11915
|
+
description: containsHTML(description) ? wrapWithSpan(description, {
|
|
11916
|
+
class: "jsf-description"
|
|
11917
|
+
}) : description,
|
|
11918
|
+
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
11852
11919
|
statement: presentation.statement && {
|
|
11853
11920
|
...presentation.statement,
|
|
11854
11921
|
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.20230717090149",
|
|
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()
|