cx 24.3.11 → 24.4.1

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/src/ui/index.js CHANGED
@@ -1,45 +1,44 @@
1
- export * from "./Controller";
2
- export * from "./Widget";
3
- export * from "./Container";
4
- export * from "./PureContainer";
5
- export * from "./Repeater";
6
- export * from "./Rescope";
7
- export * from "./StaticText";
8
- export * from "./Text";
9
- export * from "./CSS";
10
- export * from "./CSSHelper";
11
- export * from "./FocusManager";
12
- export * from "./ResizeManager";
13
- export * from "./ZIndexManager";
14
- export * from "./Format";
15
- export * from "./Culture";
16
- export * from "./Localization";
17
- export * from "./Cx";
18
- export * from "./Instance";
19
- export * from "./RenderingContext";
20
- export * from "./ContentResolver";
21
- export * from "./batchUpdates";
22
- export * from "./IsolatedScope";
23
- export * from "./DetachedScope";
24
- export * from "./Restate";
25
- export * from "./DataProxy";
26
- export * from "./keyboardShortcuts";
27
- export * from "./StructuredInstanceDataAccessor";
28
- export * from "./HoverSync";
29
- export * from "./CultureScope";
30
-
31
- export * from "./createFunctionalComponent";
32
- export * from "./flattenProps";
33
-
34
- export * from "./selection/index";
35
- export * from "./layout/index";
36
- export * from "./app/index";
37
- export * from "./adapter/index";
38
-
39
- export * from "./bind";
40
- export * from "./tpl";
41
- export * from "./expr";
42
-
43
- //re-export computable here
44
- import { computable } from "../data/computable";
45
- export { computable };
1
+ export * from "./Controller";
2
+ export * from "./Widget";
3
+ export * from "./Container";
4
+ export * from "./PureContainer";
5
+ export * from "./Repeater";
6
+ export * from "./Rescope";
7
+ export * from "./StaticText";
8
+ export * from "./Text";
9
+ export * from "./CSS";
10
+ export * from "./CSSHelper";
11
+ export * from "./FocusManager";
12
+ export * from "./ResizeManager";
13
+ export * from "./ZIndexManager";
14
+ export * from "./Format";
15
+ export * from "./Culture";
16
+ export * from "./Localization";
17
+ export * from "./Cx";
18
+ export * from "./Instance";
19
+ export * from "./RenderingContext";
20
+ export * from "./ContentResolver";
21
+ export * from "./batchUpdates";
22
+ export * from "./IsolatedScope";
23
+ export * from "./DetachedScope";
24
+ export * from "./Restate";
25
+ export * from "./DataProxy";
26
+ export * from "./keyboardShortcuts";
27
+ export * from "./StructuredInstanceDataAccessor";
28
+ export * from "./HoverSync";
29
+
30
+ export * from "./createFunctionalComponent";
31
+ export * from "./flattenProps";
32
+
33
+ export * from "./selection/index";
34
+ export * from "./layout/index";
35
+ export * from "./app/index";
36
+ export * from "./adapter/index";
37
+
38
+ export * from "./bind";
39
+ export * from "./tpl";
40
+ export * from "./expr";
41
+
42
+ //re-export computable here
43
+ import { computable } from "../data/computable";
44
+ export { computable };
@@ -1,9 +1,4 @@
1
-
2
1
  export class Console {
3
-
4
- static log();
5
-
6
- static warn();
7
-
2
+ static log(...args: unknown[]): void;
3
+ static warn(...args: unknown[]): void;
8
4
  }
