@mobilewright/inspector 0.0.61 → 0.0.63
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/dist/lib/inspect-screen.d.ts +1 -0
- package/dist/lib/inspect-screen.d.ts.map +1 -1
- package/dist/lib/inspect-screen.js +2 -1
- package/dist/lib/inspect-screen.js.map +1 -1
- package/dist/lib/locator-derivation.d.ts +2 -0
- package/dist/lib/locator-derivation.d.ts.map +1 -1
- package/dist/lib/locator-derivation.js +5 -1
- package/dist/lib/locator-derivation.js.map +1 -1
- package/dist/routes/device-actions.d.ts +1 -1
- package/dist/routes/device-actions.d.ts.map +1 -1
- package/dist/routes/device-actions.js +27 -1
- package/dist/routes/device-actions.js.map +1 -1
- package/package.json +3 -3
- package/public/codegen.html +47 -5
- package/public/css/app.css +95 -10
- package/public/js/codegen.js +139 -15
- package/public/js/view-tree.js +2 -2
|
@@ -38,6 +38,7 @@ declare function toElementJson({ node, locator, locators, depth }: ElementEntry,
|
|
|
38
38
|
isSelected: boolean | null;
|
|
39
39
|
isFocused: boolean | null;
|
|
40
40
|
isChecked: boolean | null;
|
|
41
|
+
isEditable: boolean;
|
|
41
42
|
raw: Record<string, unknown> | null;
|
|
42
43
|
locator: import("./locator-derivation.js").Locator | null;
|
|
43
44
|
locators: import("./locator-derivation.js").Locator[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspect-screen.d.ts","sourceRoot":"","sources":["../../src/lib/inspect-screen.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,
|
|
1
|
+
{"version":3,"file":"inspect-screen.d.ts","sourceRoot":"","sources":["../../src/lib/inspect-screen.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAuD,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIjH,oDAAoD;AACpD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AAE3D,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;CACd;AAED,oEAAoE;AACpE,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAUjD;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CASlI;AAED,iBAAS,aAAa,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;EAuBvG"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Captures one moment of the device screen for the Inspector and codegen: screenshot, element
|
|
2
2
|
// list with derived locators, and screen size, plus an etag that changes whenever any of them does.
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
|
-
import { deriveElementList, locatorMatchPosition } from './locator-derivation.js';
|
|
4
|
+
import { deriveElementList, isEditable, locatorMatchPosition } from './locator-derivation.js';
|
|
5
5
|
import { logger } from './logger.js';
|
|
6
6
|
import { timeoutAfter } from './timeout.js';
|
|
7
7
|
/** JPEG at 60 is ~4x smaller than PNG for the same capture time. */
|
|
@@ -41,6 +41,7 @@ function toElementJson({ node, locator, locators, depth }, index, tree) {
|
|
|
41
41
|
isSelected: node.isSelected ?? null,
|
|
42
42
|
isFocused: node.isFocused ?? null,
|
|
43
43
|
isChecked: node.isChecked ?? null,
|
|
44
|
+
isEditable: isEditable(node),
|
|
44
45
|
raw: node.raw ?? null,
|
|
45
46
|
locator,
|
|
46
47
|
locators,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspect-screen.js","sourceRoot":"","sources":["../../src/lib/inspect-screen.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,oGAAoG;AAEpG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAqB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"inspect-screen.js","sourceRoot":"","sources":["../../src/lib/inspect-screen.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,oGAAoG;AAEpG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,oBAAoB,EAAqB,MAAM,yBAAyB,CAAC;AACjH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAc5C,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AACjD,MAAM,iBAAiB,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAW,CAAC;AAEnE,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,aAAa,GAAG,MAAM,CAAC;AAK7B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAc,EAAE,KAAa,EAAE,UAAqC;IACtG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AAC,EAAE,CAAC;YACrD,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,OAAkB,CAAC;AAC5B,CAAC"}
|
|
@@ -21,6 +21,8 @@ export interface ElementEntry {
|
|
|
21
21
|
/** Nesting level in the view tree; roots are 0. With the depth-first order this rebuilds the tree. */
|
|
22
22
|
depth: number;
|
|
23
23
|
}
|
|
24
|
+
/** Whether text can be typed into the node: the same types getByRole('textfield') matches. */
|
|
25
|
+
export declare function isEditable(node: ViewNode): boolean;
|
|
24
26
|
/**
|
|
25
27
|
* Derive all matching mobilewright locators for a single ViewNode.
|
|
26
28
|
* Returns array ordered by priority: testId > role > label > text.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locator-derivation.d.ts","sourceRoot":"","sources":["../../src/lib/locator-derivation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAavD,gFAAgF;AAChF,MAAM,MAAM,OAAO,GACf;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;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AA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAG,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,sGAAsG;IACtG,KAAK,EAAE,MAAM,CAAC;CACf;AAED,8FAA8F;AAC9F,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAElD;AAyBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,EAAE,CAkBxD;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI,CAE5D;AAoDD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,YAAY,EAAE,CAenE;AAED,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAO9G"}
|
|
@@ -10,6 +10,10 @@ const ROLE_TYPES = Object.entries(ROLE_TYPE_MAP);
|
|
|
10
10
|
// iOS reports generic containers as "other", so deriving getByRole('listitem')
|
|
11
11
|
// from one would hand the user a locator matching much of the tree.
|
|
12
12
|
const TYPES_TOO_GENERIC_TO_SUGGEST = new Set(['other']);
|
|
13
|
+
/** Whether text can be typed into the node: the same types getByRole('textfield') matches. */
|
|
14
|
+
export function isEditable(node) {
|
|
15
|
+
return ROLE_TYPE_MAP.textfield.includes(bareTypeName(node.type ?? ''));
|
|
16
|
+
}
|
|
13
17
|
/** Map node.type to a mobilewright role string. Returns null for unmapped types. */
|
|
14
18
|
function deriveRole(node) {
|
|
15
19
|
// Same normalization core applies before matching: strips the Android package
|
|
@@ -36,7 +40,7 @@ function deriveRole(node) {
|
|
|
36
40
|
*/
|
|
37
41
|
export function deriveLocators(node) {
|
|
38
42
|
const locators = [];
|
|
39
|
-
const testId = node.identifier || node.resourceId;
|
|
43
|
+
const testId = node.key || node.identifier || node.resourceId;
|
|
40
44
|
if (testId)
|
|
41
45
|
locators.push({ kind: 'testId', value: testId });
|
|
42
46
|
const role = deriveRole(node);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locator-derivation.js","sourceRoot":"","sources":["../../src/lib/locator-derivation.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,uFAAuF;AACvF,mFAAmF;AAGnF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE3E,+EAA+E;AAC/E,kFAAkF;AAClF,kCAAkC;AAClC,MAAM,UAAU,GAAkC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AAEhF,gFAAgF;AAChF,+EAA+E;AAC/E,oEAAoE;AACpE,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAiBxD,oFAAoF;AACpF,SAAS,UAAU,CAAC,IAAc;IAChC,8EAA8E;IAC9E,yEAAyE;IACzE,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IAE3C,IAAI,IAAI,KAAK,gBAAgB,EAAE,CAAC;QAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,MAAM,CAAC;QAC9F,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC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AC;IACpC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DeviceManager } from '../lib/device-manager.js';
|
|
2
2
|
/**
|
|
3
3
|
* Express router for actions codegen performs on the device.
|
|
4
|
-
* POST /api/tap, POST /api/press-button, POST /api/geolocation
|
|
4
|
+
* POST /api/tap, POST /api/press-button, POST /api/geolocation, POST /api/open-url, POST /api/fill
|
|
5
5
|
*/
|
|
6
6
|
export declare function createDeviceActionsRouter(deviceManager: DeviceManager): import("express-serve-static-core").Router;
|
|
7
7
|
//# sourceMappingURL=device-actions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device-actions.d.ts","sourceRoot":"","sources":["../../src/routes/device-actions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,aAAa,EAAE,MAAM,0BAA0B,CAAC;AActE;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,aAAa,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"device-actions.d.ts","sourceRoot":"","sources":["../../src/routes/device-actions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,aAAa,EAAE,MAAM,0BAA0B,CAAC;AActE;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,aAAa,EAAE,aAAa,8CAsCrE"}
|
|
@@ -7,7 +7,7 @@ const TAP_GESTURES = ['tap', 'doubleTap', 'longPress'];
|
|
|
7
7
|
const RECORDER_BUTTONS = ['HOME', 'BACK', 'APP_SWITCH'];
|
|
8
8
|
/**
|
|
9
9
|
* Express router for actions codegen performs on the device.
|
|
10
|
-
* POST /api/tap, POST /api/press-button, POST /api/geolocation
|
|
10
|
+
* POST /api/tap, POST /api/press-button, POST /api/geolocation, POST /api/open-url, POST /api/fill
|
|
11
11
|
*/
|
|
12
12
|
export function createDeviceActionsRouter(deviceManager) {
|
|
13
13
|
const router = Router();
|
|
@@ -39,6 +39,10 @@ export function createDeviceActionsRouter(deviceManager) {
|
|
|
39
39
|
router.post('/press-button', deviceAction('Press button', parsePressButton));
|
|
40
40
|
// body: { geolocation: { latitude, longitude } } to set, { geolocation: null } to reset
|
|
41
41
|
router.post('/geolocation', deviceAction('Set geolocation', parseGeolocation));
|
|
42
|
+
// body: { url: string }, a web url or deep link with a scheme
|
|
43
|
+
router.post('/open-url', deviceAction('Open URL', parseOpenUrl));
|
|
44
|
+
// body: { x: number, y: number, text: string }, the center of the element to fill
|
|
45
|
+
router.post('/fill', deviceAction('Fill', parseFill));
|
|
42
46
|
return router;
|
|
43
47
|
}
|
|
44
48
|
function statusFor(err) {
|
|
@@ -65,6 +69,28 @@ function parsePressButton({ button }) {
|
|
|
65
69
|
}
|
|
66
70
|
return { run: device => device.screen.pressButton(button) };
|
|
67
71
|
}
|
|
72
|
+
function parseOpenUrl({ url }) {
|
|
73
|
+
if (typeof url !== 'string' || !URL.canParse(url)) {
|
|
74
|
+
return { error: 'url must be a url with a scheme, e.g. https://example.com or myapp://path' };
|
|
75
|
+
}
|
|
76
|
+
return { run: device => device.openUrl(url) };
|
|
77
|
+
}
|
|
78
|
+
// Same steps as locator.fill() in core, performed at the element's center.
|
|
79
|
+
function parseFill({ x, y, text }) {
|
|
80
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
81
|
+
return { error: 'x and y must be numbers' };
|
|
82
|
+
}
|
|
83
|
+
if (typeof text !== 'string') {
|
|
84
|
+
return { error: 'text must be a string' };
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
run: async (device) => {
|
|
88
|
+
await device.screen.tap(x, y);
|
|
89
|
+
await device.driver.clearText();
|
|
90
|
+
await device.driver.typeText(text);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
68
94
|
function parseGeolocation({ geolocation }) {
|
|
69
95
|
if (geolocation !== null && !isValidGeolocation(geolocation)) {
|
|
70
96
|
return { error: 'geolocation must be null or { latitude: -90..90, longitude: -180..180 }' };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device-actions.js","sourceRoot":"","sources":["../../src/routes/device-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAuB,MAAM,SAAS,CAAC;AAGtD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAEtE,8FAA8F;AAC9F,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,WAAW,CAAU,CAAC;AAGhE,sDAAsD;AACtD,MAAM,gBAAgB,GAA8B,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AAOnF;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,aAA4B;IACpE,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;IAExB,4FAA4F;IAC5F,gCAAgC;IAChC,SAAS,YAAY,CAAC,IAAY,EAAE,KAA0C;QAC5E,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;YACxB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAgB,CAAC,CAAC;YACtD,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;gBACtB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;gBAC9C,OAAO;YACT,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC3C,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YACzB,CAAC;YAAC,OAAO,GAAG,EAAE,CAA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,SAAS,gBAAgB,CAAC,EAAE,WAAW,EAAe;IACpD,IAAI,WAAW,KAAK,IAAI,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7D,OAAO,EAAE,KAAK,EAAE,yEAAyE,EAAE,CAAC;IAC9F,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,CAAC;AAC/D,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACxC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAgD,CAAC;IAC7F,OAAO,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI,CAAC,EAAE,IAAI,QAAQ,IAAI,EAAE;WACnE,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,IAAI,CAAC,GAAG,IAAI,SAAS,IAAI,GAAG,CAAC;AAC9E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobilewright/inspector",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.63",
|
|
4
4
|
"description": "Browser-based element inspector for Mobilewright",
|
|
5
5
|
"homepage": "https://mobilewright.dev",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"public"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@mobilewright/core": "^0.0.
|
|
35
|
-
"@mobilewright/protocol": "^0.0.
|
|
34
|
+
"@mobilewright/core": "^0.0.63",
|
|
35
|
+
"@mobilewright/protocol": "^0.0.63",
|
|
36
36
|
"express": "^5.2.1",
|
|
37
37
|
"open": "^10.2.0"
|
|
38
38
|
},
|
package/public/codegen.html
CHANGED
|
@@ -41,13 +41,45 @@
|
|
|
41
41
|
<button id="geo-btn" class="tool-btn device-btn" popovertarget="geo-popover" title="Set location" aria-label="Set location" disabled>
|
|
42
42
|
<span class="codicon codicon-location" aria-hidden="true"></span>
|
|
43
43
|
</button>
|
|
44
|
+
<button id="url-btn" class="tool-btn device-btn" popovertarget="url-popover" title="Open URL" aria-label="Open URL" disabled>
|
|
45
|
+
<span class="codicon codicon-link" aria-hidden="true"></span>
|
|
46
|
+
</button>
|
|
44
47
|
</div>
|
|
45
|
-
<form id="
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
<form id="url-popover" class="action-popover wide-popover" popover aria-labelledby="url-popover-title">
|
|
49
|
+
<div class="popover-header">
|
|
50
|
+
<h2 id="url-popover-title">Open URL</h2>
|
|
51
|
+
<button type="button" class="popover-close" popovertarget="url-popover" popovertargetaction="hide" aria-label="Close">×</button>
|
|
52
|
+
</div>
|
|
53
|
+
<p class="popover-hint">Opens a web link or deep link on the device and records <code>device.openUrl()</code>.</p>
|
|
54
|
+
<input name="url" type="text" autofocus aria-label="URL" placeholder="https://example.com or myapp://path" required />
|
|
55
|
+
<div class="popover-actions">
|
|
56
|
+
<button type="submit" class="tool-btn popover-submit-btn">Open</button>
|
|
57
|
+
</div>
|
|
58
|
+
</form>
|
|
59
|
+
<form id="fill-popover" class="action-popover wide-popover" popover aria-labelledby="fill-popover-title">
|
|
60
|
+
<div class="popover-header">
|
|
61
|
+
<h2 id="fill-popover-title">Fill text</h2>
|
|
62
|
+
<button type="button" class="popover-close" popovertarget="fill-popover" popovertargetaction="hide" aria-label="Close">×</button>
|
|
63
|
+
</div>
|
|
64
|
+
<p class="popover-hint">Taps the selected element, clears it and types this text. Records <code>locator.fill()</code>.</p>
|
|
65
|
+
<input name="text" type="text" autofocus aria-label="Text" placeholder="Text to type" />
|
|
66
|
+
<div class="popover-actions">
|
|
67
|
+
<button type="submit" class="tool-btn popover-submit-btn">Fill</button>
|
|
68
|
+
</div>
|
|
69
|
+
</form>
|
|
70
|
+
<form id="geo-popover" class="action-popover wide-popover" popover aria-labelledby="geo-popover-title">
|
|
71
|
+
<div class="popover-header">
|
|
72
|
+
<h2 id="geo-popover-title">Set location</h2>
|
|
73
|
+
<button type="button" class="popover-close" popovertarget="geo-popover" popovertargetaction="hide" aria-label="Close">×</button>
|
|
74
|
+
</div>
|
|
75
|
+
<p class="popover-hint">Moves the device's GPS to these coordinates and records <code>device.setGeolocation()</code>.</p>
|
|
76
|
+
<div class="popover-fields">
|
|
77
|
+
<label>Latitude <input name="latitude" autofocus type="number" step="any" min="-90" max="90" placeholder="-17.833" required /></label>
|
|
78
|
+
<label>Longitude <input name="longitude" type="number" step="any" min="-180" max="180" placeholder="177.947" required /></label>
|
|
79
|
+
</div>
|
|
80
|
+
<div class="popover-actions">
|
|
49
81
|
<button type="button" id="geo-reset-btn" class="tool-btn">Reset location</button>
|
|
50
|
-
<button type="submit" class="tool-btn
|
|
82
|
+
<button type="submit" class="tool-btn popover-submit-btn">Set</button>
|
|
51
83
|
</div>
|
|
52
84
|
</form>
|
|
53
85
|
<div id="screenshot-container">
|
|
@@ -88,6 +120,13 @@
|
|
|
88
120
|
<button id="copy-btn" class="tool-btn" title="Copy test" aria-label="Copy test">
|
|
89
121
|
<span class="codicon codicon-files" aria-hidden="true"></span>
|
|
90
122
|
</button>
|
|
123
|
+
<span class="tool-separator"></span>
|
|
124
|
+
<label id="target-picker">Target:
|
|
125
|
+
<select id="target-select">
|
|
126
|
+
<option value="test">Test Runner</option>
|
|
127
|
+
<option value="library">Library</option>
|
|
128
|
+
</select>
|
|
129
|
+
</label>
|
|
91
130
|
</div>
|
|
92
131
|
<textarea id="code-editor" spellcheck="false" aria-label="Generated test code"></textarea>
|
|
93
132
|
</section>
|
|
@@ -105,6 +144,7 @@
|
|
|
105
144
|
<button class="tool-btn gesture-btn" data-gesture="tap">Tap</button>
|
|
106
145
|
<button class="tool-btn gesture-btn" data-gesture="doubleTap">Double tap</button>
|
|
107
146
|
<button class="tool-btn gesture-btn" data-gesture="longPress">Long press</button>
|
|
147
|
+
<button id="fill-btn" class="tool-btn gesture-btn" popovertarget="fill-popover">Fill</button>
|
|
108
148
|
</div>
|
|
109
149
|
<div id="detail-locators"></div>
|
|
110
150
|
<div id="detail-properties"></div>
|
|
@@ -114,6 +154,8 @@
|
|
|
114
154
|
</section>
|
|
115
155
|
</main>
|
|
116
156
|
|
|
157
|
+
<div id="error-toast" role="alert" hidden></div>
|
|
158
|
+
|
|
117
159
|
<script src="/js/codegen.js" type="module"></script>
|
|
118
160
|
</body>
|
|
119
161
|
</html>
|
package/public/css/app.css
CHANGED
|
@@ -181,7 +181,8 @@ header h1 {
|
|
|
181
181
|
|
|
182
182
|
#device-picker select,
|
|
183
183
|
#auto-refresh-interval,
|
|
184
|
-
#theme-select
|
|
184
|
+
#theme-select,
|
|
185
|
+
#target-select {
|
|
185
186
|
background: var(--c-bg);
|
|
186
187
|
color: var(--c-text);
|
|
187
188
|
border: 1px solid var(--c-border);
|
|
@@ -194,7 +195,8 @@ header h1 {
|
|
|
194
195
|
|
|
195
196
|
#device-picker select:focus,
|
|
196
197
|
#auto-refresh-interval:focus,
|
|
197
|
-
#theme-select:focus
|
|
198
|
+
#theme-select:focus,
|
|
199
|
+
#target-select:focus {
|
|
198
200
|
border-color: var(--c-accent);
|
|
199
201
|
}
|
|
200
202
|
|
|
@@ -736,6 +738,7 @@ main {
|
|
|
736
738
|
.codicon-files::before { content: '\eaf0'; }
|
|
737
739
|
.codicon-check::before { content: '\eab2'; }
|
|
738
740
|
.codicon-location::before { content: '\eb1a'; }
|
|
741
|
+
.codicon-link::before { content: '\eb15'; }
|
|
739
742
|
.codicon-chevron-down::before { content: '\eab4'; }
|
|
740
743
|
.codicon-chevron-right::before { content: '\eab6'; }
|
|
741
744
|
|
|
@@ -810,6 +813,14 @@ main {
|
|
|
810
813
|
}
|
|
811
814
|
#record-btn[aria-pressed="true"] .codicon { color: var(--c-status-error); }
|
|
812
815
|
|
|
816
|
+
#target-picker {
|
|
817
|
+
display: flex;
|
|
818
|
+
align-items: center;
|
|
819
|
+
gap: 6px;
|
|
820
|
+
font-size: 11px;
|
|
821
|
+
color: var(--c-text-muted);
|
|
822
|
+
}
|
|
823
|
+
|
|
813
824
|
.tool-separator {
|
|
814
825
|
width: 1px;
|
|
815
826
|
height: 16px;
|
|
@@ -875,7 +886,8 @@ main {
|
|
|
875
886
|
|
|
876
887
|
/* ---- Set location popover ---- */
|
|
877
888
|
|
|
878
|
-
|
|
889
|
+
/* Forms the codegen toolbar and element actions open to ask for input. */
|
|
890
|
+
.action-popover {
|
|
879
891
|
padding: 16px;
|
|
880
892
|
border: 1px solid var(--c-border);
|
|
881
893
|
border-radius: 8px;
|
|
@@ -884,15 +896,15 @@ main {
|
|
|
884
896
|
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
|
|
885
897
|
}
|
|
886
898
|
|
|
887
|
-
|
|
899
|
+
.action-popover[popover]:popover-open {
|
|
888
900
|
display: flex;
|
|
889
901
|
flex-direction: column;
|
|
890
902
|
gap: 10px;
|
|
891
903
|
}
|
|
892
904
|
|
|
893
|
-
|
|
905
|
+
.action-popover::backdrop { background: rgba(0, 0, 0, 0.3); }
|
|
894
906
|
|
|
895
|
-
|
|
907
|
+
.action-popover label {
|
|
896
908
|
display: flex;
|
|
897
909
|
justify-content: space-between;
|
|
898
910
|
align-items: center;
|
|
@@ -901,7 +913,7 @@ main {
|
|
|
901
913
|
color: var(--c-text-muted);
|
|
902
914
|
}
|
|
903
915
|
|
|
904
|
-
|
|
916
|
+
.action-popover input {
|
|
905
917
|
width: 140px;
|
|
906
918
|
background: var(--c-bg);
|
|
907
919
|
color: var(--c-text);
|
|
@@ -911,18 +923,91 @@ main {
|
|
|
911
923
|
font: 12px 'SF Mono', Menlo, Monaco, monospace;
|
|
912
924
|
}
|
|
913
925
|
|
|
914
|
-
|
|
926
|
+
.action-popover input:focus { outline: none; border-color: var(--c-accent); }
|
|
927
|
+
|
|
928
|
+
/* URL and fill: a titled dialog with a full-width input. */
|
|
929
|
+
.wide-popover {
|
|
930
|
+
width: min(480px, calc(100vw - 32px));
|
|
931
|
+
padding: 20px;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
.wide-popover input {
|
|
935
|
+
width: 100%;
|
|
936
|
+
padding: 8px 10px;
|
|
937
|
+
font-size: 13px;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
.popover-header {
|
|
941
|
+
display: flex;
|
|
942
|
+
justify-content: space-between;
|
|
943
|
+
align-items: center;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
.popover-header h2 {
|
|
947
|
+
margin: 0;
|
|
948
|
+
font-size: 14px;
|
|
949
|
+
font-weight: 600;
|
|
950
|
+
color: var(--c-text-strong);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
.popover-close {
|
|
954
|
+
background: none;
|
|
955
|
+
border: none;
|
|
956
|
+
color: var(--c-text-muted);
|
|
957
|
+
font-size: 18px;
|
|
958
|
+
line-height: 1;
|
|
959
|
+
padding: 0 4px;
|
|
960
|
+
cursor: pointer;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
.popover-close:hover { color: var(--c-text); }
|
|
964
|
+
|
|
965
|
+
.popover-hint {
|
|
966
|
+
margin: 0;
|
|
967
|
+
font-size: 12px;
|
|
968
|
+
color: var(--c-text-muted);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
.popover-hint code { font-family: 'SF Mono', Menlo, Monaco, monospace; }
|
|
915
972
|
|
|
916
|
-
|
|
973
|
+
/* Side-by-side labeled inputs, each label stacked above its input. */
|
|
974
|
+
.popover-fields {
|
|
975
|
+
display: flex;
|
|
976
|
+
gap: 12px;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
.popover-fields label {
|
|
980
|
+
flex: 1;
|
|
981
|
+
flex-direction: column;
|
|
982
|
+
align-items: stretch;
|
|
983
|
+
gap: 4px;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
.popover-actions {
|
|
917
987
|
display: flex;
|
|
918
988
|
justify-content: space-between;
|
|
919
989
|
gap: 8px;
|
|
920
990
|
}
|
|
921
991
|
|
|
922
|
-
.
|
|
992
|
+
.popover-submit-btn { margin-left: auto; border-color: var(--c-accent); color: var(--c-accent); }
|
|
923
993
|
|
|
924
994
|
.tree-row.selected { background: var(--c-selected-bg); }
|
|
925
995
|
|
|
996
|
+
/* Failed device actions (codegen); the status bar is overwritten by the next refresh. */
|
|
997
|
+
#error-toast {
|
|
998
|
+
position: fixed;
|
|
999
|
+
right: 16px;
|
|
1000
|
+
bottom: 16px;
|
|
1001
|
+
max-width: 420px;
|
|
1002
|
+
padding: 10px 14px;
|
|
1003
|
+
border-radius: 6px;
|
|
1004
|
+
background: var(--c-status-error);
|
|
1005
|
+
color: #fff;
|
|
1006
|
+
font-size: 12px;
|
|
1007
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
|
|
1008
|
+
z-index: 1000;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
926
1011
|
/* ---- Element details under the view tree (codegen) ---- */
|
|
927
1012
|
|
|
928
1013
|
#tree-pane #detail-pane {
|
package/public/js/codegen.js
CHANGED
|
@@ -1,18 +1,43 @@
|
|
|
1
1
|
import { DetailPane, Inspector, ScreenshotPane, applyTheme, escQ, locatorCode, makeResizable } from './app.js'
|
|
2
2
|
import { ViewTreePane } from './view-tree.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// What the generated code runs under: the @mobilewright/test runner, or a plain script using the library.
|
|
5
|
+
// Recorded lines are the same for both, since each exposes `device` and `screen`; only the wrapper differs.
|
|
6
|
+
const TARGETS = {
|
|
7
|
+
test: {
|
|
8
|
+
render: (platform, body) => `import { test, expect } from '@mobilewright/test';
|
|
5
9
|
|
|
6
10
|
test('test', async ({ device, screen }) => {
|
|
7
|
-
});
|
|
8
|
-
|
|
11
|
+
${body}});
|
|
12
|
+
`,
|
|
13
|
+
bodyEnd: '});',
|
|
14
|
+
indent: ' ',
|
|
15
|
+
},
|
|
16
|
+
library: {
|
|
17
|
+
render: (platform, body) => `import { ${platform}, expect } from 'mobilewright';
|
|
18
|
+
|
|
19
|
+
const device = await ${platform}.launch();
|
|
20
|
+
const { screen } = device;
|
|
21
|
+
|
|
22
|
+
${body}await device.close();
|
|
23
|
+
`,
|
|
24
|
+
bodyEnd: 'await device.close();',
|
|
25
|
+
indent: '',
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DEFAULT_TARGET = 'test'
|
|
9
30
|
|
|
10
|
-
const
|
|
31
|
+
const DEFAULT_PLATFORM = 'ios'
|
|
11
32
|
|
|
12
33
|
const TREE_OPEN_STORAGE_KEY = 'mobilewright-codegen-tree-open'
|
|
13
34
|
|
|
35
|
+
const TARGET_STORAGE_KEY = 'mobilewright-codegen-target'
|
|
36
|
+
|
|
14
37
|
const COPIED_FEEDBACK_MS = 1500
|
|
15
38
|
|
|
39
|
+
const ERROR_TOAST_MS = 5000
|
|
40
|
+
|
|
16
41
|
const GESTURE_NAMES = { tap: 'Tap', doubleTap: 'Double tap', longPress: 'Long press' }
|
|
17
42
|
|
|
18
43
|
// The Inspector hides its detail pane on every refresh, which continuous refresh would do constantly,
|
|
@@ -44,10 +69,28 @@ function textOf(el) {
|
|
|
44
69
|
return String(el.text ?? el.label ?? el.value ?? '')
|
|
45
70
|
}
|
|
46
71
|
|
|
72
|
+
function canFill(el) {
|
|
73
|
+
return el.isEditable && hasArea(el) && hasRecordableLocator(el)
|
|
74
|
+
}
|
|
75
|
+
|
|
47
76
|
function hasArea(el) {
|
|
48
77
|
return Boolean(el.bounds && el.bounds.width > 0 && el.bounds.height > 0)
|
|
49
78
|
}
|
|
50
79
|
|
|
80
|
+
function readTarget() {
|
|
81
|
+
try {
|
|
82
|
+
const target = localStorage.getItem(TARGET_STORAGE_KEY)
|
|
83
|
+
return target in TARGETS ? target : DEFAULT_TARGET
|
|
84
|
+
} catch {
|
|
85
|
+
return DEFAULT_TARGET
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function renderSource(target, platform, lines) {
|
|
90
|
+
const { render, indent } = TARGETS[target]
|
|
91
|
+
return render(platform, lines.map(line => `${indent}${line}\n`).join(''))
|
|
92
|
+
}
|
|
93
|
+
|
|
51
94
|
function readTreeOpen() {
|
|
52
95
|
try {
|
|
53
96
|
return localStorage.getItem(TREE_OPEN_STORAGE_KEY) === 'true'
|
|
@@ -60,8 +103,8 @@ function centerOf({ x, y, width, height }) {
|
|
|
60
103
|
return { x: Math.round(x + width / 2), y: Math.round(y + height / 2) }
|
|
61
104
|
}
|
|
62
105
|
|
|
63
|
-
function
|
|
64
|
-
const end = source.lastIndexOf(
|
|
106
|
+
function insertBeforeBodyEnd(source, bodyEnd, line) {
|
|
107
|
+
const end = source.lastIndexOf(bodyEnd)
|
|
65
108
|
if (end === -1) {
|
|
66
109
|
return source + line + '\n'
|
|
67
110
|
}
|
|
@@ -71,7 +114,8 @@ function insertBeforeTestBodyEnd(source, line) {
|
|
|
71
114
|
class Recorder {
|
|
72
115
|
#editor = document.getElementById('code-editor')
|
|
73
116
|
#recordBtn = document.getElementById('record-btn')
|
|
74
|
-
#
|
|
117
|
+
#errorToast = document.getElementById('error-toast')
|
|
118
|
+
#errorToastTimer = null
|
|
75
119
|
// Every control above the device screen, and the subset that are hardware buttons.
|
|
76
120
|
#deviceControls = [...document.querySelectorAll('.device-btn')]
|
|
77
121
|
#hardwareButtons = [...document.querySelectorAll('.device-btn[data-button]')]
|
|
@@ -80,13 +124,23 @@ class Recorder {
|
|
|
80
124
|
#copyBtn = document.getElementById('copy-btn')
|
|
81
125
|
#treePane = document.getElementById('tree-pane')
|
|
82
126
|
#geoForm = document.getElementById('geo-popover')
|
|
127
|
+
#urlForm = document.getElementById('url-popover')
|
|
128
|
+
#fillForm = document.getElementById('fill-popover')
|
|
129
|
+
#fillBtn = document.getElementById('fill-btn')
|
|
83
130
|
#detailPane = new DetailPane()
|
|
84
|
-
#gestureButtons = [...document.querySelectorAll('.gesture-btn')]
|
|
131
|
+
#gestureButtons = [...document.querySelectorAll('.gesture-btn[data-gesture]')]
|
|
85
132
|
#detailElement = null
|
|
133
|
+
// The element Fill was clicked for; kept apart since a refresh can change the detail element meanwhile.
|
|
134
|
+
#fillElement = null
|
|
86
135
|
#viewTree
|
|
87
136
|
#isRecording = true
|
|
88
137
|
#clickMode = 'tap'
|
|
89
138
|
#inspector
|
|
139
|
+
#targetSelect = document.getElementById('target-select')
|
|
140
|
+
#target = readTarget()
|
|
141
|
+
#platform = DEFAULT_PLATFORM
|
|
142
|
+
// Every recorded line, so switching target can rebuild the source around them.
|
|
143
|
+
#lines = []
|
|
90
144
|
|
|
91
145
|
constructor() {
|
|
92
146
|
const screenshotPane = new ScreenshotPane({ showAllHighlights: false })
|
|
@@ -96,10 +150,15 @@ class Recorder {
|
|
|
96
150
|
screenshotPane,
|
|
97
151
|
elementsPane: viewTree,
|
|
98
152
|
detailPane: noDetailPane,
|
|
99
|
-
onActiveDeviceChange: device =>
|
|
153
|
+
onActiveDeviceChange: device => {
|
|
154
|
+
this.#enableDeviceControlsFor(device)
|
|
155
|
+
this.#setPlatform(device?.platform ?? this.#platform)
|
|
156
|
+
},
|
|
100
157
|
continuousRefresh: true,
|
|
101
158
|
})
|
|
102
|
-
this.#
|
|
159
|
+
this.#targetSelect.value = this.#target
|
|
160
|
+
this.#renderSource()
|
|
161
|
+
this.#targetSelect.addEventListener('change', () => this.#setTarget(this.#targetSelect.value))
|
|
103
162
|
this.#recordBtn.addEventListener('click', () => this.#setRecording(!this.#isRecording))
|
|
104
163
|
for (const btn of this.#assertButtons) {
|
|
105
164
|
btn.addEventListener('click', () => this.#setClickMode(this.#clickMode === btn.dataset.mode ? 'tap' : btn.dataset.mode))
|
|
@@ -157,6 +216,17 @@ class Recorder {
|
|
|
157
216
|
document.getElementById('geo-reset-btn').addEventListener('click', () => {
|
|
158
217
|
this.#setGeolocation(null, 'await device.setGeolocation(null);')
|
|
159
218
|
})
|
|
219
|
+
this.#urlForm.addEventListener('submit', e => {
|
|
220
|
+
e.preventDefault()
|
|
221
|
+
this.#openUrl(this.#urlForm.elements.url.value.trim())
|
|
222
|
+
})
|
|
223
|
+
this.#fillForm.addEventListener('submit', e => {
|
|
224
|
+
e.preventDefault()
|
|
225
|
+
this.#fill(this.#fillElement, this.#fillForm.elements.text.value)
|
|
226
|
+
})
|
|
227
|
+
this.#fillBtn.addEventListener('click', () => {
|
|
228
|
+
this.#fillElement = this.#detailElement
|
|
229
|
+
})
|
|
160
230
|
}
|
|
161
231
|
|
|
162
232
|
// Same outcome whether the element was clicked on the screenshot or in the view tree.
|
|
@@ -208,6 +278,24 @@ class Recorder {
|
|
|
208
278
|
for (const btn of this.#gestureButtons) {
|
|
209
279
|
btn.disabled = !hasArea(el)
|
|
210
280
|
}
|
|
281
|
+
// Only text fields can be filled, and the screen has no typing API, so fill is recorded by locator.
|
|
282
|
+
this.#fillBtn.disabled = !canFill(el)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async #openUrl(url) {
|
|
286
|
+
this.#urlForm.hidePopover()
|
|
287
|
+
await this.#perform('Open URL', '/api/open-url', { url }, `await device.openUrl('${escQ(url)}');`)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Taps, clears and types at the element's center, the same steps locator.fill() takes.
|
|
291
|
+
async #fill(el, text) {
|
|
292
|
+
this.#fillForm.hidePopover()
|
|
293
|
+
this.#fillForm.reset()
|
|
294
|
+
if (!el || !canFill(el)) {
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
const code = `await screen.${locatorCode(el)}.fill('${escQ(text)}');`
|
|
298
|
+
await this.#perform('Fill', '/api/fill', { ...centerOf(el.bounds), text }, code)
|
|
211
299
|
}
|
|
212
300
|
|
|
213
301
|
async #setGeolocation(geolocation, codeLine) {
|
|
@@ -220,8 +308,7 @@ class Recorder {
|
|
|
220
308
|
try {
|
|
221
309
|
await navigator.clipboard.writeText(this.#editor.value)
|
|
222
310
|
} catch (err) {
|
|
223
|
-
this.#
|
|
224
|
-
this.#statusBar.className = 'error'
|
|
311
|
+
this.#showError(`Copy failed: ${err.message}`)
|
|
225
312
|
return
|
|
226
313
|
}
|
|
227
314
|
icon.classList.replace('codicon-files', 'codicon-check')
|
|
@@ -251,8 +338,46 @@ class Recorder {
|
|
|
251
338
|
document.body.dataset.clickMode = clickMode
|
|
252
339
|
}
|
|
253
340
|
|
|
341
|
+
#showError(message) {
|
|
342
|
+
this.#errorToast.textContent = message
|
|
343
|
+
this.#errorToast.hidden = false
|
|
344
|
+
clearTimeout(this.#errorToastTimer)
|
|
345
|
+
this.#errorToastTimer = setTimeout(() => {
|
|
346
|
+
this.#errorToast.hidden = true
|
|
347
|
+
}, ERROR_TOAST_MS)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Inserted into the editor rather than re-rendered, so edits made by hand are kept.
|
|
254
351
|
#appendLine(codeLine) {
|
|
255
|
-
|
|
352
|
+
const { bodyEnd, indent } = TARGETS[this.#target]
|
|
353
|
+
this.#lines.push(codeLine)
|
|
354
|
+
this.#editor.value = insertBeforeBodyEnd(this.#editor.value, bodyEnd, `${indent}${codeLine}`)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Rebuilds the whole source from the recorded lines; edits made by hand are lost.
|
|
358
|
+
#renderSource() {
|
|
359
|
+
this.#editor.value = renderSource(this.#target, this.#platform, this.#lines)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
#setTarget(target) {
|
|
363
|
+
this.#target = target
|
|
364
|
+
try {
|
|
365
|
+
localStorage.setItem(TARGET_STORAGE_KEY, target)
|
|
366
|
+
} catch {
|
|
367
|
+
// storage unavailable (private mode); the choice still applies to this page
|
|
368
|
+
}
|
|
369
|
+
this.#renderSource()
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// The library script launches by platform, so its source follows the selected device.
|
|
373
|
+
#setPlatform(platform) {
|
|
374
|
+
if (platform === this.#platform) {
|
|
375
|
+
return
|
|
376
|
+
}
|
|
377
|
+
this.#platform = platform
|
|
378
|
+
if (this.#target === 'library') {
|
|
379
|
+
this.#renderSource()
|
|
380
|
+
}
|
|
256
381
|
}
|
|
257
382
|
|
|
258
383
|
#setRecording(isRecording) {
|
|
@@ -282,8 +407,7 @@ class Recorder {
|
|
|
282
407
|
throw new Error(err.error ?? res.statusText)
|
|
283
408
|
}
|
|
284
409
|
} catch (err) {
|
|
285
|
-
this.#
|
|
286
|
-
this.#statusBar.className = 'error'
|
|
410
|
+
this.#showError(`${actionName} failed: ${err.message}`)
|
|
287
411
|
return
|
|
288
412
|
}
|
|
289
413
|
if (this.#isRecording) {
|
package/public/js/view-tree.js
CHANGED
|
@@ -140,11 +140,11 @@ export class ViewTreePane {
|
|
|
140
140
|
if (name) {
|
|
141
141
|
const nameEl = document.createElement('span')
|
|
142
142
|
nameEl.className = 'tree-name'
|
|
143
|
-
nameEl.textContent =
|
|
143
|
+
nameEl.textContent = `: ${name}`
|
|
144
144
|
row.appendChild(nameEl)
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
row.title = name ? `${el.type}
|
|
147
|
+
row.title = name ? `${el.type}: ${name}` : el.type
|
|
148
148
|
row.addEventListener('mouseenter', () => this.#onHoverCb?.(el))
|
|
149
149
|
row.addEventListener('mouseleave', () => this.#onHoverCb?.(null))
|
|
150
150
|
row.addEventListener('click', () => this.#onClickCb?.(el))
|