cx 24.4.6 → 24.4.7
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/charts.js +1 -0
- package/dist/manifest.js +650 -650
- package/dist/widgets.js +1 -1
- package/package.json +1 -1
- package/src/charts/Chart.js +75 -75
- package/src/charts/ColumnBarBase.d.ts +64 -64
- package/src/charts/ColumnBarGraphBase.d.ts +73 -73
- package/src/charts/Legend.js +1 -0
- package/src/charts/LineGraph.d.ts +92 -92
- package/src/charts/PieLabel.js +71 -71
- package/src/charts/ScatterGraph.d.ts +64 -64
- package/src/charts/axis/Axis.d.ts +96 -96
- package/src/charts/axis/Axis.js +254 -254
- package/src/charts/axis/CategoryAxis.d.ts +24 -24
- package/src/charts/axis/CategoryAxis.js +212 -212
- package/src/data/StringTemplate.spec.js +105 -105
- package/src/data/getAccessor.spec.js +11 -11
- package/src/svg/Text.d.ts +40 -40
- package/src/ui/Controller.d.ts +182 -182
- package/src/ui/Culture.js +129 -129
- package/src/ui/FocusManager.js +171 -171
- package/src/ui/Instance.d.ts +72 -72
- package/src/ui/index.d.ts +42 -42
- package/src/util/Console.d.ts +4 -4
- package/src/widgets/drag-drop/DropZone.js +214 -213
- package/src/widgets/form/UploadButton.d.ts +34 -34
- package/src/widgets/grid/variables.scss +88 -88
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
import { Axis } from "./Axis";
|
|
2
|
-
import { VDOM } from "../../ui/Widget";
|
|
3
|
-
import { isUndefined } from "../../util/isUndefined";
|
|
4
|
-
import { isArray } from "../../util/isArray";
|
|
5
|
-
|
|
6
|
-
export class CategoryAxis extends Axis {
|
|
7
|
-
declareData() {
|
|
8
|
-
super.declareData(...arguments, {
|
|
9
|
-
inverted: undefined,
|
|
10
|
-
uniform: undefined,
|
|
11
|
-
names: undefined,
|
|
12
|
-
values: undefined,
|
|
13
|
-
minSize: undefined,
|
|
14
|
-
categoryCount: undefined,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
initInstance(context, instance) {
|
|
19
|
-
instance.calculator = new CategoryScale();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
explore(context, instance) {
|
|
23
|
-
super.explore(context, instance);
|
|
24
|
-
var { values, names, inverted, uniform, minSize } = instance.data;
|
|
25
|
-
instance.calculator.reset(inverted, uniform, values, names, minSize);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
reportData(context, instance) {
|
|
29
|
-
instance.set("categoryCount", instance.calculator.valueList.length);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
render(context, instance, key) {
|
|
33
|
-
var { data, calculator } = instance;
|
|
34
|
-
|
|
35
|
-
if (!data.bounds.valid()) return null;
|
|
36
|
-
|
|
37
|
-
var formatter = (v) => calculator.names[v] || v;
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<g key={key} className={data.classNames} style={data.style}>
|
|
41
|
-
{this.renderTicksAndLabels(context, instance, formatter)}
|
|
42
|
-
</g>
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
CategoryAxis.prototype.baseClass = "categoryaxis";
|
|
48
|
-
CategoryAxis.prototype.anchors = "0 1 1 0";
|
|
49
|
-
CategoryAxis.prototype.vertical = false;
|
|
50
|
-
CategoryAxis.prototype.inverted = false;
|
|
51
|
-
CategoryAxis.prototype.uniform = false;
|
|
52
|
-
CategoryAxis.prototype.labelOffset = 10;
|
|
53
|
-
CategoryAxis.prototype.labelRotation = 0;
|
|
54
|
-
CategoryAxis.prototype.labelAnchor = "auto";
|
|
55
|
-
CategoryAxis.prototype.labelDx = "auto";
|
|
56
|
-
CategoryAxis.prototype.labelDy = "auto";
|
|
57
|
-
CategoryAxis.prototype.minSize = 1;
|
|
58
|
-
|
|
59
|
-
Axis.alias("category", CategoryAxis);
|
|
60
|
-
|
|
61
|
-
class CategoryScale {
|
|
62
|
-
reset(inverted, uniform, values, names, minSize) {
|
|
63
|
-
this.padding = 0.5;
|
|
64
|
-
delete this.min;
|
|
65
|
-
delete this.max;
|
|
66
|
-
delete this.minValue;
|
|
67
|
-
delete this.maxValue;
|
|
68
|
-
this.minSize = minSize;
|
|
69
|
-
this.valuesMap = {};
|
|
70
|
-
this.valueList = [];
|
|
71
|
-
this.inverted = inverted;
|
|
72
|
-
this.uniform = uniform;
|
|
73
|
-
this.valueStacks = {};
|
|
74
|
-
this.names = {};
|
|
75
|
-
|
|
76
|
-
if (values) {
|
|
77
|
-
if (isArray(values)) values.forEach((v) => this.acknowledge(v));
|
|
78
|
-
else if (typeof values == "object")
|
|
79
|
-
for (var k in values) {
|
|
80
|
-
this.acknowledge(k);
|
|
81
|
-
this.names[k] = values[k];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (names) {
|
|
86
|
-
if (isArray(names)) {
|
|
87
|
-
values = values || [];
|
|
88
|
-
names.forEach((name, index) => {
|
|
89
|
-
var value = values[index];
|
|
90
|
-
this.names[value != null ? value : index] = name;
|
|
91
|
-
});
|
|
92
|
-
} else this.names = names;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
decodeValue(n) {
|
|
97
|
-
return n;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
encodeValue(v) {
|
|
101
|
-
return v;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
map(v, offset = 0) {
|
|
105
|
-
var index = this.valuesMap[v] || 0;
|
|
106
|
-
|
|
107
|
-
return this.origin + (index + offset - this.min + this.padding) * this.factor;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
measure(a, b) {
|
|
111
|
-
this.a = a;
|
|
112
|
-
this.b = b;
|
|
113
|
-
|
|
114
|
-
if (this.min == null) this.min = this.minValue || 0;
|
|
115
|
-
|
|
116
|
-
if (this.max == null) this.max = !isNaN(this.maxValue) ? this.maxValue : 100;
|
|
117
|
-
|
|
118
|
-
var sign = this.inverted ? -1 : 1;
|
|
119
|
-
|
|
120
|
-
if (this.max - this.min + 1 < this.minSize) {
|
|
121
|
-
this.factor = (sign * (this.b - this.a)) / this.minSize;
|
|
122
|
-
this.origin = (this.b + this.a) * 0.5 - (this.factor * (this.max - this.min + 1)) / 2;
|
|
123
|
-
} else {
|
|
124
|
-
this.factor = (sign * (this.b - this.a)) / (this.max - this.min + 2 * this.padding);
|
|
125
|
-
this.origin = (this.a * (1 + sign)) / 2 + (this.b * (1 - sign)) / 2; //a || b
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
hash() {
|
|
130
|
-
return {
|
|
131
|
-
origin: this.origin,
|
|
132
|
-
factor: this.factor,
|
|
133
|
-
min: this.min,
|
|
134
|
-
minSize: this.minSize,
|
|
135
|
-
padding: this.padding,
|
|
136
|
-
values: this.valueList.join(":"),
|
|
137
|
-
names: JSON.stringify(this.names),
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
isSame(x) {
|
|
142
|
-
var h = this.hash();
|
|
143
|
-
var same = x && !Object.keys(h).some((k) => x[k] !== h[k]);
|
|
144
|
-
this.shouldUpdate = !same;
|
|
145
|
-
return same;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
acknowledge(value, width = 0, offset = 0) {
|
|
149
|
-
var index = this.valuesMap[value];
|
|
150
|
-
if (isUndefined(index)) {
|
|
151
|
-
index = this.valueList.length;
|
|
152
|
-
this.valueList.push(value);
|
|
153
|
-
this.valuesMap[value] = index;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (this.minValue == null || index < this.minValue) {
|
|
157
|
-
this.minValue = index;
|
|
158
|
-
this.padding = Math.max(this.padding, Math.abs(offset - width / 2));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (this.maxValue == null || index > this.maxValue) {
|
|
162
|
-
this.maxValue = index;
|
|
163
|
-
this.padding = Math.max(this.padding, Math.abs(offset + width / 2));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
book(value, name) {
|
|
168
|
-
if (this.uniform) value = 0;
|
|
169
|
-
|
|
170
|
-
var stack = this.valueStacks[value];
|
|
171
|
-
if (!stack)
|
|
172
|
-
stack = this.valueStacks[value] = {
|
|
173
|
-
index: {},
|
|
174
|
-
count: 0,
|
|
175
|
-
};
|
|
176
|
-
if (!stack.index.hasOwnProperty(name)) stack.index[name] = stack.count++;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
locate(value, name) {
|
|
180
|
-
if (this.uniform) value = 0;
|
|
181
|
-
|
|
182
|
-
var stack = this.valueStacks[value];
|
|
183
|
-
if (!stack) return [0, 1];
|
|
184
|
-
|
|
185
|
-
return [stack.index[name], stack.count];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
trackValue(v, offset = 0, constrain = false) {
|
|
189
|
-
let index = Math.round((v - this.origin) / this.factor - offset + this.min - this.padding);
|
|
190
|
-
if (index < this.min) index = this.min;
|
|
191
|
-
if (index > this.max) index = this.max;
|
|
192
|
-
return this.valueList[index];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
findTickSize(minPxDist) {
|
|
196
|
-
return 1;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
getTickSizes() {
|
|
200
|
-
return [1];
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
getTicks(tickSizes) {
|
|
204
|
-
return tickSizes.map((size) => this.valueList);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
mapGridlines() {
|
|
208
|
-
return Array.from({ length: this.valueList.length + 1 }).map(
|
|
209
|
-
(_, index) => this.origin + (index - 0.5 - this.min + this.padding) * this.factor,
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
1
|
+
import { Axis } from "./Axis";
|
|
2
|
+
import { VDOM } from "../../ui/Widget";
|
|
3
|
+
import { isUndefined } from "../../util/isUndefined";
|
|
4
|
+
import { isArray } from "../../util/isArray";
|
|
5
|
+
|
|
6
|
+
export class CategoryAxis extends Axis {
|
|
7
|
+
declareData() {
|
|
8
|
+
super.declareData(...arguments, {
|
|
9
|
+
inverted: undefined,
|
|
10
|
+
uniform: undefined,
|
|
11
|
+
names: undefined,
|
|
12
|
+
values: undefined,
|
|
13
|
+
minSize: undefined,
|
|
14
|
+
categoryCount: undefined,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
initInstance(context, instance) {
|
|
19
|
+
instance.calculator = new CategoryScale();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
explore(context, instance) {
|
|
23
|
+
super.explore(context, instance);
|
|
24
|
+
var { values, names, inverted, uniform, minSize } = instance.data;
|
|
25
|
+
instance.calculator.reset(inverted, uniform, values, names, minSize);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
reportData(context, instance) {
|
|
29
|
+
instance.set("categoryCount", instance.calculator.valueList.length);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
render(context, instance, key) {
|
|
33
|
+
var { data, calculator } = instance;
|
|
34
|
+
|
|
35
|
+
if (!data.bounds.valid()) return null;
|
|
36
|
+
|
|
37
|
+
var formatter = (v) => calculator.names[v] || v;
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<g key={key} className={data.classNames} style={data.style}>
|
|
41
|
+
{this.renderTicksAndLabels(context, instance, formatter)}
|
|
42
|
+
</g>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
CategoryAxis.prototype.baseClass = "categoryaxis";
|
|
48
|
+
CategoryAxis.prototype.anchors = "0 1 1 0";
|
|
49
|
+
CategoryAxis.prototype.vertical = false;
|
|
50
|
+
CategoryAxis.prototype.inverted = false;
|
|
51
|
+
CategoryAxis.prototype.uniform = false;
|
|
52
|
+
CategoryAxis.prototype.labelOffset = 10;
|
|
53
|
+
CategoryAxis.prototype.labelRotation = 0;
|
|
54
|
+
CategoryAxis.prototype.labelAnchor = "auto";
|
|
55
|
+
CategoryAxis.prototype.labelDx = "auto";
|
|
56
|
+
CategoryAxis.prototype.labelDy = "auto";
|
|
57
|
+
CategoryAxis.prototype.minSize = 1;
|
|
58
|
+
|
|
59
|
+
Axis.alias("category", CategoryAxis);
|
|
60
|
+
|
|
61
|
+
class CategoryScale {
|
|
62
|
+
reset(inverted, uniform, values, names, minSize) {
|
|
63
|
+
this.padding = 0.5;
|
|
64
|
+
delete this.min;
|
|
65
|
+
delete this.max;
|
|
66
|
+
delete this.minValue;
|
|
67
|
+
delete this.maxValue;
|
|
68
|
+
this.minSize = minSize;
|
|
69
|
+
this.valuesMap = {};
|
|
70
|
+
this.valueList = [];
|
|
71
|
+
this.inverted = inverted;
|
|
72
|
+
this.uniform = uniform;
|
|
73
|
+
this.valueStacks = {};
|
|
74
|
+
this.names = {};
|
|
75
|
+
|
|
76
|
+
if (values) {
|
|
77
|
+
if (isArray(values)) values.forEach((v) => this.acknowledge(v));
|
|
78
|
+
else if (typeof values == "object")
|
|
79
|
+
for (var k in values) {
|
|
80
|
+
this.acknowledge(k);
|
|
81
|
+
this.names[k] = values[k];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (names) {
|
|
86
|
+
if (isArray(names)) {
|
|
87
|
+
values = values || [];
|
|
88
|
+
names.forEach((name, index) => {
|
|
89
|
+
var value = values[index];
|
|
90
|
+
this.names[value != null ? value : index] = name;
|
|
91
|
+
});
|
|
92
|
+
} else this.names = names;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
decodeValue(n) {
|
|
97
|
+
return n;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
encodeValue(v) {
|
|
101
|
+
return v;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
map(v, offset = 0) {
|
|
105
|
+
var index = this.valuesMap[v] || 0;
|
|
106
|
+
|
|
107
|
+
return this.origin + (index + offset - this.min + this.padding) * this.factor;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
measure(a, b) {
|
|
111
|
+
this.a = a;
|
|
112
|
+
this.b = b;
|
|
113
|
+
|
|
114
|
+
if (this.min == null) this.min = this.minValue || 0;
|
|
115
|
+
|
|
116
|
+
if (this.max == null) this.max = !isNaN(this.maxValue) ? this.maxValue : 100;
|
|
117
|
+
|
|
118
|
+
var sign = this.inverted ? -1 : 1;
|
|
119
|
+
|
|
120
|
+
if (this.max - this.min + 1 < this.minSize) {
|
|
121
|
+
this.factor = (sign * (this.b - this.a)) / this.minSize;
|
|
122
|
+
this.origin = (this.b + this.a) * 0.5 - (this.factor * (this.max - this.min + 1)) / 2;
|
|
123
|
+
} else {
|
|
124
|
+
this.factor = (sign * (this.b - this.a)) / (this.max - this.min + 2 * this.padding);
|
|
125
|
+
this.origin = (this.a * (1 + sign)) / 2 + (this.b * (1 - sign)) / 2; //a || b
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
hash() {
|
|
130
|
+
return {
|
|
131
|
+
origin: this.origin,
|
|
132
|
+
factor: this.factor,
|
|
133
|
+
min: this.min,
|
|
134
|
+
minSize: this.minSize,
|
|
135
|
+
padding: this.padding,
|
|
136
|
+
values: this.valueList.join(":"),
|
|
137
|
+
names: JSON.stringify(this.names),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
isSame(x) {
|
|
142
|
+
var h = this.hash();
|
|
143
|
+
var same = x && !Object.keys(h).some((k) => x[k] !== h[k]);
|
|
144
|
+
this.shouldUpdate = !same;
|
|
145
|
+
return same;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
acknowledge(value, width = 0, offset = 0) {
|
|
149
|
+
var index = this.valuesMap[value];
|
|
150
|
+
if (isUndefined(index)) {
|
|
151
|
+
index = this.valueList.length;
|
|
152
|
+
this.valueList.push(value);
|
|
153
|
+
this.valuesMap[value] = index;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (this.minValue == null || index < this.minValue) {
|
|
157
|
+
this.minValue = index;
|
|
158
|
+
this.padding = Math.max(this.padding, Math.abs(offset - width / 2));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (this.maxValue == null || index > this.maxValue) {
|
|
162
|
+
this.maxValue = index;
|
|
163
|
+
this.padding = Math.max(this.padding, Math.abs(offset + width / 2));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
book(value, name) {
|
|
168
|
+
if (this.uniform) value = 0;
|
|
169
|
+
|
|
170
|
+
var stack = this.valueStacks[value];
|
|
171
|
+
if (!stack)
|
|
172
|
+
stack = this.valueStacks[value] = {
|
|
173
|
+
index: {},
|
|
174
|
+
count: 0,
|
|
175
|
+
};
|
|
176
|
+
if (!stack.index.hasOwnProperty(name)) stack.index[name] = stack.count++;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
locate(value, name) {
|
|
180
|
+
if (this.uniform) value = 0;
|
|
181
|
+
|
|
182
|
+
var stack = this.valueStacks[value];
|
|
183
|
+
if (!stack) return [0, 1];
|
|
184
|
+
|
|
185
|
+
return [stack.index[name], stack.count];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
trackValue(v, offset = 0, constrain = false) {
|
|
189
|
+
let index = Math.round((v - this.origin) / this.factor - offset + this.min - this.padding);
|
|
190
|
+
if (index < this.min) index = this.min;
|
|
191
|
+
if (index > this.max) index = this.max;
|
|
192
|
+
return this.valueList[index];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
findTickSize(minPxDist) {
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
getTickSizes() {
|
|
200
|
+
return [1];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
getTicks(tickSizes) {
|
|
204
|
+
return tickSizes.map((size) => this.valueList);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
mapGridlines() {
|
|
208
|
+
return Array.from({ length: this.valueList.length + 1 }).map(
|
|
209
|
+
(_, index) => this.origin + (index - 0.5 - this.min + this.padding) * this.factor,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import assert from "assert";
|
|
2
|
-
import { createAccessorModelProxy } from "./createAccessorModelProxy";
|
|
3
|
-
import { getAccessor } from "./getAccessor";
|
|
4
|
-
|
|
5
|
-
describe("getAccessor", function () {
|
|
6
|
-
it("works with accessor chains", function () {
|
|
7
|
-
let m = createAccessorModelProxy();
|
|
8
|
-
let accessor = getAccessor(m.a.b);
|
|
9
|
-
assert(typeof accessor.set == "function");
|
|
10
|
-
});
|
|
11
|
-
});
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { createAccessorModelProxy } from "./createAccessorModelProxy";
|
|
3
|
+
import { getAccessor } from "./getAccessor";
|
|
4
|
+
|
|
5
|
+
describe("getAccessor", function () {
|
|
6
|
+
it("works with accessor chains", function () {
|
|
7
|
+
let m = createAccessorModelProxy();
|
|
8
|
+
let accessor = getAccessor(m.a.b);
|
|
9
|
+
assert(typeof accessor.set == "function");
|
|
10
|
+
});
|
|
11
|
+
});
|