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/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 null;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cx",
3
- "version": "23.4.0",
3
+ "version": "23.4.2",
4
4
  "description": "Advanced JavaScript UI framework for admin and dashboard applications with ready to use grid, form and chart components.",
5
5
  "main": "index.js",
6
6
  "jsnext:main": "src/index.js",
@@ -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 (x";
11
- let selector = "x";
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
 
@@ -1,49 +1,59 @@
1
- import {Binding} from './Binding';
2
- import assert from 'assert';
3
-
4
- describe('Binding', function() {
5
-
6
- describe('#get()', function () {
7
- it('should get value if value is defined', function () {
8
- var state = {person: {name: 'Joe'}};
9
- var b = Binding.get('person.name');
10
- assert.equal(b.value(state), 'Joe');
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
- describe('#set()', function () {
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
- it('produces new objects along the binding path', function () {
17
- var state = {person: {name: 'Joe'}};
18
- var b = Binding.get('person.name');
19
- var ns = b.set(state, 'Jack');
20
- assert.equal(ns.person.name, 'Jack');
21
- assert.notEqual(state, ns);
22
- assert.notEqual(state.person, ns.person);
23
- assert.notEqual(state.person.name, ns.person.name);
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
- it('returns same state object if value does not change', function () {
27
- var state = {person: {name: 'Joe'}};
28
- var b = Binding.get('person.name');
29
- var ns = b.set(state, 'Joe');
30
- assert.equal(state, ns);
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
- describe('.delete()', function () {
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
- it('correctly removes pointed properties', function () {
37
- var state = {person: {name: 'Joe'}};
38
- var b = Binding.get('person.name');
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('person' in ns);
41
- assert(!('name' in ns.person));
50
+ assert("person" in ns);
51
+ assert(!("name" in ns.person));
42
52
  });
43
53
 
44
- it('does not change state if property is non-existent', function () {
45
- var state = {person: {name: 'Joe'}};
46
- var b = Binding.get('person.name2');
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, StructuredSelector as SS } from "../core";
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): SS;
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 '../../ui/Widget';
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 (data.visible && context.lastFieldId && context.validation && context.validation.errors && context.validation.errors.length > 0) {
7
- var lastError = instance.lastError = context.validation.errors[context.validation.errors.length - 1];
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('lastErrorMessage', lastError.message);
17
- let c2 = instance.cache('lastErrorFieldId', lastError.fieldId);
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 <label key={key} className={data.classNames} htmlFor={data.fieldId}>
29
- {data.errorMessage}
30
- </label>
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 = 'validationerror';
41
+ ValidationError.prototype.baseClass = "validationerror";
35
42
  ValidationError.prototype.styled = true;
36
43
 
37
- Widget.alias('validation-error', ValidationError);
44
+ Widget.alias("validation-error", ValidationError);
@@ -1,6 +1,8 @@
1
- import * as Cx from '../../core';
2
- import { FieldProps } from './Field';
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 null;
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
  }