@antv/gpt-vis 0.5.13 → 0.6.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.
@@ -127,11 +127,38 @@ var RenderVisChart = (0, import_react.memo)(
127
127
  return "chart";
128
128
  };
129
129
  const [activeTab, setActiveTab] = (0, import_react.useState)(getValidDefaultTab());
130
- let chartJson;
130
+ let chartJson = null;
131
+ let parseError = null;
132
+ let type;
131
133
  try {
132
134
  chartJson = JSON.parse(content);
135
+ type = chartJson == null ? void 0 : chartJson.type;
133
136
  } catch (e) {
134
- const parseError = e;
137
+ parseError = e;
138
+ }
139
+ const isG6 = type ? G6List.includes(type) : false;
140
+ const handleResize = (0, import_react.useMemo)(() => {
141
+ const debouncedFn = (0, import_lodash.debounce)(() => {
142
+ var _a, _b, _c;
143
+ const chart = chartRef.current;
144
+ const container = chartContainerRef.current;
145
+ if (!chart || !container || !(container instanceof HTMLElement)) {
146
+ return;
147
+ }
148
+ try {
149
+ if (isG6) {
150
+ (_a = chart.resize) == null ? void 0 : _a.call(chart);
151
+ (_b = chart.autoFit) == null ? void 0 : _b.call(chart);
152
+ } else {
153
+ (_c = chart.changeSize) == null ? void 0 : _c.call(chart);
154
+ }
155
+ } catch (error) {
156
+ console.error("Failed to resize chart:", error);
157
+ }
158
+ }, 150);
159
+ return debouncedFn;
160
+ }, [isG6]);
161
+ if (parseError) {
135
162
  if (timeoutRef.current) {
136
163
  clearTimeout(timeoutRef.current);
137
164
  if (debug) {
@@ -152,13 +179,13 @@ var RenderVisChart = (0, import_react.memo)(
152
179
  }
153
180
  return /* @__PURE__ */ import_react.default.createElement("div", null, labels.parseError);
154
181
  }
155
- const { type, ...chartProps } = chartJson;
156
- const ChartComponent = components[type];
182
+ const { type: chartType, ...chartProps } = chartJson;
183
+ const ChartComponent = components[chartType];
157
184
  if (debug) {
158
185
  console.log("GPT-Vis withChartCode get chartJson parse from vis-chart code block", chartJson);
159
186
  }
160
187
  if (!ChartComponent) {
161
- const message = `${labels.unsupportedChart}: "${type}"`;
188
+ const message = `${labels.unsupportedChart}: "${chartType}"`;
162
189
  if (errorRender) {
163
190
  return errorRender({
164
191
  error: new Error(message),
@@ -167,8 +194,7 @@ var RenderVisChart = (0, import_react.memo)(
167
194
  }
168
195
  return /* @__PURE__ */ import_react.default.createElement("div", null, message);
169
196
  }
170
- const FallbackComponent = (fallbackProps) => {
171
- const { error } = fallbackProps;
197
+ const FallbackComponent = ({ error }) => {
172
198
  if (!hasRenderError) {
173
199
  setHasRenderError(true);
174
200
  if (showCodeTab && showTabs) {
@@ -203,14 +229,13 @@ var RenderVisChart = (0, import_react.memo)(
203
229
  const result = await (0, import_snapdom.snapdom)(chartContainerRef.current, { scale: 2 });
204
230
  await result.download({
205
231
  format: "png",
206
- filename: `chart-${type}-${Date.now()}`
232
+ filename: `chart-${chartType}-${Date.now()}`
207
233
  });
208
234
  }
209
235
  } catch (error) {
210
236
  console.error("Download image failed:", error);
211
237
  }
212
238
  };
213
- const isG6 = G6List.includes(type);
214
239
  const handleZoomOut = () => {
215
240
  if (chartRef.current && typeof chartRef.current.zoomTo === "function") {
216
241
  const currentZoom = chartRef.current.getZoom() || 1;
@@ -225,29 +250,6 @@ var RenderVisChart = (0, import_react.memo)(
225
250
  chartRef.current.zoomTo(newZoom);
226
251
  }
227
252
  };
228
- const handleResize = (0, import_react.useMemo)(() => {
229
- var _a;
230
- const debouncedFn = (0, import_lodash.debounce)(() => {
231
- var _a2, _b, _c;
232
- const chart = chartRef.current;
233
- const container = chartContainerRef.current;
234
- if (!chart || !container || !(container instanceof HTMLElement)) {
235
- return;
236
- }
237
- try {
238
- if (isG6) {
239
- (_a2 = chart.resize) == null ? void 0 : _a2.call(chart);
240
- (_b = chart.autoFit) == null ? void 0 : _b.call(chart);
241
- } else {
242
- (_c = chart.changeSize) == null ? void 0 : _c.call(chart);
243
- }
244
- } catch (error) {
245
- console.error("Failed to resize chart:", error);
246
- }
247
- }, 150);
248
- (_a = debouncedFn.cancel) == null ? void 0 : _a.call(debouncedFn);
249
- return debouncedFn;
250
- }, [isG6]);
251
253
  if (!showTabs) {
252
254
  return /* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis", style }, /* @__PURE__ */ import_react.default.createElement(import_styles.GlobalStyles, null), /* @__PURE__ */ import_react.default.createElement(import_rc_resize_observer.default, { onResize: handleResize }, /* @__PURE__ */ import_react.default.createElement(import_styles.ChartWrapper, { ref: chartContainerRef }, /* @__PURE__ */ import_react.default.createElement(
253
255
  import_react_error_boundary.ErrorBoundary,
@@ -302,7 +304,7 @@ var RenderVisChart = (0, import_react.memo)(
302
304
  }
303
305
  }
304
306
  },
305
- /* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis", type }, /* @__PURE__ */ import_react.default.createElement(import_styles.GlobalStyles, null), /* @__PURE__ */ import_react.default.createElement(import_rc_resize_observer.default, { onResize: handleResize }, /* @__PURE__ */ import_react.default.createElement(import_styles.ChartWrapper, { ref: chartContainerRef }, /* @__PURE__ */ import_react.default.createElement(
307
+ /* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis", type: chartType }, /* @__PURE__ */ import_react.default.createElement(import_styles.GlobalStyles, null), /* @__PURE__ */ import_react.default.createElement(import_rc_resize_observer.default, { onResize: handleResize }, /* @__PURE__ */ import_react.default.createElement(import_styles.ChartWrapper, { ref: chartContainerRef }, /* @__PURE__ */ import_react.default.createElement(
306
308
  ChartComponent,
307
309
  {
308
310
  ...chartProps,
@@ -47,7 +47,7 @@ var import_styled_components = __toESM(require("styled-components"));
47
47
  var StyledGPTVis = import_styled_components.default.div`
48
48
  min-width: 300px;
49
49
  max-width: 100%;
50
- height: ${({ type }) => type === "table" ? "auto" : "300px"};
50
+ height: ${({ type }) => type === "table" || type === "spreadsheet" ? "auto" : "300px"};
51
51
  /* height: 300px; */
52
52
  overflow: hidden;
53
53
  position: relative;
@@ -7,6 +7,8 @@ type SankeyDatum = {
7
7
  };
8
8
  export type SankeyProps = BasePlotProps<SankeyDatum> & Theme & Style & {
9
9
  nodeAlign?: 'left' | 'center' | 'right' | 'justify';
10
+ width?: number;
11
+ height?: number;
10
12
  };
11
13
  declare const Sankey: (props: SankeyProps) => React.JSX.Element;
12
14
  export default Sankey;
@@ -79,6 +79,7 @@ var defaultConfig = (props) => {
79
79
  };
80
80
  };
81
81
  var Sankey = (props) => {
82
+ const { width, height } = props;
82
83
  const containerRef = (0, import_react.useRef)(null);
83
84
  const chartRef = (0, import_react.useRef)(null);
84
85
  (0, import_react.useEffect)(() => {
@@ -86,7 +87,9 @@ var Sankey = (props) => {
86
87
  return;
87
88
  const chart = new import_g2.Chart({
88
89
  container: containerRef.current,
89
- autoFit: true,
90
+ autoFit: !(width && height),
91
+ ...width ? { width } : {},
92
+ ...height ? { height } : {},
90
93
  padding: "auto"
91
94
  });
92
95
  const config = defaultConfig(props);
@@ -98,6 +101,10 @@ var Sankey = (props) => {
98
101
  chartRef.current = null;
99
102
  };
100
103
  }, [props]);
101
- return /* @__PURE__ */ import_react.default.createElement("div", { ref: containerRef });
104
+ const containerStyle = {
105
+ ...width ? { width: `${width}px` } : {},
106
+ ...height ? { height: `${height}px` } : {}
107
+ };
108
+ return /* @__PURE__ */ import_react.default.createElement("div", { ref: containerRef, style: containerStyle });
102
109
  };
103
110
  var Sankey_default = Sankey;
@@ -0,0 +1,28 @@
1
+ import '@antv/s2/dist/s2.min.css';
2
+ import React from 'react';
3
+ /**
4
+ * 主题名
5
+ */
6
+ type ThemeName = 'default' | 'dark';
7
+ /**
8
+ * 数据项
9
+ */
10
+ type DataItem = Record<string, string | number | null | undefined>;
11
+ export type SpreadsheetProps = {
12
+ /** 原始数据 */
13
+ data: DataItem[];
14
+ /** 行头字段(存在时为透视表) */
15
+ rows?: string[];
16
+ /** 列头字段/列顺序 */
17
+ columns?: string[];
18
+ /** 数值字段(存在时为透视表) */
19
+ values?: string[];
20
+ /** 主题名称 */
21
+ theme?: ThemeName;
22
+ /** 宽度 */
23
+ width?: number;
24
+ /** 高度 */
25
+ height?: number;
26
+ };
27
+ declare const Spreadsheet: (props: SpreadsheetProps) => React.JSX.Element;
28
+ export default Spreadsheet;
@@ -0,0 +1,113 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/Spreadsheet/index.tsx
30
+ var Spreadsheet_exports = {};
31
+ __export(Spreadsheet_exports, {
32
+ default: () => Spreadsheet_default
33
+ });
34
+ module.exports = __toCommonJS(Spreadsheet_exports);
35
+ var import_s2 = require("@antv/s2");
36
+ var import_s2_min = require("@antv/s2/dist/s2.min.css");
37
+ var import_react = __toESM(require("react"));
38
+ var import_styled_components = __toESM(require("styled-components"));
39
+ var SpreadsheetWrapper = import_styled_components.default.div`
40
+ .spreadsheet-container {
41
+ width: 100%;
42
+ height: 100%;
43
+ }
44
+ `;
45
+ var Spreadsheet = (props) => {
46
+ const { data, rows, columns, values, theme = "default", width = 600, height = 400 } = props;
47
+ const containerRef = (0, import_react.useRef)(null);
48
+ const s2Ref = (0, import_react.useRef)(null);
49
+ const isPivot = rows && rows.length > 0 || values && values.length > 0;
50
+ (0, import_react.useEffect)(() => {
51
+ if (!containerRef.current)
52
+ return;
53
+ const fields = {};
54
+ if (isPivot) {
55
+ if (rows && rows.length > 0) {
56
+ fields.rows = rows;
57
+ }
58
+ if (columns && columns.length > 0) {
59
+ fields.columns = columns;
60
+ }
61
+ if (values && values.length > 0) {
62
+ fields.values = values;
63
+ }
64
+ } else {
65
+ if (columns && columns.length > 0) {
66
+ fields.columns = columns;
67
+ } else if (data.length > 0) {
68
+ fields.columns = Object.keys(data[0]);
69
+ }
70
+ }
71
+ const dataCfg = {
72
+ data,
73
+ fields
74
+ };
75
+ const themeCfg = {
76
+ name: theme
77
+ };
78
+ const options = {
79
+ width,
80
+ height
81
+ };
82
+ if (s2Ref.current) {
83
+ s2Ref.current.destroy();
84
+ }
85
+ const SheetClass = isPivot ? import_s2.PivotSheet : import_s2.TableSheet;
86
+ const s2 = new SheetClass(containerRef.current, dataCfg, options);
87
+ s2.setThemeCfg(themeCfg);
88
+ s2Ref.current = s2;
89
+ (async () => {
90
+ await s2.render();
91
+ if (s2.facet) {
92
+ const { panelBBox } = s2.facet;
93
+ const PADDING = 10;
94
+ const actualWidth = Math.ceil(panelBBox.maxX) + PADDING;
95
+ const actualHeight = Math.ceil(panelBBox.maxY) + PADDING;
96
+ if (actualWidth < width || actualHeight < height) {
97
+ const newWidth = Math.min(actualWidth, width);
98
+ const newHeight = Math.min(actualHeight, height);
99
+ s2.changeSheetSize(newWidth, newHeight);
100
+ await s2.render(false);
101
+ }
102
+ }
103
+ })();
104
+ return () => {
105
+ if (s2Ref.current) {
106
+ s2Ref.current.destroy();
107
+ s2Ref.current = null;
108
+ }
109
+ };
110
+ }, [data, rows, columns, values, theme, width, height, isPivot]);
111
+ return /* @__PURE__ */ import_react.default.createElement(SpreadsheetWrapper, null, /* @__PURE__ */ import_react.default.createElement("div", { ref: containerRef, className: "spreadsheet-container" }));
112
+ };
113
+ var Spreadsheet_default = Spreadsheet;
@@ -31,8 +31,9 @@ export { Map, type MapProps } from './export-map';
31
31
  import { PinMap, type PinMapProps, HeatMap, type HeatMapProps, PathMap, type PathMapProps } from './export-map';
32
32
  /********** NTV **********/
33
33
  import { default as Table, type TableProps } from './Table';
34
+ import { default as Spreadsheet, type SpreadsheetProps } from './Spreadsheet';
34
35
  export { VisText, type VisTextProps } from './Text';
35
- export { Area, Bar, Boxplot, Column, DualAxes, FishboneDiagram, FlowDiagram, Funnel, HeatMap, Histogram, IndentedTree, Line, Liquid, MindMap, NetworkGraph, OrganizationChart, PathMap, Pie, PinMap, Radar, Sankey, Scatter, Treemap, Venn, Violin, Waterfall, Table, WordCloud, type AreaProps, type BarProps, type BoxplotProps, type ColumnProps, type DualAxesProps, type FishboneDiagramProps, type FlowDiagramProps, type FunnelProps, type HeatMapProps, type HistogramProps, type IndentedTreeProps, type LineProps, type LiquidProps, type MindMapProps, type NetworkGraphProps, type OrganizationChartProps, type PathMapProps, type PieProps, type PinMapProps, type RadarProps, type SankeyProps, type ScatterProps, type TreemapProps, type VennProps, type ViolinProps, type WaterfallProps, type TableProps, type WordCloudProps, };
36
+ export { Area, Bar, Boxplot, Column, DualAxes, FishboneDiagram, FlowDiagram, Funnel, HeatMap, Histogram, IndentedTree, Line, Liquid, MindMap, NetworkGraph, OrganizationChart, PathMap, Pie, PinMap, Radar, Sankey, Scatter, Treemap, Venn, Violin, Waterfall, Table, Spreadsheet, WordCloud, type AreaProps, type BarProps, type BoxplotProps, type ColumnProps, type DualAxesProps, type FishboneDiagramProps, type FlowDiagramProps, type FunnelProps, type HeatMapProps, type HistogramProps, type IndentedTreeProps, type LineProps, type LiquidProps, type MindMapProps, type NetworkGraphProps, type OrganizationChartProps, type PathMapProps, type PieProps, type PinMapProps, type RadarProps, type SankeyProps, type ScatterProps, type TreemapProps, type VennProps, type ViolinProps, type WaterfallProps, type TableProps, type SpreadsheetProps, type WordCloudProps, };
36
37
  export type VisOptionMap = {
37
38
  [ChartType.Area]: AreaProps;
38
39
  [ChartType.Bar]: BarProps;
@@ -57,6 +58,7 @@ export type VisOptionMap = {
57
58
  [ChartType.Sankey]: SankeyProps;
58
59
  [ChartType.Scatter]: ScatterProps;
59
60
  [ChartType.Table]: TableProps;
61
+ [ChartType.Spreadsheet]: SpreadsheetProps;
60
62
  [ChartType.Treemap]: TreemapProps;
61
63
  [ChartType.Venn]: VennProps;
62
64
  [ChartType.Violin]: ViolinProps;
@@ -53,6 +53,7 @@ __export(export_exports, {
53
53
  Radar: () => import_Radar.default,
54
54
  Sankey: () => import_Sankey.default,
55
55
  Scatter: () => import_Scatter.default,
56
+ Spreadsheet: () => import_Spreadsheet.default,
56
57
  Table: () => import_Table.default,
57
58
  Treemap: () => import_Treemap.default,
58
59
  Venn: () => import_Venn.default,
@@ -90,6 +91,7 @@ var import_IndentedTree = __toESM(require("./IndentedTree"));
90
91
  var import_export_map = require("./export-map");
91
92
  var import_export_map2 = require("./export-map");
92
93
  var import_Table = __toESM(require("./Table"));
94
+ var import_Spreadsheet = __toESM(require("./Spreadsheet"));
93
95
  var import_Text = require("./Text");
94
96
  var DEFAULT_CHART_COMPONENTS = {
95
97
  [import_types.ChartType.Area]: import_Area.default,
@@ -146,6 +148,7 @@ var DEFAULT_CHART_COMPONENTS = {
146
148
  Radar,
147
149
  Sankey,
148
150
  Scatter,
151
+ Spreadsheet,
149
152
  Table,
150
153
  Treemap,
151
154
  Venn,
@@ -30,6 +30,7 @@ export declare enum ChartType {
30
30
  Violin = "violin",
31
31
  Waterfall = "waterfall",
32
32
  Table = "table",
33
+ Spreadsheet = "spreadsheet",
33
34
  VisText = "vis-text",
34
35
  WordCloud = "word-cloud"
35
36
  }
@@ -50,6 +50,7 @@ var ChartType = /* @__PURE__ */ ((ChartType2) => {
50
50
  ChartType2["Violin"] = "violin";
51
51
  ChartType2["Waterfall"] = "waterfall";
52
52
  ChartType2["Table"] = "table";
53
+ ChartType2["Spreadsheet"] = "spreadsheet";
53
54
  ChartType2["VisText"] = "vis-text";
54
55
  ChartType2["WordCloud"] = "word-cloud";
55
56
  return ChartType2;
@@ -1,2 +1,2 @@
1
- declare const _default: "0.5.13";
1
+ declare const _default: "0.6.0";
2
2
  export default _default;
@@ -22,4 +22,4 @@ __export(version_exports, {
22
22
  default: () => version_default
23
23
  });
24
24
  module.exports = __toCommonJS(version_exports);
25
- var version_default = "0.5.13";
25
+ var version_default = "0.6.0";
@@ -125,14 +125,50 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
125
125
  _useState8 = _slicedToArray(_useState7, 2),
126
126
  activeTab = _useState8[0],
127
127
  setActiveTab = _useState8[1];
128
- var chartJson;
129
128
 
130
- // Parse chart JSON with error handling
129
+ // Parse chart JSON early to determine type for hooks
130
+ var chartJson = null;
131
+ var parseError = null;
132
+ var type;
131
133
  try {
134
+ var _chartJson;
132
135
  chartJson = JSON.parse(content);
136
+ type = (_chartJson = chartJson) === null || _chartJson === void 0 ? void 0 : _chartJson.type;
133
137
  } catch (e) {
134
- var parseError = e;
138
+ parseError = e;
139
+ }
140
+
141
+ // Check if chart supports G6 zoom functionality
142
+ var isG6 = type ? G6List.includes(type) : false;
143
+
144
+ // Handle chart resizing on container size change
145
+ var handleResize = useMemo(function () {
146
+ var debouncedFn = debounce(function () {
147
+ var chart = chartRef.current;
148
+ var container = chartContainerRef.current;
149
+ if (!chart || !container || !(container instanceof HTMLElement)) {
150
+ return;
151
+ }
152
+ try {
153
+ if (isG6) {
154
+ var _chart$resize, _chart$autoFit;
155
+ // https://github.com/antvis/G6/blob/91c0ac85e4e636a05bd1a3c5e56a4928d1242a9b/packages/g6/src/runtime/graph.ts#L1334
156
+ (_chart$resize = chart.resize) === null || _chart$resize === void 0 || _chart$resize.call(chart);
157
+ (_chart$autoFit = chart.autoFit) === null || _chart$autoFit === void 0 || _chart$autoFit.call(chart);
158
+ } else {
159
+ var _chart$changeSize;
160
+ // https://github.com/antvis/G2/blob/c5b1887408f951f59f8263e7e1a306dbdae50660/src/api/runtime.ts#L236
161
+ (_chart$changeSize = chart.changeSize) === null || _chart$changeSize === void 0 || _chart$changeSize.call(chart);
162
+ }
163
+ } catch (error) {
164
+ console.error('Failed to resize chart:', error);
165
+ }
166
+ }, 150);
167
+ return debouncedFn;
168
+ }, [isG6]);
135
169
 
170
+ // Handle parse errors after all hooks are called
171
+ if (parseError) {
136
172
  // Clear any existing timeout and set loading timeout
137
173
  if (timeoutRef.current) {
138
174
  clearTimeout(timeoutRef.current);
@@ -165,10 +201,12 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
165
201
  // Return default error message
166
202
  return /*#__PURE__*/React.createElement("div", null, labels.parseError);
167
203
  }
168
- var _chartJson = chartJson,
169
- type = _chartJson.type,
170
- chartProps = _objectWithoutProperties(_chartJson, _excluded);
171
- var ChartComponent = components[type];
204
+
205
+ // chartJson is guaranteed to be non-null here
206
+ var _ref2 = chartJson,
207
+ chartType = _ref2.type,
208
+ chartProps = _objectWithoutProperties(_ref2, _excluded);
209
+ var ChartComponent = components[chartType];
172
210
 
173
211
  // Debug mode: print chart JSON
174
212
  if (debug) {
@@ -177,7 +215,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
177
215
 
178
216
  // Handle unsupported chart types
179
217
  if (!ChartComponent) {
180
- var message = "".concat(labels.unsupportedChart, ": \"").concat(type, "\"");
218
+ var message = "".concat(labels.unsupportedChart, ": \"").concat(chartType, "\"");
181
219
  if (errorRender) {
182
220
  return errorRender({
183
221
  error: new Error(message),
@@ -188,9 +226,8 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
188
226
  }
189
227
 
190
228
  // Error fallback component for chart rendering errors
191
- var FallbackComponent = function FallbackComponent(fallbackProps) {
192
- var error = fallbackProps.error;
193
-
229
+ var FallbackComponent = function FallbackComponent(_ref3) {
230
+ var error = _ref3.error;
194
231
  // Set render error state and switch to code tab
195
232
  if (!hasRenderError) {
196
233
  setHasRenderError(true);
@@ -211,7 +248,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
211
248
 
212
249
  // Handle copy functionality
213
250
  var handleCopy = /*#__PURE__*/function () {
214
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
251
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
215
252
  return _regeneratorRuntime().wrap(function _callee$(_context) {
216
253
  while (1) switch (_context.prev = _context.next) {
217
254
  case 0:
@@ -243,13 +280,13 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
243
280
  }, _callee, null, [[0, 8]]);
244
281
  }));
245
282
  return function handleCopy() {
246
- return _ref2.apply(this, arguments);
283
+ return _ref4.apply(this, arguments);
247
284
  };
248
285
  }();
249
286
 
250
287
  // Handle download functionality
251
288
  var handleDownload = /*#__PURE__*/function () {
252
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
289
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
253
290
  var result;
254
291
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
255
292
  while (1) switch (_context2.prev = _context2.next) {
@@ -268,7 +305,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
268
305
  _context2.next = 7;
269
306
  return result.download({
270
307
  format: 'png',
271
- filename: "chart-".concat(type, "-").concat(Date.now())
308
+ filename: "chart-".concat(chartType, "-").concat(Date.now())
272
309
  });
273
310
  case 7:
274
311
  _context2.next = 12;
@@ -284,13 +321,10 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
284
321
  }, _callee2, null, [[0, 9]]);
285
322
  }));
286
323
  return function handleDownload() {
287
- return _ref3.apply(this, arguments);
324
+ return _ref5.apply(this, arguments);
288
325
  };
289
326
  }();
290
327
 
291
- // Check if chart supports G6 zoom functionality
292
- var isG6 = G6List.includes(type);
293
-
294
328
  // Zoom out functionality
295
329
  var handleZoomOut = function handleZoomOut() {
296
330
  if (chartRef.current && typeof chartRef.current.zoomTo === 'function') {
@@ -309,36 +343,6 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
309
343
  }
310
344
  };
311
345
 
312
- // Handle chart resizing on container size change
313
- var handleResize = useMemo(function () {
314
- var _debouncedFn$cancel;
315
- var debouncedFn = debounce(function () {
316
- var chart = chartRef.current;
317
- var container = chartContainerRef.current;
318
-
319
- // 增加 null 检查和类型守卫
320
- if (!chart || !container || !(container instanceof HTMLElement)) {
321
- return;
322
- }
323
- try {
324
- if (isG6) {
325
- var _chart$resize, _chart$autoFit;
326
- // https://github.com/antvis/G6/blob/91c0ac85e4e636a05bd1a3c5e56a4928d1242a9b/packages/g6/src/runtime/graph.ts#L1334
327
- (_chart$resize = chart.resize) === null || _chart$resize === void 0 || _chart$resize.call(chart);
328
- (_chart$autoFit = chart.autoFit) === null || _chart$autoFit === void 0 || _chart$autoFit.call(chart);
329
- } else {
330
- var _chart$changeSize;
331
- // https://github.com/antvis/G2/blob/c5b1887408f951f59f8263e7e1a306dbdae50660/src/api/runtime.ts#L236
332
- (_chart$changeSize = chart.changeSize) === null || _chart$changeSize === void 0 || _chart$changeSize.call(chart);
333
- }
334
- } catch (error) {
335
- console.error('Failed to resize chart:', error);
336
- }
337
- }, 150);
338
- (_debouncedFn$cancel = debouncedFn.cancel) === null || _debouncedFn$cancel === void 0 || _debouncedFn$cancel.call(debouncedFn);
339
- return debouncedFn;
340
- }, [isG6]);
341
-
342
346
  // Render without tabs if showTabs is false
343
347
  if (!showTabs) {
344
348
  return /*#__PURE__*/React.createElement(StyledGPTVis, {
@@ -416,7 +420,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
416
420
  }
417
421
  }, /*#__PURE__*/React.createElement(StyledGPTVis, {
418
422
  className: "gpt-vis",
419
- type: type
423
+ type: chartType
420
424
  }, /*#__PURE__*/React.createElement(GlobalStyles, null), /*#__PURE__*/React.createElement(ResizeObserver, {
421
425
  onResize: handleResize
422
426
  }, /*#__PURE__*/React.createElement(ChartWrapper, {
@@ -4,7 +4,7 @@ export var StyledGPTVis = styled.div.withConfig({
4
4
  componentId: "gpt-vis-c7ef__sc-2dc7ka-0"
5
5
  })(["min-width:300px;max-width:100%;height:", ";overflow:hidden;position:relative;padding:16px;"], function (_ref) {
6
6
  var type = _ref.type;
7
- return type === 'table' ? 'auto' : '300px';
7
+ return type === 'table' || type === 'spreadsheet' ? 'auto' : '300px';
8
8
  });
9
9
  export var TextButton = styled.button.withConfig({
10
10
  displayName: "TextButton",
@@ -7,6 +7,8 @@ type SankeyDatum = {
7
7
  };
8
8
  export type SankeyProps = BasePlotProps<SankeyDatum> & Theme & Style & {
9
9
  nodeAlign?: 'left' | 'center' | 'right' | 'justify';
10
+ width?: number;
11
+ height?: number;
10
12
  };
11
13
  declare const Sankey: (props: SankeyProps) => React.JSX.Element;
12
14
  export default Sankey;
@@ -60,15 +60,22 @@ var defaultConfig = function defaultConfig(props) {
60
60
  } : {});
61
61
  };
62
62
  var Sankey = function Sankey(props) {
63
+ var width = props.width,
64
+ height = props.height;
63
65
  var containerRef = useRef(null);
64
66
  var chartRef = useRef(null);
65
67
  useEffect(function () {
66
68
  if (!containerRef.current) return;
67
- var chart = new Chart({
69
+ var chart = new Chart(_objectSpread(_objectSpread(_objectSpread({
68
70
  container: containerRef.current,
69
- autoFit: true,
71
+ autoFit: !(width && height)
72
+ }, width ? {
73
+ width: width
74
+ } : {}), height ? {
75
+ height: height
76
+ } : {}), {}, {
70
77
  padding: 'auto'
71
- });
78
+ }));
72
79
  var config = defaultConfig(props);
73
80
  chart.options(config);
74
81
  chart.render();
@@ -78,8 +85,14 @@ var Sankey = function Sankey(props) {
78
85
  chartRef.current = null;
79
86
  };
80
87
  }, [props]);
88
+ var containerStyle = _objectSpread(_objectSpread({}, width ? {
89
+ width: "".concat(width, "px")
90
+ } : {}), height ? {
91
+ height: "".concat(height, "px")
92
+ } : {});
81
93
  return /*#__PURE__*/React.createElement("div", {
82
- ref: containerRef
94
+ ref: containerRef,
95
+ style: containerStyle
83
96
  });
84
97
  };
85
98
  export default Sankey;
@@ -0,0 +1,28 @@
1
+ import '@antv/s2/dist/s2.min.css';
2
+ import React from 'react';
3
+ /**
4
+ * 主题名
5
+ */
6
+ type ThemeName = 'default' | 'dark';
7
+ /**
8
+ * 数据项
9
+ */
10
+ type DataItem = Record<string, string | number | null | undefined>;
11
+ export type SpreadsheetProps = {
12
+ /** 原始数据 */
13
+ data: DataItem[];
14
+ /** 行头字段(存在时为透视表) */
15
+ rows?: string[];
16
+ /** 列头字段/列顺序 */
17
+ columns?: string[];
18
+ /** 数值字段(存在时为透视表) */
19
+ values?: string[];
20
+ /** 主题名称 */
21
+ theme?: ThemeName;
22
+ /** 宽度 */
23
+ width?: number;
24
+ /** 高度 */
25
+ height?: number;
26
+ };
27
+ declare const Spreadsheet: (props: SpreadsheetProps) => React.JSX.Element;
28
+ export default Spreadsheet;