@gtkx/react 0.1.43 → 0.1.45
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.
|
@@ -5,6 +5,7 @@ const COLUMN_VIEW_WIDGET = "ColumnView";
|
|
|
5
5
|
const DROPDOWN_WIDGETS = new Set(["DropDown"]);
|
|
6
6
|
const GRID_WIDGETS = new Set(["Grid"]);
|
|
7
7
|
const NOTEBOOK_WIDGET = "Notebook";
|
|
8
|
+
const TEXT_VIEW_WIDGET = "TextView";
|
|
8
9
|
const INTERNALLY_PROVIDED_PARAMS = {
|
|
9
10
|
ApplicationWindow: new Set(["application"]),
|
|
10
11
|
};
|
|
@@ -33,6 +34,7 @@ const isColumnViewWidget = (widgetName) => widgetName === COLUMN_VIEW_WIDGET;
|
|
|
33
34
|
const isDropDownWidget = (widgetName) => DROPDOWN_WIDGETS.has(widgetName);
|
|
34
35
|
const isGridWidget = (widgetName) => GRID_WIDGETS.has(widgetName);
|
|
35
36
|
const isNotebookWidget = (widgetName) => widgetName === NOTEBOOK_WIDGET;
|
|
37
|
+
const isTextViewWidget = (widgetName) => widgetName === TEXT_VIEW_WIDGET;
|
|
36
38
|
const sanitizeDoc = (doc) => {
|
|
37
39
|
let result = doc;
|
|
38
40
|
result = result.replace(/<picture>[\s\S]*?<\/picture>/gi, "");
|
|
@@ -327,6 +329,13 @@ ${widgetPropsContent}
|
|
|
327
329
|
lines.push(`\t/** Called when selection changes */`);
|
|
328
330
|
lines.push(`\tonSelectionChanged?: (item: any, index: number) => void;`);
|
|
329
331
|
}
|
|
332
|
+
if (isTextViewWidget(widget.name)) {
|
|
333
|
+
lines.push("");
|
|
334
|
+
lines.push(`\t/** The contents of the text buffer. */`);
|
|
335
|
+
lines.push(`\ttext?: string;`);
|
|
336
|
+
lines.push(`\t/** Called when the text buffer content changes */`);
|
|
337
|
+
lines.push(`\tonChanged?: (text: string) => void;`);
|
|
338
|
+
}
|
|
330
339
|
lines.push("");
|
|
331
340
|
lines.push(`\tref?: Ref<Gtk.${widgetName}>;`);
|
|
332
341
|
lines.push(`}`);
|
package/dist/factory.js
CHANGED
|
@@ -6,6 +6,7 @@ import { NotebookNode, NotebookPageNode } from "./nodes/notebook.js";
|
|
|
6
6
|
import { OverlayNode } from "./nodes/overlay.js";
|
|
7
7
|
import { RootNode } from "./nodes/root.js";
|
|
8
8
|
import { SlotNode } from "./nodes/slot.js";
|
|
9
|
+
import { TextViewNode } from "./nodes/text-view.js";
|
|
9
10
|
import { WidgetNode } from "./nodes/widget.js";
|
|
10
11
|
export { ROOT_NODE_CONTAINER } from "./nodes/root.js";
|
|
11
12
|
const NODE_CLASSES = [
|
|
@@ -17,6 +18,7 @@ const NODE_CLASSES = [
|
|
|
17
18
|
GridChildNode,
|
|
18
19
|
NotebookPageNode,
|
|
19
20
|
SlotNode,
|
|
21
|
+
TextViewNode,
|
|
20
22
|
DropDownNode,
|
|
21
23
|
GridNode,
|
|
22
24
|
OverlayNode,
|
package/dist/generated/jsx.d.ts
CHANGED
|
@@ -1177,6 +1177,8 @@ export interface TextViewProps extends WidgetProps {
|
|
|
1177
1177
|
onSetAnchor?: (self: Gtk.TextView) => void;
|
|
1178
1178
|
onToggleCursorVisible?: (self: Gtk.TextView) => void;
|
|
1179
1179
|
onToggleOverwrite?: (self: Gtk.TextView) => void;
|
|
1180
|
+
text?: string;
|
|
1181
|
+
onChanged?: (text: string) => void;
|
|
1180
1182
|
ref?: Ref<Gtk.TextView>;
|
|
1181
1183
|
}
|
|
1182
1184
|
export interface ToggleButtonProps extends ButtonProps {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import type { Props } from "../factory.js";
|
|
3
|
+
import { Node } from "../node.js";
|
|
4
|
+
export declare class TextViewNode extends Node<Gtk.TextView> {
|
|
5
|
+
static matches(type: string): boolean;
|
|
6
|
+
private buffer;
|
|
7
|
+
private onChanged?;
|
|
8
|
+
private bufferChangedHandlerId?;
|
|
9
|
+
constructor(type: string, props: Props, app: Gtk.Application);
|
|
10
|
+
private connectBufferSignal;
|
|
11
|
+
private disconnectBufferSignal;
|
|
12
|
+
protected consumedProps(): Set<string>;
|
|
13
|
+
updateProps(oldProps: Props, newProps: Props): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createRef } from "@gtkx/ffi";
|
|
2
|
+
import * as GObject from "@gtkx/ffi/gobject";
|
|
3
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
4
|
+
import { Node } from "../node.js";
|
|
5
|
+
const getBufferText = (buffer) => {
|
|
6
|
+
const startRef = createRef(new Gtk.TextIter());
|
|
7
|
+
const endRef = createRef(new Gtk.TextIter());
|
|
8
|
+
buffer.getStartIter(startRef);
|
|
9
|
+
buffer.getEndIter(endRef);
|
|
10
|
+
return buffer.getText(startRef.value, endRef.value, true);
|
|
11
|
+
};
|
|
12
|
+
const setBufferText = (buffer, text) => {
|
|
13
|
+
buffer.setText(text, -1);
|
|
14
|
+
};
|
|
15
|
+
export class TextViewNode extends Node {
|
|
16
|
+
static matches(type) {
|
|
17
|
+
return type === "TextView";
|
|
18
|
+
}
|
|
19
|
+
buffer;
|
|
20
|
+
onChanged;
|
|
21
|
+
bufferChangedHandlerId;
|
|
22
|
+
constructor(type, props, app) {
|
|
23
|
+
super(type, props, app);
|
|
24
|
+
this.buffer = this.widget.getBuffer();
|
|
25
|
+
this.onChanged = props.onChanged;
|
|
26
|
+
if (typeof props.text === "string") {
|
|
27
|
+
setBufferText(this.buffer, props.text);
|
|
28
|
+
}
|
|
29
|
+
queueMicrotask(() => this.connectBufferSignal());
|
|
30
|
+
}
|
|
31
|
+
connectBufferSignal() {
|
|
32
|
+
if (this.onChanged && this.bufferChangedHandlerId === undefined) {
|
|
33
|
+
this.bufferChangedHandlerId = this.buffer.connect("changed", () => {
|
|
34
|
+
const text = getBufferText(this.buffer);
|
|
35
|
+
this.onChanged?.(text);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
disconnectBufferSignal() {
|
|
40
|
+
if (this.bufferChangedHandlerId !== undefined) {
|
|
41
|
+
GObject.signalHandlerDisconnect(this.buffer, this.bufferChangedHandlerId);
|
|
42
|
+
this.bufferChangedHandlerId = undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
consumedProps() {
|
|
46
|
+
const consumed = super.consumedProps();
|
|
47
|
+
consumed.add("text");
|
|
48
|
+
consumed.add("onChanged");
|
|
49
|
+
return consumed;
|
|
50
|
+
}
|
|
51
|
+
updateProps(oldProps, newProps) {
|
|
52
|
+
if (this.buffer && oldProps.onChanged !== newProps.onChanged) {
|
|
53
|
+
this.disconnectBufferSignal();
|
|
54
|
+
this.onChanged = newProps.onChanged;
|
|
55
|
+
this.connectBufferSignal();
|
|
56
|
+
}
|
|
57
|
+
if (this.buffer && oldProps.text !== newProps.text && typeof newProps.text === "string") {
|
|
58
|
+
const currentText = getBufferText(this.buffer);
|
|
59
|
+
if (currentText !== newProps.text) {
|
|
60
|
+
setBufferText(this.buffer, newProps.text);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
super.updateProps(oldProps, newProps);
|
|
64
|
+
}
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
4
4
|
"description": "Build GTK4 desktop applications with React and TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtk",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"react-reconciler": "0.33.0",
|
|
39
|
-
"@gtkx/ffi": "0.1.
|
|
39
|
+
"@gtkx/ffi": "0.1.45"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gtkx/gir": "0.1.
|
|
42
|
+
"@gtkx/gir": "0.1.45"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": "^19"
|