@gtkx/react 0.17.2 → 0.18.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 (194) hide show
  1. package/README.md +7 -7
  2. package/dist/factory.d.ts +0 -1
  3. package/dist/factory.js +21 -8
  4. package/dist/generated/internal.d.ts +4 -51
  5. package/dist/generated/internal.js +626 -412
  6. package/dist/generated/jsx.d.ts +453 -958
  7. package/dist/host-config.d.ts +1 -1
  8. package/dist/host-config.js +18 -23
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/jsx.d.ts +579 -302
  12. package/dist/jsx.js +37 -179
  13. package/dist/metadata.d.ts +3 -0
  14. package/dist/metadata.js +26 -0
  15. package/dist/node.d.ts +20 -12
  16. package/dist/node.js +72 -17
  17. package/dist/nodes/adjustable.d.ts +3 -16
  18. package/dist/nodes/adjustable.js +5 -22
  19. package/dist/nodes/alert-dialog-response.d.ts +14 -1
  20. package/dist/nodes/alert-dialog-response.js +36 -62
  21. package/dist/nodes/animation.d.ts +37 -1
  22. package/dist/nodes/animation.js +162 -105
  23. package/dist/nodes/application.d.ts +11 -1
  24. package/dist/nodes/application.js +17 -38
  25. package/dist/nodes/calendar.d.ts +13 -0
  26. package/dist/nodes/calendar.js +10 -16
  27. package/dist/nodes/color-dialog-button.d.ts +13 -0
  28. package/dist/nodes/color-dialog-button.js +10 -38
  29. package/dist/nodes/column-view-column.d.ts +13 -11
  30. package/dist/nodes/column-view-column.js +27 -23
  31. package/dist/nodes/column-view.d.ts +31 -0
  32. package/dist/nodes/column-view.js +44 -44
  33. package/dist/nodes/container-slot.d.ts +15 -0
  34. package/dist/nodes/container-slot.js +68 -0
  35. package/dist/nodes/dialog.d.ts +6 -8
  36. package/dist/nodes/dialog.js +12 -13
  37. package/dist/nodes/drawing-area.d.ts +12 -0
  38. package/dist/nodes/drawing-area.js +24 -24
  39. package/dist/nodes/drop-down.d.ts +22 -0
  40. package/dist/nodes/drop-down.js +72 -0
  41. package/dist/nodes/event-controller.d.ts +8 -17
  42. package/dist/nodes/event-controller.js +20 -42
  43. package/dist/nodes/fixed-child.d.ts +18 -1
  44. package/dist/nodes/fixed-child.js +52 -36
  45. package/dist/nodes/font-dialog-button.d.ts +13 -0
  46. package/dist/nodes/font-dialog-button.js +12 -35
  47. package/dist/nodes/grid-child.d.ts +17 -1
  48. package/dist/nodes/grid-child.js +57 -37
  49. package/dist/nodes/grid-view.d.ts +24 -0
  50. package/dist/nodes/grid-view.js +73 -0
  51. package/dist/nodes/internal/base-item-renderer.d.ts +7 -9
  52. package/dist/nodes/internal/base-item-renderer.js +15 -18
  53. package/dist/nodes/internal/grid-item-renderer.d.ts +17 -0
  54. package/dist/nodes/internal/grid-item-renderer.js +59 -0
  55. package/dist/nodes/internal/list-item-renderer.d.ts +14 -9
  56. package/dist/nodes/internal/list-item-renderer.js +96 -35
  57. package/dist/nodes/internal/list-store.d.ts +5 -0
  58. package/dist/nodes/internal/list-store.js +39 -9
  59. package/dist/nodes/internal/predicates.d.ts +4 -19
  60. package/dist/nodes/internal/predicates.js +1 -20
  61. package/dist/nodes/internal/props.d.ts +5 -0
  62. package/dist/nodes/internal/props.js +42 -0
  63. package/dist/nodes/internal/{selection-model.d.ts → selection-model-controller.d.ts} +4 -9
  64. package/dist/nodes/internal/{selection-model.js → selection-model-controller.js} +6 -15
  65. package/dist/nodes/internal/signal-store.js +12 -5
  66. package/dist/nodes/internal/simple-list-store.d.ts +5 -0
  67. package/dist/nodes/internal/simple-list-store.js +42 -13
  68. package/dist/nodes/internal/text-buffer-controller.d.ts +4 -12
  69. package/dist/nodes/internal/text-buffer-controller.js +32 -33
  70. package/dist/nodes/internal/tree-store.d.ts +7 -0
  71. package/dist/nodes/internal/tree-store.js +75 -18
  72. package/dist/nodes/internal/widget.d.ts +7 -0
  73. package/dist/nodes/internal/widget.js +68 -0
  74. package/dist/nodes/level-bar.d.ts +10 -0
  75. package/dist/nodes/level-bar.js +11 -22
  76. package/dist/nodes/list-item.d.ts +17 -9
  77. package/dist/nodes/list-item.js +67 -12
  78. package/dist/nodes/list-view.d.ts +23 -0
  79. package/dist/nodes/list-view.js +27 -31
  80. package/dist/nodes/menu.d.ts +2 -4
  81. package/dist/nodes/menu.js +0 -6
  82. package/dist/nodes/models/grid.d.ts +27 -0
  83. package/dist/nodes/models/grid.js +68 -0
  84. package/dist/nodes/models/list.d.ts +15 -13
  85. package/dist/nodes/models/list.js +48 -26
  86. package/dist/nodes/models/menu.d.ts +15 -16
  87. package/dist/nodes/models/menu.js +63 -93
  88. package/dist/nodes/navigation-page.d.ts +16 -10
  89. package/dist/nodes/navigation-page.js +108 -31
  90. package/dist/nodes/navigation-view.d.ts +15 -0
  91. package/dist/nodes/navigation-view.js +15 -65
  92. package/dist/nodes/notebook-page-tab.d.ts +10 -12
  93. package/dist/nodes/notebook-page-tab.js +24 -27
  94. package/dist/nodes/notebook-page.d.ts +19 -16
  95. package/dist/nodes/notebook-page.js +75 -56
  96. package/dist/nodes/notebook.d.ts +10 -1
  97. package/dist/nodes/notebook.js +10 -22
  98. package/dist/nodes/overlay-child.d.ts +17 -1
  99. package/dist/nodes/overlay-child.js +53 -75
  100. package/dist/nodes/popover-menu.d.ts +15 -0
  101. package/dist/nodes/popover-menu.js +13 -26
  102. package/dist/nodes/scale.d.ts +8 -0
  103. package/dist/nodes/scale.js +2 -11
  104. package/dist/nodes/scrolled-window.d.ts +9 -0
  105. package/dist/nodes/scrolled-window.js +5 -11
  106. package/dist/nodes/search-bar.d.ts +9 -0
  107. package/dist/nodes/search-bar.js +8 -33
  108. package/dist/nodes/shortcut-controller.d.ts +9 -1
  109. package/dist/nodes/shortcut-controller.js +12 -25
  110. package/dist/nodes/shortcut.d.ts +11 -33
  111. package/dist/nodes/shortcut.js +19 -15
  112. package/dist/nodes/slot.d.ts +16 -15
  113. package/dist/nodes/slot.js +63 -57
  114. package/dist/nodes/source-view.d.ts +16 -0
  115. package/dist/nodes/source-view.js +44 -44
  116. package/dist/nodes/stack-page.d.ts +21 -1
  117. package/dist/nodes/stack-page.js +68 -17
  118. package/dist/nodes/stack.d.ts +11 -0
  119. package/dist/nodes/stack.js +8 -26
  120. package/dist/nodes/text-anchor.d.ts +11 -30
  121. package/dist/nodes/text-anchor.js +20 -22
  122. package/dist/nodes/text-content.d.ts +1 -0
  123. package/dist/nodes/text-content.js +1 -1
  124. package/dist/nodes/text-paintable.d.ts +10 -15
  125. package/dist/nodes/text-paintable.js +16 -9
  126. package/dist/nodes/text-segment.d.ts +12 -10
  127. package/dist/nodes/text-segment.js +19 -11
  128. package/dist/nodes/text-tag.d.ts +20 -119
  129. package/dist/nodes/text-tag.js +153 -119
  130. package/dist/nodes/text-view.d.ts +13 -18
  131. package/dist/nodes/text-view.js +17 -17
  132. package/dist/nodes/toggle-group.d.ts +9 -0
  133. package/dist/nodes/toggle-group.js +8 -33
  134. package/dist/nodes/toggle.d.ts +15 -1
  135. package/dist/nodes/toggle.js +34 -52
  136. package/dist/nodes/virtual.d.ts +3 -10
  137. package/dist/nodes/virtual.js +1 -14
  138. package/dist/nodes/web-view.d.ts +9 -0
  139. package/dist/nodes/web-view.js +10 -24
  140. package/dist/nodes/widget.d.ts +17 -13
  141. package/dist/nodes/widget.js +185 -112
  142. package/dist/nodes/window.d.ts +20 -21
  143. package/dist/nodes/window.js +54 -35
  144. package/dist/registry.d.ts +17 -6
  145. package/dist/registry.js +104 -5
  146. package/dist/render.d.ts +1 -10
  147. package/dist/render.js +1 -13
  148. package/package.json +6 -6
  149. package/dist/animation/css-builder.d.ts +0 -3
  150. package/dist/animation/css-builder.js +0 -53
  151. package/dist/animation/types.d.ts +0 -120
  152. package/dist/animation/types.js +0 -1
  153. package/dist/nodes/abstract/positional-child.d.ts +0 -9
  154. package/dist/nodes/abstract/positional-child.js +0 -29
  155. package/dist/nodes/abstract/virtual-container.d.ts +0 -21
  156. package/dist/nodes/abstract/virtual-container.js +0 -68
  157. package/dist/nodes/abstract/virtual-single-child.d.ts +0 -18
  158. package/dist/nodes/abstract/virtual-single-child.js +0 -55
  159. package/dist/nodes/action-row-child.d.ts +0 -1
  160. package/dist/nodes/action-row-child.js +0 -30
  161. package/dist/nodes/autowrapped.d.ts +0 -1
  162. package/dist/nodes/autowrapped.js +0 -115
  163. package/dist/nodes/expander-row-child.d.ts +0 -1
  164. package/dist/nodes/expander-row-child.js +0 -30
  165. package/dist/nodes/grid.d.ts +0 -1
  166. package/dist/nodes/grid.js +0 -41
  167. package/dist/nodes/index.d.ts +0 -56
  168. package/dist/nodes/index.js +0 -56
  169. package/dist/nodes/internal/child-attachment.d.ts +0 -26
  170. package/dist/nodes/internal/child-attachment.js +0 -48
  171. package/dist/nodes/internal/deferred-action.d.ts +0 -9
  172. package/dist/nodes/internal/deferred-action.js +0 -22
  173. package/dist/nodes/internal/text-tag-styles.d.ts +0 -43
  174. package/dist/nodes/internal/text-tag-styles.js +0 -52
  175. package/dist/nodes/internal/tree-list-item-renderer.d.ts +0 -26
  176. package/dist/nodes/internal/tree-list-item-renderer.js +0 -134
  177. package/dist/nodes/internal/utils.d.ts +0 -12
  178. package/dist/nodes/internal/utils.js +0 -92
  179. package/dist/nodes/models/tree-list.d.ts +0 -28
  180. package/dist/nodes/models/tree-list.js +0 -113
  181. package/dist/nodes/pack-child.d.ts +0 -1
  182. package/dist/nodes/pack-child.js +0 -30
  183. package/dist/nodes/simple-list-item.d.ts +0 -9
  184. package/dist/nodes/simple-list-item.js +0 -9
  185. package/dist/nodes/simple-list-view.d.ts +0 -1
  186. package/dist/nodes/simple-list-view.js +0 -74
  187. package/dist/nodes/toolbar-child.d.ts +0 -1
  188. package/dist/nodes/toolbar-child.js +0 -30
  189. package/dist/nodes/tree-list-item.d.ts +0 -22
  190. package/dist/nodes/tree-list-item.js +0 -90
  191. package/dist/nodes/tree-list-view.d.ts +0 -1
  192. package/dist/nodes/tree-list-view.js +0 -77
  193. package/dist/scheduler.d.ts +0 -26
  194. package/dist/scheduler.js +0 -42
