cx 26.2.3 → 26.3.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/build/charts/helpers/SnapPointFinder.d.ts +2 -2
- package/build/charts/helpers/SnapPointFinder.d.ts.map +1 -1
- package/build/charts/helpers/ValueAtFinder.d.ts +4 -4
- package/build/charts/helpers/ValueAtFinder.d.ts.map +1 -1
- package/build/charts/helpers/ValueAtFinder.js +2 -5
- package/build/jsx-runtime.d.ts +2 -1
- package/build/jsx-runtime.d.ts.map +1 -1
- package/build/ui/createFunctionalComponent.d.ts +4 -1
- package/build/ui/createFunctionalComponent.d.ts.map +1 -1
- package/build/widgets/form/Calendar.d.ts +1 -0
- package/build/widgets/form/Calendar.d.ts.map +1 -1
- package/build/widgets/form/Calendar.js +14 -22
- package/build/widgets/form/TimeList.d.ts +3 -1
- package/build/widgets/form/TimeList.d.ts.map +1 -1
- package/dist/manifest.js +833 -833
- package/dist/widgets.js +5 -1
- package/package.json +1 -1
- package/src/charts/helpers/SnapPointFinder.ts +136 -136
- package/src/charts/helpers/ValueAtFinder.ts +72 -86
- package/src/jsx-runtime.ts +2 -1
- package/src/ui/createFunctionalComponent.spec.tsx +55 -0
- package/src/ui/createFunctionalComponent.ts +12 -2
- package/src/widgets/form/Calendar.tsx +772 -862
package/dist/widgets.js
CHANGED
|
@@ -7933,6 +7933,7 @@ const validationCheck = (date, data, disabledDaysOfWeek) => {
|
|
|
7933
7933
|
};
|
|
7934
7934
|
class CalendarCmp extends VDOM.Component {
|
|
7935
7935
|
el = null;
|
|
7936
|
+
unsubscribeWheel;
|
|
7936
7937
|
constructor(props) {
|
|
7937
7938
|
super(props);
|
|
7938
7939
|
let { data } = props.instance;
|
|
@@ -8111,7 +8112,9 @@ class CalendarCmp extends VDOM.Component {
|
|
|
8111
8112
|
if (calendarWidget.autoFocus && this.el) this.el.focus();
|
|
8112
8113
|
if (this.el) {
|
|
8113
8114
|
tooltipParentDidMount$1(this.el, ...getFieldTooltip(this.props.instance));
|
|
8114
|
-
this.el
|
|
8115
|
+
this.unsubscribeWheel = addEventListenerWithOptions(this.el, "wheel", (e) => this.handleWheel(e), {
|
|
8116
|
+
passive: false,
|
|
8117
|
+
});
|
|
8115
8118
|
}
|
|
8116
8119
|
}
|
|
8117
8120
|
UNSAFE_componentWillReceiveProps(props) {
|
|
@@ -8127,6 +8130,7 @@ class CalendarCmp extends VDOM.Component {
|
|
|
8127
8130
|
componentWillUnmount() {
|
|
8128
8131
|
offFocusOut(this);
|
|
8129
8132
|
tooltipParentWillUnmount$1(this.props.instance);
|
|
8133
|
+
this.unsubscribeWheel?.();
|
|
8130
8134
|
}
|
|
8131
8135
|
showYearDropdown() {
|
|
8132
8136
|
if (this.el && this.el.firstChild) {
|
package/package.json
CHANGED
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
import { PointReducer, PointReducerConfig, PointReducerInstance, PointReducerAccumulator } from "./PointReducer";
|
|
2
|
-
import { RenderingContext } from "../../ui/RenderingContext";
|
|
3
|
-
import { NumberProp, Bind, Prop, DataRecord } from "../../ui/Prop";
|
|
4
|
-
import { AccessorChain } from "../../data/createAccessorModelProxy";
|
|
5
|
-
|
|
6
|
-
export interface SnapAccumulator extends PointReducerAccumulator {
|
|
7
|
-
cursor: {
|
|
8
|
-
x: number | null;
|
|
9
|
-
y: number | null;
|
|
10
|
-
mapped: boolean;
|
|
11
|
-
mappedX?: number | null;
|
|
12
|
-
mappedY?: number | null;
|
|
13
|
-
};
|
|
14
|
-
dist: number;
|
|
15
|
-
snapX: any;
|
|
16
|
-
snapY: any;
|
|
17
|
-
snapRecord?: any;
|
|
18
|
-
xAxis: any;
|
|
19
|
-
yAxis: any;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface SnapPointFinderInstance extends PointReducerInstance<SnapAccumulator> {
|
|
23
|
-
xAxis?: any;
|
|
24
|
-
yAxis?: any;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface SnapPointFinderConfig extends PointReducerConfig {
|
|
28
|
-
/** Cursor X value. */
|
|
29
|
-
cursorX?: NumberProp;
|
|
30
|
-
|
|
31
|
-
/** Cursor Y value */
|
|
32
|
-
cursorY?: NumberProp;
|
|
33
|
-
|
|
34
|
-
/** A binding used to receive the x value of the nearest point.*/
|
|
35
|
-
snapX?: Bind | AccessorChain<number> | AccessorChain<string>;
|
|
36
|
-
|
|
37
|
-
/** A binding used to receive the y value of the nearest point. */
|
|
38
|
-
snapY?: Bind | AccessorChain<number> | AccessorChain<string>;
|
|
39
|
-
|
|
40
|
-
/** A binding used to receive the record prop */
|
|
41
|
-
snapRecord?: Prop<DataRecord>;
|
|
42
|
-
|
|
43
|
-
/** Maximum distance between cursor and the snap point. Default value is 50. Adjust accordingly for large distances, e.g. set to Infinity when using TimeAxis */
|
|
44
|
-
maxDistance?: number;
|
|
45
|
-
|
|
46
|
-
/** A function used to convert x values into numeric format. Commonly used with dates. */
|
|
47
|
-
convertX?: (value: number | string) => number;
|
|
48
|
-
|
|
49
|
-
/** A function used to convert y values into numeric format. Commonly used with dates. */
|
|
50
|
-
convertY?: (value: number | string) => number;
|
|
51
|
-
|
|
52
|
-
/** Name of the x-axis. Default is 'x'. */
|
|
53
|
-
xAxis?: string;
|
|
54
|
-
|
|
55
|
-
/** Name of the y-axis. Default is 'y'. */
|
|
56
|
-
yAxis?: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class SnapPointFinder extends PointReducer<SnapAccumulator> {
|
|
60
|
-
declare maxDistance: number;
|
|
61
|
-
declare convertX: (value: any) => number;
|
|
62
|
-
declare convertY: (value: any) => number;
|
|
63
|
-
declare xAxis: string;
|
|
64
|
-
declare yAxis: string;
|
|
65
|
-
|
|
66
|
-
constructor(config?: SnapPointFinderConfig) {
|
|
67
|
-
super(config);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
declareData(...args: any[]) {
|
|
71
|
-
super.declareData(...args, {
|
|
72
|
-
cursorX: undefined,
|
|
73
|
-
cursorY: undefined,
|
|
74
|
-
snapX: undefined,
|
|
75
|
-
snapY: undefined,
|
|
76
|
-
snapRecord: undefined,
|
|
77
|
-
maxDistance: undefined,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
explore(context: RenderingContext, instance: SnapPointFinderInstance) {
|
|
82
|
-
instance.xAxis = (context.axes as any)?.[this.xAxis];
|
|
83
|
-
instance.yAxis = (context.axes as any)?.[this.yAxis];
|
|
84
|
-
super.explore(context, instance);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
onInitAccumulator = (acc: SnapAccumulator, { data, xAxis, yAxis }: SnapPointFinderInstance) => {
|
|
88
|
-
const d = data as any;
|
|
89
|
-
acc.cursor = {
|
|
90
|
-
x: d.cursorX,
|
|
91
|
-
y: d.cursorY,
|
|
92
|
-
mapped: false,
|
|
93
|
-
};
|
|
94
|
-
acc.dist = d.maxDistance > 0 ? Math.pow(d.maxDistance, 2) : Number.POSITIVE_INFINITY;
|
|
95
|
-
acc.snapX = null;
|
|
96
|
-
acc.snapY = null;
|
|
97
|
-
acc.xAxis = xAxis;
|
|
98
|
-
acc.yAxis = yAxis;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
onMap = (acc: SnapAccumulator, x: any, y: any, name: string, p: any) => {
|
|
102
|
-
let { xAxis, yAxis, cursor } = acc;
|
|
103
|
-
|
|
104
|
-
if (!cursor.mapped) {
|
|
105
|
-
cursor.mappedX = cursor.x != null ? xAxis?.map(this.convertX(cursor.x)) : null;
|
|
106
|
-
cursor.mappedY = cursor.y != null ? yAxis?.map(this.convertY(cursor.y)) : null;
|
|
107
|
-
cursor.mapped = true;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
let d: number | null = null;
|
|
111
|
-
let cx = x != null ? xAxis?.map(this.convertX(x)) : null;
|
|
112
|
-
let cy = y != null ? yAxis?.map(this.convertY(y)) : null;
|
|
113
|
-
|
|
114
|
-
if (cursor.mappedX != null && cx != null) d = (d || 0) + Math.pow(Math.abs(cx - cursor.mappedX), 2);
|
|
115
|
-
if (cursor.mappedY != null && cy != null) d = (d || 0) + Math.pow(Math.abs(cy - cursor.mappedY), 2);
|
|
116
|
-
|
|
117
|
-
if (d != null && d < acc.dist) {
|
|
118
|
-
acc.dist = d;
|
|
119
|
-
acc.snapX = x;
|
|
120
|
-
acc.snapY = y;
|
|
121
|
-
acc.snapRecord = p;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
onReduce = (acc: SnapAccumulator, instance: PointReducerInstance<SnapAccumulator>) => {
|
|
126
|
-
instance.set("snapX", acc.snapX);
|
|
127
|
-
instance.set("snapY", acc.snapY);
|
|
128
|
-
instance.set("snapRecord", acc.snapRecord);
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
SnapPointFinder.prototype.maxDistance = 50;
|
|
133
|
-
SnapPointFinder.prototype.convertX = (x) => x;
|
|
134
|
-
SnapPointFinder.prototype.convertY = (y) => y;
|
|
135
|
-
SnapPointFinder.prototype.xAxis = "x";
|
|
136
|
-
SnapPointFinder.prototype.yAxis = "y";
|
|
1
|
+
import { PointReducer, PointReducerConfig, PointReducerInstance, PointReducerAccumulator } from "./PointReducer";
|
|
2
|
+
import { RenderingContext } from "../../ui/RenderingContext";
|
|
3
|
+
import { NumberProp, Bind, Prop, DataRecord } from "../../ui/Prop";
|
|
4
|
+
import { AccessorChain } from "../../data/createAccessorModelProxy";
|
|
5
|
+
|
|
6
|
+
export interface SnapAccumulator extends PointReducerAccumulator {
|
|
7
|
+
cursor: {
|
|
8
|
+
x: number | null;
|
|
9
|
+
y: number | null;
|
|
10
|
+
mapped: boolean;
|
|
11
|
+
mappedX?: number | null;
|
|
12
|
+
mappedY?: number | null;
|
|
13
|
+
};
|
|
14
|
+
dist: number;
|
|
15
|
+
snapX: any;
|
|
16
|
+
snapY: any;
|
|
17
|
+
snapRecord?: any;
|
|
18
|
+
xAxis: any;
|
|
19
|
+
yAxis: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SnapPointFinderInstance extends PointReducerInstance<SnapAccumulator> {
|
|
23
|
+
xAxis?: any;
|
|
24
|
+
yAxis?: any;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SnapPointFinderConfig extends PointReducerConfig {
|
|
28
|
+
/** Cursor X value. */
|
|
29
|
+
cursorX?: NumberProp;
|
|
30
|
+
|
|
31
|
+
/** Cursor Y value */
|
|
32
|
+
cursorY?: NumberProp;
|
|
33
|
+
|
|
34
|
+
/** A binding used to receive the x value of the nearest point.*/
|
|
35
|
+
snapX?: Bind | AccessorChain<number | null | undefined> | AccessorChain<string | null | undefined>;
|
|
36
|
+
|
|
37
|
+
/** A binding used to receive the y value of the nearest point. */
|
|
38
|
+
snapY?: Bind | AccessorChain<number | null | undefined> | AccessorChain<string | null | undefined>;
|
|
39
|
+
|
|
40
|
+
/** A binding used to receive the record prop */
|
|
41
|
+
snapRecord?: Prop<DataRecord>;
|
|
42
|
+
|
|
43
|
+
/** Maximum distance between cursor and the snap point. Default value is 50. Adjust accordingly for large distances, e.g. set to Infinity when using TimeAxis */
|
|
44
|
+
maxDistance?: number;
|
|
45
|
+
|
|
46
|
+
/** A function used to convert x values into numeric format. Commonly used with dates. */
|
|
47
|
+
convertX?: (value: number | string) => number;
|
|
48
|
+
|
|
49
|
+
/** A function used to convert y values into numeric format. Commonly used with dates. */
|
|
50
|
+
convertY?: (value: number | string) => number;
|
|
51
|
+
|
|
52
|
+
/** Name of the x-axis. Default is 'x'. */
|
|
53
|
+
xAxis?: string;
|
|
54
|
+
|
|
55
|
+
/** Name of the y-axis. Default is 'y'. */
|
|
56
|
+
yAxis?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class SnapPointFinder extends PointReducer<SnapAccumulator> {
|
|
60
|
+
declare maxDistance: number;
|
|
61
|
+
declare convertX: (value: any) => number;
|
|
62
|
+
declare convertY: (value: any) => number;
|
|
63
|
+
declare xAxis: string;
|
|
64
|
+
declare yAxis: string;
|
|
65
|
+
|
|
66
|
+
constructor(config?: SnapPointFinderConfig) {
|
|
67
|
+
super(config);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declareData(...args: any[]) {
|
|
71
|
+
super.declareData(...args, {
|
|
72
|
+
cursorX: undefined,
|
|
73
|
+
cursorY: undefined,
|
|
74
|
+
snapX: undefined,
|
|
75
|
+
snapY: undefined,
|
|
76
|
+
snapRecord: undefined,
|
|
77
|
+
maxDistance: undefined,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
explore(context: RenderingContext, instance: SnapPointFinderInstance) {
|
|
82
|
+
instance.xAxis = (context.axes as any)?.[this.xAxis];
|
|
83
|
+
instance.yAxis = (context.axes as any)?.[this.yAxis];
|
|
84
|
+
super.explore(context, instance);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
onInitAccumulator = (acc: SnapAccumulator, { data, xAxis, yAxis }: SnapPointFinderInstance) => {
|
|
88
|
+
const d = data as any;
|
|
89
|
+
acc.cursor = {
|
|
90
|
+
x: d.cursorX,
|
|
91
|
+
y: d.cursorY,
|
|
92
|
+
mapped: false,
|
|
93
|
+
};
|
|
94
|
+
acc.dist = d.maxDistance > 0 ? Math.pow(d.maxDistance, 2) : Number.POSITIVE_INFINITY;
|
|
95
|
+
acc.snapX = null;
|
|
96
|
+
acc.snapY = null;
|
|
97
|
+
acc.xAxis = xAxis;
|
|
98
|
+
acc.yAxis = yAxis;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
onMap = (acc: SnapAccumulator, x: any, y: any, name: string, p: any) => {
|
|
102
|
+
let { xAxis, yAxis, cursor } = acc;
|
|
103
|
+
|
|
104
|
+
if (!cursor.mapped) {
|
|
105
|
+
cursor.mappedX = cursor.x != null ? xAxis?.map(this.convertX(cursor.x)) : null;
|
|
106
|
+
cursor.mappedY = cursor.y != null ? yAxis?.map(this.convertY(cursor.y)) : null;
|
|
107
|
+
cursor.mapped = true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let d: number | null = null;
|
|
111
|
+
let cx = x != null ? xAxis?.map(this.convertX(x)) : null;
|
|
112
|
+
let cy = y != null ? yAxis?.map(this.convertY(y)) : null;
|
|
113
|
+
|
|
114
|
+
if (cursor.mappedX != null && cx != null) d = (d || 0) + Math.pow(Math.abs(cx - cursor.mappedX), 2);
|
|
115
|
+
if (cursor.mappedY != null && cy != null) d = (d || 0) + Math.pow(Math.abs(cy - cursor.mappedY), 2);
|
|
116
|
+
|
|
117
|
+
if (d != null && d < acc.dist) {
|
|
118
|
+
acc.dist = d;
|
|
119
|
+
acc.snapX = x;
|
|
120
|
+
acc.snapY = y;
|
|
121
|
+
acc.snapRecord = p;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
onReduce = (acc: SnapAccumulator, instance: PointReducerInstance<SnapAccumulator>) => {
|
|
126
|
+
instance.set("snapX", acc.snapX);
|
|
127
|
+
instance.set("snapY", acc.snapY);
|
|
128
|
+
instance.set("snapRecord", acc.snapRecord);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
SnapPointFinder.prototype.maxDistance = 50;
|
|
133
|
+
SnapPointFinder.prototype.convertX = (x) => x;
|
|
134
|
+
SnapPointFinder.prototype.convertY = (y) => y;
|
|
135
|
+
SnapPointFinder.prototype.xAxis = "x";
|
|
136
|
+
SnapPointFinder.prototype.yAxis = "y";
|
|
@@ -1,86 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
convert
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
acc
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (acc.left && acc.right) {
|
|
74
|
-
if (acc.left.x == acc.right.x) y = acc.left.y;
|
|
75
|
-
else if (acc.left.y != null && acc.right.y != null) {
|
|
76
|
-
y =
|
|
77
|
-
acc.left.y +
|
|
78
|
-
((acc.right.y - acc.left.y) * (acc.at - acc.left.x)) /
|
|
79
|
-
(acc.right.x - acc.left.x);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
instance.set("value", y);
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
ValueAtFinder.prototype.convert = (x) => x;
|
|
1
|
+
import { AccessorChain } from "../../data/createAccessorModelProxy";
|
|
2
|
+
import { Bind, Prop } from "../../ui/Prop";
|
|
3
|
+
import { PointReducer, PointReducerAccumulator, PointReducerConfig, PointReducerInstance } from "./PointReducer";
|
|
4
|
+
|
|
5
|
+
export interface ValueAtAccumulator extends PointReducerAccumulator {
|
|
6
|
+
at: number;
|
|
7
|
+
left?: { x: number; y: number; d: number };
|
|
8
|
+
right?: { x: number; y: number; d: number };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ValueAtFinderConfig extends PointReducerConfig {
|
|
12
|
+
/** X axis probe value. */
|
|
13
|
+
at?: Prop<string | number | null | undefined>;
|
|
14
|
+
|
|
15
|
+
/** A binding used to receive the measured y axis value */
|
|
16
|
+
value?: Bind | AccessorChain<number | null | undefined>;
|
|
17
|
+
|
|
18
|
+
/** A function used to convert x values into numeric format. Commonly used with dates. */
|
|
19
|
+
convert?: (value: number | string) => number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Calculate value at a given point on the graph */
|
|
23
|
+
export class ValueAtFinder extends PointReducer<ValueAtAccumulator> {
|
|
24
|
+
declare convert: (value: any) => number;
|
|
25
|
+
|
|
26
|
+
constructor(config?: ValueAtFinderConfig) {
|
|
27
|
+
super(config);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declareData(...args: any[]) {
|
|
31
|
+
super.declareData(...args, {
|
|
32
|
+
at: undefined,
|
|
33
|
+
value: undefined,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
onInitAccumulator = (acc: ValueAtAccumulator, { data }: PointReducerInstance<ValueAtAccumulator>) => {
|
|
38
|
+
acc.at = this.convert((data as any).at);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
onMap = (acc: ValueAtAccumulator, x: any, y: any, name: string) => {
|
|
42
|
+
let cx = this.convert(x);
|
|
43
|
+
let d = cx - acc.at;
|
|
44
|
+
if (d <= 0 && (!acc.left || acc.left.d < d)) {
|
|
45
|
+
acc.left = {
|
|
46
|
+
x: cx,
|
|
47
|
+
y,
|
|
48
|
+
d,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (d >= 0 && (!acc.right || acc.right.d > d)) {
|
|
52
|
+
acc.right = {
|
|
53
|
+
x: cx,
|
|
54
|
+
y,
|
|
55
|
+
d,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
onReduce = (acc: ValueAtAccumulator, instance: PointReducerInstance<ValueAtAccumulator>) => {
|
|
61
|
+
let y: number | null = null;
|
|
62
|
+
if (acc.left && acc.right) {
|
|
63
|
+
if (acc.left.x == acc.right.x) y = acc.left.y;
|
|
64
|
+
else if (acc.left.y != null && acc.right.y != null) {
|
|
65
|
+
y = acc.left.y + ((acc.right.y - acc.left.y) * (acc.at - acc.left.x)) / (acc.right.x - acc.left.x);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
instance.set("value", y);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
ValueAtFinder.prototype.convert = (x) => x;
|
package/src/jsx-runtime.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ComponentClass, FunctionComponent, JSX as ReactJSX } from "react";
|
|
2
2
|
import type { CxFunctionalComponent } from "./ui/createFunctionalComponent";
|
|
3
|
+
import type { PureContainerConfig } from "./ui/PureContainer";
|
|
3
4
|
import { Widget } from "./ui/Widget";
|
|
4
5
|
import { isArray } from "./util/isArray";
|
|
5
6
|
import { isString } from "./util/isString";
|
|
@@ -57,7 +58,7 @@ type CxIntrinsicElements = {
|
|
|
57
58
|
// Uses a workaround to avoid TypeScript inference issues with conditional types in LibraryManagedAttributes
|
|
58
59
|
// We use Omit to exclude componentType since it's added automatically by the jsx-runtime
|
|
59
60
|
type TransformReactComponentProps<C, P> = [C] extends [CxFunctionalComponent<any>]
|
|
60
|
-
? P //
|
|
61
|
+
? P & Omit<PureContainerConfig, keyof P> // Add container props (visible, if, controller, layout, etc.) without overriding component props
|
|
61
62
|
: [C] extends [FunctionComponent<any>]
|
|
62
63
|
? ReactElementWrapperConfig<P>
|
|
63
64
|
: [C] extends [ComponentClass<any>]
|
|
@@ -11,6 +11,61 @@ import { LabeledContainer } from "../widgets/form/LabeledContainer";
|
|
|
11
11
|
import { Repeater } from "./Repeater";
|
|
12
12
|
import { FirstVisibleChildLayout } from "./layout/FirstVisibleChildLayout";
|
|
13
13
|
import { useStoreMethods } from "../hooks";
|
|
14
|
+
import { AccessorChain, createAccessorModelProxy } from "../data/createAccessorModelProxy";
|
|
15
|
+
|
|
16
|
+
describe("createFunctionalComponent generic type safety", () => {
|
|
17
|
+
interface User {
|
|
18
|
+
id: number;
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface GenericListProps<T> {
|
|
23
|
+
items: AccessorChain<T[]>;
|
|
24
|
+
onSelect?: (item: T) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const GenericList = createFunctionalComponent(
|
|
28
|
+
<T,>({ items, onSelect }: GenericListProps<T>) => (
|
|
29
|
+
<cx>
|
|
30
|
+
<div />
|
|
31
|
+
</cx>
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
it("infers generic type parameter from AccessorChain", () => {
|
|
36
|
+
let model = createAccessorModelProxy<{ users: User[] }>();
|
|
37
|
+
|
|
38
|
+
const widget = (
|
|
39
|
+
<cx>
|
|
40
|
+
<GenericList
|
|
41
|
+
items={model.users}
|
|
42
|
+
onSelect={(user) => {
|
|
43
|
+
// user should be inferred as User
|
|
44
|
+
const id: number = user.id;
|
|
45
|
+
const name: string = user.name;
|
|
46
|
+
// @ts-expect-error - nonExistent does not exist on User
|
|
47
|
+
const x = user.nonExistent;
|
|
48
|
+
}}
|
|
49
|
+
/>
|
|
50
|
+
</cx>
|
|
51
|
+
);
|
|
52
|
+
assert.ok(widget);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("accepts PureContainerConfig props like visible", () => {
|
|
56
|
+
let model = createAccessorModelProxy<{ users: User[] }>();
|
|
57
|
+
|
|
58
|
+
const widget = (
|
|
59
|
+
<cx>
|
|
60
|
+
<GenericList
|
|
61
|
+
items={model.users}
|
|
62
|
+
visible={true}
|
|
63
|
+
/>
|
|
64
|
+
</cx>
|
|
65
|
+
);
|
|
66
|
+
assert.ok(widget);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
14
69
|
|
|
15
70
|
describe("createFunctionalComponent type safety", () => {
|
|
16
71
|
interface MyComponentProps {
|
|
@@ -49,9 +49,19 @@ export interface CxFunctionalComponent<Props = any> {
|
|
|
49
49
|
__cxFunctionalComponent: true;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
// Overload 1: Preserves generic factory types (e.g. <T>(props: Props<T>) => ...)
|
|
53
|
+
export function createFunctionalComponent<F extends (props: any) => ChildNode | ChildNode[]>(
|
|
54
|
+
factory: F,
|
|
55
|
+
): F & { __cxFunctionalComponent: true };
|
|
56
|
+
|
|
57
|
+
// Overload 2: Explicit Props type parameter (e.g. createFunctionalComponent<MyProps>(fn))
|
|
58
|
+
export function createFunctionalComponent<Props>(
|
|
53
59
|
factory: (props: Props) => ChildNode | ChildNode[],
|
|
54
|
-
): CxFunctionalComponent<Props
|
|
60
|
+
): CxFunctionalComponent<Props>;
|
|
61
|
+
|
|
62
|
+
export function createFunctionalComponent(
|
|
63
|
+
factory: (props: any) => ChildNode | ChildNode[],
|
|
64
|
+
): any {
|
|
55
65
|
if (isComponentFactory(factory)) return factory as any;
|
|
56
66
|
|
|
57
67
|
return createComponentFactory(factory, (props: any = {}) => {
|