react-spot 0.0.1

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.
@@ -0,0 +1,79 @@
1
+ import type { ResolvedSourceInfo } from './source-location-resolver';
2
+
3
+ /**
4
+ * React Fiber 节点的简化类型定义。
5
+ *
6
+ * 仅包含 react-spot 运行时需要访问的属性,
7
+ * 不依赖 React 内部类型以降低耦合。
8
+ */
9
+ export type Fiber = {
10
+ type: string | ((...args: unknown[]) => unknown) | Record<string, unknown>;
11
+ _debugOwner: Fiber | null;
12
+ _debugStack: Error;
13
+ /** fiber 树的父节点指针,沿此链可获得完整的组件层级(而非仅所有权链) */
14
+ return: Fiber | null;
15
+ memoizedProps?: Record<string, unknown>;
16
+ child?: Fiber | null;
17
+ sibling?: Fiber | null;
18
+ };
19
+
20
+ /**
21
+ * 从 DOM 元素到其所属 React 组件的追踪信息。
22
+ *
23
+ * 由 buildFiberChain 生成,包含组件名、栈帧、fiber 引用和 props,
24
+ * 是 react-spot 内部组件链路的核心数据结构。
25
+ */
26
+ export type ClickToNodeInfo = {
27
+ componentName: string;
28
+ /** 原始栈帧行,如 "at LevelD (http://…:18:26)" */
29
+ stackFrame: string | undefined;
30
+ /** React fiber 节点引用 */
31
+ fiber: Fiber;
32
+ props: Record<string, unknown> | undefined;
33
+ };
34
+
35
+ /**
36
+ * 判断链路条目是否对应原生 DOM 元素(span、div 等)。
37
+ *
38
+ * 此类条目保留在完整 chain 中供精确定位 JSX 标签,
39
+ * 但不应出现在面包屑或右键菜单的组件层级视图中。
40
+ */
41
+ export function isHostFiberEntry(entry: ClickToNodeInfo): boolean {
42
+ return typeof entry.fiber.type === 'string';
43
+ }
44
+
45
+ /**
46
+ * 组件链路中单个组件的轻量句柄。
47
+ *
48
+ * 暴露给外部消费者(如 getClickTarget 回调),
49
+ * 提供组件名和 props 的即时访问,以及延迟的源码定位能力。
50
+ */
51
+ export interface ComponentHandle {
52
+ componentName: string;
53
+ props: Record<string, unknown> | undefined;
54
+ /** 在链路中的位置(0 = 最接近被点击 DOM 的组件) */
55
+ index: number;
56
+ /**
57
+ * 延迟解析原始源码位置。
58
+ * 仅在调用时才触发 source-map 解析,结果会被缓存。
59
+ */
60
+ resolveSource: () => Promise<{
61
+ source: string;
62
+ line: number;
63
+ column: number;
64
+ } | null>;
65
+ }
66
+
67
+ /**
68
+ * 导航事件,在跳转到编辑器时触发。
69
+ *
70
+ * 当配置了 onNavigate 回调时,此事件替代默认的 protocol URL 跳转。
71
+ */
72
+ export interface NavigationEvent {
73
+ source: string;
74
+ line: number;
75
+ column: number;
76
+ /** 编辑器协议 URL,如 cursor://file/… */
77
+ url: string;
78
+ componentName?: string;
79
+ }
package/src/index.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { ReactSpot as ReactSpotImpl } from './react/ReactSpot';
2
+
3
+ /**
4
+ * In production builds the dev-only component is replaced with a no-op that
5
+ * renders nothing. Because the import of `ReactSpotImpl` is then unused,
6
+ * bundlers that honour `sideEffects: false` (webpack, Rollup, Vite, esbuild)
7
+ * can tree-shake the entire implementation module **and** its transitive
8
+ * dependencies (`@radix-ui/react-popover`, `@uiw/react-json-view`, etc.).
9
+ */
10
+ const ReactSpot: typeof ReactSpotImpl =
11
+ // biome-ignore lint/suspicious/noExplicitAny: noop stub only reachable on the production dead-code path
12
+ process.env.NODE_ENV === 'development' ? ReactSpotImpl : ((() => null) as any);
13
+
14
+ export { ReactSpot };
15
+ export { configureSourceRoot, clearCaches } from './core/source-location-resolver';
16
+ export type { ComponentHandle, NavigationEvent, ReactSpotProps } from './react/ReactSpot';
17
+
18
+ export type {
19
+ ChainTransformer,
20
+ ChainTransformContext,
21
+ TransformedEntry,
22
+ } from './core/chain-transformer';
23
+ export { createFormattedMessageTransformer } from './transformers/formatted-message';
24
+ export { findJsxPropValueLocation } from './transformers/formatted-message';
25
+ export type { TransformerRule } from './transformers/transformer-rule';
26
+ export { TRANSFORMER_PRESETS, createRuleBasedTransformer } from './transformers/transformer-rule';