cx 26.4.1 → 26.4.2
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/shapes.d.ts.map +1 -1
- package/build/charts/shapes.js +14 -7
- package/build/widgets/overlay/ContextMenu.d.ts.map +1 -1
- package/build/widgets/overlay/ContextMenu.js +1 -0
- package/build/widgets/overlay/Dropdown.d.ts +11 -3
- package/build/widgets/overlay/Dropdown.d.ts.map +1 -1
- package/build/widgets/overlay/Dropdown.js +52 -25
- package/build/widgets/overlay/Overlay.d.ts.map +1 -1
- package/build/widgets/overlay/Overlay.js +1 -1
- package/dist/charts.js +80 -45
- package/dist/manifest.js +744 -744
- package/dist/widgets.css +13 -12
- package/dist/widgets.js +215 -85
- package/package.json +1 -1
- package/src/charts/BarGraph.scss +31 -31
- package/src/charts/Legend.scss +57 -57
- package/src/charts/LegendEntry.scss +35 -35
- package/src/charts/LineGraph.scss +28 -28
- package/src/charts/helpers/SnapPointFinder.ts +136 -136
- package/src/charts/helpers/ValueAtFinder.ts +72 -72
- package/src/charts/shapes.tsx +14 -7
- package/src/data/createAccessorModelProxy.ts +66 -66
- package/src/ui/DataProxy.ts +55 -55
- package/src/ui/Repeater.spec.tsx +181 -181
- package/src/ui/Rescope.ts +50 -50
- package/src/ui/adapter/ArrayAdapter.ts +229 -229
- package/src/ui/exprHelpers.ts +96 -96
- package/src/util/scss/include.scss +69 -69
- package/src/widgets/Button.maps.scss +103 -103
- package/src/widgets/Sandbox.ts +104 -104
- package/src/widgets/form/Calendar.tsx +772 -772
- package/src/widgets/form/ColorField.scss +112 -112
- package/src/widgets/form/DateTimeField.scss +111 -111
- package/src/widgets/form/LookupField.maps.scss +26 -26
- package/src/widgets/form/LookupField.scss +227 -227
- package/src/widgets/form/MonthField.scss +113 -113
- package/src/widgets/form/NumberField.scss +72 -72
- package/src/widgets/form/Select.scss +104 -104
- package/src/widgets/form/TextField.scss +66 -66
- package/src/widgets/grid/Grid.scss +657 -657
- package/src/widgets/grid/variables.scss +47 -47
- package/src/widgets/index.ts +63 -63
- package/src/widgets/nav/MenuItem.scss +150 -150
- package/src/widgets/nav/MenuItem.tsx +525 -525
- package/src/widgets/nav/Tab.ts +122 -122
- package/src/widgets/overlay/ContextMenu.ts +1 -0
- package/src/widgets/overlay/Dropdown.scss +7 -6
- package/src/widgets/overlay/Dropdown.tsx +59 -16
- package/src/widgets/overlay/Overlay.tsx +1029 -1028
- package/src/widgets/variables.scss +61 -61
package/src/charts/shapes.tsx
CHANGED
|
@@ -35,39 +35,45 @@ export function getAvailableShapes(): string[] {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export function circle(cx: number, cy: number, size: number, props?: Config, options?: Config): React.ReactElement {
|
|
38
|
-
|
|
38
|
+
const { key, ...rest } = props ?? {};
|
|
39
|
+
return <circle key={key} {...rest} cx={cx} cy={cy} r={size / 2} />;
|
|
39
40
|
}
|
|
40
41
|
registerShape("circle", circle);
|
|
41
42
|
|
|
42
43
|
export function square(cx: number, cy: number, size: number, props?: Config, options?: Config): React.ReactElement {
|
|
43
44
|
size *= 0.9;
|
|
44
|
-
|
|
45
|
+
const { key, ...rest } = props ?? {};
|
|
46
|
+
return <rect key={key} {...rest} x={cx - size / 2} y={cy - size / 2} width={size} height={size} />;
|
|
45
47
|
}
|
|
46
48
|
registerShape("square", square);
|
|
47
49
|
registerShape("rect", square);
|
|
48
50
|
|
|
49
51
|
export function bar(cx: number, cy: number, size: number, props?: Config, options?: Config): React.ReactElement {
|
|
50
52
|
size *= 0.9;
|
|
51
|
-
|
|
53
|
+
const { key, ...rest } = props ?? {};
|
|
54
|
+
return <rect key={key} {...rest} x={cx - size / 2} y={cy - size / 4} width={size} height={size / 2} />;
|
|
52
55
|
}
|
|
53
56
|
registerShape("bar", bar);
|
|
54
57
|
|
|
55
58
|
export function column(cx: number, cy: number, size: number, props?: Config, options?: Config): React.ReactElement {
|
|
56
59
|
size *= 0.9;
|
|
57
|
-
|
|
60
|
+
const { key, ...rest } = props ?? {};
|
|
61
|
+
return <rect key={key} {...rest} x={cx - size / 4} y={cy - size / 2} width={size / 2} height={size} />;
|
|
58
62
|
}
|
|
59
63
|
registerShape("column", column);
|
|
60
64
|
|
|
61
65
|
export function line(cx: number, cy: number, size: number, props?: Config, options?: Config): React.ReactElement {
|
|
62
66
|
size *= 0.9;
|
|
63
|
-
|
|
67
|
+
const { key, ...rest } = props ?? {};
|
|
68
|
+
return <line key={key} {...rest} x1={cx - size / 2} y1={cy} x2={cx + size / 2} y2={cy} />;
|
|
64
69
|
}
|
|
65
70
|
registerShape("line", line);
|
|
66
71
|
registerShape("hline", line);
|
|
67
72
|
|
|
68
73
|
export function vline(cx: number, cy: number, size: number, props?: Config, options?: Config): React.ReactElement {
|
|
69
74
|
size *= 0.9;
|
|
70
|
-
|
|
75
|
+
const { key, ...rest } = props ?? {};
|
|
76
|
+
return <line key={key} {...rest} x1={cx} y1={cy - size / 2} x2={cx} y2={cy + size / 2} />;
|
|
71
77
|
}
|
|
72
78
|
registerShape("vline", vline);
|
|
73
79
|
|
|
@@ -80,7 +86,8 @@ export function triangle(cx: number, cy: number, size: number, props?: Config, o
|
|
|
80
86
|
d += `L ${cx + (cos * size) / 2} ${cy + (sin * size) / 2} `;
|
|
81
87
|
d += `L ${cx - (cos * size) / 2} ${cy + (sin * size) / 2} `;
|
|
82
88
|
d += `Z`;
|
|
83
|
-
|
|
89
|
+
const { key, ...rest } = props ?? {};
|
|
90
|
+
return <path key={key} {...rest} d={d} />;
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
registerShape("triangle", triangle);
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
// Homomorphic mapped type preserves Go-to-Definition in IDEs
|
|
2
|
-
// -? strips optionality, as clause filters conflicting method names
|
|
3
|
-
type AccessorChainMap<M> = {
|
|
4
|
-
[K in keyof M as Exclude<K, "toString" | "valueOf" | "nameOf">]-?: AccessorChain<M[K]>;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// Check if a type is `any` using the intersection trick
|
|
8
|
-
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
9
|
-
|
|
10
|
-
export type AccessorChain<M> = (IsAny<M> extends true
|
|
11
|
-
? { [key: string]: any } // Allow any property access for `any` type
|
|
12
|
-
: [M] extends [object]
|
|
13
|
-
? AccessorChainMap<M> // Direct mapping preserves IDE navigation
|
|
14
|
-
: [NonNullable<M>] extends [object]
|
|
15
|
-
? AccessorChainMap<NonNullable<M>> // Fallback for nullable types (e.g. optional properties)
|
|
16
|
-
: {}) & {
|
|
17
|
-
toString(): string;
|
|
18
|
-
valueOf(): M | undefined;
|
|
19
|
-
nameOf(): string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const emptyFn = () => {};
|
|
23
|
-
|
|
24
|
-
export function createAccessorModelProxy<M>(chain: string = ""): AccessorChain<M> {
|
|
25
|
-
let lastOp: string | null = null;
|
|
26
|
-
|
|
27
|
-
const proxy = new Proxy(emptyFn, {
|
|
28
|
-
get: (_, name: string | symbol) => {
|
|
29
|
-
if (typeof name !== "string") return proxy;
|
|
30
|
-
|
|
31
|
-
switch (name) {
|
|
32
|
-
case "isAccessorChain":
|
|
33
|
-
return true;
|
|
34
|
-
|
|
35
|
-
case "toString":
|
|
36
|
-
case "valueOf":
|
|
37
|
-
case "nameOf":
|
|
38
|
-
lastOp = name;
|
|
39
|
-
return proxy;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let newChain = chain;
|
|
43
|
-
if (newChain.length > 0) newChain += ".";
|
|
44
|
-
newChain += name;
|
|
45
|
-
return createAccessorModelProxy(newChain);
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
apply(): string {
|
|
49
|
-
switch (lastOp) {
|
|
50
|
-
case "nameOf":
|
|
51
|
-
const lastDotIndex = chain.lastIndexOf(".");
|
|
52
|
-
return lastDotIndex > 0 ? chain.substring(lastDotIndex + 1) : chain;
|
|
53
|
-
|
|
54
|
-
default:
|
|
55
|
-
return chain;
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
return proxy as unknown as AccessorChain<M>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const createModel = createAccessorModelProxy;
|
|
63
|
-
|
|
64
|
-
export function isAccessorChain<M>(value: unknown): value is AccessorChain<M> {
|
|
65
|
-
return value != null && !!(value as any).isAccessorChain;
|
|
66
|
-
}
|
|
1
|
+
// Homomorphic mapped type preserves Go-to-Definition in IDEs
|
|
2
|
+
// -? strips optionality, as clause filters conflicting method names
|
|
3
|
+
type AccessorChainMap<M> = {
|
|
4
|
+
[K in keyof M as Exclude<K, "toString" | "valueOf" | "nameOf">]-?: AccessorChain<M[K]>;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// Check if a type is `any` using the intersection trick
|
|
8
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
9
|
+
|
|
10
|
+
export type AccessorChain<M> = (IsAny<M> extends true
|
|
11
|
+
? { [key: string]: any } // Allow any property access for `any` type
|
|
12
|
+
: [M] extends [object]
|
|
13
|
+
? AccessorChainMap<M> // Direct mapping preserves IDE navigation
|
|
14
|
+
: [NonNullable<M>] extends [object]
|
|
15
|
+
? AccessorChainMap<NonNullable<M>> // Fallback for nullable types (e.g. optional properties)
|
|
16
|
+
: {}) & {
|
|
17
|
+
toString(): string;
|
|
18
|
+
valueOf(): M | undefined;
|
|
19
|
+
nameOf(): string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const emptyFn = () => {};
|
|
23
|
+
|
|
24
|
+
export function createAccessorModelProxy<M>(chain: string = ""): AccessorChain<M> {
|
|
25
|
+
let lastOp: string | null = null;
|
|
26
|
+
|
|
27
|
+
const proxy = new Proxy(emptyFn, {
|
|
28
|
+
get: (_, name: string | symbol) => {
|
|
29
|
+
if (typeof name !== "string") return proxy;
|
|
30
|
+
|
|
31
|
+
switch (name) {
|
|
32
|
+
case "isAccessorChain":
|
|
33
|
+
return true;
|
|
34
|
+
|
|
35
|
+
case "toString":
|
|
36
|
+
case "valueOf":
|
|
37
|
+
case "nameOf":
|
|
38
|
+
lastOp = name;
|
|
39
|
+
return proxy;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let newChain = chain;
|
|
43
|
+
if (newChain.length > 0) newChain += ".";
|
|
44
|
+
newChain += name;
|
|
45
|
+
return createAccessorModelProxy(newChain);
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
apply(): string {
|
|
49
|
+
switch (lastOp) {
|
|
50
|
+
case "nameOf":
|
|
51
|
+
const lastDotIndex = chain.lastIndexOf(".");
|
|
52
|
+
return lastDotIndex > 0 ? chain.substring(lastDotIndex + 1) : chain;
|
|
53
|
+
|
|
54
|
+
default:
|
|
55
|
+
return chain;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
return proxy as unknown as AccessorChain<M>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const createModel = createAccessorModelProxy;
|
|
63
|
+
|
|
64
|
+
export function isAccessorChain<M>(value: unknown): value is AccessorChain<M> {
|
|
65
|
+
return value != null && !!(value as any).isAccessorChain;
|
|
66
|
+
}
|
package/src/ui/DataProxy.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { AccessorChain } from "../data";
|
|
2
|
-
import { NestedDataView } from "../data/NestedDataView";
|
|
3
|
-
import { StructuredProp, WritableProp } from "./Prop";
|
|
4
|
-
import { PureContainerBase, PureContainerConfig } from "./PureContainer";
|
|
5
|
-
import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
|
|
6
|
-
|
|
7
|
-
export interface DataProxyConfig extends PureContainerConfig {
|
|
8
|
-
/** Data object with computed values to be exposed in the local store. */
|
|
9
|
-
data?: StructuredProp;
|
|
10
|
-
|
|
11
|
-
/** Binding to a value to be exposed under the `alias` name. */
|
|
12
|
-
value?: WritableProp<any>;
|
|
13
|
-
|
|
14
|
-
/** Alias name under which `value` is exposed in the local store. */
|
|
15
|
-
alias?: string | AccessorChain<any>;
|
|
16
|
-
|
|
17
|
-
/** Indicate that parent store data should not be mutated. */
|
|
18
|
-
immutable?: boolean;
|
|
19
|
-
|
|
20
|
-
/** Indicate that local store data should not be mutated. */
|
|
21
|
-
sealed?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class DataProxy extends PureContainerBase<DataProxyConfig> {
|
|
25
|
-
declare data?: any;
|
|
26
|
-
declare alias?: string;
|
|
27
|
-
declare value?: any;
|
|
28
|
-
declare immutable: boolean;
|
|
29
|
-
declare sealed: boolean;
|
|
30
|
-
|
|
31
|
-
init() {
|
|
32
|
-
if (!this.data) this.data = {};
|
|
33
|
-
|
|
34
|
-
if (this.alias) this.data[this.alias] = this.value;
|
|
35
|
-
|
|
36
|
-
super.init();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
initInstance(context: any, instance: any) {
|
|
40
|
-
instance.store = new NestedDataView({
|
|
41
|
-
store: instance.parentStore,
|
|
42
|
-
nestedData: new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true }),
|
|
43
|
-
immutable: this.immutable,
|
|
44
|
-
sealed: this.sealed,
|
|
45
|
-
});
|
|
46
|
-
super.initInstance(context, instance);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
applyParentStore(instance: any) {
|
|
50
|
-
instance.store.setStore(instance.parentStore);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
DataProxy.prototype.immutable = false;
|
|
55
|
-
DataProxy.prototype.sealed = false;
|
|
1
|
+
import { AccessorChain } from "../data";
|
|
2
|
+
import { NestedDataView } from "../data/NestedDataView";
|
|
3
|
+
import { StructuredProp, WritableProp } from "./Prop";
|
|
4
|
+
import { PureContainerBase, PureContainerConfig } from "./PureContainer";
|
|
5
|
+
import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
|
|
6
|
+
|
|
7
|
+
export interface DataProxyConfig extends PureContainerConfig {
|
|
8
|
+
/** Data object with computed values to be exposed in the local store. */
|
|
9
|
+
data?: StructuredProp;
|
|
10
|
+
|
|
11
|
+
/** Binding to a value to be exposed under the `alias` name. */
|
|
12
|
+
value?: WritableProp<any>;
|
|
13
|
+
|
|
14
|
+
/** Alias name under which `value` is exposed in the local store. */
|
|
15
|
+
alias?: string | AccessorChain<any>;
|
|
16
|
+
|
|
17
|
+
/** Indicate that parent store data should not be mutated. */
|
|
18
|
+
immutable?: boolean;
|
|
19
|
+
|
|
20
|
+
/** Indicate that local store data should not be mutated. */
|
|
21
|
+
sealed?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class DataProxy extends PureContainerBase<DataProxyConfig> {
|
|
25
|
+
declare data?: any;
|
|
26
|
+
declare alias?: string;
|
|
27
|
+
declare value?: any;
|
|
28
|
+
declare immutable: boolean;
|
|
29
|
+
declare sealed: boolean;
|
|
30
|
+
|
|
31
|
+
init() {
|
|
32
|
+
if (!this.data) this.data = {};
|
|
33
|
+
|
|
34
|
+
if (this.alias) this.data[this.alias] = this.value;
|
|
35
|
+
|
|
36
|
+
super.init();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
initInstance(context: any, instance: any) {
|
|
40
|
+
instance.store = new NestedDataView({
|
|
41
|
+
store: instance.parentStore,
|
|
42
|
+
nestedData: new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true }),
|
|
43
|
+
immutable: this.immutable,
|
|
44
|
+
sealed: this.sealed,
|
|
45
|
+
});
|
|
46
|
+
super.initInstance(context, instance);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
applyParentStore(instance: any) {
|
|
50
|
+
instance.store.setStore(instance.parentStore);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
DataProxy.prototype.immutable = false;
|
|
55
|
+
DataProxy.prototype.sealed = false;
|
package/src/ui/Repeater.spec.tsx
CHANGED
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
import { Store } from "../data/Store";
|
|
2
|
-
import { Repeater } from "./Repeater";
|
|
3
|
-
import { bind } from "./bind";
|
|
4
|
-
import { createTestRenderer, act } from "../util/test/createTestRenderer";
|
|
5
|
-
import { createAccessorModelProxy } from "../data/createAccessorModelProxy";
|
|
6
|
-
|
|
7
|
-
import assert from "assert";
|
|
8
|
-
|
|
9
|
-
describe("Repeater", () => {
|
|
10
|
-
it("allows sorting", async () => {
|
|
11
|
-
let data = [
|
|
12
|
-
{
|
|
13
|
-
value: "C",
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
value: "B",
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
value: "A",
|
|
20
|
-
},
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
let widget = (
|
|
24
|
-
<cx>
|
|
25
|
-
<div>
|
|
26
|
-
<Repeater records={data} sorters={[{ field: "value", direction: "ASC" }]} recordAlias="$item">
|
|
27
|
-
<div text={bind("$item.value")} />
|
|
28
|
-
</Repeater>
|
|
29
|
-
</div>
|
|
30
|
-
</cx>
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
let store = new Store();
|
|
34
|
-
|
|
35
|
-
const component = await createTestRenderer(store, widget);
|
|
36
|
-
|
|
37
|
-
let tree = component.toJSON();
|
|
38
|
-
assert.deepEqual(tree, {
|
|
39
|
-
type: "div",
|
|
40
|
-
props: {},
|
|
41
|
-
children: [
|
|
42
|
-
{
|
|
43
|
-
type: "div",
|
|
44
|
-
props: {},
|
|
45
|
-
children: ["A"],
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
type: "div",
|
|
49
|
-
props: {},
|
|
50
|
-
children: ["B"],
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
type: "div",
|
|
54
|
-
props: {},
|
|
55
|
-
children: ["C"],
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("changes are properly updated", async () => {
|
|
62
|
-
let divInstances: any[] = [];
|
|
63
|
-
let widget = (
|
|
64
|
-
<cx>
|
|
65
|
-
<div>
|
|
66
|
-
<Repeater records={bind("data")} sorters={[{ field: "value", direction: "ASC" }]} recordAlias="$item">
|
|
67
|
-
<div
|
|
68
|
-
text={bind("$item.value")}
|
|
69
|
-
onExplore={(context, instance) => {
|
|
70
|
-
divInstances.push(instance);
|
|
71
|
-
}}
|
|
72
|
-
/>
|
|
73
|
-
</Repeater>
|
|
74
|
-
</div>
|
|
75
|
-
</cx>
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
let store = new Store({
|
|
79
|
-
data: {
|
|
80
|
-
data: [
|
|
81
|
-
{
|
|
82
|
-
value: "C",
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
value: "B",
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const component = await createTestRenderer(store, widget);
|
|
92
|
-
|
|
93
|
-
let tree = component.toJSON();
|
|
94
|
-
assert.deepEqual(tree, {
|
|
95
|
-
type: "div",
|
|
96
|
-
props: {},
|
|
97
|
-
children: [
|
|
98
|
-
{
|
|
99
|
-
type: "div",
|
|
100
|
-
props: {},
|
|
101
|
-
children: ["B"],
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
type: "div",
|
|
105
|
-
props: {},
|
|
106
|
-
children: ["C"],
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
divInstances = [];
|
|
112
|
-
|
|
113
|
-
await act(async () => {
|
|
114
|
-
store.update("data", (data) => [{ value: "A" }, ...data]);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
assert.deepEqual(component.toJSON(), {
|
|
118
|
-
type: "div",
|
|
119
|
-
props: {},
|
|
120
|
-
children: [
|
|
121
|
-
{
|
|
122
|
-
type: "div",
|
|
123
|
-
props: {},
|
|
124
|
-
children: ["A"],
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
type: "div",
|
|
128
|
-
props: {},
|
|
129
|
-
children: ["B"],
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
type: "div",
|
|
133
|
-
props: {},
|
|
134
|
-
children: ["C"],
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
assert.equal(divInstances.length, 3);
|
|
140
|
-
assert.equal(divInstances[0].store.get("$item.value"), "A");
|
|
141
|
-
assert.equal(divInstances[1].store.get("$item.value"), "B");
|
|
142
|
-
assert.equal(divInstances[2].store.get("$item.value"), "C");
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("infers T from AccessorChain<T[]> for onCreateFilter callback", () => {
|
|
146
|
-
interface Item {
|
|
147
|
-
name: string;
|
|
148
|
-
active: boolean;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
interface AppModel {
|
|
152
|
-
items: Item[];
|
|
153
|
-
$item: Item;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const m = createAccessorModelProxy<AppModel>();
|
|
157
|
-
|
|
158
|
-
// onCreateFilter should receive (record: Item) => boolean when T is inferred from AccessorChain<Item[]>
|
|
159
|
-
const widget = (
|
|
160
|
-
<cx>
|
|
161
|
-
<div>
|
|
162
|
-
<Repeater
|
|
163
|
-
records={m.items}
|
|
164
|
-
recordAlias={m.$item}
|
|
165
|
-
onCreateFilter={() => (record) => {
|
|
166
|
-
// If T is correctly inferred as Item, record.name should be string
|
|
167
|
-
const name: string = record.name;
|
|
168
|
-
// @ts-expect-error - record.name should be string, not number
|
|
169
|
-
const wrong: number = record.name;
|
|
170
|
-
return record.active;
|
|
171
|
-
}}
|
|
172
|
-
>
|
|
173
|
-
<div text={m.$item.name} />
|
|
174
|
-
</Repeater>
|
|
175
|
-
</div>
|
|
176
|
-
</cx>
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
assert.ok(widget);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
1
|
+
import { Store } from "../data/Store";
|
|
2
|
+
import { Repeater } from "./Repeater";
|
|
3
|
+
import { bind } from "./bind";
|
|
4
|
+
import { createTestRenderer, act } from "../util/test/createTestRenderer";
|
|
5
|
+
import { createAccessorModelProxy } from "../data/createAccessorModelProxy";
|
|
6
|
+
|
|
7
|
+
import assert from "assert";
|
|
8
|
+
|
|
9
|
+
describe("Repeater", () => {
|
|
10
|
+
it("allows sorting", async () => {
|
|
11
|
+
let data = [
|
|
12
|
+
{
|
|
13
|
+
value: "C",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
value: "B",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
value: "A",
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
let widget = (
|
|
24
|
+
<cx>
|
|
25
|
+
<div>
|
|
26
|
+
<Repeater records={data} sorters={[{ field: "value", direction: "ASC" }]} recordAlias="$item">
|
|
27
|
+
<div text={bind("$item.value")} />
|
|
28
|
+
</Repeater>
|
|
29
|
+
</div>
|
|
30
|
+
</cx>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
let store = new Store();
|
|
34
|
+
|
|
35
|
+
const component = await createTestRenderer(store, widget);
|
|
36
|
+
|
|
37
|
+
let tree = component.toJSON();
|
|
38
|
+
assert.deepEqual(tree, {
|
|
39
|
+
type: "div",
|
|
40
|
+
props: {},
|
|
41
|
+
children: [
|
|
42
|
+
{
|
|
43
|
+
type: "div",
|
|
44
|
+
props: {},
|
|
45
|
+
children: ["A"],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: "div",
|
|
49
|
+
props: {},
|
|
50
|
+
children: ["B"],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "div",
|
|
54
|
+
props: {},
|
|
55
|
+
children: ["C"],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("changes are properly updated", async () => {
|
|
62
|
+
let divInstances: any[] = [];
|
|
63
|
+
let widget = (
|
|
64
|
+
<cx>
|
|
65
|
+
<div>
|
|
66
|
+
<Repeater records={bind("data")} sorters={[{ field: "value", direction: "ASC" }]} recordAlias="$item">
|
|
67
|
+
<div
|
|
68
|
+
text={bind("$item.value")}
|
|
69
|
+
onExplore={(context, instance) => {
|
|
70
|
+
divInstances.push(instance);
|
|
71
|
+
}}
|
|
72
|
+
/>
|
|
73
|
+
</Repeater>
|
|
74
|
+
</div>
|
|
75
|
+
</cx>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
let store = new Store({
|
|
79
|
+
data: {
|
|
80
|
+
data: [
|
|
81
|
+
{
|
|
82
|
+
value: "C",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
value: "B",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const component = await createTestRenderer(store, widget);
|
|
92
|
+
|
|
93
|
+
let tree = component.toJSON();
|
|
94
|
+
assert.deepEqual(tree, {
|
|
95
|
+
type: "div",
|
|
96
|
+
props: {},
|
|
97
|
+
children: [
|
|
98
|
+
{
|
|
99
|
+
type: "div",
|
|
100
|
+
props: {},
|
|
101
|
+
children: ["B"],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
type: "div",
|
|
105
|
+
props: {},
|
|
106
|
+
children: ["C"],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
divInstances = [];
|
|
112
|
+
|
|
113
|
+
await act(async () => {
|
|
114
|
+
store.update("data", (data) => [{ value: "A" }, ...data]);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
assert.deepEqual(component.toJSON(), {
|
|
118
|
+
type: "div",
|
|
119
|
+
props: {},
|
|
120
|
+
children: [
|
|
121
|
+
{
|
|
122
|
+
type: "div",
|
|
123
|
+
props: {},
|
|
124
|
+
children: ["A"],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: "div",
|
|
128
|
+
props: {},
|
|
129
|
+
children: ["B"],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
type: "div",
|
|
133
|
+
props: {},
|
|
134
|
+
children: ["C"],
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
assert.equal(divInstances.length, 3);
|
|
140
|
+
assert.equal(divInstances[0].store.get("$item.value"), "A");
|
|
141
|
+
assert.equal(divInstances[1].store.get("$item.value"), "B");
|
|
142
|
+
assert.equal(divInstances[2].store.get("$item.value"), "C");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("infers T from AccessorChain<T[]> for onCreateFilter callback", () => {
|
|
146
|
+
interface Item {
|
|
147
|
+
name: string;
|
|
148
|
+
active: boolean;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface AppModel {
|
|
152
|
+
items: Item[];
|
|
153
|
+
$item: Item;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const m = createAccessorModelProxy<AppModel>();
|
|
157
|
+
|
|
158
|
+
// onCreateFilter should receive (record: Item) => boolean when T is inferred from AccessorChain<Item[]>
|
|
159
|
+
const widget = (
|
|
160
|
+
<cx>
|
|
161
|
+
<div>
|
|
162
|
+
<Repeater
|
|
163
|
+
records={m.items}
|
|
164
|
+
recordAlias={m.$item}
|
|
165
|
+
onCreateFilter={() => (record) => {
|
|
166
|
+
// If T is correctly inferred as Item, record.name should be string
|
|
167
|
+
const name: string = record.name;
|
|
168
|
+
// @ts-expect-error - record.name should be string, not number
|
|
169
|
+
const wrong: number = record.name;
|
|
170
|
+
return record.active;
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
<div text={m.$item.name} />
|
|
174
|
+
</Repeater>
|
|
175
|
+
</div>
|
|
176
|
+
</cx>
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
assert.ok(widget);
|
|
180
|
+
});
|
|
181
|
+
});
|