@gtkx/testing 2.0.0-beta.10 → 2.0.0-beta.12
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 +8 -168
- package/dist/accessible-native.d.ts +1 -1
- package/dist/accessible-native.d.ts.map +1 -1
- package/dist/accessible-native.js +2 -2
- package/dist/accessible-native.js.map +1 -1
- package/dist/act.d.ts.map +1 -1
- package/dist/build-queries.d.ts +7 -8
- package/dist/build-queries.d.ts.map +1 -1
- package/dist/build-queries.js +25 -24
- package/dist/build-queries.js.map +1 -1
- package/dist/cleanup-registry.d.ts +2 -1
- package/dist/cleanup-registry.d.ts.map +1 -1
- package/dist/cleanup-registry.js +11 -4
- package/dist/cleanup-registry.js.map +1 -1
- package/dist/config.d.ts +3 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/editable.d.ts.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +5 -2
- package/dist/fire-event.js.map +1 -1
- package/dist/frame-sync.d.ts.map +1 -1
- package/dist/frame-sync.js +1 -10
- package/dist/frame-sync.js.map +1 -1
- package/dist/harness-window.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/matchers.d.ts +4 -6
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +2 -2
- package/dist/matchers.js.map +1 -1
- package/dist/normalize.d.ts +1 -1
- package/dist/normalize.d.ts.map +1 -1
- package/dist/normalize.js +1 -1
- package/dist/normalize.js.map +1 -1
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +13 -2
- package/dist/pretty-widget.js.map +1 -1
- package/dist/production.d.ts.map +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +6 -7
- package/dist/queries.js.map +1 -1
- package/dist/render-hook.js +3 -3
- package/dist/render-hook.js.map +1 -1
- package/dist/render.d.ts +17 -17
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +62 -62
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-naming.d.ts +2 -1
- package/dist/role-naming.d.ts.map +1 -1
- package/dist/role-naming.js +2 -1
- package/dist/role-naming.js.map +1 -1
- package/dist/screen.d.ts.map +1 -1
- package/dist/screenshot.d.ts +10 -11
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +10 -11
- package/dist/screenshot.js.map +1 -1
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.d.ts.map +1 -1
- package/dist/suggestions.js +3 -3
- package/dist/suggestions.js.map +1 -1
- package/dist/timers.d.ts.map +1 -1
- package/dist/traversal.d.ts +4 -3
- package/dist/traversal.d.ts.map +1 -1
- package/dist/traversal.js +11 -4
- package/dist/traversal.js.map +1 -1
- package/dist/types.d.ts +3 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-event/adjustment.d.ts.map +1 -1
- package/dist/user-event/adjustment.js.map +1 -1
- package/dist/user-event/click.d.ts.map +1 -1
- package/dist/user-event/click.js +0 -1
- package/dist/user-event/click.js.map +1 -1
- package/dist/user-event/column-header-click.d.ts.map +1 -1
- package/dist/user-event/column-header-click.js +1 -1
- package/dist/user-event/column-header-click.js.map +1 -1
- package/dist/user-event/controller.d.ts +1 -1
- package/dist/user-event/controller.d.ts.map +1 -1
- package/dist/user-event/controller.js +3 -3
- package/dist/user-event/controller.js.map +1 -1
- package/dist/user-event/dispatch.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.js.map +1 -1
- package/dist/user-event/gesture.d.ts +1 -1
- package/dist/user-event/gesture.d.ts.map +1 -1
- package/dist/user-event/gesture.js +104 -29
- package/dist/user-event/gesture.js.map +1 -1
- package/dist/user-event/index.d.ts.map +1 -1
- package/dist/user-event/index.js +1 -1
- package/dist/user-event/index.js.map +1 -1
- package/dist/user-event/indexed-children.d.ts.map +1 -1
- package/dist/user-event/keyboard.d.ts.map +1 -1
- package/dist/user-event/keyboard.js +43 -16
- package/dist/user-event/keyboard.js.map +1 -1
- package/dist/user-event/list-row-click.d.ts.map +1 -1
- package/dist/user-event/list-row-click.js +1 -1
- package/dist/user-event/list-row-click.js.map +1 -1
- package/dist/user-event/native-click.d.ts.map +1 -1
- package/dist/user-event/native-click.js +1 -3
- package/dist/user-event/native-click.js.map +1 -1
- package/dist/user-event/notebook-tab-click.d.ts.map +1 -1
- package/dist/user-event/notebook-tab-click.js +1 -1
- package/dist/user-event/notebook-tab-click.js.map +1 -1
- package/dist/user-event/pointer.d.ts.map +1 -1
- package/dist/user-event/selection.d.ts.map +1 -1
- package/dist/user-event/selection.js +1 -6
- package/dist/user-event/selection.js.map +1 -1
- package/dist/user-event/text.d.ts.map +1 -1
- package/dist/user-event/text.js +31 -27
- package/dist/user-event/text.js.map +1 -1
- package/dist/wait-for.d.ts.map +1 -1
- package/dist/wait-for.js +28 -21
- package/dist/wait-for.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +1 -1
- package/dist/widget-accessible-properties.d.ts.map +1 -1
- package/dist/widget-accessible-properties.js +64 -28
- package/dist/widget-accessible-properties.js.map +1 -1
- package/dist/widget-getters.d.ts.map +1 -1
- package/dist/widget-getters.js +0 -1
- package/dist/widget-getters.js.map +1 -1
- package/dist/widget-target.d.ts.map +1 -1
- package/dist/window-state.d.ts.map +1 -1
- package/dist/window-state.js +3 -1
- package/dist/window-state.js.map +1 -1
- package/dist/within.d.ts.map +1 -1
- package/dist/within.js.map +1 -1
- package/package.json +16 -23
- package/src/accessible-native.ts +5 -5
- package/src/build-queries.ts +71 -88
- package/src/cleanup-registry.ts +11 -5
- package/src/config.ts +3 -4
- package/src/errors.ts +6 -6
- package/src/fire-event.ts +6 -7
- package/src/frame-sync.ts +1 -13
- package/src/index.ts +2 -12
- package/src/matchers.ts +34 -42
- package/src/normalize.ts +1 -4
- package/src/pretty-widget.ts +17 -2
- package/src/queries.ts +11 -20
- package/src/render-hook.tsx +4 -4
- package/src/render.tsx +67 -80
- package/src/role-naming.ts +2 -1
- package/src/screenshot.ts +13 -19
- package/src/suggestions.ts +3 -3
- package/src/traversal.ts +16 -6
- package/src/types.ts +14 -20
- package/src/user-event/adjustment.ts +1 -3
- package/src/user-event/click.ts +2 -9
- package/src/user-event/column-header-click.ts +1 -1
- package/src/user-event/controller.ts +3 -3
- package/src/user-event/event-wrapper.ts +1 -1
- package/src/user-event/gesture.ts +146 -37
- package/src/user-event/index.ts +10 -22
- package/src/user-event/keyboard.ts +61 -19
- package/src/user-event/list-row-click.ts +1 -1
- package/src/user-event/native-click.ts +1 -3
- package/src/user-event/notebook-tab-click.ts +1 -1
- package/src/user-event/selection.ts +4 -20
- package/src/user-event/text.ts +37 -36
- package/src/wait-for.ts +38 -34
- package/src/widget-accessible-properties.ts +80 -36
- package/src/widget-getters.ts +1 -3
- package/src/window-state.ts +4 -3
- package/src/within.ts +2 -2
package/src/queries.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import type {
|
|
3
|
-
ByRoleOptions,
|
|
4
|
-
ByRoleValue,
|
|
5
|
-
Matcher,
|
|
6
|
-
MatcherOptions,
|
|
7
|
-
NormalizerFn,
|
|
8
|
-
QueryFamilies,
|
|
9
|
-
} from "./types.js";
|
|
2
|
+
import type { ByRoleOptions, ByRoleValue, Matcher, MatcherOptions, NormalizerFn, QueryFamilies } from "./types.js";
|
|
10
3
|
import { buildQueries, type BuiltQueries, type QueryAllBy } from "./build-queries.js";
|
|
11
4
|
import { multipleFoundError, notFoundError } from "./errors.js";
|
|
12
5
|
import { getDefaultNormalizer } from "./normalize.js";
|
|
@@ -177,8 +170,8 @@ const buildNormalizer = (options?: MatcherOptions): NormalizerFn => {
|
|
|
177
170
|
if (trim !== undefined || collapseWhitespace !== undefined) {
|
|
178
171
|
throw new Error(
|
|
179
172
|
"trim and collapseWhitespace are not supported with a normalizer. " +
|
|
180
|
-
|
|
181
|
-
|
|
173
|
+
"If you want to use the default trim and collapseWhitespace logic in your normalizer, " +
|
|
174
|
+
'use "getDefaultNormalizer({ trim, collapseWhitespace })" and compose that into your normalizer',
|
|
182
175
|
);
|
|
183
176
|
}
|
|
184
177
|
|
|
@@ -287,18 +280,14 @@ const hasMatchingAccessibleStates = (widget: Gtk.Widget, options: ByRoleOptions)
|
|
|
287
280
|
const isMatchingWidgetType = <T extends Gtk.Accessible>(
|
|
288
281
|
widget: Gtk.Widget,
|
|
289
282
|
options?: MatcherOptions<T>,
|
|
290
|
-
): widget is Gtk.Widget & T =>
|
|
291
|
-
options?.as === undefined || widget instanceof options.as;
|
|
283
|
+
): widget is Gtk.Widget & T => options?.as === undefined || widget instanceof options.as;
|
|
292
284
|
|
|
293
285
|
const hasMatchingAccessibleOptions = (widget: Gtk.Widget, options?: ByRoleOptions): boolean => {
|
|
294
286
|
if (!options) {
|
|
295
287
|
return true;
|
|
296
288
|
}
|
|
297
289
|
|
|
298
|
-
return (
|
|
299
|
-
hasMatchingAccessibleName(widget, options) &&
|
|
300
|
-
hasMatchingAccessibleStates(widget, options)
|
|
301
|
-
);
|
|
290
|
+
return hasMatchingAccessibleName(widget, options) && hasMatchingAccessibleStates(widget, options);
|
|
302
291
|
};
|
|
303
292
|
|
|
304
293
|
function nameQueryFamily<Args extends unknown[], Element extends Gtk.Accessible>(
|
|
@@ -410,12 +399,15 @@ function queryAllByLabelText<T extends Gtk.Accessible = Gtk.Widget>(
|
|
|
410
399
|
options?: MatcherOptions<T>,
|
|
411
400
|
): T[] {
|
|
412
401
|
const results: Set<Gtk.Widget> = new Set();
|
|
402
|
+
const widgets = new Set(traverse(container));
|
|
413
403
|
|
|
414
|
-
for (const widget of
|
|
404
|
+
for (const widget of widgets) {
|
|
415
405
|
collectLabelMatches(results, widget, text, options);
|
|
416
406
|
}
|
|
417
407
|
|
|
418
|
-
return [...results].filter(
|
|
408
|
+
return [...results].filter(
|
|
409
|
+
(widget): widget is Gtk.Widget & T => widgets.has(widget) && isMatchingWidgetType(widget, options),
|
|
410
|
+
);
|
|
419
411
|
}
|
|
420
412
|
|
|
421
413
|
/**
|
|
@@ -496,8 +488,7 @@ function queryAllByDisplayValue<T extends Gtk.Accessible = Gtk.Widget>(
|
|
|
496
488
|
const matches = findAll(
|
|
497
489
|
container,
|
|
498
490
|
(widget) =>
|
|
499
|
-
isMatchingWidgetType(widget, options) &&
|
|
500
|
-
isTextMatch(getWidgetDisplayValue(widget), value, widget, options),
|
|
491
|
+
isMatchingWidgetType(widget, options) && isTextMatch(getWidgetDisplayValue(widget), value, widget, options),
|
|
501
492
|
);
|
|
502
493
|
|
|
503
494
|
return matches.filter((widget): widget is Gtk.Widget & T => isMatchingWidgetType(widget, options));
|
package/src/render-hook.tsx
CHANGED
|
@@ -32,7 +32,7 @@ async function renderHook<Result, Props>(
|
|
|
32
32
|
callback: (props: Props) => Result,
|
|
33
33
|
options?: RenderHookOptions<Props>,
|
|
34
34
|
): Promise<RenderHookResult<Result, Props>> {
|
|
35
|
-
const initialProps =
|
|
35
|
+
const initialProps = options?.initialProps as Props;
|
|
36
36
|
const resultRef: { current: Result | undefined } = { current: undefined };
|
|
37
37
|
let currentProps: Props = initialProps;
|
|
38
38
|
|
|
@@ -50,9 +50,9 @@ async function renderHook<Result, Props>(
|
|
|
50
50
|
|
|
51
51
|
return {
|
|
52
52
|
result: resultRef as { current: Result },
|
|
53
|
-
rerender: async (
|
|
54
|
-
if (
|
|
55
|
-
currentProps =
|
|
53
|
+
rerender: async (...args: [] | [Props]) => {
|
|
54
|
+
if (args.length === 1) {
|
|
55
|
+
[currentProps] = args;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
await renderResult.rerender(<TestComponent props={currentProps} />);
|
package/src/render.tsx
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import type { CaughtErrorInfo, RootElement } from "@gtkx/react";
|
|
1
|
+
import type { CaughtErrorInfo, Root, RootElement } from "@gtkx/react";
|
|
2
2
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
isRootElement,
|
|
6
|
-
type ReconcilerRoot,
|
|
7
|
-
setReconcilerErrorHandler,
|
|
8
|
-
settleAccessible,
|
|
9
|
-
} from "@gtkx/react/internal";
|
|
3
|
+
import { createRoot } from "@gtkx/react";
|
|
4
|
+
import { isRootElement, settleAccessible } from "@gtkx/react/internal";
|
|
10
5
|
import { type ErrorInfo, type ReactNode, StrictMode } from "react";
|
|
11
6
|
import type { RenderResult } from "./bound-queries.js";
|
|
12
7
|
import type { QueryMap, RenderOptions, ScreenshotOptions } from "./types.js";
|
|
13
8
|
import { runInAct, runWithActEnvironment } from "./act.js";
|
|
14
|
-
import { addToCleanupQueue, runCleanup } from "./cleanup-registry.js";
|
|
9
|
+
import { addToCleanupQueue, runCleanup, runCleanupCallbacks } from "./cleanup-registry.js";
|
|
15
10
|
import { getConfig } from "./config.js";
|
|
16
11
|
import { scheduleWhenWindowReady } from "./frame-sync.js";
|
|
17
12
|
import { createHarnessWindow, presentHarnessWindow } from "./harness-window.js";
|
|
@@ -25,12 +20,10 @@ import { requireWidget } from "./widget-target.js";
|
|
|
25
20
|
import { findPresentedWindowFailure, findRenderedWindowFailure, mappedToplevels } from "./window-state.js";
|
|
26
21
|
import { within } from "./within.js";
|
|
27
22
|
|
|
28
|
-
/** A mounted render tracked so cleanup can unmount it. */
|
|
29
23
|
type ActiveRender = {
|
|
30
|
-
|
|
31
|
-
root: ReconcilerRoot;
|
|
32
|
-
/** Harness window created for the render, null when it renders into a container the caller supplied. */
|
|
24
|
+
root: Root;
|
|
33
25
|
window: Gtk.Window | null;
|
|
26
|
+
errors: RenderErrorState;
|
|
34
27
|
};
|
|
35
28
|
|
|
36
29
|
type ResolvedContainer = {
|
|
@@ -38,15 +31,13 @@ type ResolvedContainer = {
|
|
|
38
31
|
window: Gtk.Window | null;
|
|
39
32
|
};
|
|
40
33
|
|
|
41
|
-
type
|
|
34
|
+
type RenderErrorState = {
|
|
42
35
|
lastError: Error | null;
|
|
43
|
-
isHandlerInstalled: boolean;
|
|
44
36
|
};
|
|
45
37
|
|
|
46
38
|
type WindowFailureReporter = (window: Gtk.Window) => string | null;
|
|
47
39
|
type SettleAction = "render" | "rerender";
|
|
48
40
|
|
|
49
|
-
const reconcilerErrors: ReconcilerErrorState = { lastError: null, isHandlerInstalled: false };
|
|
50
41
|
const activeRenders: Set<ActiveRender> = new Set();
|
|
51
42
|
|
|
52
43
|
const settleWindow = async (
|
|
@@ -70,20 +61,23 @@ const settleWindow = async (
|
|
|
70
61
|
if (failure !== null) {
|
|
71
62
|
throw new Error(
|
|
72
63
|
`${action} timed out after ${String(timeout)}ms waiting for the window it rendered into: ${failure}. ` +
|
|
73
|
-
|
|
64
|
+
"Platform state such as focus is only readable once that window is allocated and active.",
|
|
74
65
|
);
|
|
75
66
|
}
|
|
76
67
|
};
|
|
77
68
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
69
|
+
const flushRender = async (active: ActiveRender, action: () => void): Promise<void> => {
|
|
70
|
+
try {
|
|
71
|
+
await runInAct(async () => {
|
|
72
|
+
action();
|
|
73
|
+
await Promise.resolve();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (active.errors.lastError !== null) {
|
|
77
|
+
throw active.errors.lastError;
|
|
78
|
+
}
|
|
79
|
+
} finally {
|
|
80
|
+
active.errors.lastError = null;
|
|
87
81
|
}
|
|
88
82
|
};
|
|
89
83
|
|
|
@@ -92,29 +86,15 @@ const disposeActiveRender = async (active: ActiveRender): Promise<void> => {
|
|
|
92
86
|
return;
|
|
93
87
|
}
|
|
94
88
|
|
|
95
|
-
|
|
96
|
-
await
|
|
89
|
+
try {
|
|
90
|
+
await flushRender(active, active.root.unmount);
|
|
91
|
+
} finally {
|
|
97
92
|
active.window?.destroy();
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const disposeAllActiveRenders = async (): Promise<void> => {
|
|
102
|
-
for (const active of activeRenders) {
|
|
103
|
-
await disposeActiveRender(active);
|
|
104
93
|
}
|
|
105
94
|
};
|
|
106
95
|
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const installErrorHandler = (): void => {
|
|
112
|
-
if (reconcilerErrors.isHandlerInstalled) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
setReconcilerErrorHandler(handleError);
|
|
117
|
-
reconcilerErrors.isHandlerInstalled = true;
|
|
96
|
+
const disposeAllActiveRenders = async (): Promise<void> => {
|
|
97
|
+
await runCleanupCallbacks(activeRenders.values().map((active) => () => disposeActiveRender(active)));
|
|
118
98
|
};
|
|
119
99
|
|
|
120
100
|
const resolveContainer = (container: RenderOptions["container"]): ResolvedContainer => {
|
|
@@ -191,16 +171,22 @@ const settleRender = async (
|
|
|
191
171
|
await settleWindow(settleTarget(resolved, container), findFailure, action);
|
|
192
172
|
};
|
|
193
173
|
|
|
194
|
-
const renderErrorHandlers = <Q extends QueryMap>(options: RenderOptions<Q> | undefined) =>
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
174
|
+
const renderErrorHandlers = <Q extends QueryMap>(errors: RenderErrorState, options: RenderOptions<Q> | undefined) => {
|
|
175
|
+
const handleError = (error: unknown): void => {
|
|
176
|
+
errors.lastError = error instanceof Error ? error : new Error(String(error));
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
onUncaughtError: handleError,
|
|
181
|
+
onCaughtError: (error: unknown, errorInfo: CaughtErrorInfo): void => {
|
|
182
|
+
handleError(error);
|
|
183
|
+
options?.onCaughtError?.(error, errorInfo);
|
|
184
|
+
},
|
|
185
|
+
onRecoverableError: (error: unknown, errorInfo: ErrorInfo): void => {
|
|
186
|
+
options?.onRecoverableError?.(error, errorInfo);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
};
|
|
204
190
|
|
|
205
191
|
const applyEnableAnimations = (areAnimationsEnabled: boolean): void => {
|
|
206
192
|
const settings = Gtk.Settings.getDefault();
|
|
@@ -211,41 +197,38 @@ const applyEnableAnimations = (areAnimationsEnabled: boolean): void => {
|
|
|
211
197
|
};
|
|
212
198
|
|
|
213
199
|
/**
|
|
214
|
-
* Renders
|
|
215
|
-
* scoped to it along with controls for rerendering and unmounting. When no
|
|
216
|
-
* container is supplied, a harness window is created and presented, and the editable it hands the
|
|
217
|
-
* focus to keeps its text unselected, with its caret at the end. The returned promise settles once
|
|
218
|
-
* the window the tree is shown in has been laid out and activation has arrived, so platform state
|
|
219
|
-
* such as focus is already readable when it resolves. A presented harness window is waited on until
|
|
220
|
-
* it is itself active; a window the caller or the tree owns is waited on until the application holds
|
|
221
|
-
* activation, since only a present can claim it. Rendering into a container that is not shown waits
|
|
222
|
-
* for nothing, and a window that never becomes readable within `windowActivationTimeout` throws an
|
|
223
|
-
* error naming the condition that failed rather than resolving with unreadable platform state. A
|
|
224
|
-
* tree mounted into a container that sits outside every toplevel, or inside a window that is not
|
|
225
|
-
* visible, is out of reach of a pointer and a keyboard, so every `userEvent` helper aimed at it
|
|
226
|
-
* rejects after `actionabilityTimeout` naming that condition, and `fireEvent` drives it instead.
|
|
200
|
+
* Renders React into native widgets and returns queries, debug helpers, and lifecycle controls.
|
|
227
201
|
*
|
|
228
|
-
* @
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
202
|
+
* @remarks
|
|
203
|
+
* Without a container, creates and presents a harness window. Its initially focused editable
|
|
204
|
+
* keeps its text unselected, with the caret at the end.
|
|
205
|
+
*
|
|
206
|
+
* Waits for layout and activation before resolving, so focus and other platform state can be
|
|
207
|
+
* read immediately. A new harness waits for its own activation; a caller-owned or rendered
|
|
208
|
+
* window waits for application activation, since only presentation can claim it. A container
|
|
209
|
+
* that is not shown requires no activation wait.
|
|
210
|
+
*
|
|
211
|
+
* Widgets outside all toplevels or inside a hidden window cannot receive pointer or keyboard
|
|
212
|
+
* input. `userEvent` rejects after `actionabilityTimeout`; use `fireEvent` to drive them directly.
|
|
213
|
+
*
|
|
214
|
+
* @param element React element to render.
|
|
215
|
+
* @param options Container, wrapper, custom queries, and render settings.
|
|
216
|
+
* @returns Bound queries, debug helpers, and rerender/unmount controls.
|
|
217
|
+
* @throws If a shown window is not laid out and activated within `windowActivationTimeout`.
|
|
232
218
|
*/
|
|
233
219
|
const render = async <Q extends QueryMap = Record<never, never>>(
|
|
234
220
|
element: ReactNode,
|
|
235
221
|
options?: RenderOptions<Q>,
|
|
236
222
|
): Promise<RenderResult<Q>> => {
|
|
237
|
-
installErrorHandler();
|
|
238
223
|
applyEnableAnimations(options?.areAnimationsEnabled === true);
|
|
239
224
|
const baseElement: Container = options?.baseElement ?? TOPLEVELS;
|
|
240
225
|
const Wrapper = options?.wrapper;
|
|
241
226
|
const resolved = resolveContainer(options?.container);
|
|
242
227
|
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
...renderErrorHandlers(options),
|
|
246
|
-
});
|
|
228
|
+
const errors: RenderErrorState = { lastError: null };
|
|
229
|
+
const root = createRoot(resolved.containerInfo, renderErrorHandlers(errors, options));
|
|
247
230
|
|
|
248
|
-
const active: ActiveRender = { root, window: resolved.window };
|
|
231
|
+
const active: ActiveRender = { root, window: resolved.window, errors };
|
|
249
232
|
activeRenders.add(active);
|
|
250
233
|
addToCleanupQueue(disposeAllActiveRenders);
|
|
251
234
|
addToCleanupQueue(clearScreen);
|
|
@@ -257,7 +240,9 @@ const render = async <Q extends QueryMap = Record<never, never>>(
|
|
|
257
240
|
return options?.isReactStrictMode ? <StrictMode>{wrapped}</StrictMode> : wrapped;
|
|
258
241
|
};
|
|
259
242
|
|
|
260
|
-
await
|
|
243
|
+
await flushRender(active, () => {
|
|
244
|
+
root.render(wrap(element));
|
|
245
|
+
});
|
|
261
246
|
presentHarnessWindow(resolved.window);
|
|
262
247
|
await settleRender(resolved, options?.container, "render");
|
|
263
248
|
const container = resolveResultContainer(resolved, options?.container, baseElement);
|
|
@@ -270,7 +255,9 @@ const render = async <Q extends QueryMap = Record<never, never>>(
|
|
|
270
255
|
await disposeActiveRender(active);
|
|
271
256
|
},
|
|
272
257
|
rerender: async (newElement: ReactNode) => {
|
|
273
|
-
await
|
|
258
|
+
await flushRender(active, () => {
|
|
259
|
+
root.render(wrap(newElement));
|
|
260
|
+
});
|
|
274
261
|
await settleRender(resolved, options?.container, "rerender");
|
|
275
262
|
},
|
|
276
263
|
debug: (element: Container | Container[] = baseElement, debugOptions?: PrettyWidgetOptions) => {
|
package/src/role-naming.ts
CHANGED
|
@@ -95,5 +95,6 @@ const NAMING: Partial<Record<Gtk.AccessibleRole, number>> = {
|
|
|
95
95
|
const namingFor = (role: Gtk.AccessibleRole): number => NAMING[role] ?? 0;
|
|
96
96
|
const isNameProhibited = (role: Gtk.AccessibleRole): boolean => (namingFor(role) & PROHIBITED) !== 0;
|
|
97
97
|
const isNameFromAuthor = (role: Gtk.AccessibleRole): boolean => (namingFor(role) & FROM_AUTHOR) !== 0;
|
|
98
|
+
const isNameFromContent = (role: Gtk.AccessibleRole): boolean => (namingFor(role) & FROM_CONTENT) !== 0;
|
|
98
99
|
|
|
99
|
-
export { isNameFromAuthor, isNameProhibited };
|
|
100
|
+
export { isNameFromAuthor, isNameFromContent, isNameProhibited };
|
package/src/screenshot.ts
CHANGED
|
@@ -24,13 +24,9 @@ type CaptureState = {
|
|
|
24
24
|
failure: CaptureFailure | null;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
type CaptureResult =
|
|
28
|
-
{ status: "captured"; result: ScreenshotResult } |
|
|
29
|
-
{ status: "failed"; failure: CaptureFailure };
|
|
27
|
+
type CaptureResult = { status: "captured"; result: ScreenshotResult } | { status: "failed"; failure: CaptureFailure };
|
|
30
28
|
|
|
31
|
-
type CaptureOutcome =
|
|
32
|
-
{ status: "captured"; result: ScreenshotResult } |
|
|
33
|
-
{ status: "stalled"; failure: CaptureFailure };
|
|
29
|
+
type CaptureOutcome = { status: "captured"; result: ScreenshotResult } | { status: "stalled"; failure: CaptureFailure };
|
|
34
30
|
|
|
35
31
|
type BackgroundSnapshot = {
|
|
36
32
|
renderBackground(...args: [context: object, x: number, y: number, width: number, height: number]): void;
|
|
@@ -57,8 +53,7 @@ const NOT_PRESENTING_MESSAGE =
|
|
|
57
53
|
const EMPTY_WIDGET_HINT =
|
|
58
54
|
"The display is presenting frames to this window, so the widget itself is empty: it painted nothing.";
|
|
59
55
|
|
|
60
|
-
const OTHER_FAILURE_HINT =
|
|
61
|
-
"The display is presenting frames to this window, so the capture failed for another reason.";
|
|
56
|
+
const OTHER_FAILURE_HINT = "The display is presenting frames to this window, so the capture failed for another reason.";
|
|
62
57
|
|
|
63
58
|
const NOTHING_ON_SCREEN_MESSAGE = "Nothing is on screen to capture: no toplevel window is mapped";
|
|
64
59
|
|
|
@@ -330,18 +325,17 @@ const captureUntilPaintable = (
|
|
|
330
325
|
};
|
|
331
326
|
|
|
332
327
|
/**
|
|
333
|
-
* Captures a
|
|
334
|
-
*
|
|
335
|
-
* missing parent directories. Popovers open inside the widget render on their
|
|
336
|
-
* own surfaces, so they are composited into the image at their on-screen
|
|
337
|
-
* positions. A display that never presents a frame leaves GTK without a cached
|
|
338
|
-
* render node, so the widget's contents are then snapshotted directly; when
|
|
339
|
-
* even that yields nothing, the failure names the display instead of blaming
|
|
340
|
-
* the widget.
|
|
328
|
+
* Captures a widget as PNG, retrying until it has a paintable size. Writes to `options.path`
|
|
329
|
+
* when supplied, creating missing parent directories.
|
|
341
330
|
*
|
|
342
|
-
* @
|
|
343
|
-
*
|
|
344
|
-
*
|
|
331
|
+
* @remarks
|
|
332
|
+
* Open popovers are composited at their on-screen positions. If the display has not presented
|
|
333
|
+
* a frame, captures widget contents directly instead of using GTK's cached render node.
|
|
334
|
+
* If that also fails, the error identifies the display's presentation failure.
|
|
335
|
+
*
|
|
336
|
+
* @param target Widget to capture.
|
|
337
|
+
* @param options Scale, timeout, retry interval, and output path.
|
|
338
|
+
* @returns Base64-encoded PNG data, MIME type, and dimensions.
|
|
345
339
|
*/
|
|
346
340
|
const screenshot = async (target: Gtk.Accessible, options?: ScreenshotOptions): Promise<ScreenshotResult> => {
|
|
347
341
|
const widget = requireWidget(target);
|
package/src/suggestions.ts
CHANGED
|
@@ -56,7 +56,7 @@ const roleSuggestion = (widget: Gtk.Widget, variant: Variant): Suggestion | unde
|
|
|
56
56
|
return makeSuggestion("Role", variant, roleText);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
return makeSuggestion("Role", variant, `${roleText}, { name:
|
|
59
|
+
return makeSuggestion("Role", variant, `${roleText}, { name: ${JSON.stringify(name)} }`);
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
const textSuggestion = (queryName: Method, variant: Variant, value: string | null): Suggestion | undefined => {
|
|
@@ -64,13 +64,13 @@ const textSuggestion = (queryName: Method, variant: Variant, value: string | nul
|
|
|
64
64
|
return undefined;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
return makeSuggestion(queryName, variant,
|
|
67
|
+
return makeSuggestion(queryName, variant, JSON.stringify(value));
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Computes the recommended query for reaching the given widget, preferring role, then label text,
|
|
72
72
|
* placeholder text, text, display value, and name.
|
|
73
|
-
* @param
|
|
73
|
+
* @param target Widget to build a suggestion for.
|
|
74
74
|
* @param variant Query variant the suggestion should use.
|
|
75
75
|
* @param method Restrict the suggestion to a specific query family instead of choosing by priority.
|
|
76
76
|
* @returns The best available suggestion, or undefined when no query applies.
|
package/src/traversal.ts
CHANGED
|
@@ -13,6 +13,7 @@ type QueryContainer = Gtk.Accessible | Gtk.EventController | Gtk.LayoutManager |
|
|
|
13
13
|
*/
|
|
14
14
|
type Container = QueryContainer | Gtk.Application | typeof TOPLEVELS;
|
|
15
15
|
type WidgetClass<T extends object> = abstract new (...args: never[]) => T;
|
|
16
|
+
type ChildContainer = Pick<Gtk.Widget, "getFirstChild">;
|
|
16
17
|
|
|
17
18
|
/** Container sentinel that widens a query to every toplevel window currently open. */
|
|
18
19
|
const TOPLEVELS: unique symbol = Symbol("gtkx.toplevels");
|
|
@@ -52,7 +53,7 @@ const traverseWidgetTree = function* (
|
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
|
|
55
|
-
const children = function* (widget:
|
|
56
|
+
const children = function* (widget: ChildContainer): Generator<Gtk.Widget> {
|
|
56
57
|
let child = widget.getFirstChild();
|
|
57
58
|
|
|
58
59
|
while (child) {
|
|
@@ -98,11 +99,13 @@ const mappedWidgets = function* (widget: Gtk.Widget, isParentMapped: boolean): G
|
|
|
98
99
|
}
|
|
99
100
|
};
|
|
100
101
|
|
|
101
|
-
const relationCandidates = (widget: Gtk.Widget): Iterable<Gtk.Accessible
|
|
102
|
+
const relationCandidates = function* (widget: Gtk.Widget): Generator<Iterable<Gtk.Accessible>> {
|
|
103
|
+
yield widget.listMnemonicLabels();
|
|
104
|
+
yield descendants(widget);
|
|
102
105
|
const root = widget.getRoot();
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
if (root instanceof Gtk.Widget) {
|
|
107
|
+
yield traverseWidgetTree(root, isAnyWidget);
|
|
108
|
+
}
|
|
106
109
|
};
|
|
107
110
|
|
|
108
111
|
const resolveRoot = (container: QueryContainer): Gtk.Widget | null => {
|
|
@@ -126,12 +129,18 @@ const resolveRoot = (container: QueryContainer): Gtk.Widget | null => {
|
|
|
126
129
|
};
|
|
127
130
|
|
|
128
131
|
const roots = function* (container: Container): Generator<Gtk.Widget> {
|
|
129
|
-
if (container === TOPLEVELS
|
|
132
|
+
if (container === TOPLEVELS) {
|
|
130
133
|
yield* Gtk.Window.listToplevels();
|
|
131
134
|
|
|
132
135
|
return;
|
|
133
136
|
}
|
|
134
137
|
|
|
138
|
+
if (isApplication(container)) {
|
|
139
|
+
yield* container.getWindows();
|
|
140
|
+
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
135
144
|
const root = resolveRoot(container);
|
|
136
145
|
|
|
137
146
|
if (root) {
|
|
@@ -168,5 +177,6 @@ export {
|
|
|
168
177
|
relationCandidates,
|
|
169
178
|
roots,
|
|
170
179
|
traverse,
|
|
180
|
+
type ChildContainer,
|
|
171
181
|
type Container,
|
|
172
182
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
2
|
import type { CaughtErrorInfo, RootElement } from "@gtkx/react";
|
|
3
|
-
import type { ComponentType, ErrorInfo,
|
|
3
|
+
import type { ComponentType, ErrorInfo, PropsWithChildren } from "react";
|
|
4
4
|
import type { PrettyWidgetOptions } from "./pretty-widget.js";
|
|
5
5
|
import type { Container } from "./traversal.js";
|
|
6
6
|
|
|
@@ -17,9 +17,7 @@ type NormalizerFn = (text: string) => string;
|
|
|
17
17
|
* A widget class usable as a query's `as` constraint, such as `Gtk.Button`. Abstract classes and
|
|
18
18
|
* generated GInterface pseudo-classes that extend `Gtk.Accessible` are accepted.
|
|
19
19
|
*/
|
|
20
|
-
type WidgetType<T extends Gtk.Accessible = Gtk.Accessible> = abstract new (
|
|
21
|
-
...args: never[]
|
|
22
|
-
) => T;
|
|
20
|
+
type WidgetType<T extends Gtk.Accessible = Gtk.Accessible> = abstract new (...args: never[]) => T;
|
|
23
21
|
|
|
24
22
|
/** Options controlling the default text normalizer. */
|
|
25
23
|
type NormalizerOptions = {
|
|
@@ -100,9 +98,7 @@ type ByRoleOptions<T extends Gtk.Accessible = Gtk.Accessible> = MatcherOptions<T
|
|
|
100
98
|
};
|
|
101
99
|
|
|
102
100
|
/** A React component that wraps rendered content, receiving it as its children. */
|
|
103
|
-
type WrapperComponent = ComponentType<
|
|
104
|
-
children: ReactNode;
|
|
105
|
-
}>;
|
|
101
|
+
type WrapperComponent = ComponentType<Required<PropsWithChildren>>;
|
|
106
102
|
|
|
107
103
|
/** A custom query, taking the scope to search as its first argument and its matcher arguments after it. */
|
|
108
104
|
type Query = (container: Container, ...args: never[]) => unknown;
|
|
@@ -140,19 +136,17 @@ type QueryKind = "role" | "text" | "name" | "value";
|
|
|
140
136
|
type QueryArgs<Kind extends QueryKind, T extends Gtk.Accessible> = Kind extends "role"
|
|
141
137
|
? [role: Gtk.AccessibleRole, options?: ByRoleOptions<T>]
|
|
142
138
|
: Kind extends "name"
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
? [name: Matcher, options?: MatcherOptions<T>]
|
|
140
|
+
: Kind extends "value"
|
|
141
|
+
? [value: Matcher, options?: MatcherOptions<T>]
|
|
142
|
+
: [text: Matcher, options?: MatcherOptions<T>];
|
|
147
143
|
|
|
148
144
|
/**
|
|
149
145
|
* One family's query variants, each named for its variant followed by `Suffix` and taking `Head`
|
|
150
146
|
* ahead of the family's own arguments.
|
|
151
147
|
*/
|
|
152
148
|
type QueryFamily<Suffix extends string, Kind extends QueryKind, Head extends unknown[]> = {
|
|
153
|
-
[K in keyof QueryFamilyReturns<Gtk.Widget> as `${K & string}${Suffix}`]: <
|
|
154
|
-
T extends Gtk.Accessible = Gtk.Widget,
|
|
155
|
-
>(
|
|
149
|
+
[K in keyof QueryFamilyReturns<Gtk.Widget> as `${K & string}${Suffix}`]: <T extends Gtk.Accessible = Gtk.Widget>(
|
|
156
150
|
...args: [...Head, ...QueryArgs<Kind, T>]
|
|
157
151
|
) => QueryFamilyReturns<T>[K];
|
|
158
152
|
};
|
|
@@ -241,12 +235,12 @@ type RenderHookOptions<Props> = {
|
|
|
241
235
|
wrapper?: WrapperComponent;
|
|
242
236
|
} & (undefined extends Props
|
|
243
237
|
? {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
238
|
+
/** Props the hook is invoked with until `rerender` is given new ones. */
|
|
239
|
+
initialProps?: Props;
|
|
240
|
+
}
|
|
247
241
|
: {
|
|
248
|
-
|
|
249
|
-
|
|
242
|
+
initialProps: Props;
|
|
243
|
+
});
|
|
250
244
|
|
|
251
245
|
/**
|
|
252
246
|
* The result of {@link renderHook}: the latest hook return value plus functions to rerender with new
|
|
@@ -259,7 +253,7 @@ type RenderHookResult<Result, Props> = {
|
|
|
259
253
|
current: Result;
|
|
260
254
|
};
|
|
261
255
|
/** Re-invokes the hook, keeping the previous props when none are given. */
|
|
262
|
-
rerender: (newProps
|
|
256
|
+
rerender: (...args: [] | [newProps: Props]) => Promise<void>;
|
|
263
257
|
/** Unmounts the component that calls the hook. */
|
|
264
258
|
unmount: () => Promise<void>;
|
|
265
259
|
};
|
|
@@ -20,9 +20,7 @@ type ScrollAdjustments = {
|
|
|
20
20
|
const slide = (widget: Gtk.Widget, value: number): Promise<void> =>
|
|
21
21
|
wrapEvent(widget, () => {
|
|
22
22
|
if (!(widget instanceof Gtk.Range)) {
|
|
23
|
-
throw new TypeError(
|
|
24
|
-
`userEvent.slide requires a Gtk.Range (e.g. Gtk.Scale), got ${getTypeTag(widget)}`,
|
|
25
|
-
);
|
|
23
|
+
throw new TypeError(`userEvent.slide requires a Gtk.Range (e.g. Gtk.Scale), got ${getTypeTag(widget)}`);
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
widget.emit("change-value", Gtk.ScrollType.JUMP, value);
|
package/src/user-event/click.ts
CHANGED
|
@@ -49,12 +49,7 @@ const getClickPoint = (clicked: Gtk.Widget, carrier: Gtk.Widget): PressPoint =>
|
|
|
49
49
|
return { x: bounds.getX() + bounds.getWidth() / 2, y: bounds.getY() + bounds.getHeight() / 2 };
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
const emitGesture = (
|
|
53
|
-
point: PressPoint,
|
|
54
|
-
controllers: Gtk.GestureClick[],
|
|
55
|
-
nPress: number,
|
|
56
|
-
signal: ClickPhase,
|
|
57
|
-
): void => {
|
|
52
|
+
const emitGesture = (point: PressPoint, controllers: Gtk.GestureClick[], nPress: number, signal: ClickPhase): void => {
|
|
58
53
|
for (const controller of controllers) {
|
|
59
54
|
controller.emit(signal, nPress, point.x, point.y);
|
|
60
55
|
}
|
|
@@ -235,8 +230,7 @@ const applyContainerClick: NativeClick = (widget, nPress) => {
|
|
|
235
230
|
const directClickFor = (widget: Gtk.Widget): DirectClick => {
|
|
236
231
|
const native = nativeClickFor(widget, true);
|
|
237
232
|
const container = native === null ? containerFor(widget) : null;
|
|
238
|
-
const gestures =
|
|
239
|
-
native !== null || container !== null ? getAuthoredClickGestures(widget) : clickGestures(widget);
|
|
233
|
+
const gestures = native !== null || container !== null ? getAuthoredClickGestures(widget) : clickGestures(widget);
|
|
240
234
|
const target: ClickTarget = { widget, container, gestures, isClaiming: true, native };
|
|
241
235
|
|
|
242
236
|
return { sites: targetSites(widget, target), outcome: native ?? (container === null ? null : applyContainerClick) };
|
|
@@ -256,7 +250,6 @@ const deliverClick = (widget: Gtk.Widget, nPress: number): Promise<void> =>
|
|
|
256
250
|
applyClickOutcomes(targets, nPress);
|
|
257
251
|
});
|
|
258
252
|
|
|
259
|
-
/* eslint-disable-next-line unicorn/consistent-boolean-name -- the boolean reports whether activation succeeded */
|
|
260
253
|
const tryActivate = async (widget: Gtk.Widget): Promise<boolean> => {
|
|
261
254
|
if (widget.getAccessibleRole() === Gtk.AccessibleRole.LABEL) {
|
|
262
255
|
return false;
|
|
@@ -26,7 +26,7 @@ const headerIndexFor = (header: Gtk.Widget): number => {
|
|
|
26
26
|
const titledColumnFor = (columns: Gtk.ColumnViewColumn[], title: string | null): Gtk.ColumnViewColumn | null => {
|
|
27
27
|
const matches = columns.filter((column) => column.getTitle() === title);
|
|
28
28
|
|
|
29
|
-
return matches.length === 1 ? matches[0] ?? null : null;
|
|
29
|
+
return matches.length === 1 ? (matches[0] ?? null) : null;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
const columnFor = (header: Gtk.Widget, view: Gtk.ColumnView): Gtk.ColumnViewColumn | null => {
|
|
@@ -7,7 +7,7 @@ type ControllerConstructor<T extends Gtk.EventController> = new () => T;
|
|
|
7
7
|
/**
|
|
8
8
|
* Returns every controller of the given type attached to a widget, in the order GTK4 reports them.
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
10
|
+
* @param target The widget whose controllers are inspected.
|
|
11
11
|
* @param controllerType The controller class to match.
|
|
12
12
|
* @returns The matching controllers, or an empty array when the widget has none.
|
|
13
13
|
*/
|
|
@@ -74,9 +74,9 @@ const getController = <T extends Gtk.EventController>(
|
|
|
74
74
|
widget: Gtk.Accessible,
|
|
75
75
|
controllerType: ControllerConstructor<T>,
|
|
76
76
|
): T => {
|
|
77
|
-
const
|
|
77
|
+
const controller = queryController(widget, controllerType);
|
|
78
78
|
|
|
79
|
-
if (controller ===
|
|
79
|
+
if (controller === null) {
|
|
80
80
|
throw new Error(`No ${controllerType.name} controller is attached to the widget`);
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -82,7 +82,7 @@ const waitForActionable = async (widget: Gtk.Widget): Promise<void> => {
|
|
|
82
82
|
if (failure !== null) {
|
|
83
83
|
throw new Error(
|
|
84
84
|
`Cannot dispatch user event: ${describeWidget(widget)} did not become actionable ` +
|
|
85
|
-
|
|
85
|
+
`within ${String(timeout)}ms because ${failure}`,
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
88
|
};
|