@antv/gpt-vis 0.5.3 → 0.5.5

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.
@@ -32,6 +32,7 @@ __export(VisChart_exports, {
32
32
  RenderVisChart: () => RenderVisChart
33
33
  });
34
34
  module.exports = __toCommonJS(VisChart_exports);
35
+ var import_snapdom = require("@zumer/snapdom");
35
36
  var import_react = __toESM(require("react"));
36
37
  var import_react_error_boundary = require("react-error-boundary");
37
38
  var import_react_syntax_highlighter = require("react-syntax-highlighter");
@@ -59,6 +60,7 @@ var RenderVisChart = (0, import_react.memo)(
59
60
  const [hasRenderError, setHasRenderError] = (0, import_react.useState)(false);
60
61
  const [copied, setCopied] = (0, import_react.useState)(false);
61
62
  const chartRef = (0, import_react.useRef)(null);
63
+ const chartContainerRef = (0, import_react.useRef)(null);
62
64
  let chartJson;
63
65
  try {
64
66
  chartJson = JSON.parse(content);
@@ -127,6 +129,19 @@ var RenderVisChart = (0, import_react.memo)(
127
129
  console.error("复制失败:", error);
128
130
  }
129
131
  };
132
+ const handleDownload = async () => {
133
+ try {
134
+ if (chartContainerRef.current) {
135
+ const result = await (0, import_snapdom.snapdom)(chartContainerRef.current, { scale: 2 });
136
+ await result.download({
137
+ format: "png",
138
+ filename: `chart-${type}-${Date.now()}`
139
+ });
140
+ }
141
+ } catch (error) {
142
+ console.error("下载图片失败:", error);
143
+ }
144
+ };
130
145
  const isG6 = G6List.includes(type);
131
146
  const handleZoomOut = () => {
132
147
  if (chartRef.current && typeof chartRef.current.zoomTo === "function") {
@@ -156,7 +171,7 @@ var RenderVisChart = (0, import_react.memo)(
156
171
  style: { width: "24px", height: "24px", padding: 0 }
157
172
  },
158
173
  /* @__PURE__ */ import_react.default.createElement(import_icon.ZoomOut, { size: 18 })
159
- ))) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_styles.TextButton, { onClick: handleCopy }, copied ? /* @__PURE__ */ import_react.default.createElement(import_icon.Check, null) : /* @__PURE__ */ import_react.default.createElement(import_icon.Copy, null), copied ? "完成" : "复制")))), /* @__PURE__ */ import_react.default.createElement(import_styles.TabContent, null, activeTab === "chart" ? /* @__PURE__ */ import_react.default.createElement(
174
+ ), /* @__PURE__ */ import_react.default.createElement(import_styles.Divider, null)), /* @__PURE__ */ import_react.default.createElement(import_styles.TextButton, { onClick: handleDownload }, /* @__PURE__ */ import_react.default.createElement(import_icon.DownLoad, { size: 16 }), "下载")) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_styles.TextButton, { onClick: handleCopy }, copied ? /* @__PURE__ */ import_react.default.createElement(import_icon.Check, null) : /* @__PURE__ */ import_react.default.createElement(import_icon.Copy, null), copied ? "完成" : "复制")))), /* @__PURE__ */ import_react.default.createElement(import_styles.TabContent, null, activeTab === "chart" ? /* @__PURE__ */ import_react.default.createElement(
160
175
  import_react_error_boundary.ErrorBoundary,
161
176
  {
162
177
  FallbackComponent,
@@ -171,7 +186,7 @@ var RenderVisChart = (0, import_react.memo)(
171
186
  }
172
187
  }
173
188
  },
174
- /* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis" }, /* @__PURE__ */ import_react.default.createElement(import_styles.GlobalStyles, null), /* @__PURE__ */ import_react.default.createElement(import_styles.ChartWrapper, null, /* @__PURE__ */ import_react.default.createElement(
189
+ /* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis" }, /* @__PURE__ */ import_react.default.createElement(import_styles.GlobalStyles, null), /* @__PURE__ */ import_react.default.createElement(import_styles.ChartWrapper, { ref: chartContainerRef }, /* @__PURE__ */ import_react.default.createElement(
175
190
  ChartComponent,
176
191
  {
177
192
  ...chartProps,
@@ -6,4 +6,5 @@ export declare const Copy: React.FC<Props>;
6
6
  export declare const ZoomOut: React.FC<Props>;
7
7
  export declare const ZoomIn: React.FC<Props>;
8
8
  export declare const Check: React.FC<Props>;
9
+ export declare const DownLoad: React.FC<Props>;
9
10
  export {};
@@ -31,6 +31,7 @@ var icon_exports = {};
31
31
  __export(icon_exports, {
32
32
  Check: () => Check,
33
33
  Copy: () => Copy,
34
+ DownLoad: () => DownLoad,
34
35
  ZoomIn: () => ZoomIn,
35
36
  ZoomOut: () => ZoomOut
36
37
  });
@@ -131,10 +132,31 @@ var Check = ({ size = 14, fill = "#707070" }) => /* @__PURE__ */ import_react.de
131
132
  }
132
133
  )
133
134
  );
135
+ var DownLoad = ({ size = 14, fill = "#707070" }) => /* @__PURE__ */ import_react.default.createElement(
136
+ "svg",
137
+ {
138
+ viewBox: "0 0 1024 1024",
139
+ version: "1.1",
140
+ xmlns: "http://www.w3.org/2000/svg",
141
+ "p-id": "5988",
142
+ width: size,
143
+ height: size,
144
+ fill
145
+ },
146
+ /* @__PURE__ */ import_react.default.createElement(
147
+ "path",
148
+ {
149
+ d: "M512 165.93q13.645 0 23.31 9.666t9.665 23.31V580.77L653.37 472.103q9.517-9.517 23.434-9.517 14.164 0 23.558 9.394t9.393 23.557q0 13.917-9.517 23.434L535.434 683.774q-9.517 9.517-23.434 9.517t-23.434-9.517L323.763 518.971q-9.517-10.036-9.517-23.434 0-13.645 9.665-23.31t23.31-9.665q13.917 0 23.434 9.516L479.05 580.744V198.881q0-13.645 9.665-23.31t23.31-9.665z m329.582 461.435q13.645 0 23.31 9.665t9.665 23.31v131.828q0 41.207-28.575 69.782-29.095 29.095-69.536 29.095H248.32q-40.416 0-70.03-28.848-28.847-29.613-28.847-70.03V660.34q0-13.645 9.665-23.31t23.31-9.665 23.31 9.665 9.666 23.31v131.828q0 13.645 9.665 23.31t23.31 9.665h528.127q13.398 0 22.791-9.665t9.393-23.31V660.34q0-13.645 9.666-23.31t23.31-9.665z",
150
+ "p-id": "1178",
151
+ fill: "#494949"
152
+ }
153
+ )
154
+ );
134
155
  // Annotate the CommonJS export names for ESM import in node:
135
156
  0 && (module.exports = {
136
157
  Check,
137
158
  Copy,
159
+ DownLoad,
138
160
  ZoomIn,
139
161
  ZoomOut
140
162
  });
@@ -1,2 +1,2 @@
1
- declare const _default: "0.5.3";
1
+ declare const _default: "0.5.5";
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.3";
25
+ var version_default = "0.5.5";
@@ -12,14 +12,15 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
12
12
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
13
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
14
14
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
+ import { snapdom } from '@zumer/snapdom';
15
16
  import React, { memo, useRef, useState } from 'react';
16
17
  import { ErrorBoundary } from 'react-error-boundary';
17
18
  import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
18
19
  import json from 'react-syntax-highlighter/dist/esm/languages/hljs/json';
19
20
  import { magula } from 'react-syntax-highlighter/dist/esm/styles/hljs';
20
- import { Check, Copy, ZoomIn, ZoomOut } from "./icon";
21
+ import { Check, Copy, DownLoad, ZoomIn, ZoomOut } from "./icon";
21
22
  import Loading from "./Loading";
22
- import { ChartWrapper, ErrorMessage, GlobalStyles, StyledGPTVis, StyledTabButton, TabContainer, TabContent, TabHeader, TabLeftGroup, TabRightGroup, TextButton } from "./styles";
23
+ import { ChartWrapper, Divider, ErrorMessage, GlobalStyles, StyledGPTVis, StyledTabButton, TabContainer, TabContent, TabHeader, TabLeftGroup, TabRightGroup, TextButton } from "./styles";
23
24
  import { handleCopyCode } from "./utils";
24
25
 
25
26
  // 注册 JSON 语言支持
@@ -52,6 +53,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
52
53
  copied = _useState8[0],
53
54
  setCopied = _useState8[1];
54
55
  var chartRef = useRef(null);
56
+ var chartContainerRef = useRef(null);
55
57
  var chartJson;
56
58
  try {
57
59
  chartJson = JSON.parse(content);
@@ -157,6 +159,45 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
157
159
  return _ref2.apply(this, arguments);
158
160
  };
159
161
  }();
162
+ var handleDownload = /*#__PURE__*/function () {
163
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
164
+ var result;
165
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
166
+ while (1) switch (_context2.prev = _context2.next) {
167
+ case 0:
168
+ _context2.prev = 0;
169
+ if (!chartContainerRef.current) {
170
+ _context2.next = 7;
171
+ break;
172
+ }
173
+ _context2.next = 4;
174
+ return snapdom(chartContainerRef.current, {
175
+ scale: 2
176
+ });
177
+ case 4:
178
+ result = _context2.sent;
179
+ _context2.next = 7;
180
+ return result.download({
181
+ format: 'png',
182
+ filename: "chart-".concat(type, "-").concat(Date.now())
183
+ });
184
+ case 7:
185
+ _context2.next = 12;
186
+ break;
187
+ case 9:
188
+ _context2.prev = 9;
189
+ _context2.t0 = _context2["catch"](0);
190
+ console.error('下载图片失败:', _context2.t0);
191
+ case 12:
192
+ case "end":
193
+ return _context2.stop();
194
+ }
195
+ }, _callee2, null, [[0, 9]]);
196
+ }));
197
+ return function handleDownload() {
198
+ return _ref3.apply(this, arguments);
199
+ };
200
+ }();
160
201
  var isG6 = G6List.includes(type);
