cx 26.9.2 → 26.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/widgets/form/Field.js +2 -2
- package/build/widgets/form/LabeledContainer.js +1 -1
- package/build/widgets/overlay/Overlay.d.ts.map +1 -1
- package/build/widgets/overlay/Overlay.js +6 -2
- package/dist/manifest.js +846 -846
- package/dist/widgets.js +9 -5
- package/package.json +1 -1
- package/src/data/index.ts +31 -31
- package/src/ui/Cx.tsx +505 -505
- package/src/widgets/form/Field.spec.tsx +50 -0
- package/src/widgets/form/Field.tsx +2 -2
- package/src/widgets/form/LabeledContainer.ts +1 -1
- package/src/widgets/index.ts +41 -41
- package/src/widgets/overlay/Overlay.tsx +6 -2
- package/src/widgets/overlay/Window.spec.tsx +59 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createModel } from "../../data/createAccessorModelProxy";
|
|
2
|
+
import { Store } from "../../data/Store";
|
|
3
|
+
import { createTestRenderer } from "../../util/test/createTestRenderer";
|
|
4
|
+
import { TextField } from "./TextField";
|
|
5
|
+
import { LabeledContainer } from "./LabeledContainer";
|
|
6
|
+
import assert from "assert";
|
|
7
|
+
|
|
8
|
+
interface Model {
|
|
9
|
+
name: string;
|
|
10
|
+
caption: string;
|
|
11
|
+
hint: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function collectText(node: any): string {
|
|
15
|
+
if (node == null) return "";
|
|
16
|
+
if (typeof node === "string") return node;
|
|
17
|
+
if (Array.isArray(node)) return node.map(collectText).join("");
|
|
18
|
+
return collectText(node.children);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("Field", () => {
|
|
22
|
+
const m = createModel<Model>();
|
|
23
|
+
|
|
24
|
+
it("accepts an accessor chain as label", async () => {
|
|
25
|
+
let store = new Store({ data: { caption: "Full name" } });
|
|
26
|
+
let component = await createTestRenderer(store, <TextField value={m.name} label={m.caption} />);
|
|
27
|
+
assert.ok(collectText(component.toJSON()).includes("Full name"));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("accepts an accessor chain as help", async () => {
|
|
31
|
+
let store = new Store({ data: { hint: "As on your passport" } });
|
|
32
|
+
let component = await createTestRenderer(store, <TextField value={m.name} help={m.hint} />);
|
|
33
|
+
assert.ok(collectText(component.toJSON()).includes("As on your passport"));
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("LabeledContainer", () => {
|
|
38
|
+
const m = createModel<Model>();
|
|
39
|
+
|
|
40
|
+
it("accepts an accessor chain as label", async () => {
|
|
41
|
+
let store = new Store({ data: { caption: "Contact" } });
|
|
42
|
+
let component = await createTestRenderer(
|
|
43
|
+
store,
|
|
44
|
+
<LabeledContainer label={m.caption}>
|
|
45
|
+
<TextField value={m.name} />
|
|
46
|
+
</LabeledContainer>,
|
|
47
|
+
);
|
|
48
|
+
assert.ok(collectText(component.toJSON()).includes("Contact"));
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -252,7 +252,7 @@ export class Field<
|
|
|
252
252
|
if (this.help != null) {
|
|
253
253
|
let helpConfig: any = {};
|
|
254
254
|
|
|
255
|
-
if ((this.help as any).isComponentType) helpConfig = this.help;
|
|
255
|
+
if ((this.help as any).isComponentType === true) helpConfig = this.help;
|
|
256
256
|
else if (isSelector(this.help)) helpConfig.text = this.help;
|
|
257
257
|
else Object.assign(helpConfig, this.help);
|
|
258
258
|
|
|
@@ -269,7 +269,7 @@ export class Field<
|
|
|
269
269
|
class: this.labelClass,
|
|
270
270
|
};
|
|
271
271
|
|
|
272
|
-
if ((this.label as any).isComponentType) labelConfig = this.label;
|
|
272
|
+
if ((this.label as any).isComponentType === true) labelConfig = this.label;
|
|
273
273
|
else if (isSelector(this.label)) labelConfig.text = this.label;
|
|
274
274
|
else Object.assign(labelConfig, this.label);
|
|
275
275
|
|
|
@@ -43,7 +43,7 @@ export class LabeledContainer extends FieldGroup<LabeledContainerConfig> {
|
|
|
43
43
|
required: true,
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
if ((this.label as any).isComponentType) labelConfig = this.label as Record<string, unknown>;
|
|
46
|
+
if ((this.label as any).isComponentType === true) labelConfig = this.label as Record<string, unknown>;
|
|
47
47
|
else if (isSelector(this.label)) labelConfig.text = this.label;
|
|
48
48
|
else Object.assign(labelConfig, this.label);
|
|
49
49
|
|
package/src/widgets/index.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
export { Widget } from "../ui/Widget";
|
|
2
|
-
export { Text } from "../ui/Text";
|
|
3
|
-
export { StaticText } from "../ui/StaticText";
|
|
4
|
-
export { PureContainer } from "../ui/PureContainer";
|
|
5
|
-
export { IsolatedScope } from "../ui/IsolatedScope";
|
|
6
|
-
export { DetachedScope } from "../ui/DetachedScope";
|
|
7
|
-
export { Restate, PrivateStore } from "../ui/Restate";
|
|
8
|
-
export { DataProxy } from "../ui/DataProxy";
|
|
9
|
-
export { Content } from "../ui/layout/Content";
|
|
10
|
-
export { ContentPlaceholder, ContentPlaceholderScope } from "../ui/layout/ContentPlaceholder";
|
|
11
|
-
export { LabelsTopLayout, LabelsTopLayoutCell } from "../ui/layout/LabelsTopLayout";
|
|
12
|
-
export { LabelsLeftLayout } from "../ui/layout/LabelsLeftLayout";
|
|
13
|
-
export { ContentResolver } from "../ui/ContentResolver";
|
|
14
|
-
export { Rescope } from "../ui/Rescope";
|
|
15
|
-
export { Repeater } from "../ui/Repeater";
|
|
16
|
-
|
|
17
|
-
export * from "./cx";
|
|
18
|
-
export * from "./HtmlElement";
|
|
19
|
-
export * from "./Button";
|
|
20
|
-
export * from "./DocumentTitle";
|
|
21
|
-
export * from "./List";
|
|
22
|
-
export * from "./Sandbox";
|
|
23
|
-
export * from "./CxCredit";
|
|
24
|
-
export * from "./Heading";
|
|
25
|
-
export * from "./Section";
|
|
26
|
-
export * from "./FlexBox";
|
|
27
|
-
export * from "./Icon";
|
|
28
|
-
export * from "./ProgressBar";
|
|
29
|
-
export * from "./Resizer";
|
|
30
|
-
export * from "./HighlightedSearchText";
|
|
31
|
-
export * from "./autoFocus";
|
|
32
|
-
export * from "./ReactElementWrapper";
|
|
33
|
-
|
|
34
|
-
export * from "./icons/index";
|
|
35
|
-
export * from "./overlay/index";
|
|
36
|
-
export * from "./nav/index";
|
|
37
|
-
export * from "./form/index";
|
|
38
|
-
export * from "./grid/index";
|
|
39
|
-
export * from "./drag-drop/index";
|
|
40
|
-
|
|
41
|
-
export * from "./enableAllInternalDependencies";
|
|
1
|
+
export { Widget } from "../ui/Widget";
|
|
2
|
+
export { Text } from "../ui/Text";
|
|
3
|
+
export { StaticText } from "../ui/StaticText";
|
|
4
|
+
export { PureContainer } from "../ui/PureContainer";
|
|
5
|
+
export { IsolatedScope } from "../ui/IsolatedScope";
|
|
6
|
+
export { DetachedScope } from "../ui/DetachedScope";
|
|
7
|
+
export { Restate, PrivateStore } from "../ui/Restate";
|
|
8
|
+
export { DataProxy } from "../ui/DataProxy";
|
|
9
|
+
export { Content } from "../ui/layout/Content";
|
|
10
|
+
export { ContentPlaceholder, ContentPlaceholderScope } from "../ui/layout/ContentPlaceholder";
|
|
11
|
+
export { LabelsTopLayout, LabelsTopLayoutCell } from "../ui/layout/LabelsTopLayout";
|
|
12
|
+
export { LabelsLeftLayout } from "../ui/layout/LabelsLeftLayout";
|
|
13
|
+
export { ContentResolver } from "../ui/ContentResolver";
|
|
14
|
+
export { Rescope } from "../ui/Rescope";
|
|
15
|
+
export { Repeater } from "../ui/Repeater";
|
|
16
|
+
|
|
17
|
+
export * from "./cx";
|
|
18
|
+
export * from "./HtmlElement";
|
|
19
|
+
export * from "./Button";
|
|
20
|
+
export * from "./DocumentTitle";
|
|
21
|
+
export * from "./List";
|
|
22
|
+
export * from "./Sandbox";
|
|
23
|
+
export * from "./CxCredit";
|
|
24
|
+
export * from "./Heading";
|
|
25
|
+
export * from "./Section";
|
|
26
|
+
export * from "./FlexBox";
|
|
27
|
+
export * from "./Icon";
|
|
28
|
+
export * from "./ProgressBar";
|
|
29
|
+
export * from "./Resizer";
|
|
30
|
+
export * from "./HighlightedSearchText";
|
|
31
|
+
export * from "./autoFocus";
|
|
32
|
+
export * from "./ReactElementWrapper";
|
|
33
|
+
|
|
34
|
+
export * from "./icons/index";
|
|
35
|
+
export * from "./overlay/index";
|
|
36
|
+
export * from "./nav/index";
|
|
37
|
+
export * from "./form/index";
|
|
38
|
+
export * from "./grid/index";
|
|
39
|
+
export * from "./drag-drop/index";
|
|
40
|
+
|
|
41
|
+
export * from "./enableAllInternalDependencies";
|
|
@@ -240,10 +240,14 @@ export class OverlayBase<
|
|
|
240
240
|
} else if (context.options.dismiss) instance.dismiss = context.options.dismiss;
|
|
241
241
|
|
|
242
242
|
if (instance.dismiss) {
|
|
243
|
-
|
|
243
|
+
let parentOptions = {
|
|
244
244
|
...context.parentOptions,
|
|
245
245
|
dismiss: instance.dismiss,
|
|
246
|
-
}
|
|
246
|
+
};
|
|
247
|
+
context.push("parentOptions", parentOptions);
|
|
248
|
+
// The overlay's own instance captured parentOptions before this point, so
|
|
249
|
+
// a controller attached to the overlay would not see its own dismiss.
|
|
250
|
+
instance.parentOptions = parentOptions;
|
|
247
251
|
}
|
|
248
252
|
|
|
249
253
|
if (instance.cache("dismiss", instance.dismiss)) instance.markShouldUpdate(context);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createModel } from "../../data/createAccessorModelProxy";
|
|
2
|
+
import { Store } from "../../data/Store";
|
|
3
|
+
import { Controller } from "../../ui/Controller";
|
|
4
|
+
import { act, createTestRenderer } from "../../util/test/createTestRenderer";
|
|
5
|
+
import { Window } from "./Window";
|
|
6
|
+
import assert from "assert";
|
|
7
|
+
|
|
8
|
+
interface Model {
|
|
9
|
+
visible: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe("Window", () => {
|
|
13
|
+
const m = createModel<Model>();
|
|
14
|
+
|
|
15
|
+
it("can be dismissed by a controller attached to the window", async () => {
|
|
16
|
+
let controller: WindowController | undefined;
|
|
17
|
+
|
|
18
|
+
class WindowController extends Controller {
|
|
19
|
+
onInit() {
|
|
20
|
+
controller = this;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let store = new Store({ data: { visible: true } });
|
|
25
|
+
await createTestRenderer(
|
|
26
|
+
store,
|
|
27
|
+
<Window visible={m.visible} inline controller={WindowController}>
|
|
28
|
+
Content
|
|
29
|
+
</Window>,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
assert.ok(controller, "controller was not initialized");
|
|
33
|
+
assert.equal(typeof controller.instance.parentOptions?.dismiss, "function");
|
|
34
|
+
await act(async () => controller!.instance.parentOptions.dismiss());
|
|
35
|
+
assert.equal(store.get(m.visible), false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("can be dismissed by a controller inside the window", async () => {
|
|
39
|
+
let controller: ContentController | undefined;
|
|
40
|
+
|
|
41
|
+
class ContentController extends Controller {
|
|
42
|
+
onInit() {
|
|
43
|
+
controller = this;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let store = new Store({ data: { visible: true } });
|
|
48
|
+
await createTestRenderer(
|
|
49
|
+
store,
|
|
50
|
+
<Window visible={m.visible} inline>
|
|
51
|
+
<div controller={ContentController}>Content</div>
|
|
52
|
+
</Window>,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
assert.ok(controller, "controller was not initialized");
|
|
56
|
+
await act(async () => controller!.instance.parentOptions.dismiss());
|
|
57
|
+
assert.equal(store.get(m.visible), false);
|
|
58
|
+
});
|
|
59
|
+
});
|