@@ -1,52 +0,0 @@
1
- import { hasChanged } from "./utils.js";
2
- const STYLE_PROPS = {
3
- background: "setBackground",
4
- backgroundFullHeight: "setBackgroundFullHeight",
5
- foreground: "setForeground",
6
- family: "setFamily",
7
- font: "setFont",
8
- sizePoints: "setSizePoints",
9
- size: "setSize",
10
- scale: "setScale",
11
- weight: "setWeight",
12
- style: "setStyle",
13
- stretch: "setStretch",
14
- variant: "setVariant",
15
- strikethrough: "setStrikethrough",
16
- underline: "setUnderline",
17
- overline: "setOverline",
18
- rise: "setRise",
19
- letterSpacing: "setLetterSpacing",
20
- lineHeight: "setLineHeight",
21
- leftMargin: "setLeftMargin",
22
- rightMargin: "setRightMargin",
23
- indent: "setIndent",
24
- pixelsAboveLines: "setPixelsAboveLines",
25
- pixelsBelowLines: "setPixelsBelowLines",
26
- pixelsInsideWrap: "setPixelsInsideWrap",
27
- justification: "setJustification",
28
- direction: "setDirection",
29
- wrapMode: "setWrapMode",
30
- editable: "setEditable",
31
- invisible: "setInvisible",
32
- allowBreaks: "setAllowBreaks",
33
- insertHyphens: "setInsertHyphens",
34
- fallback: "setFallback",
35
- accumulativeMargin: "setAccumulativeMargin",
36
- paragraphBackground: "setParagraphBackground",
37
- showSpaces: "setShowSpaces",
38
- textTransform: "setTextTransform",
39
- fontFeatures: "setFontFeatures",
40
- language: "setLanguage",
41
- };
42
- export function applyStyleChanges(tag, oldProps, newProps) {
43
- for (const prop of Object.keys(STYLE_PROPS)) {
44
- if (hasChanged(oldProps, newProps, prop)) {
45
- const value = newProps[prop];
46
- if (value !== undefined) {
47
- const setter = tag[STYLE_PROPS[prop]];
48
- setter.call(tag, value);
49
- }
50
- }
51
- }
52
- }
@@ -1,26 +0,0 @@
1
- import * as Gtk from "@gtkx/ffi/gtk";
2
- import type { ReactNode } from "react";
3
- import type Reconciler from "react-reconciler";
4
- import { BaseItemRenderer } from "./base-item-renderer.js";
5
- import type { TreeStore } from "./tree-store.js";
6
- export type TreeRenderItemFn<T> = (item: T | null, row: Gtk.TreeListRow | null) => ReactNode;
7
- export declare class TreeListItemRenderer extends BaseItemRenderer<TreeStore> {
8
- private expanders;
9
- private setupComplete;
10
- private pendingBinds;
11
- private renderFn;
12
- private boundItems;
13
- setRenderFn(renderFn: TreeRenderItemFn<unknown> | null): void;
14
- rebindItem(id: string): void;
15
- protected getStoreTypeName(): string;
16
- dispose(): void;
17
- protected renderItem(_ptr: number): ReactNode;
18
- protected getItemFromListItem(listItem: Gtk.ListItem): unknown;
19
- protected onSetup(listItem: Gtk.ListItem, ptr: number): Gtk.Widget;
20
- protected onSetupComplete(ptr: number): void;
21
- protected onBind(listItem: Gtk.ListItem, ptr: number, fiberRoot: Reconciler.FiberRoot): void;
22
- protected onUnbind(listItem: Gtk.ListItem): void;
23
- protected onTeardown(_listItem: Gtk.ListItem, ptr: number): void;
24
- private processPendingBind;
25
- private renderBind;
26
- }
@@ -1,134 +0,0 @@
1
- import * as Gtk from "@gtkx/ffi/gtk";
2
- import { reconciler } from "../../reconciler.js";
3
- import { BaseItemRenderer } from "./base-item-renderer.js";
4
- export class TreeListItemRenderer extends BaseItemRenderer {
5
- expanders = new Map();
6
- setupComplete = new Set();
7
- pendingBinds = new Map();
8
- renderFn = () => null;
9
- boundItems = new Map();
10
- setRenderFn(renderFn) {
11
- this.renderFn = renderFn;
12
- }
13
- rebindItem(id) {
14
- const binding = this.boundItems.get(id);
15
- if (!binding)
16
- return;
17
- const fiberRoot = this.fiberRoots.get(binding.ptr);
18
- if (!fiberRoot)
19
- return;
20
- const expander = this.expanders.get(binding.ptr);
21
- if (!expander)
22
- return;
23
- this.renderBind(binding.ptr, expander, binding.treeListRow, id, fiberRoot);
24
- }
25
- getStoreTypeName() {
26
- return "tree store";
27
- }
28
- dispose() {
29
- super.dispose();
30
- this.expanders.clear();
31
- this.setupComplete.clear();
32
- this.pendingBinds.clear();
33
- this.boundItems.clear();
34
- }
35
- renderItem(_ptr) {
36
- return this.renderFn?.(null, null);
37
- }
38
- getItemFromListItem(listItem) {
39
- const treeListRow = listItem.getItem();
40
- if (!(treeListRow instanceof Gtk.TreeListRow))
41
- return null;
42
- const stringObject = treeListRow.getItem();
43
- if (!(stringObject instanceof Gtk.StringObject))
44
- return null;
45
- return this.getStore().getItem(stringObject.getString());
46
- }
47
- onSetup(listItem, ptr) {
48
- const expander = new Gtk.TreeExpander();
49
- const box = this.createBox();
50
- expander.setChild(box);
51
- listItem.setChild(expander);
52
- this.expanders.set(ptr, expander);
53
- return box;
54
- }
55
- onSetupComplete(ptr) {
56
- this.setupComplete.add(ptr);
57
- this.processPendingBind(ptr);
58
- }
59
- onBind(listItem, ptr, fiberRoot) {
60
- const expander = this.expanders.get(ptr);
61
- if (!expander)
62
- return;
63
- const treeListRow = listItem.getItem();
64
- if (!(treeListRow instanceof Gtk.TreeListRow))
65
- return;
66
- expander.setListRow(treeListRow);
67
- const stringObject = treeListRow.getItem();
68
- if (!(stringObject instanceof Gtk.StringObject))
69
- return;
70
- const id = stringObject.getString();
71
- this.boundItems.set(id, { ptr, treeListRow });
72
- if (!this.setupComplete.has(ptr)) {
73
- this.pendingBinds.set(ptr, { treeListRow, expander, id });
74
- return;
75
- }
76
- this.renderBind(ptr, expander, treeListRow, id, fiberRoot);
77
- }
78
- onUnbind(listItem) {
79
- const expander = listItem.getChild();
80
- if (expander instanceof Gtk.TreeExpander) {
81
- expander.setListRow(null);
82
- const treeListRow = listItem.getItem();
83
- if (treeListRow instanceof Gtk.TreeListRow) {
84
- const stringObject = treeListRow.getItem();
85
- if (stringObject instanceof Gtk.StringObject) {
86
- this.boundItems.delete(stringObject.getString());
87
- }
88
- }
89
- }
90
- }
91
- onTeardown(_listItem, ptr) {
92
- this.expanders.delete(ptr);
93
- this.setupComplete.delete(ptr);
94
- this.pendingBinds.delete(ptr);
95
- }
96
- processPendingBind(ptr) {
97
- const pending = this.pendingBinds.get(ptr);
98
- if (!pending)
99
- return;
100
- this.pendingBinds.delete(ptr);
101
- const fiberRoot = this.fiberRoots.get(ptr);
102
- if (fiberRoot) {
103
- this.renderBind(ptr, pending.expander, pending.treeListRow, pending.id, fiberRoot);
104
- }
105
- }
106
- renderBind(ptr, expander, treeListRow, id, fiberRoot) {
107
- const itemData = this.getStore().getItem(id);
108
- if (itemData) {
109
- if (itemData.indentForDepth !== undefined) {
110
- expander.setIndentForDepth(itemData.indentForDepth);
111
- }
112
- if (itemData.indentForIcon !== undefined) {
113
- expander.setIndentForIcon(itemData.indentForIcon);
114
- }
115
- if (itemData.hideExpander !== undefined) {
116
- expander.setHideExpander(itemData.hideExpander);
117
- }
118
- }
119
- const element = this.renderFn?.(itemData?.value ?? null, treeListRow);
120
- reconciler.getInstance().updateContainer(element, fiberRoot, null, () => {
121
- if (this.tornDown.has(ptr))
122
- return;
123
- if (this.estimatedItemHeight !== null)
124
- return;
125
- const currentExpander = this.expanders.get(ptr);
126
- if (!currentExpander)
127
- return;
128
- const box = currentExpander.getChild();
129
- if (box) {
130
- this.clearBoxSizeRequest(box);
131
- }
132
- });
133
- }
134
- }
@@ -1,12 +0,0 @@
1
- import type { Container, ContainerClass, Props } from "../../types.js";
2
- type AnyClass = new (...args: any[]) => any;
3
- export declare const matchesAnyClass: (classes: readonly AnyClass[], containerOrClass?: Container | ContainerClass | null) => boolean;
4
- export declare const matchesInterface: (methods: readonly string[], containerOrClass?: Container | ContainerClass | null) => boolean;
5
- export declare const filterProps: (props: Props, excludeKeys: readonly string[]) => Props;
6
- export declare const resolvePropMeta: (instance: Container, key: string) => [string | null, string] | null;
7
- export declare const resolveSignal: (instance: Container, signalName: string) => boolean;
8
- export declare const propNameToSignalName: (propName: string) => string;
9
- export declare const hasChanged: <T>(oldProps: T | null, newProps: T, key: keyof T) => boolean;
10
- export declare const shallowArrayEqual: <T extends Record<string, unknown>>(a: T[], b: T[]) => boolean;
11
- export declare const primitiveArrayEqual: <T extends string | number | boolean>(a: T[] | null | undefined, b: T[] | null | undefined) => boolean;
12
- export {};
@@ -1,92 +0,0 @@
1
- import { PROPS, SIGNALS } from "../../generated/internal.js";
2
- export const matchesAnyClass = (classes, containerOrClass) => {
3
- if (!containerOrClass) {
4
- return false;
5
- }
6
- return classes.some((cls) => containerOrClass instanceof cls ||
7
- containerOrClass === cls ||
8
- Object.prototype.isPrototypeOf.call(cls, containerOrClass));
9
- };
10
- export const matchesInterface = (methods, containerOrClass) => {
11
- if (!containerOrClass) {
12
- return false;
13
- }
14
- const proto = typeof containerOrClass === "function" ? containerOrClass.prototype : containerOrClass;
15
- return methods.every((method) => method in proto);
16
- };
17
- export const filterProps = (props, excludeKeys) => {
18
- const result = {};
19
- for (const key of Object.keys(props)) {
20
- if (!excludeKeys.includes(key)) {
21
- result[key] = props[key];
22
- }
23
- }
24
- return result;
25
- };
26
- const walkPrototypeChain = (instance, lookup) => {
27
- // biome-ignore lint/complexity/noBannedTypes: Walking prototype chain requires Function type
28
- let current = instance.constructor;
29
- while (current) {
30
- const typeName = current.glibTypeName;
31
- if (typeName) {
32
- const result = lookup(typeName);
33
- if (result !== null) {
34
- return result;
35
- }
36
- }
37
- const prototype = Object.getPrototypeOf(current.prototype);
38
- current = prototype?.constructor ?? null;
39
- if (current === Object || current === Function) {
40
- break;
41
- }
42
- }
43
- return null;
44
- };
45
- export const resolvePropMeta = (instance, key) => walkPrototypeChain(instance, (typeName) => PROPS[typeName]?.[key] ?? null);
46
- export const resolveSignal = (instance, signalName) => {
47
- if (signalName === "notify")
48
- return true;
49
- return walkPrototypeChain(instance, (typeName) => (SIGNALS[typeName]?.has(signalName) ? true : null)) ?? false;
50
- };
51
- export const propNameToSignalName = (propName) => {
52
- if (!propName.startsWith("on"))
53
- return propName;
54
- return propName
55
- .slice(2)
56
- .replace(/([A-Z])/g, "-$1")
57
- .toLowerCase()
58
- .replace(/^-/, "");
59
- };
60
- export const hasChanged = (oldProps, newProps, key) => !oldProps || oldProps[key] !== newProps[key];
61
- export const shallowArrayEqual = (a, b) => {
62
- if (a.length !== b.length)
63
- return false;
64
- for (let i = 0; i < a.length; i++) {
65
- const itemA = a[i];
66
- const itemB = b[i];
67
- if (!itemA || !itemB)
68
- return false;
69
- const keysA = Object.keys(itemA);
70
- const keysB = Object.keys(itemB);
71
- if (keysA.length !== keysB.length)
72
- return false;
73
- for (const key of keysA) {
74
- if (itemA[key] !== itemB[key])
75
- return false;
76
- }
77
- }
78
- return true;
79
- };
80
- export const primitiveArrayEqual = (a, b) => {
81
- if (a === b)
82
- return true;
83
- if (!a || !b)
84
- return false;
85
- if (a.length !== b.length)
86
- return false;
87
- for (let i = 0; i < a.length; i++) {
88
- if (a[i] !== b[i])
89
- return false;
90
- }
91
- return true;
92
- };
@@ -1,28 +0,0 @@
1
- import * as Gtk from "@gtkx/ffi/gtk";
2
- import type { Node } from "../../node.js";
3
- import type { Container } from "../../types.js";
4
- import { TreeStore } from "../internal/tree-store.js";
5
- import { VirtualNode } from "../virtual.js";
6
- export type TreeListProps = {
7
- autoexpand?: boolean;
8
- selectionMode?: Gtk.SelectionMode;
9
- selected?: string[];
10
- onSelectionChanged?: (ids: string[]) => void;
11
- };
12
- export declare class TreeList extends VirtualNode<TreeListProps> {
13
- private store;
14
- private treeListModel;
15
- private selectionManager;
16
- constructor(props: TreeListProps | undefined, rootContainer: Container);
17
- private createChildModel;
18
- getStore(): TreeStore;
19
- getTreeListModel(): Gtk.TreeListModel;
20
- getSelectionModel(): Gtk.NoSelection | Gtk.SingleSelection | Gtk.MultiSelection;
21
- appendChild(child: Node): void;
22
- private addItemWithChildren;
23
- insertBefore(child: Node, before: Node): void;
24
- removeChild(child: Node): void;
25
- updateProps(oldProps: TreeListProps | null, newProps: TreeListProps): void;
26
- private getSelection;
27
- private resolveSelectionIndices;
28
- }
@@ -1,113 +0,0 @@
1
- import * as Gtk from "@gtkx/ffi/gtk";
2
- import { SelectionModelManager } from "../internal/selection-model.js";
3
- import { TreeStore } from "../internal/tree-store.js";
4
- import { createTreeItemData, TreeListItemNode } from "../tree-list-item.js";
5
- import { VirtualNode } from "../virtual.js";
6
- export class TreeList extends VirtualNode {
7
- store;
8
- treeListModel;
9
- selectionManager;
10
- constructor(props = {}, rootContainer) {
11
- super("", {}, undefined, rootContainer);
12
- this.store = new TreeStore();
13
- this.treeListModel = new Gtk.TreeListModel(this.store.getRootModel(), false, props.autoexpand ?? false, (item) => this.createChildModel(item));
14
- this.selectionManager = new SelectionModelManager({ owner: this, signalStore: this.signalStore, ...props }, this.treeListModel, () => this.getSelection(), (ids) => this.resolveSelectionIndices(ids), () => this.treeListModel.getNItems());
15
- }
16
- createChildModel(item) {
17
- if (!(item instanceof Gtk.StringObject))
18
- return null;
19
- const parentId = item.getString();
20
- return this.store.getChildrenModel(parentId);
21
- }
22
- getStore() {
23
- return this.store;
24
- }
25
- getTreeListModel() {
26
- return this.treeListModel;
27
- }
28
- getSelectionModel() {
29
- return this.selectionManager.getSelectionModel();
30
- }
31
- appendChild(child) {
32
- if (!(child instanceof TreeListItemNode)) {
33
- return;
34
- }
35
- if (!child.props.id) {
36
- throw new Error("Cannot append 'TreeListItem' to 'TreeList': missing required 'id' prop");
37
- }
38
- child.setStore(this.store);
39
- this.addItemWithChildren(child);
40
- }
41
- addItemWithChildren(node, parentId) {
42
- const id = node.props.id;
43
- if (id === undefined)
44
- return;
45
- for (const child of node.getChildNodes()) {
46
- this.addItemWithChildren(child, id);
47
- }
48
- this.store.addItem(id, createTreeItemData(node.props), parentId);
49
- }
50
- insertBefore(child, before) {
51
- if (!(child instanceof TreeListItemNode) || !(before instanceof TreeListItemNode)) {
52
- return;
53
- }
54
- if (!child.props.id) {
55
- throw new Error("Cannot insert 'TreeListItem' into 'TreeList': missing required 'id' prop");
56
- }
57
- if (!before.props.id) {
58
- throw new Error("Cannot insert 'TreeListItem' into 'TreeList': 'before' node missing required 'id' prop");
59
- }
60
- const id = child.props.id;
61
- const beforeId = before.props.id;
62
- child.setStore(this.store);
63
- this.store.insertItemBefore(id, beforeId, createTreeItemData(child.props));
64
- }
65
- removeChild(child) {
66
- if (!(child instanceof TreeListItemNode)) {
67
- return;
68
- }
69
- if (!child.props.id) {
70
- throw new Error("Cannot remove 'TreeListItem' from 'TreeList': missing required 'id' prop");
71
- }
72
- const id = child.props.id;
73
- this.store.removeItem(id);
74
- child.setStore(null);
75
- }
76
- updateProps(oldProps, newProps) {
77
- super.updateProps(oldProps, newProps);
78
- if (!oldProps || oldProps.autoexpand !== newProps.autoexpand) {
79
- this.treeListModel.setAutoexpand(newProps.autoexpand ?? false);
80
- }
81
- this.selectionManager.update(oldProps ? { owner: this, signalStore: this.signalStore, ...oldProps } : null, { owner: this, signalStore: this.signalStore, ...newProps }, this.treeListModel);
82
- }
83
- getSelection() {
84
- const selection = this.selectionManager.getSelectionModel().getSelection();
85
- const size = selection.getSize();
86
- const ids = [];
87
- for (let i = 0; i < size; i++) {
88
- const index = selection.getNth(i);
89
- const row = this.treeListModel.getRow(index);
90
- if (!row)
91
- continue;
92
- const item = row.getItem();
93
- if (item instanceof Gtk.StringObject) {
94
- ids.push(item.getString());
95
- }
96
- }
97
- return ids;
98
- }
99
- resolveSelectionIndices(ids) {
100
- const nItems = this.treeListModel.getNItems();
101
- const selected = new Gtk.Bitset();
102
- for (let i = 0; i < nItems; i++) {
103
- const row = this.treeListModel.getRow(i);
104
- if (!row)
105
- continue;
106
- const item = row.getItem();
107
- if (item instanceof Gtk.StringObject && ids.includes(item.getString())) {
108
- selected.add(i);
109
- }
110
- }
111
- return selected;
112
- }
113
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- import { PACK_INTERFACE_METHODS } from "../generated/internal.js";
2
- import { registerNodeClass } from "../registry.js";
3
- import { VirtualContainerNode } from "./abstract/virtual-container.js";
4
- import { matchesInterface } from "./internal/utils.js";
5
- class PackStartNode extends VirtualContainerNode {
6
- static priority = 1;
7
- static matches(type) {
8
- return type === "PackStart";
9
- }
10
- canBeChildOf(parent) {
11
- return matchesInterface(PACK_INTERFACE_METHODS, parent.container);
12
- }
13
- attachChild(parent, widget) {
14
- parent.packStart(widget);
15
- }
16
- }
17
- class PackEndNode extends VirtualContainerNode {
18
- static priority = 1;
19
- static matches(type) {
20
- return type === "PackEnd";
21
- }
22
- canBeChildOf(parent) {
23
- return matchesInterface(PACK_INTERFACE_METHODS, parent.container);
24
- }
25
- attachChild(parent, widget) {
26
- parent.packEnd(widget);
27
- }
28
- }
29
- registerNodeClass(PackStartNode);
30
- registerNodeClass(PackEndNode);
@@ -1,9 +0,0 @@
1
- import type { StringListItemProps } from "../jsx.js";
2
- import type { SimpleListStore } from "./internal/simple-list-store.js";
3
- import { ListItemNode } from "./list-item.js";
4
- type Props = Partial<StringListItemProps>;
5
- export declare class SimpleListItemNode extends ListItemNode<SimpleListStore, Props> {
6
- static priority: number;
7
- static matches(type: string): boolean;
8
- }
9
- export {};
@@ -1,9 +0,0 @@
1
- import { registerNodeClass } from "../registry.js";
2
- import { ListItemNode } from "./list-item.js";
3
- export class SimpleListItemNode extends ListItemNode {
4
- static priority = -1;
5
- static matches(type) {
6
- return type === "SimpleListItem";
7
- }
8
- }
9
- registerNodeClass(SimpleListItemNode);
@@ -1 +0,0 @@
1
- export {};
@@ -1,74 +0,0 @@
1
- import { DROP_DOWN_CLASSES } from "../generated/internal.js";
2
- import { registerNodeClass } from "../registry.js";
3
- import { SimpleListStore } from "./internal/simple-list-store.js";
4
- import { filterProps, matchesAnyClass } from "./internal/utils.js";
5
- import { SimpleListItemNode } from "./simple-list-item.js";
6
- import { WidgetNode } from "./widget.js";
7
- const PROP_NAMES = ["selectedId", "onSelectionChanged"];
8
- class SimpleListViewNode extends WidgetNode {
9
- static priority = -1;
10
- static matches(_type, containerOrClass) {
11
- return matchesAnyClass(DROP_DOWN_CLASSES, containerOrClass);
12
- }
13
- store = new SimpleListStore();
14
- constructor(typeName, props, container, rootContainer) {
15
- super(typeName, props, container, rootContainer);
16
- this.container.setModel(this.store.getModel());
17
- }
18
- updateProps(oldProps, newProps) {
19
- if (!oldProps || oldProps.onSelectionChanged !== newProps.onSelectionChanged) {
20
- const onSelectionChanged = newProps.onSelectionChanged;
21
- const handleSelectionChange = onSelectionChanged
22
- ? () => {
23
- const selectedIndex = this.container.getSelected();
24
- const id = this.store.getIdAtIndex(selectedIndex);
25
- if (id !== null) {
26
- onSelectionChanged(id);
27
- }
28
- }
29
- : undefined;
30
- this.signalStore.set(this, this.container, "notify::selected", handleSelectionChange);
31
- }
32
- if (!oldProps || oldProps.selectedId !== newProps.selectedId) {
33
- const index = newProps.selectedId !== undefined ? this.store.getIndexById(newProps.selectedId) : null;
34
- if (index !== null) {
35
- this.container.setSelected(index);
36
- }
37
- }
38
- super.updateProps(oldProps ? filterProps(oldProps, PROP_NAMES) : null, filterProps(newProps, PROP_NAMES));
39
- }
40
- appendChild(child) {
41
- if (!(child instanceof SimpleListItemNode)) {
42
- throw new Error(`Cannot append '${child.typeName}' to 'DropDown': expected x.SimpleListItem`);
43
- }
44
- const { id, value } = child.props;
45
- if (!id || value === undefined) {
46
- throw new Error("Expected 'id' and 'value' props to be present on SimpleListItem");
47
- }
48
- child.setStore(this.store);
49
- this.store.addItem(id, value);
50
- }
51
- insertBefore(child, before) {
52
- if (!(child instanceof SimpleListItemNode) || !(before instanceof SimpleListItemNode)) {
53
- throw new Error(`Cannot insert '${child.typeName}' into 'DropDown': expected x.SimpleListItem`);
54
- }
55
- const { id, value } = child.props;
56
- const beforeId = before.props.id;
57
- if (!id || value === undefined || !beforeId) {
58
- throw new Error("Expected 'id' and 'value' props to be present on SimpleListItem");
59
- }
60
- child.setStore(this.store);
61
- this.store.insertItemBefore(id, beforeId, value);
62
- }
63
- removeChild(child) {
64
- if (!(child instanceof SimpleListItemNode)) {
65
- throw new Error(`Cannot remove '${child.typeName}' from 'DropDown': expected x.SimpleListItem`);
66
- }
67
- const { id } = child.props;
68
- if (!id) {
69
- throw new Error("Expected 'id' prop to be present on SimpleListItem");
70
- }
71
- this.store.removeItem(id);
72
- }
73
- }
74
- registerNodeClass(SimpleListViewNode);
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- import { registerNodeClass } from "../registry.js";
2
- import { VirtualContainerNode } from "./abstract/virtual-container.js";
3
- import { matchesInterface } from "./internal/utils.js";
4
- const TOOLBAR_INTERFACE_METHODS = ["addTopBar", "addBottomBar", "remove"];
5
- class ToolbarTopNode extends VirtualContainerNode {
6
- static priority = 1;
7
- static matches(type) {
8
- return type === "ToolbarTop";
9
- }
10
- canBeChildOf(parent) {
11
- return matchesInterface(TOOLBAR_INTERFACE_METHODS, parent.container);
12
- }
13
- attachChild(parent, widget) {
14
- parent.addTopBar(widget);
15
- }
16
- }
17
- class ToolbarBottomNode extends VirtualContainerNode {
18
- static priority = 1;
19
- static matches(type) {
20
- return type === "ToolbarBottom";
21
- }
22
- canBeChildOf(parent) {
23
- return matchesInterface(TOOLBAR_INTERFACE_METHODS, parent.container);
24
- }
25
- attachChild(parent, widget) {
26
- parent.addBottomBar(widget);
27
- }
28
- }
29
- registerNodeClass(ToolbarTopNode);
30
- registerNodeClass(ToolbarBottomNode);
@@ -1,22 +0,0 @@
1
- import type { TreeListItemProps } from "../jsx.js";
2
- import type { Node } from "../node.js";
3
- import type { TreeItemData, TreeStore } from "./internal/tree-store.js";
4
- import { VirtualNode } from "./virtual.js";
5
- type Props = Partial<TreeListItemProps>;
6
- export declare const createTreeItemData: (props: Props) => TreeItemData;
7
- export declare class TreeListItemNode extends VirtualNode<Props> {
8
- static priority: number;
9
- private store;
10
- private parentItemId;
11
- private childNodes;
12
- static matches(type: string): boolean;
13
- setStore(store: TreeStore | null): void;
14
- getChildNodes(): readonly TreeListItemNode[];
15
- setParentItemId(parentId: string | null): void;
16
- getParentItemId(): string | null;
17
- appendChild(child: Node): void;
18
- insertBefore(child: Node, before: Node): void;
19
- removeChild(child: Node): void;
20
- updateProps(oldProps: Props | null, newProps: Props): void;
21
- }
22
- export {};