@remoteoss/json-schema-form 0.6.5-beta.0 → 0.7.0-dev.20230928101050
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/CHANGELOG.md +37 -7
- package/dist/index.cjs +5 -14
- package/dist/index.js +5 -14
- package/dist/standalone.js +5 -14
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +4 -9
package/CHANGELOG.md
CHANGED
|
@@ -2,36 +2,66 @@
|
|
|
2
2
|
|
|
3
3
|
##### Changes
|
|
4
4
|
|
|
5
|
-
- Add conditional logic checking
|
|
5
|
+
- json-logic: Add conditional logic checking. ([#41](https://github.com/remoteoss/json-schema-form/pull/41)) ([6292b01e](https://github.com/remoteoss/json-schema-form/commit/6292b01e3f77a9038328d7375080ffc4cb30dbc8))
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
###### Full API additions now supported from 0.6.5 onwards.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
- New custom JSON Schema keyword `x-jsf-logic` added to support cross-field validations. Built on top of [JsonLogic](https://jsonlogic.com/).
|
|
12
|
+
|
|
13
|
+
- `x-jsf-logic` can contain:
|
|
14
|
+
|
|
15
|
+
- `validations` - JsonLogic rules that validate fields and return booleans
|
|
16
|
+
- `computedValues` - JsonLogic rules that compute dynamic values
|
|
17
|
+
- `allOf.if/then/else` - Conditional logic using validations and computedValues
|
|
18
|
+
|
|
19
|
+
- New property `x-jsf-logic-validations` added to individual schema properties. Lists the validation names that should run on that property.
|
|
20
|
+
- New property `x-jsf-logic-computedAttrs` added to individual schema properties. Allows computed values to be used for attributes like `title`, `description`, `const`, etc.
|
|
21
|
+
- Computed values and validations defined in `x-jsf-logic` can reference schema properties using `vars` and any syntax supported from [JsonLogic](https://jsonlogic.com/).
|
|
22
|
+
|
|
23
|
+
- Conditional logic blocks allow selectively requiring fields or applying attributes based on validations/computed values.
|
|
24
|
+
|
|
25
|
+
While docs are underway, you can read examples from all the [tests](https://github.com/remoteoss/json-schema-form/blob/main/src/tests/jsonLogic.test.js) along with the [sample schemas](https://github.com/remoteoss/json-schema-form/blob/main/src/tests/jsonLogic.fixtures.js).
|
|
26
|
+
|
|
27
|
+
In short: `x-jsf-logic` is added to support complex conditional cross-field validations. Properties like `x-jsf-logic-validations` allow hooking those up to individual fields.
|
|
28
|
+
|
|
6
29
|
|
|
7
30
|
#### 0.6.4-beta.0 (2023-09-15)
|
|
8
31
|
|
|
9
32
|
|
|
10
33
|
|
|
11
34
|
##### Changes
|
|
35
|
+
- json-logic: computedAttrs - handle inline rules ([#40](https://github.com/remoteoss/json-schema-form/pull/40)) ([860ad91b](https://github.com/remoteoss/json-schema-form/commit/860ad91b034ab35d4d4bc51c0c04675f102bf278))
|
|
36
|
+
|
|
37
|
+
|
|
12
38
|
|
|
13
|
-
* Inline rule handling for computedAttrs ([#40](https://github.com/remoteoss/json-schema-form/pull/40)) ([860ad91b](https://github.com/remoteoss/json-schema-form/commit/860ad91b034ab35d4d4bc51c0c04675f102bf278))
|
|
14
39
|
|
|
15
40
|
#### 0.6.1-beta.0 (2023-09-13)
|
|
16
41
|
|
|
17
42
|
##### Changes
|
|
18
43
|
|
|
44
|
+
- json-logic: Computed string based values ([#37](https://github.com/remoteoss/json-schema-form/pull/37)) ([6e042ea5](https://github.com/remoteoss/json-schema-form/commit/6e042ea579497ea573710c307a6ff7ee2f19b931))
|
|
45
|
+
|
|
19
46
|
|
|
20
47
|
|
|
21
|
-
- Computed string based values for json-logic ([#37](https://github.com/remoteoss/json-schema-form/pull/37)) ([6e042ea5](https://github.com/remoteoss/json-schema-form/commit/6e042ea579497ea573710c307a6ff7ee2f19b931))
|
|
22
48
|
|
|
23
49
|
#### 0.5.0-beta.0 (2023-09-12)
|
|
24
50
|
|
|
25
51
|
##### Changes
|
|
52
|
+
- json-logic: Computed Attributes ([#36](https://github.com/remoteoss/json-schema-form/pull/36)) ([80c29589](https://github.com/remoteoss/json-schema-form/commit/80c29589ac0972e0f33add70a59df15a46db1b43))
|
|
53
|
+
- json-logic: Initial skeleton implementation ([#35](https://github.com/remoteoss/json-schema-form/pull/35)) ([63149ae8](https://github.com/remoteoss/json-schema-form/commit/63149ae863cf1b5ad76a3b2a49c7f343e55ce07b))
|
|
54
|
+
|
|
55
|
+
|
|
26
56
|
|
|
27
|
-
- Computed Attributes ([#36](https://github.com/remoteoss/json-schema-form/pull/36)) ([80c29589](https://github.com/remoteoss/json-schema-form/commit/80c29589ac0972e0f33add70a59df15a46db1b43))
|
|
28
|
-
- JSON Logic Skeleton ([#35](https://github.com/remoteoss/json-schema-form/pull/35)) ([63149ae8](https://github.com/remoteoss/json-schema-form/commit/63149ae863cf1b5ad76a3b2a49c7f343e55ce07b))
|
|
29
57
|
|
|
30
58
|
#### 0.4.5-beta.0 (2023-08-31)
|
|
59
|
+
##### Bug fixes
|
|
60
|
+
|
|
61
|
+
- Validate values based on `const` key ([#34](https://github.com/remoteoss/json-schema-form/pull/34)) ([bf07870d](https://github.com/remoteoss/json-schema-form/commit/bf07870d407d9b9b078882a078b9e4c7928df868))
|
|
62
|
+
|
|
31
63
|
|
|
32
|
-
##### Changes
|
|
33
64
|
|
|
34
|
-
* Allow validation of consts to support single values ([#34](https://github.com/remoteoss/json-schema-form/pull/34)) ([bf07870d](https://github.com/remoteoss/json-schema-form/commit/bf07870d407d9b9b078882a078b9e4c7928df868))
|
|
35
65
|
|
|
36
66
|
#### 0.4.4-beta.0 (2023-08-30)
|
|
37
67
|
|
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
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.0-dev.20230928101050
|
|
5
|
+
Generated: Thu, 28 Sep 2023 10:11:18 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -91,13 +91,6 @@ function convertDiskSizeFromTo(from, to) {
|
|
|
91
91
|
return value * Math.pow(1024, units.indexOf(from.toLowerCase())) / Math.pow(1024, units.indexOf(to.toLowerCase()));
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
function containsHTML(str = "") {
|
|
95
|
-
return /<[a-z][\s\S]*>/i.test(str);
|
|
96
|
-
}
|
|
97
|
-
function wrapWithSpan(html, properties = {}) {
|
|
98
|
-
const attributes = Object.entries(properties).reduce((acc, [key, value]) => `${acc}${key}="${value}" `, "").trim();
|
|
99
|
-
return `<span ${attributes}>${html}</span>`;
|
|
100
|
-
}
|
|
101
94
|
function hasProperty(object2, propertyName) {
|
|
102
95
|
return Object.prototype.hasOwnProperty.call(object2, propertyName);
|
|
103
96
|
}
|
|
@@ -1329,7 +1322,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1329
1322
|
const decoratedComputedAttributes = getDecoratedComputedAttributes(computedAttributes);
|
|
1330
1323
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1331
1324
|
const description = presentation?.description || node.description;
|
|
1332
|
-
const statementDescription =
|
|
1325
|
+
const statementDescription = presentation.statement?.description;
|
|
1333
1326
|
return (0, import_omitBy.default)(
|
|
1334
1327
|
{
|
|
1335
1328
|
const: node.const,
|
|
@@ -1370,10 +1363,8 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1370
1363
|
...presentation,
|
|
1371
1364
|
jsonLogicValidations,
|
|
1372
1365
|
computedAttributes: decoratedComputedAttributes,
|
|
1373
|
-
description
|
|
1374
|
-
|
|
1375
|
-
}) : description,
|
|
1376
|
-
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
1366
|
+
description,
|
|
1367
|
+
extra: presentation.extra,
|
|
1377
1368
|
statement: presentation.statement && {
|
|
1378
1369
|
...presentation.statement,
|
|
1379
1370
|
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
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.0-dev.20230928101050
|
|
5
|
+
Generated: Thu, 28 Sep 2023 10:11:18 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -55,13 +55,6 @@ function convertDiskSizeFromTo(from, to) {
|
|
|
55
55
|
return value * Math.pow(1024, units.indexOf(from.toLowerCase())) / Math.pow(1024, units.indexOf(to.toLowerCase()));
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
function containsHTML(str = "") {
|
|
59
|
-
return /<[a-z][\s\S]*>/i.test(str);
|
|
60
|
-
}
|
|
61
|
-
function wrapWithSpan(html, properties = {}) {
|
|
62
|
-
const attributes = Object.entries(properties).reduce((acc, [key, value]) => `${acc}${key}="${value}" `, "").trim();
|
|
63
|
-
return `<span ${attributes}>${html}</span>`;
|
|
64
|
-
}
|
|
65
58
|
function hasProperty(object2, propertyName) {
|
|
66
59
|
return Object.prototype.hasOwnProperty.call(object2, propertyName);
|
|
67
60
|
}
|
|
@@ -1293,7 +1286,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1293
1286
|
const decoratedComputedAttributes = getDecoratedComputedAttributes(computedAttributes);
|
|
1294
1287
|
const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1295
1288
|
const description = presentation?.description || node.description;
|
|
1296
|
-
const statementDescription =
|
|
1289
|
+
const statementDescription = presentation.statement?.description;
|
|
1297
1290
|
return omitBy(
|
|
1298
1291
|
{
|
|
1299
1292
|
const: node.const,
|
|
@@ -1334,10 +1327,8 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1334
1327
|
...presentation,
|
|
1335
1328
|
jsonLogicValidations,
|
|
1336
1329
|
computedAttributes: decoratedComputedAttributes,
|
|
1337
|
-
description
|
|
1338
|
-
|
|
1339
|
-
}) : description,
|
|
1340
|
-
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
1330
|
+
description,
|
|
1331
|
+
extra: presentation.extra,
|
|
1341
1332
|
statement: presentation.statement && {
|
|
1342
1333
|
...presentation.statement,
|
|
1343
1334
|
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
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.0-dev.20230928101050
|
|
5
|
+
Generated: Thu, 28 Sep 2023 10:11:18 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11410,13 +11410,6 @@ function convertDiskSizeFromTo(from2, to) {
|
|
|
11410
11410
|
return value * Math.pow(1024, units.indexOf(from2.toLowerCase())) / Math.pow(1024, units.indexOf(to.toLowerCase()));
|
|
11411
11411
|
};
|
|
11412
11412
|
}
|
|
11413
|
-
function containsHTML(str = "") {
|
|
11414
|
-
return /<[a-z][\s\S]*>/i.test(str);
|
|
11415
|
-
}
|
|
11416
|
-
function wrapWithSpan(html, properties = {}) {
|
|
11417
|
-
const attributes = Object.entries(properties).reduce((acc, [key, value]) => `${acc}${key}="${value}" `, "").trim();
|
|
11418
|
-
return `<span ${attributes}>${html}</span>`;
|
|
11419
|
-
}
|
|
11420
11413
|
function hasProperty(object2, propertyName) {
|
|
11421
11414
|
return Object.prototype.hasOwnProperty.call(object2, propertyName);
|
|
11422
11415
|
}
|
|
@@ -12647,7 +12640,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12647
12640
|
const decoratedComputedAttributes = getDecoratedComputedAttributes(computedAttributes);
|
|
12648
12641
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
12649
12642
|
const description = presentation?.description || node.description;
|
|
12650
|
-
const statementDescription =
|
|
12643
|
+
const statementDescription = presentation.statement?.description;
|
|
12651
12644
|
return (0, import_omitBy.default)(
|
|
12652
12645
|
{
|
|
12653
12646
|
const: node.const,
|
|
@@ -12688,10 +12681,8 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12688
12681
|
...presentation,
|
|
12689
12682
|
jsonLogicValidations,
|
|
12690
12683
|
computedAttributes: decoratedComputedAttributes,
|
|
12691
|
-
description
|
|
12692
|
-
|
|
12693
|
-
}) : description,
|
|
12694
|
-
extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
|
|
12684
|
+
description,
|
|
12685
|
+
extra: presentation.extra,
|
|
12695
12686
|
statement: presentation.statement && {
|
|
12696
12687
|
...presentation.statement,
|
|
12697
12688
|
description: statementDescription
|
package/package.json
CHANGED
|
@@ -2040,10 +2040,7 @@ describe('createHeadlessForm', () => {
|
|
|
2040
2040
|
});
|
|
2041
2041
|
|
|
2042
2042
|
expect(result).toMatchObject({
|
|
2043
|
-
fields: [
|
|
2044
|
-
{ description: 'I am regular' },
|
|
2045
|
-
{ description: '<span class="jsf-description">I am <b>bold</b>.</span>' },
|
|
2046
|
-
],
|
|
2043
|
+
fields: [{ description: 'I am regular' }, { description: 'I am <b>bold</b>.' }],
|
|
2047
2044
|
});
|
|
2048
2045
|
});
|
|
2049
2046
|
|
|
@@ -2502,7 +2499,7 @@ describe('createHeadlessForm', () => {
|
|
|
2502
2499
|
});
|
|
2503
2500
|
|
|
2504
2501
|
describe('when a field has conditional presentation properties', () => {
|
|
2505
|
-
it('
|
|
2502
|
+
it('returns the nested properties when the conditional matches', () => {
|
|
2506
2503
|
const { fields } = createHeadlessForm(schemaWithConditionalPresentationProperties, {
|
|
2507
2504
|
initialValues: {
|
|
2508
2505
|
// show the hidden statement
|
|
@@ -2510,9 +2507,7 @@ describe('createHeadlessForm', () => {
|
|
|
2510
2507
|
},
|
|
2511
2508
|
});
|
|
2512
2509
|
|
|
2513
|
-
expect(fields[0].statement.description).toBe(
|
|
2514
|
-
`<span class="jsf-statement"><a href="">conditional statement markup</a></span>`
|
|
2515
|
-
);
|
|
2510
|
+
expect(fields[0].statement.description).toBe(`<a href="">conditional statement markup</a>`);
|
|
2516
2511
|
});
|
|
2517
2512
|
});
|
|
2518
2513
|
|
|
@@ -3710,7 +3705,7 @@ describe('createHeadlessForm', () => {
|
|
|
3710
3705
|
expect(fields).toMatchObject([
|
|
3711
3706
|
{
|
|
3712
3707
|
name: 'time',
|
|
3713
|
-
description: '
|
|
3708
|
+
description: 'Write in <b>hh:ss</b> format', // from presentation
|
|
3714
3709
|
inputType: 'clock', // arbitrary type from presentation
|
|
3715
3710
|
deprecated: {
|
|
3716
3711
|
description: 'In favor of X', // from presentation
|