@replohq/canopy-sdk 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.
Files changed (241) hide show
  1. package/_vendor/replo-utils/lib/errors.d.ts +83 -0
  2. package/_vendor/replo-utils/lib/json.d.ts +6 -0
  3. package/_vendor/replo-utils/lib/misc.d.ts +128 -0
  4. package/_vendor/replo-utils/lib/misc.mjs +1 -0
  5. package/_vendor/replo-utils/lib/object.d.ts +31 -0
  6. package/_vendor/replo-utils/lib/parse.d.ts +15 -0
  7. package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.d.ts +49 -0
  8. package/_vendor/schemas/agentTools/customIntegrations/loaders/levanta.mjs +36 -0
  9. package/_vendor/schemas/agentTools/customIntegrations/loaders/product.d.ts +334 -0
  10. package/_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs +50 -0
  11. package/_vendor/schemas/cart.d.ts +198 -0
  12. package/_vendor/schemas/cart.mjs +83 -0
  13. package/_vendor/schemas/errors.d.ts +428 -0
  14. package/_vendor/schemas/errors.mjs +955 -0
  15. package/_vendor/schemas/generated/errors.d.ts +61 -0
  16. package/_vendor/schemas/generated/selectMode.d.ts +95 -0
  17. package/_vendor/schemas/generated/selectMode.mjs +1 -0
  18. package/_vendor/schemas/loaderKeys.d.ts +39 -0
  19. package/_vendor/schemas/loaderKeys.mjs +23 -0
  20. package/_vendor/schemas/objectType.d.ts +895 -0
  21. package/_vendor/schemas/objectType.mjs +2 -0
  22. package/_vendor/schemas/registry.d.ts +243 -0
  23. package/_vendor/schemas/sandboxFiles.d.ts +35 -0
  24. package/_vendor/schemas/selectMode.d.ts +507 -0
  25. package/_vendor/schemas/selectMode.mjs +194 -0
  26. package/_vendor/schemas/sellingPlan.d.ts +60 -0
  27. package/_vendor/schemas/sellingPlan.mjs +1 -0
  28. package/analytics/analytics-provider.d.ts +13 -0
  29. package/analytics/analytics-provider.js +104 -0
  30. package/analytics/analytics-provider.js.map +7 -0
  31. package/analytics/analytics-sink.d.ts +20 -0
  32. package/analytics/analytics-sink.js +1 -0
  33. package/analytics/analytics-sink.js.map +7 -0
  34. package/analytics/hooks/use-product-viewed-analytics.d.ts +23 -0
  35. package/analytics/hooks/use-product-viewed-analytics.js +34 -0
  36. package/analytics/hooks/use-product-viewed-analytics.js.map +7 -0
  37. package/analytics/sinks/ga4-sink.d.ts +15 -0
  38. package/analytics/sinks/ga4-sink.js +52 -0
  39. package/analytics/sinks/ga4-sink.js.map +7 -0
  40. package/analytics/sinks/meta-sink.d.ts +14 -0
  41. package/analytics/sinks/meta-sink.js +44 -0
  42. package/analytics/sinks/meta-sink.js.map +7 -0
  43. package/analytics/sinks/pinterest-sink.d.ts +14 -0
  44. package/analytics/sinks/pinterest-sink.js +76 -0
  45. package/analytics/sinks/pinterest-sink.js.map +7 -0
  46. package/analytics/sinks/reddit-sink.d.ts +14 -0
  47. package/analytics/sinks/reddit-sink.js +80 -0
  48. package/analytics/sinks/reddit-sink.js.map +7 -0
  49. package/analytics/sinks/replo-sink.d.ts +14 -0
  50. package/analytics/sinks/replo-sink.js +57 -0
  51. package/analytics/sinks/replo-sink.js.map +7 -0
  52. package/analytics/sinks/snapchat-sink.d.ts +14 -0
  53. package/analytics/sinks/snapchat-sink.js +67 -0
  54. package/analytics/sinks/snapchat-sink.js.map +7 -0
  55. package/analytics/sinks/tiktok-sink.d.ts +14 -0
  56. package/analytics/sinks/tiktok-sink.js +79 -0
  57. package/analytics/sinks/tiktok-sink.js.map +7 -0
  58. package/analytics/sinks/window-sink.d.ts +18 -0
  59. package/analytics/sinks/window-sink.js +46 -0
  60. package/analytics/sinks/window-sink.js.map +7 -0
  61. package/analytics/utils/analytics-utils.d.ts +7 -0
  62. package/analytics/utils/analytics-utils.js +130 -0
  63. package/analytics/utils/analytics-utils.js.map +7 -0
  64. package/analytics/utils/navigation-tracker.d.ts +16 -0
  65. package/analytics/utils/navigation-tracker.js +44 -0
  66. package/analytics/utils/navigation-tracker.js.map +7 -0
  67. package/cart/buy-now-action.d.ts +21 -0
  68. package/cart/buy-now-action.js +104 -0
  69. package/cart/buy-now-action.js.map +7 -0
  70. package/cart/cart-actions.d.ts +63 -0
  71. package/cart/cart-actions.js +90 -0
  72. package/cart/cart-actions.js.map +7 -0
  73. package/cart/cart-loader.d.ts +9 -0
  74. package/cart/cart-loader.js +11 -0
  75. package/cart/cart-loader.js.map +7 -0
  76. package/cart/cart-provider.d.ts +85 -0
  77. package/cart/cart-provider.js +358 -0
  78. package/cart/cart-provider.js.map +7 -0
  79. package/cart/cart-types.d.ts +154 -0
  80. package/cart/cart-types.js +16 -0
  81. package/cart/cart-types.js.map +7 -0
  82. package/cart/gateways/cart-gateway.d.ts +10 -0
  83. package/cart/gateways/cart-gateway.js +19 -0
  84. package/cart/gateways/cart-gateway.js.map +7 -0
  85. package/cart/gateways/cookie-cart-gateway.d.ts +28 -0
  86. package/cart/gateways/cookie-cart-gateway.js +109 -0
  87. package/cart/gateways/cookie-cart-gateway.js.map +7 -0
  88. package/cart/gateways/default-cart-gateway.d.ts +19 -0
  89. package/cart/gateways/default-cart-gateway.js +30 -0
  90. package/cart/gateways/default-cart-gateway.js.map +7 -0
  91. package/cart/gateways/resolver-cart-gateway.d.ts +2 -0
  92. package/cart/gateways/resolver-cart-gateway.js +106 -0
  93. package/cart/gateways/resolver-cart-gateway.js.map +7 -0
  94. package/cart/gateways/stripe-cart-gateway.d.ts +19 -0
  95. package/cart/gateways/stripe-cart-gateway.js +28 -0
  96. package/cart/gateways/stripe-cart-gateway.js.map +7 -0
  97. package/cart/gateways/stripe-constants.d.ts +1 -0
  98. package/cart/gateways/stripe-constants.js +5 -0
  99. package/cart/gateways/stripe-constants.js.map +7 -0
  100. package/cart/hooks/use-add-to-cart.d.ts +63 -0
  101. package/cart/hooks/use-add-to-cart.js +120 -0
  102. package/cart/hooks/use-add-to-cart.js.map +7 -0
  103. package/cart/hooks/use-buy-now.d.ts +49 -0
  104. package/cart/hooks/use-buy-now.js +62 -0
  105. package/cart/hooks/use-buy-now.js.map +7 -0
  106. package/cart/utils/cart-utils.d.ts +31 -0
  107. package/cart/utils/cart-utils.js +48 -0
  108. package/cart/utils/cart-utils.js.map +7 -0
  109. package/cart/utils/cookie-cart-persistence.d.ts +55 -0
  110. package/cart/utils/cookie-cart-persistence.js +153 -0
  111. package/cart/utils/cookie-cart-persistence.js.map +7 -0
  112. package/cart/utils/variant-to-cart-line.d.ts +124 -0
  113. package/cart/utils/variant-to-cart-line.js +202 -0
  114. package/cart/utils/variant-to-cart-line.js.map +7 -0
  115. package/chunk-46YU2W6T.mjs +538 -0
  116. package/chunk-4TZVNC3W.mjs +33 -0
  117. package/chunk-INHK6MYI.mjs +1598 -0
  118. package/editor/ClientErrorBoundary.d.ts +7 -0
  119. package/editor/ClientErrorBoundary.js +48 -0
  120. package/editor/ClientErrorBoundary.js.map +7 -0
  121. package/editor/LinkInterceptor.d.ts +1 -0
  122. package/editor/LinkInterceptor.js +124 -0
  123. package/editor/LinkInterceptor.js.map +7 -0
  124. package/editor/posthog-relay.d.ts +10 -0
  125. package/editor/posthog-relay.js +60 -0
  126. package/editor/posthog-relay.js.map +7 -0
  127. package/editor/select-mode/EditorSelection.d.ts +24 -0
  128. package/editor/select-mode/EditorSelection.js +34 -0
  129. package/editor/select-mode/EditorSelection.js.map +7 -0
  130. package/editor/select-mode/descriptor/elementDescriptor.d.ts +15 -0
  131. package/editor/select-mode/descriptor/elementDescriptor.js +213 -0
  132. package/editor/select-mode/descriptor/elementDescriptor.js.map +7 -0
  133. package/editor/select-mode/fiber.d.ts +52 -0
  134. package/editor/select-mode/fiber.js +269 -0
  135. package/editor/select-mode/fiber.js.map +7 -0
  136. package/editor/select-mode/hooks/useCrosshairCursor.d.ts +12 -0
  137. package/editor/select-mode/hooks/useCrosshairCursor.js +20 -0
  138. package/editor/select-mode/hooks/useCrosshairCursor.js.map +7 -0
  139. package/editor/select-mode/hooks/useParentMessaging.d.ts +24 -0
  140. package/editor/select-mode/hooks/useParentMessaging.js +33 -0
  141. package/editor/select-mode/hooks/useParentMessaging.js.map +7 -0
  142. package/editor/select-mode/hooks/useSelectModeController.d.ts +8 -0
  143. package/editor/select-mode/hooks/useSelectModeController.js +49 -0
  144. package/editor/select-mode/hooks/useSelectModeController.js.map +7 -0
  145. package/editor/select-mode/hooks/useSelectionHover.d.ts +22 -0
  146. package/editor/select-mode/hooks/useSelectionHover.js +98 -0
  147. package/editor/select-mode/hooks/useSelectionHover.js.map +7 -0
  148. package/editor/select-mode/hooks/useSelectionInteractions.d.ts +32 -0
  149. package/editor/select-mode/hooks/useSelectionInteractions.js +293 -0
  150. package/editor/select-mode/hooks/useSelectionInteractions.js.map +7 -0
  151. package/editor/select-mode/hooks/useSelectionScrollSync.d.ts +28 -0
  152. package/editor/select-mode/hooks/useSelectionScrollSync.js +77 -0
  153. package/editor/select-mode/hooks/useSelectionScrollSync.js.map +7 -0
  154. package/editor/select-mode/interactions/selectionGeometry.d.ts +80 -0
  155. package/editor/select-mode/interactions/selectionGeometry.js +160 -0
  156. package/editor/select-mode/interactions/selectionGeometry.js.map +7 -0
  157. package/editor/select-mode/selectModeSession.d.ts +21 -0
  158. package/editor/select-mode/selectModeSession.js +7 -0
  159. package/editor/select-mode/selectModeSession.js.map +7 -0
  160. package/editor/select-mode/selectionFrame.d.ts +48 -0
  161. package/editor/select-mode/selectionFrame.js +74 -0
  162. package/editor/select-mode/selectionFrame.js.map +7 -0
  163. package/editor/select-mode/symbolicate.d.ts +3 -0
  164. package/editor/select-mode/symbolicate.js +139 -0
  165. package/editor/select-mode/symbolicate.js.map +7 -0
  166. package/env.d.ts +13 -0
  167. package/env.js +20 -0
  168. package/env.js.map +7 -0
  169. package/gateways/canopy-api.d.ts +84 -0
  170. package/gateways/canopy-api.js +203 -0
  171. package/gateways/canopy-api.js.map +7 -0
  172. package/hooks/use-client-value.d.ts +10 -0
  173. package/hooks/use-client-value.js +12 -0
  174. package/hooks/use-client-value.js.map +7 -0
  175. package/hooks/use-formatted-price.d.ts +15 -0
  176. package/hooks/use-formatted-price.js +19 -0
  177. package/hooks/use-formatted-price.js.map +7 -0
  178. package/lib/get-query-client.d.ts +2 -0
  179. package/lib/get-query-client.js +34 -0
  180. package/lib/get-query-client.js.map +7 -0
  181. package/lib/integration-utils.d.ts +2 -0
  182. package/lib/integration-utils.js +9 -0
  183. package/lib/integration-utils.js.map +7 -0
  184. package/lib/shopify-utils.d.ts +16 -0
  185. package/lib/shopify-utils.js +11 -0
  186. package/lib/shopify-utils.js.map +7 -0
  187. package/lib/url-utils.d.ts +4 -0
  188. package/lib/url-utils.js +8 -0
  189. package/lib/url-utils.js.map +7 -0
  190. package/loaders/collection-loader.d.ts +11 -0
  191. package/loaders/collection-loader.js +53 -0
  192. package/loaders/collection-loader.js.map +7 -0
  193. package/loaders/collection-products-loader.d.ts +12 -0
  194. package/loaders/collection-products-loader.js +56 -0
  195. package/loaders/collection-products-loader.js.map +7 -0
  196. package/loaders/invoke-loader-action.d.ts +11 -0
  197. package/loaders/invoke-loader-action.js +14 -0
  198. package/loaders/invoke-loader-action.js.map +7 -0
  199. package/loaders/invoke-loader-server.d.ts +18 -0
  200. package/loaders/invoke-loader-server.js +35 -0
  201. package/loaders/invoke-loader-server.js.map +7 -0
  202. package/loaders/invoke-loader.d.ts +14 -0
  203. package/loaders/invoke-loader.js +36 -0
  204. package/loaders/invoke-loader.js.map +7 -0
  205. package/loaders/levanta-product-loader.d.ts +11 -0
  206. package/loaders/levanta-product-loader.js +53 -0
  207. package/loaders/levanta-product-loader.js.map +7 -0
  208. package/loaders/loader-error-boundary.d.ts +25 -0
  209. package/loaders/loader-error-boundary.js +24 -0
  210. package/loaders/loader-error-boundary.js.map +7 -0
  211. package/loaders/okendo-review-aggregate-loader.d.ts +17 -0
  212. package/loaders/okendo-review-aggregate-loader.js +56 -0
  213. package/loaders/okendo-review-aggregate-loader.js.map +7 -0
  214. package/loaders/okendo-reviews-loader.d.ts +23 -0
  215. package/loaders/okendo-reviews-loader.js +54 -0
  216. package/loaders/okendo-reviews-loader.js.map +7 -0
  217. package/loaders/prefetch-loaders.d.ts +33 -0
  218. package/loaders/prefetch-loaders.js +46 -0
  219. package/loaders/prefetch-loaders.js.map +7 -0
  220. package/loaders/product-loader.d.ts +11 -0
  221. package/loaders/product-loader.js +53 -0
  222. package/loaders/product-loader.js.map +7 -0
  223. package/loaders/rebuy-recommendations-loader.d.ts +159 -0
  224. package/loaders/rebuy-recommendations-loader.js +57 -0
  225. package/loaders/rebuy-recommendations-loader.js.map +7 -0
  226. package/loaders/smile-earning-rules-loader.d.ts +19 -0
  227. package/loaders/smile-earning-rules-loader.js +44 -0
  228. package/loaders/smile-earning-rules-loader.js.map +7 -0
  229. package/loaders/smile-rewards-loader.d.ts +19 -0
  230. package/loaders/smile-rewards-loader.js +44 -0
  231. package/loaders/smile-rewards-loader.js.map +7 -0
  232. package/loaders/smile-vip-tiers-loader.d.ts +18 -0
  233. package/loaders/smile-vip-tiers-loader.js +43 -0
  234. package/loaders/smile-vip-tiers-loader.js.map +7 -0
  235. package/package.json +29 -0
  236. package/providers/query-provider.d.ts +1 -0
  237. package/providers/query-provider.js +12 -0
  238. package/providers/query-provider.js.map +7 -0
  239. package/providers/replo-provider.d.ts +1 -0
  240. package/providers/replo-provider.js +20 -0
  241. package/providers/replo-provider.js.map +7 -0
