cx 23.12.3 → 24.0.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/dist/data.js +8 -5
- package/dist/manifest.js +732 -729
- package/dist/ui.js +74 -42
- package/package.json +1 -1
- package/src/charts/PieLabel.js +71 -71
- package/src/charts/axis/Axis.d.ts +96 -96
- package/src/charts/axis/Axis.js +252 -252
- package/src/data/Expression.js +212 -211
- package/src/data/Expression.spec.js +174 -164
- package/src/data/StringTemplate.spec.js +105 -105
- package/src/svg/Text.d.ts +40 -40
- package/src/ui/Controller.d.ts +182 -182
- package/src/ui/FocusManager.js +171 -171
- package/src/ui/Format.js +87 -89
- package/src/ui/Instance.d.ts +72 -72
- package/src/ui/Restate.d.ts +18 -18
- package/src/ui/Restate.js +160 -160
- package/src/widgets/form/ColorPicker.scss +275 -275
- package/src/widgets/form/ColorPicker.variables.scss +22 -22
- package/src/widgets/form/DateTimeField.d.ts +86 -86
- package/src/widgets/form/DateTimeField.js +572 -572
- package/src/widgets/form/Label.js +88 -88
- package/src/widgets/form/LookupField.d.ts +174 -174
- package/src/widgets/form/LookupField.js +1131 -1131
- package/src/widgets/form/UploadButton.d.ts +34 -34
|
@@ -1,164 +1,174 @@
|
|
|
1
|
-
import { Expression } from "./Expression";
|
|
2
|
-
import assert from "assert";
|
|
3
|
-
|
|
4
|
-
describe("Expression", function () {
|
|
5
|
-
describe("#compile()", function () {
|
|
6
|
-
it("returns a selector", function () {
|
|
7
|
-
var e = Expression.compile("{person.name}");
|
|
8
|
-
var state = {
|
|
9
|
-
person: {
|
|
10
|
-
name: "Jim",
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
assert.equal(e(state), "Jim");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("ignores bindings in strings", function () {
|
|
17
|
-
var e = Expression.compile('"{person.name}"');
|
|
18
|
-
var state = {
|
|
19
|
-
person: {
|
|
20
|
-
name: "Jim",
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
assert.equal(e(state), "{person.name}");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("properly encodes quotes #1", function () {
|
|
27
|
-
var e = Expression.compile('"\'"');
|
|
28
|
-
var state = {};
|
|
29
|
-
assert.equal(e(state), "'");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("properly encodes quotes #2", function () {
|
|
33
|
-
var e = Expression.compile('"\\""');
|
|
34
|
-
var state = {};
|
|
35
|
-
assert.equal(e(state), '"');
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("allow subexpressions", function () {
|
|
40
|
-
it("in square brackets", function () {
|
|
41
|
-
var e = Expression.compile("{[{person.name}]}");
|
|
42
|
-
var state = {
|
|
43
|
-
person: {
|
|
44
|
-
name: "Jim",
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
assert.equal(e(state), "Jim");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("in square brackets", function () {
|
|
51
|
-
var e = Expression.compile("{[{person.alias} || {person.name}]}");
|
|
52
|
-
var state = {
|
|
53
|
-
person: {
|
|
54
|
-
name: "Jim",
|
|
55
|
-
alias: "J",
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
assert.equal(e(state), "J");
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("prefixed with % sign", function () {
|
|
62
|
-
var e = Expression.compile("%{1+1}");
|
|
63
|
-
assert.equal(e(), "2");
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("can be formatted", function () {
|
|
67
|
-
var e = Expression.compile("{[1+1]:f;2}");
|
|
68
|
-
assert.equal(e(), "2.00");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("n level deep", function () {
|
|
72
|
-
var e = Expression.compile("{[{[{[1+1]}]}]:f;2}");
|
|
73
|
-
assert.equal(e(), "2.00");
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("with complex math inside", function () {
|
|
77
|
-
var e = Expression.compile("%{{data}.reduce((a,b)=>a+b, 0):f;2}");
|
|
78
|
-
var state = {
|
|
79
|
-
data: [1, 2, 3],
|
|
80
|
-
};
|
|
81
|
-
assert.equal(e(state), "6.00");
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("with a conditional operator inside", function () {
|
|
85
|
-
var e = Expression.compile('{[true ? "T" : "F"]}');
|
|
86
|
-
assert.equal(e(), "T");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
it("
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
assert.equal(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
assert.equal(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
assert.equal(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
assert(
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
// assert.equal(
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
// assert.equal(
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
// assert.equal(
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
// assert.equal(
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
// assert.equal(
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
// assert.equal(
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
});
|
|
1
|
+
import { Expression } from "./Expression";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
|
|
4
|
+
describe("Expression", function () {
|
|
5
|
+
describe("#compile()", function () {
|
|
6
|
+
it("returns a selector", function () {
|
|
7
|
+
var e = Expression.compile("{person.name}");
|
|
8
|
+
var state = {
|
|
9
|
+
person: {
|
|
10
|
+
name: "Jim",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
assert.equal(e(state), "Jim");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("ignores bindings in strings", function () {
|
|
17
|
+
var e = Expression.compile('"{person.name}"');
|
|
18
|
+
var state = {
|
|
19
|
+
person: {
|
|
20
|
+
name: "Jim",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
assert.equal(e(state), "{person.name}");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("properly encodes quotes #1", function () {
|
|
27
|
+
var e = Expression.compile('"\'"');
|
|
28
|
+
var state = {};
|
|
29
|
+
assert.equal(e(state), "'");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("properly encodes quotes #2", function () {
|
|
33
|
+
var e = Expression.compile('"\\""');
|
|
34
|
+
var state = {};
|
|
35
|
+
assert.equal(e(state), '"');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("allow subexpressions", function () {
|
|
40
|
+
it("in square brackets", function () {
|
|
41
|
+
var e = Expression.compile("{[{person.name}]}");
|
|
42
|
+
var state = {
|
|
43
|
+
person: {
|
|
44
|
+
name: "Jim",
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
assert.equal(e(state), "Jim");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("in square brackets", function () {
|
|
51
|
+
var e = Expression.compile("{[{person.alias} || {person.name}]}");
|
|
52
|
+
var state = {
|
|
53
|
+
person: {
|
|
54
|
+
name: "Jim",
|
|
55
|
+
alias: "J",
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
assert.equal(e(state), "J");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("prefixed with % sign", function () {
|
|
62
|
+
var e = Expression.compile("%{1+1}");
|
|
63
|
+
assert.equal(e(), "2");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("can be formatted", function () {
|
|
67
|
+
var e = Expression.compile("{[1+1]:f;2}");
|
|
68
|
+
assert.equal(e(), "2.00");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("n level deep", function () {
|
|
72
|
+
var e = Expression.compile("{[{[{[1+1]}]}]:f;2}");
|
|
73
|
+
assert.equal(e(), "2.00");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("with complex math inside", function () {
|
|
77
|
+
var e = Expression.compile("%{{data}.reduce((a,b)=>a+b, 0):f;2}");
|
|
78
|
+
var state = {
|
|
79
|
+
data: [1, 2, 3],
|
|
80
|
+
};
|
|
81
|
+
assert.equal(e(state), "6.00");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("with a conditional operator inside", function () {
|
|
85
|
+
var e = Expression.compile('{[true ? "T" : "F"]}');
|
|
86
|
+
assert.equal(e(), "T");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("with string interpolation inside", function () {
|
|
90
|
+
var e = Expression.compile("{[`${{test}}`]}");
|
|
91
|
+
assert.equal(e({ test: "T" }), "T");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("are working", function () {
|
|
96
|
+
it("function expressions with get", function () {
|
|
97
|
+
var e = Expression.get((get) => get("a") + get("b"));
|
|
98
|
+
assert.equal(e({ a: 1, b: 2 }), 3);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("are properly memoized", function () {
|
|
102
|
+
let inv = 0;
|
|
103
|
+
var e = Expression.get((get) => {
|
|
104
|
+
inv++;
|
|
105
|
+
return get("a") + get("b");
|
|
106
|
+
}).memoize();
|
|
107
|
+
|
|
108
|
+
assert.equal(e({ a: 1, b: 1 }), 2);
|
|
109
|
+
assert.equal(inv, 1);
|
|
110
|
+
|
|
111
|
+
assert.equal(e({ a: 1, b: 1 }), 2);
|
|
112
|
+
assert.equal(inv, 1);
|
|
113
|
+
|
|
114
|
+
assert.equal(e({ a: 1, b: 2 }), 3);
|
|
115
|
+
assert.equal(inv, 2);
|
|
116
|
+
|
|
117
|
+
assert.equal(e({ a: 1, b: 2 }), 3);
|
|
118
|
+
assert.equal(inv, 2);
|
|
119
|
+
|
|
120
|
+
assert.equal(e({ a: 2, b: 2 }), 4);
|
|
121
|
+
assert.equal(inv, 3);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("formatting can be used inside bindings", function () {
|
|
125
|
+
var e = Expression.get((get) => get("name:prefix;Hello "));
|
|
126
|
+
assert(e({ name: "CxJS" }), "Hello CxJS");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("allows using the fmt function inside", function () {
|
|
130
|
+
var e = Expression.compile('{[fmt({text}, "prefix;Hello ")]}');
|
|
131
|
+
assert.equal(e({ text: "CxJS" }), "Hello CxJS");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// it('are properly memoized with proxies', function () {
|
|
135
|
+
// let inv = 0;
|
|
136
|
+
// var e = Expression.get(d => { inv++; return d.a + d.b}).memoize();
|
|
137
|
+
//
|
|
138
|
+
// assert.equal(e({ a: 1, b: 1 }), 2);
|
|
139
|
+
// assert.equal(inv, 1);
|
|
140
|
+
//
|
|
141
|
+
// assert.equal(e({ a: 1, b: 1 }), 2);
|
|
142
|
+
// assert.equal(inv, 1);
|
|
143
|
+
//
|
|
144
|
+
// assert.equal(e({ a: 1, b: 2 }), 3);
|
|
145
|
+
// assert.equal(inv, 2);
|
|
146
|
+
//
|
|
147
|
+
// assert.equal(e({ a: 1, b: 2 }), 3);
|
|
148
|
+
// assert.equal(inv, 2);
|
|
149
|
+
//
|
|
150
|
+
// assert.equal(e({ a: 2, b: 2 }), 4);
|
|
151
|
+
// assert.equal(inv, 3);
|
|
152
|
+
// });
|
|
153
|
+
//
|
|
154
|
+
// it('are properly memoized with proxies and deep data', function () {
|
|
155
|
+
// let inv = 0;
|
|
156
|
+
// var e = Expression.get(d => { inv++; return d.v.a + d.v.b}).memoize();
|
|
157
|
+
//
|
|
158
|
+
// assert.equal(e({ v: { a: 1, b: 1 }}), 2);
|
|
159
|
+
// assert.equal(inv, 1);
|
|
160
|
+
//
|
|
161
|
+
// assert.equal(e({ v: { a: 1, b: 1 }}), 2);
|
|
162
|
+
// assert.equal(inv, 1);
|
|
163
|
+
//
|
|
164
|
+
// assert.equal(e({ v: { a: 1, b: 2 }}), 3);
|
|
165
|
+
// assert.equal(inv, 2);
|
|
166
|
+
//
|
|
167
|
+
// assert.equal(e({ v: { a: 1, b: 2 }}), 3);
|
|
168
|
+
// assert.equal(inv, 2);
|
|
169
|
+
//
|
|
170
|
+
// assert.equal(e({ v: { a: 2, b: 2 }}), 4);
|
|
171
|
+
// assert.equal(inv, 3);
|
|
172
|
+
// });
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
import { StringTemplate } from "./StringTemplate";
|
|
2
|
-
import assert from "assert";
|
|
3
|
-
|
|
4
|
-
describe("StringTemplate", function () {
|
|
5
|
-
describe("#compile()", function () {
|
|
6
|
-
it("returns a selector", function () {
|
|
7
|
-
var e = StringTemplate.compile("Hello {person.name}");
|
|
8
|
-
var state = {
|
|
9
|
-
person: {
|
|
10
|
-
name: "Jim",
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
assert.equal(e(state), "Hello Jim");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("properly encodes ' and \"", function () {
|
|
17
|
-
var e = StringTemplate.compile('It\'s "working"!');
|
|
18
|
-
assert.equal(e({}), 'It\'s "working"!');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("supports multi-line strings", function () {
|
|
22
|
-
var e = StringTemplate.compile("a\nb");
|
|
23
|
-
assert.equal(e(), "a\nb");
|
|
24
|
-
|
|
25
|
-
var e = StringTemplate.compile("a\r\nb");
|
|
26
|
-
assert.equal(e(), "a\r\nb");
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("double brackets are used to escape brackets", function () {
|
|
31
|
-
it("double brackets are preserved", function () {
|
|
32
|
-
var e = StringTemplate.compile("Hello {{person.name}}");
|
|
33
|
-
var state = {
|
|
34
|
-
person: {
|
|
35
|
-
name: "Jim",
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
assert.equal(e(state), "Hello {person.name}");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("triple brackets are converted to single brackets and a binding", function () {
|
|
42
|
-
var e = StringTemplate.compile("Hello {{{person.name}}}");
|
|
43
|
-
var state = {
|
|
44
|
-
person: {
|
|
45
|
-
name: "Jim",
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
assert.equal(e(state), "Hello {Jim}");
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("supports formatting", function () {
|
|
53
|
-
it("with colon", function () {
|
|
54
|
-
var e = StringTemplate.compile("{str:suffix;kg}");
|
|
55
|
-
assert.equal(e({ str: "5" }), "5kg");
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("with multiple formats", function () {
|
|
59
|
-
var e = StringTemplate.compile("{str:suffix;kg:wrap;(;)}");
|
|
60
|
-
assert.equal(e({ str: "5" }), "(5kg)");
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("with null values", function () {
|
|
64
|
-
var e = StringTemplate.compile("{str:suffix;kg:|N/A}");
|
|
65
|
-
assert.equal(e({ str: null }), "N/A");
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("of null values", function () {
|
|
69
|
-
var e = StringTemplate.compile("{str|N/A}");
|
|
70
|
-
assert.equal(e({ str: null }), "N/A");
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe("supports expressions", function () {
|
|
75
|
-
it("using []", function () {
|
|
76
|
-
var e = StringTemplate.compile("1 + 2 = {[1+2]}");
|
|
77
|
-
assert.equal(e(), "1 + 2 = 3");
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("using %", function () {
|
|
81
|
-
var e = StringTemplate.compile("1 + 2 = %{1+2}");
|
|
82
|
-
assert.equal(e(), "1 + 2 = 3");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("with subexpressions", function () {
|
|
86
|
-
var e = StringTemplate.compile("1 + 2 = {[%{1+2}]}");
|
|
87
|
-
assert.equal(e(), "1 + 2 = 3");
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("with a conditional operator", function () {
|
|
91
|
-
var e = StringTemplate.compile("1 + 2 = {[true ? 3 : 2]:s}");
|
|
92
|
-
assert.equal(e(), "1 + 2 = 3");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("with sub-expression formatting", function () {
|
|
96
|
-
var e = StringTemplate.compile("{[!!{person.age} ? {person.age:suffix; years old} : 'Age unknown']}");
|
|
97
|
-
var state = {
|
|
98
|
-
person: {
|
|
99
|
-
age: 32,
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
assert.equal(e(state), "32 years old");
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
1
|
+
import { StringTemplate } from "./StringTemplate";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
|
|
4
|
+
describe("StringTemplate", function () {
|
|
5
|
+
describe("#compile()", function () {
|
|
6
|
+
it("returns a selector", function () {
|
|
7
|
+
var e = StringTemplate.compile("Hello {person.name}");
|
|
8
|
+
var state = {
|
|
9
|
+
person: {
|
|
10
|
+
name: "Jim",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
assert.equal(e(state), "Hello Jim");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("properly encodes ' and \"", function () {
|
|
17
|
+
var e = StringTemplate.compile('It\'s "working"!');
|
|
18
|
+
assert.equal(e({}), 'It\'s "working"!');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("supports multi-line strings", function () {
|
|
22
|
+
var e = StringTemplate.compile("a\nb");
|
|
23
|
+
assert.equal(e(), "a\nb");
|
|
24
|
+
|
|
25
|
+
var e = StringTemplate.compile("a\r\nb");
|
|
26
|
+
assert.equal(e(), "a\r\nb");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("double brackets are used to escape brackets", function () {
|
|
31
|
+
it("double brackets are preserved", function () {
|
|
32
|
+
var e = StringTemplate.compile("Hello {{person.name}}");
|
|
33
|
+
var state = {
|
|
34
|
+
person: {
|
|
35
|
+
name: "Jim",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
assert.equal(e(state), "Hello {person.name}");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("triple brackets are converted to single brackets and a binding", function () {
|
|
42
|
+
var e = StringTemplate.compile("Hello {{{person.name}}}");
|
|
43
|
+
var state = {
|
|
44
|
+
person: {
|
|
45
|
+
name: "Jim",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
assert.equal(e(state), "Hello {Jim}");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("supports formatting", function () {
|
|
53
|
+
it("with colon", function () {
|
|
54
|
+
var e = StringTemplate.compile("{str:suffix;kg}");
|
|
55
|
+
assert.equal(e({ str: "5" }), "5kg");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("with multiple formats", function () {
|
|
59
|
+
var e = StringTemplate.compile("{str:suffix;kg:wrap;(;)}");
|
|
60
|
+
assert.equal(e({ str: "5" }), "(5kg)");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("with null values", function () {
|
|
64
|
+
var e = StringTemplate.compile("{str:suffix;kg:|N/A}");
|
|
65
|
+
assert.equal(e({ str: null }), "N/A");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("of null values", function () {
|
|
69
|
+
var e = StringTemplate.compile("{str|N/A}");
|
|
70
|
+
assert.equal(e({ str: null }), "N/A");
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("supports expressions", function () {
|
|
75
|
+
it("using []", function () {
|
|
76
|
+
var e = StringTemplate.compile("1 + 2 = {[1+2]}");
|
|
77
|
+
assert.equal(e(), "1 + 2 = 3");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("using %", function () {
|
|
81
|
+
var e = StringTemplate.compile("1 + 2 = %{1+2}");
|
|
82
|
+
assert.equal(e(), "1 + 2 = 3");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("with subexpressions", function () {
|
|
86
|
+
var e = StringTemplate.compile("1 + 2 = {[%{1+2}]}");
|
|
87
|
+
assert.equal(e(), "1 + 2 = 3");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("with a conditional operator", function () {
|
|
91
|
+
var e = StringTemplate.compile("1 + 2 = {[true ? 3 : 2]:s}");
|
|
92
|
+
assert.equal(e(), "1 + 2 = 3");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("with sub-expression formatting", function () {
|
|
96
|
+
var e = StringTemplate.compile("{[!!{person.age} ? {person.age:suffix; years old} : 'Age unknown']}");
|
|
97
|
+
var state = {
|
|
98
|
+
person: {
|
|
99
|
+
age: 32,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
assert.equal(e(state), "32 years old");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
package/src/svg/Text.d.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import * as Cx from "../core";
|
|
2
|
-
import { BoundedObject, BoundedObjectProps } from "./BoundedObject";
|
|
3
|
-
|
|
4
|
-
interface TextProps extends BoundedObjectProps {
|
|
5
|
-
/** Text to be displayed. */
|
|
6
|
-
value?: Cx.StringProp;
|
|
7
|
-
|
|
8
|
-
bind?: string;
|
|
9
|
-
tpl?: string;
|
|
10
|
-
expr?: string;
|
|
11
|
-
|
|
12
|
-
/** Offset along the x-axis. */
|
|
13
|
-
dx?: Cx.Prop<string | number>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Offset along the y-axis. This property is commonly used for vertical text alignment.
|
|
17
|
-
* Set dy="0.8em" to align the text with the top and dy="0.4em" to center it vertically.
|
|
18
|
-
*/
|
|
19
|
-
dy?: Cx.Prop<string | number>;
|
|
20
|
-
|
|
21
|
-
/** Used for horizontal text alignment. Accepted values are `start`, `middle` and `end`. */
|
|
22
|
-
textAnchor?: Cx.StringProp;
|
|
23
|
-
|
|
24
|
-
/** Used for horizontal text alignment. Accepted values are `start`, `middle` and `end`. */
|
|
25
|
-
ta?: Cx.StringProp;
|
|
26
|
-
|
|
27
|
-
/** Sets text-body color. */
|
|
28
|
-
fill?: Cx.StringProp;
|
|
29
|
-
|
|
30
|
-
/** Sets text-outline color. */
|
|
31
|
-
stroke?: Cx.StringProp;
|
|
32
|
-
|
|
33
|
-
/** Base CSS class to be applied to the element. Defaults to `text`. */
|
|
34
|
-
baseClass?: string;
|
|
35
|
-
|
|
36
|
-
/** Set to true for the text to set the text anchor based on the direction of the parent element. See PieLabels example. */
|
|
37
|
-
autoTextAnchor?: boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export class Text extends Cx.Widget<TextProps> {}
|
|
1
|
+
import * as Cx from "../core";
|
|
2
|
+
import { BoundedObject, BoundedObjectProps } from "./BoundedObject";
|
|
3
|
+
|
|
4
|
+
interface TextProps extends BoundedObjectProps {
|
|
5
|
+
/** Text to be displayed. */
|
|
6
|
+
value?: Cx.StringProp;
|
|
7
|
+
|
|
8
|
+
bind?: string;
|
|
9
|
+
tpl?: string;
|
|
10
|
+
expr?: string;
|
|
11
|
+
|
|
12
|
+
/** Offset along the x-axis. */
|
|
13
|
+
dx?: Cx.Prop<string | number>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Offset along the y-axis. This property is commonly used for vertical text alignment.
|
|
17
|
+
* Set dy="0.8em" to align the text with the top and dy="0.4em" to center it vertically.
|
|
18
|
+
*/
|
|
19
|
+
dy?: Cx.Prop<string | number>;
|
|
20
|
+
|
|
21
|
+
/** Used for horizontal text alignment. Accepted values are `start`, `middle` and `end`. */
|
|
22
|
+
textAnchor?: Cx.StringProp;
|
|
23
|
+
|
|
24
|
+
/** Used for horizontal text alignment. Accepted values are `start`, `middle` and `end`. */
|
|
25
|
+
ta?: Cx.StringProp;
|
|
26
|
+
|
|
27
|
+
/** Sets text-body color. */
|
|
28
|
+
fill?: Cx.StringProp;
|
|
29
|
+
|
|
30
|
+
/** Sets text-outline color. */
|
|
31
|
+
stroke?: Cx.StringProp;
|
|
32
|
+
|
|
33
|
+
/** Base CSS class to be applied to the element. Defaults to `text`. */
|
|
34
|
+
baseClass?: string;
|
|
35
|
+
|
|
36
|
+
/** Set to true for the text to set the text anchor based on the direction of the parent element. See PieLabels example. */
|
|
37
|
+
autoTextAnchor?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class Text extends Cx.Widget<TextProps> {}
|