cx 25.1.2 → 25.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cx",
3
- "version": "25.1.2",
3
+ "version": "25.2.0",
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",
@@ -60,7 +60,7 @@ export function stringTemplate(str) {
60
60
  }
61
61
  }
62
62
 
63
- if (quoteStart < str.length) expr = plus(expr) + quoteStr(str.substring(quoteStart));
63
+ if (quoteStart < str.length || expr.length == 0) expr = plus(expr) + quoteStr(str.substring(quoteStart));
64
64
 
65
65
  return (tplCache[str] = expression(expr));
66
66
  }
@@ -13,6 +13,11 @@ describe("StringTemplate", function () {
13
13
  assert.equal(e(state), "Hello Jim");
14
14
  });
15
15
 
16
+ it("allows empty strings", function () {
17
+ let e = StringTemplate.compile("");
18
+ assert.equal(e(), "");
19
+ });
20
+
16
21
  it("properly encodes ' and \"", function () {
17
22
  var e = StringTemplate.compile('It\'s "working"!');
18
23
  assert.equal(e({}), 'It\'s "working"!');
@@ -87,7 +92,7 @@ describe("StringTemplate", function () {
87
92
  assert.equal(e(), "a\\b");
88
93
  });
89
94
 
90
- it.only("before a special character", function () {
95
+ it("before a special character", function () {
91
96
  var e = StringTemplate.compile("\\t");
92
97
  assert.equal(e(), "\\t");
93
98
  });
@@ -1,131 +1,132 @@
1
- import { Binding } from "./Binding";
2
- import { Expression } from "./Expression";
3
- import { StringTemplate } from "./StringTemplate";
4
- import { createStructuredSelector } from "../data/createStructuredSelector";
5
- import { getSelector } from "../data/getSelector";
6
- import { isFunction } from "../util/isFunction";
7
- import { isUndefined } from "../util/isUndefined";
8
- import { isDefined } from "../util/isDefined";
9
- import { isArray } from "../util/isArray";
10
- import { isAccessorChain } from "./createAccessorModelProxy";
11
-
12
- function defaultValue(pv) {
13
- if (typeof pv == "object" && pv && pv.structured) return pv.defaultValue;
14
-
15
- return pv;
16
- }
17
-
18
- function getSelectorConfig(props, values, nameMap) {
19
- let functions = {},
20
- structures = {},
21
- defaultValues = {},
22
- constants,
23
- p,
24
- v,
25
- pv,
26
- constant = true;
27
-
28
- for (p in props) {
29
- v = values[p];
30
- pv = props[p];
31
-
32
- if (isUndefined(v) && pv && (pv.bind || pv.tpl || pv.expr)) v = pv;
33
-
34
- if (v === null) {
35
- if (!constants) constants = {};
36
- constants[p] = null;
37
- } else if (typeof v == "object") {
38
- if (v.bind) {
39
- if (isUndefined(v.defaultValue) && v != pv) v.defaultValue = defaultValue(pv);
40
- if (isDefined(v.defaultValue)) defaultValues[v.bind] = v.defaultValue;
41
- nameMap[p] = v.bind;
42
- functions[p] = Binding.get(v.bind).value;
43
- constant = false;
44
- } else if (v.expr) {
45
- functions[p] = Expression.get(v.expr);
46
- constant = false;
47
- } else if (v.get) {
48
- functions[p] = v.get;
49
- constant = false;
50
- } else if (v.tpl) {
51
- functions[p] = StringTemplate.get(v.tpl);
52
- constant = false;
53
- } else if (pv && typeof pv == "object" && pv.structured) {
54
- if (isArray(v)) functions[p] = getSelector(v);
55
- else {
56
- let s = getSelectorConfig(v, v, {});
57
- structures[p] = s;
58
- Object.assign(defaultValues, s.defaultValues);
59
- }
60
- constant = false;
61
- } else {
62
- if (!constants) constants = {};
63
- constants[p] = v;
64
- }
65
- } else if (isFunction(v)) {
66
- if (isAccessorChain(v)) {
67
- let path = v.toString();
68
- nameMap[p] = path;
69
- functions[p] = Binding.get(path).value;
70
- } else functions[p] = v;
71
- constant = false;
72
- } else {
73
- if (isUndefined(v)) {
74
- if (isUndefined(pv)) continue;
75
- v = defaultValue(pv);
76
- }
77
-
78
- if (isUndefined(v)) continue;
79
-
80
- if (!constants) constants = {};
81
-
82
- constants[p] = v;
83
- }
84
- }
85
-
86
- return {
87
- functions,
88
- structures,
89
- defaultValues,
90
- constants,
91
- constant,
92
- };
93
- }
94
-
95
- function createSelector({ functions, structures, constants, defaultValues }) {
96
- let selector = {};
97
-
98
- for (let n in functions) {
99
- selector[n] = functions[n];
100
- }
101
-
102
- for (let n in structures) selector[n] = createSelector(structures[n]);
103
-
104
- return createStructuredSelector(selector, constants);
105
- }
106
-
107
- export class StructuredSelector {
108
- constructor({ props, values }) {
109
- this.nameMap = {};
110
- this.config = getSelectorConfig(props, values, this.nameMap);
111
- }
112
-
113
- init(store) {
114
- store.init(this.config.defaultValues);
115
- }
116
-
117
- create(memoize = true) {
118
- let selector = createSelector(this.config);
119
- if (memoize && selector.memoize) return selector.memoize();
120
- return selector;
121
- }
122
-
123
- createStoreSelector() {
124
- if (this.config.constant) {
125
- let result = { ...this.config.constants };
126
- return () => result;
127
- }
128
- let selector = this.create();
129
- return (store) => selector(store.getData());
130
- }
131
- }
1
+ import { Binding } from "./Binding";
2
+ import { Expression } from "./Expression";
3
+ import { StringTemplate } from "./StringTemplate";
4
+ import { createStructuredSelector } from "../data/createStructuredSelector";
5
+ import { getSelector } from "../data/getSelector";
6
+ import { isFunction } from "../util/isFunction";
7
+ import { isUndefined } from "../util/isUndefined";
8
+ import { isDefined } from "../util/isDefined";
9
+ import { isArray } from "../util/isArray";
10
+ import { isAccessorChain } from "./createAccessorModelProxy";
11
+ import { isString } from "../util/isString";
12
+
13
+ function defaultValue(pv) {
14
+ if (typeof pv == "object" && pv && pv.structured) return pv.defaultValue;
15
+
16
+ return pv;
17
+ }
18
+
19
+ function getSelectorConfig(props, values, nameMap) {
20
+ let functions = {},
21
+ structures = {},
22
+ defaultValues = {},
23
+ constants,
24
+ p,
25
+ v,
26
+ pv,
27
+ constant = true;
28
+
29
+ for (p in props) {
30
+ v = values[p];
31
+ pv = props[p];
32
+
33
+ if (isUndefined(v) && pv && (pv.bind || pv.tpl || pv.expr)) v = pv;
34
+
35
+ if (v === null) {
36
+ if (!constants) constants = {};
37
+ constants[p] = null;
38
+ } else if (typeof v == "object") {
39
+ if (v.bind) {
40
+ if (isUndefined(v.defaultValue) && v != pv) v.defaultValue = defaultValue(pv);
41
+ if (isDefined(v.defaultValue)) defaultValues[v.bind] = v.defaultValue;
42
+ nameMap[p] = v.bind;
43
+ functions[p] = Binding.get(v.bind).value;
44
+ constant = false;
45
+ } else if (v.expr) {
46
+ functions[p] = Expression.get(v.expr);
47
+ constant = false;
48
+ } else if (v.get) {
49
+ functions[p] = v.get;
50
+ constant = false;
51
+ } else if (isString(v.tpl)) {
52
+ functions[p] = StringTemplate.get(v.tpl);
53
+ constant = false;
54
+ } else if (pv && typeof pv == "object" && pv.structured) {
55
+ if (isArray(v)) functions[p] = getSelector(v);
56
+ else {
57
+ let s = getSelectorConfig(v, v, {});
58
+ structures[p] = s;
59
+ Object.assign(defaultValues, s.defaultValues);
60
+ }
61
+ constant = false;
62
+ } else {
63
+ if (!constants) constants = {};
64
+ constants[p] = v;
65
+ }
66
+ } else if (isFunction(v)) {
67
+ if (isAccessorChain(v)) {
68
+ let path = v.toString();
69
+ nameMap[p] = path;
70
+ functions[p] = Binding.get(path).value;
71
+ } else functions[p] = v;
72
+ constant = false;
73
+ } else {
74
+ if (isUndefined(v)) {
75
+ if (isUndefined(pv)) continue;
76
+ v = defaultValue(pv);
77
+ }
78
+
79
+ if (isUndefined(v)) continue;
80
+
81
+ if (!constants) constants = {};
82
+
83
+ constants[p] = v;
84
+ }
85
+ }
86
+
87
+ return {
88
+ functions,
89
+ structures,
90
+ defaultValues,
91
+ constants,
92
+ constant,
93
+ };
94
+ }
95
+
96
+ function createSelector({ functions, structures, constants, defaultValues }) {
97
+ let selector = {};
98
+
99
+ for (let n in functions) {
100
+ selector[n] = functions[n];
101
+ }
102
+
103
+ for (let n in structures) selector[n] = createSelector(structures[n]);
104
+
105
+ return createStructuredSelector(selector, constants);
106
+ }
107
+
108
+ export class StructuredSelector {
109
+ constructor({ props, values }) {
110
+ this.nameMap = {};
111
+ this.config = getSelectorConfig(props, values, this.nameMap);
112
+ }
113
+
114
+ init(store) {
115
+ store.init(this.config.defaultValues);
116
+ }
117
+
118
+ create(memoize = true) {
119
+ let selector = createSelector(this.config);
120
+ if (memoize && selector.memoize) return selector.memoize();
121
+ return selector;
122
+ }
123
+
124
+ createStoreSelector() {
125
+ if (this.config.constant) {
126
+ let result = { ...this.config.constants };
127
+ return () => result;
128
+ }
129
+ let selector = this.create();
130
+ return (store) => selector(store.getData());
131
+ }
132
+ }
@@ -1,48 +1,49 @@
1
- import { Binding } from "./Binding";
2
- import { Expression } from "./Expression";
3
- import { StringTemplate } from "./StringTemplate";
4
- import { isArray } from "../util/isArray";
5
- import { createStructuredSelector } from "./createStructuredSelector";
6
- import { isSelector } from "./isSelector";
7
- import { isAccessorChain } from "./createAccessorModelProxy";
8
-
9
- var undefinedF = () => undefined;
10
- var nullF = () => null;
11
-
12
- export function getSelector(config) {
13
- if (config === undefined) return undefinedF;
14
- if (config === null) return nullF;
15
-
16
- switch (typeof config) {
17
- case "object":
18
- if (isArray(config)) {
19
- let selectors = config.map((x) => getSelector(x));
20
- return (data) => selectors.map((elementSelector) => elementSelector(data));
21
- }
22
-
23
- //toString converts accessor chains to binding paths
24
- if (config.bind) return Binding.get(config.bind.toString()).value;
25
-
26
- if (config.tpl) return StringTemplate.get(config.tpl);
27
-
28
- if (config.expr) return Expression.get(config.expr);
29
-
30
- if (config.get) return config.get;
31
-
32
- let selectors = {};
33
- let constants = {};
34
-
35
- for (let key in config) {
36
- if (isSelector(config[key])) selectors[key] = getSelector(config[key]);
37
- else constants[key] = config[key];
38
- }
39
- return createStructuredSelector(selectors, constants);
40
-
41
- case "function":
42
- if (isAccessorChain(config)) return Binding.get(config.toString()).value;
43
- return config;
44
-
45
- default:
46
- return () => config;
47
- }
48
- }
1
+ import { Binding } from "./Binding";
2
+ import { Expression } from "./Expression";
3
+ import { StringTemplate } from "./StringTemplate";
4
+ import { isArray } from "../util/isArray";
5
+ import { createStructuredSelector } from "./createStructuredSelector";
6
+ import { isSelector } from "./isSelector";
7
+ import { isAccessorChain } from "./createAccessorModelProxy";
8
+ import { isString } from "../util/isString";
9
+
10
+ var undefinedF = () => undefined;
11
+ var nullF = () => null;
12
+
13
+ export function getSelector(config) {
14
+ if (config === undefined) return undefinedF;
15
+ if (config === null) return nullF;
16
+
17
+ switch (typeof config) {
18
+ case "object":
19
+ if (isArray(config)) {
20
+ let selectors = config.map((x) => getSelector(x));
21
+ return (data) => selectors.map((elementSelector) => elementSelector(data));
22
+ }
23
+
24
+ //toString converts accessor chains to binding paths
25
+ if (config.bind) return Binding.get(config.bind.toString()).value;
26
+
27
+ if (isString(config.tpl)) return StringTemplate.get(config.tpl);
28
+
29
+ if (config.expr) return Expression.get(config.expr);
30
+
31
+ if (config.get) return config.get;
32
+
33
+ let selectors = {};
34
+ let constants = {};
35
+
36
+ for (let key in config) {
37
+ if (isSelector(config[key])) selectors[key] = getSelector(config[key]);
38
+ else constants[key] = config[key];
39
+ }
40
+ return createStructuredSelector(selectors, constants);
41
+
42
+ case "function":
43
+ if (isAccessorChain(config)) return Binding.get(config.toString()).value;
44
+ return config;
45
+
46
+ default:
47
+ return () => config;
48
+ }
49
+ }