@gtkx/react 0.14.0 → 0.16.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.
Files changed (182) hide show
  1. package/README.md +28 -27
  2. package/dist/errors.js +3 -0
  3. package/dist/factory.d.ts +3 -2
  4. package/dist/factory.js +1 -1
  5. package/dist/generated/internal.d.ts +28 -1
  6. package/dist/generated/internal.js +93 -18
  7. package/dist/generated/jsx.d.ts +1712 -1516
  8. package/dist/generated/jsx.js +475 -0
  9. package/dist/host-config.d.ts +3 -1
  10. package/dist/host-config.js +31 -11
  11. package/dist/jsx.d.ts +147 -97
  12. package/dist/jsx.js +89 -21
  13. package/dist/node.d.ts +3 -1
  14. package/dist/node.js +5 -3
  15. package/dist/nodes/abstract/positional-child.d.ts +9 -0
  16. package/dist/nodes/abstract/positional-child.js +29 -0
  17. package/dist/nodes/abstract/positional-parent.d.ts +18 -0
  18. package/dist/nodes/abstract/positional-parent.js +48 -0
  19. package/dist/nodes/abstract/virtual-container.d.ts +17 -0
  20. package/dist/nodes/abstract/virtual-container.js +59 -0
  21. package/dist/nodes/abstract/virtual-single-child.d.ts +18 -0
  22. package/dist/nodes/abstract/virtual-single-child.js +54 -0
  23. package/dist/nodes/action-row-child.d.ts +0 -13
  24. package/dist/nodes/action-row-child.js +14 -12
  25. package/dist/nodes/action-row.d.ts +6 -1
  26. package/dist/nodes/action-row.js +4 -37
  27. package/dist/nodes/adjustable.d.ts +23 -0
  28. package/dist/nodes/adjustable.js +62 -0
  29. package/dist/nodes/alert-dialog-response.d.ts +1 -0
  30. package/dist/nodes/alert-dialog-response.js +86 -0
  31. package/dist/nodes/animation/animation-controller.d.ts +17 -0
  32. package/dist/nodes/animation/animation-controller.js +107 -0
  33. package/dist/nodes/animation/animation-factory.d.ts +15 -0
  34. package/dist/nodes/animation/animation-factory.js +25 -0
  35. package/dist/nodes/animation/animation-node.d.ts +9 -0
  36. package/dist/nodes/animation/animation-node.js +126 -0
  37. package/dist/nodes/animation/animation-style-sheet.d.ts +16 -0
  38. package/dist/nodes/animation/animation-style-sheet.js +74 -0
  39. package/dist/nodes/animation/index.d.ts +4 -0
  40. package/dist/nodes/animation/index.js +1 -0
  41. package/dist/nodes/animation/property-mapper.d.ts +11 -0
  42. package/dist/nodes/animation/property-mapper.js +36 -0
  43. package/dist/nodes/animation/transform-state.d.ts +11 -0
  44. package/dist/nodes/animation/transform-state.js +57 -0
  45. package/dist/nodes/animation/widget-registry.d.ts +5 -0
  46. package/dist/nodes/animation/widget-registry.js +42 -0
  47. package/dist/nodes/application.js +17 -7
  48. package/dist/nodes/autowrapped.js +37 -43
  49. package/dist/nodes/calendar.js +16 -55
  50. package/dist/nodes/color-dialog-button.d.ts +1 -0
  51. package/dist/nodes/color-dialog-button.js +70 -0
  52. package/dist/nodes/column-view-column.d.ts +4 -3
  53. package/dist/nodes/column-view-column.js +5 -1
  54. package/dist/nodes/column-view.js +40 -43
  55. package/dist/nodes/dialog.d.ts +11 -0
  56. package/dist/nodes/dialog.js +20 -0
  57. package/dist/nodes/drawing-area.d.ts +1 -0
  58. package/dist/nodes/drawing-area.js +36 -0
  59. package/dist/nodes/event-controller.d.ts +1 -0
  60. package/dist/nodes/event-controller.js +96 -0
  61. package/dist/nodes/expander-row-child.d.ts +0 -14
  62. package/dist/nodes/expander-row-child.js +14 -12
  63. package/dist/nodes/expander-row.d.ts +6 -1
  64. package/dist/nodes/expander-row.js +11 -47
  65. package/dist/nodes/fixed-child.js +48 -36
  66. package/dist/nodes/font-dialog-button.d.ts +1 -0
  67. package/dist/nodes/font-dialog-button.js +90 -0
  68. package/dist/nodes/grid-child.js +39 -45
  69. package/dist/nodes/grid.d.ts +1 -0
  70. package/dist/nodes/grid.js +41 -0
  71. package/dist/nodes/index.d.ts +22 -6
  72. package/dist/nodes/index.js +22 -6
  73. package/dist/nodes/internal/base-item-renderer.d.ts +29 -0
  74. package/dist/nodes/internal/base-item-renderer.js +88 -0
  75. package/dist/nodes/internal/base-store.d.ts +9 -0
  76. package/dist/nodes/internal/base-store.js +20 -0
  77. package/dist/nodes/internal/child-attachment.d.ts +26 -0
  78. package/dist/nodes/internal/child-attachment.js +48 -0
  79. package/dist/nodes/internal/deferred-action.d.ts +8 -0
  80. package/dist/nodes/internal/deferred-action.js +19 -0
  81. package/dist/nodes/internal/list-item-renderer.d.ts +14 -14
  82. package/dist/nodes/internal/list-item-renderer.js +49 -70
  83. package/dist/nodes/internal/list-store.d.ts +7 -6
  84. package/dist/nodes/internal/list-store.js +20 -24
  85. package/dist/nodes/internal/predicates.d.ts +28 -1
  86. package/dist/nodes/internal/predicates.js +53 -38
  87. package/dist/nodes/internal/selection-model.d.ts +30 -0
  88. package/dist/nodes/internal/selection-model.js +91 -0
  89. package/dist/nodes/internal/signal-store.d.ts +5 -3
  90. package/dist/nodes/internal/signal-store.js +30 -21
  91. package/dist/nodes/internal/simple-list-store.js +6 -9
  92. package/dist/nodes/internal/text-buffer-controller.d.ts +43 -0
  93. package/dist/nodes/internal/text-buffer-controller.js +287 -0
  94. package/dist/nodes/internal/text-tag-styles.d.ts +43 -0
  95. package/dist/nodes/internal/text-tag-styles.js +52 -0
  96. package/dist/nodes/internal/tree-list-item-renderer.d.ts +16 -14
  97. package/dist/nodes/internal/tree-list-item-renderer.js +88 -91
  98. package/dist/nodes/internal/tree-store.d.ts +10 -9
  99. package/dist/nodes/internal/tree-store.js +31 -35
  100. package/dist/nodes/internal/utils.d.ts +7 -4
  101. package/dist/nodes/internal/utils.js +50 -5
  102. package/dist/nodes/level-bar.js +18 -66
  103. package/dist/nodes/list-item.d.ts +6 -3
  104. package/dist/nodes/list-item.js +7 -4
  105. package/dist/nodes/list-view.js +19 -11
  106. package/dist/nodes/menu.d.ts +3 -3
  107. package/dist/nodes/menu.js +3 -3
  108. package/dist/nodes/models/list.d.ts +11 -13
  109. package/dist/nodes/models/list.js +16 -73
  110. package/dist/nodes/models/menu.d.ts +8 -7
  111. package/dist/nodes/models/menu.js +43 -50
  112. package/dist/nodes/models/tree-list.d.ts +6 -12
  113. package/dist/nodes/models/tree-list.js +30 -93
  114. package/dist/nodes/navigation-page.d.ts +1 -0
  115. package/dist/nodes/navigation-page.js +7 -3
  116. package/dist/nodes/navigation-view.js +17 -28
  117. package/dist/nodes/notebook-page-tab.d.ts +4 -3
  118. package/dist/nodes/notebook-page-tab.js +5 -2
  119. package/dist/nodes/notebook-page.d.ts +7 -5
  120. package/dist/nodes/notebook-page.js +39 -16
  121. package/dist/nodes/notebook.js +2 -2
  122. package/dist/nodes/overlay-child.js +90 -30
  123. package/dist/nodes/pack-child.d.ts +0 -13
  124. package/dist/nodes/pack-child.js +14 -12
  125. package/dist/nodes/pack.d.ts +6 -1
  126. package/dist/nodes/pack.js +4 -37
  127. package/dist/nodes/popover-menu.js +2 -2
  128. package/dist/nodes/scale.js +15 -58
  129. package/dist/nodes/scrolled-window.js +7 -5
  130. package/dist/nodes/search-bar.d.ts +1 -0
  131. package/dist/nodes/search-bar.js +40 -0
  132. package/dist/nodes/shortcut-controller.d.ts +1 -0
  133. package/dist/nodes/shortcut-controller.js +90 -0
  134. package/dist/nodes/shortcut.d.ts +39 -0
  135. package/dist/nodes/shortcut.js +52 -0
  136. package/dist/nodes/simple-list-view.js +2 -3
  137. package/dist/nodes/slot.d.ts +6 -9
  138. package/dist/nodes/slot.js +27 -42
  139. package/dist/nodes/source-view.d.ts +1 -0
  140. package/dist/nodes/source-view.js +93 -0
  141. package/dist/nodes/stack-page.js +17 -13
  142. package/dist/nodes/stack.js +19 -5
  143. package/dist/nodes/text-anchor.d.ts +41 -0
  144. package/dist/nodes/text-anchor.js +59 -0
  145. package/dist/nodes/text-content.d.ts +10 -0
  146. package/dist/nodes/text-content.js +1 -0
  147. package/dist/nodes/text-paintable.d.ts +17 -0
  148. package/dist/nodes/text-paintable.js +34 -0
  149. package/dist/nodes/text-segment.d.ts +15 -0
  150. package/dist/nodes/text-segment.js +29 -0
  151. package/dist/nodes/text-tag.d.ts +136 -0
  152. package/dist/nodes/text-tag.js +202 -0
  153. package/dist/nodes/text-view.d.ts +31 -0
  154. package/dist/nodes/text-view.js +73 -0
  155. package/dist/nodes/toggle-group.js +24 -32
  156. package/dist/nodes/toggle.d.ts +1 -15
  157. package/dist/nodes/toggle.js +40 -32
  158. package/dist/nodes/toolbar-child.js +14 -16
  159. package/dist/nodes/tree-list-item.d.ts +7 -5
  160. package/dist/nodes/tree-list-item.js +24 -36
  161. package/dist/nodes/tree-list-view.js +9 -4
  162. package/dist/nodes/virtual.d.ts +1 -1
  163. package/dist/nodes/widget.d.ts +3 -13
  164. package/dist/nodes/widget.js +117 -231
  165. package/dist/nodes/window.d.ts +9 -3
  166. package/dist/nodes/window.js +35 -19
  167. package/dist/registry.d.ts +1 -1
  168. package/dist/render.js +8 -6
  169. package/dist/scheduler.d.ts +11 -1
  170. package/dist/scheduler.js +16 -4
  171. package/dist/types.d.ts +2 -110
  172. package/package.json +3 -3
  173. package/dist/nodes/calendar-mark.d.ts +0 -15
  174. package/dist/nodes/calendar-mark.js +0 -29
  175. package/dist/nodes/internal/constants.d.ts +0 -1
  176. package/dist/nodes/internal/constants.js +0 -21
  177. package/dist/nodes/level-bar-offset.d.ts +0 -13
  178. package/dist/nodes/level-bar-offset.js +0 -35
  179. package/dist/nodes/scale-mark.d.ts +0 -17
  180. package/dist/nodes/scale-mark.js +0 -38
  181. package/dist/nodes/virtual-child.d.ts +0 -18
  182. package/dist/nodes/virtual-child.js +0 -62
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,90 @@
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { filterProps, hasChanged, matchesAnyClass } from "./internal/utils.js";
4
+ import { WidgetNode } from "./widget.js";
5
+ const OWN_PROPS = [
6
+ "fontDesc",
7
+ "onFontDescChanged",
8
+ "title",
9
+ "modal",
10
+ "language",
11
+ "useFont",
12
+ "useSize",
13
+ "level",
14
+ ];
15
+ class FontDialogButtonNode extends WidgetNode {
16
+ static priority = 1;
17
+ dialog;
18
+ notifyHandler = null;
19
+ static matches(_type, containerOrClass) {
20
+ return matchesAnyClass([Gtk.FontDialogButton], containerOrClass);
21
+ }
22
+ static createContainer(_props, containerClass) {
23
+ const dialog = new Gtk.FontDialog();
24
+ const button = new containerClass(dialog);
25
+ return button;
26
+ }
27
+ constructor(type, props, container, rootContainer) {
28
+ super(type, props, container, rootContainer);
29
+ const dialog = container.getDialog();
30
+ if (!dialog) {
31
+ throw new Error("FontDialogButton must have a dialog");
32
+ }
33
+ this.dialog = dialog;
34
+ }
35
+ updateProps(oldProps, newProps) {
36
+ super.updateProps(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
37
+ this.applyOwnProps(oldProps, newProps);
38
+ }
39
+ applyOwnProps(oldProps, newProps) {
40
+ if (hasChanged(oldProps, newProps, "title") && newProps.title !== undefined) {
41
+ this.dialog.setTitle(newProps.title);
42
+ }
43
+ if (hasChanged(oldProps, newProps, "modal")) {
44
+ this.dialog.setModal(newProps.modal ?? true);
45
+ }
46
+ if (hasChanged(oldProps, newProps, "language") && newProps.language) {
47
+ this.dialog.setLanguage(newProps.language);
48
+ }
49
+ if (hasChanged(oldProps, newProps, "useFont")) {
50
+ this.container.setUseFont(newProps.useFont ?? false);
51
+ }
52
+ if (hasChanged(oldProps, newProps, "useSize")) {
53
+ this.container.setUseSize(newProps.useSize ?? false);
54
+ }
55
+ if (hasChanged(oldProps, newProps, "level")) {
56
+ this.container.setLevel(newProps.level ?? Gtk.FontLevel.FONT);
57
+ }
58
+ if (hasChanged(oldProps, newProps, "fontDesc") && newProps.fontDesc) {
59
+ this.container.setFontDesc(newProps.fontDesc);
60
+ }
61
+ if (hasChanged(oldProps, newProps, "onFontDescChanged")) {
62
+ this.setupNotifyHandler(newProps.onFontDescChanged);
63
+ }
64
+ }
65
+ setupNotifyHandler(callback) {
66
+ if (this.notifyHandler) {
67
+ this.signalStore.set(this, this.container, "notify", undefined);
68
+ this.notifyHandler = null;
69
+ }
70
+ if (callback) {
71
+ this.notifyHandler = (_button, pspec) => {
72
+ if (pspec.getName() === "font-desc") {
73
+ const fontDesc = this.container.getFontDesc();
74
+ if (fontDesc) {
75
+ callback(fontDesc);
76
+ }
77
+ }
78
+ };
79
+ this.signalStore.set(this, this.container, "notify", this.notifyHandler);
80
+ }
81
+ }
82
+ unmount() {
83
+ if (this.notifyHandler) {
84
+ this.signalStore.set(this, this.container, "notify", undefined);
85
+ this.notifyHandler = null;
86
+ }
87
+ super.unmount();
88
+ }
89
+ }
90
+ registerNodeClass(FontDialogButtonNode);
@@ -1,62 +1,56 @@
1
- import { batch, isObjectEqual } from "@gtkx/ffi";
1
+ import { isObjectEqual } from "@gtkx/ffi";
2
2
  import { registerNodeClass } from "../registry.js";
3
- import { SlotNode } from "./slot.js";
4
- class GridChildNode extends SlotNode {
3
+ import { PositionalChildNode } from "./abstract/positional-child.js";
4
+ import { hasChanged } from "./internal/utils.js";
5
+ class GridChildNode extends PositionalChildNode {
5
6
  static priority = 1;
6
7
  static matches(type) {
7
8
  return type === "GridChild";
8
9
  }
10
+ attachToParent(parent, child) {
11
+ const grid = parent;
12
+ const column = this.props.column ?? 0;
13
+ const row = this.props.row ?? 0;
14
+ const columnSpan = this.props.columnSpan ?? 1;
15
+ const rowSpan = this.props.rowSpan ?? 1;
16
+ const existingChild = grid.getChildAt(column, row);
17
+ if (existingChild && !isObjectEqual(existingChild, child)) {
18
+ grid.remove(existingChild);
19
+ }
20
+ grid.attach(child, column, row, columnSpan, rowSpan);
21
+ }
22
+ detachFromParent(parent, child) {
23
+ parent.remove(child);
24
+ }
9
25
  updateProps(oldProps, newProps) {
10
26
  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
- }
27
+ this.applyOwnProps(oldProps, newProps);
20
28
  }
21
- getGrid() {
22
- if (!this.parent) {
23
- throw new Error("Expected Grid reference to be set on GridChildNode");
29
+ applyOwnProps(oldProps, newProps) {
30
+ const positionChanged = hasChanged(oldProps, newProps, "column") ||
31
+ hasChanged(oldProps, newProps, "row") ||
32
+ hasChanged(oldProps, newProps, "columnSpan") ||
33
+ hasChanged(oldProps, newProps, "rowSpan");
34
+ if (positionChanged && this.parent && this.child) {
35
+ this.reattachChild();
24
36
  }
25
- return this.parent;
26
37
  }
27
- attachChild() {
28
- const grid = this.getGrid();
38
+ reattachChild() {
39
+ const grid = this.getTypedParent();
40
+ const child = this.child;
41
+ if (!child) {
42
+ return;
43
+ }
29
44
  const column = this.props.column ?? 0;
30
45
  const row = this.props.row ?? 0;
31
46
  const columnSpan = this.props.columnSpan ?? 1;
32
47
  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
- });
48
+ const existingChild = grid.getChildAt(column, row);
49
+ if (existingChild && !isObjectEqual(existingChild, child)) {
50
+ grid.remove(existingChild);
51
+ }
52
+ grid.remove(child);
53
+ grid.attach(child, column, row, columnSpan, rowSpan);
60
54
  }
61
55
  }
62
56
  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,16 +1,20 @@
1
- import "./action-row-child.js";
2
1
  import "./action-row.js";
2
+ import "./adjustable.js";
3
+ import "./animation/index.js";
4
+ import "./alert-dialog-response.js";
3
5
  import "./application.js";
4
6
  import "./autowrapped.js";
5
- import "./calendar-mark.js";
6
7
  import "./calendar.js";
8
+ import "./color-dialog-button.js";
7
9
  import "./column-view-column.js";
8
10
  import "./column-view.js";
9
- import "./expander-row-child.js";
11
+ import "./dialog.js";
12
+ import "./drawing-area.js";
10
13
  import "./expander-row.js";
11
14
  import "./fixed-child.js";
15
+ import "./font-dialog-button.js";
16
+ import "./grid.js";
12
17
  import "./grid-child.js";
13
- import "./level-bar-offset.js";
14
18
  import "./level-bar.js";
15
19
  import "./list-item.js";
16
20
  import "./list-view.js";
@@ -21,22 +25,34 @@ import "./notebook-page-tab.js";
21
25
  import "./notebook-page.js";
22
26
  import "./notebook.js";
23
27
  import "./overlay-child.js";
24
- import "./pack-child.js";
25
28
  import "./pack.js";
26
29
  import "./popover-menu.js";
27
- import "./scale-mark.js";
28
30
  import "./scale.js";
29
31
  import "./scrolled-window.js";
32
+ import "./search-bar.js";
33
+ import "./shortcut-controller.js";
34
+ import "./shortcut.js";
35
+ import "./event-controller.js";
30
36
  import "./simple-list-item.js";
31
37
  import "./simple-list-view.js";
32
38
  import "./slot.js";
39
+ import "./source-view.js";
33
40
  import "./stack-page.js";
34
41
  import "./stack.js";
42
+ import "./text-anchor.js";
43
+ import "./text-content.js";
44
+ import "./text-paintable.js";
45
+ import "./text-segment.js";
46
+ import "./text-tag.js";
47
+ import "./text-view.js";
35
48
  import "./toggle.js";
36
49
  import "./toggle-group.js";
37
50
  import "./toolbar-child.js";
38
51
  import "./tree-list-item.js";
39
52
  import "./tree-list-view.js";
40
53
  import "./virtual.js";
54
+ import "./action-row-child.js";
55
+ import "./expander-row-child.js";
56
+ import "./pack-child.js";
41
57
  import "./widget.js";
42
58
  import "./window.js";
@@ -1,16 +1,20 @@
1
- import "./action-row-child.js";
2
1
  import "./action-row.js";
2
+ import "./adjustable.js";
3
+ import "./animation/index.js";
4
+ import "./alert-dialog-response.js";
3
5
  import "./application.js";
4
6
  import "./autowrapped.js";
5
- import "./calendar-mark.js";
6
7
  import "./calendar.js";
8
+ import "./color-dialog-button.js";
7
9
  import "./column-view-column.js";
8
10
  import "./column-view.js";
9
- import "./expander-row-child.js";
11
+ import "./dialog.js";
12
+ import "./drawing-area.js";
10
13
  import "./expander-row.js";
11
14
  import "./fixed-child.js";
15
+ import "./font-dialog-button.js";
16
+ import "./grid.js";
12
17
  import "./grid-child.js";
13
- import "./level-bar-offset.js";
14
18
  import "./level-bar.js";
15
19
  import "./list-item.js";
16
20
  import "./list-view.js";
@@ -21,22 +25,34 @@ import "./notebook-page-tab.js";
21
25
  import "./notebook-page.js";
22
26
  import "./notebook.js";
23
27
  import "./overlay-child.js";
24
- import "./pack-child.js";
25
28
  import "./pack.js";
26
29
  import "./popover-menu.js";
27
- import "./scale-mark.js";
28
30
  import "./scale.js";
29
31
  import "./scrolled-window.js";
32
+ import "./search-bar.js";
33
+ import "./shortcut-controller.js";
34
+ import "./shortcut.js";
35
+ import "./event-controller.js";
30
36
  import "./simple-list-item.js";
31
37
  import "./simple-list-view.js";
32
38
  import "./slot.js";
39
+ import "./source-view.js";
33
40
  import "./stack-page.js";
34
41
  import "./stack.js";
42
+ import "./text-anchor.js";
43
+ import "./text-content.js";
44
+ import "./text-paintable.js";
45
+ import "./text-segment.js";
46
+ import "./text-tag.js";
47
+ import "./text-view.js";
35
48
  import "./toggle.js";
36
49
  import "./toggle-group.js";
37
50
  import "./toolbar-child.js";
38
51
  import "./tree-list-item.js";
39
52
  import "./tree-list-view.js";
40
53
  import "./virtual.js";
54
+ import "./action-row-child.js";
55
+ import "./expander-row-child.js";
56
+ import "./pack-child.js";
41
57
  import "./widget.js";
42
58
  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,9 @@
1
+ export declare abstract class BaseStore<TItem = unknown> {
2
+ protected items: Map<string, TItem>;
3
+ private syncAction;
4
+ constructor();
5
+ getItem(id: string): TItem | undefined;
6
+ updateItem(id: string, item: TItem): void;
7
+ protected scheduleSync(): void;
8
+ protected abstract sync(): void;
9
+ }
@@ -0,0 +1,20 @@
1
+ import { CommitPriority } from "../../scheduler.js";
2
+ import { DeferredAction } from "./deferred-action.js";
3
+ export class BaseStore {
4
+ items = new Map();
5
+ syncAction;
6
+ constructor() {
7
+ this.syncAction = new DeferredAction(() => this.sync(), CommitPriority.LOW);
8
+ }
9
+ getItem(id) {
10
+ return this.items.get(id);
11
+ }
12
+ updateItem(id, item) {
13
+ if (this.items.has(id)) {
14
+ this.items.set(id, item);
15
+ }
16
+ }
17
+ scheduleSync() {
18
+ this.syncAction.schedule();
19
+ }
20
+ }
@@ -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,8 @@
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
+ schedule(): void;
8
+ }
@@ -0,0 +1,19 @@
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
+ schedule() {
11
+ if (this.scheduled)
12
+ return;
13
+ this.scheduled = true;
14
+ scheduleAfterCommit(() => {
15
+ this.scheduled = false;
16
+ this.action();
17
+ }, this.priority);
18
+ }
19
+ }
@@ -1,19 +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
- 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;
19
19
  }