@replohq/canopy-sdk 2.0.0 → 2.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/_vendor/replo-utils/lib/log.d.ts +11 -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/errors.d.ts +36 -15
- package/_vendor/schemas/generated/selectMode.d.ts +0 -85
- 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 +361 -0
- package/_vendor/schemas/money.mjs +1 -112
- package/_vendor/schemas/selectMode.d.ts +0 -496
- package/_vendor/schemas/selectMode.mjs +3 -312
- package/_vendor/schemas/selectModeIframeRpc.d.ts +900 -0
- package/_vendor/schemas/selectModeIframeRpc.mjs +225 -0
- package/chunk-OFU2QEDR.mjs +163 -0
- package/chunk-YFJHLP53.mjs +197 -0
- package/editor/annotations/annotationController.js +1 -1
- package/editor/annotations/annotationController.js.map +2 -2
- package/editor/select-mode/EditorSelection.js +3 -15
- package/editor/select-mode/EditorSelection.js.map +2 -2
- package/editor/select-mode/fast-refresh-relay.js +2 -4
- package/editor/select-mode/fast-refresh-relay.js.map +2 -2
- package/editor/select-mode/hooks/useEditModeStateMachine.d.ts +0 -4
- package/editor/select-mode/hooks/useEditModeStateMachine.js +76 -67
- package/editor/select-mode/hooks/useEditModeStateMachine.js.map +2 -2
- package/editor/select-mode/hooks/useParentMessaging.d.ts +6 -10
- package/editor/select-mode/hooks/useParentMessaging.js +43 -68
- package/editor/select-mode/hooks/useParentMessaging.js.map +2 -2
- package/editor/select-mode/hooks/useSelectModeController.js +5 -8
- package/editor/select-mode/hooks/useSelectModeController.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionHover.js +4 -7
- package/editor/select-mode/hooks/useSelectionHover.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionInteractions.js +14 -31
- package/editor/select-mode/hooks/useSelectionInteractions.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionScrollSync.js +11 -18
- package/editor/select-mode/hooks/useSelectionScrollSync.js.map +2 -2
- package/editor/select-mode/iframeRpcChannel.d.ts +356 -0
- package/editor/select-mode/iframeRpcChannel.js +92 -0
- package/editor/select-mode/iframeRpcChannel.js.map +7 -0
- package/lib/canopy-error.js +1 -1
- package/lib/canopy-error.js.map +2 -2
- package/package.json +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { useEffect, useMemo } from "react";
|
|
2
|
+
import { useIframeRpcChannel } from "../../../_vendor/replo-utils/react/use-iframe-rpc-channel.mjs";
|
|
3
|
+
import {
|
|
4
|
+
getSelectModeIframeRpcChannel,
|
|
5
|
+
getWebsiteBuilderRpc,
|
|
6
|
+
setSelectModeParentHandlers
|
|
7
|
+
} from "../iframeRpcChannel";
|
|
5
8
|
function useParentMessaging({
|
|
6
9
|
applyOptimisticUpdate,
|
|
7
10
|
markCommitted,
|
|
8
|
-
onResolveEditRequest,
|
|
9
11
|
resolveSessionOverrides,
|
|
10
12
|
onEnterEditMode,
|
|
11
13
|
onExitEditMode,
|
|
@@ -14,76 +16,49 @@ function useParentMessaging({
|
|
|
14
16
|
setDisplayMode,
|
|
15
17
|
setSelectionType
|
|
16
18
|
}) {
|
|
19
|
+
useIframeRpcChannel(useMemo(() => getSelectModeIframeRpcChannel(), []));
|
|
17
20
|
useEffect(() => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
setSelectModeParentHandlers({
|
|
22
|
+
setDisplayMode: ({ displayMode }) => {
|
|
23
|
+
setDisplayMode(displayMode);
|
|
24
|
+
},
|
|
25
|
+
setSelectionType: ({ selectionType }) => {
|
|
26
|
+
setSelectionType(selectionType);
|
|
27
|
+
},
|
|
28
|
+
applyOptimisticUpdate: (message) => {
|
|
29
|
+
applyOptimisticUpdate?.({
|
|
30
|
+
editId: message.editId,
|
|
31
|
+
payload: message.payload,
|
|
32
|
+
targetSelector: message.targetSelector,
|
|
33
|
+
targetMode: message.targetMode
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
markCommitted: ({ editId, sessionId }) => {
|
|
37
|
+
markCommitted?.(editId, sessionId);
|
|
38
|
+
},
|
|
39
|
+
resolveSessionOverrides: ({ sessionId, outcome }) => {
|
|
40
|
+
resolveSessionOverrides?.(sessionId, outcome);
|
|
41
|
+
},
|
|
42
|
+
revertOverride: ({ editId }) => {
|
|
43
|
+
revertOverride?.(editId);
|
|
44
|
+
},
|
|
45
|
+
enterEditMode: () => {
|
|
46
|
+
onEnterEditMode?.();
|
|
47
|
+
},
|
|
48
|
+
exitEditMode: () => {
|
|
49
|
+
onExitEditMode?.();
|
|
50
|
+
},
|
|
51
|
+
formatCommand: ({ command }) => {
|
|
52
|
+
onFormatCommand?.(command);
|
|
22
53
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setDisplayMode(message.displayMode);
|
|
26
|
-
},
|
|
27
|
-
"replo:select:setSelectionType": (message) => {
|
|
28
|
-
setSelectionType(message.selectionType);
|
|
29
|
-
},
|
|
30
|
-
"replo:select:applyOptimisticUpdate": (message) => {
|
|
31
|
-
applyOptimisticUpdate?.({
|
|
32
|
-
editId: message.editId,
|
|
33
|
-
payload: message.payload,
|
|
34
|
-
targetSelector: message.targetSelector,
|
|
35
|
-
targetMode: message.targetMode
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
"replo:select:markCommitted": (message) => {
|
|
39
|
-
markCommitted?.(message.editId, message.sessionId);
|
|
40
|
-
},
|
|
41
|
-
"replo:select:resolveSessionOverrides": (message) => {
|
|
42
|
-
resolveSessionOverrides?.(message.sessionId, message.outcome);
|
|
43
|
-
},
|
|
44
|
-
"replo:select:revertOverride": (message) => {
|
|
45
|
-
revertOverride?.(message.editId);
|
|
46
|
-
},
|
|
47
|
-
"replo:select:enterEditMode": () => {
|
|
48
|
-
onEnterEditMode?.();
|
|
49
|
-
},
|
|
50
|
-
"replo:select:exitEditMode": () => {
|
|
51
|
-
onExitEditMode?.();
|
|
52
|
-
},
|
|
53
|
-
"replo:select:formatCommand": (message) => {
|
|
54
|
-
onFormatCommand?.(message.command);
|
|
55
|
-
},
|
|
56
|
-
"replo:select:resolveEditRequest": (message) => {
|
|
57
|
-
onResolveEditRequest?.({
|
|
58
|
-
editId: message.editId,
|
|
59
|
-
allowed: message.allowed
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
"replo:select:requestSymbolicate": (message) => {
|
|
63
|
-
void symbolicateSelectedElement(message.element).then(
|
|
64
|
-
(symbolicated) => {
|
|
65
|
-
window.parent.postMessage(
|
|
66
|
-
{
|
|
67
|
-
type: "replo:select:symbolicateResult",
|
|
68
|
-
requestId: message.requestId,
|
|
69
|
-
element: symbolicated
|
|
70
|
-
},
|
|
71
|
-
"*"
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
window.addEventListener("message", handleMessage);
|
|
79
|
-
window.parent.postMessage({ type: "replo:select:iframeReady" }, "*");
|
|
54
|
+
});
|
|
55
|
+
getWebsiteBuilderRpc()?.iframeReady(void 0);
|
|
80
56
|
return () => {
|
|
81
|
-
|
|
57
|
+
setSelectModeParentHandlers(null);
|
|
82
58
|
};
|
|
83
59
|
}, [
|
|
84
60
|
applyOptimisticUpdate,
|
|
85
61
|
markCommitted,
|
|
86
|
-
onResolveEditRequest,
|
|
87
62
|
resolveSessionOverrides,
|
|
88
63
|
onEnterEditMode,
|
|
89
64
|
onExitEditMode,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../editor/select-mode/hooks/useParentMessaging.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n DisplayMode,\n SelectModeFormatCommand,\n SelectModeOptimisticUpdatePayload,\n SelectModeSelectionType,\n} from \"schemas/generated/selectMode\";\n\nimport { useEffect } from \"react\";\n\nimport {
|
|
5
|
-
"mappings": "AAOA,SAAS,
|
|
4
|
+
"sourcesContent": ["import type {\n DisplayMode,\n SelectModeFormatCommand,\n SelectModeOptimisticUpdatePayload,\n SelectModeSelectionType,\n} from \"schemas/generated/selectMode\";\n\nimport { useEffect, useMemo } from \"react\";\n\nimport { useIframeRpcChannel } from \"replo-utils/react/use-iframe-rpc-channel\";\n\nimport {\n getSelectModeIframeRpcChannel,\n getWebsiteBuilderRpc,\n setSelectModeParentHandlers,\n} from \"../iframeRpcChannel\";\n\n/**\n * Inbound side of the iframe<->parent selectMode bridge.\n *\n * Listens for Website Builder \u2192 canopy methods and applies them locally:\n * - `setDisplayMode`: switch the iframe between `browse` and `selection`.\n * - `setSelectionType`: declarative push of the parent's current\n * selection type. The interesting transition is `* \u2192 \"none\"`, which\n * tears down any in-iframe selection frame / in-progress drag \u2014 agent-ui\n * drives it from `agentUiState.selectionType` so panel dismiss / submit\n * flow through the same path as exiting selection mode entirely. The\n * regression test in `EditorSelection.spec.tsx` covers the case where\n * losing this used to lock the iframe out of further selections.\n *\n * Also fires `iframeReady` on mount so the parent knows it's safe to push\n * the initial `setDisplayMode` \u2014 without this handshake the parent would\n * race the iframe's mount and the first message could be lost.\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function useParentMessaging({\n applyOptimisticUpdate,\n markCommitted,\n resolveSessionOverrides,\n onEnterEditMode,\n onExitEditMode,\n onFormatCommand,\n revertOverride,\n setDisplayMode,\n setSelectionType,\n}: {\n applyOptimisticUpdate?: (input: {\n editId: string;\n payload: SelectModeOptimisticUpdatePayload;\n targetSelector: string;\n targetMode: \"primary\" | \"group\";\n }) => void;\n markCommitted?: (editId: string, sessionId: string) => void;\n resolveSessionOverrides?: (\n sessionId: string,\n outcome: \"persisted\" | \"failed\",\n ) => void;\n onEnterEditMode?: () => void;\n onExitEditMode?: () => void;\n onFormatCommand?: (command: SelectModeFormatCommand) => void;\n revertOverride?: (editId: string) => void;\n setDisplayMode: (displayMode: DisplayMode) => void;\n setSelectionType: (selectionType: SelectModeSelectionType) => void;\n}) {\n useIframeRpcChannel(useMemo(() => getSelectModeIframeRpcChannel(), []));\n\n // eslint-disable-next-line replo/no-use-effect -- Legacy effect - may or may not be necessary\n useEffect(() => {\n setSelectModeParentHandlers({\n setDisplayMode: ({ displayMode }) => {\n setDisplayMode(displayMode);\n },\n setSelectionType: ({ selectionType }) => {\n setSelectionType(selectionType);\n },\n applyOptimisticUpdate: (message) => {\n applyOptimisticUpdate?.({\n editId: message.editId,\n payload: message.payload,\n targetSelector: message.targetSelector,\n targetMode: message.targetMode,\n });\n },\n markCommitted: ({ editId, sessionId }) => {\n markCommitted?.(editId, sessionId);\n },\n resolveSessionOverrides: ({ sessionId, outcome }) => {\n resolveSessionOverrides?.(sessionId, outcome);\n },\n revertOverride: ({ editId }) => {\n revertOverride?.(editId);\n },\n enterEditMode: () => {\n onEnterEditMode?.();\n },\n exitEditMode: () => {\n onExitEditMode?.();\n },\n formatCommand: ({ command }) => {\n onFormatCommand?.(command);\n },\n });\n getWebsiteBuilderRpc()?.iframeReady(undefined);\n\n return () => {\n setSelectModeParentHandlers(null);\n };\n }, [\n applyOptimisticUpdate,\n markCommitted,\n resolveSessionOverrides,\n onEnterEditMode,\n onExitEditMode,\n onFormatCommand,\n revertOverride,\n setDisplayMode,\n setSelectionType,\n ]);\n}\n"],
|
|
5
|
+
"mappings": "AAOA,SAAS,WAAW,eAAe;AAEnC,SAAS,2BAA2B;AAEpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAqBA,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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Ref } from "react";
|
|
2
2
|
import { displayModeStore, useDisplayMode } from "../displayModeStore";
|
|
3
|
+
import { getWebsiteBuilderRpc } from "../iframeRpcChannel";
|
|
3
4
|
import { hideSelectionFrame } from "../selectionFrame";
|
|
4
5
|
import { IDLE_SESSION } from "../selectModeSession";
|
|
5
6
|
function resetInteractionSession({
|
|
@@ -7,14 +8,10 @@ function resetInteractionSession({
|
|
|
7
8
|
}) {
|
|
8
9
|
const currentSession = interactionSessionRef.current;
|
|
9
10
|
if (currentSession.type === "drag" && currentSession.hasExceededThreshold) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
selectionRects: []
|
|
15
|
-
},
|
|
16
|
-
"*"
|
|
17
|
-
);
|
|
11
|
+
getWebsiteBuilderRpc()?.dragRectUpdated({
|
|
12
|
+
dragRect: null,
|
|
13
|
+
selectionRects: []
|
|
14
|
+
});
|
|
18
15
|
}
|
|
19
16
|
hideSelectionFrame();
|
|
20
17
|
interactionSessionRef.current = IDLE_SESSION;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../editor/select-mode/hooks/useSelectModeController.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n DisplayMode,\n SelectModeSelectionType,\n} from \"schemas/generated/selectMode\";\nimport type { SelectModeInteractionSession } from \"../selectModeSession\";\n\nimport { useCallback, useRef } from \"react\";\n\nimport { displayModeStore, useDisplayMode } from \"../displayModeStore\";\nimport { hideSelectionFrame } from \"../selectionFrame\";\nimport { IDLE_SESSION } from \"../selectModeSession\";\n\n/**\n * Tear down any in-progress drag/selection. Re-used by both the\n * display-mode flip-out path (defensive: belt-and-braces with the\n * parent's `setSelectionType(\"none\")` push) and by the explicit\n * `setSelectionType(\"none\")` path below.\n */\nfunction resetInteractionSession({\n interactionSessionRef,\n}: {\n interactionSessionRef: React.MutableRefObject<SelectModeInteractionSession>;\n}) {\n const currentSession = interactionSessionRef.current;\n if (currentSession.type === \"drag\" && currentSession.hasExceededThreshold) {\n
|
|
5
|
-
"mappings": "AAMA,SAAS,aAAa,cAAc;AAEpC,SAAS,kBAAkB,sBAAsB;AACjD,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAQ7B,SAAS,wBAAwB;AAAA,EAC/B;AACF,GAEG;AACD,QAAM,iBAAiB,sBAAsB;AAC7C,MAAI,eAAe,SAAS,UAAU,eAAe,sBAAsB;AACzE,
|
|
4
|
+
"sourcesContent": ["import type {\n DisplayMode,\n SelectModeSelectionType,\n} from \"schemas/generated/selectMode\";\nimport type { SelectModeInteractionSession } from \"../selectModeSession\";\n\nimport { useCallback, useRef } from \"react\";\n\nimport { displayModeStore, useDisplayMode } from \"../displayModeStore\";\nimport { getWebsiteBuilderRpc } from \"../iframeRpcChannel\";\nimport { hideSelectionFrame } from \"../selectionFrame\";\nimport { IDLE_SESSION } from \"../selectModeSession\";\n\n/**\n * Tear down any in-progress drag/selection. Re-used by both the\n * display-mode flip-out path (defensive: belt-and-braces with the\n * parent's `setSelectionType(\"none\")` push) and by the explicit\n * `setSelectionType(\"none\")` path below.\n */\nfunction resetInteractionSession({\n interactionSessionRef,\n}: {\n interactionSessionRef: React.MutableRefObject<SelectModeInteractionSession>;\n}) {\n const currentSession = interactionSessionRef.current;\n if (currentSession.type === \"drag\" && currentSession.hasExceededThreshold) {\n getWebsiteBuilderRpc()?.dragRectUpdated({\n dragRect: null,\n selectionRects: [],\n });\n }\n hideSelectionFrame();\n interactionSessionRef.current = IDLE_SESSION;\n}\n\nexport function useSelectModeController() {\n // Display mode lives in a module singleton so the sibling `LinkInterceptor`\n // can read it (and stand down during selection) without a shared provider.\n const displayMode = useDisplayMode();\n const interactionSessionRef =\n useRef<SelectModeInteractionSession>(IDLE_SESSION);\n\n // The parent is authoritative for \"is there a current selection?\". Canopy\n // originates selections via pointer events, posts them up, agent-ui\n // mirrors `selection.type` into `agentUiState`, and the result is pushed\n // back down here. When the parent says `none` (panel dismissed / submit /\n // exit selection mode) we tear down the in-iframe frame; the matching\n // commit-side paths are in `useSelectionInteractions`.\n const setSelectionType = useCallback(\n (selectionType: SelectModeSelectionType) => {\n if (selectionType === \"none\") {\n resetInteractionSession({ interactionSessionRef });\n }\n },\n [],\n );\n\n const setDisplayMode = useCallback((nextDisplayMode: DisplayMode) => {\n if (\n displayModeStore.getSnapshot() === \"selection\" &&\n nextDisplayMode !== \"selection\"\n ) {\n resetInteractionSession({ interactionSessionRef });\n }\n\n displayModeStore.setDisplayMode(nextDisplayMode);\n }, []);\n\n return {\n displayMode,\n interactionSessionRef,\n setDisplayMode,\n setSelectionType,\n };\n}\n"],
|
|
5
|
+
"mappings": "AAMA,SAAS,aAAa,cAAc;AAEpC,SAAS,kBAAkB,sBAAsB;AACjD,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAQ7B,SAAS,wBAAwB;AAAA,EAC/B;AACF,GAEG;AACD,QAAM,iBAAiB,sBAAsB;AAC7C,MAAI,eAAe,SAAS,UAAU,eAAe,sBAAsB;AACzE,yBAAqB,GAAG,gBAAgB;AAAA,MACtC,UAAU;AAAA,MACV,gBAAgB,CAAC;AAAA,IACnB,CAAC;AAAA,EACH;AACA,qBAAmB;AACnB,wBAAsB,UAAU;AAClC;AAEO,SAAS,0BAA0B;AAGxC,QAAM,cAAc,eAAe;AACnC,QAAM,wBACJ,OAAqC,YAAY;AAQnD,QAAM,mBAAmB;AAAA,IACvB,CAAC,kBAA2C;AAC1C,UAAI,kBAAkB,QAAQ;AAC5B,gCAAwB,EAAE,sBAAsB,CAAC;AAAA,MACnD;AAAA,IACF;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,iBAAiB,YAAY,CAAC,oBAAiC;AACnE,QACE,iBAAiB,YAAY,MAAM,eACnC,oBAAoB,aACpB;AACA,8BAAwB,EAAE,sBAAsB,CAAC;AAAA,IACnD;AAEA,qBAAiB,eAAe,eAAe;AAAA,EACjD,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
import { getNearestSelectableElement } from "../descriptor/elementDescriptor";
|
|
3
|
+
import { getWebsiteBuilderRpc } from "../iframeRpcChannel";
|
|
3
4
|
import { getElementBoundingRect } from "../interactions/selectionGeometry";
|
|
4
5
|
function useSelectionHover({
|
|
5
6
|
displayMode,
|
|
@@ -12,13 +13,9 @@ function useSelectionHover({
|
|
|
12
13
|
let hoverSyncAnimationFrameId = null;
|
|
13
14
|
let lastPointerClientPosition = null;
|
|
14
15
|
const postHoveredElement = (element) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
rect: element ? getElementBoundingRect(element) : null
|
|
19
|
-
},
|
|
20
|
-
"*"
|
|
21
|
-
);
|
|
16
|
+
getWebsiteBuilderRpc()?.hoverElement({
|
|
17
|
+
rect: element ? getElementBoundingRect(element) : null
|
|
18
|
+
});
|
|
22
19
|
};
|
|
23
20
|
const syncCurrentHover = (pointerClientPosition = lastPointerClientPosition) => {
|
|
24
21
|
let hoveredElement = null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../editor/select-mode/hooks/useSelectionHover.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 { getNearestSelectableElement } from \"../descriptor/elementDescriptor\";\nimport { getElementBoundingRect } from \"../interactions/selectionGeometry\";\n\n/**\n * Tracks whichever element is under the user's pointer while in `selection`\n * mode and reports its bounding rect to the parent so the parent can render\n * the hover overlay.\n *\n * Two behaviors worth knowing about:\n * - During an active drag we suppress hover updates; the drag overlay is\n * the only highlight we want visible.\n * - On scroll/wheel/resize we re-run the hover lookup from the last known\n * pointer position (we use rAF to coalesce). Without this, scrolling\n * over an already-hovered element wouldn't update the highlight to the\n * new element actually under the cursor.\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function useSelectionHover({\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 hoverSyncAnimationFrameId: number | null = null;\n let lastPointerClientPosition: { x: number; y: number } | null = null;\n\n // NOTE (Kevin O'Connell, 2026-04-20): `null` is the deliberate \"no element\n // under pointer / pointer left viewport\" signal \u2014 it produces a\n // clear-hover
|
|
5
|
-
"mappings": "AAIA,SAAS,iBAAiB;AAE1B,SAAS,mCAAmC;AAC5C,SAAS,8BAA8B;AAiBhC,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAGG;AAED,YAAU,MAAM;AACd,QAAI,gBAAgB,aAAa;AAC/B;AAAA,IACF;AAEA,QAAI,4BAA2C;AAC/C,QAAI,4BAA6D;AAKjE,UAAM,qBAAqB,CAAC,YAA4B;AAItD,
|
|
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 { getNearestSelectableElement } from \"../descriptor/elementDescriptor\";\nimport { getWebsiteBuilderRpc } from \"../iframeRpcChannel\";\nimport { getElementBoundingRect } from \"../interactions/selectionGeometry\";\n\n/**\n * Tracks whichever element is under the user's pointer while in `selection`\n * mode and reports its bounding rect to the parent so the parent can render\n * the hover overlay.\n *\n * Two behaviors worth knowing about:\n * - During an active drag we suppress hover updates; the drag overlay is\n * the only highlight we want visible.\n * - On scroll/wheel/resize we re-run the hover lookup from the last known\n * pointer position (we use rAF to coalesce). Without this, scrolling\n * over an already-hovered element wouldn't update the highlight to the\n * new element actually under the cursor.\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function useSelectionHover({\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 hoverSyncAnimationFrameId: number | null = null;\n let lastPointerClientPosition: { x: number; y: number } | null = null;\n\n // NOTE (Kevin O'Connell, 2026-04-20): `null` is the deliberate \"no element\n // under pointer / pointer left viewport\" signal \u2014 it produces a\n // clear-hover notification to the parent, not an error.\n const postHoveredElement = (element: Element | null) => {\n // The hover overlay only needs the element rect \u2014 serializing the full\n // styled outerHTML on every pointer move would be wasteful and never\n // consumed by the parent.\n getWebsiteBuilderRpc()?.hoverElement({\n rect: element ? getElementBoundingRect(element) : null,\n });\n };\n\n const syncCurrentHover = (\n pointerClientPosition = lastPointerClientPosition,\n ) => {\n let hoveredElement: Element | null = null;\n\n if (pointerClientPosition) {\n const isPointerWithinViewport =\n pointerClientPosition.x >= 0 &&\n pointerClientPosition.y >= 0 &&\n pointerClientPosition.x <= window.innerWidth &&\n pointerClientPosition.y <= window.innerHeight;\n\n if (isPointerWithinViewport) {\n hoveredElement = document.elementFromPoint(\n pointerClientPosition.x,\n pointerClientPosition.y,\n );\n }\n }\n\n if (!hoveredElement) {\n const hoveredElementStack = document.querySelectorAll(\":hover\");\n hoveredElement =\n hoveredElementStack[hoveredElementStack.length - 1] ?? null;\n }\n\n postHoveredElement(\n hoveredElement ? getNearestSelectableElement(hoveredElement) : null,\n );\n };\n\n const scheduleHoverSync = () => {\n if (\n interactionSessionRef.current.type === \"drag\" ||\n hoverSyncAnimationFrameId !== null\n ) {\n return;\n }\n\n hoverSyncAnimationFrameId = requestAnimationFrame(() => {\n hoverSyncAnimationFrameId = null;\n syncCurrentHover();\n });\n };\n\n const handlePointerMove = (event: PointerEvent) => {\n lastPointerClientPosition = {\n x: event.clientX,\n y: event.clientY,\n };\n\n if (interactionSessionRef.current.type === \"drag\") {\n return;\n }\n\n syncCurrentHover(lastPointerClientPosition);\n };\n\n // Catches the \"cursor is already inside the iframe when select mode\n // toggles on\" case \u2014 pointermove only fires on motion, so a stationary\n // cursor would otherwise wait forever for the first hover sync.\n const handlePointerOver = (event: PointerEvent) => {\n lastPointerClientPosition = {\n x: event.clientX,\n y: event.clientY,\n };\n\n if (interactionSessionRef.current.type === \"drag\") {\n return;\n }\n\n syncCurrentHover(lastPointerClientPosition);\n };\n\n const handlePointerOut = (event: PointerEvent) => {\n if (interactionSessionRef.current.type === \"drag\") {\n return;\n }\n\n const nextRelatedTarget = event.relatedTarget;\n if (\n nextRelatedTarget instanceof Node &&\n document.contains(nextRelatedTarget)\n ) {\n return;\n }\n\n lastPointerClientPosition = null;\n postHoveredElement(null);\n };\n\n const handleViewportChange = () => {\n scheduleHoverSync();\n };\n\n syncCurrentHover();\n document.addEventListener(\"pointermove\", handlePointerMove, true);\n document.addEventListener(\"pointerover\", handlePointerOver, true);\n document.addEventListener(\"pointerout\", handlePointerOut, true);\n document.addEventListener(\"scroll\", handleViewportChange, true);\n document.addEventListener(\"wheel\", handleViewportChange, {\n capture: true,\n passive: true,\n });\n window.addEventListener(\"resize\", handleViewportChange);\n\n return () => {\n if (hoverSyncAnimationFrameId !== null) {\n cancelAnimationFrame(hoverSyncAnimationFrameId);\n }\n document.removeEventListener(\"pointermove\", handlePointerMove, true);\n document.removeEventListener(\"pointerover\", handlePointerOver, true);\n document.removeEventListener(\"pointerout\", handlePointerOut, true);\n document.removeEventListener(\"scroll\", handleViewportChange, true);\n document.removeEventListener(\"wheel\", handleViewportChange, {\n capture: true,\n });\n window.removeEventListener(\"resize\", handleViewportChange);\n };\n }, [displayMode, interactionSessionRef]);\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,CAAC,aAAa,qBAAqB,CAAC;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
buildElementDescriptor,
|
|
4
4
|
getNearestSelectableElement
|
|
5
5
|
} from "../descriptor/elementDescriptor";
|
|
6
|
+
import { getWebsiteBuilderRpc } from "../iframeRpcChannel";
|
|
6
7
|
import {
|
|
7
8
|
collectDragCandidates,
|
|
8
9
|
getCandidatesInSelection,
|
|
@@ -52,14 +53,10 @@ function useSelectionInteractions({
|
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
55
|
if (notifyParentDragCleared && currentSession.hasExceededThreshold) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
selectionRects: []
|
|
60
|
-
},
|
|
61
|
-
"*"
|
|
62
|
-
);
|
|
56
|
+
getWebsiteBuilderRpc()?.dragRectUpdated({
|
|
57
|
+
dragRect: null,
|
|
58
|
+
selectionRects: []
|
|
59
|
+
});
|
|
63
60
|
}
|
|
64
61
|
dragCandidates = [];
|
|
65
62
|
interactionSessionRef.current = IDLE_SESSION;
|
|
@@ -97,14 +94,10 @@ function useSelectionInteractions({
|
|
|
97
94
|
scrollOffset: session.scrollOffset
|
|
98
95
|
})
|
|
99
96
|
}));
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
selectionRects
|
|
105
|
-
},
|
|
106
|
-
"*"
|
|
107
|
-
);
|
|
97
|
+
getWebsiteBuilderRpc()?.dragRectUpdated({
|
|
98
|
+
dragRect: rect,
|
|
99
|
+
selectionRects
|
|
100
|
+
});
|
|
108
101
|
};
|
|
109
102
|
const syncDragRectToViewport = () => {
|
|
110
103
|
const session = interactionSessionRef.current;
|
|
@@ -232,13 +225,7 @@ function useSelectionInteractions({
|
|
|
232
225
|
data
|
|
233
226
|
};
|
|
234
227
|
void maybeSymbolicate(data).then((symbolicated) => {
|
|
235
|
-
|
|
236
|
-
{
|
|
237
|
-
type: "replo:select:elementSelected",
|
|
238
|
-
data: symbolicated
|
|
239
|
-
},
|
|
240
|
-
"*"
|
|
241
|
-
);
|
|
228
|
+
getWebsiteBuilderRpc()?.elementSelected({ data: symbolicated });
|
|
242
229
|
});
|
|
243
230
|
};
|
|
244
231
|
const handlePointerUp = (event) => {
|
|
@@ -315,14 +302,10 @@ function useSelectionInteractions({
|
|
|
315
302
|
});
|
|
316
303
|
void Promise.all(items.map(maybeSymbolicate)).then(
|
|
317
304
|
(symbolicatedItems) => {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
items: symbolicatedItems
|
|
323
|
-
},
|
|
324
|
-
"*"
|
|
325
|
-
);
|
|
305
|
+
getWebsiteBuilderRpc()?.areaSelected({
|
|
306
|
+
rect: selectionRect,
|
|
307
|
+
items: symbolicatedItems
|
|
308
|
+
});
|
|
326
309
|
}
|
|
327
310
|
);
|
|
328
311
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../editor/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 {\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 window.parent.postMessage(\n {\n type: \"replo:select:dragRectUpdated\",\n dragRect: null,\n selectionRects: [],\n },\n \"*\",\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 window.parent.postMessage(\n {\n type: \"replo:select:dragRectUpdated\",\n dragRect: rect,\n selectionRects,\n },\n \"*\",\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 window.parent.postMessage(\n {\n type: \"replo:select:elementSelected\",\n data: symbolicated,\n },\n \"*\",\n );\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 window.parent.postMessage(\n {\n type: \"replo:select:areaSelected\",\n rect: selectionRect,\n items: symbolicatedItems,\n },\n \"*\",\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;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,
|
|
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;AA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AO,oBAAoB,UAAU,8BAA8B;AACnE,qBAAe;AAAA,IACjB;AAAA,EACF,GAAG,CAAC,aAAa,mBAAmB,uBAAuB,cAAc,CAAC;AAC5E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
|
+
import { getWebsiteBuilderRpc } from "../iframeRpcChannel";
|
|
2
3
|
import {
|
|
3
4
|
getDocumentScrollOffset,
|
|
4
5
|
getElementBoundingRect,
|
|
@@ -38,27 +39,19 @@ function useSelectionScrollSync({
|
|
|
38
39
|
height: boundingRect.height
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
clickPosition
|
|
46
|
-
},
|
|
47
|
-
"*"
|
|
48
|
-
);
|
|
42
|
+
getWebsiteBuilderRpc()?.selectedElementRectUpdate({
|
|
43
|
+
rect: boundingRect,
|
|
44
|
+
clickPosition
|
|
45
|
+
});
|
|
49
46
|
return;
|
|
50
47
|
}
|
|
51
48
|
if (session.type === "area") {
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
59
|
-
},
|
|
60
|
-
"*"
|
|
61
|
-
);
|
|
49
|
+
getWebsiteBuilderRpc()?.selectedAreaRectUpdate({
|
|
50
|
+
rect: getViewportRectFromPageRect({
|
|
51
|
+
rect: session.pageRect,
|
|
52
|
+
scrollOffset: getDocumentScrollOffset()
|
|
53
|
+
})
|
|
54
|
+
});
|
|
62
55
|
}
|
|
63
56
|
});
|
|
64
57
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../editor/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 {\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
|
|
5
|
-
"mappings": "AAIA,SAAS,iBAAiB;AAE1B;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,
|
|
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;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