9
-
@@ -1,18 +1,18 @@
1
- declare type Formatter = (any) => string;
2
-
3
- export class Format {
4
- static value(v: any, format: string): string;
5
-
6
- static parse(format: string): Formatter;
7
-
8
- static register(format: string | string[], formatter: Formatter): void;
9
-
10
- static registerFactory(format: string | string[], factory: (...args) => Formatter): void;
11
- }
12
-
13
- export function resolveMinMaxFractionDigits(
14
- minimumFractionDigits: number,
15
- maximumFractionDigits: number,
16
- ): { minimumFractionDigits: number; maximumFractionDigits: number };
17
-
18
- export function setGetFormatCacheCallback(callback: () => {}): void;
1
+ declare type Formatter = (any) => string;
2
+
3
+ export class Format {
4
+ static value(v: any, format: string): string;
5
+
6
+ static parse(format: string): Formatter;
7
+
8
+ static register(format: string | string[], formatter: Formatter): void;
9
+
10
+ static registerFactory(format: string | string[], factory: (...args) => Formatter): void;
11
+ }
12
+
13
+ export function resolveMinMaxFractionDigits(
14
+ minimumFractionDigits: number,
15
+ maximumFractionDigits: number,
16
+ ): { minimumFractionDigits: number; maximumFractionDigits: number };
17
+
18
+ export function setGetFormatCacheCallback(callback: () => {}): void;
@@ -1,234 +1,234 @@
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
-
7
- //Culture dependent formatters are defined in the ui package.
8
-
9
- const defaultFormatter = (v) => v.toString();
10
-
11
- let formatFactory = {
12
- string: function () {
13
- return defaultFormatter;
14
- },
15
-
16
- wrap: function (part0, prefix, suffix) {
17
- if (!prefix) prefix = "";
18
-
19
- if (!suffix) suffix = "";
20
-
21
- return (value) => prefix + value.toString() + suffix;
22
- },
23
-
24
- fixed: function (part0, digits) {
25
- return (value) => value.toFixed(digits);
26
- },
27
-
28
- prefix: function (part0, prefix) {
29
- if (!prefix) prefix = "";
30
-
31
- return (value) => prefix + value.toString();
32
- },
33
-
34
- suffix: function (part0, suffix) {
35
- if (!suffix) suffix = "";
36
-
37
- return (value) => value.toString() + suffix;
38
- },
39
-
40
- uppercase: function () {
41
- return (value) => value.toString().toUpperCase();
42
- },
43
-
44
- lowercase: function () {
45
- return (value) => value.toString().toLowerCase();
46
- },
47
-
48
- urlencode: function () {
49
- return (value) => encodeURIComponent(value);
50
- },
51
-
52
- number: function (part0, minFractionDigits, maxFractionDigits) {
53
- let { minimumFractionDigits, maximumFractionDigits } = resolveMinMaxFractionDigits(
54
- minFractionDigits,
55
- maxFractionDigits,
56
- );
57
- let trimmable = maximumFractionDigits - minimumFractionDigits;
58
- if (trimmable > 0) {
59
- if (minimumFractionDigits == 0) ++trimmable;
60
- return (value) => trimFractionZeros(value.toFixed(maximumFractionDigits), trimmable);
61
- }
62
- return (value) => value.toFixed(maximumFractionDigits);
63
- },
64
-
65
- percentage: function (part0, minFractionDigits, maxFractionDigits) {
66
- let numberFormatter = formatFactory.number(part0, minFractionDigits, maxFractionDigits);
67
- return (value) => numberFormatter(value * 100) + "%";
68
- },
69
-
70
- percentageSign: function (part0, minFractionDigits, maxFractionDigits) {
71
- let numberFormatter = formatFactory.number(part0, minFractionDigits, maxFractionDigits);
72
- return (value) => numberFormatter(value) + "%";
73
- },
74
-
75
- date: function () {
76
- return (value) => {
77
- let date = new Date(value);
78
- return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
79
- };
80
- },
81
-
82
- time: function () {
83
- return (value) => {
84
- let date = new Date(value);
85
- let h = date.getHours() >= 10 ? date.getHours() : "0" + date.getHours();
86
- let m = date.getMinutes() >= 10 ? date.getMinutes() : "0" + date.getMinutes();
87
- return `${h}:${m}`;
88
- };
89
- },
90
-
91
- datetime: function () {
92
- let date = formatFactory.date();
93
- let time = formatFactory.time();
94
- return (value) => date(value) + " " + time(value);
95
- },
96
-
97
- ellipsis: function (part0, length, where) {
98
- length = Number(length);
99
- if (!(length > 3)) length = 10;
100
- switch (where) {
101
- default:
102
- case "end":
103
- return (value) => {
104
- let s = String(value);
105
- if (s.length > length) return s.substring(0, length - 3) + "...";
106
- return s;
107
- };
108
-
109
- case "start":
110
- return (value) => {
111
- let s = String(value);
112
- if (s.length > length) return "..." + s.substring(s.length - length + 3);
113
- return s;
114
- };
115
-
116
- case "middle":
117
- return (value) => {
118
- let s = String(value);
119
- if (s.length > length) {
120
- let x = Math.floor(length - 2) / 2;
121
- return s.substring(0, x) + "..." + s.substring(s.length - (length - 3 - x));
122
- }
123
- return s;
124
- };
125
- }
126
- },
127
- };
128
-
129
- formatFactory.s = formatFactory.str = formatFactory.string;
130
- formatFactory.f = formatFactory.fixed;
131
- formatFactory.n = formatFactory.number;
132
- formatFactory.p = formatFactory.percentage;
133
- formatFactory.ps = formatFactory.percentageSign;
134
- formatFactory.d = formatFactory.date;
135
- formatFactory.t = formatFactory.time;
136
- formatFactory.dt = formatFactory.datetime;
137
-
138
- function buildFormatter(format) {
139
- let formatter = defaultFormatter,
140
- nullText = "";
141
- if (format) {
142
- let pipeParts = format.split("|");
143
- nullText = pipeParts[1] || "";
144
- let colonSepParts = pipeParts[0].split(":");
145
- for (let i = 0; i < colonSepParts.length; i++) {
146
- let parts = colonSepParts[i].split(";");
147
- let factory = formatFactory[parts[0]];
148
- if (!factory) debug("Unknown string format: " + format);
149
- else if (i == 0) formatter = factory(...parts);
150
- else {
151
- let outerFmt = factory(...parts);
152
- let innerFmt = formatter;
153
- formatter = (v) => outerFmt(innerFmt(v));
154
- }
155
- }
156
- }
157
- return (v) => (v == null || v === "" ? nullText : formatter(v));
158
- }
159
-
160
- let format = {
161
- cache: {},
162
- };
163
-
164
- function getDefaultFormatCache() {
165
- if (format.cacheIdentifier != GlobalCacheIdentifier.get()) {
166
- format = {
167
- cache: {},
168
- cacheIdentifier: GlobalCacheIdentifier.get(),
169
- };
170
- }
171
- return format.cache;
172
- }
173
-
174
- let getFormatCache = getDefaultFormatCache;
175
-
176
- export function setGetFormatCacheCallback(callback) {
177
- getFormatCache = callback;
178
- }
179
-
180
- function getFormatter(format) {
181
- if (!format) format = "";
182
- let formatCache = getFormatCache();
183
- let formatter = formatCache[format];
184
- if (!formatter) formatter = formatCache[format] = buildFormatter(format);
185
-
186
- return formatter;
187
- }
188
-
189
- export class Format {
190
- static value(v, format) {
191
- let formatter = getFormatter(format);
192
- return formatter(v);
193
- }
194
-
195
- static parse(format) {
196
- return getFormatter(format);
197
- }
198
-
199
- static register(format, formatter) {
200
- this.registerFactory(format, () => formatter);
201
- }
202
-
203
- static registerFactory(format, factory) {
204
- if (isArray(format)) format.forEach((f) => this.registerFactory(f, factory));
205
- else formatFactory[format] = factory;
206
- }
207
- }
208
-
209
- export function resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits) {
210
- minimumFractionDigits = minimumFractionDigits != null ? Number(minimumFractionDigits) : minimumFractionDigits;
211
- maximumFractionDigits = maximumFractionDigits != null ? Number(maximumFractionDigits) : maximumFractionDigits;
212
-
213
- if (isNumber(minimumFractionDigits)) {
214
- if (isUndefined(maximumFractionDigits)) maximumFractionDigits = minimumFractionDigits;
215
- else if (isNumber(maximumFractionDigits) && maximumFractionDigits < minimumFractionDigits)
216
- maximumFractionDigits = minimumFractionDigits;
217
- } else if (minimumFractionDigits == null && maximumFractionDigits == null) {
218
- minimumFractionDigits = 0;
219
- maximumFractionDigits = 18;
220
- }
221
-
222
- return {
223
- minimumFractionDigits,
224
- maximumFractionDigits,
225
- };
226
- }
227
-
228
- export function trimFractionZeros(str, max) {
229
- let cnt = 0,
230
- l = str.length;
231
- while (cnt < max && (str[l - 1 - cnt] === "0" || str[l - 1 - cnt] === ".")) cnt++;
232
-
233
- return cnt > 0 ? str.substring(0, l - cnt) : str;
234
- }
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
+
7
+ //Culture dependent formatters are defined in the ui package.
8
+
9
+ const defaultFormatter = (v) => v.toString();
10
+
11
+ let formatFactory = {
12
+ string: function () {
13
+ return defaultFormatter;
14
+ },
15
+
16
+ wrap: function (part0, prefix, suffix) {
17
+ if (!prefix) prefix = "";
18
+
19
+ if (!suffix) suffix = "";
20
+
21
+ return (value) => prefix + value.toString() + suffix;
22
+ },
23
+
24
+ fixed: function (part0, digits) {
25
+ return (value) => value.toFixed(digits);
26
+ },
27
+
28
+ prefix: function (part0, prefix) {
29
+ if (!prefix) prefix = "";
30
+
31
+ return (value) => prefix + value.toString();
32
+ },
33
+
34
+ suffix: function (part0, suffix) {
35
+ if (!suffix) suffix = "";
36
+
37
+ return (value) => value.toString() + suffix;
38
+ },
39
+
40
+ uppercase: function () {
41
+ return (value) => value.toString().toUpperCase();
42
+ },
43
+
44
+ lowercase: function () {
45
+ return (value) => value.toString().toLowerCase();
46
+ },
47
+
48
+ urlencode: function () {
49
+ return (value) => encodeURIComponent(value);
50
+ },
51
+
52
+ number: function (part0, minFractionDigits, maxFractionDigits) {
53
+ let { minimumFractionDigits, maximumFractionDigits } = resolveMinMaxFractionDigits(
54
+ minFractionDigits,
55
+ maxFractionDigits,
56
+ );
57
+ let trimmable = maximumFractionDigits - minimumFractionDigits;
58
+ if (trimmable > 0) {
59
+ if (minimumFractionDigits == 0) ++trimmable;
60
+ return (value) => trimFractionZeros(value.toFixed(maximumFractionDigits), trimmable);
61
+ }
62
+ return (value) => value.toFixed(maximumFractionDigits);
63
+ },
64
+
65
+ percentage: function (part0, minFractionDigits, maxFractionDigits) {
66
+ let numberFormatter = formatFactory.number(part0, minFractionDigits, maxFractionDigits);
67
+ return (value) => numberFormatter(value * 100) + "%";
68
+ },
69
+
70
+ percentageSign: function (part0, minFractionDigits, maxFractionDigits) {
71
+ let numberFormatter = formatFactory.number(part0, minFractionDigits, maxFractionDigits);
72
+ return (value) => numberFormatter(value) + "%";
73
+ },
74
+
75
+ date: function () {
76
+ return (value) => {
77
+ let date = new Date(value);
78
+ return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
79
+ };
80
+ },
81
+
82
+ time: function () {
83
+ return (value) => {
84
+ let date = new Date(value);
85
+ let h = date.getHours() >= 10 ? date.getHours() : "0" + date.getHours();
86
+ let m = date.getMinutes() >= 10 ? date.getMinutes() : "0" + date.getMinutes();
87
+ return `${h}:${m}`;
88
+ };
89
+ },
90
+
91
+ datetime: function () {
92
+ let date = formatFactory.date();
93
+ let time = formatFactory.time();
94
+ return (value) => date(value) + " " + time(value);
95
+ },
96
+
97
+ ellipsis: function (part0, length, where) {
98
+ length = Number(length);
99
+ if (!(length > 3)) length = 10;
100
+ switch (where) {
101
+ default:
102
+ case "end":
103
+ return (value) => {
104
+ let s = String(value);
105
+ if (s.length > length) return s.substring(0, length - 3) + "...";
106
+ return s;
107
+ };
108
+
109
+ case "start":
110
+ return (value) => {
111
+ let s = String(value);
112
+ if (s.length > length) return "..." + s.substring(s.length - length + 3);
113
+ return s;
114
+ };
115
+
116
+ case "middle":
117
+ return (value) => {
118
+ let s = String(value);
119
+ if (s.length > length) {
120
+ let x = Math.floor(length - 2) / 2;
121
+ return s.substring(0, x) + "..." + s.substring(s.length - (length - 3 - x));
122
+ }
123
+ return s;
124
+ };
125
+ }
126
+ },
127
+ };
128
+
129
+ formatFactory.s = formatFactory.str = formatFactory.string;
130
+ formatFactory.f = formatFactory.fixed;
131
+ formatFactory.n = formatFactory.number;
132
+ formatFactory.p = formatFactory.percentage;
133
+ formatFactory.ps = formatFactory.percentageSign;
134
+ formatFactory.d = formatFactory.date;
135
+ formatFactory.t = formatFactory.time;
136
+ formatFactory.dt = formatFactory.datetime;
137
+
138
+ function buildFormatter(format) {
139
+ let formatter = defaultFormatter,
140
+ nullText = "";
141
+ if (format) {
142
+ let pipeParts = format.split("|");
143
+ nullText = pipeParts[1] || "";
144
+ let colonSepParts = pipeParts[0].split(":");
145
+ for (let i = 0; i < colonSepParts.length; i++) {
146
+ let parts = colonSepParts[i].split(";");
147
+ let factory = formatFactory[parts[0]];
148
+ if (!factory) debug("Unknown string format: " + format);
149
+ else if (i == 0) formatter = factory(...parts);
150
+ else {
151
+ let outerFmt = factory(...parts);
152
+ let innerFmt = formatter;
153
+ formatter = (v) => outerFmt(innerFmt(v));
154
+ }
155
+ }
156
+ }
157
+ return (v) => (v == null || v === "" ? nullText : formatter(v));
158
+ }
159
+
160
+ let format = {
161
+ cache: {},
162
+ };
163
+
164
+ function getDefaultFormatCache() {
165
+ if (format.cacheIdentifier != GlobalCacheIdentifier.get()) {
166
+ format = {
167
+ cache: {},
168
+ cacheIdentifier: GlobalCacheIdentifier.get(),
169
+ };
170
+ }
171
+ return format.cache;
172
+ }
173
+
174
+ let getFormatCache = getDefaultFormatCache;
175
+
176
+ export function setGetFormatCacheCallback(callback) {
177
+ getFormatCache = callback;
178
+ }
179
+
180
+ function getFormatter(format) {
181
+ if (!format) format = "";
182
+ let formatCache = getFormatCache();
183
+ let formatter = formatCache[format];
184
+ if (!formatter) formatter = formatCache[format] = buildFormatter(format);
185
+
186
+ return formatter;
187
+ }
188
+
189
+ export class Format {
190
+ static value(v, format) {
191
+ let formatter = getFormatter(format);
192
+ return formatter(v);
193
+ }
194
+
195
+ static parse(format) {
196
+ return getFormatter(format);
197
+ }
198
+
199
+ static register(format, formatter) {
200
+ this.registerFactory(format, () => formatter);
201
+ }
202
+
203
+ static registerFactory(format, factory) {
204
+ if (isArray(format)) format.forEach((f) => this.registerFactory(f, factory));
205
+ else formatFactory[format] = factory;
206
+ }
207
+ }
208
+
209
+ export function resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits) {
210
+ minimumFractionDigits = minimumFractionDigits != null ? Number(minimumFractionDigits) : minimumFractionDigits;
211
+ maximumFractionDigits = maximumFractionDigits != null ? Number(maximumFractionDigits) : maximumFractionDigits;
212
+
213
+ if (isNumber(minimumFractionDigits)) {
214
+ if (isUndefined(maximumFractionDigits)) maximumFractionDigits = minimumFractionDigits;
215
+ else if (isNumber(maximumFractionDigits) && maximumFractionDigits < minimumFractionDigits)
216
+ maximumFractionDigits = minimumFractionDigits;
217
+ } else if (minimumFractionDigits == null && maximumFractionDigits == null) {
218
+ minimumFractionDigits = 0;
219
+ maximumFractionDigits = 18;
220
+ }
221
+
222
+ return {
223
+ minimumFractionDigits,
224
+ maximumFractionDigits,
225
+ };
226
+ }
227
+
228
+ export function trimFractionZeros(str, max) {
229
+ let cnt = 0,
230
+ l = str.length;
231
+ while (cnt < max && (str[l - 1 - cnt] === "0" || str[l - 1 - cnt] === ".")) cnt++;
232
+
233
+ return cnt > 0 ? str.substring(0, l - cnt) : str;
234
+ }
@@ -55,35 +55,35 @@ interface DropZoneProps extends Cx.StyledContainerProps {
55
55
  * instance
56
56
  Return value is written into dragDropEvent.result and can be passed
57
57
  to the source's onDragEnd callback. */
58
- onDrop?: (event?: DragEvent, instance?: Instance) => any;
58
+ onDrop?: string | ((event?: DragEvent, instance?: Instance) => any);
59
59
 
60
60
  /** A callback method used to test if dragged item (source) is compatible
61
61
  with the drop zone. */
62
- onDropTest?: (event?: DragEvent, instance?: Instance) => boolean;
62
+ onDropTest?: string | ((event?: DragEvent, instance?: Instance) => boolean);
63
63
 
64
64
  /** A callback method invoked when the dragged item gets close to the drop zone.
65
65
  See also `nearDistance`. */
66
- onDragNear?: (event?: DragEvent, instance?: Instance) => void;
66
+ onDragNear?: string | ((event?: DragEvent, instance?: Instance) => void);
67
67
 
68
68
  /** A callback method invoked when the dragged item is dragged away. */
69
- onDragAway?: (event?: DragEvent, instance?: Instance) => void;
69
+ onDragAway?: string | ((event?: DragEvent, instance?: Instance) => void);
70
70
 
71
71
  /** A callback method invoked when the dragged item is dragged over the drop zone.
72
72
  The callback is called for each `mousemove` or `touchmove` event. */
73
- onDragOver?: (event?: DragEvent, instance?: Instance) => void;
73
+ onDragOver?: string | ((event?: DragEvent, instance?: Instance) => void);
74
74
 
75
75
  /** A callback method invoked when the dragged item is dragged over the drop zone
76
76
  for the first time. */
77
- onDragEnter?: (event?: DragEvent, instance?: Instance) => void;
77
+ onDragEnter?: string | ((event?: DragEvent, instance?: Instance) => void);
78
78
 
79
79
  /** A callback method invoked when the dragged item leaves the drop zone area. */
80
- onDragLeave?: (event?: DragEvent, instance?: Instance) => void;
80
+ onDragLeave?: string | ((event?: DragEvent, instance?: Instance) => void);
81
81
 
82
82
  /** A callback method invoked when at the beginning of the drag & drop operation. */
83
- onDragStart?: (event?: DragEvent, instance?: Instance) => void;
83
+ onDragStart?: string | ((event?: DragEvent, instance?: Instance) => void);
84
84
 
85
85
  /** A callback method invoked when at the end of the drag & drop operation. */
86
- onDragEnd?: (event?: DragEvent, instance?: Instance) => void;
86
+ onDragEnd?: string | ((event?: DragEvent, instance?: Instance) => void);
87
87
 
88
88
  /** Match height of the item being dragged */
89
89
  matchHeight?: boolean;