@gtkx/react 0.15.0 → 0.17.1

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 (172) hide show
  1. package/README.md +1 -0
  2. package/dist/animation/css-builder.d.ts +3 -0
  3. package/dist/animation/css-builder.js +53 -0
  4. package/dist/animation/types.d.ts +120 -0
  5. package/dist/errors.js +3 -0
  6. package/dist/factory.d.ts +3 -2
  7. package/dist/factory.js +1 -1
  8. package/dist/fiber-root.js +1 -1
  9. package/dist/generated/internal.d.ts +28 -1
  10. package/dist/generated/internal.js +93 -18
  11. package/dist/generated/jsx.d.ts +1672 -1483
  12. package/dist/generated/jsx.js +475 -0
  13. package/dist/host-config.d.ts +3 -1
  14. package/dist/host-config.js +26 -11
  15. package/dist/jsx.d.ts +136 -166
  16. package/dist/jsx.js +58 -69
  17. package/dist/node.d.ts +4 -1
  18. package/dist/node.js +14 -3
  19. package/dist/nodes/abstract/positional-child.d.ts +9 -0
  20. package/dist/nodes/abstract/positional-child.js +29 -0
  21. package/dist/nodes/abstract/virtual-container.d.ts +21 -0
  22. package/dist/nodes/abstract/virtual-container.js +68 -0
  23. package/dist/nodes/abstract/virtual-single-child.d.ts +18 -0
  24. package/dist/nodes/abstract/virtual-single-child.js +55 -0
  25. package/dist/nodes/action-row-child.d.ts +0 -13
  26. package/dist/nodes/action-row-child.js +22 -12
  27. package/dist/nodes/adjustable.d.ts +23 -0
  28. package/dist/nodes/adjustable.js +62 -0
  29. package/dist/nodes/alert-dialog-response.js +86 -0
  30. package/dist/nodes/animation.js +252 -0
  31. package/dist/nodes/application.js +17 -7
  32. package/dist/nodes/autowrapped.js +37 -43
  33. package/dist/nodes/calendar.js +17 -43
  34. package/dist/nodes/color-dialog-button.d.ts +1 -0
  35. package/dist/nodes/color-dialog-button.js +70 -0
  36. package/dist/nodes/column-view-column.d.ts +3 -3
  37. package/dist/nodes/column-view-column.js +1 -1
  38. package/dist/nodes/column-view.js +36 -39
  39. package/dist/nodes/dialog.d.ts +11 -0
  40. package/dist/nodes/dialog.js +20 -0
  41. package/dist/nodes/drawing-area.js +24 -7
  42. package/dist/nodes/event-controller.d.ts +22 -0
  43. package/dist/nodes/event-controller.js +96 -0
  44. package/dist/nodes/expander-row-child.d.ts +0 -14
  45. package/dist/nodes/expander-row-child.js +22 -12
  46. package/dist/nodes/fixed-child.js +52 -36
  47. package/dist/nodes/font-dialog-button.d.ts +1 -0
  48. package/dist/nodes/font-dialog-button.js +90 -0
  49. package/dist/nodes/grid-child.js +43 -45
  50. package/dist/nodes/grid.d.ts +1 -0
  51. package/dist/nodes/grid.js +41 -0
  52. package/dist/nodes/index.d.ts +18 -12
  53. package/dist/nodes/index.js +18 -12
  54. package/dist/nodes/internal/base-item-renderer.d.ts +29 -0
  55. package/dist/nodes/internal/base-item-renderer.js +88 -0
  56. package/dist/nodes/internal/child-attachment.d.ts +26 -0
  57. package/dist/nodes/internal/child-attachment.js +48 -0
  58. package/dist/nodes/internal/deferred-action.d.ts +9 -0
  59. package/dist/nodes/internal/deferred-action.js +22 -0
  60. package/dist/nodes/internal/list-item-renderer.d.ts +14 -15
  61. package/dist/nodes/internal/list-item-renderer.js +51 -77
  62. package/dist/nodes/internal/list-store.d.ts +5 -6
  63. package/dist/nodes/internal/list-store.js +29 -38
  64. package/dist/nodes/internal/predicates.d.ts +25 -2
  65. package/dist/nodes/internal/predicates.js +53 -41
  66. package/dist/nodes/internal/selection-model.d.ts +30 -0
  67. package/dist/nodes/internal/selection-model.js +87 -0
  68. package/dist/nodes/internal/signal-store.d.ts +9 -5
  69. package/dist/nodes/internal/signal-store.js +31 -31
  70. package/dist/nodes/internal/simple-list-store.js +6 -9
  71. package/dist/nodes/internal/text-buffer-controller.d.ts +43 -0
  72. package/dist/nodes/internal/text-buffer-controller.js +287 -0
  73. package/dist/nodes/internal/text-tag-styles.d.ts +43 -0
  74. package/dist/nodes/internal/text-tag-styles.js +52 -0
  75. package/dist/nodes/internal/tree-list-item-renderer.d.ts +15 -14
  76. package/dist/nodes/internal/tree-list-item-renderer.js +85 -96
  77. package/dist/nodes/internal/tree-store.d.ts +8 -11
  78. package/dist/nodes/internal/tree-store.js +70 -72
  79. package/dist/nodes/internal/utils.d.ts +7 -4
  80. package/dist/nodes/internal/utils.js +50 -5
  81. package/dist/nodes/level-bar.js +19 -54
  82. package/dist/nodes/list-item.d.ts +6 -3
  83. package/dist/nodes/list-item.js +7 -4
  84. package/dist/nodes/list-view.js +17 -12
  85. package/dist/nodes/menu.d.ts +3 -3
  86. package/dist/nodes/menu.js +3 -3
  87. package/dist/nodes/models/list.d.ts +11 -13
  88. package/dist/nodes/models/list.js +16 -73
  89. package/dist/nodes/models/menu.d.ts +8 -7
  90. package/dist/nodes/models/menu.js +43 -50
  91. package/dist/nodes/models/tree-list.d.ts +6 -12
  92. package/dist/nodes/models/tree-list.js +30 -93
  93. package/dist/nodes/navigation-page.d.ts +1 -0
  94. package/dist/nodes/navigation-page.js +27 -32
  95. package/dist/nodes/navigation-view.js +17 -28
  96. package/dist/nodes/notebook-page-tab.d.ts +3 -3
  97. package/dist/nodes/notebook-page-tab.js +11 -14
  98. package/dist/nodes/notebook-page.d.ts +7 -5
  99. package/dist/nodes/notebook-page.js +45 -25
  100. package/dist/nodes/notebook.js +2 -2
  101. package/dist/nodes/overlay-child.js +90 -30
  102. package/dist/nodes/pack-child.d.ts +0 -13
  103. package/dist/nodes/pack-child.js +22 -12
  104. package/dist/nodes/popover-menu.js +2 -2
  105. package/dist/nodes/scale.js +15 -45
  106. package/dist/nodes/scrolled-window.js +7 -6
  107. package/dist/nodes/search-bar.d.ts +1 -0
  108. package/dist/nodes/search-bar.js +40 -0
  109. package/dist/nodes/shortcut-controller.d.ts +1 -37
  110. package/dist/nodes/shortcut-controller.js +8 -47
  111. package/dist/nodes/shortcut.d.ts +5 -4
  112. package/dist/nodes/shortcut.js +11 -5
  113. package/dist/nodes/simple-list-view.js +2 -3
  114. package/dist/nodes/slot.d.ts +6 -9
  115. package/dist/nodes/slot.js +27 -42
  116. package/dist/nodes/source-view.js +80 -29
  117. package/dist/nodes/stack-page.js +20 -22
  118. package/dist/nodes/stack.js +19 -5
  119. package/dist/nodes/text-anchor.d.ts +41 -0
  120. package/dist/nodes/text-anchor.js +59 -0
  121. package/dist/nodes/text-content.d.ts +10 -0
  122. package/dist/nodes/text-content.js +1 -0
  123. package/dist/nodes/text-paintable.d.ts +17 -0
  124. package/dist/nodes/text-paintable.js +34 -0
  125. package/dist/nodes/text-segment.d.ts +15 -0
  126. package/dist/nodes/text-segment.js +29 -0
  127. package/dist/nodes/text-tag.d.ts +136 -0
  128. package/dist/nodes/text-tag.js +202 -0
  129. package/dist/nodes/text-view.d.ts +30 -0
  130. package/dist/nodes/text-view.js +49 -21
  131. package/dist/nodes/toggle-group.js +24 -32
  132. package/dist/nodes/toggle.d.ts +1 -15
  133. package/dist/nodes/toggle.js +40 -32
  134. package/dist/nodes/toolbar-child.js +22 -31
  135. package/dist/nodes/tree-list-item.d.ts +7 -5
  136. package/dist/nodes/tree-list-item.js +24 -36
  137. package/dist/nodes/tree-list-view.js +9 -7
  138. package/dist/nodes/virtual.d.ts +1 -1
  139. package/dist/nodes/web-view.d.ts +1 -0
  140. package/dist/nodes/web-view.js +29 -0
  141. package/dist/nodes/widget.d.ts +2 -16
  142. package/dist/nodes/widget.js +105 -294
  143. package/dist/nodes/window.d.ts +9 -3
  144. package/dist/nodes/window.js +29 -15
  145. package/dist/registry.d.ts +1 -1
  146. package/dist/render.js +9 -7
  147. package/dist/scheduler.d.ts +11 -1
  148. package/dist/scheduler.js +16 -4
  149. package/dist/types.d.ts +2 -136
  150. package/package.json +4 -4
  151. package/dist/nodes/action-row.js +0 -46
  152. package/dist/nodes/adjustment.d.ts +0 -48
  153. package/dist/nodes/adjustment.js +0 -70
  154. package/dist/nodes/calendar-mark.d.ts +0 -15
  155. package/dist/nodes/calendar-mark.js +0 -29
  156. package/dist/nodes/expander-row.js +0 -55
  157. package/dist/nodes/internal/constants.d.ts +0 -1
  158. package/dist/nodes/internal/constants.js +0 -24
  159. package/dist/nodes/level-bar-offset.d.ts +0 -13
  160. package/dist/nodes/level-bar-offset.js +0 -35
  161. package/dist/nodes/pack.js +0 -46
  162. package/dist/nodes/scale-mark.d.ts +0 -17
  163. package/dist/nodes/scale-mark.js +0 -38
  164. package/dist/nodes/source-buffer.d.ts +0 -73
  165. package/dist/nodes/source-buffer.js +0 -149
  166. package/dist/nodes/text-buffer.d.ts +0 -43
  167. package/dist/nodes/text-buffer.js +0 -81
  168. package/dist/nodes/virtual-child.d.ts +0 -18
  169. package/dist/nodes/virtual-child.js +0 -62
  170. /package/dist/{nodes/action-row.d.ts → animation/types.js} +0 -0
  171. /package/dist/nodes/{expander-row.d.ts → alert-dialog-response.d.ts} +0 -0
  172. /package/dist/nodes/{pack.d.ts → animation.d.ts} +0 -0
