@antv/gpt-vis 0.0.1 → 0.0.2

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.
@@ -1,12 +1,6 @@
1
1
  import React from 'react';
2
- import './index.less';
3
- import { ChartComponents, CodeBlockComponent, ExtraRenderers, WithChartCodeOptions } from './type';
4
- export declare const withCodeBlock: (options: {
5
- components: ChartComponents;
6
- extraRenderers?: ExtraRenderers;
7
- debug?: boolean;
8
- loadingTimeout?: number;
9
- }) => CodeBlockComponent;
2
+ import './index.css';
3
+ import { WithChartCodeOptions } from './type';
10
4
  export declare const withChartCode: (options: WithChartCodeOptions) => keyof JSX.IntrinsicElements | import("hast-util-to-jsx-runtime/lib/components").Component<React.ClassAttributes<HTMLElement> & React.HTMLAttributes<HTMLElement> & import("hast-util-to-jsx-runtime/lib/components").ExtraProps> | undefined;
11
5
  /**
12
6
  * Includes built-in chart components such as line charts, pie charts, etc.
@@ -8,7 +8,7 @@ import { LoadingOutlined } from '@ant-design/icons';
8
8
  import { get } from 'lodash-es';
9
9
  import React, { useRef, useState } from 'react';
10
10
  import { DEFAULT_CHART_COMPONENTS } from "../constants";
11
- import "./index.less";
11
+ import "./index.css";
12
12
  var Loading = function Loading() {
13
13
  return /*#__PURE__*/React.createElement("div", {
14
14
  className: "gpt-vis-loading"
@@ -21,7 +21,7 @@ var Loading = function Loading() {
21
21
  }
22
22
  })), /*#__PURE__*/React.createElement("p", null, "\u6570\u636E\u751F\u6210\u4E2D"));
23
23
  };
24
- export var withCodeBlock = function withCodeBlock(options) {
24
+ var withCodeBlock = function withCodeBlock(options) {
25
25
  // Render code block component
26
26
  return function CodeBlock(props) {
27
27
  var _className$match;
@@ -35,6 +35,8 @@ export var withCodeBlock = function withCodeBlock(options) {
35
35
  var isVisChart = className.includes('language-vis-chart');
36
36
  var components = options.components,
37
37
  extraRenderers = options.extraRenderers,
38
+ languageRenderers = options.languageRenderers,
39
+ DefaultRenderer = options.defaultRenderer,
38
40
  debug = options.debug,
39
41
  _options$loadingTimeo = options.loadingTimeout,
40
42
  loadingTimeout = _options$loadingTimeo === void 0 ? 5000 : _options$loadingTimeo;
@@ -82,15 +84,16 @@ export var withCodeBlock = function withCodeBlock(options) {
82
84
  }, /*#__PURE__*/React.createElement(ChartComponent, chartJson));
83
85
  }
84
86
 
85
- // If the code block math extraRenderer languageName, the corresponding extraRenderers component
87
+ // If the code block math extraRenderer languageName, the corresponding extra languageRenderers component
86
88
  var languageName = ((_className$match = className.match(/language-(.*)/)) === null || _className$match === void 0 ? void 0 : _className$match[1]) || '';
87
- var ExtraRendererComponent = extraRenderers && extraRenderers[languageName];
89
+ var extraLanguageRenderers = extraRenderers || languageRenderers;
90
+ var ExtraRendererComponent = extraLanguageRenderers && extraLanguageRenderers[languageName];
88
91
  if (ExtraRendererComponent) {
89
92
  return /*#__PURE__*/React.createElement(ExtraRendererComponent, props);
90
93
  }
91
94
 
92
95
  // If the code block is not a VisChart, render plain code
93
- return /*#__PURE__*/React.createElement("code", _extends({}, rest, {
96
+ return DefaultRenderer ? /*#__PURE__*/React.createElement(DefaultRenderer, props) : /*#__PURE__*/React.createElement("code", _extends({}, rest, {
94
97
  className: className
95
98
  }), children);
96
99
  };
@@ -2,9 +2,30 @@ import { FC } from 'react';
2
2
  import { Components, ExtraProps } from 'react-markdown';
3
3
  import { BaseChartProps } from '../types';
4
4
  export type WithChartCodeOptions = {
5
+ /**
6
+ * 要额外加载的图表组件
7
+ */
5
8
  components: ChartComponents[];
6
- extraRenderers?: ExtraRenderers;
9
+ /**
10
+ * @deprecated
11
+ * 请使用 languageRenderers
12
+ */
13
+ extraRenderers?: LanguageRenderers;
14
+ /**
15
+ * 自定义其它语言代码块渲染器
16
+ */
17
+ languageRenderers?: LanguageRenderers;
18
+ /**
19
+ * 默认的代码渲染器
20
+ */
21
+ defaultRenderer?: CodeRenderer;
22
+ /**
23
+ * 打开调试日志
24
+ */
7
25
  debug?: boolean;
26
+ /**
27
+ * 设置loading动画的超时时间,默认为 5s
28
+ */
8
29
  loadingTimeout?: number;
9
30
  };
10
31
  /**
@@ -24,7 +45,11 @@ export interface ChartComponents {
24
45
  * 代码块渲染器接口
25
46
  */
26
47
  export type CodeBlockComponent = Components['code'];
27
- /** 额外的渲染器选项 */
28
- export interface ExtraRenderers {
29
- [key: string]: FC<React.ClassAttributes<HTMLElement> & React.HTMLAttributes<HTMLElement> & ExtraProps>;
48
+ type CodeRenderer = FC<React.ClassAttributes<HTMLElement> & React.HTMLAttributes<HTMLElement> & ExtraProps>;
49
+ /**
50
+ * 自定义其它语言代码块渲染器
51
+ */
52
+ interface LanguageRenderers {
53
+ [key: string]: CodeRenderer;
30
54
  }
55
+ export {};
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { Options } from 'react-markdown';
3
+ export interface GPTVisProps extends Options {
4
+ /**
5
+ * 需要被渲染的 markdown 字符串
6
+ */
7
+ children: string;
8
+ }
9
+ declare const GPTVis: React.FC<GPTVisProps>;
10
+ export default GPTVis;
@@ -1,19 +1,23 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ var _excluded = ["children", "components", "rehypePlugins"];
3
6
  import React from 'react';
4
7
  import Markdown from 'react-markdown';
5
8
  import rehypeRaw from 'rehype-raw';
6
9
  import { withDefaultChartCode } from "../ChartCodeRender";
7
- var MarkdownVis = function MarkdownVis(_ref) {
10
+ var GPTVis = function GPTVis(_ref) {
8
11
  var children = _ref.children,
9
12
  components = _ref.components,
10
- rehypePlugins = _ref.rehypePlugins;
13
+ rehypePlugins = _ref.rehypePlugins,
14
+ rest = _objectWithoutProperties(_ref, _excluded);
11
15
  var CodeBlock = withDefaultChartCode();
12
- return /*#__PURE__*/React.createElement(Markdown, {
16
+ return /*#__PURE__*/React.createElement(Markdown, _extends({
13
17
  components: _objectSpread({
14
18
  code: CodeBlock
15
19
  }, components),
16
20
  rehypePlugins: [rehypeRaw].concat(_toConsumableArray(rehypePlugins || []))
17
- }, children);
21
+ }, rest), children);
18
22
  };
19
- export default MarkdownVis;
23
+ export default GPTVis;
@@ -1,11 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import Area from "../Area";
3
+ import Column from "../Column";
3
4
  import Line from "../Line";
4
- import HeatMap from "../HeatMap";
5
- import PathMap from "../PathMap";
6
5
  import Pie from "../Pie";
7
- import PinMap from "../PinMap";
8
- import WordCloud from "../WordCloud";
9
- import Column from "../Column";
10
6
  import { ChartType } from "../types";
11
- export var DEFAULT_CHART_COMPONENTS = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ChartType.Pie, Pie), ChartType.Area, Area), ChartType.Column, Column), ChartType.Line, Line), ChartType.WordCloud, WordCloud), ChartType.PinMap, PinMap), ChartType.PathMap, PathMap), ChartType.HeatMap, HeatMap);
7
+ import WordCloud from "../WordCloud";
8
+ export var DEFAULT_CHART_COMPONENTS = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ChartType.Pie, Pie), ChartType.Area, Area), ChartType.Column, Column), ChartType.Line, Line), ChartType.WordCloud, WordCloud);
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- export { default as HeatMap } from './HeatMap';
2
- export { default as MarkdownVis } from './MarkdownVis';
3
- export { default as Message } from './Message';
4
- export { default as PathMap } from './PathMap';
1
+ export { default as Area, type AreaProps } from './Area';
2
+ export { default as Column, type ColumnProps } from './Column';
3
+ export { default as Line, type LineProps } from './Line';
5
4
  export { default as Pie } from './Pie';
