cx 26.1.13 → 26.2.0

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.
Files changed (127) hide show
  1. package/build/charts/Marker.d.ts +1 -1
  2. package/build/charts/Marker.d.ts.map +1 -1
  3. package/build/charts/Marker.js +16 -6
  4. package/build/charts/MouseTracker.d.ts +2 -0
  5. package/build/charts/MouseTracker.d.ts.map +1 -1
  6. package/build/charts/helpers/PointReducer.d.ts +2 -2
  7. package/build/charts/helpers/PointReducer.d.ts.map +1 -1
  8. package/build/data/View.d.ts +5 -3
  9. package/build/data/View.d.ts.map +1 -1
  10. package/build/data/View.js +3 -1
  11. package/build/data/ops/findTreeNode.d.ts +20 -1
  12. package/build/data/ops/findTreeNode.d.ts.map +1 -1
  13. package/build/data/ops/findTreeNode.js +19 -0
  14. package/build/data/ops/findTreePath.d.ts +1 -1
  15. package/build/data/ops/findTreePath.d.ts.map +1 -1
  16. package/build/data/ops/findTreePath.js +1 -1
  17. package/build/data/ops/removeTreeNodes.d.ts +14 -1
  18. package/build/data/ops/removeTreeNodes.d.ts.map +1 -1
  19. package/build/data/ops/removeTreeNodes.js +13 -0
  20. package/build/data/ops/updateArray.d.ts +1 -1
  21. package/build/data/ops/updateArray.d.ts.map +1 -1
  22. package/build/data/ops/updateArray.js +1 -1
  23. package/build/data/ops/updateTree.d.ts +20 -1
  24. package/build/data/ops/updateTree.d.ts.map +1 -1
  25. package/build/data/ops/updateTree.js +19 -0
  26. package/build/jsx-runtime.d.ts +1 -0
  27. package/build/jsx-runtime.d.ts.map +1 -1
  28. package/build/jsx-runtime.js +3 -1
  29. package/build/svg/Rectangle.d.ts +6 -4
  30. package/build/svg/Rectangle.d.ts.map +1 -1
  31. package/build/svg/Rectangle.js +9 -7
  32. package/build/ui/Instance.d.ts +1 -1
  33. package/build/ui/Instance.d.ts.map +1 -1
  34. package/build/ui/Instance.js +18 -8
  35. package/build/ui/IsolatedScope.d.ts +2 -1
  36. package/build/ui/IsolatedScope.d.ts.map +1 -1
  37. package/build/ui/Prop.d.ts +1 -1
  38. package/build/ui/Prop.d.ts.map +1 -1
  39. package/build/ui/Widget.d.ts +2 -0
  40. package/build/ui/Widget.d.ts.map +1 -1
  41. package/build/ui/Widget.js +4 -0
  42. package/build/ui/adapter/GroupAdapter.d.ts +4 -4
  43. package/build/ui/adapter/GroupAdapter.d.ts.map +1 -1
  44. package/build/ui/adapter/GroupAdapter.js +4 -4
  45. package/build/ui/adapter/TreeAdapter.d.ts +5 -3
  46. package/build/ui/adapter/TreeAdapter.d.ts.map +1 -1
  47. package/build/ui/adapter/TreeAdapter.js +12 -5
  48. package/build/ui/app/startAppLoop.d.ts +2 -2
  49. package/build/ui/app/startAppLoop.d.ts.map +1 -1
  50. package/build/ui/app/startHotAppLoop.d.ts +4 -4
  51. package/build/ui/app/startHotAppLoop.d.ts.map +1 -1
  52. package/build/ui/app/startHotAppLoop.js +1 -1
  53. package/build/ui/batchUpdates.d.ts.map +1 -1
  54. package/build/ui/batchUpdates.js +3 -4
  55. package/build/widgets/Button.d.ts +0 -7
  56. package/build/widgets/Button.d.ts.map +1 -1
  57. package/build/widgets/HtmlElement.d.ts +2 -2
  58. package/build/widgets/HtmlElement.d.ts.map +1 -1
  59. package/build/widgets/form/Checkbox.d.ts +3 -3
  60. package/build/widgets/form/Checkbox.d.ts.map +1 -1
  61. package/build/widgets/form/Checkbox.js +11 -6
  62. package/build/widgets/form/DateTimeField.d.ts +4 -0
  63. package/build/widgets/form/DateTimeField.d.ts.map +1 -1
  64. package/build/widgets/form/TextField.d.ts +2 -2
  65. package/build/widgets/form/TextField.d.ts.map +1 -1
  66. package/build/widgets/grid/Grid.d.ts +20 -16
  67. package/build/widgets/grid/Grid.d.ts.map +1 -1
  68. package/build/widgets/grid/Grid.js +200 -86
  69. package/build/widgets/nav/Menu.d.ts +2 -0
  70. package/build/widgets/nav/Menu.d.ts.map +1 -1
  71. package/build/widgets/nav/Route.js +1 -1
  72. package/build/widgets/overlay/FlyweightTooltipTracker.d.ts +6 -4
  73. package/build/widgets/overlay/FlyweightTooltipTracker.d.ts.map +1 -1
  74. package/build/widgets/overlay/FlyweightTooltipTracker.js +3 -0
  75. package/build/widgets/overlay/Overlay.d.ts +2 -2
  76. package/build/widgets/overlay/Overlay.d.ts.map +1 -1
  77. package/dist/data.js +52 -1
  78. package/dist/jsx-runtime.js +4 -2
  79. package/dist/manifest.js +910 -904
  80. package/dist/svg.js +3 -0
  81. package/dist/ui.js +1548 -1544
  82. package/dist/widgets.css +1 -1
  83. package/dist/widgets.js +395 -4
  84. package/package.json +2 -2
  85. package/src/charts/Marker.tsx +448 -394
  86. package/src/charts/MouseTracker.tsx +3 -0
  87. package/src/charts/helpers/PointReducer.ts +2 -2
  88. package/src/data/View.ts +76 -19
  89. package/src/data/ops/findTreeNode.ts +20 -1
  90. package/src/data/ops/findTreePath.ts +7 -2
  91. package/src/data/ops/removeTreeNodes.ts +14 -1
  92. package/src/data/ops/updateArray.ts +4 -4
  93. package/src/data/ops/updateTree.ts +32 -6
  94. package/src/index.scss +6 -6
  95. package/src/jsx-runtime.spec.tsx +40 -0
  96. package/src/jsx-runtime.ts +87 -84
  97. package/src/svg/Rectangle.tsx +80 -73
  98. package/src/ui/DataProxy.ts +55 -55
  99. package/src/ui/Instance.ts +142 -45
  100. package/src/ui/IsolatedScope.ts +4 -2
  101. package/src/ui/Prop.ts +141 -141
  102. package/src/ui/Rescope.ts +50 -50
  103. package/src/ui/Widget.tsx +292 -234
  104. package/src/ui/adapter/ArrayAdapter.ts +229 -229
  105. package/src/ui/adapter/GroupAdapter.ts +8 -10
  106. package/src/ui/adapter/TreeAdapter.ts +75 -15
  107. package/src/ui/app/Url.spec.ts +1 -1
  108. package/src/ui/app/startAppLoop.tsx +56 -45
  109. package/src/ui/app/startHotAppLoop.ts +4 -4
  110. package/src/ui/batchUpdates.ts +16 -21
  111. package/src/ui/exprHelpers.ts +96 -96
  112. package/src/widgets/Button.tsx +0 -8
  113. package/src/widgets/HtmlElement.spec.tsx +100 -72
  114. package/src/widgets/HtmlElement.tsx +11 -10
  115. package/src/widgets/Sandbox.ts +104 -104
  116. package/src/widgets/Section.scss +55 -55
  117. package/src/widgets/drag-drop/DropZone.scss +74 -74
  118. package/src/widgets/form/Checkbox.tsx +296 -243
  119. package/src/widgets/form/DateTimeField.tsx +6 -0
  120. package/src/widgets/form/TextField.tsx +2 -2
  121. package/src/widgets/grid/Grid.scss +43 -10
  122. package/src/widgets/grid/Grid.tsx +4401 -3848
  123. package/src/widgets/nav/Menu.tsx +3 -0
  124. package/src/widgets/nav/Route.ts +1 -1
  125. package/src/widgets/overlay/FlyweightTooltipTracker.ts +15 -4
  126. package/src/widgets/overlay/Overlay.tsx +2 -1
  127. package/src/widgets/overlay/index.d.ts +11 -11
