react-ai-renderer 0.1.19 → 0.1.21

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,138 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * 骨架图配置接口
5
+ */
6
+ interface SkeletonConfig {
7
+ /** 自定义骨架图组件 */
8
+ component?: React.ComponentType<SkeletonProps>;
9
+ /** 自定义骨架图元素 */
10
+ element?: React.ReactElement;
11
+ /** 自定义骨架图生成函数 */
12
+ generator?: (props: SkeletonProps) => React.ReactElement;
13
+ /** 是否启用自动生成 */
14
+ autoGenerate?: boolean;
15
+ }
16
+ /**
17
+ * 骨架图组件的属性
18
+ */
19
+ interface SkeletonProps {
20
+ componentName: string;
21
+ componentData?: ComponentData;
22
+ props?: Record<string, any>;
23
+ style?: React.CSSProperties;
24
+ }
25
+
26
+ interface ComponentData {
27
+ type: "text" | "component";
28
+ value: string;
29
+ props?: Record<string, any>;
30
+ children?: ComponentData[] | string;
31
+ selfClosing?: boolean;
32
+ isComplete?: boolean;
33
+ }
34
+ interface BaseComponentHandler {
35
+ name: string;
36
+ component: React.ComponentType<any>;
37
+ }
38
+ interface ComponentHandler extends BaseComponentHandler {
39
+ selfClosing: boolean;
40
+ /** 组件开始渲染时的钩子(组件进入渲染流程时立即调用) */
41
+ onRenderStart?: (item: ComponentData, scope: any) => void;
42
+ /** 组件渲染过程中的钩子(当 isComplete 为 false 时调用) */
43
+ onRenderProcess?: (item: ComponentData, scope: any) => void;
44
+ /** 组件渲染完成后的钩子(当 isComplete 为 true 时调用) */
45
+ onRenderFinished?: (item: ComponentData, scope: any) => void;
46
+ /** @deprecated 使用 onRenderProcess 替代 */
47
+ onRender?: (item: ComponentData, scope: any) => void;
48
+ /** 自定义加载组件,可以是 React 组件、React 元素、字符串、布尔值或返回 React 元素的函数 */
49
+ loader?: React.ComponentType<any> | React.ReactElement | string | boolean | ((componentName: string) => React.ReactElement);
50
+ /** 骨架图配置,用于在加载时显示骨架图。如果未提供且 loader 也未提供,将自动根据组件名称生成骨架图 */
51
+ skeleton?: SkeletonConfig;
52
+ /** 组件的显示标签,用于在占位组件中显示 */
53
+ label?: string;
54
+ }
55
+ /** 增强模式的组件配置 */
56
+ interface EnhancedComponentConfig {
57
+ /** 组件本身 */
58
+ value: React.ComponentType<any>;
59
+ /** 组件的显示标签 */
60
+ label?: string;
61
+ /** 自定义加载组件,可以是 React 组件、React 元素、字符串、布尔值或返回 React 元素的函数 */
62
+ loader?: React.ComponentType<any> | React.ReactElement | string | boolean | ((componentName: string) => React.ReactElement);
63
+ /** 骨架图配置,用于在加载时显示骨架图。如果未提供且 loader 也未提供,将自动根据组件名称生成骨架图 */
64
+ skeleton?: SkeletonConfig;
65
+ /** 组件开始渲染时的钩子 */
66
+ onRenderStart?: (item: ComponentData, scope: any) => void;
67
+ /** 组件渲染过程中的钩子 */
68
+ onRenderProcess?: (item: ComponentData, scope: any) => void;
69
+ /** 组件渲染完成后的钩子 */
70
+ onRenderFinished?: (item: ComponentData, scope: any) => void;
71
+ /** 是否自闭合 */
72
+ selfClosing?: boolean;
73
+ }
74
+ /** 组件值类型:可以是组件本身,也可以是增强配置对象 */
75
+ type ComponentValue = React.ComponentType<any> | EnhancedComponentConfig;
76
+ interface ParserState {
77
+ position: number;
78
+ stack: ComponentData[];
79
+ buffer: string;
80
+ }
81
+ interface ParseResult {
82
+ props: Record<string, any>;
83
+ endIndex: number;
84
+ selfClosing?: boolean;
85
+ }
86
+ interface ReactMarkdownProps {
87
+ children: string;
88
+ components?: Record<string, React.ComponentType<any>>;
89
+ componentHandlers?: ComponentHandler[];
90
+ remarkPlugins?: any[];
91
+ rehypePlugins?: any[];
92
+ scope?: any;
93
+ [key: string]: any;
94
+ }
95
+ interface StructuredRenderItem {
96
+ type: 'text' | 'component';
97
+ value: string;
98
+ }
99
+ interface ReactAIRendererProps {
100
+ /** 要渲染的 Markdown/MDX 内容 */
101
+ content?: string;
102
+ /** 作用域对象,用于传递变量和函数给组件 */
103
+ scope?: Record<string, any>;
104
+ /** 自定义组件映射,支持普通模式(组件)和增强模式(配置对象) */
105
+ components?: Record<string, ComponentValue>;
106
+ /** 子元素,作为 content 的替代方案 */
107
+ children?: string;
108
+ /** 组件处理器数组 */
109
+ componentHandlers?: ComponentHandler[];
110
+ /** MdxLayout 相关配置 */
111
+ /** 是否注入 GitHub Markdown 样式 */
112
+ useGithubStyles?: boolean;
113
+ /** MdxLayout 的自定义类名 */
114
+ mdxLayoutClassName?: string;
115
+ /** MdxLayout 的自定义样式 */
116
+ mdxLayoutStyle?: React.CSSProperties;
117
+ /** 其他传递给组件的属性 */
118
+ [key: string]: any;
119
+ }
120
+
121
+ declare function ReactAIRenderer({ content, scope, components, children, componentHandlers, useGithubStyles, mdxLayoutClassName, mdxLayoutStyle }: ReactAIRendererProps): React.JSX.Element | null;
122
+
123
+ interface ThinkProps {
124
+ content: string;
125
+ children?: React.ReactNode;
126
+ }
127
+
128
+ declare const BuiltInComponents: {
129
+ _THINK: React.FC<ThinkProps>;
130
+ pre: (props: any) => React.JSX.Element;
131
+ code: (props: any) => React.JSX.Element;
132
+ p: (pProps: any) => React.JSX.Element;
133
+ a: (aProps: any) => React.JSX.Element;
134
+ video: ({ node, ...props }: any) => React.JSX.Element;
135
+ audio: ({ node, ...props }: any) => React.JSX.Element;
136
+ };
137
+
138
+ export { BaseComponentHandler, BuiltInComponents, ComponentData, ComponentHandler, ComponentValue, EnhancedComponentConfig, ParseResult, ParserState, ReactAIRenderer, ReactAIRendererProps, ReactMarkdownProps, StructuredRenderItem };