@gtkx/react 0.9.4 → 0.10.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 +55 -67
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +8 -8
- package/dist/factory.d.ts +3 -5
- package/dist/factory.js +18 -71
- package/dist/fiber-root.d.ts +1 -1
- package/dist/fiber-root.js +1 -2
- package/dist/generated/internal.d.ts +3 -6
- package/dist/generated/internal.js +10386 -13577
- package/dist/generated/jsx.d.ts +914 -808
- package/dist/generated/jsx.js +123 -358
- package/dist/generated/registry.d.ts +4 -0
- package/dist/generated/registry.js +13 -0
- package/dist/host-config.d.ts +7 -4
- package/dist/host-config.js +53 -18
- package/dist/index.d.ts +2 -22
- package/dist/index.js +2 -40
- package/dist/jsx.d.ts +719 -0
- package/dist/jsx.js +392 -0
- package/dist/node.d.ts +15 -32
- package/dist/node.js +20 -240
- package/dist/nodes/action-row-child.d.ts +21 -0
- package/dist/nodes/action-row-child.js +69 -0
- package/dist/nodes/action-row.js +33 -0
- package/dist/nodes/application.d.ts +1 -0
- package/dist/nodes/application.js +38 -0
- package/dist/nodes/autowrapped.d.ts +1 -0
- package/dist/nodes/autowrapped.js +109 -0
- package/dist/nodes/column-view-column.d.ts +16 -0
- package/dist/nodes/column-view-column.js +54 -0
- package/dist/nodes/column-view.d.ts +0 -59
- package/dist/nodes/column-view.js +107 -226
- package/dist/nodes/fixed-child.d.ts +1 -0
- package/dist/nodes/fixed-child.js +45 -0
- package/dist/nodes/grid-child.d.ts +1 -0
- package/dist/nodes/grid-child.js +54 -0
- package/dist/nodes/index.d.ts +34 -0
- package/dist/nodes/index.js +34 -0
- package/dist/nodes/internal/list-item-renderer.d.ts +18 -0
- package/dist/nodes/internal/list-item-renderer.js +67 -0
- package/dist/nodes/internal/list-store.d.ts +16 -0
- package/dist/nodes/internal/list-store.js +69 -0
- package/dist/nodes/internal/predicates.d.ts +26 -0
- package/dist/nodes/internal/predicates.js +36 -0
- package/dist/nodes/internal/signal-store.d.ts +9 -0
- package/dist/nodes/internal/signal-store.js +54 -0
- package/dist/nodes/internal/simple-list-store.d.ts +14 -0
- package/dist/nodes/internal/simple-list-store.js +60 -0
- package/dist/nodes/internal/tree-list-item-renderer.d.ts +18 -0
- package/dist/nodes/internal/tree-list-item-renderer.js +90 -0
- package/dist/nodes/internal/tree-store.d.ts +28 -0
- package/dist/nodes/internal/tree-store.js +153 -0
- package/dist/nodes/internal/utils.d.ts +3 -0
- package/dist/nodes/internal/utils.js +20 -0
- package/dist/nodes/list-item.d.ts +12 -0
- package/dist/nodes/list-item.js +24 -0
- package/dist/nodes/list-view.d.ts +0 -22
- package/dist/nodes/list-view.js +45 -38
- package/dist/nodes/menu.d.ts +6 -106
- package/dist/nodes/menu.js +16 -268
- package/dist/nodes/models/list.d.ts +24 -0
- package/dist/nodes/models/list.js +102 -0
- package/dist/nodes/models/menu.d.ts +45 -0
- package/dist/nodes/models/menu.js +265 -0
- package/dist/nodes/models/tree-list.d.ts +28 -0
- package/dist/nodes/models/tree-list.js +141 -0
- package/dist/nodes/navigation-page.d.ts +21 -0
- package/dist/nodes/navigation-page.js +95 -0
- package/dist/nodes/navigation-view.d.ts +1 -0
- package/dist/nodes/navigation-view.js +29 -0
- package/dist/nodes/notebook-page-tab.d.ts +15 -0
- package/dist/nodes/notebook-page-tab.js +42 -0
- package/dist/nodes/notebook-page.d.ts +23 -0
- package/dist/nodes/notebook-page.js +106 -0
- package/dist/nodes/notebook.d.ts +0 -32
- package/dist/nodes/notebook.js +20 -113
- package/dist/nodes/overlay-child.d.ts +1 -0
- package/dist/nodes/overlay-child.js +30 -0
- package/dist/nodes/pack-child.d.ts +21 -0
- package/dist/nodes/pack-child.js +68 -0
- package/dist/nodes/pack.d.ts +1 -0
- package/dist/nodes/pack.js +33 -0
- package/dist/nodes/popover-menu.d.ts +1 -0
- package/dist/nodes/popover-menu.js +58 -0
- package/dist/nodes/simple-list-item.d.ts +9 -0
- package/dist/nodes/simple-list-item.js +9 -0
- package/dist/nodes/simple-list-view.d.ts +1 -0
- package/dist/nodes/simple-list-view.js +75 -0
- package/dist/nodes/slot.d.ts +18 -10
- package/dist/nodes/slot.js +83 -51
- package/dist/nodes/stack-page.d.ts +1 -0
- package/dist/nodes/stack-page.js +80 -0
- package/dist/nodes/stack.d.ts +1 -22
- package/dist/nodes/stack.js +21 -60
- package/dist/nodes/toast-overlay.d.ts +1 -0
- package/dist/nodes/toast-overlay.js +35 -0
- package/dist/nodes/toast.d.ts +17 -0
- package/dist/nodes/toast.js +77 -0
- package/dist/nodes/toolbar-child.d.ts +9 -0
- package/dist/nodes/toolbar-child.js +33 -0
- package/dist/nodes/toolbar.d.ts +1 -0
- package/dist/nodes/toolbar.js +42 -0
- package/dist/nodes/tree-list-item.d.ts +20 -0
- package/dist/nodes/tree-list-item.js +102 -0
- package/dist/nodes/tree-list-view.d.ts +1 -0
- package/dist/nodes/tree-list-view.js +57 -0
- package/dist/nodes/virtual.d.ts +13 -0
- package/dist/nodes/virtual.js +21 -0
- package/dist/nodes/widget.d.ts +17 -3
- package/dist/nodes/widget.js +258 -2
- package/dist/nodes/window.d.ts +1 -12
- package/dist/nodes/window.js +66 -27
- package/dist/portal.d.ts +18 -13
- package/dist/portal.js +17 -14
- package/dist/reconciler.d.ts +0 -4
- package/dist/reconciler.js +1 -9
- package/dist/registry.d.ts +8 -0
- package/dist/registry.js +5 -0
- package/dist/render.d.ts +108 -12
- package/dist/render.js +140 -16
- package/dist/scheduler.d.ts +4 -0
- package/dist/scheduler.js +10 -0
- package/dist/types.d.ts +3 -136
- package/package.json +6 -6
- package/dist/batch.d.ts +0 -5
- package/dist/batch.js +0 -31
- package/dist/codegen/jsx-generator.d.ts +0 -56
- package/dist/codegen/jsx-generator.js +0 -959
- package/dist/containers.d.ts +0 -58
- package/dist/nodes/about-dialog.d.ts +0 -8
- package/dist/nodes/about-dialog.js +0 -16
- package/dist/nodes/action-bar.d.ts +0 -5
- package/dist/nodes/action-bar.js +0 -6
- package/dist/nodes/combo-row.d.ts +0 -5
- package/dist/nodes/combo-row.js +0 -6
- package/dist/nodes/drop-down.d.ts +0 -9
- package/dist/nodes/drop-down.js +0 -12
- package/dist/nodes/flow-box.d.ts +0 -10
- package/dist/nodes/flow-box.js +0 -41
- package/dist/nodes/grid.d.ts +0 -30
- package/dist/nodes/grid.js +0 -84
- package/dist/nodes/header-bar.d.ts +0 -43
- package/dist/nodes/header-bar.js +0 -116
- package/dist/nodes/indexed-child-container.d.ts +0 -16
- package/dist/nodes/indexed-child-container.js +0 -22
- package/dist/nodes/list-box.d.ts +0 -10
- package/dist/nodes/list-box.js +0 -48
- package/dist/nodes/list-item-factory.d.ts +0 -19
- package/dist/nodes/list-item-factory.js +0 -58
- package/dist/nodes/overlay.d.ts +0 -11
- package/dist/nodes/overlay.js +0 -50
- package/dist/nodes/paged-stack.d.ts +0 -31
- package/dist/nodes/paged-stack.js +0 -95
- package/dist/nodes/root.d.ts +0 -8
- package/dist/nodes/root.js +0 -13
- package/dist/nodes/selectable-list.d.ts +0 -45
- package/dist/nodes/selectable-list.js +0 -260
- package/dist/nodes/stack-page-props.d.ts +0 -11
- package/dist/nodes/stack-page-props.js +0 -23
- package/dist/nodes/string-list-container.d.ts +0 -34
- package/dist/nodes/string-list-container.js +0 -118
- package/dist/nodes/string-list-item.d.ts +0 -19
- package/dist/nodes/string-list-item.js +0 -50
- package/dist/nodes/string-list-store.d.ts +0 -13
- package/dist/nodes/string-list-store.js +0 -44
- package/dist/nodes/text-view.d.ts +0 -8
- package/dist/nodes/text-view.js +0 -16
- package/dist/nodes/toggle-button.d.ts +0 -14
- package/dist/nodes/toggle-button.js +0 -39
- package/dist/nodes/toolbar-view.d.ts +0 -14
- package/dist/nodes/toolbar-view.js +0 -78
- package/dist/nodes/view-stack.d.ts +0 -9
- package/dist/nodes/view-stack.js +0 -28
- package/dist/nodes/virtual-item.d.ts +0 -19
- package/dist/nodes/virtual-item.js +0 -48
- package/dist/nodes/virtual-slot.d.ts +0 -25
- package/dist/nodes/virtual-slot.js +0 -57
- package/dist/predicates.d.ts +0 -29
- package/dist/predicates.js +0 -37
- package/dist/props.d.ts +0 -7
- package/dist/props.js +0 -12
- /package/dist/{containers.js → nodes/action-row.d.ts} +0 -0
package/dist/nodes/overlay.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Node } from "../node.js";
|
|
2
|
-
export class OverlayNode extends Node {
|
|
3
|
-
static matches(type) {
|
|
4
|
-
return type === "Overlay" || type === "Overlay.Root";
|
|
5
|
-
}
|
|
6
|
-
mainChild = null;
|
|
7
|
-
overlayChildren = [];
|
|
8
|
-
attachChild(childWidget) {
|
|
9
|
-
if (this.mainChild === null) {
|
|
10
|
-
this.mainChild = childWidget;
|
|
11
|
-
this.widget.setChild(childWidget);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
this.overlayChildren.push(childWidget);
|
|
15
|
-
this.widget.addOverlay(childWidget);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
insertChildBefore(childWidget, beforeWidget) {
|
|
19
|
-
if (this.mainChild === null) {
|
|
20
|
-
this.mainChild = childWidget;
|
|
21
|
-
this.widget.setChild(childWidget);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (this.mainChild === beforeWidget) {
|
|
25
|
-
this.overlayChildren.unshift(childWidget);
|
|
26
|
-
this.widget.addOverlay(childWidget);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const beforeIndex = this.overlayChildren.indexOf(beforeWidget);
|
|
30
|
-
if (beforeIndex === -1) {
|
|
31
|
-
this.attachChild(childWidget);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
this.overlayChildren.splice(beforeIndex, 0, childWidget);
|
|
35
|
-
this.widget.addOverlay(childWidget);
|
|
36
|
-
}
|
|
37
|
-
detachChild(childWidget) {
|
|
38
|
-
if (this.mainChild === childWidget) {
|
|
39
|
-
this.widget.setChild(undefined);
|
|
40
|
-
this.mainChild = null;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const index = this.overlayChildren.indexOf(childWidget);
|
|
44
|
-
if (index !== -1) {
|
|
45
|
-
this.overlayChildren.splice(index, 1);
|
|
46
|
-
this.widget.removeOverlay(childWidget);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
-
import type { ChildContainer, StackPageContainer, StackPageProps } from "../containers.js";
|
|
3
|
-
import type { Props } from "../factory.js";
|
|
4
|
-
import type { Node } from "../node.js";
|
|
5
|
-
import { Node as NodeClass } from "../node.js";
|
|
6
|
-
import { type StackPageLike } from "./stack-page-props.js";
|
|
7
|
-
type StackWidget = Gtk.Widget & {
|
|
8
|
-
getChildByName(name: string): Gtk.Widget | null;
|
|
9
|
-
setVisibleChild(child: Gtk.Widget): void;
|
|
10
|
-
remove(child: Gtk.Widget): void;
|
|
11
|
-
getPage(child: Gtk.Widget): StackPageLike;
|
|
12
|
-
};
|
|
13
|
-
export declare abstract class PagedStackNode<T extends StackWidget> extends NodeClass<T> implements StackPageContainer, ChildContainer {
|
|
14
|
-
static consumedPropNames: string[];
|
|
15
|
-
private pendingVisibleChildName;
|
|
16
|
-
abstract addStackPage(child: Gtk.Widget, props: StackPageProps): void;
|
|
17
|
-
protected abstract addChildToWidget(child: Gtk.Widget): void;
|
|
18
|
-
protected applyPendingVisibleChild(): void;
|
|
19
|
-
insertStackPageBefore(child: Gtk.Widget, props: StackPageProps, _beforeChild: Gtk.Widget): void;
|
|
20
|
-
removeStackPage(child: Gtk.Widget): void;
|
|
21
|
-
updateStackPageProps(child: Gtk.Widget, props: StackPageProps): void;
|
|
22
|
-
attachChild(child: Gtk.Widget): void;
|
|
23
|
-
insertChildBefore(child: Gtk.Widget, _before: Gtk.Widget): void;
|
|
24
|
-
detachChild(child: Gtk.Widget): void;
|
|
25
|
-
private setVisibleChildOrDefer;
|
|
26
|
-
appendChild(child: Node): void;
|
|
27
|
-
insertBefore(child: Node, before: Node): void;
|
|
28
|
-
removeChild(child: Node): void;
|
|
29
|
-
updateProps(oldProps: Props, newProps: Props): void;
|
|
30
|
-
}
|
|
31
|
-
export {};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Node as NodeClass } from "../node.js";
|
|
2
|
-
import { StackPageNode } from "./stack.js";
|
|
3
|
-
import { applyStackPageProps } from "./stack-page-props.js";
|
|
4
|
-
export class PagedStackNode extends NodeClass {
|
|
5
|
-
static consumedPropNames = ["visibleChildName"];
|
|
6
|
-
pendingVisibleChildName = null;
|
|
7
|
-
applyPendingVisibleChild() {
|
|
8
|
-
if (this.pendingVisibleChildName !== null) {
|
|
9
|
-
const child = this.widget.getChildByName(this.pendingVisibleChildName);
|
|
10
|
-
if (child) {
|
|
11
|
-
this.widget.setVisibleChild(child);
|
|
12
|
-
this.pendingVisibleChildName = null;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
insertStackPageBefore(child, props, _beforeChild) {
|
|
17
|
-
this.addStackPage(child, props);
|
|
18
|
-
}
|
|
19
|
-
removeStackPage(child) {
|
|
20
|
-
this.widget.remove(child);
|
|
21
|
-
}
|
|
22
|
-
updateStackPageProps(child, props) {
|
|
23
|
-
const page = this.widget.getPage(child);
|
|
24
|
-
applyStackPageProps(page, props);
|
|
25
|
-
}
|
|
26
|
-
attachChild(child) {
|
|
27
|
-
this.addChildToWidget(child);
|
|
28
|
-
}
|
|
29
|
-
insertChildBefore(child, _before) {
|
|
30
|
-
this.addChildToWidget(child);
|
|
31
|
-
}
|
|
32
|
-
detachChild(child) {
|
|
33
|
-
this.widget.remove(child);
|
|
34
|
-
}
|
|
35
|
-
setVisibleChildOrDefer(name) {
|
|
36
|
-
const child = this.widget.getChildByName(name);
|
|
37
|
-
if (child) {
|
|
38
|
-
this.widget.setVisibleChild(child);
|
|
39
|
-
this.pendingVisibleChildName = null;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
this.pendingVisibleChildName = name;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
appendChild(child) {
|
|
46
|
-
if (child instanceof StackPageNode) {
|
|
47
|
-
child.parent = this;
|
|
48
|
-
const childWidget = child.getChildWidget();
|
|
49
|
-
const props = child.getSlotProps();
|
|
50
|
-
if (childWidget) {
|
|
51
|
-
this.addStackPage(childWidget, props);
|
|
52
|
-
child.setParentContainer(this);
|
|
53
|
-
}
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
super.appendChild(child);
|
|
57
|
-
}
|
|
58
|
-
insertBefore(child, before) {
|
|
59
|
-
if (child instanceof StackPageNode) {
|
|
60
|
-
child.parent = this;
|
|
61
|
-
const childWidget = child.getChildWidget();
|
|
62
|
-
const props = child.getSlotProps();
|
|
63
|
-
if (childWidget) {
|
|
64
|
-
const beforeWidget = child.getBeforeWidget(before);
|
|
65
|
-
if (beforeWidget) {
|
|
66
|
-
this.insertStackPageBefore(childWidget, props, beforeWidget);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
this.addStackPage(childWidget, props);
|
|
70
|
-
}
|
|
71
|
-
child.setParentContainer(this);
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
super.insertBefore(child, before);
|
|
76
|
-
}
|
|
77
|
-
removeChild(child) {
|
|
78
|
-
if (child instanceof StackPageNode) {
|
|
79
|
-
const childWidget = child.getChildWidget();
|
|
80
|
-
if (childWidget) {
|
|
81
|
-
this.removeStackPage(childWidget);
|
|
82
|
-
}
|
|
83
|
-
child.unmount();
|
|
84
|
-
child.parent = null;
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
super.removeChild(child);
|
|
88
|
-
}
|
|
89
|
-
updateProps(oldProps, newProps) {
|
|
90
|
-
if (newProps.visibleChildName !== undefined) {
|
|
91
|
-
this.setVisibleChildOrDefer(newProps.visibleChildName);
|
|
92
|
-
}
|
|
93
|
-
super.updateProps(oldProps, newProps);
|
|
94
|
-
}
|
|
95
|
-
}
|
package/dist/nodes/root.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
-
import { Node } from "../node.js";
|
|
3
|
-
export declare const ROOT_NODE_CONTAINER: unique symbol;
|
|
4
|
-
export declare class RootNode extends Node<never> {
|
|
5
|
-
static matches(_type: string, widget?: Gtk.Widget | typeof ROOT_NODE_CONTAINER): boolean;
|
|
6
|
-
protected isVirtual(): boolean;
|
|
7
|
-
constructor();
|
|
8
|
-
}
|
package/dist/nodes/root.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Node } from "../node.js";
|
|
2
|
-
export const ROOT_NODE_CONTAINER = Symbol.for("ROOT_NODE_CONTAINER");
|
|
3
|
-
export class RootNode extends Node {
|
|
4
|
-
static matches(_type, widget) {
|
|
5
|
-
return widget === ROOT_NODE_CONTAINER;
|
|
6
|
-
}
|
|
7
|
-
isVirtual() {
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
constructor() {
|
|
11
|
-
super("");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
-
import type { ItemContainer } from "../containers.js";
|
|
3
|
-
import type { Props } from "../factory.js";
|
|
4
|
-
import type { Node } from "../node.js";
|
|
5
|
-
import { Node as NodeClass } from "../node.js";
|
|
6
|
-
export type SelectableListState = {
|
|
7
|
-
itemsById: Map<string, unknown>;
|
|
8
|
-
itemOrder: string[];
|
|
9
|
-
committedOrder: string[];
|
|
10
|
-
stringList: Gtk.StringList;
|
|
11
|
-
selectionModel: Gtk.SingleSelection | Gtk.MultiSelection;
|
|
12
|
-
selectionMode: Gtk.SelectionMode;
|
|
13
|
-
selected: string[];
|
|
14
|
-
onSelectionChanged?: (ids: string[]) => void;
|
|
15
|
-
selectionHandlerId: number | null;
|
|
16
|
-
needsSync: boolean;
|
|
17
|
-
needsInitialSelection: boolean;
|
|
18
|
-
};
|
|
19
|
-
type SelectableListWidget = Gtk.Widget & {
|
|
20
|
-
setModel(model: Gtk.SelectionModel): void;
|
|
21
|
-
};
|
|
22
|
-
export declare abstract class SelectableListNode<T extends SelectableListWidget, S extends SelectableListState> extends NodeClass<T, S> implements ItemContainer<unknown> {
|
|
23
|
-
appendChild(child: Node): void;
|
|
24
|
-
insertBefore(child: Node, before: Node): void;
|
|
25
|
-
removeChild(child: Node): void;
|
|
26
|
-
protected initializeSelectionState(props: Props): SelectableListState;
|
|
27
|
-
protected applySelectionModel(): void;
|
|
28
|
-
protected cleanupSelection(): void;
|
|
29
|
-
protected updateSelectionProps(oldProps: Props, newProps: Props): void;
|
|
30
|
-
private recreateSelectionModel;
|
|
31
|
-
getItems(): unknown[];
|
|
32
|
-
getItemById(id: string): unknown;
|
|
33
|
-
addItem(id: string, data: unknown): void;
|
|
34
|
-
insertItemBefore(id: string, data: unknown, beforeId: string): void;
|
|
35
|
-
removeItem(id: string): void;
|
|
36
|
-
updateItem(id: string, data: unknown): void;
|
|
37
|
-
protected scheduleSync(): void;
|
|
38
|
-
protected syncModel: () => void;
|
|
39
|
-
protected applyInitialSelection(): void;
|
|
40
|
-
protected applySelection(ids: string[]): void;
|
|
41
|
-
protected getSelectedIds(): string[];
|
|
42
|
-
protected connectSelectionHandler(): void;
|
|
43
|
-
protected disconnectSelectionHandler(): void;
|
|
44
|
-
}
|
|
45
|
-
export {};
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import { getNativeObject } from "@gtkx/ffi";
|
|
2
|
-
import * as Gio from "@gtkx/ffi/gio";
|
|
3
|
-
import * as GObject from "@gtkx/ffi/gobject";
|
|
4
|
-
import * as Gtk from "@gtkx/ffi/gtk";
|
|
5
|
-
import { scheduleFlush } from "../batch.js";
|
|
6
|
-
import { Node as NodeClass } from "../node.js";
|
|
7
|
-
import { getCallbackChange } from "../props.js";
|
|
8
|
-
import { VirtualItemNode } from "./virtual-item.js";
|
|
9
|
-
export class SelectableListNode extends NodeClass {
|
|
10
|
-
appendChild(child) {
|
|
11
|
-
if (child instanceof VirtualItemNode) {
|
|
12
|
-
child.parent = this;
|
|
13
|
-
child.addToContainer(this);
|
|
14
|
-
child.setParentContainer(this);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
super.appendChild(child);
|
|
18
|
-
}
|
|
19
|
-
insertBefore(child, before) {
|
|
20
|
-
if (child instanceof VirtualItemNode) {
|
|
21
|
-
child.parent = this;
|
|
22
|
-
if (before instanceof VirtualItemNode) {
|
|
23
|
-
child.insertBeforeInContainer(this, before.getId());
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
child.addToContainer(this);
|
|
27
|
-
}
|
|
28
|
-
child.setParentContainer(this);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
super.insertBefore(child, before);
|
|
32
|
-
}
|
|
33
|
-
removeChild(child) {
|
|
34
|
-
if (child instanceof VirtualItemNode) {
|
|
35
|
-
child.unmount();
|
|
36
|
-
child.parent = null;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
super.removeChild(child);
|
|
40
|
-
}
|
|
41
|
-
initializeSelectionState(props) {
|
|
42
|
-
const selectionMode = props.selectionMode ?? Gtk.SelectionMode.SINGLE;
|
|
43
|
-
const stringList = new Gtk.StringList([]);
|
|
44
|
-
const listModel = getNativeObject(stringList.id, Gio.ListModel) ?? undefined;
|
|
45
|
-
const selectionModel = selectionMode === Gtk.SelectionMode.MULTIPLE
|
|
46
|
-
? new Gtk.MultiSelection(listModel)
|
|
47
|
-
: new Gtk.SingleSelection(listModel);
|
|
48
|
-
if (selectionModel instanceof Gtk.SingleSelection) {
|
|
49
|
-
selectionModel.setAutoselect(false);
|
|
50
|
-
selectionModel.setCanUnselect(true);
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
itemsById: new Map(),
|
|
54
|
-
itemOrder: [],
|
|
55
|
-
committedOrder: [],
|
|
56
|
-
stringList,
|
|
57
|
-
selectionModel,
|
|
58
|
-
selectionMode,
|
|
59
|
-
selected: props.selected ?? [],
|
|
60
|
-
onSelectionChanged: props.onSelectionChanged,
|
|
61
|
-
selectionHandlerId: null,
|
|
62
|
-
needsSync: false,
|
|
63
|
-
needsInitialSelection: true,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
applySelectionModel() {
|
|
67
|
-
this.widget.setModel(this.state.selectionModel);
|
|
68
|
-
}
|
|
69
|
-
cleanupSelection() {
|
|
70
|
-
this.disconnectSelectionHandler();
|
|
71
|
-
}
|
|
72
|
-
updateSelectionProps(oldProps, newProps) {
|
|
73
|
-
const oldSelectionMode = oldProps.selectionMode;
|
|
74
|
-
const newSelectionMode = newProps.selectionMode;
|
|
75
|
-
const effectiveOldMode = oldSelectionMode ?? Gtk.SelectionMode.SINGLE;
|
|
76
|
-
const effectiveNewMode = newSelectionMode ?? Gtk.SelectionMode.SINGLE;
|
|
77
|
-
if (effectiveOldMode !== effectiveNewMode) {
|
|
78
|
-
this.recreateSelectionModel(effectiveNewMode);
|
|
79
|
-
}
|
|
80
|
-
const oldCallback = oldProps.onSelectionChanged;
|
|
81
|
-
const newCallback = newProps.onSelectionChanged;
|
|
82
|
-
const change = getCallbackChange(oldCallback, newCallback);
|
|
83
|
-
if (change.action !== "none") {
|
|
84
|
-
this.state.onSelectionChanged = change.callback;
|
|
85
|
-
if (change.action === "disconnect") {
|
|
86
|
-
this.disconnectSelectionHandler();
|
|
87
|
-
}
|
|
88
|
-
else if (change.action === "connect") {
|
|
89
|
-
this.connectSelectionHandler();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const oldSelected = oldProps.selected;
|
|
93
|
-
const newSelected = newProps.selected;
|
|
94
|
-
if (oldSelected !== newSelected && newSelected !== undefined) {
|
|
95
|
-
this.state.selected = newSelected;
|
|
96
|
-
this.applySelection(newSelected);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
recreateSelectionModel(newSelectionMode) {
|
|
100
|
-
const currentSelection = this.getSelectedIds();
|
|
101
|
-
const hadHandler = this.state.selectionHandlerId !== null;
|
|
102
|
-
this.disconnectSelectionHandler();
|
|
103
|
-
const listModel = getNativeObject(this.state.stringList.id, Gio.ListModel) ?? undefined;
|
|
104
|
-
const newSelectionModel = newSelectionMode === Gtk.SelectionMode.MULTIPLE
|
|
105
|
-
? new Gtk.MultiSelection(listModel)
|
|
106
|
-
: new Gtk.SingleSelection(listModel);
|
|
107
|
-
if (newSelectionModel instanceof Gtk.SingleSelection) {
|
|
108
|
-
newSelectionModel.setAutoselect(false);
|
|
109
|
-
newSelectionModel.setCanUnselect(true);
|
|
110
|
-
}
|
|
111
|
-
this.state.selectionModel = newSelectionModel;
|
|
112
|
-
this.state.selectionMode = newSelectionMode;
|
|
113
|
-
this.applySelectionModel();
|
|
114
|
-
this.applySelection(currentSelection);
|
|
115
|
-
if (hadHandler && this.state.onSelectionChanged) {
|
|
116
|
-
this.connectSelectionHandler();
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
getItems() {
|
|
120
|
-
return this.state.itemOrder.map((id) => this.state.itemsById.get(id));
|
|
121
|
-
}
|
|
122
|
-
getItemById(id) {
|
|
123
|
-
return this.state.itemsById.get(id);
|
|
124
|
-
}
|
|
125
|
-
addItem(id, data) {
|
|
126
|
-
this.state.itemsById.set(id, data);
|
|
127
|
-
const existingIndex = this.state.itemOrder.indexOf(id);
|
|
128
|
-
if (existingIndex !== -1) {
|
|
129
|
-
this.state.itemOrder.splice(existingIndex, 1);
|
|
130
|
-
}
|
|
131
|
-
this.state.itemOrder.push(id);
|
|
132
|
-
this.scheduleSync();
|
|
133
|
-
}
|
|
134
|
-
insertItemBefore(id, data, beforeId) {
|
|
135
|
-
this.state.itemsById.set(id, data);
|
|
136
|
-
const existingIndex = this.state.itemOrder.indexOf(id);
|
|
137
|
-
if (existingIndex !== -1) {
|
|
138
|
-
this.state.itemOrder.splice(existingIndex, 1);
|
|
139
|
-
}
|
|
140
|
-
const beforeIndex = this.state.itemOrder.indexOf(beforeId);
|
|
141
|
-
if (beforeIndex === -1) {
|
|
142
|
-
this.state.itemOrder.push(id);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
this.state.itemOrder.splice(beforeIndex, 0, id);
|
|
146
|
-
}
|
|
147
|
-
this.scheduleSync();
|
|
148
|
-
}
|
|
149
|
-
removeItem(id) {
|
|
150
|
-
const index = this.state.itemOrder.indexOf(id);
|
|
151
|
-
if (index !== -1) {
|
|
152
|
-
this.state.itemOrder.splice(index, 1);
|
|
153
|
-
this.state.itemsById.delete(id);
|
|
154
|
-
this.scheduleSync();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
updateItem(id, data) {
|
|
158
|
-
if (this.state.itemsById.has(id)) {
|
|
159
|
-
this.state.itemsById.set(id, data);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
scheduleSync() {
|
|
163
|
-
if (!this.state.needsSync) {
|
|
164
|
-
this.state.needsSync = true;
|
|
165
|
-
scheduleFlush(this.syncModel);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
syncModel = () => {
|
|
169
|
-
if (!this.state.needsSync)
|
|
170
|
-
return;
|
|
171
|
-
this.state.needsSync = false;
|
|
172
|
-
const oldOrder = this.state.committedOrder;
|
|
173
|
-
const newOrder = this.state.itemOrder;
|
|
174
|
-
let firstDiff = 0;
|
|
175
|
-
const minLen = Math.min(oldOrder.length, newOrder.length);
|
|
176
|
-
while (firstDiff < minLen && oldOrder[firstDiff] === newOrder[firstDiff]) {
|
|
177
|
-
firstDiff++;
|
|
178
|
-
}
|
|
179
|
-
let oldEndOffset = 0;
|
|
180
|
-
let newEndOffset = 0;
|
|
181
|
-
while (oldEndOffset < oldOrder.length - firstDiff &&
|
|
182
|
-
newEndOffset < newOrder.length - firstDiff &&
|
|
183
|
-
oldOrder[oldOrder.length - 1 - oldEndOffset] === newOrder[newOrder.length - 1 - newEndOffset]) {
|
|
184
|
-
oldEndOffset++;
|
|
185
|
-
newEndOffset++;
|
|
186
|
-
}
|
|
187
|
-
const removeCount = oldOrder.length - firstDiff - oldEndOffset;
|
|
188
|
-
const addItems = newOrder.slice(firstDiff, newOrder.length - newEndOffset);
|
|
189
|
-
if (removeCount > 0 || addItems.length > 0) {
|
|
190
|
-
this.state.stringList.splice(firstDiff, removeCount, addItems);
|
|
191
|
-
}
|
|
192
|
-
this.state.committedOrder = [...newOrder];
|
|
193
|
-
if (this.state.needsInitialSelection && this.state.itemOrder.length > 0) {
|
|
194
|
-
this.state.needsInitialSelection = false;
|
|
195
|
-
queueMicrotask(() => {
|
|
196
|
-
if (this.hasParent()) {
|
|
197
|
-
this.applyInitialSelection();
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
applyInitialSelection() {
|
|
203
|
-
this.applySelection(this.state.selected);
|
|
204
|
-
if (this.state.onSelectionChanged) {
|
|
205
|
-
this.connectSelectionHandler();
|
|
206
|
-
this.state.onSelectionChanged(this.getSelectedIds());
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
applySelection(ids) {
|
|
210
|
-
if (this.state.selectionMode === Gtk.SelectionMode.MULTIPLE) {
|
|
211
|
-
const multiSelection = this.state.selectionModel;
|
|
212
|
-
multiSelection.unselectAll();
|
|
213
|
-
for (const id of ids) {
|
|
214
|
-
const index = this.state.itemOrder.indexOf(id);
|
|
215
|
-
if (index !== -1) {
|
|
216
|
-
multiSelection.selectItem(index, false);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
const singleSelection = this.state.selectionModel;
|
|
222
|
-
const firstId = ids[0];
|
|
223
|
-
if (firstId !== undefined) {
|
|
224
|
-
const index = this.state.itemOrder.indexOf(firstId);
|
|
225
|
-
if (index !== -1) {
|
|
226
|
-
singleSelection.setSelected(index);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
singleSelection.setSelected(Gtk.INVALID_LIST_POSITION);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
getSelectedIds() {
|
|
235
|
-
const selection = this.state.selectionModel.getSelection();
|
|
236
|
-
const count = Number(selection.getSize());
|
|
237
|
-
const selectedIds = [];
|
|
238
|
-
for (let i = 0; i < count; i++) {
|
|
239
|
-
const position = selection.getNth(i);
|
|
240
|
-
const id = this.state.itemOrder[position];
|
|
241
|
-
if (id !== undefined) {
|
|
242
|
-
selectedIds.push(id);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return selectedIds;
|
|
246
|
-
}
|
|
247
|
-
connectSelectionHandler() {
|
|
248
|
-
if (this.state.selectionHandlerId !== null)
|
|
249
|
-
return;
|
|
250
|
-
this.state.selectionHandlerId = this.state.selectionModel.connect("selection-changed", () => {
|
|
251
|
-
this.state.onSelectionChanged?.(this.getSelectedIds());
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
disconnectSelectionHandler() {
|
|
255
|
-
if (this.state.selectionHandlerId !== null) {
|
|
256
|
-
GObject.signalHandlerDisconnect(this.state.selectionModel, this.state.selectionHandlerId);
|
|
257
|
-
this.state.selectionHandlerId = null;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { StackPageProps } from "../containers.js";
|
|
2
|
-
export type StackPageLike = {
|
|
3
|
-
setName(name: string): void;
|
|
4
|
-
setTitle(title: string): void;
|
|
5
|
-
setIconName(iconName: string): void;
|
|
6
|
-
setNeedsAttention(needsAttention: boolean): void;
|
|
7
|
-
setVisible(visible: boolean): void;
|
|
8
|
-
setUseUnderline(useUnderline: boolean): void;
|
|
9
|
-
setBadgeNumber?(badgeNumber: number): void;
|
|
10
|
-
};
|
|
11
|
-
export declare function applyStackPageProps(page: StackPageLike, props: StackPageProps): void;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function applyStackPageProps(page, props) {
|
|
2
|
-
if (props.name !== undefined) {
|
|
3
|
-
page.setName(props.name);
|
|
4
|
-
}
|
|
5
|
-
if (props.title !== undefined) {
|
|
6
|
-
page.setTitle(props.title);
|
|
7
|
-
}
|
|
8
|
-
if (props.iconName !== undefined) {
|
|
9
|
-
page.setIconName(props.iconName);
|
|
10
|
-
}
|
|
11
|
-
if (props.needsAttention !== undefined) {
|
|
12
|
-
page.setNeedsAttention(props.needsAttention);
|
|
13
|
-
}
|
|
14
|
-
if (props.visible !== undefined) {
|
|
15
|
-
page.setVisible(props.visible);
|
|
16
|
-
}
|
|
17
|
-
if (props.useUnderline !== undefined) {
|
|
18
|
-
page.setUseUnderline(props.useUnderline);
|
|
19
|
-
}
|
|
20
|
-
if (props.badgeNumber !== undefined && page.setBadgeNumber) {
|
|
21
|
-
page.setBadgeNumber(props.badgeNumber);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import * as Gio from "@gtkx/ffi/gio";
|
|
2
|
-
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
3
|
-
import type { StringListContainer } from "../containers.js";
|
|
4
|
-
import type { Props } from "../factory.js";
|
|
5
|
-
import type { Node } from "../node.js";
|
|
6
|
-
import { Node as NodeClass } from "../node.js";
|
|
7
|
-
import { StringListStore } from "./string-list-store.js";
|
|
8
|
-
type StringListContainerState = {
|
|
9
|
-
store: StringListStore;
|
|
10
|
-
onSelectionChanged?: (id: string) => void;
|
|
11
|
-
initialSelection?: string;
|
|
12
|
-
hasAppliedInitialSelection: boolean;
|
|
13
|
-
};
|
|
14
|
-
type StringListWidget = Gtk.Widget & {
|
|
15
|
-
setModel(model?: Gio.ListModel): void;
|
|
16
|
-
getSelected(): number;
|
|
17
|
-
setSelected(position: number): void;
|
|
18
|
-
};
|
|
19
|
-
export declare abstract class StringListContainerNode<T extends StringListWidget> extends NodeClass<T, StringListContainerState> implements StringListContainer {
|
|
20
|
-
static consumedPropNames: string[];
|
|
21
|
-
appendChild(child: Node): void;
|
|
22
|
-
insertBefore(child: Node, before: Node): void;
|
|
23
|
-
removeChild(child: Node): void;
|
|
24
|
-
initialize(props: Props): void;
|
|
25
|
-
private connectSelectionHandler;
|
|
26
|
-
addStringListItem(id: string, label: string): void;
|
|
27
|
-
private scheduleInitialSelectionIfNeeded;
|
|
28
|
-
private applyInitialSelection;
|
|
29
|
-
insertStringListItemBefore(id: string, label: string, beforeId: string): void;
|
|
30
|
-
removeStringListItem(id: string): void;
|
|
31
|
-
updateStringListItem(oldId: string, newId: string, newLabel: string): void;
|
|
32
|
-
updateProps(oldProps: Props, newProps: Props): void;
|
|
33
|
-
}
|
|
34
|
-
export {};
|