@gtkx/react 0.1.43 → 0.1.44
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,11 @@ ${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/** Called when the text buffer content changes */`);
|
|
335
|
+
lines.push(`\tonChanged?: (text: string) => void;`);
|
|
336
|
+
}
|
|
330
337
|
lines.push("");
|
|
331
338
|
lines.push(`\tref?: Ref<Gtk.${widgetName}>;`);
|
|
332
339
|
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,7 @@ 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
|
+
onChanged?: (text: string) => void;
|
|
1180
1181
|
ref?: Ref<Gtk.TextView>;
|
|
1181
1182
|
}
|
|
1182
1183
|
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,52 @@
|
|
|
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
|
+
export class TextViewNode extends Node {
|
|
13
|
+
static matches(type) {
|
|
14
|
+
return type === "TextView";
|
|
15
|
+
}
|
|
16
|
+
buffer;
|
|
17
|
+
onChanged;
|
|
18
|
+
bufferChangedHandlerId;
|
|
19
|
+
constructor(type, props, app) {
|
|
20
|
+
super(type, props, app);
|
|
21
|
+
this.buffer = this.widget.getBuffer();
|
|
22
|
+
this.onChanged = props.onChanged;
|
|
23
|
+
queueMicrotask(() => this.connectBufferSignal());
|
|
24
|
+
}
|
|
25
|
+
connectBufferSignal() {
|
|
26
|
+
if (this.onChanged && this.bufferChangedHandlerId === undefined) {
|
|
27
|
+
this.bufferChangedHandlerId = this.buffer.connect("changed", () => {
|
|
28
|
+
const text = getBufferText(this.buffer);
|
|
29
|
+
this.onChanged?.(text);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
disconnectBufferSignal() {
|
|
34
|
+
if (this.bufferChangedHandlerId !== undefined) {
|
|
35
|
+
GObject.signalHandlerDisconnect(this.buffer, this.bufferChangedHandlerId);
|
|
36
|
+
this.bufferChangedHandlerId = undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
consumedProps() {
|
|
40
|
+
const consumed = super.consumedProps();
|
|
41
|
+
consumed.add("onChanged");
|
|
42
|
+
return consumed;
|
|
43
|
+
}
|
|
44
|
+
updateProps(oldProps, newProps) {
|
|
45
|
+
if (this.buffer && oldProps.onChanged !== newProps.onChanged) {
|
|
46
|
+
this.disconnectBufferSignal();
|
|
47
|
+
this.onChanged = newProps.onChanged;
|
|
48
|
+
this.connectBufferSignal();
|
|
49
|
+
}
|
|
50
|
+
super.updateProps(oldProps, newProps);
|
|
51
|
+
}
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
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.44"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gtkx/gir": "0.1.
|
|
42
|
+
"@gtkx/gir": "0.1.44"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": "^19"
|