@@ -6,66 +6,77 @@ import { Store } from "../../data/Store";
6
6
  import { Cx } from "../Cx";
7
7
  import { Instance } from "../Instance";
8
8
  import { Create } from "../../util/Component";
9
+ import { View } from "../../data/View";
9
10
 
10
11
  export interface StartAppLoopOptions {
11
- destroyDelay?: number;
12
- removeParentDOMElement?: boolean;
13
- [key: string]: any;
12
+ destroyDelay?: number;
13
+ removeParentDOMElement?: boolean;
14
+ [key: string]: any;
14
15
  }
15
16
 
16
17
  export function startAppLoop(
17
- parentDOMElement: HTMLElement,
18
- storeOrInstance?: Store | Instance,
19
- widget?: Create<typeof Widget> | Create<typeof Widget>[],
20
- options: StartAppLoopOptions = {},
18
+ parentDOMElement: HTMLElement,
19
+ storeOrInstance?: View | Instance,
20
+ widget?: Create<typeof Widget> | Create<typeof Widget>[],
21
+ options: StartAppLoopOptions = {},
21
22
  ): () => void {
22
- if (!parentDOMElement || parentDOMElement.nodeType !== 1)
23
- throw new Error("First argument to startAppLoop should be a valid DOM element.");
23
+ if (!parentDOMElement || parentDOMElement.nodeType !== 1)
24
+ throw new Error(
25
+ "First argument to startAppLoop should be a valid DOM element.",
26
+ );
24
27
 
25
- let store: Store | undefined;
26
- let instance: Instance | undefined;
27
- let parentInstance: Instance | undefined;
28
+ let store: Store | undefined;
29
+ let instance: Instance | undefined;
30
+ let parentInstance: Instance | undefined;
28
31
 
29
- if (!storeOrInstance) storeOrInstance = new Store();
32
+ if (!storeOrInstance) storeOrInstance = new Store();
30
33
 
31
- if ((storeOrInstance as any).notify) store = storeOrInstance as Store;
32
- else if ((storeOrInstance as any).getChild) {
33
- if ((storeOrInstance as any).widget === widget) instance = storeOrInstance as Instance;
34
- else parentInstance = storeOrInstance as Instance;
35
- } else throw new Error("Second argument to startAppLoop should be either of type Store or Instance");
34
+ if ((storeOrInstance as any).notify) store = storeOrInstance as Store;
35
+ else if ((storeOrInstance as any).getChild) {
36
+ if ((storeOrInstance as any).widget === widget)
37
+ instance = storeOrInstance as Instance;
38
+ else parentInstance = storeOrInstance as Instance;
39
+ } else
40
+ throw new Error(
41
+ "Second argument to startAppLoop should be either of type Store or Instance",
42
+ );
36
43
 
37
- let content = (
38
- <Cx
39
- store={store}
40
- widget={widget}
41
- instance={instance}
42
- parentInstance={parentInstance}
43
- options={options}
44
- subscribe
45
- />
46
- ) as any;
44
+ let content = (
45
+ <Cx
46
+ store={store}
47
+ widget={widget}
48
+ instance={instance}
49
+ parentInstance={parentInstance}
50
+ options={options}
51
+ subscribe
52
+ />
53
+ ) as any;
47
54
 
48
- let root = VDOM.DOM.createRoot(parentDOMElement);
49
- root.render(content);
55
+ let root = VDOM.DOM.createRoot(parentDOMElement);
56
+ root.render(content);
50
57
 
51
- let stopped = false;
58
+ let stopped = false;
52
59
 
53
- return function () {
54
- if (stopped) return;
60
+ return function () {
61
+ if (stopped) return;
55
62
 
56
- stopped = true;
63
+ stopped = true;
57
64
 
58
- if (!options.destroyDelay) destroy(parentDOMElement, options, root);
59
- else {
60
- setTimeout(() => {
61
- destroy(parentDOMElement, options, root);
62
- }, options.destroyDelay);
63
- }
64
- };
65
+ if (!options.destroyDelay) destroy(parentDOMElement, options, root);
66
+ else {
67
+ setTimeout(() => {
68
+ destroy(parentDOMElement, options, root);
69
+ }, options.destroyDelay);
70
+ }
71
+ };
65
72
  }
