cx 24.10.1 → 24.10.3
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 +6 -0
- package/dist/manifest.js +701 -701
- package/dist/util.js +7 -0
- package/dist/widgets.css +23 -20
- package/package.json +1 -1
- package/src/charts/LegendEntry.js +9 -1
- package/src/util/Format.js +269 -261
- package/src/widgets/grid/Grid.scss +637 -680
- package/src/widgets/grid/variables.scss +133 -88
package/dist/util.js
CHANGED
|
@@ -255,6 +255,12 @@ var formatFactory = {
|
|
|
255
255
|
return s.padStart(length, "0");
|
|
256
256
|
};
|
|
257
257
|
},
|
|
258
|
+
leftPad: function leftPad(part0, length, _char) {
|
|
259
|
+
return function (value) {
|
|
260
|
+
var s = String(value);
|
|
261
|
+
return s.padStart(length, _char != null ? _char : " ");
|
|
262
|
+
};
|
|
263
|
+
},
|
|
258
264
|
capitalize: function capitalize$1() {
|
|
259
265
|
return function (value) {
|
|
260
266
|
var s = String(value);
|
|
@@ -279,6 +285,7 @@ formatFactory.d = formatFactory.date;
|
|
|
279
285
|
formatFactory.t = formatFactory.time;
|
|
280
286
|
formatFactory.dt = formatFactory.datetime;
|
|
281
287
|
formatFactory.zeropad = formatFactory.zeroPad;
|
|
288
|
+
formatFactory.leftpad = formatFactory.leftPad;
|
|
282
289
|
formatFactory.capitalize = formatFactory.capitalize;
|
|
283
290
|
formatFactory.titlecase = formatFactory.titleCase;
|
|
284
291
|
function buildFormatter(format) {
|
package/dist/widgets.css
CHANGED
|
@@ -4899,54 +4899,57 @@ th.cxe-calendar-display {
|
|
|
4899
4899
|
.cxe-grid-group-caption:not(:first-child) td {
|
|
4900
4900
|
padding-top: 15px;
|
|
4901
4901
|
}
|
|
4902
|
-
|
|
4903
|
-
|
|
4902
|
+
|
|
4903
|
+
.cxe-grid-group-caption.cxs-level-1 td {
|
|
4904
|
+
font-weight: bold;
|
|
4905
|
+
font-size: 115%;
|
|
4904
4906
|
}
|
|
4907
|
+
|
|
4905
4908
|
.cxe-grid-group-caption.cxs-level-2 td {
|
|
4909
|
+
font-weight: bold;
|
|
4910
|
+
font-size: 130%;
|
|
4906
4911
|
border-bottom: 1px solid grey;
|
|
4907
4912
|
}
|
|
4908
|
-
|
|
4909
|
-
font-size: 145%;
|
|
4910
|
-
}
|
|
4913
|
+
|
|
4911
4914
|
.cxe-grid-group-caption.cxs-level-3 td {
|
|
4915
|
+
font-weight: bold;
|
|
4916
|
+
font-size: 145%;
|
|
4912
4917
|
border-bottom: 1px solid grey;
|
|
4913
4918
|
}
|
|
4914
|
-
|
|
4915
|
-
font-size: 160%;
|
|
4916
|
-
}
|
|
4919
|
+
|
|
4917
4920
|
.cxe-grid-group-caption.cxs-level-4 td {
|
|
4921
|
+
font-weight: bold;
|
|
4922
|
+
font-size: 160%;
|
|
4918
4923
|
border-bottom: 1px solid grey;
|
|
4919
4924
|
}
|
|
4920
4925
|
|
|
4921
|
-
.cxe-grid-group-footer {
|
|
4922
|
-
font-weight: bold;
|
|
4923
|
-
}
|
|
4924
4926
|
.cxe-grid-group-footer td {
|
|
4925
|
-
border-top: 1px solid #bfbfbf;
|
|
4926
4927
|
box-sizing: border-box;
|
|
4927
4928
|
}
|
|
4928
4929
|
.cxe-grid-group-footer td.cxs-pad {
|
|
4929
4930
|
padding: 5px;
|
|
4930
4931
|
}
|
|
4931
|
-
|
|
4932
|
+
|
|
4933
|
+
.cxe-grid-group-footer.cxs-level-1 td {
|
|
4932
4934
|
font-weight: bold;
|
|
4933
|
-
|
|
4935
|
+
border-top: 1px solid #bfbfbf;
|
|
4934
4936
|
}
|
|
4937
|
+
|
|
4935
4938
|
.cxe-grid-group-footer.cxs-level-2 td {
|
|
4939
|
+
font-weight: bold;
|
|
4940
|
+
font-size: 110%;
|
|
4936
4941
|
border-top: 1px solid grey;
|
|
4937
4942
|
}
|
|
4938
|
-
|
|
4943
|
+
|
|
4944
|
+
.cxe-grid-group-footer.cxs-level-3 td {
|
|
4939
4945
|
font-weight: bold;
|
|
4940
4946
|
font-size: 120%;
|
|
4941
|
-
}
|
|
4942
|
-
.cxe-grid-group-footer.cxs-level-3 td {
|
|
4943
4947
|
border-top: 1px solid grey;
|
|
4944
4948
|
}
|
|
4945
|
-
|
|
4949
|
+
|
|
4950
|
+
.cxe-grid-group-footer.cxs-level-4 td {
|
|
4946
4951
|
font-weight: bold;
|
|
4947
4952
|
font-size: 130%;
|
|
4948
|
-
}
|
|
4949
|
-
.cxe-grid-group-footer.cxs-level-4 td {
|
|
4950
4953
|
border-top: 1px solid grey;
|
|
4951
4954
|
}
|
|
4952
4955
|
|
package/package.json
CHANGED
|
@@ -69,7 +69,15 @@ export class LegendEntry extends Container {
|
|
|
69
69
|
let { data } = instance;
|
|
70
70
|
let content = !isUndefined(this.text) ? data.text : this.renderChildren(context, instance);
|
|
71
71
|
return (
|
|
72
|
-
<div
|
|
72
|
+
<div
|
|
73
|
+
key={key}
|
|
74
|
+
className={data.classNames}
|
|
75
|
+
style={data.style}
|
|
76
|
+
onMouseDown={stopPropagation}
|
|
77
|
+
onClick={(e) => {
|
|
78
|
+
this.handleClick(e, instance);
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
73
81
|
{this.renderShape(instance)}
|
|
74
82
|
{content != null && <div>{content}</div>}
|
|
75
83
|
</div>
|
package/src/util/Format.js
CHANGED
|
@@ -1,261 +1,269 @@
|
|
|
1
|
-
import { debug } from "./Debug";
|
|
2
|
-
import { GlobalCacheIdentifier } from "./GlobalCacheIdentifier";
|
|
3
|
-
import { isNumber } from "../util/isNumber";
|
|
4
|
-
import { isUndefined } from "../util/isUndefined";
|
|
5
|
-
import { isArray } from "../util/isArray";
|
|
6
|
-
import { capitalize } from "./capitalize";
|
|
7
|
-
|
|
8
|
-
//Culture dependent formatters are defined in the ui package.
|
|
9
|
-
|
|
10
|
-
const defaultFormatter = (v) => v.toString();
|
|
11
|
-
|
|
12
|
-
let formatFactory = {
|
|
13
|
-
string: function () {
|
|
14
|
-
return defaultFormatter;
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
wrap: function (part0, prefix, suffix) {
|
|
18
|
-
if (!prefix) prefix = "";
|
|
19
|
-
|
|
20
|
-
if (!suffix) suffix = "";
|
|
21
|
-
|
|
22
|
-
return (value) => prefix + value.toString() + suffix;
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
fixed: function (part0, digits) {
|
|
26
|
-
return (value) => value.toFixed(digits);
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
prefix: function (part0, prefix) {
|
|
30
|
-
if (!prefix) prefix = "";
|
|
31
|
-
|
|
32
|
-
return (value) => prefix + value.toString();
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
suffix: function (part0, suffix) {
|
|
36
|
-
if (!suffix) suffix = "";
|
|
37
|
-
|
|
38
|
-
return (value) => value.toString() + suffix;
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
uppercase: function () {
|
|
42
|
-
return (value) => value.toString().toUpperCase();
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
lowercase: function () {
|
|
46
|
-
return (value) => value.toString().toLowerCase();
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
urlencode: function () {
|
|
50
|
-
return (value) => encodeURIComponent(value);
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
number: function (part0, minFractionDigits, maxFractionDigits) {
|
|
54
|
-
let { minimumFractionDigits, maximumFractionDigits } = resolveMinMaxFractionDigits(
|
|
55
|
-
minFractionDigits,
|
|
56
|
-
maxFractionDigits,
|
|
57
|
-
);
|
|
58
|
-
let trimmable = maximumFractionDigits - minimumFractionDigits;
|
|
59
|
-
if (trimmable > 0) {
|
|
60
|
-
if (minimumFractionDigits == 0) ++trimmable;
|
|
61
|
-
return (value) => trimFractionZeros(value.toFixed(maximumFractionDigits), trimmable);
|
|
62
|
-
}
|
|
63
|
-
return (value) => value.toFixed(maximumFractionDigits);
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
percentage: function (part0, minFractionDigits, maxFractionDigits) {
|
|
67
|
-
let numberFormatter = formatFactory.number(part0, minFractionDigits, maxFractionDigits);
|
|
68
|
-
return (value) => numberFormatter(value * 100) + "%";
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
percentageSign: function (part0, minFractionDigits, maxFractionDigits) {
|
|
72
|
-
let numberFormatter = formatFactory.number(part0, minFractionDigits, maxFractionDigits);
|
|
73
|
-
return (value) => numberFormatter(value) + "%";
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
date: function () {
|
|
77
|
-
return (value) => {
|
|
78
|
-
let date = new Date(value);
|
|
79
|
-
return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
time: function () {
|
|
84
|
-
return (value) => {
|
|
85
|
-
let date = new Date(value);
|
|
86
|
-
let h = date.getHours() >= 10 ? date.getHours() : "0" + date.getHours();
|
|
87
|
-
let m = date.getMinutes() >= 10 ? date.getMinutes() : "0" + date.getMinutes();
|
|
88
|
-
return `${h}:${m}`;
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
datetime: function () {
|
|
93
|
-
let date = formatFactory.date();
|
|
94
|
-
let time = formatFactory.time();
|
|
95
|
-
return (value) => date(value) + " " + time(value);
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
ellipsis: function (part0, length, where) {
|
|
99
|
-
length = Number(length);
|
|
100
|
-
if (!(length > 3)) length = 10;
|
|
101
|
-
switch (where) {
|
|
102
|
-
default:
|
|
103
|
-
case "end":
|
|
104
|
-
return (value) => {
|
|
105
|
-
let s = String(value);
|
|
106
|
-
if (s.length > length) return s.substring(0, length - 3) + "...";
|
|
107
|
-
return s;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
case "start":
|
|
111
|
-
return (value) => {
|
|
112
|
-
let s = String(value);
|
|
113
|
-
if (s.length > length) return "..." + s.substring(s.length - length + 3);
|
|
114
|
-
return s;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
case "middle":
|
|
118
|
-
return (value) => {
|
|
119
|
-
let s = String(value);
|
|
120
|
-
if (s.length > length) {
|
|
121
|
-
let x = Math.floor(length - 2) / 2;
|
|
122
|
-
return s.substring(0, x) + "..." + s.substring(s.length - (length - 3 - x));
|
|
123
|
-
}
|
|
124
|
-
return s;
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
zeroPad: function (part0, length) {
|
|
130
|
-
return (value) => {
|
|
131
|
-
let s = String(value);
|
|
132
|
-
return s.padStart(length, "0");
|
|
133
|
-
};
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return (value) => {
|
|
138
|
-
let s = String(value);
|
|
139
|
-
return
|
|
140
|
-
};
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return (value) => {
|
|
145
|
-
let s = String(value);
|
|
146
|
-
return s
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
formatFactory.
|
|
161
|
-
formatFactory.
|
|
162
|
-
formatFactory.
|
|
163
|
-
formatFactory.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
let
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
static
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
minimumFractionDigits
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
1
|
+
import { debug } from "./Debug";
|
|
2
|
+
import { GlobalCacheIdentifier } from "./GlobalCacheIdentifier";
|
|
3
|
+
import { isNumber } from "../util/isNumber";
|
|
4
|
+
import { isUndefined } from "../util/isUndefined";
|
|
5
|
+
import { isArray } from "../util/isArray";
|
|
6
|
+
import { capitalize } from "./capitalize";
|
|
7
|
+
|
|
8
|
+
//Culture dependent formatters are defined in the ui package.
|
|
9
|
+
|
|
10
|
+
const defaultFormatter = (v) => v.toString();
|
|
11
|
+
|
|
12
|
+
let formatFactory = {
|
|
13
|
+
string: function () {
|
|
14
|
+
return defaultFormatter;
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
wrap: function (part0, prefix, suffix) {
|
|
18
|
+
if (!prefix) prefix = "";
|
|
19
|
+
|
|
20
|
+
if (!suffix) suffix = "";
|
|
21
|
+
|
|
22
|
+
return (value) => prefix + value.toString() + suffix;
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
fixed: function (part0, digits) {
|
|
26
|
+
return (value) => value.toFixed(digits);
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
prefix: function (part0, prefix) {
|
|
30
|
+
if (!prefix) prefix = "";
|
|
31
|
+
|
|
32
|
+
return (value) => prefix + value.toString();
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
suffix: function (part0, suffix) {
|
|
36
|
+
if (!suffix) suffix = "";
|
|
37
|
+
|
|
38
|
+
return (value) => value.toString() + suffix;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
uppercase: function () {
|
|
42
|
+
return (value) => value.toString().toUpperCase();
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
lowercase: function () {
|
|
46
|
+
return (value) => value.toString().toLowerCase();
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
urlencode: function () {
|
|
50
|
+
return (value) => encodeURIComponent(value);
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
number: function (part0, minFractionDigits, maxFractionDigits) {
|
|
54
|
+
let { minimumFractionDigits, maximumFractionDigits } = resolveMinMaxFractionDigits(
|
|
55
|
+
minFractionDigits,
|
|
56
|
+
maxFractionDigits,
|
|
57
|
+
);
|
|
58
|
+
let trimmable = maximumFractionDigits - minimumFractionDigits;
|
|
59
|
+
if (trimmable > 0) {
|
|
60
|
+
if (minimumFractionDigits == 0) ++trimmable;
|
|
61
|
+
return (value) => trimFractionZeros(value.toFixed(maximumFractionDigits), trimmable);
|
|
62
|
+
}
|
|
63
|
+
return (value) => value.toFixed(maximumFractionDigits);
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
percentage: function (part0, minFractionDigits, maxFractionDigits) {
|
|
67
|
+
let numberFormatter = formatFactory.number(part0, minFractionDigits, maxFractionDigits);
|
|
68
|
+
return (value) => numberFormatter(value * 100) + "%";
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
percentageSign: function (part0, minFractionDigits, maxFractionDigits) {
|
|
72
|
+
let numberFormatter = formatFactory.number(part0, minFractionDigits, maxFractionDigits);
|
|
73
|
+
return (value) => numberFormatter(value) + "%";
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
date: function () {
|
|
77
|
+
return (value) => {
|
|
78
|
+
let date = new Date(value);
|
|
79
|
+
return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
time: function () {
|
|
84
|
+
return (value) => {
|
|
85
|
+
let date = new Date(value);
|
|
86
|
+
let h = date.getHours() >= 10 ? date.getHours() : "0" + date.getHours();
|
|
87
|
+
let m = date.getMinutes() >= 10 ? date.getMinutes() : "0" + date.getMinutes();
|
|
88
|
+
return `${h}:${m}`;
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
datetime: function () {
|
|
93
|
+
let date = formatFactory.date();
|
|
94
|
+
let time = formatFactory.time();
|
|
95
|
+
return (value) => date(value) + " " + time(value);
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
ellipsis: function (part0, length, where) {
|
|
99
|
+
length = Number(length);
|
|
100
|
+
if (!(length > 3)) length = 10;
|
|
101
|
+
switch (where) {
|
|
102
|
+
default:
|
|
103
|
+
case "end":
|
|
104
|
+
return (value) => {
|
|
105
|
+
let s = String(value);
|
|
106
|
+
if (s.length > length) return s.substring(0, length - 3) + "...";
|
|
107
|
+
return s;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
case "start":
|
|
111
|
+
return (value) => {
|
|
112
|
+
let s = String(value);
|
|
113
|
+
if (s.length > length) return "..." + s.substring(s.length - length + 3);
|
|
114
|
+
return s;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
case "middle":
|
|
118
|
+
return (value) => {
|
|
119
|
+
let s = String(value);
|
|
120
|
+
if (s.length > length) {
|
|
121
|
+
let x = Math.floor(length - 2) / 2;
|
|
122
|
+
return s.substring(0, x) + "..." + s.substring(s.length - (length - 3 - x));
|
|
123
|
+
}
|
|
124
|
+
return s;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
zeroPad: function (part0, length) {
|
|
130
|
+
return (value) => {
|
|
131
|
+
let s = String(value);
|
|
132
|
+
return s.padStart(length, "0");
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
leftPad: function (part0, length, char) {
|
|
137
|
+
return (value) => {
|
|
138
|
+
let s = String(value);
|
|
139
|
+
return s.padStart(length, char ?? " ");
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
capitalize: function () {
|
|
144
|
+
return (value) => {
|
|
145
|
+
let s = String(value);
|
|
146
|
+
return capitalize(s);
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
titleCase: function () {
|
|
151
|
+
return (value) => {
|
|
152
|
+
let s = String(value);
|
|
153
|
+
return s.replace(/\w\S*/g, function (word) {
|
|
154
|
+
return capitalize(word.toLowerCase());
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
formatFactory.s = formatFactory.str = formatFactory.string;
|
|
161
|
+
formatFactory.f = formatFactory.fixed;
|
|
162
|
+
formatFactory.n = formatFactory.number;
|
|
163
|
+
formatFactory.p = formatFactory.percentage;
|
|
164
|
+
formatFactory.ps = formatFactory.percentageSign;
|
|
165
|
+
formatFactory.d = formatFactory.date;
|
|
166
|
+
formatFactory.t = formatFactory.time;
|
|
167
|
+
formatFactory.dt = formatFactory.datetime;
|
|
168
|
+
formatFactory.zeropad = formatFactory.zeroPad;
|
|
169
|
+
formatFactory.leftpad = formatFactory.leftPad;
|
|
170
|
+
formatFactory.capitalize = formatFactory.capitalize;
|
|
171
|
+
formatFactory.titlecase = formatFactory.titleCase;
|
|
172
|
+
|
|
173
|
+
function buildFormatter(format) {
|
|
174
|
+
let formatter = defaultFormatter,
|
|
175
|
+
nullText = "";
|
|
176
|
+
if (format) {
|
|
177
|
+
let pipeParts = format.split("|");
|
|
178
|
+
nullText = pipeParts[1] || "";
|
|
179
|
+
let colonSepParts = pipeParts[0].split(":");
|
|
180
|
+
for (let i = 0; i < colonSepParts.length; i++) {
|
|
181
|
+
let parts = colonSepParts[i].split(";");
|
|
182
|
+
let factory = formatFactory[parts[0]];
|
|
183
|
+
if (!factory) debug("Unknown string format: " + format);
|
|
184
|
+
else if (i == 0) formatter = factory(...parts);
|
|
185
|
+
else {
|
|
186
|
+
let outerFmt = factory(...parts);
|
|
187
|
+
let innerFmt = formatter;
|
|
188
|
+
formatter = (v) => outerFmt(innerFmt(v));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return (v) => (v == null || v === "" ? nullText : formatter(v));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
let format = {
|
|
196
|
+
cache: {},
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
function getDefaultFormatCache() {
|
|
200
|
+
if (format.cacheIdentifier != GlobalCacheIdentifier.get()) {
|
|
201
|
+
format = {
|
|
202
|
+
cache: {},
|
|
203
|
+
cacheIdentifier: GlobalCacheIdentifier.get(),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return format.cache;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let getFormatCache = getDefaultFormatCache;
|
|
210
|
+
|
|
211
|
+
export function setGetFormatCacheCallback(callback) {
|
|
212
|
+
getFormatCache = callback;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function getFormatter(format) {
|
|
216
|
+
if (!format) format = "";
|
|
217
|
+
let formatCache = getFormatCache();
|
|
218
|
+
let formatter = formatCache[format];
|
|
219
|
+
if (!formatter) formatter = formatCache[format] = buildFormatter(format);
|
|
220
|
+
|
|
221
|
+
return formatter;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export class Format {
|
|
225
|
+
static value(v, format) {
|
|
226
|
+
let formatter = getFormatter(format);
|
|
227
|
+
return formatter(v);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
static parse(format) {
|
|
231
|
+
return getFormatter(format);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
static register(format, formatter) {
|
|
235
|
+
this.registerFactory(format, () => formatter);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static registerFactory(format, factory) {
|
|
239
|
+
if (isArray(format)) format.forEach((f) => this.registerFactory(f, factory));
|
|
240
|
+
else formatFactory[format] = factory;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits) {
|
|
245
|
+
minimumFractionDigits = minimumFractionDigits != null ? Number(minimumFractionDigits) : minimumFractionDigits;
|
|
246
|
+
maximumFractionDigits = maximumFractionDigits != null ? Number(maximumFractionDigits) : maximumFractionDigits;
|
|
247
|
+
|
|
248
|
+
if (isNumber(minimumFractionDigits)) {
|
|
249
|
+
if (isUndefined(maximumFractionDigits)) maximumFractionDigits = minimumFractionDigits;
|
|
250
|
+
else if (isNumber(maximumFractionDigits) && maximumFractionDigits < minimumFractionDigits)
|
|
251
|
+
maximumFractionDigits = minimumFractionDigits;
|
|
252
|
+
} else if (minimumFractionDigits == null && maximumFractionDigits == null) {
|
|
253
|
+
minimumFractionDigits = 0;
|
|
254
|
+
maximumFractionDigits = 18;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
minimumFractionDigits,
|
|
259
|
+
maximumFractionDigits,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function trimFractionZeros(str, max) {
|
|
264
|
+
let cnt = 0,
|
|
265
|
+
l = str.length;
|
|
266
|
+
while (cnt < max && (str[l - 1 - cnt] === "0" || str[l - 1 - cnt] === ".")) cnt++;
|
|
267
|
+
|
|
268
|
+
return cnt > 0 ? str.substring(0, l - cnt) : str;
|
|
269
|
+
}
|