@gtkx/testing 1.0.0-rc.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -9
- package/dist/accessible-native.d.ts +16 -0
- package/dist/accessible-native.d.ts.map +1 -0
- package/dist/accessible-native.js +206 -0
- package/dist/accessible-native.js.map +1 -0
- package/dist/act.d.ts +2 -0
- package/dist/act.d.ts.map +1 -1
- package/dist/act.js.map +1 -1
- package/dist/build-queries.d.ts +27 -10
- package/dist/build-queries.d.ts.map +1 -1
- package/dist/build-queries.js +39 -30
- package/dist/build-queries.js.map +1 -1
- package/dist/cleanup-registry.d.ts +1 -1
- package/dist/cleanup-registry.d.ts.map +1 -1
- package/dist/cleanup-registry.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.d.ts +10 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +12 -3
- package/dist/errors.js.map +1 -1
- package/dist/fire-event.d.ts +35 -6
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +23 -7
- package/dist/fire-event.js.map +1 -1
- package/dist/frame-sync.d.ts +2 -1
- package/dist/frame-sync.d.ts.map +1 -1
- package/dist/frame-sync.js +15 -5
- package/dist/frame-sync.js.map +1 -1
- package/dist/harness-window.d.ts +4 -0
- package/dist/harness-window.d.ts.map +1 -0
- package/dist/harness-window.js +6 -0
- package/dist/harness-window.js.map +1 -0
- package/dist/index.d.ts +14 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +4 -0
- package/dist/internal.js.map +1 -0
- package/dist/matchers.d.ts +125 -39
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +156 -18
- package/dist/matchers.js.map +1 -1
- package/dist/pretty-format.d.ts +2 -0
- package/dist/pretty-format.d.ts.map +1 -0
- package/dist/pretty-format.js +2 -0
- package/dist/pretty-format.js.map +1 -0
- package/dist/pretty-widget.d.ts +7 -3
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +74 -57
- package/dist/pretty-widget.js.map +1 -1
- package/dist/production.d.ts +8 -0
- package/dist/production.d.ts.map +1 -0
- package/dist/production.js +34 -0
- package/dist/production.js.map +1 -0
- package/dist/queries.d.ts +99 -56
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +123 -83
- package/dist/queries.js.map +1 -1
- package/dist/query-helpers.d.ts +44 -0
- package/dist/query-helpers.d.ts.map +1 -0
- package/dist/query-helpers.js +57 -0
- package/dist/query-helpers.js.map +1 -0
- package/dist/render-children.d.ts +9 -0
- package/dist/render-children.d.ts.map +1 -0
- package/dist/render-children.js +11 -0
- package/dist/render-children.js.map +1 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +13 -11
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts +12 -3
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-helpers.js +13 -4
- package/dist/role-helpers.js.map +1 -1
- package/dist/role-naming.d.ts +5 -0
- package/dist/role-naming.d.ts.map +1 -0
- package/dist/role-naming.js +96 -0
- package/dist/role-naming.js.map +1 -0
- package/dist/screenshot.d.ts +12 -20
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +183 -91
- package/dist/screenshot.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 +9 -1
- package/dist/traversal.d.ts.map +1 -1
- package/dist/traversal.js +26 -6
- package/dist/traversal.js.map +1 -1
- package/dist/types.d.ts +67 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-event/adjustment.d.ts +16 -0
- package/dist/user-event/adjustment.d.ts.map +1 -1
- package/dist/user-event/adjustment.js +34 -2
- package/dist/user-event/adjustment.js.map +1 -1
- package/dist/user-event/click.d.ts +45 -3
- package/dist/user-event/click.d.ts.map +1 -1
- package/dist/user-event/click.js +177 -39
- package/dist/user-event/click.js.map +1 -1
- package/dist/user-event/column-header-click.d.ts +4 -0
- package/dist/user-event/column-header-click.d.ts.map +1 -0
- package/dist/user-event/column-header-click.js +65 -0
- package/dist/user-event/column-header-click.js.map +1 -0
- package/dist/user-event/controller.d.ts +29 -0
- package/dist/user-event/controller.d.ts.map +1 -1
- package/dist/user-event/controller.js +28 -0
- package/dist/user-event/controller.js.map +1 -1
- package/dist/user-event/event-wrapper.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.js +2 -1
- package/dist/user-event/event-wrapper.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 +70 -2
- package/dist/user-event/index.d.ts.map +1 -1
- package/dist/user-event/index.js +43 -26
- package/dist/user-event/index.js.map +1 -1
- package/dist/user-event/indexed-children.d.ts +10 -0
- package/dist/user-event/indexed-children.d.ts.map +1 -0
- package/dist/user-event/indexed-children.js +50 -0
- package/dist/user-event/indexed-children.js.map +1 -0
- 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 +46 -16
- package/dist/user-event/keyboard.js.map +1 -1
- package/dist/user-event/list-row-click.d.ts +4 -0
- package/dist/user-event/list-row-click.d.ts.map +1 -0
- package/dist/user-event/list-row-click.js +39 -0
- package/dist/user-event/list-row-click.js.map +1 -0
- package/dist/user-event/native-click.d.ts +6 -0
- package/dist/user-event/native-click.d.ts.map +1 -0
- package/dist/user-event/native-click.js +32 -0
- package/dist/user-event/native-click.js.map +1 -0
- package/dist/user-event/pointer.d.ts +1 -1
- package/dist/user-event/pointer.d.ts.map +1 -1
- package/dist/user-event/pointer.js +37 -13
- package/dist/user-event/pointer.js.map +1 -1
- package/dist/user-event/selection.d.ts +18 -0
- package/dist/user-event/selection.d.ts.map +1 -1
- package/dist/user-event/selection.js +56 -30
- 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 +34 -3
- package/dist/user-event/text.d.ts.map +1 -1
- package/dist/user-event/text.js +94 -17
- 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 +14 -10
- package/dist/widget-accessible-properties.d.ts.map +1 -1
- package/dist/widget-accessible-properties.js +135 -173
- package/dist/widget-accessible-properties.js.map +1 -1
- package/dist/widget-getters.d.ts +8 -0
- package/dist/widget-getters.d.ts.map +1 -0
- package/dist/widget-getters.js +19 -0
- package/dist/widget-getters.js.map +1 -0
- package/dist/within.d.ts +3 -2
- package/dist/within.d.ts.map +1 -1
- package/dist/within.js +3 -2
- package/dist/within.js.map +1 -1
- package/package.json +13 -8
- package/src/accessible-native.ts +333 -0
- package/src/act.ts +2 -0
- package/src/build-queries.ts +66 -48
- package/src/cleanup-registry.ts +1 -1
- package/src/config.ts +4 -3
- package/src/errors.ts +14 -3
- package/src/fire-event.ts +61 -8
- package/src/frame-sync.ts +21 -5
- package/src/harness-window.ts +9 -0
- package/src/index.ts +18 -11
- package/src/internal.ts +11 -0
- package/src/matchers.ts +466 -64
- package/src/pretty-format.ts +1 -0
- package/src/pretty-widget.ts +100 -72
- package/src/production.ts +52 -0
- package/src/queries.ts +128 -89
- package/src/query-helpers.ts +97 -0
- package/src/render-children.ts +25 -0
- package/src/render.tsx +18 -13
- package/src/role-helpers.ts +14 -4
- package/src/role-naming.ts +99 -0
- package/src/screenshot.ts +272 -103
- package/src/suggestions.ts +3 -0
- package/src/traversal.ts +49 -6
- package/src/types.ts +69 -19
- package/src/user-event/adjustment.ts +42 -2
- package/src/user-event/click.ts +248 -46
- package/src/user-event/column-header-click.ts +90 -0
- package/src/user-event/controller.ts +29 -0
- package/src/user-event/event-wrapper.ts +3 -1
- package/src/user-event/gesture.ts +57 -6
- package/src/user-event/index.ts +119 -29
- package/src/user-event/indexed-children.ts +75 -0
- package/src/user-event/keyboard.ts +70 -20
- package/src/user-event/list-row-click.ts +57 -0
- package/src/user-event/native-click.ts +46 -0
- package/src/user-event/pointer.ts +52 -13
- package/src/user-event/selection.ts +74 -33
- package/src/user-event/state.ts +2 -2
- package/src/user-event/text.ts +121 -23
- package/src/wait-for.ts +2 -0
- package/src/widget-accessible-properties.ts +183 -214
- package/src/widget-getters.ts +32 -0
- package/src/within.ts +3 -2
package/dist/user-event/click.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import * as Gdk from "@gtkx/gi/gdk";
|
|
1
2
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
-
import {
|
|
3
|
+
import { hasSignalListener } from "@gtkx/runtime/internal";
|
|
4
|
+
import { callBooleanGetter, getCallableMethod, hasWidgetMethod } from "../widget-getters.js";
|
|
5
|
+
import { queryAllControllers } from "./controller.js";
|
|
3
6
|
import { wrapEvent } from "./event-wrapper.js";
|
|
4
|
-
|
|
7
|
+
import { hasIndexedChildren, selectContainerChild, SELECTED_PROBE, unselectOtherChildren } from "./indexed-children.js";
|
|
8
|
+
import { isClickTransparent, nativeClickFor } from "./native-click.js";
|
|
9
|
+
const CLICK_SIGNALS = ["pressed", "released"];
|
|
10
|
+
const PRIMARY_BUTTONS = new Set([0, Gdk.BUTTON_PRIMARY]);
|
|
11
|
+
const getCenterPoint = (widget) => {
|
|
5
12
|
const width = widget.getWidth();
|
|
6
13
|
const height = widget.getHeight();
|
|
7
14
|
if (width > 0 && height > 0) {
|
|
@@ -9,35 +16,139 @@ const getPressPoint = (widget) => {
|
|
|
9
16
|
}
|
|
10
17
|
return { x: 0, y: 0 };
|
|
11
18
|
};
|
|
12
|
-
const
|
|
13
|
-
|
|
19
|
+
const getClickPoint = (clicked, carrier) => {
|
|
20
|
+
if (clicked === carrier) {
|
|
21
|
+
return getCenterPoint(clicked);
|
|
22
|
+
}
|
|
23
|
+
const [isComputed, bounds] = clicked.computeBounds(carrier);
|
|
24
|
+
if (!isComputed) {
|
|
25
|
+
return getCenterPoint(carrier);
|
|
26
|
+
}
|
|
27
|
+
return { x: bounds.getX() + bounds.getWidth() / 2, y: bounds.getY() + bounds.getHeight() / 2 };
|
|
28
|
+
};
|
|
29
|
+
const emitGesture = (point, controllers, nPress, signal) => {
|
|
14
30
|
for (const controller of controllers) {
|
|
15
|
-
controller.emit(signal, nPress, x, y);
|
|
31
|
+
controller.emit(signal, nPress, point.x, point.y);
|
|
16
32
|
}
|
|
17
33
|
};
|
|
18
|
-
const
|
|
19
|
-
emitGesture(widget, controllers, nPress,
|
|
34
|
+
const emitClickPhase = (widget, controllers, nPress, phase) => {
|
|
35
|
+
emitGesture(getCenterPoint(widget), controllers, nPress, phase);
|
|
20
36
|
};
|
|
21
|
-
const
|
|
22
|
-
|
|
37
|
+
const emitSitePhase = (sites, nPress, phase) => {
|
|
38
|
+
for (const site of sites) {
|
|
39
|
+
emitGesture(site.point, site.gestures, nPress, phase);
|
|
40
|
+
}
|
|
23
41
|
};
|
|
24
|
-
const emitClickSequence = (
|
|
25
|
-
const controllers = getOrCreateControllers(target, Gtk.GestureClick);
|
|
42
|
+
const emitClickSequence = (sites, nPress) => {
|
|
26
43
|
for (let i = 1; i <= nPress; i++) {
|
|
27
|
-
|
|
28
|
-
|
|
44
|
+
emitSitePhase(sites, i, "pressed");
|
|
45
|
+
emitSitePhase(sites, i, "released");
|
|
29
46
|
}
|
|
30
|
-
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
47
|
+
};
|
|
48
|
+
const containerFor = (widget) => {
|
|
49
|
+
const parent = widget.getParent();
|
|
50
|
+
return parent !== null && hasWidgetMethod(widget, SELECTED_PROBE) && hasIndexedChildren(parent) ? parent : null;
|
|
51
|
+
};
|
|
52
|
+
const hasClickHandlers = (gesture) => hasSignalListener(gesture, CLICK_SIGNALS);
|
|
53
|
+
const isInternalGesture = (gesture) => !hasSignalListener(gesture);
|
|
54
|
+
const isPrimaryGesture = (gesture) => PRIMARY_BUTTONS.has(gesture.getButton());
|
|
55
|
+
const clickGestures = (widget) => queryAllControllers(widget, Gtk.GestureClick).filter((gesture) => isPrimaryGesture(gesture));
|
|
56
|
+
const getAuthoredClickGestures = (widget) => clickGestures(widget).filter((gesture) => hasClickHandlers(gesture));
|
|
57
|
+
const isClaimingTarget = (widget) => widget instanceof Gtk.Button || containerFor(widget) !== null;
|
|
58
|
+
const gestureTargetFor = (widget, isInternalAllowed) => {
|
|
59
|
+
const gestures = clickGestures(widget);
|
|
60
|
+
if (isClaimingTarget(widget)) {
|
|
61
|
+
return { widget, container: containerFor(widget), gestures, isClaiming: true, native: null };
|
|
62
|
+
}
|
|
63
|
+
const authored = gestures.filter((gesture) => hasClickHandlers(gesture));
|
|
64
|
+
if (authored.length > 0) {
|
|
65
|
+
return { widget, container: null, gestures: authored, isClaiming: false, native: null };
|
|
66
|
+
}
|
|
67
|
+
if (isInternalAllowed && gestures.some((gesture) => isInternalGesture(gesture))) {
|
|
68
|
+
return { widget, container: null, gestures, isClaiming: true, native: null };
|
|
38
69
|
}
|
|
39
70
|
return null;
|
|
40
71
|
};
|
|
72
|
+
const clickTargetFor = (widget, scope) => {
|
|
73
|
+
if (isClickTransparent(widget)) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const native = nativeClickFor(widget, scope.isClicked);
|
|
77
|
+
if (native !== null) {
|
|
78
|
+
return { widget, container: null, gestures: getAuthoredClickGestures(widget), isClaiming: true, native };
|
|
79
|
+
}
|
|
80
|
+
return gestureTargetFor(widget, scope.isInternalAllowed);
|
|
81
|
+
};
|
|
82
|
+
const isSelfClickTarget = (widget) => isClickTransparent(widget) || clickTargetFor(widget, { isClicked: true, isInternalAllowed: false }) !== null;
|
|
83
|
+
const nextClickWidget = (current, target) => target?.isClaiming === true ? null : current.getParent();
|
|
84
|
+
const collectClickTargets = (widget) => {
|
|
85
|
+
const targets = [];
|
|
86
|
+
let current = widget;
|
|
87
|
+
while (current !== null) {
|
|
88
|
+
const isClicked = current === widget;
|
|
89
|
+
const scope = { isClicked, isInternalAllowed: !isClicked && targets.length === 0 };
|
|
90
|
+
const target = clickTargetFor(current, scope);
|
|
91
|
+
const next = nextClickWidget(current, target);
|
|
92
|
+
if (target !== null) {
|
|
93
|
+
targets.push(target);
|
|
94
|
+
}
|
|
95
|
+
current = next;
|
|
96
|
+
}
|
|
97
|
+
return targets;
|
|
98
|
+
};
|
|
99
|
+
const targetSites = (clicked, target) => {
|
|
100
|
+
const { container } = target;
|
|
101
|
+
const site = { gestures: target.gestures, point: getClickPoint(clicked, target.widget) };
|
|
102
|
+
if (container === null) {
|
|
103
|
+
return [site];
|
|
104
|
+
}
|
|
105
|
+
return [site, { gestures: getAuthoredClickGestures(container), point: getClickPoint(clicked, container) }];
|
|
106
|
+
};
|
|
107
|
+
const isSingleClickActivating = (container) => callBooleanGetter(container, "getActivateOnSingleClick") ?? true;
|
|
108
|
+
const isMultipleSelection = (container) => getCallableMethod(container, "getSelectionMode")?.() === Gtk.SelectionMode.MULTIPLE;
|
|
109
|
+
const isChildSelectable = (child) => callBooleanGetter(child, "getSelectable") ?? true;
|
|
110
|
+
const replaceContainerSelection = (container, child) => {
|
|
111
|
+
if (!isChildSelectable(child)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
selectContainerChild(container, child);
|
|
115
|
+
if (isMultipleSelection(container)) {
|
|
116
|
+
unselectOtherChildren(container, child);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const isActivatedByClick = (container, nPress) => isSingleClickActivating(container) || nPress > 1;
|
|
120
|
+
const isSelectionReplacedByClick = (container, nPress) => nPress > 1 || !isSingleClickActivating(container);
|
|
121
|
+
const applyContainerOutcome = (target, nPress) => {
|
|
122
|
+
const { container, widget } = target;
|
|
123
|
+
if (container === null || widget.getParent() !== container) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (isActivatedByClick(container, nPress)) {
|
|
127
|
+
widget.activate();
|
|
128
|
+
}
|
|
129
|
+
if (isSelectionReplacedByClick(container, nPress)) {
|
|
130
|
+
replaceContainerSelection(container, widget);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const applyClickOutcome = (target, nPress) => {
|
|
134
|
+
if (target.native === null) {
|
|
135
|
+
applyContainerOutcome(target, nPress);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
target.native(target.widget, nPress);
|
|
139
|
+
};
|
|
140
|
+
const applyClickOutcomes = (targets, nPress) => {
|
|
141
|
+
for (const target of targets) {
|
|
142
|
+
applyClickOutcome(target, nPress);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const deliverClick = (widget, nPress) => wrapEvent(widget, () => {
|
|
146
|
+
const targets = collectClickTargets(widget);
|
|
147
|
+
const sites = targets.flatMap((target) => targetSites(widget, target));
|
|
148
|
+
emitClickSequence(sites, nPress);
|
|
149
|
+
applyClickOutcomes(targets, nPress);
|
|
150
|
+
});
|
|
151
|
+
/* eslint-disable-next-line unicorn/consistent-boolean-name -- the boolean reports whether activation succeeded */
|
|
41
152
|
const tryActivate = async (widget) => {
|
|
42
153
|
if (widget.getAccessibleRole() === Gtk.AccessibleRole.LABEL) {
|
|
43
154
|
return false;
|
|
@@ -48,26 +159,53 @@ const tryActivate = async (widget) => {
|
|
|
48
159
|
});
|
|
49
160
|
return isActivated;
|
|
50
161
|
};
|
|
162
|
+
/**
|
|
163
|
+
* Activates a widget that neither claims the click nor carries a click gesture of its own, and
|
|
164
|
+
* otherwise delivers a press and release. The press travels outwards from the clicked widget
|
|
165
|
+
* through every widget carrying a click gesture with a pressed or released handler, the way GTK
|
|
166
|
+
* hands the same press to each of them, and stops at the first Gtk.Button or indexed child of a
|
|
167
|
+
* list box or flow box, which claims it. A gesture GTK attached itself takes the press only when no
|
|
168
|
+
* widget below it handles one, and stops it there, so an expander or a notebook tab nested in a row
|
|
169
|
+
* opens instead of activating the row. Coordinates are the clicked widget's position in each
|
|
170
|
+
* carrier, so a gesture the container of an indexed child carries reads the child's position rather
|
|
171
|
+
* than the container's center. An indexed child that the press reaches is then activated, or
|
|
172
|
+
* exclusively selected when its container does not activate on a single click. A widget with the
|
|
173
|
+
* label role is never activated, but does consume the click when it carries a gesture of its own.
|
|
174
|
+
*
|
|
175
|
+
* The press also stops at a widget whose click GTK4 implements in C on a gesture it attached
|
|
176
|
+
* itself, reading a GdkEvent that off-screen synthesis cannot produce. Gestures that widget carries
|
|
177
|
+
* of its own still take the press and release, the way GTK hands them the press before its own
|
|
178
|
+
* gesture claims it, and the same outcome is then applied through the public action GTK's own
|
|
179
|
+
* handler invokes: a list, grid, or column-view row is focused and selected, and activated as well
|
|
180
|
+
* on a second press or when its view activates on a single click; an expandable tree expander
|
|
181
|
+
* toggles its expansion, once per press, and only when it is the widget clicked, so a click on its
|
|
182
|
+
* child falls through to the enclosing row; a column header sorts by its column. Sorting goes
|
|
183
|
+
* through Gtk.ColumnView.sortByColumn, so the primary sort column and order match what a pointer
|
|
184
|
+
* produces while previously sorted columns are dropped rather than kept as secondary keys. A
|
|
185
|
+
* column-view cell and the row that carries the column headers stand in the way of the click rather
|
|
186
|
+
* than taking it, so a click on either reaches the row or the view behind it.
|
|
187
|
+
*/
|
|
51
188
|
const click = async (widget) => {
|
|
52
|
-
if (widget
|
|
53
|
-
await emitClickSequence(widget, widget, 1);
|
|
189
|
+
if (!isSelfClickTarget(widget) && (await tryActivate(widget))) {
|
|
54
190
|
return;
|
|
55
191
|
}
|
|
56
|
-
|
|
57
|
-
await wrapEvent(widget, () => {
|
|
58
|
-
widget.setActive(!widget.getActive());
|
|
59
|
-
});
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (await tryActivate(widget)) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const target = findClickableAncestor(widget);
|
|
66
|
-
if (target) {
|
|
67
|
-
await emitClickSequence(widget, target, 1);
|
|
68
|
-
}
|
|
192
|
+
await deliverClick(widget, 1);
|
|
69
193
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Delivers a two-press click gesture the way {@link click} delivers a single press, without trying
|
|
196
|
+
* activation first. A list box row or flow box child the presses reach, clicked directly or through
|
|
197
|
+
* a descendant, is activated and exclusively selected, as GTK's double-click path does whether or
|
|
198
|
+
* not the container activates on a single click. A widget whose click GTK4 implements itself
|
|
199
|
+
* receives that outcome once per press, so a list, grid, or column-view row is selected and then
|
|
200
|
+
* activated by the second press, a tree expander ends back where it started, and a column header
|
|
201
|
+
* sorts and then inverts its order.
|
|
202
|
+
*/
|
|
203
|
+
const dblClick = (widget) => deliverClick(widget, 2);
|
|
204
|
+
/**
|
|
205
|
+
* Delivers a three-press click gesture the same way a double click is delivered, applying the same
|
|
206
|
+
* outcome to a list box row or flow box child the presses reach, and applying the outcome GTK4
|
|
207
|
+
* implements itself once per press to a row, tree expander, or column header.
|
|
208
|
+
*/
|
|
209
|
+
const tripleClick = (widget) => deliverClick(widget, 3);
|
|
210
|
+
export { clickGestures, emitClickPhase, getAuthoredClickGestures, click, dblClick, tripleClick };
|
|
73
211
|
//# sourceMappingURL=click.js.map
|
|
@@ -1 +1 @@
|
|
|
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,iB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,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.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;;;;;;GAQG;AACH,MAAM,QAAQ,GAAG,CAAC,MAAkB,EAAiB,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAChF;;;;GAIG;AACH,MAAM,WAAW,GAAG,CAAC,MAAkB,EAAiB,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAEnF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import * as Gdk from \"@gtkx/gi/gdk\";\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport { hasSignalListener } from \"@gtkx/runtime/internal\";\nimport { callBooleanGetter, getCallableMethod, hasWidgetMethod } from \"../widget-getters.js\";\nimport { queryAllControllers } from \"./controller.js\";\nimport { wrapEvent } from \"./event-wrapper.js\";\nimport { hasIndexedChildren, selectContainerChild, SELECTED_PROBE, unselectOtherChildren } from \"./indexed-children.js\";\nimport { isClickTransparent, type NativeClick, nativeClickFor } from \"./native-click.js\";\n\ntype PressPoint = { x: number; y: number };\ntype ClickPhase = \"pressed\" | \"released\";\ntype ClickSite = { gestures: Gtk.GestureClick[]; point: PressPoint };\ntype ClickScope = { isClicked: boolean; isInternalAllowed: boolean };\n\ntype ClickTarget = {\n widget: Gtk.Widget;\n container: Gtk.Widget | null;\n gestures: Gtk.GestureClick[];\n isClaiming: boolean;\n native: NativeClick | null;\n};\n\nconst CLICK_SIGNALS = [\"pressed\", \"released\"];\nconst PRIMARY_BUTTONS: Set<number> = new Set([0, Gdk.BUTTON_PRIMARY]);\n\nconst getCenterPoint = (widget: Gtk.Widget): PressPoint => {\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 getClickPoint = (clicked: Gtk.Widget, carrier: Gtk.Widget): PressPoint => {\n if (clicked === carrier) {\n return getCenterPoint(clicked);\n }\n\n const [isComputed, bounds] = clicked.computeBounds(carrier);\n\n if (!isComputed) {\n return getCenterPoint(carrier);\n }\n\n return { x: bounds.getX() + bounds.getWidth() / 2, y: bounds.getY() + bounds.getHeight() / 2 };\n};\n\nconst emitGesture = (point: PressPoint, controllers: Gtk.GestureClick[], nPress: number, signal: string): void => {\n for (const controller of controllers) {\n controller.emit(signal, nPress, point.x, point.y);\n }\n};\n\nconst emitClickPhase = (\n widget: Gtk.Widget,\n controllers: Gtk.GestureClick[],\n nPress: number,\n phase: ClickPhase,\n): void => {\n emitGesture(getCenterPoint(widget), controllers, nPress, phase);\n};\n\nconst emitSitePhase = (sites: ClickSite[], nPress: number, phase: ClickPhase): void => {\n for (const site of sites) {\n emitGesture(site.point, site.gestures, nPress, phase);\n }\n};\n\nconst emitClickSequence = (sites: ClickSite[], nPress: number): void => {\n for (let i = 1; i <= nPress; i++) {\n emitSitePhase(sites, i, \"pressed\");\n emitSitePhase(sites, i, \"released\");\n }\n};\n\nconst containerFor = (widget: Gtk.Widget): Gtk.Widget | null => {\n const parent = widget.getParent();\n\n return parent !== null && hasWidgetMethod(widget, SELECTED_PROBE) && hasIndexedChildren(parent) ? parent : null;\n};\n\nconst hasClickHandlers = (gesture: Gtk.GestureClick): boolean => hasSignalListener(gesture, CLICK_SIGNALS);\nconst isInternalGesture = (gesture: Gtk.GestureClick): boolean => !hasSignalListener(gesture);\nconst isPrimaryGesture = (gesture: Gtk.GestureClick): boolean => PRIMARY_BUTTONS.has(gesture.getButton());\n\nconst clickGestures = (widget: Gtk.Widget): Gtk.GestureClick[] =>\n queryAllControllers(widget, Gtk.GestureClick).filter((gesture) => isPrimaryGesture(gesture));\n\nconst getAuthoredClickGestures = (widget: Gtk.Widget): Gtk.GestureClick[] =>\n clickGestures(widget).filter((gesture) => hasClickHandlers(gesture));\n\nconst isClaimingTarget = (widget: Gtk.Widget): boolean =>\n widget instanceof Gtk.Button || containerFor(widget) !== null;\n\nconst gestureTargetFor = (widget: Gtk.Widget, isInternalAllowed: boolean): ClickTarget | null => {\n const gestures = clickGestures(widget);\n\n if (isClaimingTarget(widget)) {\n return { widget, container: containerFor(widget), gestures, isClaiming: true, native: null };\n }\n\n const authored = gestures.filter((gesture) => hasClickHandlers(gesture));\n\n if (authored.length > 0) {\n return { widget, container: null, gestures: authored, isClaiming: false, native: null };\n }\n\n if (isInternalAllowed && gestures.some((gesture) => isInternalGesture(gesture))) {\n return { widget, container: null, gestures, isClaiming: true, native: null };\n }\n\n return null;\n};\n\nconst clickTargetFor = (widget: Gtk.Widget, scope: ClickScope): ClickTarget | null => {\n if (isClickTransparent(widget)) {\n return null;\n }\n\n const native = nativeClickFor(widget, scope.isClicked);\n\n if (native !== null) {\n return { widget, container: null, gestures: getAuthoredClickGestures(widget), isClaiming: true, native };\n }\n\n return gestureTargetFor(widget, scope.isInternalAllowed);\n};\n\nconst isSelfClickTarget = (widget: Gtk.Widget): boolean =>\n isClickTransparent(widget) || clickTargetFor(widget, { isClicked: true, isInternalAllowed: false }) !== null;\n\nconst nextClickWidget = (current: Gtk.Widget, target: ClickTarget | null): Gtk.Widget | null =>\n target?.isClaiming === true ? null : current.getParent();\n\nconst collectClickTargets = (widget: Gtk.Widget): ClickTarget[] => {\n const targets: ClickTarget[] = [];\n let current: Gtk.Widget | null = widget;\n\n while (current !== null) {\n const isClicked = current === widget;\n const scope = { isClicked, isInternalAllowed: !isClicked && targets.length === 0 };\n const target = clickTargetFor(current, scope);\n const next = nextClickWidget(current, target);\n\n if (target !== null) {\n targets.push(target);\n }\n\n current = next;\n }\n\n return targets;\n};\n\nconst targetSites = (clicked: Gtk.Widget, target: ClickTarget): ClickSite[] => {\n const { container } = target;\n const site = { gestures: target.gestures, point: getClickPoint(clicked, target.widget) };\n\n if (container === null) {\n return [site];\n }\n\n return [site, { gestures: getAuthoredClickGestures(container), point: getClickPoint(clicked, container) }];\n};\n\nconst isSingleClickActivating = (container: Gtk.Widget): boolean =>\n callBooleanGetter(container, \"getActivateOnSingleClick\") ?? true;\n\nconst isMultipleSelection = (container: Gtk.Widget): boolean =>\n getCallableMethod<[], Gtk.SelectionMode>(container, \"getSelectionMode\")?.() === Gtk.SelectionMode.MULTIPLE;\n\nconst isChildSelectable = (child: Gtk.Widget): boolean => callBooleanGetter(child, \"getSelectable\") ?? true;\n\nconst replaceContainerSelection = (container: Gtk.Widget, child: Gtk.Widget): void => {\n if (!isChildSelectable(child)) {\n return;\n }\n\n selectContainerChild(container, child);\n\n if (isMultipleSelection(container)) {\n unselectOtherChildren(container, child);\n }\n};\n\nconst isActivatedByClick = (container: Gtk.Widget, nPress: number): boolean =>\n isSingleClickActivating(container) || nPress > 1;\n\nconst isSelectionReplacedByClick = (container: Gtk.Widget, nPress: number): boolean =>\n nPress > 1 || !isSingleClickActivating(container);\n\nconst applyContainerOutcome = (target: ClickTarget, nPress: number): void => {\n const { container, widget } = target;\n\n if (container === null || widget.getParent() !== container) {\n return;\n }\n\n if (isActivatedByClick(container, nPress)) {\n widget.activate();\n }\n\n if (isSelectionReplacedByClick(container, nPress)) {\n replaceContainerSelection(container, widget);\n }\n};\n\nconst applyClickOutcome = (target: ClickTarget, nPress: number): void => {\n if (target.native === null) {\n applyContainerOutcome(target, nPress);\n\n return;\n }\n\n target.native(target.widget, nPress);\n};\n\nconst applyClickOutcomes = (targets: ClickTarget[], nPress: number): void => {\n for (const target of targets) {\n applyClickOutcome(target, nPress);\n }\n};\n\nconst deliverClick = (widget: Gtk.Widget, nPress: number): Promise<void> =>\n wrapEvent(widget, () => {\n const targets = collectClickTargets(widget);\n const sites = targets.flatMap((target) => targetSites(widget, target));\n emitClickSequence(sites, nPress);\n applyClickOutcomes(targets, nPress);\n });\n\n/* eslint-disable-next-line unicorn/consistent-boolean-name -- the boolean reports whether activation succeeded */\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 * Activates a widget that neither claims the click nor carries a click gesture of its own, and\n * otherwise delivers a press and release. The press travels outwards from the clicked widget\n * through every widget carrying a click gesture with a pressed or released handler, the way GTK\n * hands the same press to each of them, and stops at the first Gtk.Button or indexed child of a\n * list box or flow box, which claims it. A gesture GTK attached itself takes the press only when no\n * widget below it handles one, and stops it there, so an expander or a notebook tab nested in a row\n * opens instead of activating the row. Coordinates are the clicked widget's position in each\n * carrier, so a gesture the container of an indexed child carries reads the child's position rather\n * than the container's center. An indexed child that the press reaches is then activated, or\n * exclusively selected when its container does not activate on a single click. A widget with the\n * label role is never activated, but does consume the click when it carries a gesture of its own.\n *\n * The press also stops at a widget whose click GTK4 implements in C on a gesture it attached\n * itself, reading a GdkEvent that off-screen synthesis cannot produce. Gestures that widget carries\n * of its own still take the press and release, the way GTK hands them the press before its own\n * gesture claims it, and the same outcome is then applied through the public action GTK's own\n * handler invokes: a list, grid, or column-view row is focused and selected, and activated as well\n * on a second press or when its view activates on a single click; an expandable tree expander\n * toggles its expansion, once per press, and only when it is the widget clicked, so a click on its\n * child falls through to the enclosing row; a column header sorts by its column. Sorting goes\n * through Gtk.ColumnView.sortByColumn, so the primary sort column and order match what a pointer\n * produces while previously sorted columns are dropped rather than kept as secondary keys. A\n * column-view cell and the row that carries the column headers stand in the way of the click rather\n * than taking it, so a click on either reaches the row or the view behind it.\n */\nconst click = async (widget: Gtk.Widget): Promise<void> => {\n if (!isSelfClickTarget(widget) && (await tryActivate(widget))) {\n return;\n }\n\n await deliverClick(widget, 1);\n};\n\n/**\n * Delivers a two-press click gesture the way {@link click} delivers a single press, without trying\n * activation first. A list box row or flow box child the presses reach, clicked directly or through\n * a descendant, is activated and exclusively selected, as GTK's double-click path does whether or\n * not the container activates on a single click. A widget whose click GTK4 implements itself\n * receives that outcome once per press, so a list, grid, or column-view row is selected and then\n * activated by the second press, a tree expander ends back where it started, and a column header\n * sorts and then inverts its order.\n */\nconst dblClick = (widget: Gtk.Widget): Promise<void> => deliverClick(widget, 2);\n/**\n * Delivers a three-press click gesture the same way a double click is delivered, applying the same\n * outcome to a list box row or flow box child the presses reach, and applying the outcome GTK4\n * implements itself once per press to a row, tree expander, or column header.\n */\nconst tripleClick = (widget: Gtk.Widget): Promise<void> => deliverClick(widget, 3);\n\nexport { clickGestures, emitClickPhase, getAuthoredClickGestures, click, dblClick, tripleClick };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-header-click.d.ts","sourceRoot":"","sources":["../../src/user-event/column-header-click.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AA4EpC,QAAA,MAAM,gBAAgB,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,QAAQ,MAAM,KAAG,IAW9D,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import { children } from "../traversal.js";
|
|
3
|
+
import { getWidgetTextContent } from "../widget-accessible-properties.js";
|
|
4
|
+
const columnViewFor = (header) => {
|
|
5
|
+
let current = header.getParent();
|
|
6
|
+
while (current !== null) {
|
|
7
|
+
if (current instanceof Gtk.ColumnView) {
|
|
8
|
+
return current;
|
|
9
|
+
}
|
|
10
|
+
current = current.getParent();
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
const columnsFor = (view) => {
|
|
15
|
+
const model = view.getColumns();
|
|
16
|
+
const columns = [];
|
|
17
|
+
for (let index = 0; index < model.getNItems(); index++) {
|
|
18
|
+
const column = model.getItem(index);
|
|
19
|
+
if (column instanceof Gtk.ColumnViewColumn) {
|
|
20
|
+
columns.push(column);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return columns;
|
|
24
|
+
};
|
|
25
|
+
const headerIndexFor = (header) => {
|
|
26
|
+
const parent = header.getParent();
|
|
27
|
+
return parent === null ? -1 : [...children(parent)].indexOf(header);
|
|
28
|
+
};
|
|
29
|
+
const titledColumnFor = (columns, title) => {
|
|
30
|
+
const matches = columns.filter((column) => column.getTitle() === title);
|
|
31
|
+
return matches.length === 1 ? matches[0] ?? null : null;
|
|
32
|
+
};
|
|
33
|
+
const columnFor = (header, view) => {
|
|
34
|
+
const columns = columnsFor(view);
|
|
35
|
+
const picked = columns[headerIndexFor(header)] ?? null;
|
|
36
|
+
const title = getWidgetTextContent(header);
|
|
37
|
+
if (picked !== null && picked.getTitle() === title) {
|
|
38
|
+
return picked;
|
|
39
|
+
}
|
|
40
|
+
return titledColumnFor(columns, title) ?? picked;
|
|
41
|
+
};
|
|
42
|
+
const sortableColumnFor = (header, view) => {
|
|
43
|
+
const column = columnFor(header, view);
|
|
44
|
+
return column !== null && column.getSorter() !== null ? column : null;
|
|
45
|
+
};
|
|
46
|
+
const invertedSortDirection = (order) => order === Gtk.SortType.ASCENDING ? Gtk.SortType.DESCENDING : Gtk.SortType.ASCENDING;
|
|
47
|
+
const nextSortDirection = (view, column) => {
|
|
48
|
+
const sorter = view.getSorter();
|
|
49
|
+
if (!(sorter instanceof Gtk.ColumnViewSorter) || sorter.getPrimarySortColumn() !== column) {
|
|
50
|
+
return Gtk.SortType.ASCENDING;
|
|
51
|
+
}
|
|
52
|
+
return invertedSortDirection(sorter.getPrimarySortOrder());
|
|
53
|
+
};
|
|
54
|
+
const applyHeaderClick = (header, nPress) => {
|
|
55
|
+
const view = columnViewFor(header);
|
|
56
|
+
const column = view === null ? null : sortableColumnFor(header, view);
|
|
57
|
+
if (view === null || column === null) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
for (let press = 1; press <= nPress; press++) {
|
|
61
|
+
view.sortByColumn(column, nextSortDirection(view, column));
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export { applyHeaderClick };
|
|
65
|
+
//# sourceMappingURL=column-header-click.js.map
|
|
@@ -0,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"../widget-accessible-properties.js\";\n\nconst columnViewFor = (header: Gtk.Widget): Gtk.ColumnView | null => {\n let current: Gtk.Widget | null = header.getParent();\n\n while (current !== null) {\n if (current instanceof Gtk.ColumnView) {\n return current;\n }\n\n current = current.getParent();\n }\n\n return null;\n};\n\nconst columnsFor = (view: Gtk.ColumnView): Gtk.ColumnViewColumn[] => {\n const model = view.getColumns();\n const columns: Gtk.ColumnViewColumn[] = [];\n\n for (let index = 0; index < model.getNItems(); index++) {\n const column = model.getItem(index);\n\n if (column instanceof Gtk.ColumnViewColumn) {\n columns.push(column);\n }\n }\n\n return columns;\n};\n\nconst headerIndexFor = (header: Gtk.Widget): number => {\n const parent = header.getParent();\n\n return parent === null ? -1 : [...children(parent)].indexOf(header);\n};\n\nconst titledColumnFor = (columns: Gtk.ColumnViewColumn[], title: string | null): Gtk.ColumnViewColumn | null => {\n const matches = columns.filter((column) => column.getTitle() === title);\n\n return matches.length === 1 ? matches[0] ?? null : null;\n};\n\nconst columnFor = (header: Gtk.Widget, view: Gtk.ColumnView): Gtk.ColumnViewColumn | null => {\n const columns = columnsFor(view);\n const picked = columns[headerIndexFor(header)] ?? null;\n const title = getWidgetTextContent(header);\n\n if (picked !== null && picked.getTitle() === title) {\n return picked;\n }\n\n return titledColumnFor(columns, title) ?? picked;\n};\n\nconst sortableColumnFor = (header: Gtk.Widget, view: Gtk.ColumnView): Gtk.ColumnViewColumn | null => {\n const column = columnFor(header, view);\n\n return column !== null && column.getSorter() !== null ? column : null;\n};\n\nconst invertedSortDirection = (order: Gtk.SortType): Gtk.SortType =>\n order === Gtk.SortType.ASCENDING ? Gtk.SortType.DESCENDING : Gtk.SortType.ASCENDING;\n\nconst nextSortDirection = (view: Gtk.ColumnView, column: Gtk.ColumnViewColumn): Gtk.SortType => {\n const sorter = view.getSorter();\n\n if (!(sorter instanceof Gtk.ColumnViewSorter) || sorter.getPrimarySortColumn() !== column) {\n return Gtk.SortType.ASCENDING;\n }\n\n return invertedSortDirection(sorter.getPrimarySortOrder());\n};\n\nconst applyHeaderClick = (header: Gtk.Widget, nPress: number): void => {\n const view = columnViewFor(header);\n const column = view === null ? null : sortableColumnFor(header, view);\n\n if (view === null || column === null) {\n return;\n }\n\n for (let press = 1; press <= nPress; press++) {\n view.sortByColumn(column, nextSortDirection(view, column));\n }\n};\n\nexport { applyHeaderClick };\n"]}
|
|
@@ -1,8 +1,37 @@
|
|
|
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
|
+
*/
|
|
6
35
|
declare const getController: <T extends Gtk.EventController>(widget: Gtk.Widget, controllerType: ControllerConstructor<T>) => T;
|
|
7
36
|
declare const getOrCreateControllers: <T extends Gtk.EventController>(widget: Gtk.Widget, controllerType: ControllerConstructor<T>) => T[];
|
|
8
37
|
export { queryAllControllers, queryController, getAllControllers, getController, getOrCreateControllers, type ControllerConstructor, };
|
|
@@ -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,QAAQ,GAAG,CAAC,MAAM,EAClB,gBAAgB,qBAAqB,CAAC,CAAC,CAAC,KACzC,CAAC,GAAG,IAA8D,CAAC;AAEtE,QAAA,MAAM,iBAAiB,GAAI,CAAC,SAAS,GAAG,CAAC,eAAe,EACpD,QAAQ,GAAG,CAAC,MAAM,EAClB,gBAAgB,qBAAqB,CAAC,CAAC,CAAC,KACzC,CAAC,EAQH,CAAC;AAEF,QAAA,MAAM,aAAa,GAAI,CAAC,SAAS,GAAG,CAAC,eAAe,EAChD,QAAQ,GAAG,CAAC,MAAM,EAClB,gBAAgB,qBAAqB,CAAC,CAAC,CAAC,KACzC,CAQ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AAI,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,13 @@ 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
|
+
*/
|
|
21
49
|
const getController = (widget, controllerType) => {
|
|
22
50
|
const [controller] = getAllControllers(widget, controllerType);
|
|
23
51
|
if (controller === undefined) {
|
|
@@ -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,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC;IACvC,MAAM,OAAO,GAAQ,EAAE,CAAC;IAExB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAE1C,IAAI,UAAU,YAAY,cAAc,EAAE,CAAC;YACvC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7B,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,CACpB,MAAkB,EAClB,cAAwC,EAChC,EAAE,CAAC,mBAAmB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAEtE;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,CACtB,MAAkB,EAClB,cAAwC,EACrC,EAAE;IACL,MAAM,WAAW,GAAG,mBAAmB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAEhE,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,MAAM,cAAc,CAAC,IAAI,uCAAuC,CAAC,CAAC;IACtF,CAAC;IAED,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,aAAa,GAAG,CAClB,MAAkB,EAClB,cAAwC,EACvC,EAAE;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAE/D,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,MAAM,cAAc,CAAC,IAAI,uCAAuC,CAAC,CAAC;IACtF,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-wrapper.d.ts","sourceRoot":"","sources":["../../src/user-event/event-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"event-wrapper.d.ts","sourceRoot":"","sources":["../../src/user-event/event-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAyEpC,QAAA,MAAM,SAAS,GAAU,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,KAAG,OAAO,CAAC,IAAI,CAM/F,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -9,7 +9,8 @@ const WINDOW_NOT_ACTIVE = "its window never became active";
|
|
|
9
9
|
const actionableHop = () => new Promise((resolve) => setTimeout(resolve, 1));
|
|
10
10
|
const canDisplayDeliverActivation = (window) => window.getDisplay().getDefaultSeat() !== null;
|
|
11
11
|
const findWindowActionabilityFailure = (widget, root) => {
|
|
12
|
-
|
|
12
|
+
const [isComputed, allocation] = root.computeBounds(root);
|
|
13
|
+
if (!isComputed || allocation.getWidth() === 0) {
|
|
13
14
|
return WINDOW_NOT_ALLOCATED;
|
|
14
15
|
}
|
|
15
16
|
if (!widget.getMapped()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-wrapper.js","sourceRoot":"","sources":["../../src/user-event/event-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC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IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAE3E,OAAO,IAAI,GAAG,GAAG,aAAa,UAAU,UAAU,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC;AACvF,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,EAAE,MAAkB,EAAiB,EAAE;IAClE,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC,oBAAoB,CAAC;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;IACtC,IAAI,OAAO,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAE/C,OAAO,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC/C,MAAM,aAAa,EAAE,CAAC;QACtB,OAAO,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACX,+BAA+B,cAAc,CAAC,MAAM,CAAC,6BAA6B;YAClF,UAAU,MAAM,CAAC,OAAO,CAAC,cAAc,OAAO,EAAE,CACnD,CAAC;IACN,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,KAAK,EAAE,MAAkB,EAAE,IAAoC,EAAiB,EAAE;IAChG,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAEhC,MAAM,QAAQ,CAAC,KAAK,IAAI,EAAE;QACtB,MAAM,IAAI,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\nimport { runInAct } from \"../act.js\";\nimport { getConfig } from \"../config.js\";\nimport { formatRole } from \"../role-helpers.js\";\n\nconst NOT_SENSITIVE = \"it is not sensitive (the widget or one of its ancestors is disabled)\";\nconst WINDOW_NOT_ALLOCATED = \"its window has not been allocated a size\";\nconst NOT_MAPPED = \"it is not mapped (it is not shown on screen, e.g. it is hidden or on a non-visible page)\";\nconst WINDOW_NOT_ACTIVE = \"its window never became active\";\n\nconst actionableHop = (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 1));\n\nconst canDisplayDeliverActivation = (window: Gtk.Window): boolean =>\n window.getDisplay().getDefaultSeat() !== null;\n\nconst findWindowActionabilityFailure = (widget: Gtk.Widget, root: Gtk.Window): string | null => {\n const [isComputed, allocation] = root.computeBounds(root);\n\n if (!isComputed || allocation.getWidth() === 0) {\n return WINDOW_NOT_ALLOCATED;\n }\n\n if (!widget.getMapped()) {\n return NOT_MAPPED;\n }\n\n if (canDisplayDeliverActivation(root) && !root.isActive()) {\n return WINDOW_NOT_ACTIVE;\n }\n\n return null;\n};\n\nconst findActionabilityFailure = (widget: Gtk.Widget): string | null => {\n if (!widget.isSensitive()) {\n return NOT_SENSITIVE;\n }\n\n const root = widget.getRoot();\n\n if (!(root instanceof Gtk.Window) || !root.getVisible()) {\n return null;\n }\n\n return findWindowActionabilityFailure(widget, root);\n};\n\nconst describeWidget = (widget: Gtk.Widget): string => {\n const tag = widget.constructor.name;\n const name = widget.getName();\n const nameAttribute = name && !name.endsWith(tag) ? ` name=\"${name}\"` : \"\";\n\n return `<${tag}${nameAttribute} role=\"${formatRole(widget.getAccessibleRole())}\">`;\n};\n\nconst waitForActionable = async (widget: Gtk.Widget): Promise<void> => {\n const timeout = getConfig().actionabilityTimeout;\n const deadline = Date.now() + timeout;\n let failure = findActionabilityFailure(widget);\n\n while (failure !== null && Date.now() < deadline) {\n await actionableHop();\n failure = findActionabilityFailure(widget);\n }\n\n if (failure !== null) {\n throw new Error(\n `Cannot dispatch user event: ${describeWidget(widget)} did not become actionable ` +\n `within ${String(timeout)}ms because ${failure}`,\n );\n }\n};\n\nconst wrapEvent = async (widget: Gtk.Widget, body: () => void | PromiseLike<void>): Promise<void> => {\n await waitForActionable(widget);\n\n await runInAct(async () => {\n await body();\n });\n};\n\nexport { wrapEvent };\n"]}
|