@gtkx/testing 1.0.0-rc.2 → 1.0.0-rc.4
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 +4 -5
- package/dist/act.d.ts +2 -0
- package/dist/act.d.ts.map +1 -1
- package/dist/act.js.map +1 -1
- package/dist/bound-queries.d.ts +2 -3
- package/dist/bound-queries.d.ts.map +1 -1
- package/dist/bound-queries.js.map +1 -1
- package/dist/build-queries.d.ts.map +1 -1
- package/dist/build-queries.js +18 -7
- package/dist/build-queries.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -3
- package/dist/config.js.map +1 -1
- package/dist/errors.js +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/matchers.d.ts +125 -21
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +258 -21
- package/dist/matchers.js.map +1 -1
- package/dist/normalize.d.ts +10 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +20 -0
- package/dist/normalize.js.map +1 -0
- package/dist/pretty-widget.d.ts +2 -1
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +3 -3
- package/dist/pretty-widget.js.map +1 -1
- package/dist/queries.d.ts +4 -21
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +46 -59
- package/dist/queries.js.map +1 -1
- package/dist/render.js +3 -3
- package/dist/render.js.map +1 -1
- package/dist/suggestions.d.ts +3 -0
- package/dist/suggestions.d.ts.map +1 -1
- package/dist/suggestions.js.map +1 -1
- package/dist/traversal.d.ts +5 -0
- package/dist/traversal.d.ts.map +1 -1
- package/dist/traversal.js +1 -0
- package/dist/traversal.js.map +1 -1
- package/dist/types.d.ts +69 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-event/adjustment.d.ts +13 -0
- package/dist/user-event/adjustment.d.ts.map +1 -1
- package/dist/user-event/adjustment.js +11 -0
- package/dist/user-event/adjustment.js.map +1 -1
- package/dist/user-event/click.d.ts +7 -0
- package/dist/user-event/click.d.ts.map +1 -1
- package/dist/user-event/click.js +7 -0
- package/dist/user-event/click.js.map +1 -1
- package/dist/user-event/controller.d.ts +31 -1
- package/dist/user-event/controller.d.ts.map +1 -1
- package/dist/user-event/controller.js +36 -1
- package/dist/user-event/controller.js.map +1 -1
- package/dist/user-event/gesture.d.ts +51 -0
- package/dist/user-event/gesture.d.ts.map +1 -1
- package/dist/user-event/gesture.js +47 -4
- package/dist/user-event/gesture.js.map +1 -1
- package/dist/user-event/index.d.ts +27 -0
- package/dist/user-event/index.d.ts.map +1 -1
- package/dist/user-event/index.js.map +1 -1
- package/dist/user-event/keyboard.d.ts +4 -2
- package/dist/user-event/keyboard.d.ts.map +1 -1
- package/dist/user-event/keyboard.js +13 -12
- package/dist/user-event/keyboard.js.map +1 -1
- package/dist/user-event/pointer.js +5 -5
- package/dist/user-event/pointer.js.map +1 -1
- package/dist/user-event/selection.d.ts +15 -0
- package/dist/user-event/selection.d.ts.map +1 -1
- package/dist/user-event/selection.js +15 -0
- package/dist/user-event/selection.js.map +1 -1
- package/dist/user-event/state.d.ts +1 -1
- package/dist/user-event/state.d.ts.map +1 -1
- package/dist/user-event/state.js +1 -1
- package/dist/user-event/state.js.map +1 -1
- package/dist/user-event/text.d.ts +30 -3
- package/dist/user-event/text.d.ts.map +1 -1
- package/dist/user-event/text.js +28 -1
- package/dist/user-event/text.js.map +1 -1
- package/dist/wait-for.d.ts +2 -0
- package/dist/wait-for.d.ts.map +1 -1
- package/dist/wait-for.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +28 -2
- package/dist/widget-accessible-properties.d.ts.map +1 -1
- package/dist/widget-accessible-properties.js +129 -10
- package/dist/widget-accessible-properties.js.map +1 -1
- package/dist/within.js.map +1 -1
- package/package.json +7 -7
- package/src/act.ts +2 -0
- package/src/bound-queries.ts +2 -3
- package/src/build-queries.ts +20 -8
- package/src/config.ts +4 -3
- package/src/errors.ts +2 -2
- package/src/index.ts +11 -2
- package/src/matchers.ts +500 -53
- package/src/normalize.ts +28 -0
- package/src/pretty-widget.ts +5 -4
- package/src/queries.ts +79 -105
- package/src/render.tsx +3 -3
- package/src/suggestions.ts +3 -0
- package/src/traversal.ts +5 -0
- package/src/types.ts +88 -4
- package/src/user-event/adjustment.ts +13 -0
- package/src/user-event/click.ts +7 -0
- package/src/user-event/controller.ts +50 -1
- package/src/user-event/gesture.ts +57 -6
- package/src/user-event/index.ts +27 -0
- package/src/user-event/keyboard.ts +18 -16
- package/src/user-event/pointer.ts +5 -5
- package/src/user-event/selection.ts +15 -0
- package/src/user-event/state.ts +2 -2
- package/src/user-event/text.ts +31 -4
- package/src/wait-for.ts +2 -0
- package/src/widget-accessible-properties.ts +188 -10
- package/src/within.ts +1 -1
package/dist/traversal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traversal.js","sourceRoot":"","sources":["../src/traversal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"traversal.js","sourceRoot":"","sources":["../src/traversal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAcpC,sFAAsF;AACtF,MAAM,SAAS,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAE1D,MAAM,aAAa,GAAG,CAAC,SAAoB,EAAgC,EAAE,CAAC,SAAS,YAAY,GAAG,CAAC,WAAW,CAAC;AAEnH,MAAM,kBAAkB,GAAG,QAAQ,CAAC,EAAE,IAAgB;IAClD,MAAM,IAAI,CAAC;IACX,IAAI,KAAK,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IAEjC,OAAO,KAAK,EAAE,CAAC;QACX,KAAK,CAAC,CAAC,kBAAk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AAE,SAAoB;IAC5C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,KAAK,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,SAAoB,EAAE,OAAsC,EAAgB,EAAE;IAC3F,MAAM,OAAO,GAAiB,EAAE,CAAC;IAEjC,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACrC,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAkB,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\n\n/**\n * A scope that resolves to a single root widget: the widget itself, the widget a controller or\n * layout manager is attached to, or a list item's or header's child.\n */\ntype QueryContainer = Gtk.Widget | Gtk.EventController | Gtk.LayoutManager | Gtk.ListItem | Gtk.ListHeader;\n/**\n * A scope that queries and traversal can run against: a widget, an event\n * controller, a layout manager, a list item or header, an application, or the\n * sentinel representing all current toplevel windows.\n */\ntype Container = QueryContainer | Gtk.Application | typeof TOPLEVELS;\n\n/** Container sentinel that widens a query to every toplevel window currently open. */\nconst TOPLEVELS: unique symbol = Symbol(\"gtkx.toplevels\");\n\nconst isApplication = (container: Container): container is Gtk.Application => container instanceof Gtk.Application;\n\nconst traverseWidgetTree = function* (root: Gtk.Widget): Generator<Gtk.Widget> {\n yield root;\n let child = root.getFirstChild();\n\n while (child) {\n yield* traverseWidgetTree(child);\n child = child.getNextSibling();\n }\n};\n\nconst descendants = function* (widget: Gtk.Widget): Generator<Gtk.Widget> {\n const tree = traverseWidgetTree(widget);\n tree.next();\n yield* tree;\n};\n\nconst resolveRoot = (container: QueryContainer): Gtk.Widget | null => {\n if (container instanceof Gtk.Widget) {\n return container;\n }\n\n if (container instanceof Gtk.EventController) {\n return container.getWidget();\n }\n\n if (container instanceof Gtk.LayoutManager) {\n return container.getWidget();\n }\n\n if (container instanceof Gtk.ListItem || container instanceof Gtk.ListHeader) {\n return container.getChild();\n }\n\n return null;\n};\n\nconst roots = function* (container: Container): Generator<Gtk.Widget> {\n if (container === TOPLEVELS || isApplication(container)) {\n yield* Gtk.Window.listToplevels();\n\n return;\n }\n\n const root = resolveRoot(container);\n\n if (root) {\n yield root;\n }\n};\n\nconst traverse = function* (container: Container): Generator<Gtk.Widget> {\n for (const root of roots(container)) {\n yield* traverseWidgetTree(root);\n }\n};\n\nconst findAll = (container: Container, isMatch: (node: Gtk.Widget) => boolean): Gtk.Widget[] => {\n const results: Gtk.Widget[] = [];\n\n for (const node of traverse(container)) {\n if (isMatch(node)) {\n results.push(node);\n }\n }\n\n return results;\n};\n\nexport { TOPLEVELS, descendants, roots, traverse, findAll, type Container };\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ type MatcherFunction = (content: string, widget: Gtk.Widget) => boolean;
|
|
|
12
12
|
type Matcher = string | number | RegExp | MatcherFunction;
|
|
13
13
|
/** Normalizes a widget's text before it is compared against a matcher. */
|
|
14
14
|
type NormalizerFn = (text: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* A widget class usable as a query's `as` constraint, such as `Gtk.Button`. Abstract classes and
|
|
17
|
+
* generated GInterface pseudo-classes are accepted.
|
|
18
|
+
*/
|
|
19
|
+
type WidgetType<T extends Gtk.Widget = Gtk.Widget> = abstract new (...args: never[]) => T;
|
|
15
20
|
/** Options controlling the default text normalizer. */
|
|
16
21
|
type NormalizerOptions = {
|
|
17
22
|
/** Trim leading and trailing whitespace. */
|
|
@@ -31,7 +36,7 @@ type WaitForOptions = {
|
|
|
31
36
|
stackTraceError?: Error | undefined;
|
|
32
37
|
};
|
|
33
38
|
/** Options controlling text matching and, for asynchronous queries, polling behavior. */
|
|
34
|
-
type MatcherOptions = {
|
|
39
|
+
type MatcherOptions<T extends Gtk.Widget = Gtk.Widget> = {
|
|
35
40
|
/** When true (the default), require an exact match; when false, match case-insensitively as a substring. */
|
|
36
41
|
exact?: boolean | undefined;
|
|
37
42
|
/** Custom normalizer replacing the default; cannot be combined with `trim` or `collapseWhitespace`. */
|
|
@@ -42,27 +47,39 @@ type MatcherOptions = {
|
|
|
42
47
|
collapseWhitespace?: boolean | undefined;
|
|
43
48
|
/** Whether to include a suggested better query in error messages. */
|
|
44
49
|
suggest?: boolean | undefined;
|
|
50
|
+
/** Restricts matches to instances of this widget class, and narrows the query's return type to it. */
|
|
51
|
+
as?: WidgetType<T> | undefined;
|
|
45
52
|
} & WaitForOptions;
|
|
46
53
|
/** Constraints on a widget's numeric range value used by role queries. */
|
|
47
54
|
type ByRoleValue = {
|
|
48
55
|
/** The current value. */
|
|
49
56
|
now?: number | undefined;
|
|
57
|
+
/** The lower bound of the value's range. */
|
|
50
58
|
min?: number | undefined;
|
|
59
|
+
/** The upper bound of the value's range. */
|
|
51
60
|
max?: number | undefined;
|
|
52
61
|
/** Matcher for the value's textual representation. */
|
|
53
62
|
text?: Matcher | undefined;
|
|
54
63
|
};
|
|
55
64
|
/** Options for role queries: an accessible name matcher plus accessible state and value constraints. */
|
|
56
|
-
type ByRoleOptions = MatcherOptions & {
|
|
65
|
+
type ByRoleOptions<T extends Gtk.Widget = Gtk.Widget> = MatcherOptions<T> & {
|
|
66
|
+
/** Matcher for the widget's accessible name. */
|
|
57
67
|
name?: Matcher | undefined;
|
|
68
|
+
/** Required checked state; a mixed check button reads as neither, so it matches neither value. */
|
|
58
69
|
checked?: boolean | undefined;
|
|
70
|
+
/** Required active state of a toggle button; any other widget matches neither value. */
|
|
59
71
|
pressed?: boolean | undefined;
|
|
72
|
+
/** Required selected state of a row, list item, grid cell, option or tree item. */
|
|
60
73
|
selected?: boolean | undefined;
|
|
74
|
+
/** Required expanded state of an expander or tree expander. */
|
|
61
75
|
expanded?: boolean | undefined;
|
|
62
76
|
/** Heading or hierarchy level. */
|
|
63
77
|
level?: number | undefined;
|
|
78
|
+
/** Required busy state, which an unset state satisfies as false. */
|
|
64
79
|
busy?: boolean | undefined;
|
|
80
|
+
/** Matcher for the widget's own accessible description, ignoring its `described-by` targets. */
|
|
65
81
|
description?: Matcher | undefined;
|
|
82
|
+
/** Constraints on the widget's range value, each checked only when given. */
|
|
66
83
|
value?: ByRoleValue | undefined;
|
|
67
84
|
/** When true, include widgets excluded from the accessibility tree. */
|
|
68
85
|
hidden?: boolean | undefined;
|
|
@@ -71,25 +88,62 @@ type ByRoleOptions = MatcherOptions & {
|
|
|
71
88
|
type WrapperComponent = ComponentType<{
|
|
72
89
|
children: ReactNode;
|
|
73
90
|
}>;
|
|
91
|
+
/** A custom query, taking the scope to search as its first argument and its matcher arguments after it. */
|
|
74
92
|
type Query = (container: Container, ...args: never[]) => unknown;
|
|
93
|
+
/** Custom queries keyed by the name each is bound under. */
|
|
75
94
|
type QueryMap = Record<string, Query>;
|
|
95
|
+
/** A query with its container argument already applied. */
|
|
76
96
|
type BoundQuery<Q extends Query> = Q extends (container: Container, ...args: infer A) => infer R ? (...args: A) => R : never;
|
|
97
|
+
/** Custom queries with their container argument already applied, keyed as they were passed in. */
|
|
77
98
|
type BoundCustomQueries<Q extends QueryMap> = {
|
|
78
99
|
[K in keyof Q]: BoundQuery<Q[K]>;
|
|
79
100
|
};
|
|
101
|
+
/** What each variant of a query family yields for the widget type it matched. */
|
|
102
|
+
type QueryFamilyReturns<T extends Gtk.Widget> = {
|
|
103
|
+
/** The single match, or null when nothing matched; throws when more than one matched. */
|
|
104
|
+
queryBy: T | null;
|
|
105
|
+
/** Every match, empty when nothing matched. */
|
|
106
|
+
queryAllBy: T[];
|
|
107
|
+
/** The single match; throws when nothing or more than one matched. */
|
|
108
|
+
getBy: T;
|
|
109
|
+
/** Every match; throws when nothing matched. */
|
|
110
|
+
getAllBy: T[];
|
|
111
|
+
/** The single match, retried until it appears or the timeout elapses. */
|
|
112
|
+
findBy: Promise<T>;
|
|
113
|
+
/** Every match, retried until at least one appears or the timeout elapses. */
|
|
114
|
+
findAllBy: Promise<T[]>;
|
|
115
|
+
};
|
|
116
|
+
/** What a query family matches against, which fixes the arguments it takes. */
|
|
117
|
+
type QueryKind = "role" | "text" | "name" | "value";
|
|
118
|
+
/** The arguments a query of the given kind takes after the family's leading ones. */
|
|
119
|
+
type QueryArgs<Kind extends QueryKind, T extends Gtk.Widget> = Kind extends "role" ? [role: Gtk.AccessibleRole, options?: ByRoleOptions<T>] : Kind extends "name" ? [name: Matcher, options?: MatcherOptions<T>] : Kind extends "value" ? [value: Matcher, options?: MatcherOptions<T>] : [text: Matcher, options?: MatcherOptions<T>];
|
|
120
|
+
/**
|
|
121
|
+
* One family's query variants, each named for its variant followed by `Suffix` and taking `Head`
|
|
122
|
+
* ahead of the family's own arguments.
|
|
123
|
+
*/
|
|
124
|
+
type QueryFamily<Suffix extends string, Kind extends QueryKind, Head extends unknown[]> = {
|
|
125
|
+
[K in keyof QueryFamilyReturns<Gtk.Widget> as `${K & string}${Suffix}`]: <T extends Gtk.Widget = Gtk.Widget>(...args: [...Head, ...QueryArgs<Kind, T>]) => QueryFamilyReturns<T>[K];
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Every built-in query, spanning the Role, LabelText, Text, Name, PlaceholderText, and DisplayValue
|
|
129
|
+
* families, with `Head` prepended to each signature.
|
|
130
|
+
*/
|
|
131
|
+
type QueryFamilies<Head extends unknown[]> = QueryFamily<"Role", "role", Head> & QueryFamily<"LabelText", "text", Head> & QueryFamily<"Text", "text", Head> & QueryFamily<"Name", "name", Head> & QueryFamily<"PlaceholderText", "text", Head> & QueryFamily<"DisplayValue", "value", Head>;
|
|
80
132
|
/**
|
|
81
133
|
* Options for {@link render}: the container and base element to mount into, an optional wrapper,
|
|
82
134
|
* React behavior toggles, error callbacks, and custom queries to bind.
|
|
83
135
|
*/
|
|
84
136
|
type RenderOptions<Q extends QueryMap = Record<never, never>> = {
|
|
137
|
+
/** Widget or root element to mount into; an undecorated harness window is created when omitted. */
|
|
85
138
|
container?: Gtk.Widget | RootElement | undefined;
|
|
86
139
|
/** Root of the subtree that bound queries search. */
|
|
87
140
|
baseElement?: Container | undefined;
|
|
141
|
+
/** Component wrapped around the rendered element, such as a context provider. */
|
|
88
142
|
wrapper?: WrapperComponent | undefined;
|
|
89
143
|
/** Render inside React StrictMode. */
|
|
90
|
-
|
|
144
|
+
isReactStrictMode?: boolean | undefined;
|
|
91
145
|
/** Enable widget animations during the test. */
|
|
92
|
-
|
|
146
|
+
areAnimationsEnabled?: boolean | undefined;
|
|
93
147
|
/** Called for errors caught by React error boundaries. */
|
|
94
148
|
onCaughtError?: ((error: unknown, errorInfo: ErrorInfo) => void) | undefined;
|
|
95
149
|
/** Called for errors React recovered from automatically. */
|
|
@@ -97,16 +151,24 @@ type RenderOptions<Q extends QueryMap = Record<never, never>> = {
|
|
|
97
151
|
/** Custom queries to bind to the rendered result. */
|
|
98
152
|
queries?: Q | undefined;
|
|
99
153
|
};
|
|
154
|
+
/** Console helpers bundled with the bound queries on {@link screen} and on a render result. */
|
|
100
155
|
type DebugUtilities = {
|
|
156
|
+
/** Prints the widget tree of the given containers, or of the whole scope, to the console. */
|
|
101
157
|
debug: (element?: Container | Container[], options?: PrettyWidgetOptions) => void;
|
|
158
|
+
/** Prints the accessible roles found in the scope, with the widgets carrying each one. */
|
|
102
159
|
logRoles: () => void;
|
|
160
|
+
/** Captures a window, writes the image to a temporary file, and logs its path. */
|
|
103
161
|
screenshot: (selector?: WindowSelector, options?: ScreenshotOptions) => Promise<ScreenshotResult>;
|
|
104
162
|
};
|
|
105
163
|
/** A captured screenshot: base64-encoded image data, its MIME type, and pixel dimensions. */
|
|
106
164
|
type ScreenshotResult = {
|
|
165
|
+
/** Base64-encoded image bytes. */
|
|
107
166
|
data: string;
|
|
167
|
+
/** MIME type of the encoded image, always `image/png`. */
|
|
108
168
|
mimeType: string;
|
|
169
|
+
/** Image width in pixels, after the scale factor is applied. */
|
|
109
170
|
width: number;
|
|
171
|
+
/** Image height in pixels, after the scale factor is applied. */
|
|
110
172
|
height: number;
|
|
111
173
|
};
|
|
112
174
|
/** Options for capturing a screenshot: the poll timeout and interval, plus a rendering scale factor. */
|
|
@@ -139,8 +201,10 @@ type RenderHookResult<Result, Props> = {
|
|
|
139
201
|
result: {
|
|
140
202
|
current: Result;
|
|
141
203
|
};
|
|
204
|
+
/** Re-invokes the hook, keeping the previous props when none are given. */
|
|
142
205
|
rerender: (newProps?: Props) => Promise<void>;
|
|
206
|
+
/** Unmounts the component that calls the hook. */
|
|
143
207
|
unmount: () => Promise<void>;
|
|
144
208
|
};
|
|
145
|
-
export { type MatcherFunction, type Matcher, type NormalizerFn, type NormalizerOptions, type WaitForOptions, type MatcherOptions, type ByRoleValue, type ByRoleOptions, type WrapperComponent, type QueryMap, type BoundCustomQueries, type RenderOptions, type DebugUtilities, type ScreenshotResult, type ScreenshotOptions, type WindowSelector, type RenderHookOptions, type RenderHookResult, };
|
|
209
|
+
export { type MatcherFunction, type Matcher, type NormalizerFn, type NormalizerOptions, type WaitForOptions, type MatcherOptions, type ByRoleValue, type ByRoleOptions, type WidgetType, type WrapperComponent, type QueryMap, type BoundCustomQueries, type QueryFamilies, type RenderOptions, type DebugUtilities, type ScreenshotResult, type ScreenshotOptions, type WindowSelector, type RenderHookOptions, type RenderHookResult, };
|
|
146
210
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK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 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAkKA,OAAO,EAmBN,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport type { RootElement } from \"@gtkx/react\";\nimport type { ComponentType, ErrorInfo, ReactNode } from \"react\";\nimport type { PrettyWidgetOptions } from \"./pretty-widget.js\";\nimport type { Container } from \"./traversal.js\";\n\n/**\n * A custom matcher predicate: given a candidate widget's normalized text content and the widget\n * itself, returns whether it matches.\n */\ntype MatcherFunction = (content: string, widget: Gtk.Widget) => boolean;\n/** A value used to match widget text: a string or number, a regular expression, or a custom {@link MatcherFunction}. */\ntype Matcher = string | number | RegExp | MatcherFunction;\n/** Normalizes a widget's text before it is compared against a matcher. */\ntype NormalizerFn = (text: string) => string;\n\n/** Options controlling the default text normalizer. */\ntype NormalizerOptions = {\n /** Trim leading and trailing whitespace. */\n trim?: boolean | undefined;\n /** Collapse runs of whitespace into a single space. */\n collapseWhitespace?: boolean | undefined;\n};\n\n/** Options controlling how asynchronous queries and waits poll for a condition. */\ntype WaitForOptions = {\n /** Maximum time in milliseconds to keep retrying before failing. */\n timeout?: number | undefined;\n /** Delay in milliseconds between retries. */\n interval?: number | undefined;\n /** Transforms the error thrown when the timeout elapses. */\n onTimeout?: ((error: Error) => Error) | undefined;\n /** Error whose stack trace attributes the timeout failure to the calling code. */\n stackTraceError?: Error | undefined;\n};\n\n/** Options controlling text matching and, for asynchronous queries, polling behavior. */\ntype MatcherOptions = {\n /** When true (the default), require an exact match; when false, match case-insensitively as a substring. */\n exact?: boolean | undefined;\n /** Custom normalizer replacing the default; cannot be combined with `trim` or `collapseWhitespace`. */\n normalizer?: NormalizerFn | undefined;\n /** Forwarded to the default normalizer when no custom `normalizer` is given. */\n trim?: boolean | undefined;\n /** Forwarded to the default normalizer when no custom `normalizer` is given. */\n collapseWhitespace?: boolean | undefined;\n /** Whether to include a suggested better query in error messages. */\n suggest?: boolean | undefined;\n} & WaitForOptions;\n\n/** Constraints on a widget's numeric range value used by role queries. */\ntype ByRoleValue = {\n /** The current value. */\n now?: number | undefined;\n min?: number | undefined;\n max?: number | undefined;\n /** Matcher for the value's textual representation. */\n text?: Matcher | undefined;\n};\n\n/** Options for role queries: an accessible name matcher plus accessible state and value constraints. */\ntype ByRoleOptions = MatcherOptions & {\n name?: Matcher | undefined;\n checked?: boolean | undefined;\n pressed?: boolean | undefined;\n selected?: boolean | undefined;\n expanded?: boolean | undefined;\n /** Heading or hierarchy level. */\n level?: number | undefined;\n busy?: boolean | undefined;\n description?: Matcher | undefined;\n value?: ByRoleValue | undefined;\n /** When true, include widgets excluded from the accessibility tree. */\n hidden?: boolean | undefined;\n};\n\n/** A React component that wraps rendered content, receiving it as its children. */\ntype WrapperComponent = ComponentType<{\n children: ReactNode;\n}>;\n\ntype Query = (container: Container, ...args: never[]) => unknown;\ntype QueryMap = Record<string, Query>;\n\ntype BoundQuery<Q extends Query> = Q extends (container: Container, ...args: infer A) => infer R\n ? (...args: A) => R\n : never;\n\ntype BoundCustomQueries<Q extends QueryMap> = { [K in keyof Q]: BoundQuery<Q[K]> };\n\n/**\n * Options for {@link render}: the container and base element to mount into, an optional wrapper,\n * React behavior toggles, error callbacks, and custom queries to bind.\n */\ntype RenderOptions<Q extends QueryMap = Record<never, never>> = {\n container?: Gtk.Widget | RootElement | undefined;\n /** Root of the subtree that bound queries search. */\n baseElement?: Container | undefined;\n wrapper?: WrapperComponent | undefined;\n /** Render inside React StrictMode. */\n reactStrictMode?: boolean | undefined;\n /** Enable widget animations during the test. */\n animations?: boolean | undefined;\n /** Called for errors caught by React error boundaries. */\n onCaughtError?: ((error: unknown, errorInfo: ErrorInfo) => void) | undefined;\n /** Called for errors React recovered from automatically. */\n onRecoverableError?: ((error: unknown, errorInfo: ErrorInfo) => void) | undefined;\n /** Custom queries to bind to the rendered result. */\n queries?: Q | undefined;\n};\n\ntype DebugUtilities = {\n debug: (element?: Container | Container[], options?: PrettyWidgetOptions) => void;\n logRoles: () => void;\n screenshot: (selector?: WindowSelector, options?: ScreenshotOptions) => Promise<ScreenshotResult>;\n};\n\n/** A captured screenshot: base64-encoded image data, its MIME type, and pixel dimensions. */\ntype ScreenshotResult = {\n data: string;\n mimeType: string;\n width: number;\n height: number;\n};\n\n/** Options for capturing a screenshot: the poll timeout and interval, plus a rendering scale factor. */\ntype ScreenshotOptions = Pick<WaitForOptions, \"timeout\" | \"interval\"> & {\n /** Device scale factor applied when rendering. */\n scale?: number;\n};\n\n/**\n * Selects the window to screenshot by index, or by title (exact string or regular expression);\n * undefined targets the default window.\n */\ntype WindowSelector = number | string | RegExp | undefined;\n\n/**\n * Options for {@link renderHook}: an optional wrapper and the initial props (required unless the\n * props type permits undefined).\n */\ntype RenderHookOptions<Props> = {\n wrapper?: WrapperComponent;\n} & (undefined extends Props\n ? {\n initialProps?: Props;\n }\n : {\n initialProps: Props;\n });\n\n/**\n * The result of {@link renderHook}: the latest hook return value plus functions to rerender with new\n * props and to unmount.\n */\ntype RenderHookResult<Result, Props> = {\n /** Holds the most recent value returned by the hook under `current`. */\n result: { current: Result };\n rerender: (newProps?: Props) => Promise<void>;\n unmount: () => Promise<void>;\n};\n\nexport {\n type MatcherFunction,\n type Matcher,\n type NormalizerFn,\n type NormalizerOptions,\n type WaitForOptions,\n type MatcherOptions,\n type ByRoleValue,\n type ByRoleOptions,\n type WrapperComponent,\n type QueryMap,\n type BoundCustomQueries,\n type RenderOptions,\n type DebugUtilities,\n type ScreenshotResult,\n type ScreenshotOptions,\n type WindowSelector,\n type RenderHookOptions,\n type RenderHookResult,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAoPA,OAAO,EAqBN,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\nimport type { RootElement } from \"@gtkx/react\";\nimport type { ComponentType, ErrorInfo, ReactNode } from \"react\";\nimport type { PrettyWidgetOptions } from \"./pretty-widget.js\";\nimport type { Container } from \"./traversal.js\";\n\n/**\n * A custom matcher predicate: given a candidate widget's normalized text content and the widget\n * itself, returns whether it matches.\n */\ntype MatcherFunction = (content: string, widget: Gtk.Widget) => boolean;\n/** A value used to match widget text: a string or number, a regular expression, or a custom {@link MatcherFunction}. */\ntype Matcher = string | number | RegExp | MatcherFunction;\n/** Normalizes a widget's text before it is compared against a matcher. */\ntype NormalizerFn = (text: string) => string;\n/**\n * A widget class usable as a query's `as` constraint, such as `Gtk.Button`. Abstract classes and\n * generated GInterface pseudo-classes are accepted.\n */\ntype WidgetType<T extends Gtk.Widget = Gtk.Widget> = abstract new (...args: never[]) => T;\n\n/** Options controlling the default text normalizer. */\ntype NormalizerOptions = {\n /** Trim leading and trailing whitespace. */\n trim?: boolean | undefined;\n /** Collapse runs of whitespace into a single space. */\n collapseWhitespace?: boolean | undefined;\n};\n\n/** Options controlling how asynchronous queries and waits poll for a condition. */\ntype WaitForOptions = {\n /** Maximum time in milliseconds to keep retrying before failing. */\n timeout?: number | undefined;\n /** Delay in milliseconds between retries. */\n interval?: number | undefined;\n /** Transforms the error thrown when the timeout elapses. */\n onTimeout?: ((error: Error) => Error) | undefined;\n /** Error whose stack trace attributes the timeout failure to the calling code. */\n stackTraceError?: Error | undefined;\n};\n\n/** Options controlling text matching and, for asynchronous queries, polling behavior. */\ntype MatcherOptions<T extends Gtk.Widget = Gtk.Widget> = {\n /** When true (the default), require an exact match; when false, match case-insensitively as a substring. */\n exact?: boolean | undefined;\n /** Custom normalizer replacing the default; cannot be combined with `trim` or `collapseWhitespace`. */\n normalizer?: NormalizerFn | undefined;\n /** Forwarded to the default normalizer when no custom `normalizer` is given. */\n trim?: boolean | undefined;\n /** Forwarded to the default normalizer when no custom `normalizer` is given. */\n collapseWhitespace?: boolean | undefined;\n /** Whether to include a suggested better query in error messages. */\n suggest?: boolean | undefined;\n /** Restricts matches to instances of this widget class, and narrows the query's return type to it. */\n as?: WidgetType<T> | undefined;\n} & WaitForOptions;\n\n/** Constraints on a widget's numeric range value used by role queries. */\ntype ByRoleValue = {\n /** The current value. */\n now?: number | undefined;\n /** The lower bound of the value's range. */\n min?: number | undefined;\n /** The upper bound of the value's range. */\n max?: number | undefined;\n /** Matcher for the value's textual representation. */\n text?: Matcher | undefined;\n};\n\n/** Options for role queries: an accessible name matcher plus accessible state and value constraints. */\ntype ByRoleOptions<T extends Gtk.Widget = Gtk.Widget> = MatcherOptions<T> & {\n /** Matcher for the widget's accessible name. */\n name?: Matcher | undefined;\n /** Required checked state; a mixed check button reads as neither, so it matches neither value. */\n checked?: boolean | undefined;\n /** Required active state of a toggle button; any other widget matches neither value. */\n pressed?: boolean | undefined;\n /** Required selected state of a row, list item, grid cell, option or tree item. */\n selected?: boolean | undefined;\n /** Required expanded state of an expander or tree expander. */\n expanded?: boolean | undefined;\n /** Heading or hierarchy level. */\n level?: number | undefined;\n /** Required busy state, which an unset state satisfies as false. */\n busy?: boolean | undefined;\n /** Matcher for the widget's own accessible description, ignoring its `described-by` targets. */\n description?: Matcher | undefined;\n /** Constraints on the widget's range value, each checked only when given. */\n value?: ByRoleValue | undefined;\n /** When true, include widgets excluded from the accessibility tree. */\n hidden?: boolean | undefined;\n};\n\n/** A React component that wraps rendered content, receiving it as its children. */\ntype WrapperComponent = ComponentType<{\n children: ReactNode;\n}>;\n\n/** A custom query, taking the scope to search as its first argument and its matcher arguments after it. */\ntype Query = (container: Container, ...args: never[]) => unknown;\n/** Custom queries keyed by the name each is bound under. */\ntype QueryMap = Record<string, Query>;\n\n/** A query with its container argument already applied. */\ntype BoundQuery<Q extends Query> = Q extends (container: Container, ...args: infer A) => infer R\n ? (...args: A) => R\n : never;\n\n/** Custom queries with their container argument already applied, keyed as they were passed in. */\ntype BoundCustomQueries<Q extends QueryMap> = { [K in keyof Q]: BoundQuery<Q[K]> };\n\n/** What each variant of a query family yields for the widget type it matched. */\ntype QueryFamilyReturns<T extends Gtk.Widget> = {\n /** The single match, or null when nothing matched; throws when more than one matched. */\n queryBy: T | null;\n /** Every match, empty when nothing matched. */\n queryAllBy: T[];\n /** The single match; throws when nothing or more than one matched. */\n getBy: T;\n /** Every match; throws when nothing matched. */\n getAllBy: T[];\n /** The single match, retried until it appears or the timeout elapses. */\n findBy: Promise<T>;\n /** Every match, retried until at least one appears or the timeout elapses. */\n findAllBy: Promise<T[]>;\n};\n\n/** What a query family matches against, which fixes the arguments it takes. */\ntype QueryKind = \"role\" | \"text\" | \"name\" | \"value\";\n\n/** The arguments a query of the given kind takes after the family's leading ones. */\ntype QueryArgs<Kind extends QueryKind, T extends Gtk.Widget> = Kind extends \"role\"\n ? [role: Gtk.AccessibleRole, options?: ByRoleOptions<T>]\n : Kind extends \"name\"\n ? [name: Matcher, options?: MatcherOptions<T>]\n : Kind extends \"value\"\n ? [value: Matcher, options?: MatcherOptions<T>]\n : [text: Matcher, options?: MatcherOptions<T>];\n\n/**\n * One family's query variants, each named for its variant followed by `Suffix` and taking `Head`\n * ahead of the family's own arguments.\n */\ntype QueryFamily<Suffix extends string, Kind extends QueryKind, Head extends unknown[]> = {\n [K in keyof QueryFamilyReturns<Gtk.Widget> as `${K & string}${Suffix}`]: <T extends Gtk.Widget = Gtk.Widget>(\n ...args: [...Head, ...QueryArgs<Kind, T>]\n ) => QueryFamilyReturns<T>[K];\n};\n\n/**\n * Every built-in query, spanning the Role, LabelText, Text, Name, PlaceholderText, and DisplayValue\n * families, with `Head` prepended to each signature.\n */\ntype QueryFamilies<Head extends unknown[]> = QueryFamily<\"Role\", \"role\", Head> &\n QueryFamily<\"LabelText\", \"text\", Head> &\n QueryFamily<\"Text\", \"text\", Head> &\n QueryFamily<\"Name\", \"name\", Head> &\n QueryFamily<\"PlaceholderText\", \"text\", Head> &\n QueryFamily<\"DisplayValue\", \"value\", Head>;\n\n/**\n * Options for {@link render}: the container and base element to mount into, an optional wrapper,\n * React behavior toggles, error callbacks, and custom queries to bind.\n */\ntype RenderOptions<Q extends QueryMap = Record<never, never>> = {\n /** Widget or root element to mount into; an undecorated harness window is created when omitted. */\n container?: Gtk.Widget | RootElement | undefined;\n /** Root of the subtree that bound queries search. */\n baseElement?: Container | undefined;\n /** Component wrapped around the rendered element, such as a context provider. */\n wrapper?: WrapperComponent | undefined;\n /** Render inside React StrictMode. */\n isReactStrictMode?: boolean | undefined;\n /** Enable widget animations during the test. */\n areAnimationsEnabled?: boolean | undefined;\n /** Called for errors caught by React error boundaries. */\n onCaughtError?: ((error: unknown, errorInfo: ErrorInfo) => void) | undefined;\n /** Called for errors React recovered from automatically. */\n onRecoverableError?: ((error: unknown, errorInfo: ErrorInfo) => void) | undefined;\n /** Custom queries to bind to the rendered result. */\n queries?: Q | undefined;\n};\n\n/** Console helpers bundled with the bound queries on {@link screen} and on a render result. */\ntype DebugUtilities = {\n /** Prints the widget tree of the given containers, or of the whole scope, to the console. */\n debug: (element?: Container | Container[], options?: PrettyWidgetOptions) => void;\n /** Prints the accessible roles found in the scope, with the widgets carrying each one. */\n logRoles: () => void;\n /** Captures a window, writes the image to a temporary file, and logs its path. */\n screenshot: (selector?: WindowSelector, options?: ScreenshotOptions) => Promise<ScreenshotResult>;\n};\n\n/** A captured screenshot: base64-encoded image data, its MIME type, and pixel dimensions. */\ntype ScreenshotResult = {\n /** Base64-encoded image bytes. */\n data: string;\n /** MIME type of the encoded image, always `image/png`. */\n mimeType: string;\n /** Image width in pixels, after the scale factor is applied. */\n width: number;\n /** Image height in pixels, after the scale factor is applied. */\n height: number;\n};\n\n/** Options for capturing a screenshot: the poll timeout and interval, plus a rendering scale factor. */\ntype ScreenshotOptions = Pick<WaitForOptions, \"timeout\" | \"interval\"> & {\n /** Device scale factor applied when rendering. */\n scale?: number;\n};\n\n/**\n * Selects the window to screenshot by index, or by title (exact string or regular expression);\n * undefined targets the default window.\n */\ntype WindowSelector = number | string | RegExp | undefined;\n\n/**\n * Options for {@link renderHook}: an optional wrapper and the initial props (required unless the\n * props type permits undefined).\n */\ntype RenderHookOptions<Props> = {\n wrapper?: WrapperComponent;\n} & (undefined extends Props\n ? {\n initialProps?: Props;\n }\n : {\n initialProps: Props;\n });\n\n/**\n * The result of {@link renderHook}: the latest hook return value plus functions to rerender with new\n * props and to unmount.\n */\ntype RenderHookResult<Result, Props> = {\n /** Holds the most recent value returned by the hook under `current`. */\n result: { current: Result };\n /** Re-invokes the hook, keeping the previous props when none are given. */\n rerender: (newProps?: Props) => Promise<void>;\n /** Unmounts the component that calls the hook. */\n unmount: () => Promise<void>;\n};\n\nexport {\n type MatcherFunction,\n type Matcher,\n type NormalizerFn,\n type NormalizerOptions,\n type WaitForOptions,\n type MatcherOptions,\n type ByRoleValue,\n type ByRoleOptions,\n type WidgetType,\n type WrapperComponent,\n type QueryMap,\n type BoundCustomQueries,\n type QueryFamilies,\n type RenderOptions,\n type DebugUtilities,\n type ScreenshotResult,\n type ScreenshotOptions,\n type WindowSelector,\n type RenderHookOptions,\n type RenderHookResult,\n};\n"]}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
2
|
/** A scroll distance in pixels along each axis. */
|
|
3
3
|
type ScrollDelta = {
|
|
4
|
+
/** Distance added to the horizontal adjustment. */
|
|
4
5
|
x?: number;
|
|
6
|
+
/** Distance added to the vertical adjustment. */
|
|
5
7
|
y?: number;
|
|
6
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Emits a jump `change-value` so a Gtk.Range moves to the given value.
|
|
11
|
+
*
|
|
12
|
+
* @throws When the widget is not a Gtk.Range.
|
|
13
|
+
*/
|
|
7
14
|
declare const slide: (widget: Gtk.Widget, value: number) => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Adds the delta to the adjustments of the widget itself, or of its nearest Gtk.ScrolledWindow or
|
|
17
|
+
* Gtk.Scrollable ancestor.
|
|
18
|
+
*
|
|
19
|
+
* @throws When neither the widget nor any of its ancestors is scrollable.
|
|
20
|
+
*/
|
|
8
21
|
declare const scroll: (widget: Gtk.Widget, delta: ScrollDelta) => Promise<void>;
|
|
9
22
|
export { slide, scroll, type ScrollDelta };
|
|
10
23
|
//# sourceMappingURL=adjustment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adjustment.d.ts","sourceRoot":"","sources":["../../src/user-event/adjustment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAGpC,mDAAmD;AACnD,KAAK,WAAW,GAAG;IACf,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAOF,QAAA,MAAM,KAAK,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,IAAI,CASzD,CAAC;AAwBP,QAAA,MAAM,MAAM,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,WAAW,KAAG,OAAO,CAAC,IAAI,CAY/D,CAAC;AAEP,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"adjustment.d.ts","sourceRoot":"","sources":["../../src/user-event/adjustment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAGpC,mDAAmD;AACnD,KAAK,WAAW,GAAG;IACf,mDAAmD;IACnD,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,iDAAiD;IACjD,CAAC,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAOF;;;;GAIG;AACH,QAAA,MAAM,KAAK,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,IAAI,CASzD,CAAC;AAwBP;;;;;GAKG;AACH,QAAA,MAAM,MAAM,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,WAAW,KAAG,OAAO,CAAC,IAAI,CAY/D,CAAC;AAEP,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,CAAC"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
2
|
import { wrapEvent } from "./event-wrapper.js";
|
|
3
|
+
/**
|
|
4
|
+
* Emits a jump `change-value` so a Gtk.Range moves to the given value.
|
|
5
|
+
*
|
|
6
|
+
* @throws When the widget is not a Gtk.Range.
|
|
7
|
+
*/
|
|
3
8
|
const slide = (widget, value) => wrapEvent(widget, () => {
|
|
4
9
|
if (!(widget instanceof Gtk.Range)) {
|
|
5
10
|
throw new TypeError(`userEvent.slide requires a Gtk.Range (e.g. Gtk.Scale), got ${widget.constructor.name}`);
|
|
@@ -23,6 +28,12 @@ const applyScrollDelta = (adjustment, delta) => {
|
|
|
23
28
|
}
|
|
24
29
|
adjustment.setValue(adjustment.getValue() + delta);
|
|
25
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Adds the delta to the adjustments of the widget itself, or of its nearest Gtk.ScrolledWindow or
|
|
33
|
+
* Gtk.Scrollable ancestor.
|
|
34
|
+
*
|
|
35
|
+
* @throws When neither the widget nor any of its ancestors is scrollable.
|
|
36
|
+
*/
|
|
26
37
|
const scroll = (widget, delta) => wrapEvent(widget, () => {
|
|
27
38
|
const adjustments = resolveScrollAdjustments(widget);
|
|
28
39
|
if (!adjustments) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adjustment.js","sourceRoot":"","sources":["../../src/user-event/adjustment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"adjustment.js","sourceRoot":"","sources":["../../src/user-event/adjustment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAe/C;;;;GAIG;AACH,MAAM,KAAK,GAAG,C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AE,KAAkB,EAAiB,EAAE,CACrE,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE;IACnB,MAAM,WAAW,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAErD,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACX,gGAAgG,CACnG,CAAC;IACN,CAAC;IAED,gBAAgB,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACvD,gBAAgB,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC;AAEP,OAAO,EAAE,KAAK,EAAE,MAAM,EAAoB,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\nimport { wrapEvent } from \"./event-wrapper.js\";\n\n/** A scroll distance in pixels along each axis. */\ntype ScrollDelta = {\n /** Distance added to the horizontal adjustment. */\n x?: number;\n /** Distance added to the vertical adjustment. */\n y?: number;\n};\n\ntype ScrollAdjustments = {\n horizontal: Gtk.Adjustment | null;\n vertical: Gtk.Adjustment | null;\n};\n\n/**\n * Emits a jump `change-value` so a Gtk.Range moves to the given value.\n *\n * @throws When the widget is not a Gtk.Range.\n */\nconst slide = (widget: Gtk.Widget, value: number): Promise<void> =>\n wrapEvent(widget, () => {\n if (!(widget instanceof Gtk.Range)) {\n throw new TypeError(\n `userEvent.slide requires a Gtk.Range (e.g. Gtk.Scale), got ${widget.constructor.name}`,\n );\n }\n\n widget.emit(\"change-value\", Gtk.ScrollType.JUMP, value);\n });\n\nconst resolveScrollAdjustments = (widget: Gtk.Widget): ScrollAdjustments | null => {\n for (let current: Gtk.Widget | null = widget; current; current = current.getParent()) {\n if (current instanceof Gtk.ScrolledWindow) {\n return { horizontal: current.getHadjustment(), vertical: current.getVadjustment() };\n }\n\n if (current instanceof Gtk.Scrollable) {\n return { horizontal: current.getHadjustment(), vertical: current.getVadjustment() };\n }\n }\n\n return null;\n};\n\nconst applyScrollDelta = (adjustment: Gtk.Adjustment | null, delta: number): void => {\n if (!adjustment || delta === 0) {\n return;\n }\n\n adjustment.setValue(adjustment.getValue() + delta);\n};\n\n/**\n * Adds the delta to the adjustments of the widget itself, or of its nearest Gtk.ScrolledWindow or\n * Gtk.Scrollable ancestor.\n *\n * @throws When neither the widget nor any of its ancestors is scrollable.\n */\nconst scroll = (widget: Gtk.Widget, delta: ScrollDelta): Promise<void> =>\n wrapEvent(widget, () => {\n const adjustments = resolveScrollAdjustments(widget);\n\n if (!adjustments) {\n throw new Error(\n \"userEvent.scroll: no Gtk.ScrolledWindow or Gtk.Scrollable found on the widget or its ancestors\",\n );\n }\n\n applyScrollDelta(adjustments.horizontal, delta.x ?? 0);\n applyScrollDelta(adjustments.vertical, delta.y ?? 0);\n });\n\nexport { slide, scroll, type ScrollDelta };\n"]}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
2
|
declare const emitPress: (widget: Gtk.Widget, controllers: Gtk.GestureClick[], nPress: number) => void;
|
|
3
3
|
declare const emitRelease: (widget: Gtk.Widget, controllers: Gtk.GestureClick[], nPress: number) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Presses and releases a Gtk.Button, flips a Gtk.Switch, and otherwise activates the widget,
|
|
6
|
+
* falling back to a click gesture on the nearest Gtk.Button or click-gesture ancestor when
|
|
7
|
+
* activation does nothing. A widget with the label role is never activated.
|
|
8
|
+
*/
|
|
4
9
|
declare const click: (widget: Gtk.Widget) => Promise<void>;
|
|
10
|
+
/** Emits a two-press click gesture at the widget's center, adding a Gtk.GestureClick when it has none. */
|
|
5
11
|
declare const dblClick: (widget: Gtk.Widget) => Promise<void>;
|
|
12
|
+
/** Emits a three-press click gesture at the widget's center, adding a Gtk.GestureClick when it has none. */
|
|
6
13
|
declare const tripleClick: (widget: Gtk.Widget) => Promise<void>;
|
|
7
14
|
export { emitPress, emitRelease, click, dblClick, tripleClick };
|
|
8
15
|
//# sourceMappingURL=click.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../src/user-event/click.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAuBpC,QAAA,MAAM,SAAS,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,aAAa,GAAG,CAAC,YAAY,EAAE,EAAE,QAAQ,MAAM,KAAG,IAExF,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,aAAa,GAAG,CAAC,YAAY,EAAE,EAAE,QAAQ,MAAM,KAAG,IAE1F,CAAC;AAwCF,QAAA,MAAM,KAAK,GAAU,QAAQ,GAAG,CAAC,MAAM,KAAG,OAAO,CAAC,IAAI,CAwBrD,CAAC;AAEF,QAAA,MAAM,QAAQ,GAAI,QAAQ,GAAG,CAAC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAyC,CAAC;AAC7F,QAAA,MAAM,WAAW,GAAI,QAAQ,GAAG,CAAC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAyC,CAAC;AAEhG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"click.d.ts","sourceRoot":"","sources":["../../src/user-event/click.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAuBpC,QAAA,MAAM,SAAS,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,aAAa,GAAG,CAAC,YAAY,EAAE,EAAE,QAAQ,MAAM,KAAG,IAExF,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,aAAa,GAAG,CAAC,YAAY,EAAE,EAAE,QAAQ,MAAM,KAAG,IAE1F,CAAC;AAwCF;;;;GAIG;AACH,QAAA,MAAM,KAAK,GAAU,QAAQ,GAAG,CAAC,MAAM,KAAG,OAAO,CAAC,IAAI,CAwBrD,CAAC;AAEF,0GAA0G;AAC1G,QAAA,MAAM,QAAQ,GAAI,QAAQ,GAAG,CAAC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAyC,CAAC;AAC7F,4GAA4G;AAC5G,QAAA,MAAM,WAAW,GAAI,QAAQ,GAAG,CAAC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAyC,CAAC;AAEhG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/user-event/click.js
CHANGED
|
@@ -48,6 +48,11 @@ const tryActivate = async (widget) => {
|
|
|
48
48
|
});
|
|
49
49
|
return isActivated;
|
|
50
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Presses and releases a Gtk.Button, flips a Gtk.Switch, and otherwise activates the widget,
|
|
53
|
+
* falling back to a click gesture on the nearest Gtk.Button or click-gesture ancestor when
|
|
54
|
+
* activation does nothing. A widget with the label role is never activated.
|
|
55
|
+
*/
|
|
51
56
|
const click = async (widget) => {
|
|
52
57
|
if (widget instanceof Gtk.Button) {
|
|
53
58
|
await emitClickSequence(widget, widget, 1);
|
|
@@ -67,7 +72,9 @@ const click = async (widget) => {
|
|
|
67
72
|
await emitClickSequence(widget, target, 1);
|
|
68
73
|
}
|
|
69
74
|
};
|
|
75
|
+
/** Emits a two-press click gesture at the widget's center, adding a Gtk.GestureClick when it has none. */
|
|
70
76
|
const dblClick = (widget) => emitClickSequence(widget, widget, 2);
|
|
77
|
+
/** Emits a three-press click gesture at the widget's center, adding a Gtk.GestureClick when it has none. */
|
|
71
78
|
const tripleClick = (widget) => emitClickSequence(widget, widget, 3);
|
|
72
79
|
export { emitPress, emitRelease, click, dblClick, tripleClick };
|
|
73
80
|
//# sourceMappingURL=click.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"click.js","sourceR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C,CAAC;IAEH,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,KAAK,EAAE,MAAkB,EAAiB,EAAE;IACtD,IAAI,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAE3C,OAAO;IACX,CAAC;IAED,IAAI,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE;YACzB,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,OAAO;IACX,CAAC;IAED,IAAI,MAAM,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO;IACX,CAAC;IAED,MAAM,MAAM,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAE7C,IAAI,MAAM,EAAE,CAAC;QACT,MAAM,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,MAAkB,EAAiB,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AAC7F,MAAM,WAAW,GAAG,CAAC,MAAkB,EAAiB,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AAEhG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\nimport { getOrCreateControllers, queryController } from \"./controller.js\";\nimport { wrapEvent } from \"./event-wrapper.js\";\n\nconst getPressPoint = (widget: Gtk.Widget): { x: number; y: number } => {\n const width = widget.getWidth();\n const height = widget.getHeight();\n\n if (width > 0 && height > 0) {\n return { x: width / 2, y: height / 2 };\n }\n\n return { x: 0, y: 0 };\n};\n\nconst emitGesture = (widget: Gtk.Widget, controllers: Gtk.GestureClick[], nPress: number, signal: string): void => {\n const { x, y } = getPressPoint(widget);\n\n for (const controller of controllers) {\n controller.emit(signal, nPress, x, y);\n }\n};\n\nconst emitPress = (widget: Gtk.Widget, controllers: Gtk.GestureClick[], nPress: number): void => {\n emitGesture(widget, controllers, nPress, \"pressed\");\n};\n\nconst emitRelease = (widget: Gtk.Widget, controllers: Gtk.GestureClick[], nPress: number): void => {\n emitGesture(widget, controllers, nPress, \"released\");\n};\n\nconst emitClickSequence = (widget: Gtk.Widget, target: Gtk.Widget, nPress: number): Promise<void> =>\n wrapEvent(widget, () => {\n const controllers = getOrCreateControllers(target, Gtk.GestureClick);\n\n for (let i = 1; i <= nPress; i++) {\n emitPress(target, controllers, i);\n emitRelease(target, controllers, i);\n }\n });\n\nconst findClickableAncestor = (widget: Gtk.Widget): Gtk.Widget | null => {\n let current = widget.getParent();\n\n while (current) {\n if (current instanceof Gtk.Button || queryController(current, Gtk.GestureClick) !== null) {\n return current;\n }\n\n current = current.getParent();\n }\n\n return null;\n};\n\nconst tryActivate = async (widget: Gtk.Widget): Promise<boolean> => {\n if (widget.getAccessibleRole() === Gtk.AccessibleRole.LABEL) {\n return false;\n }\n\n let isActivated = false;\n\n await wrapEvent(widget, () => {\n isActivated = widget.activate();\n });\n\n return isActivated;\n};\n\nconst click = async (widget: Gtk.Widget): Promise<void> => {\n if (widget instanceof Gtk.Button) {\n await emitClickSequence(widget, widget, 1);\n\n return;\n }\n\n if (widget instanceof Gtk.Switch) {\n await wrapEvent(widget, () => {\n widget.setActive(!widget.getActive());\n });\n\n return;\n }\n\n if (await tryActivate(widget)) {\n return;\n }\n\n const target = findClickableAncestor(widget);\n\n if (target) {\n await emitClickSequence(widget, target, 1);\n }\n};\n\nconst dblClick = (widget: Gtk.Widget): Promise<void> => emitClickSequence(widget, widget, 2);\nconst tripleClick = (widget: Gtk.Widget): Promise<void> => emitClickSequence(widget, widget, 3);\n\nexport { emitPress, emitRelease, click, dblClick, tripleClick };\n"]}
|
|
1
|
+
{"version":3,"file":"click.js","sourceRoot":"","sources":["../../src/user-event/click.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,MAAM,aAAa,GAAG,CAAC,MAAkB,EAA4B,EAAE;IACnE,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAElC,IAAI,KAAK,GAAG,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;IAC3C,CAAC;IAED,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,MAAkB,EAAE,WAA+B,EAAE,MAAc,EAAE,MAAc,EAAQ,EAAE;IAC9G,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAEvC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACnC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,MAAkB,EAAE,WAA+B,EAAE,MAAc,EAAQ,EAAE;IAC5F,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE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AAE,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\nimport { getOrCreateControllers, queryController } from \"./controller.js\";\nimport { wrapEvent } from \"./event-wrapper.js\";\n\nconst getPressPoint = (widget: Gtk.Widget): { x: number; y: number } => {\n const width = widget.getWidth();\n const height = widget.getHeight();\n\n if (width > 0 && height > 0) {\n return { x: width / 2, y: height / 2 };\n }\n\n return { x: 0, y: 0 };\n};\n\nconst emitGesture = (widget: Gtk.Widget, controllers: Gtk.GestureClick[], nPress: number, signal: string): void => {\n const { x, y } = getPressPoint(widget);\n\n for (const controller of controllers) {\n controller.emit(signal, nPress, x, y);\n }\n};\n\nconst emitPress = (widget: Gtk.Widget, controllers: Gtk.GestureClick[], nPress: number): void => {\n emitGesture(widget, controllers, nPress, \"pressed\");\n};\n\nconst emitRelease = (widget: Gtk.Widget, controllers: Gtk.GestureClick[], nPress: number): void => {\n emitGesture(widget, controllers, nPress, \"released\");\n};\n\nconst emitClickSequence = (widget: Gtk.Widget, target: Gtk.Widget, nPress: number): Promise<void> =>\n wrapEvent(widget, () => {\n const controllers = getOrCreateControllers(target, Gtk.GestureClick);\n\n for (let i = 1; i <= nPress; i++) {\n emitPress(target, controllers, i);\n emitRelease(target, controllers, i);\n }\n });\n\nconst findClickableAncestor = (widget: Gtk.Widget): Gtk.Widget | null => {\n let current = widget.getParent();\n\n while (current) {\n if (current instanceof Gtk.Button || queryController(current, Gtk.GestureClick) !== null) {\n return current;\n }\n\n current = current.getParent();\n }\n\n return null;\n};\n\nconst tryActivate = async (widget: Gtk.Widget): Promise<boolean> => {\n if (widget.getAccessibleRole() === Gtk.AccessibleRole.LABEL) {\n return false;\n }\n\n let isActivated = false;\n\n await wrapEvent(widget, () => {\n isActivated = widget.activate();\n });\n\n return isActivated;\n};\n\n/**\n * Presses and releases a Gtk.Button, flips a Gtk.Switch, and otherwise activates the widget,\n * falling back to a click gesture on the nearest Gtk.Button or click-gesture ancestor when\n * activation does nothing. A widget with the label role is never activated.\n */\nconst click = async (widget: Gtk.Widget): Promise<void> => {\n if (widget instanceof Gtk.Button) {\n await emitClickSequence(widget, widget, 1);\n\n return;\n }\n\n if (widget instanceof Gtk.Switch) {\n await wrapEvent(widget, () => {\n widget.setActive(!widget.getActive());\n });\n\n return;\n }\n\n if (await tryActivate(widget)) {\n return;\n }\n\n const target = findClickableAncestor(widget);\n\n if (target) {\n await emitClickSequence(widget, target, 1);\n }\n};\n\n/** Emits a two-press click gesture at the widget's center, adding a Gtk.GestureClick when it has none. */\nconst dblClick = (widget: Gtk.Widget): Promise<void> => emitClickSequence(widget, widget, 2);\n/** Emits a three-press click gesture at the widget's center, adding a Gtk.GestureClick when it has none. */\nconst tripleClick = (widget: Gtk.Widget): Promise<void> => emitClickSequence(widget, widget, 3);\n\nexport { emitPress, emitRelease, click, dblClick, tripleClick };\n"]}
|
|
@@ -1,8 +1,38 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
/** An event controller class that can be constructed without arguments, such as `Gtk.GestureClick`. */
|
|
2
3
|
type ControllerConstructor<T extends Gtk.EventController> = new () => T;
|
|
4
|
+
/**
|
|
5
|
+
* Returns every controller of the given type attached to a widget, in the order GTK4 reports them.
|
|
6
|
+
*
|
|
7
|
+
* @param widget The widget whose controllers are inspected.
|
|
8
|
+
* @param controllerType The controller class to match.
|
|
9
|
+
* @returns The matching controllers, or an empty array when the widget has none.
|
|
10
|
+
*/
|
|
3
11
|
declare const queryAllControllers: <T extends Gtk.EventController>(widget: Gtk.Widget, controllerType: ControllerConstructor<T>) => T[];
|
|
12
|
+
/**
|
|
13
|
+
* Returns the first controller of the given type attached to a widget.
|
|
14
|
+
*
|
|
15
|
+
* @param widget The widget whose controllers are inspected.
|
|
16
|
+
* @param controllerType The controller class to match.
|
|
17
|
+
* @returns The first matching controller, or null when the widget has none.
|
|
18
|
+
*/
|
|
4
19
|
declare const queryController: <T extends Gtk.EventController>(widget: Gtk.Widget, controllerType: ControllerConstructor<T>) => T | null;
|
|
20
|
+
/**
|
|
21
|
+
* Returns every controller of the given type attached to a widget.
|
|
22
|
+
*
|
|
23
|
+
* @param widget The widget whose controllers are inspected.
|
|
24
|
+
* @param controllerType The controller class to match.
|
|
25
|
+
* @throws When the widget has no controller of that type.
|
|
26
|
+
*/
|
|
5
27
|
declare const getAllControllers: <T extends Gtk.EventController>(widget: Gtk.Widget, controllerType: ControllerConstructor<T>) => T[];
|
|
28
|
+
/**
|
|
29
|
+
* Returns the first controller of the given type attached to a widget.
|
|
30
|
+
*
|
|
31
|
+
* @param widget The widget whose controllers are inspected.
|
|
32
|
+
* @param controllerType The controller class to match.
|
|
33
|
+
* @throws When the widget has no controller of that type.
|
|
34
|
+
*/
|
|
35
|
+
declare const getController: <T extends Gtk.EventController>(widget: Gtk.Widget, controllerType: ControllerConstructor<T>) => T;
|
|
6
36
|
declare const getOrCreateControllers: <T extends Gtk.EventController>(widget: Gtk.Widget, controllerType: ControllerConstructor<T>) => T[];
|
|
7
|
-
export { queryAllControllers, queryController, getAllControllers, getOrCreateControllers, type ControllerConstructor };
|
|
37
|
+
export { queryAllControllers, queryController, getAllControllers, getController, getOrCreateControllers, type ControllerConstructor, };
|
|
8
38
|
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/user-event/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AAEzC,KAAK,qBAAqB,CAAC,CAAC,SAAS,GAAG,CAAC,eAAe,IAAI,UAAU,CAAC,CAAC;AAExE,QAAA,MAAM,mBAAmB,GAAI,CAAC,SAAS,GAAG,CAAC,eAAe,EACtD,QAAQ,GAAG,CAAC,MAAM,EAClB,gBAAgB,qBAAqB,CAAC,CAAC,CAAC,KACzC,CAAC,EAcH,CAAC;AAEF,QAAA,MAAM,eAAe,GAAI,CAAC,SAAS,GAAG,CAAC,eAAe,EAClD,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I,CAAC,SAAS,GAAG,CAAC,eAAe,EAChD,QAAQ,GAAG,CAAC,MAAM,EAClB,gBAAgB,qBAAqB,CAAC,CAAC,CAAC,KACzC,CAQF,CAAC;AAEF,QAAA,MAAM,sBAAsB,GAAI,CAAC,SAAS,GAAG,CAAC,eAAe,EACzD,QAAQ,GAAG,CAAC,MAAM,EAClB,gBAAgB,qBAAqB,CAAC,CAAC,CAAC,KACzC,CAAC,EAWH,CAAC;AAEF,OAAO,EACH,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,sBAAsB,EACtB,KAAK,qBAAqB,GAC7B,CAAC"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns every controller of the given type attached to a widget, in the order GTK4 reports them.
|
|
3
|
+
*
|
|
4
|
+
* @param widget The widget whose controllers are inspected.
|
|
5
|
+
* @param controllerType The controller class to match.
|
|
6
|
+
* @returns The matching controllers, or an empty array when the widget has none.
|
|
7
|
+
*/
|
|
1
8
|
const queryAllControllers = (widget, controllerType) => {
|
|
2
9
|
const controllers = widget.observeControllers();
|
|
3
10
|
const nItems = controllers.getNItems();
|
|
@@ -10,7 +17,21 @@ const queryAllControllers = (widget, controllerType) => {
|
|
|
10
17
|
}
|
|
11
18
|
return matches;
|
|
12
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Returns the first controller of the given type attached to a widget.
|
|
22
|
+
*
|
|
23
|
+
* @param widget The widget whose controllers are inspected.
|
|
24
|
+
* @param controllerType The controller class to match.
|
|
25
|
+
* @returns The first matching controller, or null when the widget has none.
|
|
26
|
+
*/
|
|
13
27
|
const queryController = (widget, controllerType) => queryAllControllers(widget, controllerType)[0] ?? null;
|
|
28
|
+
/**
|
|
29
|
+
* Returns every controller of the given type attached to a widget.
|
|
30
|
+
*
|
|
31
|
+
* @param widget The widget whose controllers are inspected.
|
|
32
|
+
* @param controllerType The controller class to match.
|
|
33
|
+
* @throws When the widget has no controller of that type.
|
|
34
|
+
*/
|
|
14
35
|
const getAllControllers = (widget, controllerType) => {
|
|
15
36
|
const controllers = queryAllControllers(widget, controllerType);
|
|
16
37
|
if (controllers.length === 0) {
|
|
@@ -18,6 +39,20 @@ const getAllControllers = (widget, controllerType) => {
|
|
|
18
39
|
}
|
|
19
40
|
return controllers;
|
|
20
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Returns the first controller of the given type attached to a widget.
|
|
44
|
+
*
|
|
45
|
+
* @param widget The widget whose controllers are inspected.
|
|
46
|
+
* @param controllerType The controller class to match.
|
|
47
|
+
* @throws When the widget has no controller of that type.
|
|
48
|
+
*/
|
|
49
|
+
const getController = (widget, controllerType) => {
|
|
50
|
+
const [controller] = getAllControllers(widget, controllerType);
|
|
51
|
+
if (controller === undefined) {
|
|
52
|
+
throw new Error(`No ${controllerType.name} controller is attached to the widget`);
|
|
53
|
+
}
|
|
54
|
+
return controller;
|
|
55
|
+
};
|
|
21
56
|
const getOrCreateControllers = (widget, controllerType) => {
|
|
22
57
|
const existing = queryAllControllers(widget, controllerType);
|
|
23
58
|
if (existing.length > 0) {
|
|
@@ -27,5 +62,5 @@ const getOrCreateControllers = (widget, controllerType) => {
|
|
|
27
62
|
widget.addController(controller);
|
|
28
63
|
return [controller];
|
|
29
64
|
};
|
|
30
|
-
export { queryAllControllers, queryController, getAllControllers, getOrCreateControllers };
|
|
65
|
+
export { queryAllControllers, queryController, getAllControllers, getController, getOrCreateControllers, };
|
|
31
66
|
//# sourceMappingURL=controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/user-event/controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/user-event/controller.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CACxB,MAAkB,EAClB,cAAwC,EACrC,EAAE;IACL,MAAM,WAAW,GAAG,MAAM,CAAC,kBAAkB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CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAC3B,MAAkB,EAClB,cAAwC,EACrC,EAAE;IACL,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAE7D,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,cAAc,EAAE,CAAC;IACxC,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAEjC,OAAO,CAAC,UAAU,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF,OAAO,EACH,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,sBAAsB,GAEzB,CAAC","sourcesContent":["import type * as Gtk from \"@gtkx/gi/gtk\";\n\n/** An event controller class that can be constructed without arguments, such as `Gtk.GestureClick`. */\ntype ControllerConstructor<T extends Gtk.EventController> = new () => T;\n\n/**\n * Returns every controller of the given type attached to a widget, in the order GTK4 reports them.\n *\n * @param widget The widget whose controllers are inspected.\n * @param controllerType The controller class to match.\n * @returns The matching controllers, or an empty array when the widget has none.\n */\nconst queryAllControllers = <T extends Gtk.EventController>(\n widget: Gtk.Widget,\n controllerType: ControllerConstructor<T>,\n): T[] => {\n const controllers = widget.observeControllers();\n const nItems = controllers.getNItems();\n const matches: T[] = [];\n\n for (let i = 0; i < nItems; i++) {\n const controller = controllers.getItem(i);\n\n if (controller instanceof controllerType) {\n matches.push(controller);\n }\n }\n\n return matches;\n};\n\n/**\n * Returns the first controller of the given type attached to a widget.\n *\n * @param widget The widget whose controllers are inspected.\n * @param controllerType The controller class to match.\n * @returns The first matching controller, or null when the widget has none.\n */\nconst queryController = <T extends Gtk.EventController>(\n widget: Gtk.Widget,\n controllerType: ControllerConstructor<T>,\n): T | null => queryAllControllers(widget, controllerType)[0] ?? null;\n\n/**\n * Returns every controller of the given type attached to a widget.\n *\n * @param widget The widget whose controllers are inspected.\n * @param controllerType The controller class to match.\n * @throws When the widget has no controller of that type.\n */\nconst getAllControllers = <T extends Gtk.EventController>(\n widget: Gtk.Widget,\n controllerType: ControllerConstructor<T>,\n): T[] => {\n const controllers = queryAllControllers(widget, controllerType);\n\n if (controllers.length === 0) {\n throw new Error(`No ${controllerType.name} controller is attached to the widget`);\n }\n\n return controllers;\n};\n\n/**\n * Returns the first controller of the given type attached to a widget.\n *\n * @param widget The widget whose controllers are inspected.\n * @param controllerType The controller class to match.\n * @throws When the widget has no controller of that type.\n */\nconst getController = <T extends Gtk.EventController>(\n widget: Gtk.Widget,\n controllerType: ControllerConstructor<T>,\n): T => {\n const [controller] = getAllControllers(widget, controllerType);\n\n if (controller === undefined) {\n throw new Error(`No ${controllerType.name} controller is attached to the widget`);\n }\n\n return controller;\n};\n\nconst getOrCreateControllers = <T extends Gtk.EventController>(\n widget: Gtk.Widget,\n controllerType: ControllerConstructor<T>,\n): T[] => {\n const existing = queryAllControllers(widget, controllerType);\n\n if (existing.length > 0) {\n return existing;\n }\n\n const controller = new controllerType();\n widget.addController(controller);\n\n return [controller];\n};\n\nexport {\n queryAllControllers,\n queryController,\n getAllControllers,\n getController,\n getOrCreateControllers,\n type ControllerConstructor,\n};\n"]}
|