@@ -0,0 +1,52 @@
1
+ export interface SourceLocation {
2
+ filePath: string;
3
+ lineNumber: number;
4
+ columnNumber?: number;
5
+ componentName?: string;
6
+ }
7
+ export interface EventHandlers {
8
+ onClick?: string;
9
+ onMouseEnter?: string;
10
+ onMouseLeave?: string;
11
+ onFocus?: string;
12
+ onBlur?: string;
13
+ }
14
+ export interface ReactFiber {
15
+ _debugSource?: {
16
+ fileName: string;
17
+ lineNumber: number;
18
+ columnNumber?: number;
19
+ };
20
+ _debugStack?: unknown;
21
+ _debugOwner?: ReactFiber;
22
+ type?: {
23
+ name?: string;
24
+ displayName?: string;
25
+ } | string | ((...args: unknown[]) => unknown) | null;
26
+ return?: ReactFiber | null;
27
+ memoizedProps?: Record<string, unknown>;
28
+ pendingProps?: Record<string, unknown>;
29
+ }
30
+ export declare function getFiberFromElement(element: HTMLElement): ReactFiber | null;
31
+ export declare function getComponentName(fiber: ReactFiber | null | undefined): string | undefined;
32
+ export declare function findDebugSource(fiber: ReactFiber, maxDepth?: number): {
33
+ source: ReactFiber["_debugSource"];
34
+ componentName?: string;
35
+ } | null;
36
+ export declare function findDebugSourceReact19(fiber: ReactFiber): {
37
+ source: ReactFiber["_debugSource"];
38
+ componentName?: string;
39
+ } | null;
40
+ export declare function getSourceLocation(element: HTMLElement): SourceLocation | undefined;
41
+ /**
42
+ * Extract event handlers from React fiber or DOM element
43
+ *
44
+ * @author Kevin O'Connell 2026-04-17
45
+ */
46
+ export declare function extractEventHandlers(element: HTMLElement): EventHandlers;
47
+ /**
48
+ * Convert a function to a readable string representation
49
+ *
50
+ * @author Kevin O'Connell 2026-04-17
51
+ */
52
+ export declare function stringifyHandler(fn: unknown): string;
@@ -0,0 +1,269 @@
1
+ const REACT_INTERNAL_FRAME_PATTERNS = [
2
+ /react.*jsx-dev-runtime/,
3
+ /react.*jsx-runtime/,
4
+ /react-dom\//,
5
+ /react\/cjs\/react\./,
6
+ /react-server-dom/,
7
+ /react_server_dom/,
8
+ /next[/_.]dist[/_.]compiled/,
9
+ /\/node_modules\/(next|react|react-dom)\//
10
+ ];
11
+ function isReactInternalFrame(fileName) {
12
+ return REACT_INTERNAL_FRAME_PATTERNS.some((pattern) => {
13
+ return pattern.test(fileName);
14
+ });
15
+ }
16
+ function parseDebugStackSource(debugStack) {
17
+ let stackText = null;
18
+ if (typeof debugStack === "string") {
19
+ stackText = debugStack;
20
+ } else if (typeof debugStack === "object" && debugStack && "stack" in debugStack) {
21
+ const stack = debugStack.stack;
22
+ if (typeof stack === "string") {
23
+ stackText = stack;
24
+ }
25
+ }
26
+ if (!stackText) {
27
+ return null;
28
+ }
29
+ for (const rawLine of stackText.split("\n")) {
30
+ const line = rawLine.trim();
31
+ if (!line) {
32
+ continue;
33
+ }
34
+ const stackFrameMatch = line.match(/^at\s+(?:.*\()?(.*):(\d+):(\d+)\)?$/) ?? line.match(/^(.*):(\d+):(\d+)$/);
35
+ if (!stackFrameMatch) {
36
+ continue;
37
+ }
38
+ const fileName = stackFrameMatch[1]?.trim();
39
+ const lineNumber = Number.parseInt(stackFrameMatch[2] ?? "", 10);
40
+ const columnNumber = Number.parseInt(stackFrameMatch[3] ?? "", 10);
41
+ if (!fileName || !Number.isFinite(lineNumber) || !Number.isFinite(columnNumber)) {
42
+ continue;
43
+ }
44
+ if (isReactInternalFrame(fileName)) {
45
+ continue;
46
+ }
47
+ return {
48
+ fileName,
49
+ lineNumber,
50
+ columnNumber
51
+ };
52
+ }
53
+ return null;
54
+ }
55
+ function getFiberFromElement(element) {
56
+ if (!element || typeof element !== "object") {
57
+ return null;
58
+ }
59
+ const symbolKeys = Object.getOwnPropertySymbols(element);
60
+ const fiberSymbolKey = symbolKeys.find((symbolKey) => {
61
+ return symbolKey.toString().includes("reactFiber");
62
+ });
63
+ if (fiberSymbolKey) {
64
+ return (
65
+ // Legacy cast - may or may not be necessary
66
+ // eslint-disable-next-line replo/no-as-cast
67
+ element[fiberSymbolKey] ?? null
68
+ );
69
+ }
70
+ const keys = Object.keys(element);
71
+ const fiberKey = keys.find((key) => key.startsWith("__reactFiber$"));
72
+ if (fiberKey) {
73
+ return element[fiberKey] ?? null;
74
+ }
75
+ const instanceKey = keys.find((key) => {
76
+ return key.startsWith("__reactInternalInstance$");
77
+ });
78
+ if (instanceKey) {
79
+ return (
80
+ // Legacy cast - may or may not be necessary
81
+ // eslint-disable-next-line replo/no-as-cast
82
+ element[instanceKey] ?? null
83
+ );
84
+ }
85
+ const possibleFiberKey = keys.find((key) => {
86
+ if (!key.startsWith("__react")) {
87
+ return false;
88
+ }
89
+ const value = element[key];
90
+ return value && typeof value === "object" && "_debugSource" in value;
91
+ });
92
+ if (possibleFiberKey) {
93
+ return (
94
+ // Legacy cast - may or may not be necessary
95
+ // eslint-disable-next-line replo/no-as-cast
96
+ element[possibleFiberKey] ?? null
97
+ );
98
+ }
99
+ return null;
100
+ }
101
+ function getComponentName(fiber) {
102
+ if (!fiber?.type) {
103
+ return void 0;
104
+ }
105
+ if (typeof fiber.type === "string") {
106
+ return void 0;
107
+ }
108
+ if (typeof fiber.type === "function") {
109
+ return fiber.type.name || void 0;
110
+ }
111
+ if (typeof fiber.type === "object") {
112
+ return fiber.type.displayName ?? fiber.type.name ?? void 0;
113
+ }
114
+ return void 0;
115
+ }
116
+ function findDebugSource(fiber, maxDepth = 50) {
117
+ let current = fiber;
118
+ let depth = 0;
119
+ while (current && depth < maxDepth) {
120
+ if (current._debugSource) {
121
+ return {
122
+ source: current._debugSource,
123
+ componentName: getComponentName(current)
124
+ };
125
+ }
126
+ if (current._debugOwner?._debugSource) {
127
+ return {
128
+ source: current._debugOwner._debugSource,
129
+ componentName: getComponentName(current._debugOwner)
130
+ };
131
+ }
132
+ current = current.return;
133
+ depth++;
134
+ }
135
+ return null;
136
+ }
137
+ function findDebugSourceReact19(fiber) {
138
+ let current = fiber;
139
+ let depth = 0;
140
+ const maxDepth = 50;
141
+ while (current && depth < maxDepth) {
142
+ const anyFiber = current;
143
+ const possibleSourceKeys = [
144
+ "_debugSource",
145
+ "__source",
146
+ "_source",
147
+ "debugSource"
148
+ ];
149
+ for (const key of possibleSourceKeys) {
150
+ const source = anyFiber[key];
151
+ if (source && typeof source === "object" && "fileName" in source) {
152
+ return {
153
+ // Legacy cast - may or may not be necessary
154
+ // eslint-disable-next-line replo/no-as-cast
155
+ source,
156
+ componentName: getComponentName(current)
157
+ };
158
+ }
159
+ }
160
+ if (current.memoizedProps) {
161
+ const props = current.memoizedProps;
162
+ if (props.__source && typeof props.__source === "object") {
163
+ const source = props.__source;
164
+ if (source.fileName && source.lineNumber) {
165
+ return {
166
+ source: {
167
+ fileName: source.fileName,
168
+ lineNumber: source.lineNumber,
169
+ columnNumber: source.columnNumber
170
+ },
171
+ componentName: getComponentName(current)
172
+ };
173
+ }
174
+ }
175
+ }
176
+ const debugStackSource = parseDebugStackSource(current._debugStack) ?? parseDebugStackSource(current._debugOwner?._debugStack);
177
+ if (debugStackSource) {
178
+ return {
179
+ source: debugStackSource,
180
+ componentName: getComponentName(current)
181
+ };
182
+ }
183
+ current = current.return;
184
+ depth++;
185
+ }
186
+ return null;
187
+ }
188
+ function getSourceLocation(element) {
189
+ let currentElement = element;
190
+ while (currentElement) {
191
+ const fiber = getFiberFromElement(currentElement);
192
+ if (fiber) {
193
+ const debugInfo = findDebugSource(fiber) ?? findDebugSourceReact19(fiber);
194
+ if (debugInfo?.source) {
195
+ return {
196
+ filePath: debugInfo.source.fileName,
197
+ lineNumber: debugInfo.source.lineNumber,
198
+ columnNumber: debugInfo.source.columnNumber,
199
+ componentName: debugInfo.componentName ?? void 0
200
+ };
201
+ }
202
+ }
203
+ currentElement = currentElement.parentElement;
204
+ }
205
+ return void 0;
206
+ }
207
+ function extractEventHandlers(element) {
208
+ const handlers = {};
209
+ const fiber = getFiberFromElement(element);
210
+ if (fiber) {
211
+ const props = fiber.memoizedProps ?? fiber.pendingProps;
212
+ if (props) {
213
+ if (typeof props.onClick === "function") {
214
+ handlers.onClick = stringifyHandler(props.onClick);
215
+ }
216
+ if (typeof props.onMouseEnter === "function") {
217
+ handlers.onMouseEnter = stringifyHandler(props.onMouseEnter);
218
+ }
219
+ if (typeof props.onMouseLeave === "function") {
220
+ handlers.onMouseLeave = stringifyHandler(props.onMouseLeave);
221
+ }
222
+ if (typeof props.onFocus === "function") {
223
+ handlers.onFocus = stringifyHandler(props.onFocus);
224
+ }
225
+ if (typeof props.onBlur === "function") {
226
+ handlers.onBlur = stringifyHandler(props.onBlur);
227
+ }
228
+ }
229
+ }
230
+ if (!handlers.onClick) {
231
+ const onClickMatch = element.outerHTML.match(
232
+ /onClick={([^}]+(?:{[^}]*}[^}]*)*)}/
233
+ );
234
+ if (onClickMatch?.[1]) {
235
+ handlers.onClick = onClickMatch[1].trim();
236
+ }
237
+ }
238
+ return handlers;
239
+ }
240
+ function stringifyHandler(fn) {
241
+ if (typeof fn !== "function") {
242
+ return "";
243
+ }
244
+ const source = fn.toString();
245
+ if (source.startsWith("(") || source.startsWith("function")) {
246
+ const arrowMatch = source.match(/^\(\)\s*=>\s*([\S\s]+)$/);
247
+ if (arrowMatch) {
248
+ return arrowMatch[1].trim();
249
+ }
250
+ const arrowWithParamsMatch = source.match(/^\([^)]*\)\s*=>\s*([\S\s]+)$/);
251
+ if (arrowWithParamsMatch) {
252
+ return arrowWithParamsMatch[1].trim();
253
+ }
254
+ }
255
+ if (source.length > 200) {
256
+ return `${source.slice(0, 200)}...`;
257
+ }
258
+ return source;
259
+ }
260
+ export {
261
+ extractEventHandlers,
262
+ findDebugSource,
263
+ findDebugSourceReact19,
264
+ getComponentName,
265
+ getFiberFromElement,
266
+ getSourceLocation,
267
+ stringifyHandler
268
+ };
269
+ //# sourceMappingURL=fiber.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../editor/select-mode/fiber.ts"],
4
+ "sourcesContent": ["// =============================================================================\n// React Fiber / Source Location Utilities\n// =============================================================================\n\nexport interface SourceLocation {\n filePath: string;\n lineNumber: number;\n columnNumber?: number;\n componentName?: string;\n}\n\nexport interface EventHandlers {\n onClick?: string;\n onMouseEnter?: string;\n onMouseLeave?: string;\n onFocus?: string;\n onBlur?: string;\n}\n\nexport interface ReactFiber {\n _debugSource?: {\n fileName: string;\n lineNumber: number;\n columnNumber?: number;\n };\n _debugStack?: unknown;\n _debugOwner?: ReactFiber;\n type?:\n | { name?: string; displayName?: string }\n | string\n | ((...args: unknown[]) => unknown)\n | null;\n return?: ReactFiber | null;\n memoizedProps?: Record<string, unknown>;\n pendingProps?: Record<string, unknown>;\n}\n\ninterface ReactFiberWithHandlers extends ReactFiber {\n memoizedProps?: Record<string, unknown>;\n pendingProps?: Record<string, unknown>;\n}\n\n// Frames produced by React's own JSX runtime \u2014 these come first in\n// `_debugStack.stack` because the `Error` is constructed inside `jsxDEV`. We\n// want the frame *above* them, which is the actual JSX call site.\n//\n// Turbopack rewrites `node_modules/next/dist/compiled/react-server-dom-*` and\n// friends into mangled chunk paths like\n// `_next/static/chunks/<hash>_next_dist_compiled_react-server-dom-turbopack_<hash>._.js`,\n// so we match both the human-readable module paths and the chunk-name forms.\n// Without this, `_debugStack`'s top frame inside React's RSC runtime gets\n// surfaced as the \"host\" source location for every text node on the page \u2014\n// which then symbolicates back to bundled React, not user code.\nconst REACT_INTERNAL_FRAME_PATTERNS = [\n /react.*jsx-dev-runtime/,\n /react.*jsx-runtime/,\n /react-dom\\//,\n /react\\/cjs\\/react\\./,\n /react-server-dom/,\n /react_server_dom/,\n /next[/_.]dist[/_.]compiled/,\n /\\/node_modules\\/(next|react|react-dom)\\//,\n];\n\nfunction isReactInternalFrame(fileName: string): boolean {\n return REACT_INTERNAL_FRAME_PATTERNS.some((pattern) => {\n return pattern.test(fileName);\n });\n}\n\nfunction parseDebugStackSource(\n debugStack: unknown,\n): ReactFiber[\"_debugSource\"] | null {\n let stackText: string | null = null;\n\n if (typeof debugStack === \"string\") {\n stackText = debugStack;\n } else if (\n typeof debugStack === \"object\" &&\n debugStack &&\n \"stack\" in debugStack\n ) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const stack = (debugStack as { stack?: unknown }).stack;\n if (typeof stack === \"string\") {\n stackText = stack;\n }\n }\n\n if (!stackText) {\n return null;\n }\n\n for (const rawLine of stackText.split(\"\\n\")) {\n const line = rawLine.trim();\n if (!line) {\n continue;\n }\n\n const stackFrameMatch =\n line.match(/^at\\s+(?:.*\\()?(.*):(\\d+):(\\d+)\\)?$/) ??\n line.match(/^(.*):(\\d+):(\\d+)$/);\n\n if (!stackFrameMatch) {\n continue;\n }\n\n const fileName = stackFrameMatch[1]?.trim();\n const lineNumber = Number.parseInt(stackFrameMatch[2] ?? \"\", 10);\n const columnNumber = Number.parseInt(stackFrameMatch[3] ?? \"\", 10);\n\n if (\n !fileName ||\n !Number.isFinite(lineNumber) ||\n !Number.isFinite(columnNumber)\n ) {\n continue;\n }\n\n if (isReactInternalFrame(fileName)) {\n continue;\n }\n\n return {\n fileName,\n lineNumber,\n columnNumber,\n };\n }\n\n return null;\n}\n\nexport function getFiberFromElement(element: HTMLElement): ReactFiber | null {\n if (!element || typeof element !== \"object\") {\n return null;\n }\n\n const symbolKeys = Object.getOwnPropertySymbols(element);\n const fiberSymbolKey = symbolKeys.find((symbolKey) => {\n return symbolKey.toString().includes(\"reactFiber\");\n });\n if (fiberSymbolKey) {\n return (\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n (element as unknown as Record<symbol, ReactFiber>)[fiberSymbolKey] ?? null\n );\n }\n\n const keys = Object.keys(element);\n const fiberKey = keys.find((key) => key.startsWith(\"__reactFiber$\"));\n if (fiberKey) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n return (element as unknown as Record<string, ReactFiber>)[fiberKey] ?? null;\n }\n const instanceKey = keys.find((key) => {\n return key.startsWith(\"__reactInternalInstance$\");\n });\n if (instanceKey) {\n return (\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n (element as unknown as Record<string, ReactFiber>)[instanceKey] ?? null\n );\n }\n\n const possibleFiberKey = keys.find((key) => {\n if (!key.startsWith(\"__react\")) {\n return false;\n }\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const value = (element as unknown as Record<string, unknown>)[key];\n return value && typeof value === \"object\" && \"_debugSource\" in value;\n });\n\n if (possibleFiberKey) {\n return (\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n (element as unknown as Record<string, ReactFiber>)[possibleFiberKey] ??\n null\n );\n }\n\n return null;\n}\n\nexport function getComponentName(\n fiber: ReactFiber | null | undefined,\n): string | undefined {\n if (!fiber?.type) {\n return undefined;\n }\n\n if (typeof fiber.type === \"string\") {\n return undefined;\n }\n\n if (typeof fiber.type === \"function\") {\n return fiber.type.name || undefined;\n }\n\n if (typeof fiber.type === \"object\") {\n return fiber.type.displayName ?? fiber.type.name ?? undefined;\n }\n\n return undefined;\n}\n\nexport function findDebugSource(\n fiber: ReactFiber,\n maxDepth = 50,\n): { source: ReactFiber[\"_debugSource\"]; componentName?: string } | null {\n let current: ReactFiber | null | undefined = fiber;\n let depth = 0;\n\n while (current && depth < maxDepth) {\n if (current._debugSource) {\n return {\n source: current._debugSource,\n componentName: getComponentName(current),\n };\n }\n\n if (current._debugOwner?._debugSource) {\n return {\n source: current._debugOwner._debugSource,\n componentName: getComponentName(current._debugOwner),\n };\n }\n\n current = current.return;\n depth++;\n }\n\n return null;\n}\n\n// NOTE (Derek, 2026-02-12): React 19 changed the internal fiber shape \u2014 _debugSource and\n// _debugOwner behave differently. We keep both versions so the scaffold works regardless\n// of the host project's React version. findDebugSource handles 18, this handles 19.\nexport function findDebugSourceReact19(\n fiber: ReactFiber,\n): { source: ReactFiber[\"_debugSource\"]; componentName?: string } | null {\n let current: ReactFiber | null | undefined = fiber;\n let depth = 0;\n const maxDepth = 50;\n\n while (current && depth < maxDepth) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const anyFiber = current as unknown as Record<string, unknown>;\n const possibleSourceKeys = [\n \"_debugSource\",\n \"__source\",\n \"_source\",\n \"debugSource\",\n ];\n\n for (const key of possibleSourceKeys) {\n const source = anyFiber[key];\n if (source && typeof source === \"object\" && \"fileName\" in source) {\n return {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n source: source as ReactFiber[\"_debugSource\"],\n componentName: getComponentName(current),\n };\n }\n }\n\n if (current.memoizedProps) {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const props = current.memoizedProps as Record<string, unknown>;\n if (props.__source && typeof props.__source === \"object\") {\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const source = props.__source as {\n fileName?: string;\n lineNumber?: number;\n columnNumber?: number;\n };\n if (source.fileName && source.lineNumber) {\n return {\n source: {\n fileName: source.fileName,\n lineNumber: source.lineNumber,\n columnNumber: source.columnNumber,\n },\n componentName: getComponentName(current),\n };\n }\n }\n }\n\n const debugStackSource =\n parseDebugStackSource(current._debugStack) ??\n parseDebugStackSource(current._debugOwner?._debugStack);\n if (debugStackSource) {\n return {\n source: debugStackSource,\n componentName: getComponentName(current),\n };\n }\n\n current = current.return;\n depth++;\n }\n\n return null;\n}\n\nexport function getSourceLocation(\n element: HTMLElement,\n): SourceLocation | undefined {\n let currentElement: HTMLElement | null = element;\n\n while (currentElement) {\n const fiber = getFiberFromElement(currentElement);\n if (fiber) {\n const debugInfo = findDebugSource(fiber) ?? findDebugSourceReact19(fiber);\n if (debugInfo?.source) {\n return {\n filePath: debugInfo.source.fileName,\n lineNumber: debugInfo.source.lineNumber,\n columnNumber: debugInfo.source.columnNumber,\n componentName: debugInfo.componentName ?? undefined,\n };\n }\n }\n\n currentElement = currentElement.parentElement;\n }\n\n return undefined;\n}\n\n/**\n * Extract event handlers from React fiber or DOM element\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function extractEventHandlers(element: HTMLElement): EventHandlers {\n const handlers: EventHandlers = {};\n\n // Try to get handlers from React fiber\n // Legacy cast - may or may not be necessary\n // eslint-disable-next-line replo/no-as-cast\n const fiber = getFiberFromElement(element) as ReactFiberWithHandlers | null;\n if (fiber) {\n const props = fiber.memoizedProps ?? fiber.pendingProps;\n if (props) {\n // Extract onClick handler\n if (typeof props.onClick === \"function\") {\n handlers.onClick = stringifyHandler(props.onClick);\n }\n\n // Extract other handlers\n if (typeof props.onMouseEnter === \"function\") {\n handlers.onMouseEnter = stringifyHandler(props.onMouseEnter);\n }\n if (typeof props.onMouseLeave === \"function\") {\n handlers.onMouseLeave = stringifyHandler(props.onMouseLeave);\n }\n if (typeof props.onFocus === \"function\") {\n handlers.onFocus = stringifyHandler(props.onFocus);\n }\n if (typeof props.onBlur === \"function\") {\n handlers.onBlur = stringifyHandler(props.onBlur);\n }\n }\n }\n\n // Fallback: try to parse from outerHTML (less reliable)\n if (!handlers.onClick) {\n const onClickMatch = element.outerHTML.match(\n /onClick={([^}]+(?:{[^}]*}[^}]*)*)}/,\n );\n if (onClickMatch?.[1]) {\n handlers.onClick = onClickMatch[1].trim();\n }\n }\n\n return handlers;\n}\n\n/**\n * Convert a function to a readable string representation\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function stringifyHandler(fn: unknown): string {\n if (typeof fn !== \"function\") {\n return \"\";\n }\n\n // Get function source\n const source = fn.toString();\n\n // Clean up arrow functions\n if (source.startsWith(\"(\") || source.startsWith(\"function\")) {\n // For arrow functions like () => setCount(c => c + 1)\n const arrowMatch = source.match(/^\\(\\)\\s*=>\\s*([\\S\\s]+)$/);\n if (arrowMatch) {\n return arrowMatch[1]!.trim();\n }\n\n // For arrow functions with params like (e) => handleClick(e)\n const arrowWithParamsMatch = source.match(/^\\([^)]*\\)\\s*=>\\s*([\\S\\s]+)$/);\n if (arrowWithParamsMatch) {\n return arrowWithParamsMatch[1]!.trim();\n }\n }\n\n // Return truncated source for regular functions\n if (source.length > 200) {\n return `${source.slice(0, 200)}...`;\n }\n\n return source;\n}\n"],
5
+ "mappings": "AAqDA,MAAM,gCAAgC;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,qBAAqB,UAA2B;AACvD,SAAO,8BAA8B,KAAK,CAAC,YAAY;AACrD,WAAO,QAAQ,KAAK,QAAQ;AAAA,EAC9B,CAAC;AACH;AAEA,SAAS,sBACP,YACmC;AACnC,MAAI,YAA2B;AAE/B,MAAI,OAAO,eAAe,UAAU;AAClC,gBAAY;AAAA,EACd,WACE,OAAO,eAAe,YACtB,cACA,WA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AAG;AAE3D,UAAM,aAAa,OAAO,MAAM,yBAAyB;AACzD,QAAI,YAAY;AACd,aAAO,WAAW,CAAC,EAAG,KAAK;AAAA,IAC7B;AAGA,UAAM,uBAAuB,OAAO,MAAM,8BAA8B;AACxE,QAAI,sBAAsB;AACxB,aAAO,qBAAqB,CAAC,EAAG,KAAK;AAAA,IACvC;AAAA,EACF;AAGA,MAAI,OAAO,SAAS,KAAK;AACvB,WAAO,GAAG,OAAO,MAAM,GAAG,GAAG,CAAC;AAAA,EAChC;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,12 @@
1
+ import type { DisplayMode } from "../../../_vendor/schemas/generated/selectMode";
2
+ /**
3
+ * Forces a crosshair cursor + disables text selection / drag while the iframe
4
+ * is in `selection` mode. We inject a `<style>` tag into the iframe document
5
+ * (rather than toggling a class on `<html>`) so that the `!important` rule
6
+ * wins against any per-element cursor styling on the page being edited.
7
+ *
8
+ * @author Kevin O'Connell 2026-04-17
9
+ */
10
+ export declare function useCrosshairCursor({ displayMode, }: {
11
+ displayMode: DisplayMode;
12
+ }): void;
@@ -0,0 +1,20 @@
1
+ import { useEffect } from "react";
2
+ function useCrosshairCursor({
3
+ displayMode
4
+ }) {
5
+ useEffect(() => {
6
+ if (displayMode !== "selection") {
7
+ return;
8
+ }
9
+ const styleElement = document.createElement("style");
10
+ styleElement.textContent = "* { cursor: crosshair !important; user-select: none !important; -webkit-user-drag: none !important; }";
11
+ document.head.append(styleElement);
12
+ return () => {
13
+ styleElement.remove();
14
+ };
15
+ }, [displayMode]);
16
+ }
17
+ export {
18
+ useCrosshairCursor
19
+ };
20
+ //# sourceMappingURL=useCrosshairCursor.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../editor/select-mode/hooks/useCrosshairCursor.ts"],
4
+ "sourcesContent": ["import type { DisplayMode } from \"schemas/generated/selectMode\";\n\nimport { useEffect } from \"react\";\n\n/**\n * Forces a crosshair cursor + disables text selection / drag while the iframe\n * is in `selection` mode. We inject a `<style>` tag into the iframe document\n * (rather than toggling a class on `<html>`) so that the `!important` rule\n * wins against any per-element cursor styling on the page being edited.\n *\n * @author Kevin O'Connell 2026-04-17\n */\nexport function useCrosshairCursor({\n displayMode,\n}: {\n displayMode: DisplayMode;\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 const styleElement = document.createElement(\"style\");\n styleElement.textContent =\n \"* { cursor: crosshair !important; user-select: none !important; -webkit-user-drag: none !important; }\";\n document.head.append(styleElement);\n\n return () => {\n styleElement.remove();\n };\n }, [displayMode]);\n}\n"],
5
+ "mappings": "AAEA,SAAS,iBAAiB;AAUnB,SAAS,mBAAmB;AAAA,EACjC;AACF,GAEG;AAED,YAAU,MAAM;AACd,QAAI,gBAAgB,aAAa;AAC/B;AAAA,IACF;AAEA,UAAM,eAAe,SAAS,cAAc,OAAO;AACnD,iBAAa,cACX;AACF,aAAS,KAAK,OAAO,YAAY;AAEjC,WAAO,MAAM;AACX,mBAAa,OAAO;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAClB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,24 @@
1
+ import type { DisplayMode, SelectModeSelectionType } from "../../../_vendor/schemas/generated/selectMode";
2
+ /**
3
+ * Inbound side of the iframe<->parent selectMode bridge.
4
+ *
5
+ * Listens for `SelectModeParentMessage`s and applies them locally:
6
+ * - `SET_DISPLAY_MODE`: switch the iframe between `browse` and `selection`.
7
+ * - `SET_SELECTION_TYPE`: declarative push of the parent's current
8
+ * selection type. The interesting transition is `* → "none"`, which
9
+ * tears down any in-iframe selection frame / in-progress drag — agent-ui
10
+ * drives it from `agentUiState.selectionType` so panel dismiss / submit
11
+ * flow through the same path as exiting selection mode entirely. The
12
+ * regression test in `EditorSelection.spec.tsx` covers the case where
13
+ * losing this used to lock the iframe out of further selections.
14
+ *
15
+ * Also fires `IFRAME_READY` on mount so the parent knows it's safe to push
16
+ * the initial `SET_DISPLAY_MODE` — without this handshake the parent would
17
+ * race the iframe's mount and the first message could be lost.
18
+ *
19
+ * @author Kevin O'Connell 2026-04-17
20
+ */
21
+ export declare function useParentMessaging({ setDisplayMode, setSelectionType, }: {
22
+ setDisplayMode: (displayMode: DisplayMode) => void;
23
+ setSelectionType: (selectionType: SelectModeSelectionType) => void;
24
+ }): void;
@@ -0,0 +1,33 @@
1
+ import { useEffect } from "react";
2
+ import { exhaustiveSwitch } from "../../../_vendor/replo-utils/lib/misc.mjs";
3
+ import { selectModeParentMessageSchema } from "../../../_vendor/schemas/selectMode.mjs";
4
+ function useParentMessaging({
5
+ setDisplayMode,
6
+ setSelectionType
7
+ }) {
8
+ useEffect(() => {
9
+ const handleMessage = (event) => {
10
+ const parsed = selectModeParentMessageSchema.safeParse(event.data);
11
+ if (!parsed.success) {
12
+ return;
13
+ }
14
+ exhaustiveSwitch(parsed.data)({
15
+ "replo:select:setDisplayMode": (message) => {
16
+ setDisplayMode(message.displayMode);
17
+ },
18
+ "replo:select:setSelectionType": (message) => {
19
+ setSelectionType(message.selectionType);
20
+ }
21
+ });
22
+ };
23
+ window.addEventListener("message", handleMessage);
24
+ window.parent.postMessage({ type: "replo:select:iframeReady" }, "*");
25
+ return () => {
26
+ window.removeEventListener("message", handleMessage);
27
+ };
28
+ }, [setDisplayMode, setSelectionType]);
29
+ }
30
+ export {
31
+ useParentMessaging
32
+ };
33
+ //# sourceMappingURL=useParentMessaging.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../editor/select-mode/hooks/useParentMessaging.ts"],
4
+ "sourcesContent": ["import type {\n DisplayMode,\n SelectModeSelectionType,\n} from \"schemas/generated/selectMode\";\n\nimport { useEffect } from \"react\";\n\nimport { exhaustiveSwitch } from \"replo-utils/lib/misc\";\nimport { selectModeParentMessageSchema } from \"schemas/selectMode\";\n\n/**\n * Inbound side of the iframe<->parent selectMode bridge.\n *\n * Listens for `SelectModeParentMessage`s and applies them locally:\n * - `SET_DISPLAY_MODE`: switch the iframe between `browse` and `selection`.\n * - `SET_SELECTION_TYPE`: 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 `IFRAME_READY` on mount so the parent knows it's safe to push\n * the initial `SET_DISPLAY_MODE` \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 setDisplayMode,\n setSelectionType,\n}: {\n setDisplayMode: (displayMode: DisplayMode) => void;\n setSelectionType: (selectionType: SelectModeSelectionType) => void;\n}) {\n // eslint-disable-next-line replo/no-use-effect -- Legacy effect - may or may not be necessary\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n // NOTE (Kevin O'Connell, 2026-04-21): Validate before dispatch so an\n // unrelated message in the same window (e.g. dev-tools, third-party\n // script) doesn't trip `exhaustiveSwitch`. Mirrors the parent-side\n // validation in `PageRenderer` for `SelectModeIframeMessage`.\n const parsed = selectModeParentMessageSchema.safeParse(event.data);\n if (!parsed.success) {\n return;\n }\n\n exhaustiveSwitch(parsed.data)({\n \"replo:select:setDisplayMode\": (message) => {\n setDisplayMode(message.displayMode);\n },\n \"replo:select:setSelectionType\": (message) => {\n setSelectionType(message.selectionType);\n },\n });\n };\n\n window.addEventListener(\"message\", handleMessage);\n window.parent.postMessage({ type: \"replo:select:iframeReady\" }, \"*\");\n\n return () => {\n window.removeEventListener(\"message\", handleMessage);\n };\n }, [setDisplayMode, setSelectionType]);\n}\n"],
5
+ "mappings": "AAKA,SAAS,iBAAiB;AAE1B,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;AAqBvC,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AACF,GAGG;AAED,YAAU,MAAM;AACd,UAAM,gBAAgB,CAAC,UAAwB;AAK7C,YAAM,SAAS,8BAA8B,UAAU,MAAM,IAAI;AACjE,UAAI,CAAC,OAAO,SAAS;AACnB;AAAA,MACF;AAEA,uBAAiB,OAAO,IAAI,EAAE;AAAA,QAC5B,+BAA+B,CAAC,YAAY;AAC1C,yBAAe,QAAQ,WAAW;AAAA,QACpC;AAAA,QACA,iCAAiC,CAAC,YAAY;AAC5C,2BAAiB,QAAQ,aAAa;AAAA,QACxC;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,iBAAiB,WAAW,aAAa;AAChD,WAAO,OAAO,YAAY,EAAE,MAAM,2BAA2B,GAAG,GAAG;AAEnE,WAAO,MAAM;AACX,aAAO,oBAAoB,WAAW,aAAa;AAAA,IACrD;AAAA,EACF,GAAG,CAAC,gBAAgB,gBAAgB,CAAC;AACvC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ import type { DisplayMode, SelectModeSelectionType } from "../../../_vendor/schemas/generated/selectMode";
2
+ import type { SelectModeInteractionSession } from "../selectModeSession";
3
+ export declare function useSelectModeController(): {
4
+ displayMode: DisplayMode;
5
+ interactionSessionRef: import("react").RefObject<SelectModeInteractionSession>;
6
+ setDisplayMode: (nextDisplayMode: DisplayMode) => void;
7
+ setSelectionType: (selectionType: SelectModeSelectionType) => void;
8
+ };
@@ -0,0 +1,49 @@
1
+ import { useCallback, useRef, useState } from "react";
2
+ import { hideSelectionFrame } from "../selectionFrame";
3
+ import { IDLE_SESSION } from "../selectModeSession";
4
+ function resetInteractionSession({
5
+ interactionSessionRef
6
+ }) {
7
+ const currentSession = interactionSessionRef.current;
8
+ if (currentSession.type === "drag" && currentSession.hasExceededThreshold) {
9
+ window.parent.postMessage(
10
+ {
11
+ type: "replo:select:dragRectUpdated",
12
+ rect: null
13
+ },
14
+ "*"
15
+ );
16
+ }
17
+ hideSelectionFrame();
18
+ interactionSessionRef.current = IDLE_SESSION;
19
+ }
20
+ function useSelectModeController() {
21
+ const [displayMode, setDisplayModeState] = useState("browse");
22
+ const displayModeRef = useRef("browse");
23
+ const interactionSessionRef = useRef(IDLE_SESSION);
24
+ const setSelectionType = useCallback(
25
+ (selectionType) => {
26
+ if (selectionType === "none") {
27
+ resetInteractionSession({ interactionSessionRef });
28
+ }
29
+ },
30
+ []
31
+ );
32
+ const setDisplayMode = useCallback((nextDisplayMode) => {
33
+ if (displayModeRef.current === "selection" && nextDisplayMode !== "selection") {
34
+ resetInteractionSession({ interactionSessionRef });
35
+ }
36
+ displayModeRef.current = nextDisplayMode;
37
+ setDisplayModeState(nextDisplayMode);
38
+ }, []);
39
+ return {
40
+ displayMode,
41
+ interactionSessionRef,
42
+ setDisplayMode,
43
+ setSelectionType
44
+ };
45
+ }
46
+ export {
47
+ useSelectModeController
48
+ };
49
+ //# sourceMappingURL=useSelectModeController.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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, useState } from \"react\";\n\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 window.parent.postMessage(\n {\n type: \"replo:select:dragRectUpdated\",\n rect: null,\n },\n \"*\",\n );\n }\n hideSelectionFrame();\n interactionSessionRef.current = IDLE_SESSION;\n}\n\nexport function useSelectModeController() {\n const [displayMode, setDisplayModeState] = useState<DisplayMode>(\"browse\");\n const displayModeRef = useRef<DisplayMode>(\"browse\");\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 displayModeRef.current === \"selection\" &&\n nextDisplayMode !== \"selection\"\n ) {\n resetInteractionSession({ interactionSessionRef });\n }\n\n displayModeRef.current = nextDisplayMode;\n setDisplayModeState(nextDisplayMode);\n }, []);\n\n return {\n displayMode,\n interactionSessionRef,\n setDisplayMode,\n setSelectionType,\n };\n}\n"],
5
+ "mappings": "AAMA,SAAS,aAAa,QAAQ,gBAAgB;AAE9C,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,WAAO,OAAO;AAAA,MACZ;AAAA,QACE,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,qBAAmB;AACnB,wBAAsB,UAAU;AAClC;AAEO,SAAS,0BAA0B;AACxC,QAAM,CAAC,aAAa,mBAAmB,IAAI,SAAsB,QAAQ;AACzE,QAAM,iBAAiB,OAAoB,QAAQ;AACnD,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,eAAe,YAAY,eAC3B,oBAAoB,aACpB;AACA,8BAAwB,EAAE,sBAAsB,CAAC;AAAA,IACnD;AAEA,mBAAe,UAAU;AACzB,wBAAoB,eAAe;AAAA,EACrC,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,22 @@
1
+ import type { MutableRefObject } from "react";
2
+ import type { DisplayMode } from "../../../_vendor/schemas/generated/selectMode";
3
+ import type { SelectModeInteractionSession } from "../selectModeSession";
4
+ /**
5
+ * Tracks whichever element is under the user's pointer while in `selection`
6
+ * mode and reports its bounding rect to the parent so the parent can render
7
+ * the hover overlay.
8
+ *
9
+ * Two behaviors worth knowing about:
10
+ * - During an active drag we suppress hover updates; the drag overlay is
11
+ * the only highlight we want visible.
12
+ * - On scroll/wheel/resize we re-run the hover lookup from the last known
13
+ * pointer position (we use rAF to coalesce). Without this, scrolling
14
+ * over an already-hovered element wouldn't update the highlight to the
15
+ * new element actually under the cursor.
16
+ *
17
+ * @author Kevin O'Connell 2026-04-17
18
+ */
19
+ export declare function useSelectionHover({ displayMode, interactionSessionRef, }: {
20
+ displayMode: DisplayMode;
21
+ interactionSessionRef: MutableRefObject<SelectModeInteractionSession>;
22
+ }): void;