@gtkx/react 1.3.0 → 1.5.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.
- package/README.md +5 -4
- package/dist/adw/dialog.js +2 -2
- package/dist/adw/dialog.js.map +1 -1
- package/dist/adw/element-behaviors.js +19 -107
- package/dist/adw/element-behaviors.js.map +1 -1
- package/dist/components/application.d.ts.map +1 -1
- package/dist/components/application.js +3 -3
- package/dist/components/application.js.map +1 -1
- package/dist/components/window.js +3 -3
- package/dist/components/window.js.map +1 -1
- package/dist/element-behaviors.js +55 -60
- package/dist/element-behaviors.js.map +1 -1
- package/dist/element-config.js +1 -1
- package/dist/element-config.js.map +1 -1
- package/dist/hooks/use-bind-setting.d.ts.map +1 -1
- package/dist/hooks/use-bind-setting.js +3 -2
- package/dist/hooks/use-bind-setting.js.map +1 -1
- package/dist/hooks/use-property.d.ts +1 -1
- package/dist/hooks/use-property.d.ts.map +1 -1
- package/dist/hooks/use-property.js +5 -1
- package/dist/hooks/use-property.js.map +1 -1
- package/dist/prop-types.d.ts +9 -1
- package/dist/prop-types.d.ts.map +1 -1
- package/dist/prop-types.js.map +1 -1
- package/dist/reconciler/apply-props.d.ts +2 -1
- package/dist/reconciler/apply-props.d.ts.map +1 -1
- package/dist/reconciler/apply-props.js +59 -24
- package/dist/reconciler/apply-props.js.map +1 -1
- package/dist/reconciler/behaviors.d.ts +19 -3
- package/dist/reconciler/behaviors.d.ts.map +1 -1
- package/dist/reconciler/behaviors.js +73 -17
- package/dist/reconciler/behaviors.js.map +1 -1
- package/dist/reconciler/host-config.d.ts.map +1 -1
- package/dist/reconciler/host-config.js +2 -1
- package/dist/reconciler/host-config.js.map +1 -1
- package/dist/reconciler/metadata.d.ts +6 -1
- package/dist/reconciler/metadata.d.ts.map +1 -1
- package/dist/reconciler/metadata.js +39 -6
- package/dist/reconciler/metadata.js.map +1 -1
- package/dist/reconciler/placement.js +4 -4
- package/dist/reconciler/placement.js.map +1 -1
- package/dist/reconciler/registry.d.ts +2 -0
- package/dist/reconciler/registry.d.ts.map +1 -1
- package/dist/reconciler/registry.js.map +1 -1
- package/dist/reconciler/root.d.ts.map +1 -1
- package/dist/reconciler/root.js.map +1 -1
- package/dist/reconciler/signals.d.ts +3 -2
- package/dist/reconciler/signals.d.ts.map +1 -1
- package/dist/reconciler/signals.js +49 -16
- package/dist/reconciler/signals.js.map +1 -1
- package/dist/reconciler/style.d.ts +2 -1
- package/dist/reconciler/style.d.ts.map +1 -1
- package/dist/reconciler/style.js +4 -3
- package/dist/reconciler/style.js.map +1 -1
- package/dist/reconciler/text.js +3 -3
- package/dist/reconciler/text.js.map +1 -1
- package/env.d.ts +10 -7
- package/package.json +6 -6
- package/src/adw/dialog.tsx +2 -2
- package/src/adw/element-behaviors.ts +22 -162
- package/src/components/application.tsx +18 -3
- package/src/components/window.tsx +3 -3
- package/src/element-behaviors.ts +75 -96
- package/src/element-config.ts +1 -1
- package/src/hooks/use-bind-setting.ts +3 -2
- package/src/hooks/use-property.ts +6 -2
- package/src/prop-types.ts +10 -0
- package/src/reconciler/apply-props.ts +73 -26
- package/src/reconciler/behaviors.ts +130 -33
- package/src/reconciler/host-config.ts +3 -1
- package/src/reconciler/metadata.ts +62 -6
- package/src/reconciler/placement.ts +4 -4
- package/src/reconciler/registry.ts +2 -0
- package/src/reconciler/root.ts +1 -1
- package/src/reconciler/signals.ts +62 -17
- package/src/reconciler/style.ts +4 -3
- package/src/reconciler/text.ts +3 -3
package/src/prop-types.ts
CHANGED
|
@@ -246,6 +246,15 @@ type GtkScaleProps = {
|
|
|
246
246
|
marks?: ScaleMark[] | null | undefined;
|
|
247
247
|
};
|
|
248
248
|
|
|
249
|
+
/** Props of a `Gtk.ListBox` element. */
|
|
250
|
+
type GtkListBoxProps = {
|
|
251
|
+
/**
|
|
252
|
+
* Index of the row to select; `-1` or `null` selects none. Applied once the row exists, and
|
|
253
|
+
* re-applied whenever the box's own selection drifts from it. Left alone while the prop is absent.
|
|
254
|
+
*/
|
|
255
|
+
selectedIndex?: number | null | undefined;
|
|
256
|
+
} & ChildrenProps;
|
|
257
|
+
|
|
249
258
|
/** Props of a `Gtk.Calendar` element. */
|
|
250
259
|
type GtkCalendarProps = {
|
|
251
260
|
/** Days of the shown month drawn as marked, cleared and re-marked whenever the list changes. */
|
|
@@ -324,6 +333,7 @@ export {
|
|
|
324
333
|
type GtkConstraintLayoutProps,
|
|
325
334
|
type GtkHeaderBarProps,
|
|
326
335
|
type GtkScaleProps,
|
|
336
|
+
type GtkListBoxProps,
|
|
327
337
|
type GtkCalendarProps,
|
|
328
338
|
type GtkLevelBarProps,
|
|
329
339
|
type GtkSizeGroupProps,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type * as GObject from "@gtkx/gi/gobject";
|
|
2
1
|
import type { SignalHandler } from "@gtkx/runtime";
|
|
2
|
+
import * as GObject from "@gtkx/gi/gobject";
|
|
3
3
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
4
|
-
import { coerceObjectProperty } from "@gtkx/runtime";
|
|
5
|
-
import { drain, isDeepEqual, kebabCase } from "@gtkx/utils";
|
|
4
|
+
import { coerceObjectProperty, getInstanceType, signalForHandlerName, TYPE_INVALID } from "@gtkx/runtime";
|
|
5
|
+
import { drain, isDeepEqual, kebabCase, lowerFirst, unsanitizeIdentifier } from "@gtkx/utils";
|
|
6
6
|
import type { ElementBehavior, Props } from "./registry.js";
|
|
7
7
|
import { applyAccessibleProps, isAccessibleProp } from "../utils/accessible-props.js";
|
|
8
|
-
import { type TypeInfo, typeInfoFor } from "./metadata.js";
|
|
8
|
+
import { getPropertyName, hasProperty, type TypeInfo, typeInfoFor } from "./metadata.js";
|
|
9
9
|
import { type ElementNode, getOrCreateContext, type SignalTarget } from "./node.js";
|
|
10
10
|
import { applyWrite, connectHandler, disconnectHandler } from "./signals.js";
|
|
11
11
|
import { bufferText, hasSameText, isContentPaintableProp, markTextDirty, TEXT_PROP } from "./text.js";
|
|
@@ -16,29 +16,53 @@ type PropChange = { prev: Props; next: Props };
|
|
|
16
16
|
|
|
17
17
|
const REACT_RESERVED_PROPS = new Set(["children", "ref", "key"]);
|
|
18
18
|
const NOTIFY_PREFIX = "onNotify";
|
|
19
|
-
const HANDLER_PREFIX = "on";
|
|
20
19
|
const HANDLER_NAME = /^on[A-Z]/;
|
|
21
20
|
const flushDirty: Set<ElementNode> = new Set();
|
|
22
21
|
const accessibleDirty: Map<ElementNode, Props> = new Map();
|
|
23
|
-
const mapWatched:
|
|
22
|
+
const mapWatched: WeakMap<ElementNode, () => void> = new WeakMap();
|
|
24
23
|
const pendingMap: Set<ElementNode> = new Set();
|
|
25
24
|
|
|
26
25
|
const isHandlerName = (name: string): boolean => HANDLER_NAME.test(name);
|
|
26
|
+
const notifiedAccessor = (name: string): string => lowerFirst(name.slice(NOTIFY_PREFIX.length));
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const unknownSignalError = (typeName: string, name: string): Error =>
|
|
29
|
+
new Error(
|
|
30
|
+
`The handler prop '${name}' of <${typeName}> names no signal ${typeName} carries. Name a ` +
|
|
31
|
+
`signal the element carries, or declare the one '${name}' stands for on ${typeName} when ` +
|
|
32
|
+
"its class is registered.",
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const lookedUpSignal = (target: SignalTarget, name: string): string => {
|
|
36
|
+
const type = getInstanceType(target.object);
|
|
37
|
+
const signal = type === TYPE_INVALID ? undefined : signalForHandlerName(type, name);
|
|
38
|
+
|
|
39
|
+
if (signal === undefined) {
|
|
40
|
+
throw unknownSignalError(target.typeName, name);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return signal;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const signalForProp = (target: SignalTarget, info: TypeInfo, name: string): string => {
|
|
29
47
|
if (name === NOTIFY_PREFIX) {
|
|
30
48
|
return "notify";
|
|
31
49
|
}
|
|
32
50
|
|
|
33
51
|
if (name.startsWith(NOTIFY_PREFIX) && name.length > NOTIFY_PREFIX.length) {
|
|
34
|
-
|
|
52
|
+
const accessor = notifiedAccessor(name);
|
|
53
|
+
const property = getPropertyName(target.object, accessor) ?? unsanitizeIdentifier(kebabCase(accessor));
|
|
54
|
+
|
|
55
|
+
return `notify::${property}`;
|
|
35
56
|
}
|
|
36
57
|
|
|
37
|
-
return info.signals[name] ??
|
|
58
|
+
return info.signals[name] ?? lookedUpSignal(target, name);
|
|
38
59
|
};
|
|
39
60
|
|
|
40
61
|
const isReservedName = (name: string, info: TypeInfo): boolean =>
|
|
41
|
-
REACT_RESERVED_PROPS.has(name) ||
|
|
62
|
+
REACT_RESERVED_PROPS.has(name) ||
|
|
63
|
+
(isHandlerName(name) && !hasProperty(info, name)) ||
|
|
64
|
+
(isAccessibleProp(name) && !hasProperty(info, name)) ||
|
|
65
|
+
info.constructOnly.has(name);
|
|
42
66
|
|
|
43
67
|
const isSkippedValueName = (name: string, info: TypeInfo, consumed: Set<string>): boolean =>
|
|
44
68
|
isReservedName(name, info) || consumed.has(name);
|
|
@@ -48,7 +72,7 @@ const writeValue = (object: GObject.Object, name: string, value: unknown): void
|
|
|
48
72
|
return;
|
|
49
73
|
}
|
|
50
74
|
|
|
51
|
-
applyWrite(() => {
|
|
75
|
+
applyWrite(name, () => {
|
|
52
76
|
Reflect.set(object, name, coerceObjectProperty(object, name, value));
|
|
53
77
|
});
|
|
54
78
|
};
|
|
@@ -72,7 +96,7 @@ const applyBufferText = (buffer: Gtk.TextBuffer, text: string): void => {
|
|
|
72
96
|
return;
|
|
73
97
|
}
|
|
74
98
|
|
|
75
|
-
applyWrite(() => {
|
|
99
|
+
applyWrite(TEXT_PROP, () => {
|
|
76
100
|
buffer.beginIrreversibleAction();
|
|
77
101
|
buffer.setText(text, -1);
|
|
78
102
|
buffer.endIrreversibleAction();
|
|
@@ -191,24 +215,26 @@ const restoreActionableSensitivity = (node: ElementNode, info: TypeInfo, prev: P
|
|
|
191
215
|
const desired = "sensitive" in next ? next.sensitive : info.defaults.sensitive;
|
|
192
216
|
|
|
193
217
|
if (typeof desired === "boolean") {
|
|
194
|
-
applyWrite(() => {
|
|
218
|
+
applyWrite("sensitive", () => {
|
|
195
219
|
Reflect.set(node.object, "sensitive", desired);
|
|
196
220
|
});
|
|
197
221
|
}
|
|
198
222
|
};
|
|
199
223
|
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
if (!isHandlerName(name)) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
224
|
+
const applyHandler = (target: SignalTarget, info: TypeInfo, name: string, next: Props): void => {
|
|
225
|
+
const value = next[name];
|
|
205
226
|
|
|
206
|
-
|
|
227
|
+
if (typeof value === "function") {
|
|
228
|
+
connectHandler(target, name, signalForProp(target, info, name), value as SignalHandler);
|
|
229
|
+
} else {
|
|
230
|
+
disconnectHandler(target, name);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
207
233
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
234
|
+
const applyHandlers = (target: SignalTarget, info: TypeInfo, prev: Props, next: Props): void => {
|
|
235
|
+
eachChangedName(prev, next, (name) => {
|
|
236
|
+
if (isHandlerName(name) && !hasProperty(info, name)) {
|
|
237
|
+
applyHandler(target, info, name, next);
|
|
212
238
|
}
|
|
213
239
|
});
|
|
214
240
|
};
|
|
@@ -231,6 +257,15 @@ const flushBehaviors = (): void => {
|
|
|
231
257
|
});
|
|
232
258
|
};
|
|
233
259
|
|
|
260
|
+
const teardownBehaviors = (node: ElementNode): void => {
|
|
261
|
+
flushDirty.delete(node);
|
|
262
|
+
unwatchMap(node);
|
|
263
|
+
|
|
264
|
+
for (const [behavior, context] of node.contexts) {
|
|
265
|
+
behavior.teardown?.(node.object, context);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
234
269
|
const applyAccessible = (object: GObject.Object, prev: Props | null, next: Props): void => {
|
|
235
270
|
if (object instanceof Gtk.Accessible) {
|
|
236
271
|
applyAccessibleProps(object, prev, next);
|
|
@@ -260,14 +295,25 @@ const watchMap = (node: ElementNode): void => {
|
|
|
260
295
|
return;
|
|
261
296
|
}
|
|
262
297
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
object.connect("map", () => {
|
|
298
|
+
const onMapped = (): undefined => {
|
|
266
299
|
pendingMap.add(node);
|
|
267
300
|
setTimeout(settleAccessible, 0);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
object.on("map", onMapped);
|
|
304
|
+
|
|
305
|
+
mapWatched.set(node, () => {
|
|
306
|
+
object.off("map", onMapped);
|
|
268
307
|
});
|
|
269
308
|
};
|
|
270
309
|
|
|
310
|
+
const unwatchMap = (node: ElementNode): void => {
|
|
311
|
+
mapWatched.get(node)?.();
|
|
312
|
+
mapWatched.delete(node);
|
|
313
|
+
pendingMap.delete(node);
|
|
314
|
+
accessibleDirty.delete(node);
|
|
315
|
+
};
|
|
316
|
+
|
|
271
317
|
const settleAccessible = (): void => {
|
|
272
318
|
drain(pendingMap, (node) => {
|
|
273
319
|
if (node.object instanceof Gtk.Widget && node.object.getMapped()) {
|
|
@@ -319,6 +365,7 @@ export {
|
|
|
319
365
|
flushAccessible,
|
|
320
366
|
settleAccessible,
|
|
321
367
|
flushBehaviors,
|
|
368
|
+
teardownBehaviors,
|
|
322
369
|
applyElementProps,
|
|
323
370
|
applyAdoptedProps,
|
|
324
371
|
assertPropsCanChange,
|
|
@@ -10,8 +10,9 @@ import {
|
|
|
10
10
|
typeFromName,
|
|
11
11
|
typeIsA,
|
|
12
12
|
} from "@gtkx/runtime";
|
|
13
|
-
import { getOrInsert, isDeepEqual, structuredClone } from "@gtkx/utils";
|
|
13
|
+
import { getOrInsert, isDeepEqual, kebabCase, structuredClone, unsanitizeIdentifier } from "@gtkx/utils";
|
|
14
14
|
import type { DetachInfo, ElementBehavior, PlaceInfo, Props } from "./registry.js";
|
|
15
|
+
import { getPropertyName } from "./metadata.js";
|
|
15
16
|
import { applyWrite } from "./signals.js";
|
|
16
17
|
import { hasSameText } from "./text.js";
|
|
17
18
|
|
|
@@ -32,10 +33,26 @@ type ListHooks<P extends GObject.Object, I, H> = {
|
|
|
32
33
|
|
|
33
34
|
type ListEntry = { item: unknown; handle: unknown };
|
|
34
35
|
type ListState = { snapshot: unknown[]; entries: ListEntry[] };
|
|
35
|
-
type DeferredState = { desired: unknown; isPresent: boolean;
|
|
36
|
+
type DeferredState = { desired: unknown; isPresent: boolean; isScheduled: boolean; disconnect: (() => void) | null };
|
|
36
37
|
type CanApply<P extends GObject.Object, V> = (object: P, value: V) => boolean;
|
|
38
|
+
|
|
39
|
+
type DeferredOps<P extends GObject.Object, V> = {
|
|
40
|
+
canApply?: CanApply<P, V> | undefined;
|
|
41
|
+
parse?: ((value: unknown) => V | undefined) | undefined;
|
|
42
|
+
read: (object: P) => unknown;
|
|
43
|
+
write: (object: P, value: V) => void;
|
|
44
|
+
signal?: string | undefined;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type DeferredHooks<P extends GObject.Object, V> = Omit<DeferredOps<P, V>, "read" | "write"> & {
|
|
48
|
+
read?: ((object: P) => unknown) | undefined;
|
|
49
|
+
write?: ((object: P, value: V) => void) | undefined;
|
|
50
|
+
};
|
|
51
|
+
|
|
37
52
|
type ChildSetter = GObject.Object & { setChild: (child: Gtk.Widget | null) => void };
|
|
38
53
|
type ContentSetter<C extends Gtk.Widget> = GObject.Object & { setContent: (content: C | null) => void };
|
|
54
|
+
type MatchingKey<P, F> = keyof P & string & { [K in keyof P]: P[K] extends F ? K : never }[keyof P];
|
|
55
|
+
type MethodKey<P, A> = MatchingKey<P, (argument: A) => unknown>;
|
|
39
56
|
|
|
40
57
|
type BoxLike = GObject.Object & {
|
|
41
58
|
remove: (child: Gtk.Widget) => void;
|
|
@@ -170,51 +187,109 @@ const list = <P extends GObject.Object, I, H = void>(
|
|
|
170
187
|
return behavior;
|
|
171
188
|
};
|
|
172
189
|
|
|
173
|
-
const
|
|
174
|
-
object:
|
|
175
|
-
|
|
190
|
+
const settleDeferred = <P extends GObject.Object, V>(
|
|
191
|
+
object: P,
|
|
192
|
+
state: DeferredState,
|
|
176
193
|
prop: string,
|
|
177
|
-
|
|
194
|
+
ops: DeferredOps<P, V>,
|
|
178
195
|
): void => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (!state.isPresent || Object.is(state.applied, state.desired)) {
|
|
196
|
+
if (!state.isPresent || Object.is(ops.read(object), state.desired)) {
|
|
182
197
|
return;
|
|
183
198
|
}
|
|
184
199
|
|
|
185
|
-
|
|
200
|
+
const desired = state.desired as V;
|
|
201
|
+
|
|
202
|
+
if (ops.canApply !== undefined && !ops.canApply(object, desired)) {
|
|
186
203
|
return;
|
|
187
204
|
}
|
|
188
205
|
|
|
189
|
-
applyWrite(() => {
|
|
190
|
-
|
|
206
|
+
applyWrite(prop, () => {
|
|
207
|
+
ops.write(object, desired);
|
|
191
208
|
});
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const scheduleSettle = <P extends GObject.Object, V>(
|
|
212
|
+
object: P,
|
|
213
|
+
state: DeferredState,
|
|
214
|
+
prop: string,
|
|
215
|
+
ops: DeferredOps<P, V>,
|
|
216
|
+
): void => {
|
|
217
|
+
if (state.isScheduled) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
state.isScheduled = true;
|
|
192
222
|
|
|
193
|
-
|
|
223
|
+
queueMicrotask(() => {
|
|
224
|
+
state.isScheduled = false;
|
|
225
|
+
|
|
226
|
+
if (state.disconnect !== null) {
|
|
227
|
+
settleDeferred(object, state, prop, ops);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
194
230
|
};
|
|
195
231
|
|
|
196
|
-
const
|
|
232
|
+
const watchDrift = <P extends GObject.Object, V>(
|
|
233
|
+
object: P,
|
|
234
|
+
state: DeferredState,
|
|
197
235
|
prop: string,
|
|
198
|
-
|
|
199
|
-
):
|
|
236
|
+
ops: DeferredOps<P, V>,
|
|
237
|
+
): void => {
|
|
238
|
+
if (state.disconnect !== null) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const signal = ops.signal ?? `notify::${getPropertyName(object, prop) ?? unsanitizeIdentifier(kebabCase(prop))}`;
|
|
243
|
+
|
|
244
|
+
const handler = (): undefined => {
|
|
245
|
+
scheduleSettle(object, state, prop, ops);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
object.on(signal, handler);
|
|
249
|
+
|
|
250
|
+
state.disconnect = (): void => {
|
|
251
|
+
object.off(signal, handler);
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const deferredBehavior = <P extends GObject.Object, V>(prop: string, ops: DeferredOps<P, V>): ElementBehavior<P> => ({
|
|
200
256
|
deferred: [prop],
|
|
201
|
-
initialize: (): DeferredState => ({ desired: undefined, isPresent: false,
|
|
257
|
+
initialize: (): DeferredState => ({ desired: undefined, isPresent: false, isScheduled: false, disconnect: null }),
|
|
202
258
|
update: (_object, _prev, next, context) => {
|
|
203
259
|
const state = context as DeferredState;
|
|
204
|
-
state.desired = next[prop];
|
|
205
|
-
state.isPresent =
|
|
260
|
+
state.desired = ops.parse === undefined ? next[prop] : ops.parse(next[prop]);
|
|
261
|
+
state.isPresent = state.desired !== undefined;
|
|
206
262
|
|
|
207
263
|
return [prop];
|
|
208
264
|
},
|
|
209
265
|
flush: (object, context) => {
|
|
210
|
-
|
|
266
|
+
const state = context as DeferredState;
|
|
267
|
+
settleDeferred(object, state, prop, ops);
|
|
268
|
+
watchDrift(object, state, prop, ops);
|
|
269
|
+
},
|
|
270
|
+
teardown: (_object, context) => {
|
|
271
|
+
const state = context as DeferredState;
|
|
272
|
+
state.disconnect?.();
|
|
273
|
+
state.disconnect = null;
|
|
211
274
|
},
|
|
212
275
|
});
|
|
213
276
|
|
|
277
|
+
const deferredWith = <P extends GObject.Object, V>(prop: string, hooks: DeferredHooks<P, V>): ElementBehavior<P> =>
|
|
278
|
+
deferredBehavior<P, V>(prop, {
|
|
279
|
+
...hooks,
|
|
280
|
+
read: hooks.read ?? ((object) => Reflect.get(object, prop)),
|
|
281
|
+
write: hooks.write ?? ((object, value) => {
|
|
282
|
+
Reflect.set(object, prop, value);
|
|
283
|
+
}),
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
const deferred = <P extends GObject.Object, V>(prop: string, canApply?: CanApply<P, V>): ElementBehavior<P> =>
|
|
287
|
+
deferredWith<P, V>(prop, { canApply });
|
|
288
|
+
|
|
214
289
|
const controlledText = (prop: string): ElementBehavior =>
|
|
215
290
|
value(prop, (object, next) => {
|
|
216
291
|
if (!hasSameText(object, prop, next)) {
|
|
217
|
-
applyWrite(() => {
|
|
292
|
+
applyWrite(prop, () => {
|
|
218
293
|
Reflect.set(object, prop, next);
|
|
219
294
|
});
|
|
220
295
|
}
|
|
@@ -253,12 +328,39 @@ const boxSlot = <P extends BoxLike>(): ElementBehavior<P> =>
|
|
|
253
328
|
},
|
|
254
329
|
});
|
|
255
330
|
|
|
256
|
-
const
|
|
331
|
+
const callMethod = <P extends GObject.Object, A>(parent: P, method: MethodKey<P, A>, argument: A): unknown =>
|
|
332
|
+
(parent[method] as (argument: A) => unknown)(argument);
|
|
333
|
+
|
|
334
|
+
const methodSlot = <P extends GObject.Object, C extends GObject.Object>(
|
|
335
|
+
slotName: string,
|
|
336
|
+
childType: string,
|
|
337
|
+
add: MethodKey<P, C>,
|
|
338
|
+
remove?: MethodKey<P, C>,
|
|
339
|
+
): ElementBehavior => {
|
|
340
|
+
const hooks: SlotHooks<P, C> = { attach: (parent, child) => callMethod(parent, add, child) };
|
|
341
|
+
|
|
342
|
+
if (remove !== undefined) {
|
|
343
|
+
hooks.detach = (parent, child) => {
|
|
344
|
+
callMethod(parent, remove, child);
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return slot<P, C>(slotName, childType, hooks);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
const setterSlot = <P extends GObject.Object, C extends GObject.Object>(
|
|
257
352
|
slotName: string,
|
|
258
353
|
childType: string,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
354
|
+
setter: MethodKey<P, C | null>,
|
|
355
|
+
): ElementBehavior =>
|
|
356
|
+
slot<P, C>(slotName, childType, {
|
|
357
|
+
attach: (parent, child) => {
|
|
358
|
+
callMethod<P, C | null>(parent, setter, child);
|
|
359
|
+
},
|
|
360
|
+
detach: (parent) => {
|
|
361
|
+
callMethod<P, C | null>(parent, setter, null);
|
|
362
|
+
},
|
|
363
|
+
});
|
|
262
364
|
|
|
263
365
|
const indexedSlot = <P extends IndexedChildHost<C>, C extends GObject.Object>(
|
|
264
366
|
slotName: string,
|
|
@@ -277,12 +379,6 @@ const indexedSlot = <P extends IndexedChildHost<C>, C extends GObject.Object>(
|
|
|
277
379
|
},
|
|
278
380
|
});
|
|
279
381
|
|
|
280
|
-
const adoptedChildrenSlot = <P extends GObject.Object, C extends GObject.Object>(
|
|
281
|
-
childType: string,
|
|
282
|
-
add: (parent: P, item: C) => unknown,
|
|
283
|
-
remove: (parent: P, item: C) => void,
|
|
284
|
-
): ElementBehavior => addRemoveSlot<C, P>("children", childType, add, remove);
|
|
285
|
-
|
|
286
382
|
const wrappedRow = <W extends Gtk.Widget>(
|
|
287
383
|
Wrapper: new (props: Props) => W,
|
|
288
384
|
setChild: (wrapper: W, inner: Gtk.Widget) => void,
|
|
@@ -346,12 +442,13 @@ export {
|
|
|
346
442
|
value,
|
|
347
443
|
list,
|
|
348
444
|
deferred,
|
|
445
|
+
deferredWith,
|
|
349
446
|
controlledText,
|
|
350
447
|
childSetterSlot,
|
|
351
448
|
contentSetterSlot,
|
|
352
449
|
boxSlot,
|
|
353
|
-
|
|
354
|
-
|
|
450
|
+
methodSlot,
|
|
451
|
+
setterSlot,
|
|
355
452
|
indexedSlot,
|
|
356
453
|
wrappingIndexedSlot,
|
|
357
454
|
};
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
assertPropsCanChange,
|
|
15
15
|
flushAccessible,
|
|
16
16
|
flushBehaviors,
|
|
17
|
+
teardownBehaviors,
|
|
17
18
|
} from "./apply-props.js";
|
|
18
19
|
import { attachChild, detachChild } from "./child-routing.js";
|
|
19
20
|
import { resolveElementNode } from "./instance.js";
|
|
@@ -161,7 +162,7 @@ const hostConfig = {
|
|
|
161
162
|
suspendInstance: (): void => undefined,
|
|
162
163
|
waitForCommitToBeReady: (): null => null,
|
|
163
164
|
NotPendingTransition: null,
|
|
164
|
-
HostTransitionContext: createContext(null)
|
|
165
|
+
HostTransitionContext: createContext(null),
|
|
165
166
|
};
|
|
166
167
|
|
|
167
168
|
const reconciler: ReactReconciler.Reconciler<Container, Instance, TextNode, unknown, unknown, object> =
|
|
@@ -190,6 +191,7 @@ function createPriorityTracker(): PriorityTracker {
|
|
|
190
191
|
|
|
191
192
|
const detachElement = (instance: ElementNode): void => {
|
|
192
193
|
disconnectAllHandlers(instance);
|
|
194
|
+
teardownBehaviors(instance);
|
|
193
195
|
|
|
194
196
|
if (instance.object instanceof Gtk.Widget) {
|
|
195
197
|
releaseStyle(instance.object);
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type * as GObject from "@gtkx/gi/gobject";
|
|
2
|
+
import {
|
|
3
|
+
type AnyClass,
|
|
4
|
+
getClassType,
|
|
5
|
+
getDeclaredPropertyName,
|
|
6
|
+
TYPE_INVALID,
|
|
7
|
+
typeFromName,
|
|
8
|
+
typeInterfaces,
|
|
9
|
+
typeName,
|
|
10
|
+
typeParent,
|
|
11
|
+
} from "@gtkx/runtime";
|
|
2
12
|
import { getOrInsert } from "@gtkx/utils";
|
|
3
|
-
import {
|
|
13
|
+
import { properties, type PropertyEntry, signals, userEventSignals } from "virtual:gtkx-config";
|
|
4
14
|
import { deferredProps, type ElementBehavior, ELEMENTS } from "./registry.js";
|
|
5
15
|
|
|
6
16
|
type TypeInfo = {
|
|
7
17
|
typeName: string;
|
|
18
|
+
properties: Record<string, PropertyEntry>;
|
|
8
19
|
signals: Record<string, string>;
|
|
9
20
|
userEventSignals: Set<string>;
|
|
10
21
|
behaviors: ElementBehavior[];
|
|
@@ -17,6 +28,12 @@ type TypeInfo = {
|
|
|
17
28
|
defaults: Record<string, unknown>;
|
|
18
29
|
};
|
|
19
30
|
|
|
31
|
+
const WRITABLE = 2;
|
|
32
|
+
const CONSTRUCT = 4;
|
|
33
|
+
const CONSTRUCT_ONLY = 8;
|
|
34
|
+
const NAME = 0;
|
|
35
|
+
const FLAGS = 1;
|
|
36
|
+
const DEFAULT_VALUE = 2;
|
|
20
37
|
const ancestryCache: Map<string, string[]> = new Map();
|
|
21
38
|
const typeInfoCache: Map<string, TypeInfo> = new Map();
|
|
22
39
|
|
|
@@ -60,11 +77,29 @@ const addAll = <T>(target: Set<T>, source: Iterable<T> | undefined): void => {
|
|
|
60
77
|
const accumulateAncestor = (info: TypeInfo, ancestor: string): void => {
|
|
61
78
|
Object.assign(info.signals, signals[ancestor] ?? {});
|
|
62
79
|
addAll(info.userEventSignals, userEventSignals[ancestor]);
|
|
63
|
-
addAll(info.constructOnly, constructOnlyProps[ancestor]);
|
|
64
|
-
addAll(info.construct, constructProps[ancestor]);
|
|
65
80
|
info.behaviors.push(...(ELEMENTS[ancestor]?.behaviors ?? []));
|
|
66
81
|
};
|
|
67
82
|
|
|
83
|
+
const resolveProperty = (info: TypeInfo, name: string, entry: PropertyEntry): void => {
|
|
84
|
+
if ((entry[FLAGS] & CONSTRUCT_ONLY) !== 0) {
|
|
85
|
+
info.constructOnly.add(name);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if ((entry[FLAGS] & (WRITABLE | CONSTRUCT | CONSTRUCT_ONLY)) !== 0) {
|
|
89
|
+
info.construct.add(name);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (entry.length > DEFAULT_VALUE) {
|
|
93
|
+
info.defaults[name] = entry[DEFAULT_VALUE];
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const resolveProperties = (info: TypeInfo): void => {
|
|
98
|
+
for (const [name, entry] of Object.entries(info.properties)) {
|
|
99
|
+
resolveProperty(info, name, entry);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
68
103
|
const applyBehaviorFlags = (info: TypeInfo, behavior: ElementBehavior): void => {
|
|
69
104
|
if (behavior.flush !== undefined) {
|
|
70
105
|
info.hasFlush = true;
|
|
@@ -85,6 +120,7 @@ const buildTypeInfo = (name: string): TypeInfo => {
|
|
|
85
120
|
|
|
86
121
|
const info: TypeInfo = {
|
|
87
122
|
typeName: name,
|
|
123
|
+
properties: {},
|
|
88
124
|
signals: {},
|
|
89
125
|
userEventSignals: new Set(),
|
|
90
126
|
behaviors: [],
|
|
@@ -105,12 +141,32 @@ const buildTypeInfo = (name: string): TypeInfo => {
|
|
|
105
141
|
info.isLazy = chain.some((ancestor) => ELEMENTS[ancestor]?.isLazy === true);
|
|
106
142
|
|
|
107
143
|
for (const ancestor of chain.toReversed()) {
|
|
108
|
-
Object.assign(info.
|
|
144
|
+
Object.assign(info.properties, properties[ancestor] ?? {});
|
|
109
145
|
}
|
|
110
146
|
|
|
147
|
+
resolveProperties(info);
|
|
148
|
+
|
|
111
149
|
return info;
|
|
112
150
|
};
|
|
113
151
|
|
|
114
152
|
const typeInfoFor = (name: string): TypeInfo => getOrInsert(typeInfoCache, name, buildTypeInfo);
|
|
115
153
|
|
|
116
|
-
|
|
154
|
+
const getTypeInfo = (object: GObject.Object): TypeInfo | undefined => {
|
|
155
|
+
const name = typeName(getClassType(object.constructor as AnyClass));
|
|
156
|
+
|
|
157
|
+
return name === null ? undefined : typeInfoFor(name);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const hasProperty = (info: TypeInfo, accessor: string): boolean => Object.hasOwn(info.properties, accessor);
|
|
161
|
+
|
|
162
|
+
const propertyNameFor = (info: TypeInfo, accessor: string): string | undefined =>
|
|
163
|
+
info.properties[accessor]?.[NAME];
|
|
164
|
+
|
|
165
|
+
const getPropertyName = (object: GObject.Object, accessor: string): string | undefined => {
|
|
166
|
+
const info = getTypeInfo(object);
|
|
167
|
+
|
|
168
|
+
return (info === undefined ? undefined : propertyNameFor(info, accessor)) ??
|
|
169
|
+
getDeclaredPropertyName(object, accessor);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export { getPropertyName, hasProperty, typeInfoFor, type TypeInfo };
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
type PlaceableNode,
|
|
16
16
|
type PlacedChild,
|
|
17
17
|
} from "./node.js";
|
|
18
|
-
import { applyWrite } from "./signals.js";
|
|
18
|
+
import { applyMutation, applyWrite } from "./signals.js";
|
|
19
19
|
import { markTextDirty } from "./text.js";
|
|
20
20
|
|
|
21
21
|
type AttachContext = { parent: ElementNode; entry: PlacedChild; index: number; sibling: GObject.Object | null };
|
|
@@ -78,7 +78,7 @@ const wireBufferView = (node: PlaceableNode, parent: ElementNode): void => {
|
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
const writeSlot = (parent: ElementNode, entry: PlacedChild, value: GObject.Object | null): void => {
|
|
81
|
-
applyWrite(() => {
|
|
81
|
+
applyWrite(entry.slot, () => {
|
|
82
82
|
Reflect.set(parent.object, entry.slot, value);
|
|
83
83
|
});
|
|
84
84
|
};
|
|
@@ -135,7 +135,7 @@ const runAttach = (parent: ElementNode, entry: PlacedChild, index: number, sibli
|
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
const attachEntry = (parent: ElementNode, entry: PlacedChild, index: number, sibling: GObject.Object | null): void => {
|
|
138
|
-
|
|
138
|
+
applyMutation(() => {
|
|
139
139
|
runAttach(parent, entry, index, sibling);
|
|
140
140
|
});
|
|
141
141
|
};
|
|
@@ -160,7 +160,7 @@ const runDetach = (parent: ElementNode, entry: PlacedChild): void => {
|
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
const detachEntry = (parent: ElementNode, entry: PlacedChild): void => {
|
|
163
|
-
|
|
163
|
+
applyMutation(() => {
|
|
164
164
|
runDetach(parent, entry);
|
|
165
165
|
});
|
|
166
166
|
};
|
|
@@ -54,6 +54,8 @@ type ElementBehavior<T extends GObject.Object = GObject.Object> = {
|
|
|
54
54
|
update?: (object: T, prev: Props, next: Props, context: unknown) => Iterable<string> | undefined;
|
|
55
55
|
/** Runs after the commit that touched the node, once every child has been placed. */
|
|
56
56
|
flush?: (object: T, context: unknown) => void;
|
|
57
|
+
/** Releases whatever `initialize` or a later hook acquired, once the node is destroyed. */
|
|
58
|
+
teardown?: (object: T, context: unknown) => void;
|
|
57
59
|
/** Props to withhold from the constructor, leaving them for a later hook to apply. */
|
|
58
60
|
deferred?: string[];
|
|
59
61
|
/**
|
package/src/reconciler/root.ts
CHANGED
|
@@ -171,7 +171,7 @@ const quit = (): typeof Gdk.EVENT_PROPAGATE | typeof Gdk.EVENT_STOP => {
|
|
|
171
171
|
* @param container The GObject to render into, or {@link rootElement} to render at the top level.
|
|
172
172
|
*/
|
|
173
173
|
const createPortal = (children: ReactNode, container: Container, key?: string): ReactPortal =>
|
|
174
|
-
reconciler.createPortal(children, container, null, key ?? null)
|
|
174
|
+
reconciler.createPortal(children, container, null, key ?? null);
|
|
175
175
|
|
|
176
176
|
export {
|
|
177
177
|
setReconcilerErrorHandler,
|