66
73
 
67
- function destroy(parentDOMElement: HTMLElement, options: StartAppLoopOptions, root: Root): void {
68
- if (root) root.unmount();
69
- if (options.removeParentDOMElement && parentDOMElement.parentNode)
70
- parentDOMElement.parentNode.removeChild(parentDOMElement);
74
+ function destroy(
75
+ parentDOMElement: HTMLElement,
76
+ options: StartAppLoopOptions,
77
+ root: Root,
78
+ ): void {
79
+ if (root) root.unmount();
80
+ if (options.removeParentDOMElement && parentDOMElement.parentNode)
81
+ parentDOMElement.parentNode.removeChild(parentDOMElement);
71
82
  }
@@ -1,7 +1,7 @@
1
- import { startAppLoop, StartAppLoopOptions } from "./startAppLoop";
2
- import { Widget, WidgetConfig } from "../Widget";
3
- import { Store } from "../../data/Store";
1
+ import { View } from "../../data/View";
4
2
  import { Create } from "../../util/Component";
3
+ import { Widget } from "../Widget";
4
+ import { startAppLoop, StartAppLoopOptions } from "./startAppLoop";
5
5
 
6
6
  export interface HotModule {
7
7
  hot?: {
@@ -14,7 +14,7 @@ export interface HotModule {
14
14
  export function startHotAppLoop(
15
15
  appModule: HotModule,
16
16
  element: HTMLElement,
17
- store: Store,
17
+ store: View,
18
18
  widgets: Create<typeof Widget> | Create<typeof Widget>[],
19
19
  options: StartAppLoopOptions = {},
20
20
  ): () => void {
@@ -1,5 +1,5 @@
1
- import { VDOM } from './Widget';
2
- import { SubscriberList } from '../util/SubscriberList';
1
+ import { VDOM } from "./VDOM";
2
+ import { SubscriberList } from "../util/SubscriberList";
3
3
 
4
4
  interface UpdateCallback {
5
5
  pending: number;
@@ -16,13 +16,11 @@ export function batchUpdates(callback: () => void): void {
16
16
  isBatching++;
17
17
  try {
18
18
  callback();
19
- }
20
- finally {
19
+ } finally {
21
20
  isBatching--;
22
21
  }
23
22
  });
24
- else
25
- callback();
23
+ else callback();
26
24
  }
27
25
 
28
26
  export function isBatchingUpdates(): boolean {
@@ -30,7 +28,7 @@ export function isBatchingUpdates(): boolean {
30
28
  }
31
29
 
32
30
  export function notifyBatchedUpdateStarting(): void {
33
- promiseSubscribers.execute((x: any) =>{
31
+ promiseSubscribers.execute((x: any) => {
34
32
  (x as UpdateCallback).pending++;
35
33
  });
36
34
  }
@@ -39,14 +37,15 @@ export function notifyBatchedUpdateCompleted(): void {
39
37
  promiseSubscribers.execute((x: any) => {
40
38
  let cb = x as UpdateCallback;
41
39
  cb.finished++;
42
- if (cb.finished >= cb.pending)
43
- cb.complete(true);
40
+ if (cb.finished >= cb.pending) cb.complete(true);
44
41
  });
45
42
  }
46
43
 
47
- let updateId = 0;
48
-
49
- export function batchUpdatesAndNotify(callback: () => void, notifyCallback: (success: boolean) => void, timeout: number = 1000): void {
44
+ export function batchUpdatesAndNotify(
45
+ callback: () => void,
46
+ notifyCallback: (success: boolean) => void,
47
+ timeout: number = 1000,
48
+ ): void {
50
49
  let done = false;
51
50
  let timer: NodeJS.Timeout | undefined;
52
51
  let unsubscribe: (() => void) | undefined;
@@ -57,21 +56,17 @@ export function batchUpdatesAndNotify(callback: () => void, notifyCallback: (suc
57
56
  complete: (success?: boolean) => {
58
57
  if (!done) {
59
58
  done = true;
60
- if (timer)
61
- clearInterval(timer);
62
- if (unsubscribe)
63
- unsubscribe();
59
+ if (timer) clearInterval(timer);
60
+ if (unsubscribe) unsubscribe();
64
61
  notifyCallback(!!success);
65
62
  }
66
- }
63
+ },
67
64
  };
68
65
 
69
66
  unsubscribe = promiseSubscribers.subscribe(update as any);
70
67
 
71
68
  batchUpdates(callback);
72
69
 
73
- if (update.pending <= update.finished)
74
- update.complete(true);
75
- else
76
- timer = setTimeout(update.complete, timeout);
70
+ if (update.pending <= update.finished) update.complete(true);
71
+ else timer = setTimeout(update.complete, timeout);
77
72
  }
@@ -1,96 +1,96 @@
1
- import { computable } from "../data/computable";
2
- import { AccessorChain } from "../data/createAccessorModelProxy";
3
- import { Selector } from "../data/Selector";
4
- import { Format } from "../util/Format";
5
- import { expr } from "./expr";
6
-
7
- /** Returns a selector that converts the value to boolean using !! */
8
- export function truthy<V>(arg: AccessorChain<V>): Selector<boolean> {
9
- return expr(arg, (x) => !!x);
10
- }
11
-
12
- /** Returns a selector that checks if the value is falsy using ! */
13
- export function falsy<V>(arg: AccessorChain<V>): Selector<boolean> {
14
- return expr(arg, (x) => !x);
15
- }
16
-
17
- /** Returns a selector that checks if the value is strictly true (=== true) */
18
- export function isTrue(arg: AccessorChain<any>): Selector<boolean> {
19
- return expr(arg, (x) => x === true);
20
- }
21
-
22
- /** Returns a selector that checks if the value is strictly false (=== false) */
23
- export function isFalse(arg: AccessorChain<any>): Selector<boolean> {
24
- return expr(arg, (x) => x === false);
25
- }
26
-
27
- /** Returns a selector that checks if the value is not null or undefined (x != null) */
28
- export function hasValue<V>(arg: AccessorChain<V>): Selector<boolean> {
29
- return expr(arg, (x) => x != null);
30
- }
31
-
32
- /** Returns a selector that checks if a string or array is empty (null, undefined, or length === 0) */
33
- export function isEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
34
- return expr(arg, (x) => x == null || x.length === 0);
35
- }
36
-
37
- /** Returns a selector that checks if a string or array is non-empty (not null/undefined and length > 0) */
38
- export function isNonEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
39
- return expr(arg, (x) => x != null && x.length > 0);
40
- }
41
-
42
- /** Returns a selector that checks if the value is less than the given value */
43
- export function lessThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
44
- return expr(arg, (x) => x < value);
45
- }
46
-
47
- /** Returns a selector that checks if the value is less than or equal to the given value */
48
- export function lessThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
49
- return expr(arg, (x) => x <= value);
50
- }
51
-
52
- /** Returns a selector that checks if the value is greater than the given value */
53
- export function greaterThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
54
- return expr(arg, (x) => x > value);
55
- }
56
-
57
- /** Returns a selector that checks if the value is greater than or equal to the given value */
58
- export function greaterThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
59
- return expr(arg, (x) => x >= value);
60
- }
61
-
62
- /** Returns a selector that checks if the value equals the given value using == */
63
- export function equal<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
64
- return expr(arg, (x) => x == value);
65
- }
66
-
67
- /** Returns a selector that checks if the value does not equal the given value using != */
68
- export function notEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
69
- return expr(arg, (x) => x != value);
70
- }
71
-
72
- /** Returns a selector that checks if the value strictly equals the given value using === */
73
- export function strictEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
74
- return expr(arg, (x) => x === value);
75
- }
76
-
77
- /** Returns a selector that checks if the value strictly does not equal the given value using !== */
78
- export function strictNotEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
79
- return expr(arg, (x) => x !== value);
80
- }
81
-
82
- /** Returns a selector that formats the value using the specified format string.
83
- * Format strings use semicolon-separated syntax: "formatType;param1;param2"
84
- * @param arg - The accessor chain to the value
85
- * @param fmt - The format string
86
- * @param nullText - Optional text to display for null/undefined values
87
- * @example
88
- * format(m.price, "n;2") // formats as number with 2 decimal places
89
- * format(m.date, "d") // formats as date
90
- * format(m.value, "p;0;2") // formats as percentage with 0-2 decimal places
91
- * format(m.value, "n;2", "N/A") // shows "N/A" for null values
92
- */
93
- export function format<V>(arg: AccessorChain<V>, fmt: string, nullText?: string): Selector<string> {
94
- let f = nullText != null ? `${fmt}|${nullText}` : fmt;
95
- return computable(arg, (x) => Format.value(x, f));
96
- }
1
+ import { computable } from "../data/computable";
2
+ import { AccessorChain } from "../data/createAccessorModelProxy";
3
+ import { Selector } from "../data/Selector";
4
+ import { Format } from "../util/Format";
5
+ import { expr } from "./expr";
6
+
7
+ /** Returns a selector that converts the value to boolean using !! */
8
+ export function truthy<V>(arg: AccessorChain<V>): Selector<boolean> {
9
+ return expr(arg, (x) => !!x);
10
+ }
11
+
12
+ /** Returns a selector that checks if the value is falsy using ! */
13
+ export function falsy<V>(arg: AccessorChain<V>): Selector<boolean> {
14
+ return expr(arg, (x) => !x);
15
+ }
16
+
17
+ /** Returns a selector that checks if the value is strictly true (=== true) */
18
+ export function isTrue(arg: AccessorChain<any>): Selector<boolean> {
19
+ return expr(arg, (x) => x === true);
20
+ }
21
+
22
+ /** Returns a selector that checks if the value is strictly false (=== false) */
23
+ export function isFalse(arg: AccessorChain<any>): Selector<boolean> {
24
+ return expr(arg, (x) => x === false);
25
+ }
26
+
27
+ /** Returns a selector that checks if the value is not null or undefined (x != null) */
28
+ export function hasValue<V>(arg: AccessorChain<V>): Selector<boolean> {
29
+ return expr(arg, (x) => x != null);
30
+ }
31
+
32
+ /** Returns a selector that checks if a string or array is empty (null, undefined, or length === 0) */
33
+ export function isEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
34
+ return expr(arg, (x) => x == null || x.length === 0);
35
+ }
36
+
37
+ /** Returns a selector that checks if a string or array is non-empty (not null/undefined and length > 0) */
38
+ export function isNonEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
39
+ return expr(arg, (x) => x != null && x.length > 0);
40
+ }
41
+
42
+ /** Returns a selector that checks if the value is less than the given value */
43
+ export function lessThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
44
+ return expr(arg, (x) => x < value);
45
+ }
46
+
47
+ /** Returns a selector that checks if the value is less than or equal to the given value */
48
+ export function lessThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
49
+ return expr(arg, (x) => x <= value);
50
+ }
51
+
52
+ /** Returns a selector that checks if the value is greater than the given value */
53
+ export function greaterThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
54
+ return expr(arg, (x) => x > value);
55
+ }
56
+
57
+ /** Returns a selector that checks if the value is greater than or equal to the given value */
58
+ export function greaterThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
59
+ return expr(arg, (x) => x >= value);
60
+ }
61
+
62
+ /** Returns a selector that checks if the value equals the given value using == */
63
+ export function equal<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
64
+ return expr(arg, (x) => x == value);
65
+ }
66
+
67
+ /** Returns a selector that checks if the value does not equal the given value using != */
68
+ export function notEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
69
+ return expr(arg, (x) => x != value);
70
+ }
71
+
72
+ /** Returns a selector that checks if the value strictly equals the given value using === */
73
+ export function strictEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
74
+ return expr(arg, (x) => x === value);
75
+ }
76
+
77
+ /** Returns a selector that checks if the value strictly does not equal the given value using !== */
78
+ export function strictNotEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
79
+ return expr(arg, (x) => x !== value);
80
+ }
81
+
82
+ /** Returns a selector that formats the value using the specified format string.
83
+ * Format strings use semicolon-separated syntax: "formatType;param1;param2"
84
+ * @param arg - The accessor chain to the value
85
+ * @param fmt - The format string
86
+ * @param nullText - Optional text to display for null/undefined values
87
+ * @example
88
+ * format(m.price, "n;2") // formats as number with 2 decimal places
89
+ * format(m.date, "d") // formats as date
90
+ * format(m.value, "p;0;2") // formats as percentage with 0-2 decimal places
91
+ * format(m.value, "n;2", "N/A") // shows "N/A" for null values
92
+ */
93
+ export function format<V>(arg: AccessorChain<V>, fmt: string, nullText?: string): Selector<string> {
94
+ let f = nullText != null ? `${fmt}|${nullText}` : fmt;
95
+ return computable(arg, (x) => Format.value(x, f));
96
+ }
@@ -41,14 +41,6 @@ export interface ButtonConfig extends Omit<HtmlElementConfig<"button">, "disable
41
41
  /** Set to `false` to disable the button. */