6
- export { default as PinMap } from './PinMap';
7
5
  export { default as WordCloud } from './WordCloud';
8
6
  export { withChartCode, withDefaultChartCode } from './ChartCodeRender';
7
+ export { default as GPTVis } from './GPTVis';
8
+ /**
9
+ * @deprecated
10
+ * 请使用 GPTVis
11
+ */
12
+ export { default as MarkdownVis } from './GPTVis';
9
13
  export * from './types';
10
- export { default as Column, type ColumnProps } from './Column';
11
- export { default as Line, type LineProps } from './Line';
12
- export { default as Area, type AreaProps } from './Area';
package/dist/index.js CHANGED
@@ -1,12 +1,17 @@
1
- export { default as HeatMap } from "./HeatMap";
2
- export { default as MarkdownVis } from "./MarkdownVis";
3
- export { default as Message } from "./Message";
4
- export { default as PathMap } from "./PathMap";
1
+ export { default as Area } from "./Area";
2
+ export { default as Column } from "./Column";
3
+ export { default as Line } from "./Line";
5
4
  export { default as Pie } from "./Pie";
6
- export { default as PinMap } from "./PinMap";
7
5
  export { default as WordCloud } from "./WordCloud";
6
+ // export { default as HeatMap } from './HeatMap';
7
+ // export { default as PathMap } from './PathMap';
8
+ // export { default as PinMap } from './PinMap';
9
+
8
10
  export { withChartCode, withDefaultChartCode } from "./ChartCodeRender";
9
- export * from "./types";
10
- export { default as Column } from "./Column";
11
- export { default as Line } from "./Line";
12
- export { default as Area } from "./Area";
11
+ export { default as GPTVis } from "./GPTVis";
12
+ /**
13
+ * @deprecated
14
+ * 请使用 GPTVis
15
+ */
16
+ export { default as MarkdownVis } from "./GPTVis";
17
+ export * from "./types";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/gpt-vis",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A chart library for LLM Agent",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
- import { Options } from 'react-markdown';
3
- export type MarkdownVisProps = {
4
- /**
5
- * 需要被渲染的 markdown 字符串
6
- */
7
- children: string;
8
- /**
9
- * 注册的组件
10
- */
11
- components?: Options['components'];
12
- /**
13
- * 注册的 rehype 插件
14
- */
15
- rehypePlugins: Options['rehypePlugins'];
16
- /**
17
- * CSS Properties
18
- */
19
- style?: React.CSSProperties;
20
- };
21
- declare const MarkdownVis: React.FC<MarkdownVisProps>;
22
- export default MarkdownVis;
File without changes