@@ -2,11 +2,14 @@ import type { ListItemProps } from "../jsx.js";
2
2
  import type { ListStore } from "./internal/list-store.js";
3
3
  import { VirtualNode } from "./virtual.js";
4
4
  type Props = Partial<ListItemProps>;
5
- export declare class ListItemNode<T extends Omit<ListStore, "items" | "model"> = ListStore, P extends Props = Props> extends VirtualNode<P> {
5
+ export declare class ListItemNode<T extends {
6
+ updateItem(id: string, value: unknown): void;
7
+ } = ListStore, P extends Props = Props> extends VirtualNode<P> {
6
8
  static priority: number;
7
- private store?;
9
+ private store;
8
10
  static matches(type: string): boolean;
9
- setStore(store?: T | null): void;
11
+ setStore(store: T | null): void;
10
12
  updateProps(oldProps: P | null, newProps: P): void;
13
+ protected applyOwnProps(oldProps: P | null, newProps: P): void;
11
14
  }
12
15
  export {};
@@ -1,8 +1,9 @@
1
1
  import { registerNodeClass } from "../registry.js";
2
+ import { hasChanged } from "./internal/utils.js";
2
3
  import { VirtualNode } from "./virtual.js";
3
4
  export class ListItemNode extends VirtualNode {
4
5
  static priority = 1;
5
- store;
6
+ store = null;
6
7
  static matches(type) {
7
8
  return type === "ListItem";
8
9
  }
@@ -11,10 +12,12 @@ export class ListItemNode extends VirtualNode {
11
12
  }
12
13
  updateProps(oldProps, newProps) {
13
14
  super.updateProps(oldProps, newProps);
14
- if (!this.store) {
15
+ this.applyOwnProps(oldProps, newProps);
16
+ }
17
+ applyOwnProps(oldProps, newProps) {
18
+ if (!this.store)
15
19
  return;
16
- }
17
- if (!oldProps || oldProps.id !== newProps.id || oldProps.value !== newProps.value) {
20
+ if (hasChanged(oldProps, newProps, "id") || hasChanged(oldProps, newProps, "value")) {
18
21
  if (newProps.id !== undefined) {
19
22
  this.store.updateItem(newProps.id, newProps.value);
20
23
  }
@@ -1,11 +1,12 @@
1
+ import { isObjectEqual } from "@gtkx/ffi";
1
2
  import { LIST_WIDGET_CLASSES } from "../generated/internal.js";
2
3
  import { registerNodeClass } from "../registry.js";
3
4
  import { ListItemRenderer } from "./internal/list-item-renderer.js";
4
- import { filterProps, matchesAnyClass } from "./internal/utils.js";
5
+ import { filterProps, hasChanged, matchesAnyClass } from "./internal/utils.js";
5
6
  import { ListItemNode } from "./list-item.js";
6
- import { List } from "./models/list.js";
7
+ import { ListModel } from "./models/list.js";
7
8
  import { WidgetNode } from "./widget.js";
8
- const PROP_NAMES = ["renderItem", "estimatedItemHeight"];
9
+ const OWN_PROPS = ["renderItem", "estimatedItemHeight"];
9
10
  class ListViewNode extends WidgetNode {
10
11
  static priority = 1;
11
12
  itemRenderer;
@@ -15,13 +16,14 @@ class ListViewNode extends WidgetNode {
15
16
  }
16
17
  constructor(typeName, props, container, rootContainer) {
17
18
  super(typeName, props, container, rootContainer);
18
- this.list = new List({
19
+ this.list = new ListModel({ owner: this, signalStore: this.signalStore }, {
19
20
  selectionMode: props.selectionMode,
20
21
  selected: props.selected,
21
22
  onSelectionChanged: props.onSelectionChanged,
22
23
  });
23
- this.itemRenderer = new ListItemRenderer();
24
+ this.itemRenderer = new ListItemRenderer(this.signalStore);
24
25
  this.itemRenderer.setStore(this.list.getStore());
26
+ this.list.getStore().setOnItemUpdated((id) => this.itemRenderer.rebindItem(id));
25
27
  this.container.setFactory(this.itemRenderer.getFactory());
26
28
  }
27
29
  mount() {
@@ -51,19 +53,22 @@ class ListViewNode extends WidgetNode {
51
53
  this.list.removeChild(child);
52
54
  }
53
55
  updateProps(oldProps, newProps) {
54
- if (!oldProps || oldProps.renderItem !== newProps.renderItem) {
55
- this.itemRenderer.setRenderFn(newProps.renderItem);
56
+ super.updateProps(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
57
+ this.applyOwnProps(oldProps, newProps);
58
+ }
59
+ applyOwnProps(oldProps, newProps) {
60
+ if (hasChanged(oldProps, newProps, "renderItem")) {
61
+ this.itemRenderer.setRenderFn(newProps.renderItem ?? null);
56
62
  }
57
- if (!oldProps || oldProps.estimatedItemHeight !== newProps.estimatedItemHeight) {
58
- this.itemRenderer.setEstimatedItemHeight(newProps.estimatedItemHeight);
63
+ if (hasChanged(oldProps, newProps, "estimatedItemHeight")) {
64
+ this.itemRenderer.setEstimatedItemHeight(newProps.estimatedItemHeight ?? null);
59
65
  }
60
66
  const previousModel = this.list.getSelectionModel();
61
- this.list.updateProps(filterProps(oldProps ?? {}, PROP_NAMES), filterProps(newProps, PROP_NAMES));
67
+ this.list.updateProps(oldProps, newProps);
62
68
  const currentModel = this.list.getSelectionModel();
63
- if (previousModel !== currentModel) {
69
+ if (!isObjectEqual(previousModel, currentModel)) {
64
70
  this.container.setModel(currentModel);
65
71
  }
66
- super.updateProps(filterProps(oldProps ?? {}, PROP_NAMES), filterProps(newProps, PROP_NAMES));
67
72
  }
68
73
  }
69
74
  registerNodeClass(ListViewNode);
@@ -1,8 +1,8 @@
1
1
  import type { Container } from "../types.js";
2
- import { Menu, type MenuProps } from "./models/menu.js";
3
- export declare class MenuNode extends Menu {
2
+ import { MenuModel, type MenuProps } from "./models/menu.js";
3
+ export declare class MenuNode extends MenuModel {
4
4
  static priority: number;
5
5
  static matches(type: string): boolean;
6
6
  private static getType;
7
- constructor(typeName: string, props: MenuProps, _container: undefined, rootContainer?: Container);
7
+ constructor(typeName: string, props: MenuProps, _container: undefined, rootContainer: Container);
8
8
  }
@@ -1,7 +1,7 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import { registerNodeClass } from "../registry.js";
3
- import { Menu } from "./models/menu.js";
4
- export class MenuNode extends Menu {
3
+ import { MenuModel } from "./models/menu.js";
4
+ export class MenuNode extends MenuModel {
5
5
  static priority = 1;
6
6
  static matches(type) {
7
7
  return type === "MenuItem" || type === "MenuSection" || type === "MenuSubmenu";
@@ -19,7 +19,7 @@ export class MenuNode extends Menu {
19
19
  throw new Error(`Unable to find menu type '${typeName}'`);
20
20
  }
21
21
  constructor(typeName, props, _container, rootContainer) {
22
- super(MenuNode.getType(typeName), props, undefined, rootContainer instanceof Gtk.Application ? rootContainer : undefined);
22
+ super(MenuNode.getType(typeName), props, rootContainer, undefined, rootContainer instanceof Gtk.Application ? rootContainer : undefined);
23
23
  }
24
24
  }
25
25
  registerNodeClass(MenuNode);
@@ -1,30 +1,28 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import type { Node } from "../../node.js";
3
3
  import { ListStore } from "../internal/list-store.js";
4
- import { VirtualNode } from "../virtual.js";
4
+ import type { SignalStore } from "../internal/signal-store.js";
5
5
  export type ListProps = {
6
6
  selectionMode?: Gtk.SelectionMode;
7
7
  selected?: string[];
8
8
  onSelectionChanged?: (ids: string[]) => void;
9
9
  };
10
- type SelectionModel = Gtk.NoSelection | Gtk.SingleSelection | Gtk.MultiSelection;
11
- export declare class List extends VirtualNode<ListProps> {
10
+ type ListModelConfig = {
11
+ owner: object;
12
+ signalStore: SignalStore;
13
+ };
14
+ export declare class ListModel {
15
+ private config;
12
16
  private store;
13
- private selectionModel;
14
- private handleSelectionChange?;
15
- private pendingSelection?;
16
- private selectionScheduled;
17
- constructor(props?: ListProps);
18
- private initSelectionHandler;
17
+ private selectionManager;
18
+ constructor(config: ListModelConfig, props?: ListProps);
19
19
  getStore(): ListStore;
20
- getSelectionModel(): SelectionModel;
20
+ getSelectionModel(): Gtk.NoSelection | Gtk.SingleSelection | Gtk.MultiSelection;
21
21
  appendChild(child: Node): void;
22
22
  insertBefore(child: Node, before: Node): void;
23
23
  removeChild(child: Node): void;
24
24
  updateProps(oldProps: ListProps | null, newProps: ListProps): void;
25
- private createSelectionModel;
26
25
  private getSelection;
27
- private setSelection;
28
- private applySelection;
26
+ private resolveSelectionIndices;
29
27
  }
30
28
  export {};
@@ -1,37 +1,21 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
- import { CommitPriority, scheduleAfterCommit } from "../../scheduler.js";
3
2
  import { ListStore } from "../internal/list-store.js";
4
- import { signalStore } from "../internal/signal-store.js";
3
+ import { SelectionModelManager } from "../internal/selection-model.js";
5
4
  import { ListItemNode } from "../list-item.js";
6
- import { VirtualNode } from "../virtual.js";
7
- export class List extends VirtualNode {
5
+ export class ListModel {
6
+ config;
8
7
  store;
9
- selectionModel;
10
- handleSelectionChange;
11
- pendingSelection;
12
- selectionScheduled = false;
13
- constructor(props = {}) {
14
- super("", {}, undefined);
8
+ selectionManager;
9
+ constructor(config, props = {}) {
10
+ this.config = config;
15
11
  this.store = new ListStore();
16
- this.selectionModel = this.createSelectionModel(props.selectionMode);
17
- this.selectionModel.setModel(this.store.getModel());
18
- this.initSelectionHandler(props.onSelectionChanged);
19
- }
20
- initSelectionHandler(onSelectionChanged) {
21
- if (!onSelectionChanged) {
22
- signalStore.set(this, this.selectionModel, "selection-changed", null);
23
- return;
24
- }
25
- this.handleSelectionChange = () => {
26
- onSelectionChanged(this.getSelection());
27
- };
28
- signalStore.set(this, this.selectionModel, "selection-changed", this.handleSelectionChange);
12
+ this.selectionManager = new SelectionModelManager({ ...config, ...props }, this.store.getModel(), () => this.getSelection(), (ids) => this.resolveSelectionIndices(ids), () => this.store.getModel().getNItems());
29
13
  }
30
14
  getStore() {
31
15
  return this.store;
32
16
  }
33
17
  getSelectionModel() {
34
- return this.selectionModel;
18
+ return this.selectionManager.getSelectionModel();
35
19
  }
36
20
  appendChild(child) {
37
21
  if (!(child instanceof ListItemNode)) {
@@ -55,39 +39,11 @@ export class List extends VirtualNode {
55
39
  child.setStore(null);
56
40
  }
57
41
  updateProps(oldProps, newProps) {
58
- super.updateProps(oldProps, newProps);
59
- if (oldProps && oldProps.selectionMode !== newProps.selectionMode) {
60
- signalStore.set(this, this.selectionModel, "selection-changed", null);
61
- this.selectionModel = this.createSelectionModel(newProps.selectionMode);
62
- this.selectionModel.setModel(this.store.getModel());
63
- this.initSelectionHandler(newProps.onSelectionChanged);
64
- this.setSelection(newProps.selected);
65
- return;
66
- }
67
- if (!oldProps || oldProps.onSelectionChanged !== newProps.onSelectionChanged) {
68
- this.initSelectionHandler(newProps.onSelectionChanged);
69
- }
70
- if (!oldProps || oldProps.selected !== newProps.selected) {
71
- this.setSelection(newProps.selected);
72
- }
73
- }
74
- createSelectionModel(mode) {
75
- const model = this.store.getModel();
76
- const selectionMode = mode ?? Gtk.SelectionMode.SINGLE;
77
- if (selectionMode === Gtk.SelectionMode.NONE) {
78
- return new Gtk.NoSelection(model);
79
- }
80
- if (selectionMode === Gtk.SelectionMode.MULTIPLE) {
81
- return new Gtk.MultiSelection(model);
82
- }
83
- const selectionModel = new Gtk.SingleSelection(model);
84
- selectionModel.setAutoselect(selectionMode === Gtk.SelectionMode.BROWSE);
85
- selectionModel.setCanUnselect(selectionMode !== Gtk.SelectionMode.BROWSE);
86
- return selectionModel;
42
+ this.selectionManager.update(oldProps ? { ...this.config, ...oldProps } : null, { ...this.config, ...newProps }, this.store.getModel());
87
43
  }
88
44
  getSelection() {
89
45
  const model = this.store.getModel();
90
- const selection = this.selectionModel.getSelection();
46
+ const selection = this.selectionManager.getSelectionModel().getSelection();
91
47
  const size = selection.getSize();
92
48
  const ids = [];
93
49
  for (let i = 0; i < size; i++) {
@@ -99,29 +55,16 @@ export class List extends VirtualNode {
99
55
  }
100
56
  return ids;
101
57
  }
102
- setSelection(ids) {
103
- this.pendingSelection = ids;
104
- if (!this.selectionScheduled) {
105
- this.selectionScheduled = true;
106
- scheduleAfterCommit(() => this.applySelection(), CommitPriority.LOW);
107
- }
108
- }
109
- applySelection() {
110
- this.selectionScheduled = false;
111
- const ids = this.pendingSelection;
112
- this.pendingSelection = undefined;
58
+ resolveSelectionIndices(ids) {
113
59
  const model = this.store.getModel();
114
60
  const nItems = model.getNItems();
115
61
  const selected = new Gtk.Bitset();
116
- const mask = Gtk.Bitset.newRange(0, nItems);
117
- if (ids) {
118
- for (const id of ids) {
119
- const index = model.find(id);
120
- if (index < nItems) {
121
- selected.add(index);
122
- }
62
+ for (const id of ids) {
63
+ const index = model.find(id);
64
+ if (index < nItems) {
65
+ selected.add(index);
123
66
  }
124
67
  }
125
- this.selectionModel.setSelection(selected, mask);
68
+ return selected;
126
69
  }
127
70
  }
@@ -1,6 +1,7 @@
1
1
  import * as Gio from "@gtkx/ffi/gio";
2
2
  import type * as Gtk from "@gtkx/ffi/gtk";
3
3
  import type { Node } from "../../node.js";
4
+ import type { Container } from "../../types.js";
4
5
  import { VirtualNode } from "../virtual.js";
5
6
  export type MenuType = "root" | "item" | "section" | "submenu";
6
7
  export type MenuProps = {
@@ -9,16 +10,16 @@ export type MenuProps = {
9
10
  accels?: string | string[];
10
11
  onActivate?: () => void;
11
12
  };
12
- export declare class Menu extends VirtualNode<MenuProps> {
13
- private actionMap?;
13
+ export declare class MenuModel extends VirtualNode<MenuProps> {
14
+ private actionMap;
14
15
  private actionPrefix;
15
- private parent?;
16
+ private parent;
16
17
  private menu;
17
18
  private type;
18
- private application?;
19
- private action?;
19
+ private application;
20
+ private action;
20
21
  private children;
21
- constructor(type: MenuType, props: MenuProps, actionMap?: Gio.ActionMap, application?: Gtk.Application);
22
+ constructor(type: MenuType, props: MenuProps, rootContainer: Container, actionMap?: Gio.ActionMap, application?: Gtk.Application);
22
23
  setActionMap(actionMap: Gio.ActionMap, prefix: string): void;
23
24
  private getAccels;
24
25
  private getActionName;
@@ -34,7 +35,7 @@ export declare class Menu extends VirtualNode<MenuProps> {
34
35
  getMenu(): Gio.Menu;
35
36
  private getAction;
36
37
  removeFromParent(): void;
37
- insertInParentBefore(before: Menu): void;
38
+ insertInParentBefore(before: MenuModel): void;
38
39
  appendToParent(): void;
39
40
  appendChild(child: Node): void;
40
41
  insertBefore(child: Node, before: Node): void;
@@ -1,23 +1,22 @@
1
- import { batch, isObjectEqual } from "@gtkx/ffi";
1
+ import { isObjectEqual } from "@gtkx/ffi";
2
2
  import * as Gio from "@gtkx/ffi/gio";
3
3
  import { CommitPriority, scheduleAfterCommit } from "../../scheduler.js";
4
- import { signalStore } from "../internal/signal-store.js";
5
4
  import { VirtualNode } from "../virtual.js";
6
- export class Menu extends VirtualNode {
7
- actionMap;
5
+ export class MenuModel extends VirtualNode {
6
+ actionMap = null;
8
7
  actionPrefix;
9
- parent;
8
+ parent = null;
10
9
  menu;
11
10
  type;
12
- application;
13
- action;
11
+ application = null;
12
+ action = null;
14
13
  children = [];
15
- constructor(type, props, actionMap, application) {
16
- super("", props, undefined);
14
+ constructor(type, props, rootContainer, actionMap, application) {
15
+ super("", props, undefined, rootContainer);
17
16
  this.type = type;
18
- this.actionMap = actionMap;
17
+ this.actionMap = actionMap ?? null;
19
18
  this.actionPrefix = application ? "app" : "menu";
20
- this.application = application;
19
+ this.application = application ?? null;
21
20
  this.menu = new Gio.Menu();
22
21
  }
23
22
  setActionMap(actionMap, prefix) {
@@ -65,29 +64,25 @@ export class Menu extends VirtualNode {
65
64
  return this.actionMap;
66
65
  }
67
66
  createAction() {
68
- batch(() => {
69
- if (this.action) {
70
- signalStore.set(this, this.action, "activate", undefined);
71
- }
72
- this.action = new Gio.SimpleAction(this.getId());
73
- signalStore.set(this, this.action, "activate", this.getOnActivate());
74
- this.getActionMap().addAction(this.action);
75
- if (this.application && this.props.accels) {
76
- this.application.setAccelsForAction(this.getActionName(), this.getAccels());
77
- }
78
- });
67
+ if (this.action) {
68
+ this.signalStore.set(this, this.action, "activate", null);
69
+ }
70
+ this.action = new Gio.SimpleAction(this.getId());
71
+ this.signalStore.set(this, this.action, "activate", this.getOnActivate());
72
+ this.getActionMap().addAction(this.action);
73
+ if (this.application && this.props.accels) {
74
+ this.application.setAccelsForAction(this.getActionName(), this.getAccels());
75
+ }
79
76
  }
80
77
  removeAction() {
81
- batch(() => {
82
- if (this.application && this.props.accels) {
83
- this.application.setAccelsForAction(this.getActionName(), []);
84
- }
85
- if (this.action) {
86
- this.getActionMap().removeAction(this.getId());
87
- signalStore.set(this, this.action, "activate", undefined);
88
- this.action = undefined;
89
- }
90
- });
78
+ if (this.application && this.props.accels) {
79
+ this.application.setAccelsForAction(this.getActionName(), []);
80
+ }
81
+ if (this.action) {
82
+ this.getActionMap().removeAction(this.getId());
83
+ this.signalStore.set(this, this.action, "activate", null);
84
+ this.action = null;
85
+ }
91
86
  }
92
87
  getPosition() {
93
88
  return this.findPositionIn(this.getParent());
@@ -125,7 +120,7 @@ export class Menu extends VirtualNode {
125
120
  if (!this.parent)
126
121
  return;
127
122
  const parent = this.parent;
128
- this.parent = undefined;
123
+ this.parent = null;
129
124
  scheduleAfterCommit(() => {
130
125
  const position = this.findPositionIn(parent);
131
126
  if (position >= 0) {
@@ -152,7 +147,7 @@ export class Menu extends VirtualNode {
152
147
  parent.insertSubmenu(beforePosition, this.menu, this.props.label);
153
148
  break;
154
149
  }
155
- });
150
+ }, CommitPriority.NORMAL);
156
151
  }
157
152
  appendToParent() {
158
153
  if (this.type === "item" && this.actionMap) {
@@ -171,10 +166,10 @@ export class Menu extends VirtualNode {
171
166
  parent.appendSubmenu(this.menu, this.props.label);
172
167
  break;
173
168
  }
174
- });
169
+ }, CommitPriority.NORMAL);
175
170
  }
176
171
  appendChild(child) {
177
- if (!(child instanceof Menu)) {
172
+ if (!(child instanceof MenuModel)) {
178
173
  return;
179
174
  }
180
175
  this.children.push(child);
@@ -185,7 +180,7 @@ export class Menu extends VirtualNode {
185
180
  child.appendToParent();
186
181
  }
187
182
  insertBefore(child, before) {
188
- if (!(child instanceof Menu) || !(before instanceof Menu)) {
183
+ if (!(child instanceof MenuModel) || !(before instanceof MenuModel)) {
189
184
  return;
190
185
  }
191
186
  const beforeIndex = this.children.indexOf(before);
@@ -202,7 +197,7 @@ export class Menu extends VirtualNode {
202
197
  child.insertInParentBefore(before);
203
198
  }
204
199
  removeChild(child) {
205
- if (!(child instanceof Menu)) {
200
+ if (!(child instanceof MenuModel)) {
206
201
  return;
207
202
  }
208
203
  const index = this.children.indexOf(child);
@@ -237,7 +232,7 @@ export class Menu extends VirtualNode {
237
232
  return;
238
233
  }
239
234
  if (oldProps.onActivate !== newProps.onActivate) {
240
- signalStore.set(this, this.getAction(), "activate", newProps.onActivate);
235
+ this.signalStore.set(this, this.getAction(), "activate", newProps.onActivate);
241
236
  }
242
237
  if (oldProps.accels !== newProps.accels) {
243
238
  if (this.application) {
@@ -251,18 +246,16 @@ export class Menu extends VirtualNode {
251
246
  }
252
247
  if (!oldProps || oldProps.label !== newProps.label) {
253
248
  const parent = this.parent;
254
- batch(() => {
255
- const position = this.findPositionIn(parent);
256
- if (position >= 0) {
257
- parent.remove(position);
258
- if (this.type === "section") {
259
- parent.insertSection(position, this.menu, this.props.label);
260
- }
261
- else if (this.type === "submenu") {
262
- parent.insertSubmenu(position, this.menu, this.props.label);
263
- }
249
+ const position = this.findPositionIn(parent);
250
+ if (position >= 0) {
251
+ parent.remove(position);
252
+ if (this.type === "section") {
253
+ parent.insertSection(position, this.menu, this.props.label);
254
+ }
255
+ else if (this.type === "submenu") {
256
+ parent.insertSubmenu(position, this.menu, this.props.label);
264
257
  }
265
- });
258
+ }
266
259
  }
267
260
  }
268
261
  unmount() {
@@ -1,5 +1,6 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import type { Node } from "../../node.js";
3
+ import type { Container } from "../../types.js";
3
4
  import { TreeStore } from "../internal/tree-store.js";
4
5
  import { VirtualNode } from "../virtual.js";
5
6
  export type TreeListProps = {
@@ -8,27 +9,20 @@ export type TreeListProps = {
8
9
  selected?: string[];
9
10
  onSelectionChanged?: (ids: string[]) => void;
10
11
  };
11
- type SelectionModel = Gtk.NoSelection | Gtk.SingleSelection | Gtk.MultiSelection;
12
12
  export declare class TreeList extends VirtualNode<TreeListProps> {
13
13
  private store;
14
14
  private treeListModel;
15
- private selectionModel;
16
- private handleSelectionChange?;
17
- private pendingSelection?;
18
- private selectionScheduled;
19
- constructor(props?: TreeListProps);
20
- private initSelectionHandler;
15
+ private selectionManager;
16
+ constructor(props: TreeListProps | undefined, rootContainer: Container);
21
17
  private createChildModel;
22
18
  getStore(): TreeStore;
23
19
  getTreeListModel(): Gtk.TreeListModel;
24
- getSelectionModel(): SelectionModel;
20
+ getSelectionModel(): Gtk.NoSelection | Gtk.SingleSelection | Gtk.MultiSelection;
25
21
  appendChild(child: Node): void;
22
+ private addItemWithChildren;
26
23
  insertBefore(child: Node, before: Node): void;
27
24
  removeChild(child: Node): void;
28
25
  updateProps(oldProps: TreeListProps | null, newProps: TreeListProps): void;
29
- private createSelectionModel;
30
26
  private getSelection;
31
- private setSelection;
32
- private applySelection;
27
+ private resolveSelectionIndices;
33
28
  }
34
- export {};