cx 23.4.0 → 23.4.2
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/data.js +2 -7
- package/dist/manifest.js +590 -590
- package/dist/widgets.js +4 -2
- package/package.json +1 -1
- package/src/data/Binding.js +2 -12
- package/src/data/Binding.spec.js +48 -38
- package/src/data/StructuredSelector.d.ts +4 -2
- package/src/data/createAccessorModelProxy.spec.tsx +6 -0
- package/src/widgets/form/ValidationError.js +20 -13
- package/src/widgets/form/Validator.d.ts +5 -3
- package/src/widgets/form/Validator.js +3 -2
package/dist/widgets.js
CHANGED
|
@@ -7392,6 +7392,7 @@ var ValidationError = /*#__PURE__*/ (function(_Widget) {
|
|
|
7392
7392
|
{
|
|
7393
7393
|
className: data.classNames,
|
|
7394
7394
|
htmlFor: data.fieldId,
|
|
7395
|
+
style: data.style,
|
|
7395
7396
|
children: data.errorMessage
|
|
7396
7397
|
},
|
|
7397
7398
|
key
|
|
@@ -17046,8 +17047,9 @@ var Validator = /*#__PURE__*/ (function(_Field) {
|
|
|
17046
17047
|
return false;
|
|
17047
17048
|
};
|
|
17048
17049
|
|
|
17049
|
-
_proto.render = function render() {
|
|
17050
|
-
return
|
|
17050
|
+
_proto.render = function render(context, instance, key) {
|
|
17051
|
+
if (!instance.state.visited || !instance.data.error) return;
|
|
17052
|
+
return this.renderChildren(context, instance, key);
|
|
17051
17053
|
};
|
|
17052
17054
|
|
|
17053
17055
|
return Validator;
|
package/package.json
CHANGED
package/src/data/Binding.js
CHANGED
|
@@ -7,18 +7,8 @@ export class Binding {
|
|
|
7
7
|
constructor(path) {
|
|
8
8
|
this.path = path;
|
|
9
9
|
this.parts = path.split(".");
|
|
10
|
-
let body = "return
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
for (let i = 0; i < this.parts.length; i++) {
|
|
14
|
-
if (this.parts[i][0] >= "0" && this.parts[i][0] <= "9") selector += "[" + this.parts[i] + "]";
|
|
15
|
-
else selector += "." + this.parts[i];
|
|
16
|
-
|
|
17
|
-
if (i + 1 < this.parts.length) body += " && " + selector;
|
|
18
|
-
else body += " ? " + selector + " : undefined";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
body += ")";
|
|
10
|
+
let body = "return x";
|
|
11
|
+
for (let i = 0; i < this.parts.length; i++) body += '?.["' + this.parts[i] + '"]';
|
|
22
12
|
this.value = new Function("x", body);
|
|
23
13
|
}
|
|
24
14
|
|
package/src/data/Binding.spec.js
CHANGED
|
@@ -1,49 +1,59 @@
|
|
|
1
|
-
import {Binding} from
|
|
2
|
-
import assert from
|
|
3
|
-
|
|
4
|
-
describe(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
12
|
-
});
|
|
1
|
+
import { Binding } from "./Binding";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
|
|
4
|
+
describe("Binding", function () {
|
|
5
|
+
describe("#get()", function () {
|
|
6
|
+
it("should get value if value is defined", function () {
|
|
7
|
+
var state = { person: { name: "Joe" } };
|
|
8
|
+
var b = Binding.get("person.name");
|
|
9
|
+
assert.equal(b.value(state), "Joe");
|
|
10
|
+
});
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
it("allows non-standard property identifiers", function () {
|
|
13
|
+
var state = { person: { "@schema": "Person" } };
|
|
14
|
+
var b = Binding.get("person.@schema");
|
|
15
|
+
assert.equal(b.value(state), "Person");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
describe("#set()", function () {
|
|
20
|
+
it("produces new objects along the binding path", function () {
|
|
21
|
+
var state = { person: { name: "Joe" } };
|
|
22
|
+
var b = Binding.get("person.name");
|
|
23
|
+
var ns = b.set(state, "Jack");
|
|
24
|
+
assert.equal(ns.person.name, "Jack");
|
|
25
|
+
assert.notEqual(state, ns);
|
|
26
|
+
assert.notEqual(state.person, ns.person);
|
|
27
|
+
assert.notEqual(state.person.name, ns.person.name);
|
|
28
|
+
});
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
30
|
+
it("returns same state object if value does not change", function () {
|
|
31
|
+
var state = { person: { name: "Joe" } };
|
|
32
|
+
var b = Binding.get("person.name");
|
|
33
|
+
var ns = b.set(state, "Joe");
|
|
34
|
+
assert.equal(state, ns);
|
|
35
|
+
});
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
it("allows non-standard property identifiers", function () {
|
|
38
|
+
var state = { person: { "@schema": "Person" } };
|
|
39
|
+
var b = Binding.get("person.@schema");
|
|
40
|
+
var ns = b.set(state, "Test");
|
|
41
|
+
assert.equal(ns.person["@schema"], "Test");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
35
44
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var
|
|
45
|
+
describe(".delete()", function () {
|
|
46
|
+
it("correctly removes pointed properties", function () {
|
|
47
|
+
var state = { person: { name: "Joe" } };
|
|
48
|
+
var b = Binding.get("person.name");
|
|
39
49
|
var ns = b.delete(state);
|
|
40
|
-
assert(
|
|
41
|
-
assert(!(
|
|
50
|
+
assert("person" in ns);
|
|
51
|
+
assert(!("name" in ns.person));
|
|
42
52
|
});
|
|
43
53
|
|
|
44
|
-
it(
|
|
45
|
-
var state = {person: {name:
|
|
46
|
-
var b = Binding.get(
|
|
54
|
+
it("does not change state if property is non-existent", function () {
|
|
55
|
+
var state = { person: { name: "Joe" } };
|
|
56
|
+
var b = Binding.get("person.name2");
|
|
47
57
|
var ns = b.delete(state);
|
|
48
58
|
assert(ns == state);
|
|
49
59
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StructuredProp, Record,
|
|
1
|
+
import { StructuredProp, Record, Selector } from "../core";
|
|
2
2
|
import { View } from "./View";
|
|
3
3
|
|
|
4
4
|
interface StructuredSelectorConfig {
|
|
@@ -11,5 +11,7 @@ export class StructuredSelector {
|
|
|
11
11
|
|
|
12
12
|
init(store: View);
|
|
13
13
|
|
|
14
|
-
create(memoize?: bool = true):
|
|
14
|
+
create(memoize?: bool = true): Selector<Record>;
|
|
15
|
+
|
|
16
|
+
createStoreSelector(): (store: View) => Record;
|
|
15
17
|
}
|
|
@@ -7,6 +7,7 @@ interface Model {
|
|
|
7
7
|
city: string;
|
|
8
8
|
streetNumber: number;
|
|
9
9
|
};
|
|
10
|
+
"@crazy": string;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
describe("createAccessorModelProxy", () => {
|
|
@@ -35,4 +36,9 @@ describe("createAccessorModelProxy", () => {
|
|
|
35
36
|
assert.strictEqual(streetNumber.nameOf(), "streetNumber");
|
|
36
37
|
assert.strictEqual(city.nameOf(), "city");
|
|
37
38
|
});
|
|
39
|
+
|
|
40
|
+
it("allows non-standard property identifiers ", () => {
|
|
41
|
+
let model = createAccessorModelProxy<Model>();
|
|
42
|
+
assert.strictEqual(model["@crazy"].nameOf(), "@crazy");
|
|
43
|
+
});
|
|
38
44
|
});
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {Widget, VDOM} from
|
|
1
|
+
import { Widget, VDOM } from "../../ui/Widget";
|
|
2
2
|
|
|
3
3
|
export class ValidationError extends Widget {
|
|
4
|
-
|
|
5
4
|
checkVisible(context, instance, data) {
|
|
6
|
-
if (
|
|
7
|
-
|
|
5
|
+
if (
|
|
6
|
+
data.visible &&
|
|
7
|
+
context.lastFieldId &&
|
|
8
|
+
context.validation &&
|
|
9
|
+
context.validation.errors &&
|
|
10
|
+
context.validation.errors.length > 0
|
|
11
|
+
) {
|
|
12
|
+
var lastError = (instance.lastError = context.validation.errors[context.validation.errors.length - 1]);
|
|
8
13
|
return lastError.fieldId == context.lastFieldId && lastError.visited;
|
|
9
14
|
}
|
|
10
15
|
|
|
@@ -12,9 +17,9 @@ export class ValidationError extends Widget {
|
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
explore(context, instance) {
|
|
15
|
-
var {data, lastError} = instance;
|
|
16
|
-
let c1 = instance.cache(
|
|
17
|
-
let c2 = instance.cache(
|
|
20
|
+
var { data, lastError } = instance;
|
|
21
|
+
let c1 = instance.cache("lastErrorMessage", lastError.message);
|
|
22
|
+
let c2 = instance.cache("lastErrorFieldId", lastError.fieldId);
|
|
18
23
|
if (c1 || c2) {
|
|
19
24
|
data.errorMessage = lastError.message;
|
|
20
25
|
data.fieldId = lastError.fieldId;
|
|
@@ -24,14 +29,16 @@ export class ValidationError extends Widget {
|
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
render(context, instance, key) {
|
|
27
|
-
var {data} = instance;
|
|
28
|
-
return
|
|
29
|
-
{data.
|
|
30
|
-
|
|
32
|
+
var { data } = instance;
|
|
33
|
+
return (
|
|
34
|
+
<label key={key} className={data.classNames} htmlFor={data.fieldId} style={data.style}>
|
|
35
|
+
{data.errorMessage}
|
|
36
|
+
</label>
|
|
37
|
+
);
|
|
31
38
|
}
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
ValidationError.prototype.baseClass =
|
|
41
|
+
ValidationError.prototype.baseClass = "validationerror";
|
|
35
42
|
ValidationError.prototype.styled = true;
|
|
36
43
|
|
|
37
|
-
Widget.alias(
|
|
44
|
+
Widget.alias("validation-error", ValidationError);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import * as Cx from
|
|
2
|
-
import { FieldProps } from
|
|
1
|
+
import * as Cx from "../../core";
|
|
2
|
+
import { FieldProps } from "./Field";
|
|
3
3
|
|
|
4
|
-
interface ValidatorProps extends FieldProps {
|
|
4
|
+
interface ValidatorProps extends FieldProps {
|
|
5
|
+
value: Cx.StructuredProp;
|
|
6
|
+
}
|
|
5
7
|
|
|
6
8
|
export class Validator extends Cx.Widget<ValidatorProps> {}
|
|
@@ -14,7 +14,8 @@ export class Validator extends Field {
|
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
render() {
|
|
18
|
-
return
|
|
17
|
+
render(context, instance, key) {
|
|
18
|
+
if (!instance.state.visited || !instance.data.error) return;
|
|
19
|
+
return this.renderChildren(context, instance, key);
|
|
19
20
|
}
|
|
20
21
|
}
|