@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
@@ -1,62 +1,60 @@
1
- import { batch, isObjectEqual } from "@gtkx/ffi";
1
+ import { isObjectEqual } from "@gtkx/ffi";
2
+ import * as Gtk from "@gtkx/ffi/gtk";
2
3
  import { registerNodeClass } from "../registry.js";
3
- import { SlotNode } from "./slot.js";
4
- class GridChildNode extends SlotNode {
4
+ import { PositionalChildNode } from "./abstract/positional-child.js";
5
+ import { hasChanged } from "./internal/utils.js";
6
+ class GridChildNode extends PositionalChildNode {
5
7
  static priority = 1;
6
8
  static matches(type) {
7
9
  return type === "GridChild";
8
10
  }
11
+ canBeChildOf(parent) {
12
+ return parent.container instanceof Gtk.Grid;
13
+ }
14
+ attachToParent(parent, child) {
15
+ const grid = parent;
16
+ const column = this.props.column ?? 0;
17
+ const row = this.props.row ?? 0;
18
+ const columnSpan = this.props.columnSpan ?? 1;
19
+ const rowSpan = this.props.rowSpan ?? 1;
20
+ const existingChild = grid.getChildAt(column, row);
21
+ if (existingChild && !isObjectEqual(existingChild, child)) {
22
+ grid.remove(existingChild);
23
+ }
24
+ grid.attach(child, column, row, columnSpan, rowSpan);
25
+ }
26
+ detachFromParent(parent, child) {
27
+ parent.remove(child);
28
+ }
9
29
  updateProps(oldProps, newProps) {
10
30
  super.updateProps(oldProps, newProps);
11
- if (!oldProps ||
12
- oldProps.column !== newProps.column ||
13
- oldProps.row !== newProps.row ||
14
- oldProps.columnSpan !== newProps.columnSpan ||
15
- oldProps.rowSpan !== newProps.rowSpan) {
16
- if (this.parent && this.child) {
17
- this.attachChild();
18
- }
19
- }
31
+ this.applyOwnProps(oldProps, newProps);
20
32
  }
21
- getGrid() {
22
- if (!this.parent) {
23
- throw new Error("Expected Grid reference to be set on GridChildNode");
33
+ applyOwnProps(oldProps, newProps) {
34
+ const positionChanged = hasChanged(oldProps, newProps, "column") ||
35
+ hasChanged(oldProps, newProps, "row") ||
36
+ hasChanged(oldProps, newProps, "columnSpan") ||
37
+ hasChanged(oldProps, newProps, "rowSpan");
38
+ if (positionChanged && this.parent && this.child) {
39
+ this.reattachChild();
24
40
  }
25
- return this.parent;
26
41
  }
27
- attachChild() {
28
- const grid = this.getGrid();
42
+ reattachChild() {
43
+ const grid = this.getTypedParent();
44
+ const child = this.child;
45
+ if (!child) {
46
+ return;
47
+ }
29
48
  const column = this.props.column ?? 0;
30
49
  const row = this.props.row ?? 0;
31
50
  const columnSpan = this.props.columnSpan ?? 1;
32
51
  const rowSpan = this.props.rowSpan ?? 1;
33
- batch(() => {
34
- const existingChild = grid.getChildAt(column, row);
35
- if (existingChild && this.child && !isObjectEqual(existingChild, this.child)) {
36
- grid.remove(existingChild);
37
- }
38
- if (this.child) {
39
- const currentParent = this.child.getParent();
40
- if (currentParent && isObjectEqual(currentParent, grid)) {
41
- grid.remove(this.child);
42
- }
43
- grid.attach(this.child, column, row, columnSpan, rowSpan);
44
- }
45
- });
46
- }
47
- onChildChange(oldChild) {
48
- const grid = this.getGrid();
49
- batch(() => {
50
- if (oldChild) {
51
- const parent = oldChild.getParent();
52
- if (parent && isObjectEqual(parent, grid)) {
53
- grid.remove(oldChild);
54
- }
55
- }
56
- if (this.child) {
57
- this.attachChild();
58
- }
59
- });
52
+ const existingChild = grid.getChildAt(column, row);
53
+ if (existingChild && !isObjectEqual(existingChild, child)) {
54
+ grid.remove(existingChild);
55
+ }
56
+ grid.remove(child);
57
+ grid.attach(child, column, row, columnSpan, rowSpan);
60
58
  }
61
59
  }
62
60
  registerNodeClass(GridChildNode);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { isAttachable } from "./internal/predicates.js";
4
+ import { matchesAnyClass } from "./internal/utils.js";
5
+ import { SlotNode } from "./slot.js";
6
+ import { WidgetNode } from "./widget.js";
7
+ class GridNode extends WidgetNode {
8
+ static priority = 0;
9
+ static matches(_type, containerOrClass) {
10
+ return matchesAnyClass([Gtk.Grid], containerOrClass);
11
+ }
12
+ isGridChild(child) {
13
+ return child.typeName === "GridChild";
14
+ }
15
+ appendChild(child) {
16
+ if (child instanceof SlotNode) {
17
+ super.appendChild(child);
18
+ return;
19
+ }
20
+ if (isAttachable(child) && this.isGridChild(child)) {
21
+ child.attachTo(this);
22
+ return;
23
+ }
24
+ throw new Error(`Cannot append '${child.typeName}' to 'Grid': expected x.GridChild`);
25
+ }
26
+ insertBefore(child, _before) {
27
+ this.appendChild(child);
28
+ }
29
+ removeChild(child) {
30
+ if (child instanceof SlotNode) {
31
+ super.removeChild(child);
32
+ return;
33
+ }
34
+ if (isAttachable(child) && this.isGridChild(child)) {
35
+ child.detachFrom(this);
36
+ return;
37
+ }
38
+ throw new Error(`Cannot remove '${child.typeName}' from 'Grid': expected x.GridChild`);
39
+ }
40
+ }
41
+ registerNodeClass(GridNode);
@@ -1,17 +1,18 @@
1
- import "./action-row-child.js";
2
- import "./action-row.js";
1
+ import "./adjustable.js";
2
+ import "./animation.js";
3
+ import "./alert-dialog-response.js";
3
4
  import "./application.js";
4
5
  import "./autowrapped.js";
5
- import "./calendar-mark.js";
6
6
  import "./calendar.js";
7
+ import "./color-dialog-button.js";
7
8
  import "./column-view-column.js";
8
9
  import "./column-view.js";
10
+ import "./dialog.js";
9
11
  import "./drawing-area.js";
10
- import "./expander-row-child.js";
11
- import "./expander-row.js";
12
12
  import "./fixed-child.js";
13
+ import "./font-dialog-button.js";
14
+ import "./grid.js";
13
15
  import "./grid-child.js";
14
- import "./level-bar-offset.js";
15
16
  import "./level-bar.js";
16
17
  import "./list-item.js";
17
18
  import "./list-view.js";
@@ -22,23 +23,24 @@ import "./notebook-page-tab.js";
22
23
  import "./notebook-page.js";
23
24
  import "./notebook.js";
24
25
  import "./overlay-child.js";
25
- import "./pack-child.js";
26
- import "./pack.js";
27
26
  import "./popover-menu.js";
28
- import "./adjustment.js";
29
- import "./scale-mark.js";
30
27
  import "./scale.js";
31
28
  import "./scrolled-window.js";
29
+ import "./search-bar.js";
32
30
  import "./shortcut-controller.js";
33
31
  import "./shortcut.js";
32
+ import "./event-controller.js";
34
33
  import "./simple-list-item.js";
35
34
  import "./simple-list-view.js";
36
35
  import "./slot.js";
37
- import "./source-buffer.js";
38
36
  import "./source-view.js";
39
37
  import "./stack-page.js";
40
38
  import "./stack.js";
41
- import "./text-buffer.js";
39
+ import "./text-anchor.js";
40
+ import "./text-content.js";
41
+ import "./text-paintable.js";
42
+ import "./text-segment.js";
43
+ import "./text-tag.js";
42
44
  import "./text-view.js";
43
45
  import "./toggle.js";
44
46
  import "./toggle-group.js";
@@ -46,5 +48,9 @@ import "./toolbar-child.js";
46
48
  import "./tree-list-item.js";
47
49
  import "./tree-list-view.js";
48
50
  import "./virtual.js";
51
+ import "./web-view.js";
52
+ import "./action-row-child.js";
53
+ import "./expander-row-child.js";
54
+ import "./pack-child.js";
49
55
  import "./widget.js";
50
56
  import "./window.js";
@@ -1,17 +1,18 @@
1
- import "./action-row-child.js";
2
- import "./action-row.js";
1
+ import "./adjustable.js";
2
+ import "./animation.js";
3
+ import "./alert-dialog-response.js";
3
4
  import "./application.js";
4
5
  import "./autowrapped.js";
5
- import "./calendar-mark.js";
6
6
  import "./calendar.js";
7
+ import "./color-dialog-button.js";
7
8
  import "./column-view-column.js";
8
9
  import "./column-view.js";
10
+ import "./dialog.js";
9
11
  import "./drawing-area.js";
10
- import "./expander-row-child.js";
11
- import "./expander-row.js";
12
12
  import "./fixed-child.js";
13
+ import "./font-dialog-button.js";
14
+ import "./grid.js";
13
15
  import "./grid-child.js";
14
- import "./level-bar-offset.js";
15
16
  import "./level-bar.js";
16
17
  import "./list-item.js";
17
18
  import "./list-view.js";
@@ -22,23 +23,24 @@ import "./notebook-page-tab.js";
22
23
  import "./notebook-page.js";
23
24
  import "./notebook.js";
24
25
  import "./overlay-child.js";
25
- import "./pack-child.js";
26
- import "./pack.js";
27
26
  import "./popover-menu.js";
28
- import "./adjustment.js";
29
- import "./scale-mark.js";
30
27
  import "./scale.js";
31
28
  import "./scrolled-window.js";
29
+ import "./search-bar.js";
32
30
  import "./shortcut-controller.js";
33
31
  import "./shortcut.js";
32
+ import "./event-controller.js";
34
33
  import "./simple-list-item.js";
35
34
  import "./simple-list-view.js";
36
35
  import "./slot.js";
37
- import "./source-buffer.js";
38
36
  import "./source-view.js";
39
37
  import "./stack-page.js";
40
38
  import "./stack.js";
41
- import "./text-buffer.js";
39
+ import "./text-anchor.js";
40
+ import "./text-content.js";
41
+ import "./text-paintable.js";
42
+ import "./text-segment.js";
43
+ import "./text-tag.js";
42
44
  import "./text-view.js";
43
45
  import "./toggle.js";
44
46
  import "./toggle-group.js";
@@ -46,5 +48,9 @@ import "./toolbar-child.js";
46
48
  import "./tree-list-item.js";
47
49
  import "./tree-list-view.js";
48
50
  import "./virtual.js";
51
+ import "./web-view.js";
52
+ import "./action-row-child.js";
53
+ import "./expander-row-child.js";
54
+ import "./pack-child.js";
49
55
  import "./widget.js";
50
56
  import "./window.js";
@@ -0,0 +1,29 @@
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { ReactNode } from "react";
3
+ import type Reconciler from "react-reconciler";
4
+ import type { SignalStore } from "./signal-store.js";
5
+ export declare abstract class BaseItemRenderer<TStore = unknown> {
6
+ protected factory: Gtk.SignalListItemFactory;
7
+ protected fiberRoots: Map<number, any>;
8
+ protected tornDown: Set<number>;
9
+ protected estimatedItemHeight: number | null;
10
+ private store;
11
+ protected signalStore: SignalStore;
12
+ protected abstract getStoreTypeName(): string;
13
+ constructor(signalStore: SignalStore);
14
+ getFactory(): Gtk.SignalListItemFactory;
15
+ setEstimatedItemHeight(height: number | null): void;
16
+ setStore(store: TStore | null): void;
17
+ protected getStore(): TStore;
18
+ dispose(): void;
19
+ protected abstract renderItem(ptr: number): ReactNode;
20
+ protected abstract getItemFromListItem(listItem: Gtk.ListItem): unknown;
21
+ protected abstract onSetup(listItem: Gtk.ListItem, ptr: number): Gtk.Widget;
22
+ protected abstract onBind(listItem: Gtk.ListItem, ptr: number, fiberRoot: Reconciler.FiberRoot): void;
23
+ protected abstract onUnbind(listItem: Gtk.ListItem): void;
24
+ protected abstract onTeardown(listItem: Gtk.ListItem, ptr: number): void;
25
+ protected onSetupComplete(_ptr: number): void;
26
+ protected createBox(): Gtk.Box;
27
+ protected clearBoxSizeRequest(box: Gtk.Widget): void;
28
+ private initializeFactory;
29
+ }
@@ -0,0 +1,88 @@
1
+ import { getNativeId } from "@gtkx/ffi";
2
+ import * as Gtk from "@gtkx/ffi/gtk";
3
+ import { createFiberRoot } from "../../fiber-root.js";
4
+ import { reconciler } from "../../reconciler.js";
5
+ export class BaseItemRenderer {
6
+ factory;
7
+ fiberRoots = new Map();
8
+ tornDown = new Set();
9
+ estimatedItemHeight = null;
10
+ store = null;
11
+ signalStore;
12
+ constructor(signalStore) {
13
+ this.signalStore = signalStore;
14
+ this.factory = new Gtk.SignalListItemFactory();
15
+ this.initializeFactory();
16
+ }
17
+ getFactory() {
18
+ return this.factory;
19
+ }
20
+ setEstimatedItemHeight(height) {
21
+ this.estimatedItemHeight = height;
22
+ }
23
+ setStore(store) {
24
+ this.store = store;
25
+ }
26
+ getStore() {
27
+ if (!this.store) {
28
+ throw new Error(`Expected ${this.getStoreTypeName()} to be set on ${this.constructor.name}`);
29
+ }
30
+ return this.store;
31
+ }
32
+ dispose() {
33
+ this.signalStore.clear(this);
34
+ this.fiberRoots.clear();
35
+ this.tornDown.clear();
36
+ }
37
+ onSetupComplete(_ptr) { }
38
+ createBox() {
39
+ const box = new Gtk.Box(Gtk.Orientation.HORIZONTAL);
40
+ box.setValign(Gtk.Align.CENTER);
41
+ if (this.estimatedItemHeight !== null) {
42
+ box.setSizeRequest(-1, this.estimatedItemHeight);
43
+ }
44
+ return box;
45
+ }
46
+ clearBoxSizeRequest(box) {
47
+ if (box instanceof Gtk.Box) {
48
+ box.setSizeRequest(-1, -1);
49
+ }
50
+ }
51
+ initializeFactory() {
52
+ this.signalStore.set(this, this.factory, "setup", (listItem) => {
53
+ const ptr = getNativeId(listItem.handle);
54
+ const container = this.onSetup(listItem, ptr);
55
+ const fiberRoot = createFiberRoot(container);
56
+ this.fiberRoots.set(ptr, fiberRoot);
57
+ const element = this.renderItem(ptr);
58
+ reconciler.getInstance().updateContainer(element, fiberRoot, null, () => {
59
+ if (this.tornDown.has(ptr))
60
+ return;
61
+ this.onSetupComplete(ptr);
62
+ });
63
+ });
64
+ this.signalStore.set(this, this.factory, "bind", (listItem) => {
65
+ const ptr = getNativeId(listItem.handle);
66
+ const fiberRoot = this.fiberRoots.get(ptr);
67
+ if (!fiberRoot)
68
+ return;
69
+ this.onBind(listItem, ptr, fiberRoot);
70
+ });
71
+ this.signalStore.set(this, this.factory, "unbind", (listItem) => {
72
+ this.onUnbind(listItem);
73
+ });
74
+ this.signalStore.set(this, this.factory, "teardown", (listItem) => {
75
+ const ptr = getNativeId(listItem.handle);
76
+ const fiberRoot = this.fiberRoots.get(ptr);
77
+ if (fiberRoot) {
78
+ this.tornDown.add(ptr);
79
+ this.onTeardown(listItem, ptr);
80
+ reconciler.getInstance().updateContainer(null, fiberRoot, null, () => { });
81
+ queueMicrotask(() => {
82
+ this.fiberRoots.delete(ptr);
83
+ this.tornDown.delete(ptr);
84
+ });
85
+ }
86
+ });
87
+ }
88
+ }
@@ -0,0 +1,26 @@
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
+ type AttachmentStrategy = {
3
+ type: "appendable";
4
+ container: Gtk.Widget & {
5
+ append(child: Gtk.Widget): void;
6
+ };
7
+ } | {
8
+ type: "addable";
9
+ container: Gtk.Widget & {
10
+ add(child: Gtk.Widget): void;
11
+ };
12
+ } | {
13
+ type: "content";
14
+ container: Gtk.Widget & {
15
+ setContent(content: Gtk.Widget | null): void;
16
+ };
17
+ } | {
18
+ type: "singleChild";
19
+ container: Gtk.Widget & {
20
+ setChild(child: Gtk.Widget | null): void;
21
+ };
22
+ };
23
+ export declare const getAttachmentStrategy: (container: Gtk.Widget) => AttachmentStrategy | null;
24
+ export declare const attachChild: (child: Gtk.Widget, strategy: AttachmentStrategy) => void;
25
+ export declare const detachChild: (child: Gtk.Widget, strategy: AttachmentStrategy) => void;
26
+ export {};
@@ -0,0 +1,48 @@
1
+ import { isAddable, isAppendable, isContentWidget, isRemovable, isSingleChild } from "./predicates.js";
2
+ export const getAttachmentStrategy = (container) => {
3
+ if (isAppendable(container)) {
4
+ return { type: "appendable", container };
5
+ }
6
+ if (isAddable(container)) {
7
+ return { type: "addable", container };
8
+ }
9
+ if (isContentWidget(container)) {
10
+ return { type: "content", container };
11
+ }
12
+ if (isSingleChild(container)) {
13
+ return { type: "singleChild", container };
14
+ }
15
+ return null;
16
+ };
17
+ export const attachChild = (child, strategy) => {
18
+ switch (strategy.type) {
19
+ case "appendable":
20
+ strategy.container.append(child);
21
+ break;
22
+ case "addable":
23
+ strategy.container.add(child);
24
+ break;
25
+ case "content":
26
+ strategy.container.setContent(child);
27
+ break;
28
+ case "singleChild":
29
+ strategy.container.setChild(child);
30
+ break;
31
+ }
32
+ };
33
+ export const detachChild = (child, strategy) => {
34
+ switch (strategy.type) {
35
+ case "appendable":
36
+ case "addable":
37
+ if (isRemovable(strategy.container)) {
38
+ strategy.container.remove(child);
39
+ }
40
+ break;
41
+ case "content":
42
+ strategy.container.setContent(null);
43
+ break;
44
+ case "singleChild":
45
+ strategy.container.setChild(null);
46
+ break;
47
+ }
48
+ };
@@ -0,0 +1,9 @@
1
+ import { type CommitPriority } from "../../scheduler.js";
2
+ export declare class DeferredAction {
3
+ private action;
4
+ private priority;
5
+ private scheduled;
6
+ constructor(action: () => void, priority: CommitPriority);
7
+ get isPending(): boolean;
8
+ schedule(): void;
9
+ }
@@ -0,0 +1,22 @@
1
+ import { scheduleAfterCommit } from "../../scheduler.js";
2
+ export class DeferredAction {
3
+ action;
4
+ priority;
5
+ scheduled = false;
6
+ constructor(action, priority) {
7
+ this.action = action;
8
+ this.priority = priority;
9
+ }
10
+ get isPending() {
11
+ return this.scheduled;
12
+ }
13
+ schedule() {
14
+ if (this.scheduled)
15
+ return;
16
+ this.scheduled = true;
17
+ scheduleAfterCommit(() => {
18
+ this.scheduled = false;
19
+ this.action();
20
+ }, this.priority);
21
+ }
22
+ }
@@ -1,20 +1,19 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import type { ReactNode } from "react";
3
+ import type Reconciler from "react-reconciler";
4
+ import { BaseItemRenderer } from "./base-item-renderer.js";
3
5
  import type { ListStore } from "./list-store.js";
4
6
  export type RenderItemFn<T> = (item: T | null) => ReactNode;
5
- export declare class ListItemRenderer {
6
- private factory;
7
- private store?;
8
- private fiberRoots;
9
- private tornDown;
10
- private renderFn?;
11
- private estimatedItemHeight?;
12
- constructor();
13
- getFactory(): Gtk.SignalListItemFactory;
14
- setRenderFn(renderFn?: RenderItemFn<unknown>): void;
15
- setStore(store?: ListStore | null): void;
16
- setEstimatedItemHeight(height?: number): void;
17
- private getStore;
18
- dispose(): void;
19
- private initialize;
7
+ export declare class ListItemRenderer extends BaseItemRenderer<ListStore> {
8
+ private renderFn;
9
+ private boundItems;
10
+ setRenderFn(renderFn: RenderItemFn<unknown> | null): void;
11
+ rebindItem(id: string): void;
12
+ protected getStoreTypeName(): string;
13
+ protected renderItem(_ptr: number): ReactNode;
14
+ protected getItemFromListItem(listItem: Gtk.ListItem): string | null;
15
+ protected onSetup(listItem: Gtk.ListItem, _ptr: number): Gtk.Widget;
16
+ protected onBind(listItem: Gtk.ListItem, ptr: number, fiberRoot: Reconciler.FiberRoot): void;
17
+ protected onUnbind(listItem: Gtk.ListItem): void;
18
+ protected onTeardown(_listItem: Gtk.ListItem, _ptr: number): void;
20
19
  }