42
42
  enabled?: BooleanProp;
43
43
 
44
- /**
45
- * Click handler.
46
- *
47
- * @param e - Event.
48
- * @param instance - Cx widget instance that fired the event.
49
- */
50
- onClick?: string | ((e: React.MouseEvent, instance: Instance) => void);
51
-
52
44
  /** Button type. */
53
45
  type?: "submit" | "button";
54
46
 
@@ -3,87 +3,115 @@ import assert from "assert";
3
3
  import { createTestRenderer } from "../util/test/createTestRenderer";
4
4
  import { bind } from "../ui/bind";
5
5
  import { VDOM } from "../ui/Widget";
6
+ import { Instance } from "../ui/Instance";
6
7
 
7
8
  describe("HtmlElement", () => {
8
- it("renders textual content provided through the text property", async () => {
9
- let widget = (
10
- <cx>
11
- <div text={bind("text")} />
12
- </cx>
13
- );
9
+ it("renders textual content provided through the text property", async () => {
10
+ let widget = (
11
+ <cx>
12
+ <div text={bind("text")} />
13
+ </cx>
14
+ );
14
15
 
15
- let store = new Store({
16
- data: {
17
- text: "Test",
18
- },
19
- });
16
+ let store = new Store({
17
+ data: {
18
+ text: "Test",
19
+ },
20
+ });
20
21
 
21
- const component = await createTestRenderer(store, widget);
22
+ const component = await createTestRenderer(store, widget);
22
23
 
23
- let tree = component.toJSON();
24
- assert(tree && !Array.isArray(tree), "Expected single element");
25
- assert.equal(tree.type, "div");
26
- assert.deepEqual(tree.children, ["Test"]);
27
- });
24
+ let tree = component.toJSON();
25
+ assert(tree && !Array.isArray(tree), "Expected single element");
26
+ assert.equal(tree.type, "div");
27
+ assert.deepEqual(tree.children, ["Test"]);
28
+ });
28
29
 
29
- it("allows spread bindings", async () => {
30
- let store = new Store({
31
- data: {
32
- title: "title",
33
- },
34
- });
30
+ it("allows spread bindings", async () => {
31
+ let store = new Store({
32
+ data: {
33
+ title: "title",
34
+ },
35
+ });
35
36
 
36
- const component = await createTestRenderer(
37
- store,
38
- <cx>
39
- <a href="#" {...{ title: { bind: "title" } }}>
40
- Link
41
- </a>
42
- </cx>,
43
- );
37
+ const component = await createTestRenderer(
38
+ store,
39
+ <cx>
40
+ <a href="#" {...{ title: { bind: "title" } }}>
41
+ Link
42
+ </a>
43
+ </cx>,
44
+ );
44
45
 
45
- let tree = component.toJSON();
46
- assert(tree && !Array.isArray(tree), "Expected single element");
47
- assert.deepEqual(tree, {
48
- type: "a",
49
- children: ["Link"],
50
- props: {
51
- href: "#",
52
- title: "title",
53
- },
54
- });
55
- });
46
+ let tree = component.toJSON();
47
+ assert(tree && !Array.isArray(tree), "Expected single element");
48
+ assert.deepEqual(tree, {
49
+ type: "a",
50
+ children: ["Link"],
51
+ props: {
52
+ href: "#",
53
+ title: "title",
54
+ },
55
+ });
56
+ });
56
57
 
57
- it("supports SVG elements with camelCase attributes", async () => {
58
- let store = new Store();
58
+ it("supports SVG elements with camelCase attributes", async () => {
59
+ let store = new Store();
59
60
 
60
- const component = await createTestRenderer(
61
- store,
62
- <cx>
63
- <svg>
64
- <path
65
- d="M200,176V64a23.9,23.9,0,0,0-24-24H40"
66
- fill="none"
67
- stroke="#343434"
68
- strokeLinecap="round"
69
- strokeLinejoin="round"
70
- strokeWidth="12"
71
- />
72
- </svg>
73
- </cx>,
74
- );
61
+ const component = await createTestRenderer(
62
+ store,
63
+ <cx>
64
+ <svg>
65
+ <path
66
+ d="M200,176V64a23.9,23.9,0,0,0-24-24H40"
67
+ fill="none"
68
+ stroke="#343434"
69
+ strokeLinecap="round"
70
+ strokeLinejoin="round"
71
+ strokeWidth="12"
72
+ />
73
+ </svg>
74
+ </cx>,
75
+ );
75
76
 
76
- let tree = component.toJSON();
77
- assert(tree && !Array.isArray(tree), "Expected single element");
78
- assert.equal(tree.type, "svg");
79
- assert(tree.children && tree.children.length === 1, "Expected one child");
80
- let path = tree.children[0] as any;
81
- assert.equal(path.type, "path");
82
- assert.equal(path.props.d, "M200,176V64a23.9,23.9,0,0,0-24-24H40");
83
- assert.equal(path.props.fill, "none");
84
- assert.equal(path.props.stroke, "#343434");
85
- assert.equal(path.props.strokeLinecap, "round");
86
- assert.equal(path.props.strokeLinejoin, "round");
87
- assert.equal(path.props.strokeWidth, "12");
88
- });
77
+ let tree = component.toJSON();
78
+ assert(tree && !Array.isArray(tree), "Expected single element");
79
+ assert.equal(tree.type, "svg");
80
+ assert(tree.children && tree.children.length === 1, "Expected one child");
81
+ let path = tree.children[0] as any;
82
+ assert.equal(path.type, "path");
83
+ assert.equal(path.props.d, "M200,176V64a23.9,23.9,0,0,0-24-24H40");
84
+ assert.equal(path.props.fill, "none");
85
+ assert.equal(path.props.stroke, "#343434");
86
+ assert.equal(path.props.strokeLinecap, "round");
87
+ assert.equal(path.props.strokeLinejoin, "round");
88
+ assert.equal(path.props.strokeWidth, "12");
89
+ });
90
+
91
+ it("infers event handler parameter types", async () => {
92
+ let clickedWith: {
93
+ event: React.MouseEvent<HTMLButtonElement>;
94
+ instance: Instance;
95
+ } | null = null;
96
+
97
+ let store = new Store();
98
+
99
+ const component = await createTestRenderer(
100
+ store,
101
+ <cx>
102
+ <button
103
+ onClick={(e, instance) => {
104
+ // TypeScript should infer e as React.MouseEvent<HTMLButtonElement> and instance as Instance
105
+ clickedWith = { event: e, instance };
106
+ }}
107
+ >
108
+ Click me
109
+ </button>
110
+ </cx>,
111
+ );
112
+
113
+ let tree = component.toJSON();
114
+ assert(tree && !Array.isArray(tree), "Expected single element");
115
+ assert.equal(tree.type, "button");
116
+ });
89
117
  });
