@peers-app/peers-ui 0.33.23 → 0.34.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/dist/command-palette/command-palette.js +4 -2
- package/dist/components/router.d.ts +1 -0
- package/dist/components/router.js +4 -1
- package/dist/host-shell/host-shell-consumer.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -1
- package/dist/isolated-screens/config.d.ts +51 -0
- package/dist/isolated-screens/config.js +73 -0
- package/dist/isolated-screens/frame-autostart.d.ts +1 -0
- package/dist/isolated-screens/frame-autostart.js +18 -0
- package/dist/isolated-screens/frame-bridge.d.ts +30 -0
- package/dist/isolated-screens/frame-bridge.js +113 -0
- package/dist/isolated-screens/frame-component.d.ts +6 -0
- package/dist/isolated-screens/frame-component.js +20 -0
- package/dist/isolated-screens/frame-document.d.ts +26 -0
- package/dist/isolated-screens/frame-document.js +69 -0
- package/dist/isolated-screens/frame-policy.d.ts +17 -0
- package/dist/isolated-screens/frame-policy.js +230 -0
- package/dist/isolated-screens/frame-protocol.d.ts +185 -0
- package/dist/isolated-screens/frame-protocol.js +139 -0
- package/dist/isolated-screens/frame-pvars.d.ts +33 -0
- package/dist/isolated-screens/frame-pvars.js +152 -0
- package/dist/isolated-screens/frame-realm.d.ts +12 -0
- package/dist/isolated-screens/frame-realm.js +31 -0
- package/dist/isolated-screens/frame-runtime.d.ts +5 -0
- package/dist/isolated-screens/frame-runtime.js +416 -0
- package/dist/isolated-screens/frame-storage.d.ts +43 -0
- package/dist/isolated-screens/frame-storage.js +85 -0
- package/dist/isolated-screens/index.d.ts +3 -0
- package/dist/isolated-screens/index.js +13 -0
- package/dist/isolated-screens/isolated-screen.d.ts +191 -0
- package/dist/isolated-screens/isolated-screen.js +684 -0
- package/dist/isolated-screens/piece-frames.d.ts +27 -0
- package/dist/isolated-screens/piece-frames.js +311 -0
- package/dist/isolated-screens/piece-reach.d.ts +11 -0
- package/dist/isolated-screens/piece-reach.js +56 -0
- package/dist/isolated-screens/port-channel.d.ts +47 -0
- package/dist/isolated-screens/port-channel.js +153 -0
- package/dist/isolated-screens/routes-sandbox.d.ts +8 -0
- package/dist/isolated-screens/routes-sandbox.js +130 -0
- package/dist/isolated-screens/screen-tab-context.d.ts +4 -0
- package/dist/isolated-screens/screen-tab-context.js +6 -0
- package/dist/isolated-screens/test-ports.d.ts +3 -0
- package/dist/isolated-screens/test-ports.js +21 -0
- package/dist/mentions/mentions-client.js +9 -0
- package/dist/notifications/index.js +9 -5
- package/dist/operator-console/console-copy.d.ts +15 -0
- package/dist/operator-console/console-copy.js +97 -0
- package/dist/operator-console/console-header.d.ts +33 -0
- package/dist/operator-console/console-header.js +67 -0
- package/dist/operator-console/console-input.d.ts +20 -0
- package/dist/operator-console/console-input.js +313 -0
- package/dist/operator-console/console-repl.d.ts +7 -0
- package/dist/operator-console/console-repl.js +108 -0
- package/dist/operator-console/console-scope.d.ts +45 -0
- package/dist/operator-console/console-scope.js +174 -0
- package/dist/operator-console/console-screen.d.ts +8 -0
- package/dist/operator-console/console-screen.js +32 -0
- package/dist/operator-console/console-session.d.ts +106 -0
- package/dist/operator-console/console-session.js +567 -0
- package/dist/operator-console/console-test-host.d.ts +21 -0
- package/dist/operator-console/console-test-host.js +114 -0
- package/dist/operator-console/console-theme.d.ts +41 -0
- package/dist/operator-console/console-theme.js +55 -0
- package/dist/operator-console/console-value.d.ts +27 -0
- package/dist/operator-console/console-value.js +291 -0
- package/dist/operator-console/operator-console-state.js +3 -1
- package/dist/operator-console/operator-console.d.ts +8 -21
- package/dist/operator-console/operator-console.js +8 -61
- package/dist/root-layout/app-shell-height.d.ts +24 -3
- package/dist/root-layout/app-shell-height.js +25 -4
- package/dist/root-layout/host-app-menu.d.ts +17 -0
- package/dist/root-layout/host-app-menu.js +22 -0
- package/dist/root-layout/layouts/full-screen-layout.js +7 -1
- package/dist/root-layout/layouts/tabs-with-console-layout.js +1 -1
- package/dist/system-apps/console.app.d.ts +15 -0
- package/dist/system-apps/console.app.js +25 -0
- package/dist/system-apps/index.d.ts +1 -0
- package/dist/system-apps/index.js +6 -1
- package/dist/tabs-layout/tabs-layout.js +13 -20
- package/dist/tabs-layout/tabs-state.js +39 -16
- package/dist/theme.css +66 -0
- package/dist/ui-contracts/piece-height.d.ts +18 -0
- package/dist/ui-contracts/piece-height.js +15 -0
- package/dist/ui-contracts/piece-host.d.ts +24 -1
- package/dist/ui-contracts/piece-host.js +53 -2
- package/dist/ui-contracts/piece-props.d.ts +16 -0
- package/dist/ui-contracts/piece-props.js +39 -0
- package/dist/ui-contracts/piece-resolution.d.ts +5 -0
- package/dist/ui-contracts/piece-resolution.js +38 -2
- package/dist/ui-contracts/piece.d.ts +2 -7
- package/dist/ui-contracts/piece.js +22 -37
- package/dist/ui-contracts/popover-surface.d.ts +14 -0
- package/dist/ui-contracts/popover-surface.js +32 -3
- package/dist/ui-inspection/dom-actions.d.ts +23 -0
- package/dist/ui-inspection/dom-actions.js +169 -0
- package/dist/ui-inspection/dom-inspector.d.ts +20 -0
- package/dist/ui-inspection/dom-inspector.js +184 -0
- package/dist/ui-inspection/index.d.ts +73 -0
- package/dist/ui-inspection/index.js +147 -0
- package/dist/ui-router/find-route.d.ts +6 -0
- package/dist/ui-router/find-route.js +22 -0
- package/dist/ui-router/routes-loader.js +23 -4
- package/dist/ui-router/runnable-version.js +3 -0
- package/dist/ui-router/ui-loader.d.ts +6 -1
- package/dist/ui-router/ui-loader.js +102 -26
- package/package.json +3 -3
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* What `peers ui inspect` reads of one document: its visible text and interactive elements. The
|
|
4
|
+
* host's window runs it, and so does each isolated package screen's frame for its own document
|
|
5
|
+
* (`ui-inspection/index.ts` merges them).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isElementHidden = isElementHidden;
|
|
9
|
+
exports.getDocumentUIState = getDocumentUIState;
|
|
10
|
+
/**
|
|
11
|
+
* Check if an element or any of its ancestors is hidden
|
|
12
|
+
* This handles cases where a parent container has display:none (like inactive tabs)
|
|
13
|
+
*/
|
|
14
|
+
function isElementHidden(el) {
|
|
15
|
+
let current = el;
|
|
16
|
+
while (current && current !== document.body) {
|
|
17
|
+
const style = getComputedStyle(current);
|
|
18
|
+
if (style.display === "none" || style.visibility === "hidden") {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
current = current.parentElement;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generate a unique CSS selector for an element
|
|
27
|
+
*/
|
|
28
|
+
function getSelector(el) {
|
|
29
|
+
if (el.id) {
|
|
30
|
+
return `#${CSS.escape(el.id)}`;
|
|
31
|
+
}
|
|
32
|
+
const path = [];
|
|
33
|
+
let current = el;
|
|
34
|
+
while (current && current !== document.body) {
|
|
35
|
+
let selector = current.tagName.toLowerCase();
|
|
36
|
+
if (current.className && typeof current.className === "string") {
|
|
37
|
+
const classes = current.className
|
|
38
|
+
.trim()
|
|
39
|
+
.split(/\s+/)
|
|
40
|
+
.filter((c) => c && !c.startsWith("_"));
|
|
41
|
+
if (classes.length > 0) {
|
|
42
|
+
selector += `.${classes
|
|
43
|
+
.slice(0, 2)
|
|
44
|
+
.map((name) => CSS.escape(name))
|
|
45
|
+
.join(".")}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Index among same-tag siblings for uniqueness: that is :nth-of-type, not :nth-child.
|
|
49
|
+
const parent = current.parentElement;
|
|
50
|
+
if (parent) {
|
|
51
|
+
const tagName = current.tagName;
|
|
52
|
+
const siblings = Array.from(parent.children).filter((c) => c.tagName === tagName);
|
|
53
|
+
if (siblings.length > 1) {
|
|
54
|
+
const index = siblings.indexOf(current) + 1;
|
|
55
|
+
selector += `:nth-of-type(${index})`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
path.unshift(selector);
|
|
59
|
+
current = current.parentElement;
|
|
60
|
+
}
|
|
61
|
+
return ["body", ...path].join(" > ");
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get all visible text content from the page
|
|
65
|
+
*/
|
|
66
|
+
function getVisibleText() {
|
|
67
|
+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, {
|
|
68
|
+
acceptNode: (node) => {
|
|
69
|
+
const parent = node.parentElement;
|
|
70
|
+
if (!parent)
|
|
71
|
+
return NodeFilter.FILTER_REJECT;
|
|
72
|
+
// Check if element or any ancestor is hidden (handles inactive tabs)
|
|
73
|
+
if (isElementHidden(parent)) {
|
|
74
|
+
return NodeFilter.FILTER_REJECT;
|
|
75
|
+
}
|
|
76
|
+
const tag = parent.tagName.toLowerCase();
|
|
77
|
+
if (["script", "style", "noscript"].includes(tag)) {
|
|
78
|
+
return NodeFilter.FILTER_REJECT;
|
|
79
|
+
}
|
|
80
|
+
const text = node.textContent?.trim();
|
|
81
|
+
if (!text)
|
|
82
|
+
return NodeFilter.FILTER_REJECT;
|
|
83
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
const texts = [];
|
|
87
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
88
|
+
const text = node.textContent?.trim();
|
|
89
|
+
if (text)
|
|
90
|
+
texts.push(text);
|
|
91
|
+
}
|
|
92
|
+
return texts.join(" ");
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get all interactive elements from the page
|
|
96
|
+
*/
|
|
97
|
+
function getInteractiveElements(includeRects) {
|
|
98
|
+
const elements = [];
|
|
99
|
+
const interactiveSelectors = 'button, a, input, textarea, select, [role="button"], [onclick], [tabindex]:not([tabindex="-1"])';
|
|
100
|
+
document.querySelectorAll(interactiveSelectors).forEach((el) => {
|
|
101
|
+
const htmlEl = el;
|
|
102
|
+
// Skip hidden elements (including those in inactive tabs)
|
|
103
|
+
if (isElementHidden(htmlEl))
|
|
104
|
+
return;
|
|
105
|
+
const tag = el.tagName.toLowerCase();
|
|
106
|
+
const uiEl = {
|
|
107
|
+
tag,
|
|
108
|
+
selector: getSelector(el),
|
|
109
|
+
};
|
|
110
|
+
// Get text content
|
|
111
|
+
const text = htmlEl.innerText?.trim() || htmlEl.getAttribute("aria-label") || htmlEl.getAttribute("title");
|
|
112
|
+
if (text)
|
|
113
|
+
uiEl.text = text.substring(0, 100); // Limit text length
|
|
114
|
+
// Input-specific properties
|
|
115
|
+
if (el instanceof HTMLInputElement) {
|
|
116
|
+
uiEl.type = el.type;
|
|
117
|
+
if (el.type !== "password") {
|
|
118
|
+
uiEl.value = el.value;
|
|
119
|
+
}
|
|
120
|
+
if (el.placeholder)
|
|
121
|
+
uiEl.placeholder = el.placeholder;
|
|
122
|
+
}
|
|
123
|
+
else if (el instanceof HTMLTextAreaElement) {
|
|
124
|
+
uiEl.type = "textarea";
|
|
125
|
+
uiEl.value = el.value;
|
|
126
|
+
if (el.placeholder)
|
|
127
|
+
uiEl.placeholder = el.placeholder;
|
|
128
|
+
}
|
|
129
|
+
else if (el instanceof HTMLSelectElement) {
|
|
130
|
+
uiEl.type = "select";
|
|
131
|
+
uiEl.value = el.value;
|
|
132
|
+
}
|
|
133
|
+
// Link href
|
|
134
|
+
if (el instanceof HTMLAnchorElement && el.href) {
|
|
135
|
+
uiEl.href = el.href;
|
|
136
|
+
}
|
|
137
|
+
// Disabled state
|
|
138
|
+
if (htmlEl.hasAttribute("disabled") || htmlEl.getAttribute("aria-disabled") === "true") {
|
|
139
|
+
uiEl.disabled = true;
|
|
140
|
+
}
|
|
141
|
+
// Bounding rect
|
|
142
|
+
if (includeRects) {
|
|
143
|
+
const rect = htmlEl.getBoundingClientRect();
|
|
144
|
+
uiEl.rect = {
|
|
145
|
+
x: Math.round(rect.x),
|
|
146
|
+
y: Math.round(rect.y),
|
|
147
|
+
width: Math.round(rect.width),
|
|
148
|
+
height: Math.round(rect.height),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
elements.push(uiEl);
|
|
152
|
+
});
|
|
153
|
+
return elements;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get current route from hash or pathname
|
|
157
|
+
*/
|
|
158
|
+
function getRoute() {
|
|
159
|
+
const hash = window.location.hash;
|
|
160
|
+
if (hash && hash !== "#") {
|
|
161
|
+
return hash.substring(1); // Remove leading #
|
|
162
|
+
}
|
|
163
|
+
const path = window.location.pathname;
|
|
164
|
+
if (path && path !== "/") {
|
|
165
|
+
return path;
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Read this document's UI state for `peers ui inspect`: its route, visible text and interactive
|
|
171
|
+
* elements. It doesn't look inside frames; `inspectUI` does that.
|
|
172
|
+
*
|
|
173
|
+
* @param options.includeRects - Include each element's rectangle, in this window's coordinates.
|
|
174
|
+
*/
|
|
175
|
+
function getDocumentUIState(options) {
|
|
176
|
+
const includeRects = options?.includeRects ?? false;
|
|
177
|
+
return {
|
|
178
|
+
url: window.location.href,
|
|
179
|
+
title: document.title,
|
|
180
|
+
route: getRoute(),
|
|
181
|
+
text: getVisibleText(),
|
|
182
|
+
elements: getInteractiveElements(includeRects),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { IUIActionResult, IUIScrollInput, IUIState } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* `peers ui inspect`, `click`, `set` and `scroll` across the host's window and the isolated
|
|
4
|
+
* package screens inside it. A screen's frame can't be read from the host, so each frame answers
|
|
5
|
+
* for its own document, and the host merges the answers: a frame's text follows the host's, and
|
|
6
|
+
* its elements' selectors start with the frame (`peers-frame:<frameId> >>> …`) and their
|
|
7
|
+
* rectangles are moved into the window's coordinates. An action whose selector names a frame is
|
|
8
|
+
* sent to that frame.
|
|
9
|
+
*/
|
|
10
|
+
/** How a selector names an element inside an isolated screen's frame. */
|
|
11
|
+
export declare const FRAME_SELECTOR_PREFIX = "peers-frame:";
|
|
12
|
+
/** The separator between a frame and the selector inside it. */
|
|
13
|
+
export declare const FRAME_SELECTOR_SEPARATOR = " >>> ";
|
|
14
|
+
/** One isolated screen's frame, as inspection reaches it. */
|
|
15
|
+
export interface IInspectableFrame {
|
|
16
|
+
/** The frame's id, unique in this window. */
|
|
17
|
+
frameId: string;
|
|
18
|
+
/** Its element in the host's document. */
|
|
19
|
+
element: HTMLIFrameElement;
|
|
20
|
+
/** A name for errors: the package. */
|
|
21
|
+
label: string;
|
|
22
|
+
/** Read the frame's document. */
|
|
23
|
+
inspect(includeRects: boolean): Promise<IUIState>;
|
|
24
|
+
/** Act in the frame's document. */
|
|
25
|
+
act(operation: UIActionOperation, input: IUIActionInput): Promise<IUIActionResult>;
|
|
26
|
+
}
|
|
27
|
+
/** An action `peers ui` can take. */
|
|
28
|
+
export type UIActionOperation = "click" | "setText" | "scroll";
|
|
29
|
+
/** An action's input, as the CLI sends it. */
|
|
30
|
+
export interface IUIActionInput extends Partial<IUIScrollInput> {
|
|
31
|
+
selector?: string;
|
|
32
|
+
text?: string;
|
|
33
|
+
clear?: boolean;
|
|
34
|
+
pressEnter?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Make a frame reachable by inspection while it's mounted.
|
|
38
|
+
*
|
|
39
|
+
* @returns A function that takes it away again.
|
|
40
|
+
*/
|
|
41
|
+
export declare function registerInspectableFrame(frame: IInspectableFrame): () => void;
|
|
42
|
+
/**
|
|
43
|
+
* Read the window's UI state, the isolated screens in it included.
|
|
44
|
+
*
|
|
45
|
+
* @param options.includeRects - Include each element's rectangle, in the window's coordinates.
|
|
46
|
+
*/
|
|
47
|
+
export declare function inspectUI(options?: {
|
|
48
|
+
includeRects?: boolean;
|
|
49
|
+
}): Promise<IUIState>;
|
|
50
|
+
/**
|
|
51
|
+
* Split a selector that names an element inside a frame.
|
|
52
|
+
*
|
|
53
|
+
* @returns The frame's id and the selector inside it, or `undefined` for the host's document.
|
|
54
|
+
*/
|
|
55
|
+
export declare function splitFrameSelector(selector: string | undefined): {
|
|
56
|
+
frameId: string;
|
|
57
|
+
inner: string;
|
|
58
|
+
} | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Act on this document only: the frame runtime calls it for an action sent to its frame.
|
|
61
|
+
*
|
|
62
|
+
* @param operation - What to do.
|
|
63
|
+
* @param input - The CLI's input.
|
|
64
|
+
*/
|
|
65
|
+
export declare function actOnDocument(operation: UIActionOperation, input: IUIActionInput): IUIActionResult;
|
|
66
|
+
/**
|
|
67
|
+
* Act on the window: in the host's document, or in the frame the selector names.
|
|
68
|
+
*
|
|
69
|
+
* @param operation - What to do.
|
|
70
|
+
* @param input - The CLI's input.
|
|
71
|
+
*/
|
|
72
|
+
export declare function actOnUI(operation: UIActionOperation, input: IUIActionInput): Promise<IUIActionResult>;
|
|
73
|
+
export { getDocumentUIState } from "./dom-inspector";
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDocumentUIState = exports.FRAME_SELECTOR_SEPARATOR = exports.FRAME_SELECTOR_PREFIX = void 0;
|
|
4
|
+
exports.registerInspectableFrame = registerInspectableFrame;
|
|
5
|
+
exports.inspectUI = inspectUI;
|
|
6
|
+
exports.splitFrameSelector = splitFrameSelector;
|
|
7
|
+
exports.actOnDocument = actOnDocument;
|
|
8
|
+
exports.actOnUI = actOnUI;
|
|
9
|
+
const dom_actions_1 = require("./dom-actions");
|
|
10
|
+
const dom_inspector_1 = require("./dom-inspector");
|
|
11
|
+
/**
|
|
12
|
+
* `peers ui inspect`, `click`, `set` and `scroll` across the host's window and the isolated
|
|
13
|
+
* package screens inside it. A screen's frame can't be read from the host, so each frame answers
|
|
14
|
+
* for its own document, and the host merges the answers: a frame's text follows the host's, and
|
|
15
|
+
* its elements' selectors start with the frame (`peers-frame:<frameId> >>> …`) and their
|
|
16
|
+
* rectangles are moved into the window's coordinates. An action whose selector names a frame is
|
|
17
|
+
* sent to that frame.
|
|
18
|
+
*/
|
|
19
|
+
/** How a selector names an element inside an isolated screen's frame. */
|
|
20
|
+
exports.FRAME_SELECTOR_PREFIX = "peers-frame:";
|
|
21
|
+
/** The separator between a frame and the selector inside it. */
|
|
22
|
+
exports.FRAME_SELECTOR_SEPARATOR = " >>> ";
|
|
23
|
+
const frames = new Map();
|
|
24
|
+
/** How long a frame has to answer before inspection goes on without it. */
|
|
25
|
+
const FRAME_TIMEOUT_MS = 3000;
|
|
26
|
+
/**
|
|
27
|
+
* Make a frame reachable by inspection while it's mounted.
|
|
28
|
+
*
|
|
29
|
+
* @returns A function that takes it away again.
|
|
30
|
+
*/
|
|
31
|
+
function registerInspectableFrame(frame) {
|
|
32
|
+
frames.set(frame.frameId, frame);
|
|
33
|
+
return () => {
|
|
34
|
+
if (frames.get(frame.frameId) === frame)
|
|
35
|
+
frames.delete(frame.frameId);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function withTimeout(promise, label) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const timer = setTimeout(() => reject(new Error(`${label} didn't answer`)), FRAME_TIMEOUT_MS);
|
|
41
|
+
promise.then((value) => {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
resolve(value);
|
|
44
|
+
}, (error) => {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
reject(error);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** The mounted frames that show, in document order. */
|
|
51
|
+
function visibleFrames() {
|
|
52
|
+
return [...frames.values()]
|
|
53
|
+
.filter((frame) => frame.element.isConnected && !(0, dom_inspector_1.isElementHidden)(frame.element))
|
|
54
|
+
.sort((a, b) => a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Read the window's UI state, the isolated screens in it included.
|
|
58
|
+
*
|
|
59
|
+
* @param options.includeRects - Include each element's rectangle, in the window's coordinates.
|
|
60
|
+
*/
|
|
61
|
+
async function inspectUI(options) {
|
|
62
|
+
const includeRects = options?.includeRects === true;
|
|
63
|
+
const state = (0, dom_inspector_1.getDocumentUIState)({ includeRects });
|
|
64
|
+
for (const frame of visibleFrames()) {
|
|
65
|
+
try {
|
|
66
|
+
const inner = await withTimeout(frame.inspect(includeRects), frame.label);
|
|
67
|
+
if (inner.text)
|
|
68
|
+
state.text = state.text ? `${state.text} ${inner.text}` : inner.text;
|
|
69
|
+
const box = includeRects ? frame.element.getBoundingClientRect() : undefined;
|
|
70
|
+
for (const element of inner.elements) {
|
|
71
|
+
state.elements.push({
|
|
72
|
+
...element,
|
|
73
|
+
selector: `${exports.FRAME_SELECTOR_PREFIX}${frame.frameId}${exports.FRAME_SELECTOR_SEPARATOR}${element.selector}`,
|
|
74
|
+
...(box && element.rect
|
|
75
|
+
? {
|
|
76
|
+
rect: {
|
|
77
|
+
...element.rect,
|
|
78
|
+
x: Math.round(element.rect.x + box.x),
|
|
79
|
+
y: Math.round(element.rect.y + box.y),
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
: {}),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
88
|
+
state.text = `${state.text} [${frame.label}: ${message}]`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return state;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Split a selector that names an element inside a frame.
|
|
95
|
+
*
|
|
96
|
+
* @returns The frame's id and the selector inside it, or `undefined` for the host's document.
|
|
97
|
+
*/
|
|
98
|
+
function splitFrameSelector(selector) {
|
|
99
|
+
if (!selector?.startsWith(exports.FRAME_SELECTOR_PREFIX))
|
|
100
|
+
return undefined;
|
|
101
|
+
const rest = selector.slice(exports.FRAME_SELECTOR_PREFIX.length);
|
|
102
|
+
const at = rest.indexOf(exports.FRAME_SELECTOR_SEPARATOR);
|
|
103
|
+
if (at < 0)
|
|
104
|
+
return undefined;
|
|
105
|
+
return { frameId: rest.slice(0, at), inner: rest.slice(at + exports.FRAME_SELECTOR_SEPARATOR.length) };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Act on this document only: the frame runtime calls it for an action sent to its frame.
|
|
109
|
+
*
|
|
110
|
+
* @param operation - What to do.
|
|
111
|
+
* @param input - The CLI's input.
|
|
112
|
+
*/
|
|
113
|
+
function actOnDocument(operation, input) {
|
|
114
|
+
switch (operation) {
|
|
115
|
+
case "click":
|
|
116
|
+
return (0, dom_actions_1.doClick)(String(input.selector ?? ""));
|
|
117
|
+
case "setText":
|
|
118
|
+
return (0, dom_actions_1.doSet)(String(input.selector ?? ""), String(input.text ?? ""), {
|
|
119
|
+
clear: input.clear === true,
|
|
120
|
+
pressEnter: input.pressEnter === true,
|
|
121
|
+
});
|
|
122
|
+
case "scroll":
|
|
123
|
+
return (0, dom_actions_1.doScroll)(input);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Act on the window: in the host's document, or in the frame the selector names.
|
|
128
|
+
*
|
|
129
|
+
* @param operation - What to do.
|
|
130
|
+
* @param input - The CLI's input.
|
|
131
|
+
*/
|
|
132
|
+
async function actOnUI(operation, input) {
|
|
133
|
+
const target = splitFrameSelector(input.selector);
|
|
134
|
+
if (!target)
|
|
135
|
+
return actOnDocument(operation, input);
|
|
136
|
+
const frame = frames.get(target.frameId);
|
|
137
|
+
if (!frame)
|
|
138
|
+
return { success: false, error: `No open screen has frame ${target.frameId}` };
|
|
139
|
+
try {
|
|
140
|
+
return await withTimeout(frame.act(operation, { ...input, selector: target.inner }), frame.label);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
var dom_inspector_2 = require("./dom-inspector");
|
|
147
|
+
Object.defineProperty(exports, "getDocumentUIState", { enumerable: true, get: function () { return dom_inspector_2.getDocumentUIState; } });
|
|
@@ -13,3 +13,9 @@ export declare function registeredRoutes(): IPeersUIRoute[];
|
|
|
13
13
|
export declare function findRoute(context: UIContext & {
|
|
14
14
|
path: string;
|
|
15
15
|
}, props: Record<string, unknown>, routes?: IPeersUIRoute[]): IPeersUIRoute | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The package id peers-ui registers its own screens under; mirrors `ui-loader.tsx`. Its routes are
|
|
18
|
+
* exempt from the screen-path rule below, so no installed package may use it (`routes-loader.ts`
|
|
19
|
+
* never lists one that does).
|
|
20
|
+
*/
|
|
21
|
+
export declare const SYSTEM_PACKAGE_ID = "000peers0system000package";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SYSTEM_PACKAGE_ID = void 0;
|
|
3
4
|
exports.registeredRoutes = registeredRoutes;
|
|
4
5
|
exports.findRoute = findRoute;
|
|
5
6
|
/** The UI routes registered so far, highest priority first; empty before the shell starts. */
|
|
@@ -27,6 +28,8 @@ function findRoute(context, props, routes = registeredRoutes()) {
|
|
|
27
28
|
continue;
|
|
28
29
|
if (route.path && !pathMatches(route.path, context.path))
|
|
29
30
|
continue;
|
|
31
|
+
if (!ownsPath(route, context))
|
|
32
|
+
continue;
|
|
30
33
|
if (route.propsSchema && !route.propsSchema.safeParse(props).success)
|
|
31
34
|
continue;
|
|
32
35
|
if (route.isMatch && !route.isMatch(props, context))
|
|
@@ -35,6 +38,25 @@ function findRoute(context, props, routes = registeredRoutes()) {
|
|
|
35
38
|
}
|
|
36
39
|
return undefined;
|
|
37
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The package id peers-ui registers its own screens under; mirrors `ui-loader.tsx`. Its routes are
|
|
43
|
+
* exempt from the screen-path rule below, so no installed package may use it (`routes-loader.ts`
|
|
44
|
+
* never lists one that does).
|
|
45
|
+
*/
|
|
46
|
+
exports.SYSTEM_PACKAGE_ID = "000peers0system000package";
|
|
47
|
+
/**
|
|
48
|
+
* Whether a screen route may render this path: a package's screens render only its own paths
|
|
49
|
+
* (`package-nav/<its id>/…`), so one package can't take over another's screen with a broader
|
|
50
|
+
* or higher-priority route. peers-ui's own screens and routes that aren't screens are exempt.
|
|
51
|
+
*/
|
|
52
|
+
function ownsPath(route, context) {
|
|
53
|
+
if ((context.uiCategory !== "screen" && route.uiCategory !== "screen") ||
|
|
54
|
+
!route.packageId ||
|
|
55
|
+
route.packageId === exports.SYSTEM_PACKAGE_ID) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return /^\/*package-nav\/([^/]+)\//i.exec(context.path)?.[1] === route.packageId;
|
|
59
|
+
}
|
|
38
60
|
function pathMatches(routePath, path) {
|
|
39
61
|
// A simple regex is shorter than an `isMatch` function. Otherwise the route path is a prefix.
|
|
40
62
|
const regex = routePath.match(/^\/(.+)\/([gimsuy]{0,6})$/);
|
|
@@ -2,13 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadAllRoutes = exports.allPackages = void 0;
|
|
4
4
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
5
|
+
const config_1 = require("../isolated-screens/config");
|
|
6
|
+
const routes_sandbox_1 = require("../isolated-screens/routes-sandbox");
|
|
5
7
|
require("../ui-defaults");
|
|
6
8
|
const bundle_files_1 = require("./bundle-files");
|
|
9
|
+
const find_route_1 = require("./find-route");
|
|
7
10
|
const runnable_version_1 = require("./runnable-version");
|
|
8
11
|
/** Packages with authorized navigation metadata available in the current context. */
|
|
9
12
|
exports.allPackages = (0, peers_sdk_1.observable)([]);
|
|
10
13
|
let allRoutesLoaded = false;
|
|
11
14
|
const prefsSubscribed = new Set();
|
|
15
|
+
/**
|
|
16
|
+
* Whether a package row may be listed: enabled, with a selected version, and not using the id
|
|
17
|
+
* peers-ui's own screens are registered under. A package with that id would inherit their
|
|
18
|
+
* exemption from the screen-path rule (`findRoute`) and their routes' owner lookup, and so show
|
|
19
|
+
* its screen in other packages' tabs and in place of built-in screens.
|
|
20
|
+
*/
|
|
21
|
+
function listable(pkg) {
|
|
22
|
+
return (!!pkg && !pkg.disabled && !!pkg.activePackageVersionId && pkg.packageId !== find_route_1.SYSTEM_PACKAGE_ID);
|
|
23
|
+
}
|
|
12
24
|
/**
|
|
13
25
|
* Follow this device's version selection for a package: a new one, or a cleared one that hands
|
|
14
26
|
* the package back to the group's version, rechecks it, so its app links, icon and routes follow
|
|
@@ -49,8 +61,7 @@ function refreshPackage(packageId) {
|
|
|
49
61
|
const next = (refreshing[packageId] ?? Promise.resolve()).then(async () => {
|
|
50
62
|
try {
|
|
51
63
|
const pkg = await (0, peers_sdk_1.Packages)().get(packageId);
|
|
52
|
-
const
|
|
53
|
-
const entry = pkg && listed ? await enrichWithPvAppNavs(pkg) : undefined;
|
|
64
|
+
const entry = listable(pkg) ? await enrichWithPvAppNavs(pkg) : undefined;
|
|
54
65
|
const _allPackages = (0, exports.allPackages)();
|
|
55
66
|
const idx = _allPackages.findIndex((p) => p.packageId === packageId);
|
|
56
67
|
if (entry) {
|
|
@@ -94,7 +105,7 @@ const loadAllRoutes = async () => {
|
|
|
94
105
|
disabled: { $ne: true },
|
|
95
106
|
activePackageVersionId: { $exists: true },
|
|
96
107
|
});
|
|
97
|
-
const enriched = await Promise.all(packagesWithUI.map(enrichWithPvAppNavs));
|
|
108
|
+
const enriched = await Promise.all(packagesWithUI.filter(listable).map(enrichWithPvAppNavs));
|
|
98
109
|
(0, exports.allPackages)(enriched);
|
|
99
110
|
await Promise.all(enriched.map((pkg) => loadRoutesBundle(pkg)));
|
|
100
111
|
for (const pkg of enriched) {
|
|
@@ -133,8 +144,16 @@ function loadRoutesBundle(pkg, forceRefresh) {
|
|
|
133
144
|
if (bundleCode) {
|
|
134
145
|
if (selected?.dataContext.groupId)
|
|
135
146
|
(0, peers_sdk_1.assertPackageBundleIntegrity)(selected.pv, "routes", bundleCode);
|
|
147
|
+
const rw = window;
|
|
148
|
+
if ((0, config_1.runsIsolated)(pkg.packageId)) {
|
|
149
|
+
// Run in the routes sandbox: only its routes, as data, come back, each stamped with
|
|
150
|
+
// this package.
|
|
151
|
+
const routes = await (0, routes_sandbox_1.evaluateRoutesBundle)(pkg.packageId, bundleCode);
|
|
152
|
+
for (const route of routes)
|
|
153
|
+
rw.registerPeersUIRoute?.(route);
|
|
154
|
+
return {};
|
|
155
|
+
}
|
|
136
156
|
const exportRoutes = (peerRoutes) => {
|
|
137
|
-
const rw = window;
|
|
138
157
|
peerRoutes.routes.forEach((route) => {
|
|
139
158
|
rw.registerPeersUIRoute?.(route);
|
|
140
159
|
});
|
|
@@ -44,6 +44,9 @@ async function resolveRunnableVersion(pkg, servingPackageVersionId) {
|
|
|
44
44
|
const pv = await (0, peers_sdk_1.PackageVersions)(dataContext).get(pvId);
|
|
45
45
|
if (!pv)
|
|
46
46
|
return undefined;
|
|
47
|
+
if (pv.packageId !== stored.packageId) {
|
|
48
|
+
throw new Error(`The selected version of ${pkg.name} belongs to another package`);
|
|
49
|
+
}
|
|
47
50
|
if (pv.versionTag === "dev" && !devicePvId && !servingPackageVersionId) {
|
|
48
51
|
// Same reason resolveDevicePackageVersion unloads it with.
|
|
49
52
|
throw new Error(`Only a dev version (v${pv.version}) is selected; activate it on this device to run it`);
|
|
@@ -2,6 +2,11 @@ import { type IPeersUI, type IPeersUIRoute, type UIContext } from "@peers-app/pe
|
|
|
2
2
|
import "../ui-defaults";
|
|
3
3
|
interface IProps extends UIContext {
|
|
4
4
|
props: Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* The tab's path as it is, when `path` is a normalized form for matching (the system router
|
|
7
|
+
* lowercases it and drops the query). An isolated screen gets this one.
|
|
8
|
+
*/
|
|
9
|
+
tabPath?: string;
|
|
5
10
|
}
|
|
6
11
|
/**
|
|
7
12
|
* Pick a registered route for the current screen context and render its component.
|
|
@@ -9,7 +14,7 @@ interface IProps extends UIContext {
|
|
|
9
14
|
* @param props - Screen context, including the route props to validate.
|
|
10
15
|
*/
|
|
11
16
|
export declare const UIRouter: (props: IProps) => import("react/jsx-runtime").JSX.Element | undefined;
|
|
12
|
-
/** Package id used when peers-ui registers its own built-in screens. */
|
|
17
|
+
/** Package id used when peers-ui registers its own built-in screens. No installed package may use it. */
|
|
13
18
|
export declare const peersSystemPackageId = "000peers0system000package";
|
|
14
19
|
/**
|
|
15
20
|
* This is meant to make it easy to register components that are internal to peers
|