@gtkx/react 0.6.0 → 0.7.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 (84) hide show
  1. package/dist/batch.d.ts +4 -1
  2. package/dist/batch.js +19 -10
  3. package/dist/codegen/jsx-generator.d.ts +4 -4
  4. package/dist/codegen/jsx-generator.js +24 -27
  5. package/dist/container-interfaces.d.ts +19 -6
  6. package/dist/container-interfaces.js +26 -6
  7. package/dist/errors.d.ts +8 -0
  8. package/dist/errors.js +38 -0
  9. package/dist/factory.js +9 -3
  10. package/dist/generated/jsx.d.ts +38 -26
  11. package/dist/generated/jsx.js +12 -2
  12. package/dist/index.js +3 -1
  13. package/dist/node.d.ts +5 -0
  14. package/dist/node.js +62 -6
  15. package/dist/nodes/action-bar.d.ts +2 -6
  16. package/dist/nodes/action-bar.js +3 -12
  17. package/dist/nodes/column-view.d.ts +19 -44
  18. package/dist/nodes/column-view.js +70 -243
  19. package/dist/nodes/combo-row.d.ts +5 -0
  20. package/dist/nodes/combo-row.js +6 -0
  21. package/dist/nodes/drop-down.d.ts +9 -0
  22. package/dist/nodes/drop-down.js +12 -0
  23. package/dist/nodes/flow-box.d.ts +4 -6
  24. package/dist/nodes/flow-box.js +8 -16
  25. package/dist/nodes/grid.d.ts +15 -15
  26. package/dist/nodes/grid.js +21 -64
  27. package/dist/nodes/header-bar.d.ts +34 -11
  28. package/dist/nodes/header-bar.js +52 -24
  29. package/dist/nodes/indexed-child-container.d.ts +16 -0
  30. package/dist/nodes/indexed-child-container.js +22 -0
  31. package/dist/nodes/list-box.d.ts +3 -6
  32. package/dist/nodes/list-box.js +6 -14
  33. package/dist/nodes/list-item-factory.d.ts +19 -0
  34. package/dist/nodes/list-item-factory.js +58 -0
  35. package/dist/nodes/list-view.d.ts +24 -0
  36. package/dist/nodes/list-view.js +46 -0
  37. package/dist/nodes/menu.d.ts +25 -19
  38. package/dist/nodes/menu.js +30 -59
  39. package/dist/nodes/notebook.d.ts +13 -14
  40. package/dist/nodes/notebook.js +18 -56
  41. package/dist/nodes/paged-stack.d.ts +39 -0
  42. package/dist/nodes/paged-stack.js +54 -0
  43. package/dist/nodes/selectable-list.d.ts +41 -0
  44. package/dist/nodes/selectable-list.js +228 -0
  45. package/dist/nodes/stack-page-props.d.ts +11 -0
  46. package/dist/nodes/stack-page-props.js +23 -0
  47. package/dist/nodes/stack.d.ts +14 -28
  48. package/dist/nodes/stack.js +30 -142
  49. package/dist/nodes/string-list-container.d.ts +41 -0
  50. package/dist/nodes/string-list-container.js +90 -0
  51. package/dist/nodes/string-list-item.d.ts +15 -0
  52. package/dist/nodes/string-list-item.js +48 -0
  53. package/dist/nodes/string-list-store.d.ts +13 -0
  54. package/dist/nodes/string-list-store.js +44 -0
  55. package/dist/nodes/text-view.d.ts +1 -1
  56. package/dist/nodes/text-view.js +1 -5
  57. package/dist/nodes/toggle-button.d.ts +1 -1
  58. package/dist/nodes/toggle-button.js +1 -3
  59. package/dist/nodes/view-stack.d.ts +9 -0
  60. package/dist/nodes/view-stack.js +28 -0
  61. package/dist/nodes/virtual-item.d.ts +20 -0
  62. package/dist/nodes/virtual-item.js +57 -0
  63. package/dist/nodes/virtual-slot.d.ts +25 -0
  64. package/dist/nodes/virtual-slot.js +71 -0
  65. package/dist/nodes/widget.d.ts +0 -3
  66. package/dist/nodes/widget.js +0 -28
  67. package/dist/nodes/window.d.ts +1 -1
  68. package/dist/nodes/window.js +9 -15
  69. package/dist/predicates.d.ts +8 -0
  70. package/dist/predicates.js +8 -0
  71. package/dist/props.d.ts +7 -5
  72. package/dist/props.js +11 -9
  73. package/dist/reconciler/host-config.d.ts +19 -0
  74. package/dist/reconciler/host-config.js +89 -0
  75. package/dist/reconciler.d.ts +2 -26
  76. package/dist/reconciler.js +15 -106
  77. package/dist/render.d.ts +1 -2
  78. package/dist/render.js +16 -4
  79. package/dist/types.d.ts +19 -16
  80. package/package.json +4 -4
  81. package/dist/nodes/dropdown.d.ts +0 -39
  82. package/dist/nodes/dropdown.js +0 -103
  83. package/dist/nodes/list.d.ts +0 -43
  84. package/dist/nodes/list.js +0 -153
