@lowdefy/server-dev 0.0.0-experimental-20260714194008 → 0.0.0-experimental-20260715070907
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/client/Routing.jsx +2 -0
- package/client/feedback/FeedbackMount.jsx +6 -0
- package/client/feedback/FeedbackOverlay.jsx +11 -0
- package/client/feedback/captureTabScreenshot.js +80 -0
- package/client/feedback/drawAnnotationsSvg.js +119 -0
- package/client/openInEditor/OpenInEditorListener.jsx +261 -0
- package/client/openInEditor/findBlockLocation.js +49 -0
- package/lib/docs/captureAnnotatedScreenshot.js +5 -85
- package/lib/docs/docs.test.mjs +22 -0
- package/lib/docs/findConfig.js +24 -2
- package/lib/docs/saveAnnotatedScreenshot.js +43 -0
- package/lib/docs/setupTestFixtures.mjs +8 -0
- package/lib/server/auth/getDevSession.js +70 -0
- package/lib/server/auth/getDevSession.test.mjs +138 -0
- package/lib/server/auth/{getHeadlessSession.js → getHeadlessUser.js} +9 -8
- package/lib/server/auth/{getMockSession.js → getMockUser.js} +8 -21
- package/lib/server/auth/headlessUser.js +1 -1
- package/lib/server/auth/session.js +9 -12
- package/manager/run.mjs +11 -9
- package/package.json +33 -32
- package/package.original.json +33 -32
- package/src/routes/auth.js +11 -0
- package/src/routes/auth.test.mjs +84 -0
- package/src/routes/feedback.js +43 -20
- package/src/routes/feedback.test.mjs +105 -1
package/client/Routing.jsx
CHANGED
|
@@ -22,6 +22,7 @@ import createLinkComponent from '@lowdefy/client/adapters/Link.js';
|
|
|
22
22
|
import BuildingPage from '../lib/client/BuildingPage.jsx';
|
|
23
23
|
import FeedbackMount from './feedback/FeedbackMount.jsx';
|
|
24
24
|
import Inspector from './Inspector.jsx';
|
|
25
|
+
import OpenInEditorListener from './openInEditor/OpenInEditorListener.jsx';
|
|
25
26
|
import Reload from './Reload.jsx';
|
|
26
27
|
import Page from './Page.jsx';
|
|
27
28
|
import setPageId from '../lib/client/setPageId.js';
|
|
@@ -72,6 +73,7 @@ function Routing({ auth, lowdefy, router }) {
|
|
|
72
73
|
<>
|
|
73
74
|
<Inspector basePath={router.basePath} lowdefy={lowdefy} pageId={pageId} />
|
|
74
75
|
<FeedbackMount basePath={router.basePath} lowdefy={lowdefy} pageId={pageId} />
|
|
76
|
+
<OpenInEditorListener basePath={router.basePath} pageId={pageId} />
|
|
75
77
|
<Reload basePath={router.basePath} lowdefy={lowdefy}>
|
|
76
78
|
{(resetContext) => (
|
|
77
79
|
<Suspense key={`${pageId}_${getReloadVersion()}`} fallback={<BuildingPage />}>
|
|
@@ -34,6 +34,12 @@ function logBannerOnce() {
|
|
|
34
34
|
'color: #4f9cf9; font-weight: bold;',
|
|
35
35
|
'color: inherit;'
|
|
36
36
|
);
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
console.info(
|
|
39
|
+
'%cLowdefy Open Code%c — Cmd/Ctrl+click any element to open its yaml in VS Code.',
|
|
40
|
+
'color: #4f9cf9; font-weight: bold;',
|
|
41
|
+
'color: inherit;'
|
|
42
|
+
);
|
|
37
43
|
} catch {
|
|
38
44
|
// Never let a console-styling quirk break the app.
|
|
39
45
|
}
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
injectFeedbackStyleTag,
|
|
46
46
|
removeFeedbackStyleTag,
|
|
47
47
|
} from './feedbackStyles.js';
|
|
48
|
+
import captureTabScreenshot from './captureTabScreenshot.js';
|
|
48
49
|
import copyToClipboard from './copyToClipboard.js';
|
|
49
50
|
import sendFeedback from './sendFeedback.js';
|
|
50
51
|
|
|
@@ -616,6 +617,16 @@ function FeedbackOverlay({ basePath, pageId, onClose }) {
|
|
|
616
617
|
try {
|
|
617
618
|
dispatch({ type: 'SEND_START' });
|
|
618
619
|
const batch = buildBatch({ state, pageId });
|
|
620
|
+
// Capture the annotated screenshot in THIS tab — the pixels the
|
|
621
|
+
// developer is actually looking at (theme, loaded data) — and ship it
|
|
622
|
+
// with the batch for the server to save. On failure the field is
|
|
623
|
+
// absent and the server falls back to its headless capture.
|
|
624
|
+
if (state.includeScreenshot) {
|
|
625
|
+
const screenshot = await captureTabScreenshot({ annotations: state.batch });
|
|
626
|
+
if (screenshot) {
|
|
627
|
+
batch.screenshot = screenshot;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
619
630
|
// The server enriches annotations with yaml file:line locations and
|
|
620
631
|
// returns the agent-readable text; the clipboard is the delivery
|
|
621
632
|
// channel — the developer pastes it into whichever agent session
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { toPng } from 'html-to-image';
|
|
18
|
+
|
|
19
|
+
import drawAnnotationsSvg from './drawAnnotationsSvg.js';
|
|
20
|
+
|
|
21
|
+
// Chrome caps canvas dimensions well above this, but rasterizing a very long
|
|
22
|
+
// page at retina density burns memory for no feedback value — drop to 1x
|
|
23
|
+
// instead of failing.
|
|
24
|
+
const MAX_CANVAS_DIMENSION = 16000;
|
|
25
|
+
|
|
26
|
+
function resolveBackgroundColor() {
|
|
27
|
+
try {
|
|
28
|
+
const bodyBg = getComputedStyle(document.body).backgroundColor;
|
|
29
|
+
if (bodyBg && bodyBg !== 'rgba(0, 0, 0, 0)' && bodyBg !== 'transparent') {
|
|
30
|
+
return bodyBg;
|
|
31
|
+
}
|
|
32
|
+
const htmlBg = getComputedStyle(document.documentElement).backgroundColor;
|
|
33
|
+
if (htmlBg && htmlBg !== 'rgba(0, 0, 0, 0)' && htmlBg !== 'transparent') {
|
|
34
|
+
return htmlBg;
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
// Fall through to the default.
|
|
38
|
+
}
|
|
39
|
+
return '#ffffff';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Rasterizes the developer's actual tab — theme, loaded data, exact pixels —
|
|
43
|
+
// with the batch's annotations drawn on top, and returns a PNG data URL the
|
|
44
|
+
// batch POSTs to the dev server to save. This replaces re-rendering the page
|
|
45
|
+
// headless, which diverged from what the developer was looking at (light
|
|
46
|
+
// theme, un-settled requests, no client-only state). Returns null on any
|
|
47
|
+
// failure so the server can fall back to the headless capture.
|
|
48
|
+
async function captureTabScreenshot({ annotations }) {
|
|
49
|
+
try {
|
|
50
|
+
drawAnnotationsSvg(annotations ?? []);
|
|
51
|
+
const pixelRatio =
|
|
52
|
+
Math.max(document.documentElement.scrollWidth, document.documentElement.scrollHeight) *
|
|
53
|
+
(window.devicePixelRatio || 1) >
|
|
54
|
+
MAX_CANVAS_DIMENSION
|
|
55
|
+
? 1
|
|
56
|
+
: window.devicePixelRatio || 1;
|
|
57
|
+
const dataUrl = await toPng(document.documentElement, {
|
|
58
|
+
// Keep everything except the overlay's own UI (panels, tray, chips).
|
|
59
|
+
// The annotation SVG lives outside the overlay root, so it stays in.
|
|
60
|
+
filter: (node) =>
|
|
61
|
+
!(node instanceof Element && node.hasAttribute('data-lowdefy-feedback')),
|
|
62
|
+
pixelRatio,
|
|
63
|
+
backgroundColor: resolveBackgroundColor(),
|
|
64
|
+
});
|
|
65
|
+
if (typeof dataUrl === 'string' && dataUrl.startsWith('data:image/png')) {
|
|
66
|
+
return dataUrl;
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
} finally {
|
|
72
|
+
try {
|
|
73
|
+
document.getElementById('lowdefy-feedback-annotations-svg')?.remove();
|
|
74
|
+
} catch {
|
|
75
|
+
// Never let cleanup break the send flow.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default captureTabScreenshot;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Draws a batch's annotations (element outlines with index labels, plus the
|
|
18
|
+
// drawn rect/arrow/freehand shapes) as an SVG layer appended to document.body,
|
|
19
|
+
// id "lowdefy-feedback-annotations-svg" — callers remove it by id when done.
|
|
20
|
+
//
|
|
21
|
+
// Shared by two capture paths, so it MUST stay fully self-contained (no outer
|
|
22
|
+
// imports or closures): captureTabScreenshot.js calls it directly in the
|
|
23
|
+
// developer's tab, and captureAnnotatedScreenshot.js passes it to Playwright's
|
|
24
|
+
// page.evaluate, which serializes the function source into the headless page.
|
|
25
|
+
//
|
|
26
|
+
// Geometry is viewport-relative at the recorded scroll offset. The layer is
|
|
27
|
+
// positioned absolute at the CURRENT scroll offset (document coordinates
|
|
28
|
+
// covering the visible viewport box), which lands the shapes correctly both in
|
|
29
|
+
// a full-document rasterization (in-tab) and in a viewport screenshot after
|
|
30
|
+
// scrolling to the recorded offset (headless).
|
|
31
|
+
function drawAnnotationsSvg(annotations) {
|
|
32
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
33
|
+
const svg = document.createElementNS(NS, 'svg');
|
|
34
|
+
svg.setAttribute('id', 'lowdefy-feedback-annotations-svg');
|
|
35
|
+
svg.setAttribute(
|
|
36
|
+
'style',
|
|
37
|
+
`position:absolute;left:${window.scrollX}px;top:${window.scrollY}px;` +
|
|
38
|
+
`width:${window.innerWidth}px;height:${window.innerHeight}px;` +
|
|
39
|
+
'pointer-events:none;z-index:2147483000;'
|
|
40
|
+
);
|
|
41
|
+
const defs = document.createElementNS(NS, 'defs');
|
|
42
|
+
const marker = document.createElementNS(NS, 'marker');
|
|
43
|
+
marker.setAttribute('id', 'ldf-annotation-arrowhead');
|
|
44
|
+
marker.setAttribute('markerWidth', '10');
|
|
45
|
+
marker.setAttribute('markerHeight', '8');
|
|
46
|
+
marker.setAttribute('refX', '9');
|
|
47
|
+
marker.setAttribute('refY', '4');
|
|
48
|
+
marker.setAttribute('orient', 'auto');
|
|
49
|
+
const head = document.createElementNS(NS, 'polygon');
|
|
50
|
+
head.setAttribute('points', '0 0, 10 4, 0 8');
|
|
51
|
+
head.setAttribute('fill', '#ff4785');
|
|
52
|
+
marker.appendChild(head);
|
|
53
|
+
defs.appendChild(marker);
|
|
54
|
+
svg.appendChild(defs);
|
|
55
|
+
|
|
56
|
+
const stroke = '#ff4785';
|
|
57
|
+
annotations.forEach((annotation, index) => {
|
|
58
|
+
const rect = annotation.geometry?.elementRect;
|
|
59
|
+
if (rect) {
|
|
60
|
+
const outline = document.createElementNS(NS, 'rect');
|
|
61
|
+
outline.setAttribute('x', rect.x);
|
|
62
|
+
outline.setAttribute('y', rect.y);
|
|
63
|
+
outline.setAttribute('width', rect.width);
|
|
64
|
+
outline.setAttribute('height', rect.height);
|
|
65
|
+
outline.setAttribute('fill', 'rgba(255,71,133,0.08)');
|
|
66
|
+
outline.setAttribute('stroke', stroke);
|
|
67
|
+
outline.setAttribute('stroke-width', '2');
|
|
68
|
+
svg.appendChild(outline);
|
|
69
|
+
const label = document.createElementNS(NS, 'text');
|
|
70
|
+
label.setAttribute('x', rect.x);
|
|
71
|
+
label.setAttribute('y', Math.max(12, rect.y - 6));
|
|
72
|
+
label.setAttribute('fill', stroke);
|
|
73
|
+
label.setAttribute('font-size', '12');
|
|
74
|
+
label.setAttribute('font-family', 'system-ui, sans-serif');
|
|
75
|
+
label.setAttribute('font-weight', '600');
|
|
76
|
+
label.textContent = `${index + 1}`;
|
|
77
|
+
svg.appendChild(label);
|
|
78
|
+
}
|
|
79
|
+
(annotation.geometry?.shapes ?? []).forEach((shape) => {
|
|
80
|
+
if (shape.type === 'rect' && shape.points?.length >= 2) {
|
|
81
|
+
const [a, b] = shape.points;
|
|
82
|
+
const el = document.createElementNS(NS, 'rect');
|
|
83
|
+
el.setAttribute('x', Math.min(a.x, b.x));
|
|
84
|
+
el.setAttribute('y', Math.min(a.y, b.y));
|
|
85
|
+
el.setAttribute('width', Math.abs(b.x - a.x));
|
|
86
|
+
el.setAttribute('height', Math.abs(b.y - a.y));
|
|
87
|
+
el.setAttribute('fill', 'rgba(255,71,133,0.08)');
|
|
88
|
+
el.setAttribute('stroke', stroke);
|
|
89
|
+
el.setAttribute('stroke-width', '2.5');
|
|
90
|
+
svg.appendChild(el);
|
|
91
|
+
}
|
|
92
|
+
if (shape.type === 'arrow' && shape.points?.length >= 2) {
|
|
93
|
+
const [tail, headPoint] = shape.points;
|
|
94
|
+
const el = document.createElementNS(NS, 'line');
|
|
95
|
+
el.setAttribute('x1', tail.x);
|
|
96
|
+
el.setAttribute('y1', tail.y);
|
|
97
|
+
el.setAttribute('x2', headPoint.x);
|
|
98
|
+
el.setAttribute('y2', headPoint.y);
|
|
99
|
+
el.setAttribute('stroke', stroke);
|
|
100
|
+
el.setAttribute('stroke-width', '2.5');
|
|
101
|
+
el.setAttribute('marker-end', 'url(#ldf-annotation-arrowhead)');
|
|
102
|
+
svg.appendChild(el);
|
|
103
|
+
}
|
|
104
|
+
if (shape.type === 'freehand' && shape.points?.length >= 2) {
|
|
105
|
+
const el = document.createElementNS(NS, 'polyline');
|
|
106
|
+
el.setAttribute('points', shape.points.map((p) => `${p.x},${p.y}`).join(' '));
|
|
107
|
+
el.setAttribute('fill', 'none');
|
|
108
|
+
el.setAttribute('stroke', stroke);
|
|
109
|
+
el.setAttribute('stroke-width', '2.5');
|
|
110
|
+
el.setAttribute('stroke-linejoin', 'round');
|
|
111
|
+
el.setAttribute('stroke-linecap', 'round');
|
|
112
|
+
svg.appendChild(el);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
document.body.appendChild(svg);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default drawAnnotationsSvg;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
18
|
+
import { createPortal } from 'react-dom';
|
|
19
|
+
|
|
20
|
+
import { blockAncestorChain, nearestBlock } from '../feedback/elementInspect.js';
|
|
21
|
+
import { highlightBox, labelChip, overlayContainer } from '../feedback/feedbackStyles.js';
|
|
22
|
+
import findBlockLocation from './findBlockLocation.js';
|
|
23
|
+
|
|
24
|
+
const STYLE_TAG_ID = 'lowdefy-open-in-editor-style-tag';
|
|
25
|
+
const BODY_CLASS = 'lowdefy-open-in-editor-target';
|
|
26
|
+
|
|
27
|
+
// Cursor over arbitrary app descendants can't be forced from inline styles —
|
|
28
|
+
// same trick as feedbackStyles' picking/drawing classes.
|
|
29
|
+
function injectStyleTag() {
|
|
30
|
+
if (typeof document === 'undefined' || document.getElementById(STYLE_TAG_ID)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const style = document.createElement('style');
|
|
34
|
+
style.id = STYLE_TAG_ID;
|
|
35
|
+
style.textContent = `
|
|
36
|
+
.${BODY_CLASS}, .${BODY_CLASS} * {
|
|
37
|
+
cursor: pointer !important;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
document.head.appendChild(style);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function removeStyleTag() {
|
|
44
|
+
if (typeof document === 'undefined') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
document.getElementById(STYLE_TAG_ID)?.remove();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The feedback overlay owns clicks while it is open (its picking mode claims
|
|
51
|
+
// them) — the Cmd/Ctrl+click shortcut stays out of the way until it closes.
|
|
52
|
+
// :not() skips this component's own highlight portal, which carries
|
|
53
|
+
// data-lowdefy-feedback purely for screenshot/picking exclusion.
|
|
54
|
+
function feedbackOverlayOpen() {
|
|
55
|
+
return Boolean(
|
|
56
|
+
document.querySelector('[data-lowdefy-feedback]:not([data-lowdefy-open-in-editor])')
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Dev-only: Cmd/Ctrl+click any element to open the YAML that defines its
|
|
61
|
+
// block in VS Code (vscode://file deep link, at the exact line). While the
|
|
62
|
+
// modifier is held, the hovered block shows the same blue highlight box and
|
|
63
|
+
// blockId chip as the annotation overlay's picking mode, and the cursor
|
|
64
|
+
// switches to a pointer — so the developer sees exactly what a click will
|
|
65
|
+
// open. Mounted always-on from Routing.jsx alongside Inspector and
|
|
66
|
+
// FeedbackMount, and follows their resilience contract — every handler is
|
|
67
|
+
// try/caught so this can never take the app down with it.
|
|
68
|
+
//
|
|
69
|
+
// The click resolves the nearest block and, when that id is generated at
|
|
70
|
+
// runtime (list items, Dynamic endpoints), falls back through the ancestor
|
|
71
|
+
// block chain until an id resolves in config — the same strategy the
|
|
72
|
+
// feedback pipeline uses in enrichFeedback.js.
|
|
73
|
+
function OpenInEditorListener({ basePath, pageId }) {
|
|
74
|
+
const [hoverBlock, setHoverBlock] = useState(null); // { blockId, rect }
|
|
75
|
+
// Refs keep the freshest values without re-binding the capture listeners
|
|
76
|
+
// on every SPA navigation or hover change.
|
|
77
|
+
const pageIdRef = useRef(pageId);
|
|
78
|
+
pageIdRef.current = pageId;
|
|
79
|
+
const hoverRef = useRef(hoverBlock);
|
|
80
|
+
hoverRef.current = hoverBlock;
|
|
81
|
+
const lastPointerRef = useRef(null); // { x, y }
|
|
82
|
+
|
|
83
|
+
// Style tag lifecycle — the listener is always mounted, so this lives for
|
|
84
|
+
// the app's lifetime and only the body class toggles per hover.
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
injectStyleTag();
|
|
87
|
+
return () => removeStyleTag();
|
|
88
|
+
}, []);
|
|
89
|
+
|
|
90
|
+
// Pointer cursor only while a block is highlighted — over non-block areas
|
|
91
|
+
// the cursor stays native, signalling the click would do nothing.
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
try {
|
|
94
|
+
document.body.classList.toggle(BODY_CLASS, Boolean(hoverBlock));
|
|
95
|
+
} catch {
|
|
96
|
+
// no-op
|
|
97
|
+
}
|
|
98
|
+
return () => {
|
|
99
|
+
try {
|
|
100
|
+
document.body.classList.remove(BODY_CLASS);
|
|
101
|
+
} catch {
|
|
102
|
+
// no-op
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}, [hoverBlock]);
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
function clearHover() {
|
|
109
|
+
if (hoverRef.current) {
|
|
110
|
+
setHoverBlock(null);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function resolveHover() {
|
|
115
|
+
try {
|
|
116
|
+
const point = lastPointerRef.current;
|
|
117
|
+
if (!point || feedbackOverlayOpen()) {
|
|
118
|
+
clearHover();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const el = document.elementFromPoint(point.x, point.y);
|
|
122
|
+
const blockId = nearestBlock(el);
|
|
123
|
+
const blockEl = blockId ? document.getElementById(`bl-${blockId}`) : null;
|
|
124
|
+
if (!blockEl) {
|
|
125
|
+
clearHover();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const rect = blockEl.getBoundingClientRect();
|
|
129
|
+
setHoverBlock({
|
|
130
|
+
blockId,
|
|
131
|
+
rect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height },
|
|
132
|
+
});
|
|
133
|
+
} catch {
|
|
134
|
+
clearHover();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function onPointerMove(event) {
|
|
139
|
+
try {
|
|
140
|
+
lastPointerRef.current = { x: event.clientX, y: event.clientY };
|
|
141
|
+
if (event.metaKey || event.ctrlKey) {
|
|
142
|
+
resolveHover();
|
|
143
|
+
} else {
|
|
144
|
+
clearHover();
|
|
145
|
+
}
|
|
146
|
+
} catch {
|
|
147
|
+
// Best-effort hover tracking.
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Modifier pressed/released while the mouse is stationary — pointermove
|
|
152
|
+
// alone would leave the highlight stale.
|
|
153
|
+
function onKeyDown(event) {
|
|
154
|
+
if (event.key === 'Meta' || event.key === 'Control') {
|
|
155
|
+
resolveHover();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function onKeyUp(event) {
|
|
160
|
+
if (event.key === 'Meta' || event.key === 'Control') {
|
|
161
|
+
clearHover();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Cmd+Tab away releases the modifier without a keyup reaching the page.
|
|
166
|
+
function onBlur() {
|
|
167
|
+
clearHover();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Keep the highlight glued to the block while the app scrolls under a
|
|
171
|
+
// stationary cursor.
|
|
172
|
+
function onScroll() {
|
|
173
|
+
if (hoverRef.current) {
|
|
174
|
+
resolveHover();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function openBlockInEditor({ candidates }) {
|
|
179
|
+
for (const blockId of candidates) {
|
|
180
|
+
const location = await findBlockLocation({
|
|
181
|
+
basePath,
|
|
182
|
+
blockId,
|
|
183
|
+
pageId: pageIdRef.current,
|
|
184
|
+
});
|
|
185
|
+
if (location) {
|
|
186
|
+
window.location.assign(`vscode://file${location.file}:${location.line}`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
// eslint-disable-next-line no-console
|
|
192
|
+
console.info(
|
|
193
|
+
`Lowdefy: no config location found for "${candidates[0]}" — the block is generated at runtime.`
|
|
194
|
+
);
|
|
195
|
+
} catch {
|
|
196
|
+
// no-op
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function onClickCapture(event) {
|
|
201
|
+
try {
|
|
202
|
+
if (!(event.metaKey || event.ctrlKey) || event.shiftKey || event.altKey) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (feedbackOverlayOpen()) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const candidates = blockAncestorChain(event.target);
|
|
209
|
+
if (candidates.length === 0) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// Only claim the click once a block is under the cursor — plain
|
|
213
|
+
// Cmd/Ctrl+clicks elsewhere keep their default behaviour.
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
event.stopPropagation();
|
|
216
|
+
void openBlockInEditor({ candidates });
|
|
217
|
+
} catch {
|
|
218
|
+
// Never let the shortcut break the developer's app.
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
window.addEventListener('pointermove', onPointerMove);
|
|
223
|
+
window.addEventListener('keydown', onKeyDown);
|
|
224
|
+
window.addEventListener('keyup', onKeyUp);
|
|
225
|
+
window.addEventListener('blur', onBlur);
|
|
226
|
+
window.addEventListener('scroll', onScroll, true);
|
|
227
|
+
window.addEventListener('click', onClickCapture, { capture: true });
|
|
228
|
+
return () => {
|
|
229
|
+
window.removeEventListener('pointermove', onPointerMove);
|
|
230
|
+
window.removeEventListener('keydown', onKeyDown);
|
|
231
|
+
window.removeEventListener('keyup', onKeyUp);
|
|
232
|
+
window.removeEventListener('blur', onBlur);
|
|
233
|
+
window.removeEventListener('scroll', onScroll, true);
|
|
234
|
+
window.removeEventListener('click', onClickCapture, { capture: true });
|
|
235
|
+
};
|
|
236
|
+
}, [basePath]);
|
|
237
|
+
|
|
238
|
+
if (!hoverBlock || typeof document === 'undefined' || !document.body) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
// data-lowdefy-feedback keeps this out of the annotation overlay's element
|
|
242
|
+
// picking and out of tab-captured screenshots (both exclude that root).
|
|
243
|
+
return createPortal(
|
|
244
|
+
<div data-lowdefy-feedback data-lowdefy-open-in-editor style={overlayContainer}>
|
|
245
|
+
<div
|
|
246
|
+
style={{
|
|
247
|
+
...highlightBox,
|
|
248
|
+
top: hoverBlock.rect.top,
|
|
249
|
+
left: hoverBlock.rect.left,
|
|
250
|
+
width: hoverBlock.rect.width,
|
|
251
|
+
height: hoverBlock.rect.height,
|
|
252
|
+
}}
|
|
253
|
+
>
|
|
254
|
+
<span style={labelChip}>{hoverBlock.blockId}</span>
|
|
255
|
+
</div>
|
|
256
|
+
</div>,
|
|
257
|
+
document.body
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export default OpenInEditorListener;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Resolves a blockId to its YAML source via the dev server's existing
|
|
18
|
+
// GET /lowdefy-docs/find/{id}?pageId= route (which JIT-builds the page's
|
|
19
|
+
// keyMap on demand). Returns { file, line } with an absolute file path, or
|
|
20
|
+
// null when the id has no configured location. Best-effort, matching
|
|
21
|
+
// sendFeedback.js — a dev-only feature must never throw into the app.
|
|
22
|
+
async function findBlockLocation({ basePath, blockId, pageId }) {
|
|
23
|
+
try {
|
|
24
|
+
const response = await fetch(
|
|
25
|
+
`${basePath}/lowdefy-docs/find/${encodeURIComponent(blockId)}` +
|
|
26
|
+
`?pageId=${encodeURIComponent(pageId ?? '')}`
|
|
27
|
+
);
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const data = await response.json();
|
|
32
|
+
const source = data.matches?.[0]?.location?.source;
|
|
33
|
+
if (typeof source !== 'string' || source.length === 0) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
// source is "<absolute path>" or "<absolute path>:<line>" — a numeric
|
|
37
|
+
// suffix after the last colon is the 1-based line number. Splitting on
|
|
38
|
+
// the last colon keeps Windows drive-letter colons intact.
|
|
39
|
+
const match = source.match(/^(.*):(\d+)$/);
|
|
40
|
+
if (match) {
|
|
41
|
+
return { file: match[1], line: Number(match[2]) };
|
|
42
|
+
}
|
|
43
|
+
return { file: source, line: 1 };
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default findBlockLocation;
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import fs from 'node:fs';
|
|
18
18
|
import path from 'node:path';
|
|
19
19
|
|
|
20
|
+
import drawAnnotationsSvg from '../../client/feedback/drawAnnotationsSvg.js';
|
|
20
21
|
import { getBrowser, openPage } from './getBrowser.js';
|
|
21
22
|
|
|
22
23
|
// Renders the page headless at the batch's recorded viewport/scroll, injects
|
|
@@ -59,91 +60,10 @@ async function captureAnnotatedScreenshot({ origin, batch, fileName }) {
|
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
// Shapes and element rects are viewport-relative at the recorded scroll
|
|
62
|
-
// offset — after scrolling to the same offset they overlay 1:1.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
svg.setAttribute(
|
|
67
|
-
'style',
|
|
68
|
-
'position:fixed;inset:0;width:100%;height:100%;pointer-events:none;z-index:2147483000;'
|
|
69
|
-
);
|
|
70
|
-
const defs = document.createElementNS(NS, 'defs');
|
|
71
|
-
const marker = document.createElementNS(NS, 'marker');
|
|
72
|
-
marker.setAttribute('id', 'ldf-annotation-arrowhead');
|
|
73
|
-
marker.setAttribute('markerWidth', '10');
|
|
74
|
-
marker.setAttribute('markerHeight', '8');
|
|
75
|
-
marker.setAttribute('refX', '9');
|
|
76
|
-
marker.setAttribute('refY', '4');
|
|
77
|
-
marker.setAttribute('orient', 'auto');
|
|
78
|
-
const head = document.createElementNS(NS, 'polygon');
|
|
79
|
-
head.setAttribute('points', '0 0, 10 4, 0 8');
|
|
80
|
-
head.setAttribute('fill', '#ff4785');
|
|
81
|
-
marker.appendChild(head);
|
|
82
|
-
defs.appendChild(marker);
|
|
83
|
-
svg.appendChild(defs);
|
|
84
|
-
|
|
85
|
-
const stroke = '#ff4785';
|
|
86
|
-
annotations.forEach((annotation, index) => {
|
|
87
|
-
const rect = annotation.geometry?.elementRect;
|
|
88
|
-
if (rect) {
|
|
89
|
-
const outline = document.createElementNS(NS, 'rect');
|
|
90
|
-
outline.setAttribute('x', rect.x);
|
|
91
|
-
outline.setAttribute('y', rect.y);
|
|
92
|
-
outline.setAttribute('width', rect.width);
|
|
93
|
-
outline.setAttribute('height', rect.height);
|
|
94
|
-
outline.setAttribute('fill', 'rgba(255,71,133,0.08)');
|
|
95
|
-
outline.setAttribute('stroke', stroke);
|
|
96
|
-
outline.setAttribute('stroke-width', '2');
|
|
97
|
-
svg.appendChild(outline);
|
|
98
|
-
const label = document.createElementNS(NS, 'text');
|
|
99
|
-
label.setAttribute('x', rect.x);
|
|
100
|
-
label.setAttribute('y', Math.max(12, rect.y - 6));
|
|
101
|
-
label.setAttribute('fill', stroke);
|
|
102
|
-
label.setAttribute('font-size', '12');
|
|
103
|
-
label.setAttribute('font-family', 'system-ui, sans-serif');
|
|
104
|
-
label.setAttribute('font-weight', '600');
|
|
105
|
-
label.textContent = `${index + 1}`;
|
|
106
|
-
svg.appendChild(label);
|
|
107
|
-
}
|
|
108
|
-
(annotation.geometry?.shapes ?? []).forEach((shape) => {
|
|
109
|
-
if (shape.type === 'rect' && shape.points?.length >= 2) {
|
|
110
|
-
const [a, b] = shape.points;
|
|
111
|
-
const el = document.createElementNS(NS, 'rect');
|
|
112
|
-
el.setAttribute('x', Math.min(a.x, b.x));
|
|
113
|
-
el.setAttribute('y', Math.min(a.y, b.y));
|
|
114
|
-
el.setAttribute('width', Math.abs(b.x - a.x));
|
|
115
|
-
el.setAttribute('height', Math.abs(b.y - a.y));
|
|
116
|
-
el.setAttribute('fill', 'rgba(255,71,133,0.08)');
|
|
117
|
-
el.setAttribute('stroke', stroke);
|
|
118
|
-
el.setAttribute('stroke-width', '2.5');
|
|
119
|
-
svg.appendChild(el);
|
|
120
|
-
}
|
|
121
|
-
if (shape.type === 'arrow' && shape.points?.length >= 2) {
|
|
122
|
-
const [tail, headPoint] = shape.points;
|
|
123
|
-
const el = document.createElementNS(NS, 'line');
|
|
124
|
-
el.setAttribute('x1', tail.x);
|
|
125
|
-
el.setAttribute('y1', tail.y);
|
|
126
|
-
el.setAttribute('x2', headPoint.x);
|
|
127
|
-
el.setAttribute('y2', headPoint.y);
|
|
128
|
-
el.setAttribute('stroke', stroke);
|
|
129
|
-
el.setAttribute('stroke-width', '2.5');
|
|
130
|
-
el.setAttribute('marker-end', 'url(#ldf-annotation-arrowhead)');
|
|
131
|
-
svg.appendChild(el);
|
|
132
|
-
}
|
|
133
|
-
if (shape.type === 'freehand' && shape.points?.length >= 2) {
|
|
134
|
-
const el = document.createElementNS(NS, 'polyline');
|
|
135
|
-
el.setAttribute('points', shape.points.map((p) => `${p.x},${p.y}`).join(' '));
|
|
136
|
-
el.setAttribute('fill', 'none');
|
|
137
|
-
el.setAttribute('stroke', stroke);
|
|
138
|
-
el.setAttribute('stroke-width', '2.5');
|
|
139
|
-
el.setAttribute('stroke-linejoin', 'round');
|
|
140
|
-
el.setAttribute('stroke-linecap', 'round');
|
|
141
|
-
svg.appendChild(el);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
document.body.appendChild(svg);
|
|
146
|
-
}, batch.annotations ?? []);
|
|
63
|
+
// offset — after scrolling to the same offset they overlay 1:1. The
|
|
64
|
+
// compositor is shared with the in-tab capture (drawAnnotationsSvg is
|
|
65
|
+
// self-contained, so Playwright can serialize it into the page).
|
|
66
|
+
await page.evaluate(drawAnnotationsSvg, batch.annotations ?? []);
|
|
147
67
|
await page.waitForTimeout(150);
|
|
148
68
|
|
|
149
69
|
const buffer = await page.screenshot({ type: 'png' });
|