@gtkx/react 0.12.0 → 0.13.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.
- package/README.md +1 -1
- package/dist/generated/jsx.d.ts +32 -18
- package/dist/host-config.js +3 -3
- package/dist/jsx.d.ts +530 -372
- package/dist/jsx.js +401 -353
- package/dist/nodes/action-row-child.d.ts +4 -11
- package/dist/nodes/action-row-child.js +10 -66
- package/dist/nodes/action-row.js +21 -4
- package/dist/nodes/application.js +22 -3
- package/dist/nodes/autowrapped.js +13 -3
- package/dist/nodes/calendar-mark.d.ts +15 -0
- package/dist/nodes/calendar-mark.js +29 -0
- package/dist/nodes/calendar.d.ts +1 -0
- package/dist/nodes/calendar.js +70 -0
- package/dist/nodes/column-view-column.d.ts +1 -0
- package/dist/nodes/column-view-column.js +4 -0
- package/dist/nodes/column-view.js +24 -7
- package/dist/nodes/expander-row-child.d.ts +15 -0
- package/dist/nodes/expander-row-child.js +20 -0
- package/dist/nodes/expander-row.d.ts +1 -0
- package/dist/nodes/expander-row.js +54 -0
- package/dist/nodes/fixed-child.js +10 -8
- package/dist/nodes/grid-child.js +10 -8
- package/dist/nodes/index.d.ts +12 -0
- package/dist/nodes/index.js +12 -0
- package/dist/nodes/internal/list-item-renderer.d.ts +3 -0
- package/dist/nodes/internal/list-item-renderer.js +25 -9
- package/dist/nodes/internal/list-store.js +2 -2
- package/dist/nodes/internal/tree-list-item-renderer.d.ts +8 -0
- package/dist/nodes/internal/tree-list-item-renderer.js +68 -24
- package/dist/nodes/internal/tree-store.js +3 -4
- package/dist/nodes/level-bar-offset.d.ts +13 -0
- package/dist/nodes/level-bar-offset.js +35 -0
- package/dist/nodes/level-bar.d.ts +1 -0
- package/dist/nodes/level-bar.js +82 -0
- package/dist/nodes/list-view.js +14 -7
- package/dist/nodes/menu.js +4 -4
- package/dist/nodes/models/list.d.ts +2 -1
- package/dist/nodes/models/list.js +21 -12
- package/dist/nodes/models/menu.d.ts +1 -0
- package/dist/nodes/models/menu.js +24 -17
- package/dist/nodes/models/tree-list.d.ts +2 -1
- package/dist/nodes/models/tree-list.js +43 -24
- package/dist/nodes/navigation-page.d.ts +16 -0
- package/dist/nodes/navigation-page.js +58 -0
- package/dist/nodes/navigation-view.d.ts +1 -0
- package/dist/nodes/navigation-view.js +105 -0
- package/dist/nodes/notebook-page-tab.js +1 -1
- package/dist/nodes/notebook-page.js +3 -2
- package/dist/nodes/notebook.js +3 -3
- package/dist/nodes/overlay-child.js +29 -14
- package/dist/nodes/pack-child.d.ts +4 -11
- package/dist/nodes/pack-child.js +10 -66
- package/dist/nodes/pack.js +21 -4
- package/dist/nodes/popover-menu.js +15 -12
- package/dist/nodes/scale-mark.d.ts +17 -0
- package/dist/nodes/scale-mark.js +38 -0
- package/dist/nodes/scale.d.ts +1 -0
- package/dist/nodes/scale.js +70 -0
- package/dist/nodes/simple-list-view.js +3 -3
- package/dist/nodes/slot.d.ts +2 -1
- package/dist/nodes/slot.js +2 -2
- package/dist/nodes/stack-page.js +7 -7
- package/dist/nodes/stack.js +5 -5
- package/dist/nodes/toggle-group.d.ts +1 -0
- package/dist/nodes/toggle-group.js +48 -0
- package/dist/nodes/toggle.d.ts +15 -0
- package/dist/nodes/toggle.js +70 -0
- package/dist/nodes/toolbar-child.js +18 -16
- package/dist/nodes/tree-list-view.js +16 -7
- package/dist/nodes/virtual-child.d.ts +18 -0
- package/dist/nodes/virtual-child.js +62 -0
- package/dist/nodes/widget.js +22 -8
- package/dist/nodes/window.d.ts +22 -0
- package/dist/nodes/window.js +11 -2
- package/dist/render.d.ts +3 -5
- package/dist/render.js +3 -5
- package/dist/scheduler.d.ts +13 -1
- package/dist/scheduler.js +26 -6
- package/dist/types.d.ts +25 -0
- package/package.json +3 -3
package/dist/nodes/pack.js
CHANGED
|
@@ -2,6 +2,7 @@ import { PACK_INTERFACE_METHODS } from "../generated/internal.js";
|
|
|
2
2
|
import { registerNodeClass } from "../registry.js";
|
|
3
3
|
import { matchesInterface } from "./internal/utils.js";
|
|
4
4
|
import { PackChild } from "./pack-child.js";
|
|
5
|
+
import { SlotNode } from "./slot.js";
|
|
5
6
|
import { WidgetNode } from "./widget.js";
|
|
6
7
|
class PackNode extends WidgetNode {
|
|
7
8
|
static priority = 0;
|
|
@@ -13,17 +14,33 @@ class PackNode extends WidgetNode {
|
|
|
13
14
|
child.setParent(this.container);
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
18
|
+
super.appendChild(child);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`Cannot append '${child.typeName}' to 'Pack': expected x.PackStart, x.PackEnd, or Widget`);
|
|
17
22
|
}
|
|
18
|
-
insertBefore(child) {
|
|
19
|
-
|
|
23
|
+
insertBefore(child, before) {
|
|
24
|
+
if (child instanceof PackChild) {
|
|
25
|
+
child.setParent(this.container);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
29
|
+
super.insertBefore(child, before);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`Cannot insert '${child.typeName}' into 'Pack': expected x.PackStart, x.PackEnd, or Widget`);
|
|
20
33
|
}
|
|
21
34
|
removeChild(child) {
|
|
22
35
|
if (child instanceof PackChild) {
|
|
23
36
|
child.unmount();
|
|
24
37
|
return;
|
|
25
38
|
}
|
|
26
|
-
|
|
39
|
+
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
40
|
+
super.removeChild(child);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`Cannot remove '${child.typeName}' from 'Pack': expected x.PackStart, x.PackEnd, or Widget`);
|
|
27
44
|
}
|
|
28
45
|
}
|
|
29
46
|
registerNodeClass(PackNode);
|
|
@@ -24,34 +24,37 @@ class PopoverMenuNode extends WidgetNode {
|
|
|
24
24
|
this.container.setMenuModel(this.menu.getMenu());
|
|
25
25
|
}
|
|
26
26
|
appendChild(child) {
|
|
27
|
+
if (child instanceof MenuNode) {
|
|
28
|
+
this.menu.appendChild(child);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
27
31
|
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
28
32
|
super.appendChild(child);
|
|
29
33
|
return;
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
throw new Error(`Cannot append '${child.typeName}' to 'PopoverMenu': expected MenuItem`);
|
|
33
|
-
}
|
|
34
|
-
this.menu.appendChild(child);
|
|
35
|
+
throw new Error(`Cannot append '${child.typeName}' to 'PopoverMenu': expected MenuItem or Widget`);
|
|
35
36
|
}
|
|
36
37
|
insertBefore(child, before) {
|
|
38
|
+
if (child instanceof MenuNode) {
|
|
39
|
+
this.menu.insertBefore(child, before);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
37
42
|
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
38
43
|
super.insertBefore(child, before);
|
|
39
44
|
return;
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
throw new Error(`Cannot insert '${child.typeName}' to 'PopoverMenu': expected MenuItem`);
|
|
43
|
-
}
|
|
44
|
-
this.menu.insertBefore(child, before);
|
|
46
|
+
throw new Error(`Cannot insert '${child.typeName}' into 'PopoverMenu': expected MenuItem or Widget`);
|
|
45
47
|
}
|
|
46
48
|
removeChild(child) {
|
|
49
|
+
if (child instanceof MenuNode) {
|
|
50
|
+
this.menu.removeChild(child);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
47
53
|
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
48
54
|
super.removeChild(child);
|
|
49
55
|
return;
|
|
50
56
|
}
|
|
51
|
-
|
|
52
|
-
throw new Error(`Cannot remove '${child.typeName}' from 'PopoverMenu': expected MenuItem`);
|
|
53
|
-
}
|
|
54
|
-
this.menu.removeChild(child);
|
|
57
|
+
throw new Error(`Cannot remove '${child.typeName}' from 'PopoverMenu': expected MenuItem or Widget`);
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
registerNodeClass(PopoverMenuNode);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import { VirtualNode } from "./virtual.js";
|
|
3
|
+
export type ScaleMarkProps = {
|
|
4
|
+
value: number;
|
|
5
|
+
position?: Gtk.PositionType;
|
|
6
|
+
label?: string | null;
|
|
7
|
+
};
|
|
8
|
+
export declare class ScaleMarkNode extends VirtualNode<ScaleMarkProps> {
|
|
9
|
+
static priority: number;
|
|
10
|
+
private scale?;
|
|
11
|
+
private onRebuild?;
|
|
12
|
+
static matches(type: string): boolean;
|
|
13
|
+
setScale(scale: Gtk.Scale, onRebuild: () => void): void;
|
|
14
|
+
addMark(): void;
|
|
15
|
+
updateProps(oldProps: ScaleMarkProps | null, newProps: ScaleMarkProps): void;
|
|
16
|
+
unmount(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import { registerNodeClass } from "../registry.js";
|
|
3
|
+
import { VirtualNode } from "./virtual.js";
|
|
4
|
+
export class ScaleMarkNode extends VirtualNode {
|
|
5
|
+
static priority = 1;
|
|
6
|
+
scale;
|
|
7
|
+
onRebuild;
|
|
8
|
+
static matches(type) {
|
|
9
|
+
return type === "ScaleMark";
|
|
10
|
+
}
|
|
11
|
+
setScale(scale, onRebuild) {
|
|
12
|
+
this.scale = scale;
|
|
13
|
+
this.onRebuild = onRebuild;
|
|
14
|
+
}
|
|
15
|
+
addMark() {
|
|
16
|
+
if (!this.scale)
|
|
17
|
+
return;
|
|
18
|
+
const { value, position, label } = this.props;
|
|
19
|
+
this.scale.addMark(value, position ?? Gtk.PositionType.BOTTOM, label);
|
|
20
|
+
}
|
|
21
|
+
updateProps(oldProps, newProps) {
|
|
22
|
+
super.updateProps(oldProps, newProps);
|
|
23
|
+
if (oldProps && this.scale) {
|
|
24
|
+
const changed = oldProps.value !== newProps.value ||
|
|
25
|
+
oldProps.position !== newProps.position ||
|
|
26
|
+
oldProps.label !== newProps.label;
|
|
27
|
+
if (changed) {
|
|
28
|
+
this.onRebuild?.();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
unmount() {
|
|
33
|
+
this.scale = undefined;
|
|
34
|
+
this.onRebuild = undefined;
|
|
35
|
+
super.unmount();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
registerNodeClass(ScaleMarkNode);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import { registerNodeClass } from "../registry.js";
|
|
3
|
+
import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
|
|
4
|
+
import { isContainerType } from "./internal/utils.js";
|
|
5
|
+
import { ScaleMarkNode } from "./scale-mark.js";
|
|
6
|
+
import { SlotNode } from "./slot.js";
|
|
7
|
+
import { WidgetNode } from "./widget.js";
|
|
8
|
+
class ScaleNode extends WidgetNode {
|
|
9
|
+
static priority = 1;
|
|
10
|
+
markChildren = [];
|
|
11
|
+
static matches(_type, containerOrClass) {
|
|
12
|
+
return isContainerType(Gtk.Scale, containerOrClass);
|
|
13
|
+
}
|
|
14
|
+
appendChild(child) {
|
|
15
|
+
if (child instanceof ScaleMarkNode) {
|
|
16
|
+
child.setScale(this.container, () => this.scheduleRebuildAllMarks());
|
|
17
|
+
this.markChildren.push(child);
|
|
18
|
+
scheduleAfterCommit(() => child.addMark());
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
22
|
+
super.appendChild(child);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`Cannot append '${child.typeName}' to 'Scale': expected x.ScaleMark or Widget`);
|
|
26
|
+
}
|
|
27
|
+
insertBefore(child, before) {
|
|
28
|
+
if (child instanceof ScaleMarkNode) {
|
|
29
|
+
child.setScale(this.container, () => this.scheduleRebuildAllMarks());
|
|
30
|
+
const beforeIndex = this.markChildren.indexOf(before);
|
|
31
|
+
if (beforeIndex >= 0) {
|
|
32
|
+
this.markChildren.splice(beforeIndex, 0, child);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.markChildren.push(child);
|
|
36
|
+
}
|
|
37
|
+
this.scheduleRebuildAllMarks();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
41
|
+
super.insertBefore(child, before);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`Cannot insert '${child.typeName}' into 'Scale': expected x.ScaleMark or Widget`);
|
|
45
|
+
}
|
|
46
|
+
removeChild(child) {
|
|
47
|
+
if (child instanceof ScaleMarkNode) {
|
|
48
|
+
const index = this.markChildren.indexOf(child);
|
|
49
|
+
if (index >= 0) {
|
|
50
|
+
this.markChildren.splice(index, 1);
|
|
51
|
+
}
|
|
52
|
+
this.scheduleRebuildAllMarks(CommitPriority.HIGH);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
56
|
+
super.removeChild(child);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`Cannot remove '${child.typeName}' from 'Scale': expected x.ScaleMark or Widget`);
|
|
60
|
+
}
|
|
61
|
+
scheduleRebuildAllMarks(priority = CommitPriority.NORMAL) {
|
|
62
|
+
scheduleAfterCommit(() => {
|
|
63
|
+
this.container.clearMarks();
|
|
64
|
+
for (const mark of this.markChildren) {
|
|
65
|
+
mark.addMark();
|
|
66
|
+
}
|
|
67
|
+
}, priority);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
registerNodeClass(ScaleNode);
|
|
@@ -40,7 +40,7 @@ class SimpleListViewNode extends WidgetNode {
|
|
|
40
40
|
}
|
|
41
41
|
appendChild(child) {
|
|
42
42
|
if (!(child instanceof SimpleListItemNode)) {
|
|
43
|
-
throw new Error(`Cannot append '${child.typeName}' to '
|
|
43
|
+
throw new Error(`Cannot append '${child.typeName}' to 'DropDown': expected x.SimpleListItem`);
|
|
44
44
|
}
|
|
45
45
|
const { id, value } = child.props;
|
|
46
46
|
if (!id || value === undefined) {
|
|
@@ -51,7 +51,7 @@ class SimpleListViewNode extends WidgetNode {
|
|
|
51
51
|
}
|
|
52
52
|
insertBefore(child, before) {
|
|
53
53
|
if (!(child instanceof SimpleListItemNode) || !(before instanceof SimpleListItemNode)) {
|
|
54
|
-
throw new Error(`Cannot insert '${child.typeName}'
|
|
54
|
+
throw new Error(`Cannot insert '${child.typeName}' into 'DropDown': expected x.SimpleListItem`);
|
|
55
55
|
}
|
|
56
56
|
const { id, value } = child.props;
|
|
57
57
|
const beforeId = before.props.id;
|
|
@@ -63,7 +63,7 @@ class SimpleListViewNode extends WidgetNode {
|
|
|
63
63
|
}
|
|
64
64
|
removeChild(child) {
|
|
65
65
|
if (!(child instanceof SimpleListItemNode)) {
|
|
66
|
-
throw new Error(`Cannot remove '${child.typeName}' from '
|
|
66
|
+
throw new Error(`Cannot remove '${child.typeName}' from 'DropDown': expected x.SimpleListItem`);
|
|
67
67
|
}
|
|
68
68
|
const { id } = child.props;
|
|
69
69
|
if (!id) {
|
package/dist/nodes/slot.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
2
|
import type { SlotProps } from "../jsx.js";
|
|
3
3
|
import type { Node } from "../node.js";
|
|
4
|
+
import type { Props } from "../types.js";
|
|
4
5
|
import { VirtualNode } from "./virtual.js";
|
|
5
6
|
type SlotNodeProps = Omit<SlotProps, "children">;
|
|
6
|
-
export declare class SlotNode<P extends
|
|
7
|
+
export declare class SlotNode<P extends Props = SlotNodeProps> extends VirtualNode<P> {
|
|
7
8
|
static priority: number;
|
|
8
9
|
static matches(type: string): boolean;
|
|
9
10
|
parent?: Gtk.Widget;
|
package/dist/nodes/slot.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isObjectEqual } from "@gtkx/ffi";
|
|
2
2
|
import { toCamelCase } from "@gtkx/gir";
|
|
3
3
|
import { registerNodeClass } from "../registry.js";
|
|
4
|
-
import { scheduleAfterCommit } from "../scheduler.js";
|
|
4
|
+
import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
|
|
5
5
|
import { resolvePropMeta } from "./internal/utils.js";
|
|
6
6
|
import { VirtualNode } from "./virtual.js";
|
|
7
7
|
import { WidgetNode } from "./widget.js";
|
|
@@ -64,7 +64,7 @@ export class SlotNode extends VirtualNode {
|
|
|
64
64
|
if (this.parent) {
|
|
65
65
|
this.onChildChange(oldChild ?? null);
|
|
66
66
|
}
|
|
67
|
-
});
|
|
67
|
+
}, CommitPriority.HIGH);
|
|
68
68
|
}
|
|
69
69
|
onChildChange(oldChild) {
|
|
70
70
|
const parent = this.getParent();
|
package/dist/nodes/stack-page.js
CHANGED
|
@@ -38,13 +38,13 @@ class StackPageNode extends SlotNode {
|
|
|
38
38
|
let page;
|
|
39
39
|
if (parent instanceof Adw.ViewStack) {
|
|
40
40
|
if (this.props.title && this.props.iconName) {
|
|
41
|
-
page = parent.addTitledWithIcon(child, this.props.title, this.props.iconName, this.props.
|
|
41
|
+
page = parent.addTitledWithIcon(child, this.props.title, this.props.iconName, this.props.id);
|
|
42
42
|
}
|
|
43
43
|
else if (this.props.title) {
|
|
44
|
-
page = parent.addTitled(child, this.props.title, this.props.
|
|
44
|
+
page = parent.addTitled(child, this.props.title, this.props.id);
|
|
45
45
|
}
|
|
46
|
-
else if (this.props.
|
|
47
|
-
page = parent.addNamed(child, this.props.
|
|
46
|
+
else if (this.props.id) {
|
|
47
|
+
page = parent.addNamed(child, this.props.id);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
page = parent.add(child);
|
|
@@ -52,10 +52,10 @@ class StackPageNode extends SlotNode {
|
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
54
|
if (this.props.title) {
|
|
55
|
-
page = parent.addTitled(child, this.props.title, this.props.
|
|
55
|
+
page = parent.addTitled(child, this.props.title, this.props.id);
|
|
56
56
|
}
|
|
57
|
-
else if (this.props.
|
|
58
|
-
page = parent.addNamed(child, this.props.
|
|
57
|
+
else if (this.props.id) {
|
|
58
|
+
page = parent.addNamed(child, this.props.id);
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
61
|
page = parent.addChild(child);
|
package/dist/nodes/stack.js
CHANGED
|
@@ -3,18 +3,18 @@ import { registerNodeClass } from "../registry.js";
|
|
|
3
3
|
import { scheduleAfterCommit } from "../scheduler.js";
|
|
4
4
|
import { filterProps, matchesAnyClass } from "./internal/utils.js";
|
|
5
5
|
import { WidgetNode } from "./widget.js";
|
|
6
|
-
const PROPS = ["
|
|
6
|
+
const PROPS = ["page"];
|
|
7
7
|
class StackNode extends WidgetNode {
|
|
8
8
|
static priority = 1;
|
|
9
9
|
static matches(_type, containerOrClass) {
|
|
10
10
|
return matchesAnyClass(STACK_CLASSES, containerOrClass);
|
|
11
11
|
}
|
|
12
12
|
updateProps(oldProps, newProps) {
|
|
13
|
-
if (newProps.
|
|
14
|
-
const
|
|
13
|
+
if (newProps.page && this.container.getVisibleChildName() !== newProps.page) {
|
|
14
|
+
const page = newProps.page;
|
|
15
15
|
scheduleAfterCommit(() => {
|
|
16
|
-
if (this.container.getChildByName(
|
|
17
|
-
this.container.setVisibleChildName(
|
|
16
|
+
if (this.container.getChildByName(page)) {
|
|
17
|
+
this.container.setVisibleChildName(page);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as Adw from "@gtkx/ffi/adw";
|
|
2
|
+
import { registerNodeClass } from "../registry.js";
|
|
3
|
+
import { isContainerType } from "./internal/utils.js";
|
|
4
|
+
import { SlotNode } from "./slot.js";
|
|
5
|
+
import { ToggleNode } from "./toggle.js";
|
|
6
|
+
import { WidgetNode } from "./widget.js";
|
|
7
|
+
class ToggleGroupNode extends WidgetNode {
|
|
8
|
+
static priority = 1;
|
|
9
|
+
static matches(_type, containerOrClass) {
|
|
10
|
+
return isContainerType(Adw.ToggleGroup, containerOrClass);
|
|
11
|
+
}
|
|
12
|
+
appendChild(child) {
|
|
13
|
+
if (child instanceof ToggleNode) {
|
|
14
|
+
child.setToggleGroup(this.container);
|
|
15
|
+
child.addToGroup();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
19
|
+
super.appendChild(child);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
throw new Error(`Cannot append '${child.typeName}' to 'ToggleGroup': expected x.Toggle or Widget`);
|
|
23
|
+
}
|
|
24
|
+
insertBefore(child, before) {
|
|
25
|
+
if (child instanceof ToggleNode) {
|
|
26
|
+
child.setToggleGroup(this.container);
|
|
27
|
+
child.addToGroup();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
31
|
+
super.insertBefore(child, before);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`Cannot insert '${child.typeName}' into 'ToggleGroup': expected x.Toggle or Widget`);
|
|
35
|
+
}
|
|
36
|
+
removeChild(child) {
|
|
37
|
+
if (child instanceof ToggleNode) {
|
|
38
|
+
child.removeFromGroup();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (child instanceof SlotNode || child instanceof WidgetNode) {
|
|
42
|
+
super.removeChild(child);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Cannot remove '${child.typeName}' from 'ToggleGroup': expected x.Toggle or Widget`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
registerNodeClass(ToggleGroupNode);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as Adw from "@gtkx/ffi/adw";
|
|
2
|
+
import type { ToggleProps } from "../jsx.js";
|
|
3
|
+
import { VirtualNode } from "./virtual.js";
|
|
4
|
+
export declare class ToggleNode extends VirtualNode<ToggleProps> {
|
|
5
|
+
static priority: number;
|
|
6
|
+
private toggleGroup?;
|
|
7
|
+
private toggle?;
|
|
8
|
+
static matches(type: string): boolean;
|
|
9
|
+
setToggleGroup(toggleGroup: Adw.ToggleGroup): void;
|
|
10
|
+
addToGroup(): void;
|
|
11
|
+
removeFromGroup(): void;
|
|
12
|
+
updateProps(oldProps: ToggleProps | null, newProps: ToggleProps): void;
|
|
13
|
+
unmount(): void;
|
|
14
|
+
private applyProps;
|
|
15
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as Adw from "@gtkx/ffi/adw";
|
|
2
|
+
import { registerNodeClass } from "../registry.js";
|
|
3
|
+
import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
|
|
4
|
+
import { VirtualNode } from "./virtual.js";
|
|
5
|
+
export class ToggleNode extends VirtualNode {
|
|
6
|
+
static priority = 1;
|
|
7
|
+
toggleGroup;
|
|
8
|
+
toggle;
|
|
9
|
+
static matches(type) {
|
|
10
|
+
return type === "Toggle";
|
|
11
|
+
}
|
|
12
|
+
setToggleGroup(toggleGroup) {
|
|
13
|
+
this.toggleGroup = toggleGroup;
|
|
14
|
+
}
|
|
15
|
+
addToGroup() {
|
|
16
|
+
if (!this.toggleGroup || this.toggle)
|
|
17
|
+
return;
|
|
18
|
+
const toggleGroup = this.toggleGroup;
|
|
19
|
+
this.toggle = new Adw.Toggle();
|
|
20
|
+
scheduleAfterCommit(() => {
|
|
21
|
+
if (this.toggle) {
|
|
22
|
+
this.applyProps(this.props);
|
|
23
|
+
toggleGroup.add(this.toggle);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
removeFromGroup() {
|
|
28
|
+
if (!this.toggleGroup || !this.toggle)
|
|
29
|
+
return;
|
|
30
|
+
const toggleGroup = this.toggleGroup;
|
|
31
|
+
const toggle = this.toggle;
|
|
32
|
+
this.toggle = undefined;
|
|
33
|
+
scheduleAfterCommit(() => {
|
|
34
|
+
toggleGroup.remove(toggle);
|
|
35
|
+
}, CommitPriority.HIGH);
|
|
36
|
+
}
|
|
37
|
+
updateProps(oldProps, newProps) {
|
|
38
|
+
super.updateProps(oldProps, newProps);
|
|
39
|
+
if (oldProps && this.toggle) {
|
|
40
|
+
this.applyProps(newProps);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
unmount() {
|
|
44
|
+
this.removeFromGroup();
|
|
45
|
+
super.unmount();
|
|
46
|
+
}
|
|
47
|
+
applyProps(props) {
|
|
48
|
+
if (!this.toggle)
|
|
49
|
+
return;
|
|
50
|
+
if (props.id !== undefined && props.id !== this.toggle.getName()) {
|
|
51
|
+
this.toggle.setName(props.id);
|
|
52
|
+
}
|
|
53
|
+
if (props.label !== undefined && props.label !== this.toggle.getLabel()) {
|
|
54
|
+
this.toggle.setLabel(props.label);
|
|
55
|
+
}
|
|
56
|
+
if (props.iconName !== undefined && props.iconName !== this.toggle.getIconName()) {
|
|
57
|
+
this.toggle.setIconName(props.iconName);
|
|
58
|
+
}
|
|
59
|
+
if (props.tooltip !== undefined && props.tooltip !== this.toggle.getTooltip()) {
|
|
60
|
+
this.toggle.setTooltip(props.tooltip);
|
|
61
|
+
}
|
|
62
|
+
if (props.enabled !== undefined && props.enabled !== this.toggle.getEnabled()) {
|
|
63
|
+
this.toggle.setEnabled(props.enabled);
|
|
64
|
+
}
|
|
65
|
+
if (props.useUnderline !== undefined && props.useUnderline !== this.toggle.getUseUnderline()) {
|
|
66
|
+
this.toggle.setUseUnderline(props.useUnderline);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
registerNodeClass(ToggleNode);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isObjectEqual } from "@gtkx/ffi";
|
|
1
|
+
import { batch, isObjectEqual } from "@gtkx/ffi";
|
|
2
2
|
import { registerNodeClass } from "../registry.js";
|
|
3
3
|
import { SlotNode } from "./slot.js";
|
|
4
4
|
class ToolbarChildNode extends SlotNode {
|
|
5
5
|
static priority = 1;
|
|
6
6
|
static matches(type) {
|
|
7
|
-
return type === "
|
|
7
|
+
return type === "ToolbarTop" || type === "ToolbarBottom";
|
|
8
8
|
}
|
|
9
9
|
getToolbar() {
|
|
10
10
|
if (!this.parent) {
|
|
@@ -13,25 +13,27 @@ class ToolbarChildNode extends SlotNode {
|
|
|
13
13
|
return this.parent;
|
|
14
14
|
}
|
|
15
15
|
getPosition() {
|
|
16
|
-
return this.typeName === "
|
|
16
|
+
return this.typeName === "ToolbarTop" ? "top" : "bottom";
|
|
17
17
|
}
|
|
18
18
|
onChildChange(oldChild) {
|
|
19
19
|
const toolbar = this.getToolbar();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
toolbar
|
|
20
|
+
batch(() => {
|
|
21
|
+
if (oldChild) {
|
|
22
|
+
const parent = oldChild.getParent();
|
|
23
|
+
if (parent && isObjectEqual(parent, toolbar)) {
|
|
24
|
+
toolbar.remove(oldChild);
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
if (this.child) {
|
|
28
|
+
const position = this.getPosition();
|
|
29
|
+
if (position === "top") {
|
|
30
|
+
toolbar.addTopBar(this.child);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
toolbar.addBottomBar(this.child);
|
|
34
|
+
}
|
|
33
35
|
}
|
|
34
|
-
}
|
|
36
|
+
});
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
registerNodeClass(ToolbarChildNode);
|
|
@@ -5,7 +5,8 @@ import { filterProps } from "./internal/utils.js";
|
|
|
5
5
|
import { TreeList } from "./models/tree-list.js";
|
|
6
6
|
import { TreeListItemNode } from "./tree-list-item.js";
|
|
7
7
|
import { WidgetNode } from "./widget.js";
|
|
8
|
-
const
|
|
8
|
+
const RENDERER_PROP_NAMES = ["renderItem", "estimatedItemHeight"];
|
|
9
|
+
const PROP_NAMES = [...RENDERER_PROP_NAMES, "autoexpand", "selectionMode", "selected", "onSelectionChanged"];
|
|
9
10
|
class TreeListViewNode extends WidgetNode {
|
|
10
11
|
static priority = 1;
|
|
11
12
|
itemRenderer;
|
|
@@ -19,7 +20,12 @@ class TreeListViewNode extends WidgetNode {
|
|
|
19
20
|
constructor(typeName, props, container, rootContainer) {
|
|
20
21
|
const listView = container ?? new Gtk.ListView();
|
|
21
22
|
super(typeName, props, listView, rootContainer);
|
|
22
|
-
this.treeList = new TreeList(
|
|
23
|
+
this.treeList = new TreeList({
|
|
24
|
+
autoexpand: props.autoexpand,
|
|
25
|
+
selectionMode: props.selectionMode,
|
|
26
|
+
selected: props.selected,
|
|
27
|
+
onSelectionChanged: props.onSelectionChanged,
|
|
28
|
+
});
|
|
23
29
|
this.itemRenderer = new TreeListItemRenderer();
|
|
24
30
|
this.itemRenderer.setStore(this.treeList.getStore());
|
|
25
31
|
this.container.setFactory(this.itemRenderer.getFactory());
|
|
@@ -30,19 +36,19 @@ class TreeListViewNode extends WidgetNode {
|
|
|
30
36
|
}
|
|
31
37
|
appendChild(child) {
|
|
32
38
|
if (!(child instanceof TreeListItemNode)) {
|
|
33
|
-
throw new Error(`Cannot append '${child.typeName}' to 'TreeListView': expected TreeListItem`);
|
|
39
|
+
throw new Error(`Cannot append '${child.typeName}' to 'TreeListView': expected x.TreeListItem`);
|
|
34
40
|
}
|
|
35
41
|
this.treeList.appendChild(child);
|
|
36
42
|
}
|
|
37
43
|
insertBefore(child, before) {
|
|
38
44
|
if (!(child instanceof TreeListItemNode) || !(before instanceof TreeListItemNode)) {
|
|
39
|
-
throw new Error(`Cannot insert '${child.typeName}'
|
|
45
|
+
throw new Error(`Cannot insert '${child.typeName}' into 'TreeListView': expected x.TreeListItem`);
|
|
40
46
|
}
|
|
41
47
|
this.treeList.insertBefore(child, before);
|
|
42
48
|
}
|
|
43
49
|
removeChild(child) {
|
|
44
50
|
if (!(child instanceof TreeListItemNode)) {
|
|
45
|
-
throw new Error(`Cannot remove '${child.typeName}' from 'TreeListView': expected TreeListItem`);
|
|
51
|
+
throw new Error(`Cannot remove '${child.typeName}' from 'TreeListView': expected x.TreeListItem`);
|
|
46
52
|
}
|
|
47
53
|
this.treeList.removeChild(child);
|
|
48
54
|
}
|
|
@@ -50,8 +56,11 @@ class TreeListViewNode extends WidgetNode {
|
|
|
50
56
|
if (!oldProps || oldProps.renderItem !== newProps.renderItem) {
|
|
51
57
|
this.itemRenderer.setRenderFn(newProps.renderItem);
|
|
52
58
|
}
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
if (!oldProps || oldProps.estimatedItemHeight !== newProps.estimatedItemHeight) {
|
|
60
|
+
this.itemRenderer.setEstimatedItemHeight(newProps.estimatedItemHeight);
|
|
61
|
+
}
|
|
62
|
+
this.treeList.updateProps(oldProps ? filterProps(oldProps, RENDERER_PROP_NAMES) : null, filterProps(newProps, RENDERER_PROP_NAMES));
|
|
63
|
+
super.updateProps(oldProps ? filterProps(oldProps, PROP_NAMES) : null, filterProps(newProps, PROP_NAMES));
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
registerNodeClass(TreeListViewNode);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import type { Node } from "../node.js";
|
|
3
|
+
import { VirtualNode } from "./virtual.js";
|
|
4
|
+
type ChildParentWidget = Gtk.Widget & {
|
|
5
|
+
remove(child: Gtk.Widget): void;
|
|
6
|
+
};
|
|
7
|
+
export declare abstract class VirtualChildNode<P extends ChildParentWidget = ChildParentWidget> extends VirtualNode {
|
|
8
|
+
protected parent?: P;
|
|
9
|
+
protected children: Gtk.Widget[];
|
|
10
|
+
setParent(newParent?: P): void;
|
|
11
|
+
protected abstract getPositionLabel(): string;
|
|
12
|
+
protected abstract attachChild(parent: P, widget: Gtk.Widget): void;
|
|
13
|
+
unmount(): void;
|
|
14
|
+
appendChild(child: Node): void;
|
|
15
|
+
insertBefore(child: Node): void;
|
|
16
|
+
removeChild(child: Node): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|