package/dist/node.js CHANGED
@@ -4,8 +4,10 @@ import * as Gtk from "@gtkx/ffi/gtk";
4
4
  import * as GtkSource from "@gtkx/ffi/gtksource";
5
5
  import * as Vte from "@gtkx/ffi/vte";
6
6
  import * as WebKit from "@gtkx/ffi/webkit";
7
+ import { isChildContainer } from "./container-interfaces.js";
7
8
  import { CONSTRUCTOR_PARAMS, PROP_SETTERS, SETTER_GETTERS } from "./generated/internal.js";
8
9
  import { isAddable, isAppendable, isRemovable, isSingleChild } from "./predicates.js";
10
+ export const normalizeWidgetType = (type) => type.split(".")[0] || type;
9
11
  const NAMESPACE_REGISTRY = [
10
12
  ["GtkSource", GtkSource],
11
13
  ["WebKit", WebKit],
@@ -32,10 +34,12 @@ export class Node {
32
34
  static matches(_type, _existingWidget) {
33
35
  return false;
34
36
  }
37
+ static consumedPropNames = [];
35
38
  signalHandlers = new Map();
36
39
  widget = undefined;
37
40
  widgetType;
38
41
  nodeType;
42
+ parent = null;
39
43
  _state = null;
40
44
  get state() {
41
45
  if (this._state === null) {
@@ -51,7 +55,7 @@ export class Node {
51
55
  }
52
56
  constructor(type, existingWidget) {
53
57
  this.nodeType = type;
54
- this.widgetType = type.split(".")[0] || type;
58
+ this.widgetType = normalizeWidgetType(type);
55
59
  if (existingWidget) {
56
60
  this.widget = existingWidget;
57
61
  }
@@ -67,12 +71,12 @@ export class Node {
67
71
  this.updateProps({}, props);
68
72
  }
69
73
  createWidget(type, props) {
70
- const normalizedType = type.split(".")[0] || type;
71
- const WidgetClass = resolveWidgetClass(normalizedType);
74
+ const widgetType = normalizeWidgetType(type);
75
+ const WidgetClass = resolveWidgetClass(widgetType);
72
76
  if (!WidgetClass) {
73
- throw new Error(`Unknown GTK widget type: ${normalizedType}`);
77
+ throw new Error(`Unknown GTK widget type: ${widgetType}`);
74
78
  }
75
- return new WidgetClass(...extractConstructorArgs(normalizedType, props));
79
+ return new WidgetClass(...extractConstructorArgs(widgetType, props));
76
80
  }
77
81
  getWidget() {
78
82
  return this.widget;
@@ -87,6 +91,13 @@ export class Node {
87
91
  child.attachToParentBefore(this, before);
88
92
  }
89
93
  attachToParent(parent) {
94
+ this.parent = parent;
95
+ if (isChildContainer(parent)) {
96
+ const widget = this.getWidget();
97
+ if (widget)
98
+ parent.attachChild(widget);
99
+ return;
100
+ }
90
101
  const parentWidget = parent.getWidget();
91
102
  const widget = this.getWidget();
92
103
  if (!parentWidget || !widget)
@@ -102,6 +113,14 @@ export class Node {
102
113
  }
103
114
  }
104
115
  detachFromParent(parent) {
116
+ this.parent = null;
117
+ this.disconnectAllSignals();
118
+ if (isChildContainer(parent)) {
119
+ const widget = this.getWidget();
120
+ if (widget)
121
+ parent.detachChild(widget);
122
+ return;
123
+ }
105
124
  const parentWidget = parent.getWidget();
106
125
  const widget = this.getWidget();
107
126
  if (!parentWidget || !widget)
@@ -113,7 +132,33 @@ export class Node {
113
132
  parentWidget.setChild(null);
114
133
  }
115
134
  }
135
+ disconnectAllSignals() {
136
+ const widget = this.getWidget();
137
+ if (!widget)
138
+ return;
139
+ for (const [_eventName, handlerId] of this.signalHandlers) {
140
+ GObject.signalHandlerDisconnect(widget, handlerId);
141
+ }
142
+ this.signalHandlers.clear();
143
+ }
144
+ hasParent() {
145
+ return this.parent !== null;
146
+ }
116
147
  attachToParentBefore(parent, before) {
148
+ this.parent = parent;
149
+ if (isChildContainer(parent)) {
150
+ const widget = this.getWidget();
151
+ const beforeWidget = before.getWidget();
152
+ if (widget) {
153
+ if (beforeWidget) {
154
+ parent.insertChildBefore(widget, beforeWidget);
155
+ }
156
+ else {
157
+ parent.attachChild(widget);
158
+ }
159
+ }
160
+ return;
161
+ }
117
162
  const parentWidget = parent.getWidget();
118
163
  const widget = this.getWidget();
119
164
  const beforeWidget = before.getWidget();
@@ -127,7 +172,18 @@ export class Node {
127
172
  }
128
173
  }
129
174
  consumedProps() {
130
- return new Set(["children"]);
175
+ const consumed = new Set(["children"]);
176
+ let proto = Object.getPrototypeOf(this);
177
+ while (proto && proto.constructor !== Object) {
178
+ const propNames = proto.constructor.consumedPropNames;
179
+ if (propNames) {
180
+ for (const name of propNames) {
181
+ consumed.add(name);
182
+ }
183
+ }
184
+ proto = Object.getPrototypeOf(proto);
185
+ }
186
+ return consumed;
131
187
  }
132
188
  updateProps(oldProps, newProps) {
133
189
  const widget = this.getWidget();
@@ -1,9 +1,5 @@
1
1
  import type * as Gtk from "@gtkx/ffi/gtk";
2
- import type { ChildContainer } from "../container-interfaces.js";
3
- import { Node } from "../node.js";
4
- export declare class ActionBarNode extends Node<Gtk.ActionBar> implements ChildContainer {
2
+ import { PackContainerNode } from "./header-bar.js";
3
+ export declare class ActionBarNode extends PackContainerNode<Gtk.ActionBar> {
5
4
  static matches(type: string): boolean;
6
- attachChild(child: Gtk.Widget): void;
7
- insertChildBefore(child: Gtk.Widget, _before: Gtk.Widget): void;
8
- detachChild(child: Gtk.Widget): void;
9
5
  }
@@ -1,15 +1,6 @@
1
- import { Node } from "../node.js";
2
- export class ActionBarNode extends Node {
1
+ import { PackContainerNode } from "./header-bar.js";
2
+ export class ActionBarNode extends PackContainerNode {
3
3
  static matches(type) {
4
- return type === "ActionBar";
5
- }
6
- attachChild(child) {
7
- this.widget.packStart(child);
8
- }
9
- insertChildBefore(child, _before) {
10
- this.attachChild(child);
11
- }
12
- detachChild(child) {
13
- this.widget.remove(child);
4
+ return type === "ActionBar" || type === "ActionBar.Root";
14
5
  }
15
6
  }
@@ -1,62 +1,45 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
- import type Reconciler from "react-reconciler";
3
- import { type ColumnContainer, type ItemContainer } from "../container-interfaces.js";
2
+ import { type ColumnContainer } from "../container-interfaces.js";
4
3
  import type { Props } from "../factory.js";
5
4
  import { Node } from "../node.js";
6
- import type { ColumnSortFn, RenderItemFn } from "../types.js";
7
- interface ColumnViewState {
8
- stringList: Gtk.StringList;
9
- selectionModel: Gtk.SingleSelection;
10
- sortListModel: Gtk.SortListModel;
11
- items: unknown[];
5
+ import type { RenderItemFn } from "../types.js";
6
+ import { type ListItemFactoryHandlers, type ListItemInfo } from "./list-item-factory.js";
7
+ import { SelectableListNode, type SelectableListState } from "./selectable-list.js";
8
+ import { VirtualItemNode } from "./virtual-item.js";
9
+ type ColumnViewState = SelectableListState & {
12
10
  columns: ColumnViewColumnNode[];
13
- committedLength: number;
14
11
  sortColumn: string | null;
15
12
  sortOrder: Gtk.SortType;
16
- sortFn: ColumnSortFn<unknown, string> | null;
17
- isSorting: boolean;
18
13
  onSortChange: ((column: string | null, order: Gtk.SortType) => void) | null;
19
14
  sorterChangedHandlerId: number | null;
20
15
  lastNotifiedColumn: string | null;
21
16
  lastNotifiedOrder: Gtk.SortType;
22
- }
23
- export declare class ColumnViewNode extends Node<Gtk.ColumnView, ColumnViewState> implements ItemContainer<unknown>, ColumnContainer {
17
+ };
18
+ export declare class ColumnViewNode extends SelectableListNode<Gtk.ColumnView, ColumnViewState> implements ColumnContainer {
19
+ static consumedPropNames: string[];
24
20
  static matches(type: string): boolean;
25
21
  initialize(props: Props): void;
26
- private initializeStateWithPlaceholders;
27
- private createGtkModels;
28
22
  private connectSorterChangedSignal;
29
- private waitForSortComplete;
30
23
  private disconnectSorterChangedSignal;
31
24
  private notifySortChange;
32
- getItems(): unknown[];
33
- getSortFn(): ColumnSortFn<unknown, string> | null;
34
- compareItems(a: unknown, b: unknown, columnId: string): number;
25
+ detachFromParent(parent: Node): void;
26
+ updateProps(oldProps: Props, newProps: Props): void;
27
+ private applySortIndicator;
35
28
  addColumn(columnNode: ColumnViewColumnNode): void;
36
- private applySortByColumn;
37
- findColumnById(id: string): ColumnViewColumnNode | undefined;
38
- removeColumn(column: ColumnViewColumnNode): void;
39
29
  insertColumnBefore(column: ColumnViewColumnNode, before: ColumnViewColumnNode): void;
40
- private syncStringList;
41
- addItem(item: unknown): void;
42
- insertItemBefore(item: unknown, beforeItem: unknown): void;
43
- removeItem(item: unknown): void;
44
- protected consumedProps(): Set<string>;
45
- updateProps(oldProps: Props, newProps: Props): void;
46
- }
47
- interface ListItemInfo {
48
- box: Gtk.Box;
49
- fiberRoot: Reconciler.FiberRoot;
30
+ removeColumn(column: ColumnViewColumnNode): void;
50
31
  }
51
- interface ColumnViewColumnState {
32
+ type ColumnViewColumnState = {
52
33
  column: Gtk.ColumnViewColumn;
53
34
  factory: Gtk.SignalListItemFactory;
35
+ factoryHandlers: ListItemFactoryHandlers | null;
54
36
  renderCell: RenderItemFn<unknown>;
55
37
  columnId: string | null;
56
38
  sorter: Gtk.CustomSorter | null;
57
39
  listItemCache: Map<number, ListItemInfo>;
58
- }
40
+ };
59
41
  export declare class ColumnViewColumnNode extends Node<never, ColumnViewColumnState> {
42
+ static consumedPropNames: string[];
60
43
  static matches(type: string): boolean;
61
44
  protected isVirtual(): boolean;
62
45
  private columnView;
@@ -64,21 +47,13 @@ export declare class ColumnViewColumnNode extends Node<never, ColumnViewColumnSt
64
47
  getColumn(): Gtk.ColumnViewColumn;
65
48
  getId(): string | null;
66
49
  setColumnView(columnView: ColumnViewNode | null): void;
67
- updateSorterFromRoot(): void;
50
+ updateSorter(): void;
68
51
  attachToParent(parent: Node): void;
69
52
  attachToParentBefore(parent: Node, before: Node): void;
70
53
  detachFromParent(parent: Node): void;
71
- protected consumedProps(): Set<string>;
72
54
  updateProps(oldProps: Props, newProps: Props): void;
73
55
  }
74
- export declare class ColumnViewItemNode extends Node {
56
+ export declare class ColumnViewItemNode extends VirtualItemNode {
75
57
  static matches(type: string): boolean;
76
- protected isVirtual(): boolean;
77
- private item;
78
- initialize(props: Props): void;
79
- getItem(): unknown;
80
- attachToParent(parent: Node): void;
81
- attachToParentBefore(parent: Node, before: Node): void;
82
- detachFromParent(parent: Node): void;
83
58
  }
84
59
  export {};