161
202
 
162
203
  // 缩放功能函数
@@ -206,7 +247,11 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
206
247
  }
207
248
  }, /*#__PURE__*/React.createElement(ZoomOut, {
208
249
  size: 18
209
- })))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextButton, {
250
+ })), /*#__PURE__*/React.createElement(Divider, null)), /*#__PURE__*/React.createElement(TextButton, {
251
+ onClick: handleDownload
252
+ }, /*#__PURE__*/React.createElement(DownLoad, {
253
+ size: 16
254
+ }), "\u4E0B\u8F7D")) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextButton, {
210
255
  onClick: handleCopy
211
256
  }, copied ? /*#__PURE__*/React.createElement(Check, null) : /*#__PURE__*/React.createElement(Copy, null), copied ? '完成' : '复制')))), /*#__PURE__*/React.createElement(TabContent, null, activeTab === 'chart' ? /*#__PURE__*/React.createElement(ErrorBoundary, {
212
257
  FallbackComponent: FallbackComponent,
@@ -222,7 +267,9 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
222
267
  }
223
268
  }, /*#__PURE__*/React.createElement(StyledGPTVis, {
224
269
  className: "gpt-vis"
225
- }, /*#__PURE__*/React.createElement(GlobalStyles, null), /*#__PURE__*/React.createElement(ChartWrapper, null, /*#__PURE__*/React.createElement(ChartComponent, _extends({}, chartProps, {
270
+ }, /*#__PURE__*/React.createElement(GlobalStyles, null), /*#__PURE__*/React.createElement(ChartWrapper, {
271
+ ref: chartContainerRef
272
+ }, /*#__PURE__*/React.createElement(ChartComponent, _extends({}, chartProps, {
226
273
  onReady: function onReady(chart) {
227
274
  chartRef.current = chart;
228
275
  }
@@ -6,4 +6,5 @@ export declare const Copy: React.FC<Props>;
6
6
  export declare const ZoomOut: React.FC<Props>;
7
7
  export declare const ZoomIn: React.FC<Props>;
8
8
  export declare const Check: React.FC<Props>;
9
+ export declare const DownLoad: React.FC<Props>;
9
10
  export {};
@@ -81,4 +81,23 @@ export var Check = function Check(_ref4) {
81
81
  fill: "",
82
82
  "p-id": "5989"
83
83
  }));
84
+ };
85
+ export var DownLoad = function DownLoad(_ref5) {
86
+ var _ref5$size = _ref5.size,
87
+ size = _ref5$size === void 0 ? 14 : _ref5$size,
88
+ _ref5$fill = _ref5.fill,
89
+ fill = _ref5$fill === void 0 ? '#707070' : _ref5$fill;
90
+ return /*#__PURE__*/React.createElement("svg", {
91
+ viewBox: "0 0 1024 1024",
92
+ version: "1.1",
93
+ xmlns: "http://www.w3.org/2000/svg",
94
+ "p-id": "5988",
95
+ width: size,
96
+ height: size,
97
+ fill: fill
98
+ }, /*#__PURE__*/React.createElement("path", {
99
+ d: "M512 165.93q13.645 0 23.31 9.666t9.665 23.31V580.77L653.37 472.103q9.517-9.517 23.434-9.517 14.164 0 23.558 9.394t9.393 23.557q0 13.917-9.517 23.434L535.434 683.774q-9.517 9.517-23.434 9.517t-23.434-9.517L323.763 518.971q-9.517-10.036-9.517-23.434 0-13.645 9.665-23.31t23.31-9.665q13.917 0 23.434 9.516L479.05 580.744V198.881q0-13.645 9.665-23.31t23.31-9.665z m329.582 461.435q13.645 0 23.31 9.665t9.665 23.31v131.828q0 41.207-28.575 69.782-29.095 29.095-69.536 29.095H248.32q-40.416 0-70.03-28.848-28.847-29.613-28.847-70.03V660.34q0-13.645 9.665-23.31t23.31-9.665 23.31 9.665 9.666 23.31v131.828q0 13.645 9.665 23.31t23.31 9.665h528.127q13.398 0 22.791-9.665t9.393-23.31V660.34q0-13.645 9.666-23.31t23.31-9.665z",
100
+ "p-id": "1178",
101
+ fill: "#494949"
102
+ }));
84
103
  };
@@ -1,2 +1,2 @@
1
- declare const _default: "0.5.3";
1
+ declare const _default: "0.5.5";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '0.5.3';
1
+ export default '0.5.5';