@@ -67,18 +67,19 @@ type CxEventHandler<T> = T extends (event: infer E) => any
67
67
  // Note: For string literal union props (like SVG's strokeLinecap), we also accept `string`
68
68
  // because TypeScript widens string literals to `string` in JSX attribute syntax.
69
69
  // This is a known TypeScript behavior where `<path strokeLinecap="round"/>` infers "round" as string.
70
+ // We exclude style/className/class as they're handled by StyledContainerConfig with better CxJS types.
70
71
  type TransformHtmlElementProps<T> = {
71
- [K in keyof T]: K extends "children"
72
+ [K in keyof T as K extends "style" | "className" | "class"
73
+ ? never
74
+ : K]: K extends "children"
72
75
  ? ChildNode | ChildNode[]
73
- : K extends "className" | "class"
74
- ? ClassProp
75
- : IsEventHandler<K, T[K]> extends true
76
- ? CxEventHandler<T[K]>
77
- : string extends T[K]
78
- ? Prop<T[K]> // Plain string props - no change needed
79
- : NonNullable<T[K]> extends string
80
- ? Prop<T[K]> | string // String literal unions - accept string for JSX compatibility
81
- : Prop<T[K]>;
76
+ : IsEventHandler<K, T[K]> extends true
77
+ ? CxEventHandler<T[K]>
78
+ : string extends T[K]
79
+ ? Prop<T[K]> // Plain string props - no change needed
80
+ : NonNullable<T[K]> extends string
81
+ ? Prop<T[K]> | string // String literal unions - accept string for JSX compatibility
82
+ : Prop<T[K]>;
82
83
  };
83
84
 
84
85
  /** Base HtmlElement configuration - core CxJS properties for extension by widgets */