@replohq/sandbox-runtime 0.1.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/ClientErrorBoundary.d.ts +10 -0
- package/ClientErrorBoundary.js +61 -0
- package/ClientErrorBoundary.js.map +7 -0
- package/DocumentReadyBeacon.d.ts +1 -0
- package/DocumentReadyBeacon.js +9 -0
- package/DocumentReadyBeacon.js.map +7 -0
- package/LICENSE +11 -0
- package/LinkInterceptor.d.ts +1 -0
- package/LinkInterceptor.js +128 -0
- package/LinkInterceptor.js.map +7 -0
- package/NextErrorReporter.d.ts +1 -0
- package/NextErrorReporter.js +92 -0
- package/NextErrorReporter.js.map +7 -0
- package/_vendor/replo-utils/lib/crypto.d.ts +30 -0
- package/_vendor/replo-utils/lib/errors.d.ts +83 -0
- package/_vendor/replo-utils/lib/fonts.d.ts +49 -0
- package/_vendor/replo-utils/lib/fonts.mjs +221 -0
- package/_vendor/replo-utils/lib/geometry.d.ts +18 -0
- package/_vendor/replo-utils/lib/geometry.mjs +9 -0
- package/_vendor/replo-utils/lib/json.d.ts +6 -0
- package/_vendor/replo-utils/lib/log.d.ts +11 -0
- package/_vendor/replo-utils/lib/misc.d.ts +145 -0
- package/_vendor/replo-utils/lib/misc.mjs +2 -0
- package/_vendor/replo-utils/lib/object.d.ts +31 -0
- package/_vendor/replo-utils/lib/parse.d.ts +15 -0
- package/_vendor/replo-utils/lib/posthogReplay.d.ts +43 -0
- package/_vendor/replo-utils/lib/posthogReplay.mjs +121 -0
- package/_vendor/replo-utils/react/use-iframe-rpc-channel.d.ts +14 -0
- package/_vendor/replo-utils/react/use-iframe-rpc-channel.mjs +14 -0
- package/_vendor/schemas/designLibrary.d.ts +361 -0
- package/_vendor/schemas/designLibrary.mjs +126 -0
- package/_vendor/schemas/errors.d.ts +459 -0
- package/_vendor/schemas/generated/errors.d.ts +61 -0
- package/_vendor/schemas/generated/pageAnnotations.d.ts +48 -0
- package/_vendor/schemas/generated/pageAnnotations.mjs +1 -0
- package/_vendor/schemas/generated/selectMode.d.ts +119 -0
- package/_vendor/schemas/generated/selectMode.mjs +1 -0
- package/_vendor/schemas/generated/selectModeIframeRpc.d.ts +100 -0
- package/_vendor/schemas/generated/selectModeIframeRpc.mjs +1 -0
- package/_vendor/schemas/iframeRpcChannel.d.ts +82 -0
- package/_vendor/schemas/iframeRpcChannel.mjs +520 -0
- package/_vendor/schemas/pageAnnotations.d.ts +134 -0
- package/_vendor/schemas/pageAnnotations.mjs +61 -0
- package/_vendor/schemas/savedStyles.d.ts +140 -0
- package/_vendor/schemas/selectMode.d.ts +522 -0
- package/_vendor/schemas/selectMode.mjs +3 -0
- package/_vendor/schemas/selectModeIframeRpc.d.ts +900 -0
- package/_vendor/schemas/selectModeIframeRpc.mjs +223 -0
- package/annotations/AnnotationLayerMount.d.ts +1 -0
- package/annotations/AnnotationLayerMount.js +13 -0
- package/annotations/AnnotationLayerMount.js.map +7 -0
- package/annotations/annotationController.d.ts +1 -0
- package/annotations/annotationController.js +384 -0
- package/annotations/annotationController.js.map +7 -0
- package/annotations/bridgeGate.d.ts +7 -0
- package/annotations/bridgeGate.js +22 -0
- package/annotations/bridgeGate.js.map +7 -0
- package/chunk-3UFG7XTQ.mjs +205 -0
- package/chunk-FNTGY7I5.mjs +68 -0
- package/chunk-N5EI2MOZ.mjs +1535 -0
- package/design-library-preview/DesignLibraryPreview.d.ts +1 -0
- package/design-library-preview/DesignLibraryPreview.js +93 -0
- package/design-library-preview/DesignLibraryPreview.js.map +7 -0
- package/package.json +41 -0
- package/posthog-relay.d.ts +11 -0
- package/posthog-relay.js +72 -0
- package/posthog-relay.js.map +7 -0
- package/sandbox-runtime.d.ts +1 -0
- package/sandbox-runtime.js +29 -0
- package/sandbox-runtime.js.map +7 -0
- package/select-mode/EditorSelection.d.ts +24 -0
- package/select-mode/EditorSelection.js +95 -0
- package/select-mode/EditorSelection.js.map +7 -0
- package/select-mode/annotationFrames.d.ts +33 -0
- package/select-mode/annotationFrames.js +119 -0
- package/select-mode/annotationFrames.js.map +7 -0
- package/select-mode/descriptor/elementDescriptor.d.ts +26 -0
- package/select-mode/descriptor/elementDescriptor.js +201 -0
- package/select-mode/descriptor/elementDescriptor.js.map +7 -0
- package/select-mode/descriptor/styleExtraction.d.ts +3 -0
- package/select-mode/descriptor/styleExtraction.js +271 -0
- package/select-mode/descriptor/styleExtraction.js.map +7 -0
- package/select-mode/displayModeStore.d.ts +10 -0
- package/select-mode/displayModeStore.js +47 -0
- package/select-mode/displayModeStore.js.map +7 -0
- package/select-mode/fast-refresh-relay.d.ts +3 -0
- package/select-mode/fast-refresh-relay.js +33 -0
- package/select-mode/fast-refresh-relay.js.map +7 -0
- package/select-mode/fiber.d.ts +49 -0
- package/select-mode/fiber.js +306 -0
- package/select-mode/fiber.js.map +7 -0
- package/select-mode/hooks/useCrosshairCursor.d.ts +12 -0
- package/select-mode/hooks/useCrosshairCursor.js +20 -0
- package/select-mode/hooks/useCrosshairCursor.js.map +7 -0
- package/select-mode/hooks/useEditModeStateMachine.d.ts +16 -0
- package/select-mode/hooks/useEditModeStateMachine.js +235 -0
- package/select-mode/hooks/useEditModeStateMachine.js.map +7 -0
- package/select-mode/hooks/useOptimisticOverrides.d.ts +17 -0
- package/select-mode/hooks/useOptimisticOverrides.js +283 -0
- package/select-mode/hooks/useOptimisticOverrides.js.map +7 -0
- package/select-mode/hooks/useParentMessaging.d.ts +36 -0
- package/select-mode/hooks/useParentMessaging.js +74 -0
- package/select-mode/hooks/useParentMessaging.js.map +7 -0
- package/select-mode/hooks/useSelectModeController.d.ts +8 -0
- package/select-mode/hooks/useSelectModeController.js +46 -0
- package/select-mode/hooks/useSelectModeController.js.map +7 -0
- package/select-mode/hooks/useSelectionHover.d.ts +22 -0
- package/select-mode/hooks/useSelectionHover.js +110 -0
- package/select-mode/hooks/useSelectionHover.js.map +7 -0
- package/select-mode/hooks/useSelectionInteractions.d.ts +37 -0
- package/select-mode/hooks/useSelectionInteractions.js +353 -0
- package/select-mode/hooks/useSelectionInteractions.js.map +7 -0
- package/select-mode/hooks/useSelectionScrollSync.d.ts +28 -0
- package/select-mode/hooks/useSelectionScrollSync.js +70 -0
- package/select-mode/hooks/useSelectionScrollSync.js.map +7 -0
- package/select-mode/hooks/useSiblingResolution.d.ts +6 -0
- package/select-mode/hooks/useSiblingResolution.js +59 -0
- package/select-mode/hooks/useSiblingResolution.js.map +7 -0
- package/select-mode/iframeRpcChannel.d.ts +356 -0
- package/select-mode/iframeRpcChannel.js +92 -0
- package/select-mode/iframeRpcChannel.js.map +7 -0
- package/select-mode/inlineTextMarks.d.ts +6 -0
- package/select-mode/inlineTextMarks.js +25 -0
- package/select-mode/inlineTextMarks.js.map +7 -0
- package/select-mode/interactions/selectionGeometry.d.ts +105 -0
- package/select-mode/interactions/selectionGeometry.js +192 -0
- package/select-mode/interactions/selectionGeometry.js.map +7 -0
- package/select-mode/selectModeSession.d.ts +21 -0
- package/select-mode/selectModeSession.js +7 -0
- package/select-mode/selectModeSession.js.map +7 -0
- package/select-mode/selectionFrame.d.ts +81 -0
- package/select-mode/selectionFrame.js +132 -0
- package/select-mode/selectionFrame.js.map +7 -0
- package/select-mode/symbolicate.d.ts +2 -0
- package/select-mode/symbolicate.js +200 -0
- package/select-mode/symbolicate.js.map +7 -0
- package/select-mode/tiptapInlineEditor.d.ts +23 -0
- package/select-mode/tiptapInlineEditor.js +120 -0
- package/select-mode/tiptapInlineEditor.js.map +7 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import {
|
|
3
|
+
buildElementDescriptor,
|
|
4
|
+
getNearestSelectableElement
|
|
5
|
+
} from "../descriptor/elementDescriptor";
|
|
6
|
+
import { getWebsiteBuilderRpc } from "../iframeRpcChannel";
|
|
7
|
+
import {
|
|
8
|
+
collectDragCandidates,
|
|
9
|
+
getCandidatesInSelection,
|
|
10
|
+
getDocumentScrollOffset,
|
|
11
|
+
getDragPositionFromClient,
|
|
12
|
+
getElementAnchor,
|
|
13
|
+
getPageRectFromViewportRect,
|
|
14
|
+
getViewportRectFromPageRect,
|
|
15
|
+
getViewportSelectionRect
|
|
16
|
+
} from "../interactions/selectionGeometry";
|
|
17
|
+
import { showSelectionFrame, showSelectionFrames } from "../selectionFrame";
|
|
18
|
+
import { IDLE_SESSION } from "../selectModeSession";
|
|
19
|
+
import { symbolicateSelectedElement } from "../symbolicate";
|
|
20
|
+
import { isTextEditableElement } from "./useEditModeStateMachine";
|
|
21
|
+
import { getSourceLocationSiblingSelectors } from "./useSiblingResolution";
|
|
22
|
+
const DOUBLE_CLICK_THRESHOLD_MS = 500;
|
|
23
|
+
async function maybeSymbolicate(data) {
|
|
24
|
+
return data.kind === "react-element" ? symbolicateSelectedElement(data) : data;
|
|
25
|
+
}
|
|
26
|
+
function useSelectionInteractions({
|
|
27
|
+
displayMode,
|
|
28
|
+
editingElementRef,
|
|
29
|
+
interactionSessionRef,
|
|
30
|
+
onBeginEditing
|
|
31
|
+
}) {
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (displayMode !== "selection") {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
let dragAnimationFrameId = null;
|
|
37
|
+
let lastClick = null;
|
|
38
|
+
let dragCandidates = [];
|
|
39
|
+
const stopDragAnimation = () => {
|
|
40
|
+
if (dragAnimationFrameId === null) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
cancelAnimationFrame(dragAnimationFrameId);
|
|
44
|
+
dragAnimationFrameId = null;
|
|
45
|
+
};
|
|
46
|
+
const resetDragState = ({
|
|
47
|
+
notifyParentDragCleared = true
|
|
48
|
+
} = {}) => {
|
|
49
|
+
const currentSession = interactionSessionRef.current;
|
|
50
|
+
stopDragAnimation();
|
|
51
|
+
if (currentSession.type !== "drag") {
|
|
52
|
+
dragCandidates = [];
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (notifyParentDragCleared && currentSession.hasExceededThreshold) {
|
|
56
|
+
getWebsiteBuilderRpc()?.dragRectUpdated({
|
|
57
|
+
dragRect: null,
|
|
58
|
+
selectionRects: []
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
dragCandidates = [];
|
|
62
|
+
interactionSessionRef.current = IDLE_SESSION;
|
|
63
|
+
};
|
|
64
|
+
const postCurrentDragRect = () => {
|
|
65
|
+
const session = interactionSessionRef.current;
|
|
66
|
+
if (session.type !== "drag") {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const rect = getViewportSelectionRect({
|
|
70
|
+
dragStart: session.dragStart,
|
|
71
|
+
dragCurrent: session.dragCurrent,
|
|
72
|
+
scrollOffset: session.scrollOffset
|
|
73
|
+
});
|
|
74
|
+
if (rect.width <= 6 && rect.height <= 6 && !session.hasExceededThreshold) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!session.hasExceededThreshold) {
|
|
78
|
+
interactionSessionRef.current = {
|
|
79
|
+
...session,
|
|
80
|
+
hasExceededThreshold: true
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const selectionPageRect = getPageRectFromViewportRect({
|
|
84
|
+
rect,
|
|
85
|
+
scrollOffset: session.scrollOffset
|
|
86
|
+
});
|
|
87
|
+
const selectionRects = getCandidatesInSelection({
|
|
88
|
+
candidates: dragCandidates,
|
|
89
|
+
selectionPageRect
|
|
90
|
+
}).map((candidate) => ({
|
|
91
|
+
id: candidate.id,
|
|
92
|
+
rect: getViewportRectFromPageRect({
|
|
93
|
+
rect: candidate.pageRect,
|
|
94
|
+
scrollOffset: session.scrollOffset
|
|
95
|
+
})
|
|
96
|
+
}));
|
|
97
|
+
getWebsiteBuilderRpc()?.dragRectUpdated({
|
|
98
|
+
dragRect: rect,
|
|
99
|
+
selectionRects
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const syncDragRectToViewport = () => {
|
|
103
|
+
const session = interactionSessionRef.current;
|
|
104
|
+
if (session.type !== "drag") {
|
|
105
|
+
dragAnimationFrameId = null;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const nextScrollOffset = getDocumentScrollOffset();
|
|
109
|
+
const nextDragCurrent = getDragPositionFromClient({
|
|
110
|
+
clientX: session.dragCurrent.clientX,
|
|
111
|
+
clientY: session.dragCurrent.clientY,
|
|
112
|
+
scrollOffset: nextScrollOffset
|
|
113
|
+
});
|
|
114
|
+
if (nextDragCurrent.pageX !== session.dragCurrent.pageX || nextDragCurrent.pageY !== session.dragCurrent.pageY) {
|
|
115
|
+
interactionSessionRef.current = {
|
|
116
|
+
...session,
|
|
117
|
+
dragCurrent: nextDragCurrent,
|
|
118
|
+
scrollOffset: nextScrollOffset
|
|
119
|
+
};
|
|
120
|
+
postCurrentDragRect();
|
|
121
|
+
} else {
|
|
122
|
+
interactionSessionRef.current = {
|
|
123
|
+
...session,
|
|
124
|
+
scrollOffset: nextScrollOffset
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);
|
|
128
|
+
};
|
|
129
|
+
const handlePointerDown = (event) => {
|
|
130
|
+
if (editingElementRef?.current && event.target instanceof Node && editingElementRef.current.contains(event.target)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
event.stopPropagation();
|
|
135
|
+
const scrollOffset = getDocumentScrollOffset();
|
|
136
|
+
const dragStart = getDragPositionFromClient({
|
|
137
|
+
clientX: event.clientX,
|
|
138
|
+
clientY: event.clientY,
|
|
139
|
+
scrollOffset
|
|
140
|
+
});
|
|
141
|
+
interactionSessionRef.current = {
|
|
142
|
+
type: "drag",
|
|
143
|
+
dragStart,
|
|
144
|
+
dragCurrent: dragStart,
|
|
145
|
+
scrollOffset,
|
|
146
|
+
hasExceededThreshold: false
|
|
147
|
+
};
|
|
148
|
+
dragCandidates = collectDragCandidates(scrollOffset);
|
|
149
|
+
if (dragAnimationFrameId === null) {
|
|
150
|
+
dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const handlePointerMove = (event) => {
|
|
154
|
+
const session = interactionSessionRef.current;
|
|
155
|
+
if (session.type !== "drag") {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
interactionSessionRef.current = {
|
|
159
|
+
...session,
|
|
160
|
+
dragCurrent: getDragPositionFromClient({
|
|
161
|
+
clientX: event.clientX,
|
|
162
|
+
clientY: event.clientY,
|
|
163
|
+
scrollOffset: getDocumentScrollOffset()
|
|
164
|
+
})
|
|
165
|
+
};
|
|
166
|
+
postCurrentDragRect();
|
|
167
|
+
};
|
|
168
|
+
const handleViewportChangeDuringDrag = () => {
|
|
169
|
+
const session = interactionSessionRef.current;
|
|
170
|
+
if (session.type !== "drag" || dragAnimationFrameId !== null) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);
|
|
174
|
+
};
|
|
175
|
+
const commitElementSelection = ({
|
|
176
|
+
targetElement,
|
|
177
|
+
pointerEvent
|
|
178
|
+
}) => {
|
|
179
|
+
const selectionElement = getNearestSelectableElement(targetElement);
|
|
180
|
+
const targetRect = selectionElement.getBoundingClientRect();
|
|
181
|
+
const clickPosition = {
|
|
182
|
+
x: pointerEvent.clientX,
|
|
183
|
+
y: pointerEvent.clientY
|
|
184
|
+
};
|
|
185
|
+
const scrollOffset = getDocumentScrollOffset();
|
|
186
|
+
showSelectionFrame({
|
|
187
|
+
variant: "element",
|
|
188
|
+
pageRect: {
|
|
189
|
+
x: targetRect.left + scrollOffset.left,
|
|
190
|
+
y: targetRect.top + scrollOffset.top,
|
|
191
|
+
width: targetRect.width,
|
|
192
|
+
height: targetRect.height
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
const now = pointerEvent.timeStamp;
|
|
196
|
+
const previousClick = lastClick;
|
|
197
|
+
if (previousClick && previousClick.target === selectionElement && now - previousClick.time <= DOUBLE_CLICK_THRESHOLD_MS && isTextEditableElement(selectionElement)) {
|
|
198
|
+
lastClick = null;
|
|
199
|
+
onBeginEditing({
|
|
200
|
+
element: selectionElement,
|
|
201
|
+
descriptorPromise: previousClick.descriptorPromise
|
|
202
|
+
});
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const data = buildElementDescriptor({
|
|
206
|
+
element: selectionElement,
|
|
207
|
+
clickPosition,
|
|
208
|
+
siblingSelectors: selectionElement instanceof HTMLElement ? getSourceLocationSiblingSelectors({ element: selectionElement }) : []
|
|
209
|
+
});
|
|
210
|
+
lastClick = {
|
|
211
|
+
descriptorPromise: Promise.resolve(data),
|
|
212
|
+
target: selectionElement,
|
|
213
|
+
time: now
|
|
214
|
+
};
|
|
215
|
+
if (!selectionElement.isConnected) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
interactionSessionRef.current = {
|
|
219
|
+
type: "element",
|
|
220
|
+
element: selectionElement,
|
|
221
|
+
clickPosition: {
|
|
222
|
+
x: pointerEvent.clientX - targetRect.left,
|
|
223
|
+
y: pointerEvent.clientY - targetRect.top
|
|
224
|
+
},
|
|
225
|
+
data
|
|
226
|
+
};
|
|
227
|
+
void maybeSymbolicate(data).then((symbolicated) => {
|
|
228
|
+
getWebsiteBuilderRpc()?.elementSelected({ data: symbolicated });
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
const handlePointerUp = (event) => {
|
|
232
|
+
if (editingElementRef?.current && event.target instanceof Node && editingElementRef.current.contains(event.target)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const snapshot = interactionSessionRef.current;
|
|
236
|
+
const wasDragging = snapshot.type === "drag" ? snapshot.hasExceededThreshold : false;
|
|
237
|
+
const dragStart = snapshot.type === "drag" ? snapshot.dragStart : null;
|
|
238
|
+
const dragCurrent = snapshot.type === "drag" ? snapshot.dragCurrent : null;
|
|
239
|
+
const scrollOffset = snapshot.type === "drag" ? snapshot.scrollOffset : getDocumentScrollOffset();
|
|
240
|
+
const candidates = dragCandidates;
|
|
241
|
+
resetDragState({ notifyParentDragCleared: false });
|
|
242
|
+
if (!dragStart || snapshot.type !== "drag") {
|
|
243
|
+
const targetElement = event.target;
|
|
244
|
+
if (!(targetElement instanceof Element)) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
commitElementSelection({
|
|
248
|
+
targetElement,
|
|
249
|
+
pointerEvent: event
|
|
250
|
+
});
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const resolvedDragCurrent = dragCurrent ?? dragStart;
|
|
254
|
+
const selectionRect = getViewportSelectionRect({
|
|
255
|
+
dragStart,
|
|
256
|
+
dragCurrent: resolvedDragCurrent,
|
|
257
|
+
scrollOffset
|
|
258
|
+
});
|
|
259
|
+
if (!wasDragging) {
|
|
260
|
+
const targetElement = event.target;
|
|
261
|
+
if (!(targetElement instanceof Element)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
commitElementSelection({
|
|
265
|
+
targetElement,
|
|
266
|
+
pointerEvent: event
|
|
267
|
+
});
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const pageRect = getPageRectFromViewportRect({
|
|
271
|
+
rect: selectionRect,
|
|
272
|
+
scrollOffset
|
|
273
|
+
});
|
|
274
|
+
const selectedCandidates = getCandidatesInSelection({
|
|
275
|
+
candidates,
|
|
276
|
+
selectionPageRect: pageRect
|
|
277
|
+
});
|
|
278
|
+
const items = selectedCandidates.map((candidate) => {
|
|
279
|
+
return buildElementDescriptor({
|
|
280
|
+
element: candidate.element,
|
|
281
|
+
clickPosition: getElementAnchor({
|
|
282
|
+
element: candidate.element,
|
|
283
|
+
selectionRect
|
|
284
|
+
})
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
interactionSessionRef.current = {
|
|
288
|
+
type: "area",
|
|
289
|
+
pageRect,
|
|
290
|
+
items
|
|
291
|
+
};
|
|
292
|
+
showSelectionFrames({
|
|
293
|
+
frames: selectedCandidates.map((candidate) => ({
|
|
294
|
+
variant: "area",
|
|
295
|
+
pageRect: {
|
|
296
|
+
x: candidate.pageRect.x,
|
|
297
|
+
y: candidate.pageRect.y,
|
|
298
|
+
width: candidate.pageRect.width,
|
|
299
|
+
height: candidate.pageRect.height
|
|
300
|
+
}
|
|
301
|
+
}))
|
|
302
|
+
});
|
|
303
|
+
void Promise.all(items.map(maybeSymbolicate)).then(
|
|
304
|
+
(symbolicatedItems) => {
|
|
305
|
+
getWebsiteBuilderRpc()?.areaSelected({
|
|
306
|
+
rect: selectionRect,
|
|
307
|
+
items: symbolicatedItems
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
);
|
|
311
|
+
};
|
|
312
|
+
const handleClick = (event) => {
|
|
313
|
+
if (editingElementRef?.current && event.target instanceof Node && editingElementRef.current.contains(event.target)) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
event.preventDefault();
|
|
317
|
+
event.stopPropagation();
|
|
318
|
+
};
|
|
319
|
+
const handlePointerCancel = () => {
|
|
320
|
+
resetDragState();
|
|
321
|
+
};
|
|
322
|
+
const handleWindowBlur = () => {
|
|
323
|
+
resetDragState();
|
|
324
|
+
};
|
|
325
|
+
document.addEventListener("pointerdown", handlePointerDown, true);
|
|
326
|
+
document.addEventListener("pointermove", handlePointerMove, true);
|
|
327
|
+
document.addEventListener("pointerup", handlePointerUp, true);
|
|
328
|
+
document.addEventListener("pointercancel", handlePointerCancel, true);
|
|
329
|
+
document.addEventListener("click", handleClick, true);
|
|
330
|
+
document.addEventListener("scroll", handleViewportChangeDuringDrag, true);
|
|
331
|
+
window.addEventListener("blur", handleWindowBlur);
|
|
332
|
+
window.addEventListener("resize", handleViewportChangeDuringDrag);
|
|
333
|
+
return () => {
|
|
334
|
+
document.removeEventListener("pointerdown", handlePointerDown, true);
|
|
335
|
+
document.removeEventListener("pointermove", handlePointerMove, true);
|
|
336
|
+
document.removeEventListener("pointerup", handlePointerUp, true);
|
|
337
|
+
document.removeEventListener("pointercancel", handlePointerCancel, true);
|
|
338
|
+
document.removeEventListener("click", handleClick, true);
|
|
339
|
+
document.removeEventListener(
|
|
340
|
+
"scroll",
|
|
341
|
+
handleViewportChangeDuringDrag,
|
|
342
|
+
true
|
|
343
|
+
);
|
|
344
|
+
window.removeEventListener("blur", handleWindowBlur);
|
|
345
|
+
window.removeEventListener("resize", handleViewportChangeDuringDrag);
|
|
346
|
+
resetDragState();
|
|
347
|
+
};
|
|
348
|
+
}, [displayMode, editingElementRef, interactionSessionRef, onBeginEditing]);
|
|
349
|
+
}
|
|
350
|
+
export {
|
|
351
|
+
useSelectionInteractions
|
|
352
|
+
};
|
|
353
|
+
//# sourceMappingURL=useSelectionInteractions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../select-mode/hooks/useSelectionInteractions.ts"],
|
|
4
|
+
"sourcesContent": ["import type { MutableRefObject } from \"react\";\nimport type {\n DisplayMode,\n SelectableData,\n SelectModeClickPosition,\n} from \"schemas/generated/selectMode\";\nimport type { DragCandidate } from \"../interactions/selectionGeometry\";\nimport type { SelectModeInteractionSession } from \"../selectModeSession\";\n\nimport { useEffect } from \"react\";\n\nimport {\n buildElementDescriptor,\n getNearestSelectableElement,\n} from \"../descriptor/elementDescriptor\";\nimport { getWebsiteBuilderRpc } from \"../iframeRpcChannel\";\nimport {\n collectDragCandidates,\n getCandidatesInSelection,\n getDocumentScrollOffset,\n getDragPositionFromClient,\n getElementAnchor,\n getPageRectFromViewportRect,\n getViewportRectFromPageRect,\n getViewportSelectionRect,\n} from \"../interactions/selectionGeometry\";\nimport { showSelectionFrame, showSelectionFrames } from \"../selectionFrame\";\nimport { IDLE_SESSION } from \"../selectModeSession\";\nimport { symbolicateSelectedElement } from \"../symbolicate\";\nimport { isTextEditableElement } from \"./useEditModeStateMachine\";\nimport { getSourceLocationSiblingSelectors } from \"./useSiblingResolution\";\n\nconst DOUBLE_CLICK_THRESHOLD_MS = 500;\n\n// React fibers carry only Turbopack chunk paths; resolving them to the\n// user's source file is async and only meaningful for \"react-element\"\n// kinds. Plan selectables already point at the right thing.\nasync function maybeSymbolicate(data: SelectableData): Promise<SelectableData> {\n return data.kind === \"react-element\"\n ? symbolicateSelectedElement(data)\n : data;\n}\n\n/**\n * Owns the iframe-side pointer interactions that drive selection:\n *\n * - On `pointerdown` we open a `drag` session (storing both client + page\n * coords plus the current scroll offset). We don't yet know if this will\n * become a click or an actual drag.\n * - On `pointermove` we update the drag rect and post `DRAG_RECT_UPDATED`\n * to the parent so the live drag rectangle can render. We only flip\n * `hasExceededThreshold` once the rect grows past 6\u00D76 px so that a tiny\n * accidental drag still resolves as a click.\n * - On `pointerup` we either:\n * - resolve as an `ELEMENT_SELECTED` (single click / sub-threshold drag)\n * - resolve as an `AREA_SELECTED` (drag past threshold), filtering the\n * candidates snapshotted at drag start against the final rectangle to\n * enumerate which descendants the user enclosed.\n * - During an active drag a `requestAnimationFrame` loop keeps the rect in\n * sync with the page scroll so the rectangle visually \"sticks\" to the\n * page rather than the viewport.\n *\n * We capture-listen and `preventDefault`/`stopPropagation` clicks so the\n * underlying page can't navigate or trigger handlers while the user is\n * working in selection mode.\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function useSelectionInteractions({\n displayMode,\n editingElementRef,\n interactionSessionRef,\n onBeginEditing,\n}: {\n displayMode: DisplayMode;\n editingElementRef?: MutableRefObject<HTMLElement | null>;\n interactionSessionRef: MutableRefObject<SelectModeInteractionSession>;\n onBeginEditing: (args: {\n element: Element;\n descriptorPromise: Promise<SelectableData>;\n }) => void;\n}) {\n // eslint-disable-next-line replo/no-use-effect -- Legacy effect - may or may not be necessary\n useEffect(() => {\n if (displayMode !== \"selection\") {\n return;\n }\n\n let dragAnimationFrameId: number | null = null;\n let lastClick: {\n descriptorPromise: Promise<SelectableData>;\n target: Element;\n time: number;\n } | null = null;\n // Snapshot of the page's meaningful elements + their page rects, taken\n // once when a drag begins so per-move hit-testing avoids a full-DOM scan.\n let dragCandidates: DragCandidate[] = [];\n\n const stopDragAnimation = () => {\n if (dragAnimationFrameId === null) {\n return;\n }\n\n cancelAnimationFrame(dragAnimationFrameId);\n dragAnimationFrameId = null;\n };\n\n // `notifyParentDragCleared` posts a null drag rect so the parent tears\n // down the live drag overlay. The area-commit path suppresses it: the\n // parent maps a null drag rect to `selection = none`, which round-trips\n // back as `setSelectionType(\"none\")` and wipes the in-iframe frames we're\n // about to paint. The follow-up `areaSelected` supersedes the drag overlay\n // on its own, so the null post is pure collateral damage there.\n const resetDragState = ({\n notifyParentDragCleared = true,\n }: { notifyParentDragCleared?: boolean } = {}) => {\n const currentSession = interactionSessionRef.current;\n\n stopDragAnimation();\n\n if (currentSession.type !== \"drag\") {\n dragCandidates = [];\n return;\n }\n\n if (notifyParentDragCleared && currentSession.hasExceededThreshold) {\n getWebsiteBuilderRpc()?.dragRectUpdated({\n dragRect: null,\n selectionRects: [],\n });\n }\n\n dragCandidates = [];\n interactionSessionRef.current = IDLE_SESSION;\n };\n\n const postCurrentDragRect = () => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\") {\n return;\n }\n\n const rect = getViewportSelectionRect({\n dragStart: session.dragStart,\n dragCurrent: session.dragCurrent,\n scrollOffset: session.scrollOffset,\n });\n\n if (\n rect.width <= 6 &&\n rect.height <= 6 &&\n !session.hasExceededThreshold\n ) {\n return;\n }\n\n if (!session.hasExceededThreshold) {\n interactionSessionRef.current = {\n ...session,\n hasExceededThreshold: true,\n };\n }\n\n // Cheap hit-test against the candidates we snapshotted at drag start,\n // projected back to viewport coords so the parent can paint a live\n // highlight on each element the drag will capture. No DOM scan here.\n const selectionPageRect = getPageRectFromViewportRect({\n rect,\n scrollOffset: session.scrollOffset,\n });\n const selectionRects = getCandidatesInSelection({\n candidates: dragCandidates,\n selectionPageRect,\n }).map((candidate) => ({\n id: candidate.id,\n rect: getViewportRectFromPageRect({\n rect: candidate.pageRect,\n scrollOffset: session.scrollOffset,\n }),\n }));\n\n getWebsiteBuilderRpc()?.dragRectUpdated({\n dragRect: rect,\n selectionRects,\n });\n };\n\n const syncDragRectToViewport = () => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\") {\n dragAnimationFrameId = null;\n return;\n }\n\n const nextScrollOffset = getDocumentScrollOffset();\n const nextDragCurrent = getDragPositionFromClient({\n clientX: session.dragCurrent.clientX,\n clientY: session.dragCurrent.clientY,\n scrollOffset: nextScrollOffset,\n });\n\n if (\n nextDragCurrent.pageX !== session.dragCurrent.pageX ||\n nextDragCurrent.pageY !== session.dragCurrent.pageY\n ) {\n interactionSessionRef.current = {\n ...session,\n dragCurrent: nextDragCurrent,\n scrollOffset: nextScrollOffset,\n };\n postCurrentDragRect();\n } else {\n interactionSessionRef.current = {\n ...session,\n scrollOffset: nextScrollOffset,\n };\n }\n\n dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);\n };\n\n const handlePointerDown = (event: PointerEvent) => {\n if (\n editingElementRef?.current &&\n event.target instanceof Node &&\n editingElementRef.current.contains(event.target)\n ) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n\n const scrollOffset = getDocumentScrollOffset();\n const dragStart = getDragPositionFromClient({\n clientX: event.clientX,\n clientY: event.clientY,\n scrollOffset,\n });\n interactionSessionRef.current = {\n type: \"drag\",\n dragStart,\n dragCurrent: dragStart,\n scrollOffset,\n hasExceededThreshold: false,\n };\n dragCandidates = collectDragCandidates(scrollOffset);\n\n if (dragAnimationFrameId === null) {\n dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);\n }\n };\n\n const handlePointerMove = (event: PointerEvent) => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\") {\n return;\n }\n\n interactionSessionRef.current = {\n ...session,\n dragCurrent: getDragPositionFromClient({\n clientX: event.clientX,\n clientY: event.clientY,\n scrollOffset: getDocumentScrollOffset(),\n }),\n };\n postCurrentDragRect();\n };\n\n const handleViewportChangeDuringDrag = () => {\n const session = interactionSessionRef.current;\n if (session.type !== \"drag\" || dragAnimationFrameId !== null) {\n return;\n }\n\n dragAnimationFrameId = requestAnimationFrame(syncDragRectToViewport);\n };\n\n const commitElementSelection = ({\n targetElement,\n pointerEvent,\n }: {\n targetElement: Element;\n pointerEvent: PointerEvent;\n }) => {\n const selectionElement = getNearestSelectableElement(targetElement);\n const targetRect = selectionElement.getBoundingClientRect();\n const clickPosition: SelectModeClickPosition = {\n x: pointerEvent.clientX,\n y: pointerEvent.clientY,\n };\n\n // Paint the in-iframe selection frame synchronously for instant\n // feedback \u2014 symbolicate is a network roundtrip and we don't want\n // the visual selection to wait on it.\n const scrollOffset = getDocumentScrollOffset();\n showSelectionFrame({\n variant: \"element\",\n pageRect: {\n x: targetRect.left + scrollOffset.left,\n y: targetRect.top + scrollOffset.top,\n width: targetRect.width,\n height: targetRect.height,\n },\n });\n\n const now = pointerEvent.timeStamp;\n const previousClick = lastClick;\n if (\n previousClick &&\n previousClick.target === selectionElement &&\n now - previousClick.time <= DOUBLE_CLICK_THRESHOLD_MS &&\n isTextEditableElement(selectionElement)\n ) {\n lastClick = null;\n onBeginEditing({\n element: selectionElement,\n descriptorPromise: previousClick.descriptorPromise,\n });\n return;\n }\n\n // NOTE (Noah, 2026-07-24): Commit the selection immediately rather than\n // deferring it behind the double-click window. A single click always\n // selects, and a double-click is just \"select + edit\", so there's nothing\n // to suppress \u2014 waiting only added a full DOUBLE_CLICK_THRESHOLD_MS of\n // latency to every click and left `interactionSessionRef` non-element in\n // the gap. Double-click is still detected via the `lastClick` timestamp\n // above; the follow-up click reuses this descriptor to open the editor.\n const data = buildElementDescriptor({\n element: selectionElement,\n clickPosition,\n siblingSelectors:\n selectionElement instanceof HTMLElement\n ? getSourceLocationSiblingSelectors({ element: selectionElement })\n : [],\n });\n lastClick = {\n descriptorPromise: Promise.resolve(data),\n target: selectionElement,\n time: now,\n };\n\n if (!selectionElement.isConnected) {\n return;\n }\n interactionSessionRef.current = {\n type: \"element\",\n element: selectionElement,\n clickPosition: {\n x: pointerEvent.clientX - targetRect.left,\n y: pointerEvent.clientY - targetRect.top,\n },\n data,\n };\n void maybeSymbolicate(data).then((symbolicated) => {\n getWebsiteBuilderRpc()?.elementSelected({ data: symbolicated });\n });\n };\n\n const handlePointerUp = (event: PointerEvent) => {\n // Clicks inside the element being edited belong to the inline editor, not\n // select mode. Without this guard the double-click detection below re-runs\n // `onBeginEditing` on the same element (e.g. when repositioning the\n // caret), rebuilding the editor over itself and wiping the content.\n // Mirrors the guards in `handlePointerDown` and `handleClick`.\n if (\n editingElementRef?.current &&\n event.target instanceof Node &&\n editingElementRef.current.contains(event.target)\n ) {\n return;\n }\n const snapshot = interactionSessionRef.current;\n const wasDragging =\n snapshot.type === \"drag\" ? snapshot.hasExceededThreshold : false;\n const dragStart = snapshot.type === \"drag\" ? snapshot.dragStart : null;\n const dragCurrent =\n snapshot.type === \"drag\" ? snapshot.dragCurrent : null;\n const scrollOffset =\n snapshot.type === \"drag\"\n ? snapshot.scrollOffset\n : getDocumentScrollOffset();\n // `resetDragState` clears `dragCandidates`, so grab them first \u2014 the\n // final committed set is the same cached candidates the live preview\n // used, so preview and result never disagree.\n const candidates = dragCandidates;\n\n // Suppress the null drag-rect post: if this resolves to an area\n // selection it would otherwise flash the parent to `selection = none`\n // and wipe the frames we paint below. Click/empty-drag paths don't\n // depend on it (a sub-threshold drag never posted a rect to clear).\n resetDragState({ notifyParentDragCleared: false });\n\n if (!dragStart || snapshot.type !== \"drag\") {\n const targetElement = event.target;\n if (!(targetElement instanceof Element)) {\n return;\n }\n\n commitElementSelection({\n targetElement,\n pointerEvent: event,\n });\n return;\n }\n\n const resolvedDragCurrent = dragCurrent ?? dragStart;\n const selectionRect = getViewportSelectionRect({\n dragStart,\n dragCurrent: resolvedDragCurrent,\n scrollOffset,\n });\n\n if (!wasDragging) {\n const targetElement = event.target;\n if (!(targetElement instanceof Element)) {\n return;\n }\n\n commitElementSelection({\n targetElement,\n pointerEvent: event,\n });\n return;\n }\n\n const pageRect = getPageRectFromViewportRect({\n rect: selectionRect,\n scrollOffset,\n });\n\n const selectedCandidates = getCandidatesInSelection({\n candidates,\n selectionPageRect: pageRect,\n });\n const items = selectedCandidates.map((candidate) => {\n return buildElementDescriptor({\n element: candidate.element,\n clickPosition: getElementAnchor({\n element: candidate.element,\n selectionRect,\n }),\n });\n });\n\n interactionSessionRef.current = {\n type: \"area\",\n pageRect,\n items,\n };\n\n // Highlight each captured element so the committed area selection\n // \"sticks\" inside the iframe \u2014 matching how a single click stays\n // outlined \u2014 rather than drawing one faint box over the drag region.\n showSelectionFrames({\n frames: selectedCandidates.map((candidate) => ({\n variant: \"area\" as const,\n pageRect: {\n x: candidate.pageRect.x,\n y: candidate.pageRect.y,\n width: candidate.pageRect.width,\n height: candidate.pageRect.height,\n },\n })),\n });\n\n void Promise.all(items.map(maybeSymbolicate)).then(\n (symbolicatedItems) => {\n getWebsiteBuilderRpc()?.areaSelected({\n rect: selectionRect,\n items: symbolicatedItems,\n });\n },\n );\n };\n\n const handleClick = (event: MouseEvent) => {\n if (\n editingElementRef?.current &&\n event.target instanceof Node &&\n editingElementRef.current.contains(event.target)\n ) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n };\n\n const handlePointerCancel = () => {\n resetDragState();\n };\n\n const handleWindowBlur = () => {\n resetDragState();\n };\n\n document.addEventListener(\"pointerdown\", handlePointerDown, true);\n document.addEventListener(\"pointermove\", handlePointerMove, true);\n document.addEventListener(\"pointerup\", handlePointerUp, true);\n document.addEventListener(\"pointercancel\", handlePointerCancel, true);\n document.addEventListener(\"click\", handleClick, true);\n document.addEventListener(\"scroll\", handleViewportChangeDuringDrag, true);\n window.addEventListener(\"blur\", handleWindowBlur);\n window.addEventListener(\"resize\", handleViewportChangeDuringDrag);\n\n return () => {\n document.removeEventListener(\"pointerdown\", handlePointerDown, true);\n document.removeEventListener(\"pointermove\", handlePointerMove, true);\n document.removeEventListener(\"pointerup\", handlePointerUp, true);\n document.removeEventListener(\"pointercancel\", handlePointerCancel, true);\n document.removeEventListener(\"click\", handleClick, true);\n document.removeEventListener(\n \"scroll\",\n handleViewportChangeDuringDrag,\n true,\n );\n window.removeEventListener(\"blur\", handleWindowBlur);\n window.removeEventListener(\"resize\", handleViewportChangeDuringDrag);\n resetDragState();\n };\n }, [displayMode, editingElementRef, interactionSessionRef, onBeginEditing]);\n}\n"],
|
|
5
|
+
"mappings": "AASA,SAAS,iBAAiB;AAE1B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB,2BAA2B;AACxD,SAAS,oBAAoB;AAC7B,SAAS,kCAAkC;AAC3C,SAAS,6BAA6B;AACtC,SAAS,yCAAyC;AAElD,MAAM,4BAA4B;AAKlC,eAAe,iBAAiB,MAA+C;AAC7E,SAAO,KAAK,SAAS,kBACjB,2BAA2B,IAAI,IAC/B;AACN;AA2BO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAQG;AAED,YAAU,MAAM;AACd,QAAI,gBAAgB,aAAa;AAC/B;AAAA,IACF;AAEA,QAAI,uBAAsC;AAC1C,QAAI,YAIO;AAGX,QAAI,iBAAkC,CAAC;AAEvC,UAAM,oBAAoB,MAAM;AAC9B,UAAI,yBAAyB,MAAM;AACjC;AAAA,MACF;AAEA,2BAAqB,oBAAoB;AACzC,6BAAuB;AAAA,IACzB;AAQA,UAAM,iBAAiB,CAAC;AAAA,MACtB,0BAA0B;AAAA,IAC5B,IAA2C,CAAC,MAAM;AAChD,YAAM,iBAAiB,sBAAsB;AAE7C,wBAAkB;AAElB,UAAI,eAAe,SAAS,QAAQ;AAClC,yBAAiB,CAAC;AAClB;AAAA,MACF;AAEA,UAAI,2BAA2B,eAAe,sBAAsB;AAClE,6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,IAAI;AACxE,WAAO,iBAAiB,QAAQ,gBAAgB;AAChD,WAAO,iBAAiB,UAAU,8BAA8B;AAEhE,WAAO,MAAM;AACX,eAAS,oBAAoB,eAAe,mBAAmB,IAAI;AACnE,eAAS,oBAAoB,eAAe,mBAAmB,IAAI;AACnE,eAAS,oBAAoB,aAAa,iBAAiB,IAAI;AAC/D,eAAS,oBAAoB,iBAAiB,qBAAqB,IAAI;AACvE,eAAS,oBAAoB,SAAS,aAAa,IAAI;AACvD,eAAS;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,aAAO,oBAAoB,QAAQ,gBAAgB;AACnD,aAAO,oBAAoB,UAAU,8BAA8B;AACnE,qBAAe;AAAA,IACjB;AAAA,EACF,GAAG,CAAC,aAAa,mBAAmB,uBAAuB,cAAc,CAAC;AAC5E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MutableRefObject } from "react";
|
|
2
|
+
import type { DisplayMode } from "../../_vendor/schemas/generated/selectMode";
|
|
3
|
+
import type { SelectModeInteractionSession } from "../selectModeSession";
|
|
4
|
+
/**
|
|
5
|
+
* After a selection (element or area) has been resolved, the parent's
|
|
6
|
+
* highlight overlay is positioned in viewport coordinates. When the user
|
|
7
|
+
* scrolls the iframe document the highlight would otherwise lag behind the
|
|
8
|
+
* underlying element. This hook re-sends an updated rect on every scroll
|
|
9
|
+
* (rAF-coalesced) so the parent overlay tracks the element/area through
|
|
10
|
+
* scrolls without us having to mirror scroll state into the parent.
|
|
11
|
+
*
|
|
12
|
+
* - For an `element` session we send only `{ boundingRect, clickPosition }`
|
|
13
|
+
* — the rest of the descriptor (selector, outerHTML, computed styles,
|
|
14
|
+
* text metrics, source location) was captured at selection-commit time
|
|
15
|
+
* and doesn't change while the user is just scrolling. Rebuilding the
|
|
16
|
+
* full descriptor here used to call `serializeStyledElement` (recursive
|
|
17
|
+
* `getComputedStyle` walk) on every scroll frame; this keeps the hot
|
|
18
|
+
* path to a single `getBoundingClientRect` read.
|
|
19
|
+
* - For an `area` session we keep the original *page* rect (which doesn't
|
|
20
|
+
* move) and convert it to viewport coordinates using the latest scroll
|
|
21
|
+
* offset before sending.
|
|
22
|
+
*
|
|
23
|
+
* @author Kevin O'Connell 2026-04-17
|
|
24
|
+
*/
|
|
25
|
+
export declare function useSelectionScrollSync({ displayMode, interactionSessionRef, }: {
|
|
26
|
+
displayMode: DisplayMode;
|
|
27
|
+
interactionSessionRef: MutableRefObject<SelectModeInteractionSession>;
|
|
28
|
+
}): void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { getWebsiteBuilderRpc } from "../iframeRpcChannel";
|
|
3
|
+
import {
|
|
4
|
+
getDocumentScrollOffset,
|
|
5
|
+
getElementBoundingRect,
|
|
6
|
+
getViewportRectFromPageRect
|
|
7
|
+
} from "../interactions/selectionGeometry";
|
|
8
|
+
import { showSelectionFrame } from "../selectionFrame";
|
|
9
|
+
function useSelectionScrollSync({
|
|
10
|
+
displayMode,
|
|
11
|
+
interactionSessionRef
|
|
12
|
+
}) {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (displayMode !== "selection") {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
let animationFrameId = null;
|
|
18
|
+
const handleScroll = () => {
|
|
19
|
+
if (animationFrameId !== null) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
animationFrameId = requestAnimationFrame(() => {
|
|
23
|
+
animationFrameId = null;
|
|
24
|
+
const session = interactionSessionRef.current;
|
|
25
|
+
if (session.type === "element") {
|
|
26
|
+
const boundingRect = getElementBoundingRect(session.element);
|
|
27
|
+
const sessionClickPosition = session.clickPosition;
|
|
28
|
+
const clickPosition = {
|
|
29
|
+
x: sessionClickPosition !== null ? boundingRect.left + sessionClickPosition.x : boundingRect.right,
|
|
30
|
+
y: sessionClickPosition !== null ? boundingRect.top + sessionClickPosition.y : boundingRect.bottom
|
|
31
|
+
};
|
|
32
|
+
const scrollOffset = getDocumentScrollOffset();
|
|
33
|
+
showSelectionFrame({
|
|
34
|
+
variant: "element",
|
|
35
|
+
pageRect: {
|
|
36
|
+
x: boundingRect.left + scrollOffset.left,
|
|
37
|
+
y: boundingRect.top + scrollOffset.top,
|
|
38
|
+
width: boundingRect.width,
|
|
39
|
+
height: boundingRect.height
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
getWebsiteBuilderRpc()?.selectedElementRectUpdate({
|
|
43
|
+
rect: boundingRect,
|
|
44
|
+
clickPosition
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (session.type === "area") {
|
|
49
|
+
getWebsiteBuilderRpc()?.selectedAreaRectUpdate({
|
|
50
|
+
rect: getViewportRectFromPageRect({
|
|
51
|
+
rect: session.pageRect,
|
|
52
|
+
scrollOffset: getDocumentScrollOffset()
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
document.addEventListener("scroll", handleScroll, true);
|
|
59
|
+
return () => {
|
|
60
|
+
document.removeEventListener("scroll", handleScroll, true);
|
|
61
|
+
if (animationFrameId !== null) {
|
|
62
|
+
cancelAnimationFrame(animationFrameId);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}, [displayMode, interactionSessionRef]);
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
useSelectionScrollSync
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=useSelectionScrollSync.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../select-mode/hooks/useSelectionScrollSync.ts"],
|
|
4
|
+
"sourcesContent": ["import type { MutableRefObject } from \"react\";\nimport type { DisplayMode } from \"schemas/generated/selectMode\";\nimport type { SelectModeInteractionSession } from \"../selectModeSession\";\n\nimport { useEffect } from \"react\";\n\nimport { getWebsiteBuilderRpc } from \"../iframeRpcChannel\";\nimport {\n getDocumentScrollOffset,\n getElementBoundingRect,\n getViewportRectFromPageRect,\n} from \"../interactions/selectionGeometry\";\nimport { showSelectionFrame } from \"../selectionFrame\";\n\n/**\n * After a selection (element or area) has been resolved, the parent's\n * highlight overlay is positioned in viewport coordinates. When the user\n * scrolls the iframe document the highlight would otherwise lag behind the\n * underlying element. This hook re-sends an updated rect on every scroll\n * (rAF-coalesced) so the parent overlay tracks the element/area through\n * scrolls without us having to mirror scroll state into the parent.\n *\n * - For an `element` session we send only `{ boundingRect, clickPosition }`\n * \u2014 the rest of the descriptor (selector, outerHTML, computed styles,\n * text metrics, source location) was captured at selection-commit time\n * and doesn't change while the user is just scrolling. Rebuilding the\n * full descriptor here used to call `serializeStyledElement` (recursive\n * `getComputedStyle` walk) on every scroll frame; this keeps the hot\n * path to a single `getBoundingClientRect` read.\n * - For an `area` session we keep the original *page* rect (which doesn't\n * move) and convert it to viewport coordinates using the latest scroll\n * offset before sending.\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function useSelectionScrollSync({\n displayMode,\n interactionSessionRef,\n}: {\n displayMode: DisplayMode;\n interactionSessionRef: MutableRefObject<SelectModeInteractionSession>;\n}) {\n // eslint-disable-next-line replo/no-use-effect -- Legacy effect - may or may not be necessary\n useEffect(() => {\n if (displayMode !== \"selection\") {\n return;\n }\n\n let animationFrameId: number | null = null;\n\n const handleScroll = () => {\n if (animationFrameId !== null) {\n return;\n }\n\n animationFrameId = requestAnimationFrame(() => {\n animationFrameId = null;\n\n const session = interactionSessionRef.current;\n if (session.type === \"element\") {\n const boundingRect = getElementBoundingRect(session.element);\n const sessionClickPosition = session.clickPosition;\n const clickPosition = {\n x:\n sessionClickPosition !== null\n ? boundingRect.left + sessionClickPosition.x\n : boundingRect.right,\n y:\n sessionClickPosition !== null\n ? boundingRect.top + sessionClickPosition.y\n : boundingRect.bottom,\n };\n // Page coordinates of the in-iframe frame are stable across\n // pure scroll, but layout shifts during scroll (sticky\n // headers expanding, lazy images settling, etc.) can move the\n // selected element. Re-applying every rAF tick keeps the\n // frame glued; same-value style writes are cheap and don't\n // repaint.\n const scrollOffset = getDocumentScrollOffset();\n showSelectionFrame({\n variant: \"element\",\n pageRect: {\n x: boundingRect.left + scrollOffset.left,\n y: boundingRect.top + scrollOffset.top,\n width: boundingRect.width,\n height: boundingRect.height,\n },\n });\n getWebsiteBuilderRpc()?.selectedElementRectUpdate({\n rect: boundingRect,\n clickPosition,\n });\n return;\n }\n\n if (session.type === \"area\") {\n getWebsiteBuilderRpc()?.selectedAreaRectUpdate({\n rect: getViewportRectFromPageRect({\n rect: session.pageRect,\n scrollOffset: getDocumentScrollOffset(),\n }),\n });\n }\n });\n };\n\n document.addEventListener(\"scroll\", handleScroll, true);\n return () => {\n document.removeEventListener(\"scroll\", handleScroll, true);\n if (animationFrameId !== null) {\n cancelAnimationFrame(animationFrameId);\n }\n };\n }, [displayMode, interactionSessionRef]);\n}\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,iBAAiB;AAE1B,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AAuB5B,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AACF,GAGG;AAED,YAAU,MAAM;AACd,QAAI,gBAAgB,aAAa;AAC/B;AAAA,IACF;AAEA,QAAI,mBAAkC;AAEtC,UAAM,eAAe,MAAM;AACzB,UAAI,qBAAqB,MAAM;AAC7B;AAAA,MACF;AAEA,yBAAmB,sBAAsB,MAAM;AAC7C,2BAAmB;AAEnB,cAAM,UAAU,sBAAsB;AACtC,YAAI,QAAQ,SAAS,WAAW;AAC9B,gBAAM,eAAe,uBAAuB,QAAQ,OAAO;AAC3D,gBAAM,uBAAuB,QAAQ;AACrC,gBAAM,gBAAgB;AAAA,YACpB,GACE,yBAAyB,OACrB,aAAa,OAAO,qBAAqB,IACzC,aAAa;AAAA,YACnB,GACE,yBAAyB,OACrB,aAAa,MAAM,qBAAqB,IACxC,aAAa;AAAA,UACrB;AAOA,gBAAM,eAAe,wBAAwB;AAC7C,6BAAmB;AAAA,YACjB,SAAS;AAAA,YACT,UAAU;AAAA,cACR,GAAG,aAAa,OAAO,aAAa;AAAA,cACpC,GAAG,aAAa,MAAM,aAAa;AAAA,cACnC,OAAO,aAAa;AAAA,cACpB,QAAQ,aAAa;AAAA,YACvB;AAAA,UACF,CAAC;AACD,+BAAqB,GAAG,0BAA0B;AAAA,YAChD,MAAM;AAAA,YACN;AAAA,UACF,CAAC;AACD;AAAA,QACF;AAEA,YAAI,QAAQ,SAAS,QAAQ;AAC3B,+BAAqB,GAAG,uBAAuB;AAAA,YAC7C,MAAM,4BAA4B;AAAA,cAChC,MAAM,QAAQ;AAAA,cACd,cAAc,wBAAwB;AAAA,YACxC,CAAC;AAAA,UACH,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAEA,aAAS,iBAAiB,UAAU,cAAc,IAAI;AACtD,WAAO,MAAM;AACX,eAAS,oBAAoB,UAAU,cAAc,IAAI;AACzD,UAAI,qBAAqB,MAAM;AAC7B,6BAAqB,gBAAgB;AAAA,MACvC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,qBAAqB,CAAC;AACzC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { buildSelector } from "../descriptor/elementDescriptor";
|
|
2
|
+
import { getHostSourceIdentity } from "../fiber";
|
|
3
|
+
const sourceIdentityCache = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function getSourceIdentityKey(element) {
|
|
5
|
+
const cached = sourceIdentityCache.get(element);
|
|
6
|
+
if (cached !== void 0) {
|
|
7
|
+
return cached;
|
|
8
|
+
}
|
|
9
|
+
const identity = getHostSourceIdentity(element);
|
|
10
|
+
if (!identity) {
|
|
11
|
+
sourceIdentityCache.set(element, null);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const key = [
|
|
15
|
+
identity.filePath,
|
|
16
|
+
identity.lineNumber,
|
|
17
|
+
identity.columnNumber ?? "",
|
|
18
|
+
identity.tagName
|
|
19
|
+
].join(":");
|
|
20
|
+
sourceIdentityCache.set(element, key);
|
|
21
|
+
return key;
|
|
22
|
+
}
|
|
23
|
+
function getSourceLocationSiblingElements({
|
|
24
|
+
element
|
|
25
|
+
}) {
|
|
26
|
+
if (!(element instanceof HTMLElement) || !document.body) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const selectedLocationKey = getSourceIdentityKey(element);
|
|
30
|
+
if (!selectedLocationKey) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const siblings = [];
|
|
34
|
+
const treeWalker = document.createTreeWalker(
|
|
35
|
+
document.body,
|
|
36
|
+
NodeFilter.SHOW_ELEMENT
|
|
37
|
+
);
|
|
38
|
+
let currentNode = treeWalker.nextNode();
|
|
39
|
+
while (currentNode) {
|
|
40
|
+
if (currentNode instanceof HTMLElement && currentNode !== element) {
|
|
41
|
+
const currentLocationKey = getSourceIdentityKey(currentNode);
|
|
42
|
+
if (currentLocationKey === selectedLocationKey) {
|
|
43
|
+
siblings.push(currentNode);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
currentNode = treeWalker.nextNode();
|
|
47
|
+
}
|
|
48
|
+
return siblings;
|
|
49
|
+
}
|
|
50
|
+
function getSourceLocationSiblingSelectors({
|
|
51
|
+
element
|
|
52
|
+
}) {
|
|
53
|
+
return getSourceLocationSiblingElements({ element }).map(buildSelector);
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
getSourceLocationSiblingElements,
|
|
57
|
+
getSourceLocationSiblingSelectors
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=useSiblingResolution.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../select-mode/hooks/useSiblingResolution.ts"],
|
|
4
|
+
"sourcesContent": ["import { buildSelector } from \"../descriptor/elementDescriptor\";\nimport { getHostSourceIdentity } from \"../fiber\";\n\nconst sourceIdentityCache = new WeakMap<HTMLElement, string | null>();\n\nfunction getSourceIdentityKey(element: HTMLElement): string | null {\n const cached = sourceIdentityCache.get(element);\n if (cached !== undefined) {\n return cached;\n }\n const identity = getHostSourceIdentity(element);\n if (!identity) {\n sourceIdentityCache.set(element, null);\n return null;\n }\n const key = [\n identity.filePath,\n identity.lineNumber,\n identity.columnNumber ?? \"\",\n identity.tagName,\n ].join(\":\");\n sourceIdentityCache.set(element, key);\n return key;\n}\n\nexport function getSourceLocationSiblingElements({\n element,\n}: {\n element: Element;\n}): HTMLElement[] {\n if (!(element instanceof HTMLElement) || !document.body) {\n return [];\n }\n\n const selectedLocationKey = getSourceIdentityKey(element);\n if (!selectedLocationKey) {\n return [];\n }\n\n const siblings: HTMLElement[] = [];\n const treeWalker = document.createTreeWalker(\n document.body,\n NodeFilter.SHOW_ELEMENT,\n );\n\n let currentNode = treeWalker.nextNode();\n while (currentNode) {\n if (currentNode instanceof HTMLElement && currentNode !== element) {\n const currentLocationKey = getSourceIdentityKey(currentNode);\n if (currentLocationKey === selectedLocationKey) {\n siblings.push(currentNode);\n }\n }\n currentNode = treeWalker.nextNode();\n }\n\n return siblings;\n}\n\nexport function getSourceLocationSiblingSelectors({\n element,\n}: {\n element: Element;\n}): string[] {\n return getSourceLocationSiblingElements({ element }).map(buildSelector);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAEtC,MAAM,sBAAsB,oBAAI,QAAoC;AAEpE,SAAS,qBAAqB,SAAqC;AACjE,QAAM,SAAS,oBAAoB,IAAI,OAAO;AAC9C,MAAI,WAAW,QAAW;AACxB,WAAO;AAAA,EACT;AACA,QAAM,WAAW,sBAAsB,OAAO;AAC9C,MAAI,CAAC,UAAU;AACb,wBAAo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