@antv/dumi-theme-antv 0.8.0-beta.14 → 0.8.0-beta.16

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,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Dropdown } from "antd";
3
- import { useLibrary, useProducts } from "../../../../../hooks/useProducts";
3
+ import { useAntVConfig, useProducts } from "../../../../../hooks/useProducts";
4
4
  import { useLocale, FormattedMessage } from "dumi";
5
5
  import styles from "./index.module.less";
6
6
  export function ChooseLib(props) {
@@ -15,9 +15,13 @@ export function ChooseLib(props) {
15
15
  var _useProducts = useProducts(),
16
16
  _useProducts$data = _useProducts.data,
17
17
  data = _useProducts$data === void 0 ? [] : _useProducts$data;
18
- var _useLibrary = useLibrary(),
19
- _useLibrary$data = _useLibrary.data,
20
- library = _useLibrary$data === void 0 ? [] : _useLibrary$data;
18
+ var _useAntVConfig = useAntVConfig(),
19
+ _useAntVConfig$data = _useAntVConfig.data,
20
+ _useAntVConfig$data2 = _useAntVConfig$data === void 0 ? {
21
+ library: []
22
+ } : _useAntVConfig$data,
23
+ _useAntVConfig$data2$ = _useAntVConfig$data2.library,
24
+ library = _useAntVConfig$data2$ === void 0 ? [] : _useAntVConfig$data2$;
21
25
  var onSelect = function onSelect(key) {
22
26
  onChange === null || onChange === void 0 || onChange(key);
23
27
  };
@@ -18,7 +18,7 @@ import classnames from "classnames";
18
18
  import { FormattedMessage, useSiteData } from 'dumi';
19
19
  import { sample, sampleSize } from "lodash-es";
20
20
  import { AIChatStore } from "../../../../model/AIChat";
21
- import { useLibrary } from "../../../../hooks/useProducts";
21
+ import { useAntVConfig } from "../../../../hooks/useProducts";
22
22
  import { getBaseSiteDataUrl } from "../../../../utils/env";
23
23
  export var RecommendCase = function RecommendCase(props) {
24
24
  var _useState = useState(false),
@@ -31,9 +31,13 @@ export var RecommendCase = function RecommendCase(props) {
31
31
  _useState4 = _slicedToArray(_useState3, 2),
32
32
  list = _useState4[0],
33
33
  setList = _useState4[1];
34
- var _useLibrary = useLibrary(),
35
- _useLibrary$data = _useLibrary.data,
36
- library = _useLibrary$data === void 0 ? [] : _useLibrary$data;
34
+ var _useAntVConfig = useAntVConfig(),
35
+ _useAntVConfig$data = _useAntVConfig.data,
36
+ _useAntVConfig$data2 = _useAntVConfig$data === void 0 ? {
37
+ library: []
38
+ } : _useAntVConfig$data,
39
+ _useAntVConfig$data2$ = _useAntVConfig$data2.library,
40
+ library = _useAntVConfig$data2$ === void 0 ? [] : _useAntVConfig$data2$;
37
41
  var fetchList = /*#__PURE__*/function () {
38
42
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
39
43
  var _themeConfig$ai, data, url;
@@ -82,8 +86,10 @@ export var RecommendCase = function RecommendCase(props) {
82
86
  };
83
87
  }();
84
88
  useEffect(function () {
85
- fetchList();
86
- }, []);
89
+ if (library.length) {
90
+ fetchList();
91
+ }
92
+ }, [themeConfig.isAntVSite, library.length]);
87
93
  if (!list.length) {
88
94
  return null;
89
95
  }
@@ -45,7 +45,8 @@ export function HomeDialog(props) {
45
45
  mode: snap.mode,
46
46
  jump: true,
47
47
  context: fileSummary,
48
- lang: locale.id
48
+ lang: locale.id,
49
+ entry_point: 'home'
49
50
  });
50
51
  },
51
52
  style: props.promptTextareaStyle,
@@ -17,9 +17,9 @@ export function useProducts() {
17
17
  staleTime: 24 * 60 * 60 * 1000 // 一天内数据不会被认为是 "stale",不会触发后台刷新
18
18
  });
19
19
  }
20
- export function getLibrary() {
20
+ export function getAntVConfig() {
21
21
  // 如需要修改产品信息,请到 https://yuyan.antfin-inc.com/antv/site-data/sprints 修改区块内容
22
- return fetch("".concat(getBaseSiteDataUrl(), "/antv/library.json") // 生产环境
22
+ return fetch("".concat(getBaseSiteDataUrl(), "/antv/config.json") // 生产环境
23
23
  // 'https://site-data-pre.alipay.com/antv/products.json', // 预发测试
24
24
  ).then(function (res) {
25
25
  return res.json();
@@ -27,10 +27,15 @@ export function getLibrary() {
27
27
  }
28
28
 
29
29
  // 封装了 queryKey 和 fetcher 的自定义 Hook
30
- export function useLibrary() {
30
+ export function useAntVConfig() {
31
31
  return useQuery({
32
- queryKey: ['antv-library'],
33
- queryFn: getLibrary,
34
- staleTime: 24 * 60 * 60 * 1000 // 一天内数据不会被认为是 "stale",不会触发后台刷新
32
+ queryKey: ['antv-config'],
33
+ queryFn: getAntVConfig,
34
+ staleTime: 24 * 60 * 60 * 1000,
35
+ // 一天内数据不会被认为是 "stale",不会触发后台刷新
36
+ initialData: {
37
+ "VisionSnapVersion": "3.4.6",
38
+ "library": ["G2", "F2", "G6"]
39
+ }
35
40
  });
36
41
  }
@@ -233,6 +233,8 @@
233
233
  "ai.conversations.ok": "OK",
234
234
  "ai.conversations.cancel": "Cancel",
235
235
  "ai.msgbox.delete": "Delete",
236
+ "ai.msgbox.auto.fix": "Auto Fix",
237
+ "ai.msgbox.auto.fix.prompt": "This code encountered a problem during execution. Here is the exact error message it threw.",
236
238
  "ai.chooseLib.placeholder": "Choose Technology Stack",
237
239
  "ai.search.try": "Try",
238
240
  "ai.search.visualization": "Q&A",
@@ -232,6 +232,8 @@
232
232
  "ai.conversations.ok": "确定",
233
233
  "ai.conversations.cancel": "取消",
234
234
  "ai.msgbox.delete": "删除",
235
+ "ai.msgbox.auto.fix": "自动修复",
236
+ "ai.msgbox.auto.fix.prompt": "这个代码在执行时遇到了问题。下面是它抛出的确切错误信息。",
235
237
  "ai.chooseLib.placeholder": "选择技术栈",
236
238
  "ai.search.try": "试试",
237
239
  "ai.search.visualization": "可视化答疑",
@@ -15,6 +15,7 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs';
15
15
  import { history } from "dumi";
16
16
  import { message } from "antd";
17
17
  import { AIMode } from "../components/AI/constant";
18
+ import { trackEvent } from "../utils/analytics";
18
19
 
19
20
  // --- 配置 ---
20
21
  // 定义需要持久化的 state key
@@ -30,7 +31,8 @@ var initialState = {
30
31
  tempMessage: null,
31
32
  codeBlock: null,
32
33
  lib: null,
33
- mode: AIMode.implement
34
+ mode: AIMode.implement,
35
+ errorMsg: null
34
36
  };
35
37
 
36
38
  // --- valtio Store 创建 ---
@@ -222,7 +224,6 @@ export var createPureNewSession = function createPureNewSession(title) {
222
224
  AIChatStore.activeSessionId = newSessionId;
223
225
  };
224
226
  export var createNewSession = function createNewSession(config) {
225
- // todo 埋点
226
227
  // 1. 创建一个新的会话
227
228
  createPureNewSession(config.promptText);
228
229
 
@@ -240,6 +241,16 @@ export var createNewSession = function createNewSession(config) {
240
241
  var _config$lang;
241
242
  history.push("/".concat((_config$lang = config.lang) !== null && _config$lang !== void 0 ? _config$lang : 'zh', "/ai-playground"));
242
243
  }
244
+ // 埋点
245
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object') {
246
+ trackEvent('start_ai_chat', {
247
+ entry_point: config.entry_point,
248
+ mode: AIChatStore.mode,
249
+ lib: AIChatStore.lib,
250
+ page_title: document.title,
251
+ location: location.href
252
+ });
253
+ }
243
254
  };
244
255
 
245
256
  /**
@@ -90,7 +90,8 @@ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
90
90
  showLineNumbers: false // (可选) 显示行号
91
91
  ,
92
92
  customStyle: {
93
- paddingTop: '2em'
93
+ paddingTop: '2em',
94
+ background: '#fafafa'
94
95
  }
95
96
  }, codeString));
96
97
  };
@@ -1,10 +1,11 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
4
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
5
  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; }
5
6
  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; } }
6
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import { BranchesOutlined, CheckOutlined, CopyOutlined, DeleteOutlined, PlusSquareOutlined, SyncOutlined } from '@ant-design/icons';
8
+ import { BranchesOutlined, CheckOutlined, CopyOutlined, DeleteOutlined, PlusSquareOutlined, SyncOutlined, ToolOutlined } from '@ant-design/icons';
8
9
  import { Bubble } from '@ant-design/x';
9
10
  import { Button, Flex, Space, Tooltip } from 'antd';
10
11
  import { useChat } from '@ai-sdk/react';
@@ -22,6 +23,7 @@ import styles from "./index.module.less";
22
23
  import { useAutoScroll } from "./useAutoScroll";
23
24
  import { getBaseURL } from "../../../../utils/env";
24
25
  import { AIMode } from "../../../../components/AI/constant";
26
+ import { trackEvent } from "../../../../utils/analytics";
25
27
  var avatar = {
26
28
  icon: /*#__PURE__*/React.createElement("img", {
27
29
  draggable: false,
@@ -188,9 +190,9 @@ function MsgBox(props) {
188
190
  text: promptText
189
191
  }, {
190
192
  body: {
191
- context: fileSummary,
192
- lib: snap.lib,
193
- mode: snap.mode
193
+ // context: fileSummary,
194
+ // lib: snap.lib,
195
+ // mode: snap.mode,
194
196
  }
195
197
  });
196
198
  setPromptText('');
@@ -203,6 +205,16 @@ function MsgBox(props) {
203
205
  lib: snap.lib
204
206
  });
205
207
  chatScrollIntoView();
208
+ // 埋点
209
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object') {
210
+ trackEvent('start_ai_chat', {
211
+ entry_point: simple ? 'Drawer' : 'MsgBox',
212
+ mode: AIChatStore.mode,
213
+ lib: AIChatStore.lib,
214
+ page_title: document.title,
215
+ location: location.href
216
+ });
217
+ }
206
218
  };
207
219
 
208
220
  // 同步 Valtio store -> useChat state
@@ -254,12 +266,36 @@ function MsgBox(props) {
254
266
  useEffect(function () {
255
267
  chatScrollIntoView();
256
268
  stop();
269
+ AIChatStore.errorMsg = null;
257
270
  }, [snap.activeSessionId]);
258
271
 
259
272
  // 将 messages 数组作为依赖项。当它变化时,Hook 会运行。
260
273
  var _useAutoScroll = useAutoScroll(messages),
261
274
  containerRef = _useAutoScroll.containerRef,
262
275
  anchorRef = _useAutoScroll.anchorRef;
276
+ var autofix = function autofix() {
277
+ var _derivedState$activeS6;
278
+ var autoFixPromptText = "".concat(formatMessage({
279
+ id: 'ai.msgbox.auto.fix.prompt'
280
+ }), " [").concat(snap.errorMsg, "]");
281
+ sendMessage({
282
+ text: autoFixPromptText
283
+ }, {
284
+ body: {
285
+ antvContext: snap.codeBlock
286
+ }
287
+ });
288
+ AIChatStore.errorMsg = null;
289
+ (_derivedState$activeS6 = derivedState.activeSession) === null || _derivedState$activeS6 === void 0 || (_derivedState$activeS6 = _derivedState$activeS6.messages) === null || _derivedState$activeS6 === void 0 || _derivedState$activeS6.push({
290
+ id: crypto.randomUUID(),
291
+ role: 'user',
292
+ content: autoFixPromptText,
293
+ createdAt: Date.now(),
294
+ context: snap.codeBlock,
295
+ lib: snap.lib
296
+ });
297
+ chatScrollIntoView();
298
+ };
263
299
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Flex, {
264
300
  gap: "middle",
265
301
  vertical: true,
@@ -345,7 +381,14 @@ function MsgBox(props) {
345
381
  className: styles.newButton
346
382
  }, /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(PlusSquareOutlined, null), formatMessage({
347
383
  id: 'ai.msgbox.start.new.chat'
348
- }))))), /*#__PURE__*/React.createElement(PromptTextarea, {
384
+ }))), snap.errorMsg && status === 'ready' && /*#__PURE__*/React.createElement(Button, {
385
+ onClick: autofix,
386
+ color: "danger",
387
+ variant: "filled",
388
+ icon: /*#__PURE__*/React.createElement(ToolOutlined, null)
389
+ }, formatMessage({
390
+ id: 'ai.msgbox.auto.fix'
391
+ })))), /*#__PURE__*/React.createElement(PromptTextarea, {
349
392
  size: "compact",
350
393
  value: promptText,
351
394
  onChange: setPromptText,
@@ -45,7 +45,8 @@ function SessionLayout(props) {
45
45
  }, children[0]), /*#__PURE__*/React.createElement("div", {
46
46
  className: styles.taskBox
47
47
  }, children[1])) : /*#__PURE__*/React.createElement("div", {
48
- className: classnames(styles.msgBox, styles.msgBoxFull)
48
+ className: classnames(styles.msgBox, styles.msgBoxFull),
49
+ key: snap.codeBlock
49
50
  }, children[0]), isDragging && /*#__PURE__*/React.createElement("div", {
50
51
  style: {
51
52
  position: 'fixed',
@@ -1,3 +1,7 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1
5
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
6
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
7
  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; }
@@ -68,38 +72,112 @@ export function generateDependencies(codeString) {
68
72
  dependencies[pkg] = "latest";
69
73
  }
70
74
  }
75
+
76
+ // f2的语法是jsx。VisionSnap限制只要是jsx就必须装React。
71
77
  } catch (err) {
72
78
  _iterator.e(err);
73
79
  } finally {
74
80
  _iterator.f();
75
81
  }
82
+ if (Object.prototype.hasOwnProperty.call(dependencies, "@antv/f2")) {
83
+ dependencies["react"] = "^18";
84
+ dependencies["react-dom"] = "^18";
85
+ }
76
86
  return dependencies;
77
87
  }
88
+
89
+ /**
90
+ * 基于代码内容,启发式地判断其最合适的文件扩展名。
91
+ * @param {string} code - 要分析的前端代码字符串。
92
+ * @returns {'tsx' | 'jsx' | 'ts' | 'js'} - 推断出的文件扩展名(不含点)。
93
+ */
94
+ export function getLanguageExtension(code) {
95
+ // --- 特征检测函数 ---
96
+
97
+ /**
98
+ * 检查代码是否包含 JSX 语法。
99
+ * 这是一个启发式检查,它查找类似HTML标签的模式。
100
+ * - 匹配 <div...>, <MyComponent...>, </tag>, <Component/>, <>
101
+ */
102
+ var containsJsx = function containsJsx(text) {
103
+ // 1. 查找开/闭标签 <...> 或自闭合标签 <.../>
104
+ // 2. 忽略可能误判的比较操作,如 `i < j`
105
+ // 这个正则查找一个'<'符号,后面不能是'!' (注释)或'=' (小于等于),
106
+ // 并且后面跟着一个合法的标签名(字母开头)或闭合标签'/'。
107
+ // 这比简单的 /<...>/ 更可靠。
108
+ var jsxRegex = /<(?![\s!=])([a-zA-Z][a-zA-Z0-9-]*|\/|)/;
109
+ return jsxRegex.test(text);
110
+ };
111
+
112
+ /**
113
+ * 检查代码是否包含 TypeScript 语法。
114
+ * 这是一个启发式检查,查找TS独有的关键字和语法模式。
115
+ */
116
+ var containsTypeScript = function containsTypeScript(text) {
117
+ // 检查点 1: 类型/接口定义(非常明确的信号)
118
+ // 匹配 `type MyType = ...` 或 `interface MyInterface { ... }`
119
+ var typeDefinitionRegex = /\b(interface|type)\s+[A-Z][a-zA-Z0-9]*\b/;
120
+ if (typeDefinitionRegex.test(text)) {
121
+ return true;
122
+ }
123
+
124
+ // 检查点 2: 变量或参数的类型注解(强信号)
125
+ // 匹配 `: string`, `: number`, `: MyType` 等
126
+ // 这个正则查找一个冒号,后面跟着一个类型(通常大写字母开头或ts内置类型)
127
+ var typeAnnotationRegex = /:\s*([A-Z][a-zA-Z0-9<>.]*|string|number|boolean|any\[?\]?)/;
128
+ if (typeAnnotationRegex.test(text)) {
129
+ return true;
130
+ }
131
+
132
+ // 检查点 3: 其他TS关键字
133
+ // 匹配 `as someType`, `implements`, `private`, `public`, `protected` 等
134
+ var tsKeywordsRegex = /\b(as|implements|private|public|protected|readonly)\s+[a-zA-Z]/;
135
+ if (tsKeywordsRegex.test(text)) {
136
+ return true;
137
+ }
138
+ return false;
139
+ };
140
+
141
+ // --- 决策逻辑 ---
142
+
143
+ if (containsJsx(code)) {
144
+ if (containsTypeScript(code)) {
145
+ return 'tsx';
146
+ }
147
+ return 'jsx';
148
+ } else {
149
+ if (containsTypeScript(code)) {
150
+ return 'ts';
151
+ }
152
+ return 'js';
153
+ }
154
+ }
78
155
  export function wrap2VisionSnap() {
79
156
  var codeBlock = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
157
+ var ext = getLanguageExtension(codeBlock);
158
+ var mainFile = "/src/index.".concat(ext);
159
+ var appFile = "/src/App.".concat(ext);
80
160
  var dependencies = generateDependencies(codeBlock);
81
161
  var rootElementType = dependencies['@antv/f2'] ? 'canvas' : 'div';
82
162
  var dependenciesJSON = {
83
163
  "name": "AntV-adapted-project",
84
164
  "version": "1.0.0",
85
- "main": "/src/index.jsx",
165
+ "main": mainFile,
86
166
  "dependencies": dependencies
87
167
  };
88
168
  return {
89
- modules: {
169
+ modules: _defineProperty(_defineProperty({
90
170
  '/package.json': {
91
171
  fpath: '/package.json',
92
172
  code: JSON.stringify(dependenciesJSON, null, 2)
93
- },
94
- '/src/index.jsx': {
95
- fpath: '/src/index.jsx',
96
- code: "\n// --- Adapter Script ---\n\n// 1. \u627E\u5230\u7F16\u8F91\u5668\u73AF\u5883\u63D0\u4F9B\u7684\u6839\u8282\u70B9 #root\nconst rootElement = document.getElementById('root');\n\nif (rootElement) {\n // 2. \u5728 #root \u5185\u90E8\u521B\u5EFA\u4E00\u4E2A ".concat(rootElementType, "\n const containerElement = document.createElement('").concat(rootElementType, "');\n\n // 3. \u5C06\u8FD9\u4E2A div \u7684 id \u8BBE\u7F6E\u4E3A 'container'\uFF0C\u4EE5\u6EE1\u8DB3\u7528\u6237\u4EE3\u7801\u7684\u9700\u6C42\n containerElement.id = 'container';\n\n // 4. \u5C06\u5B83\u6DFB\u52A0\u5230 #root \u4E2D\n rootElement.appendChild(containerElement);\n\n // 5. \u73B0\u5728 DOM \u4E2D\u5DF2\u7ECF\u5B58\u5728 #container\uFF0C\u5B89\u5168\u5730\u5BFC\u5165\u5E76\u6267\u884C\u7528\u6237\u7684\u4EE3\u7801\n import('./App.jsx');\n\n}\n ")
97
- },
98
- '/src/App.jsx': {
99
- fpath: '/src/App.jsx',
100
- code: codeBlock
101
173
  }
102
- }
174
+ }, mainFile, {
175
+ fpath: mainFile,
176
+ code: "\n// --- Adapter Script ---\n\n// 1. \u627E\u5230\u7F16\u8F91\u5668\u73AF\u5883\u63D0\u4F9B\u7684\u6839\u8282\u70B9 #root\nconst rootElement = document.getElementById('root');\n\nif (rootElement) {\n // 2. \u5728 #root \u5185\u90E8\u521B\u5EFA\u4E00\u4E2A ".concat(rootElementType, "\n const containerElement = document.createElement('").concat(rootElementType, "');\n\n // 3. \u5C06\u8FD9\u4E2A div \u7684 id \u8BBE\u7F6E\u4E3A 'container'\uFF0C\u4EE5\u6EE1\u8DB3\u7528\u6237\u4EE3\u7801\u7684\u9700\u6C42\n containerElement.id = 'container';\n\n // 4. \u5C06\u5B83\u6DFB\u52A0\u5230 #root \u4E2D\n rootElement.appendChild(containerElement);\n\n // 5. \u73B0\u5728 DOM \u4E2D\u5DF2\u7ECF\u5B58\u5728 #container\uFF0C\u5B89\u5168\u5730\u5BFC\u5165\u5E76\u6267\u884C\u7528\u6237\u7684\u4EE3\u7801\n import('./App.").concat(ext, "');\n\n}\n ")
177
+ }), appFile, {
178
+ fpath: [appFile],
179
+ code: codeBlock
180
+ })
103
181
  };
104
182
  }
105
183
  export function wrap2Sandpack() {
@@ -8,8 +8,15 @@ import { requestProxy, useVisionsnapSdk } from "../../../../hooks/useVisionsnapS
8
8
  import { ErrorBoundary } from 'react-error-boundary';
9
9
  import Loading from "dumi/theme/slots/Loading";
10
10
  import { ErrorFallback } from "../../../../builtins/Playground";
11
+ import { useAntVConfig } from "../../../../hooks/useProducts";
11
12
  function TaskBox() {
12
13
  var _themeConfig$ai, _themeConfig$ai2;
14
+ var _useAntVConfig = useAntVConfig(),
15
+ _useAntVConfig$data = _useAntVConfig.data,
16
+ _useAntVConfig$data2 = _useAntVConfig$data === void 0 ? {
17
+ VisionSnapVersion: '3.4.6'
18
+ } : _useAntVConfig$data,
19
+ version = _useAntVConfig$data2.VisionSnapVersion;
13
20
  var snap = useSnapshot(AIChatStore);
14
21
  var _useSiteData = useSiteData(),
15
22
  themeConfig = _useSiteData.themeConfig;
@@ -42,13 +49,17 @@ function TaskBox() {
42
49
  }]
43
50
  }];
44
51
  }, [demoId, snap.activeSessionId, snap.anonymousUserId, snap.codeBlock]);
45
- var _useVisionsnapSdk = useVisionsnapSdk('3.2.15'),
52
+ var _useVisionsnapSdk = useVisionsnapSdk(version),
46
53
  sdk = _useVisionsnapSdk.sdk,
47
54
  loading = _useVisionsnapSdk.loading;
48
55
  if (loading) {
49
56
  return /*#__PURE__*/React.createElement(Loading, null);
50
57
  }
51
58
  var wrappedVisionSnapCode = wrap2VisionSnap(snap.codeBlock);
59
+ var handleEsmLoadFailed = function handleEsmLoadFailed(err) {
60
+ var _err$data;
61
+ AIChatStore.errorMsg = ((_err$data = err.data) === null || _err$data === void 0 || (_err$data = _err$data.error) === null || _err$data === void 0 || (_err$data = _err$data.split('\n')) === null || _err$data === void 0 ? void 0 : _err$data[0]) || JSON.stringify(err) || err.message;
62
+ };
52
63
  if (themeConfig.isAntVSite || ((_themeConfig$ai = themeConfig.ai) === null || _themeConfig$ai === void 0 ? void 0 : _themeConfig$ai.codeRunner) === "VisionSnap" || !((_themeConfig$ai2 = themeConfig.ai) !== null && _themeConfig$ai2 !== void 0 && _themeConfig$ai2.codeRunner) || !wrappedVisionSnapCode.modules["/package.json"].code.includes("@antv/f2")) {
53
64
  return /*#__PURE__*/React.createElement(ErrorBoundary, {
54
65
  FallbackComponent: ErrorFallback
@@ -68,7 +79,8 @@ function TaskBox() {
68
79
  proxyOptions: {
69
80
  isWAN: true
70
81
  },
71
- src: "https://www.weavefox.cn/_visionsnap_render/index.html?version=3.2.15&enableInspector=1"
82
+ src: "https://www.weavefox.cn/_visionsnap_render/index.html?version=".concat(version, "&enableInspector=1"),
83
+ onEsmLoadFailed: handleEsmLoadFailed
72
84
  }));
73
85
  } else {
74
86
  return /*#__PURE__*/React.createElement(CodeRunner, {
@@ -31,7 +31,8 @@ export var SearchResult = function SearchResult(_ref) {
31
31
  mode: 'solve',
32
32
  lib: !themeConfig.isAntVSite ? themeConfig.title : undefined,
33
33
  jump: true,
34
- lang: intl.locale === 'zh' ? 'zh' : 'en'
34
+ lang: intl.locale === 'zh' ? 'zh' : 'en',
35
+ entry_point: 'SearchResult'
35
36
  });
36
37
  }
37
38
  return /*#__PURE__*/React.createElement("div", {
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 统一的事件跟踪函数
3
+ * @param {string} eventName - 事件名称,如 'button_click'
4
+ * @param {object} params - 事件相关的参数
5
+ */
6
+ export var trackEvent = function trackEvent(eventName) {
7
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
8
+ if (typeof window === 'undefined') {
9
+ return false;
10
+ }
11
+ if (window.gtag) {
12
+ window.gtag('event', eventName, params);
13
+ } else {
14
+ console.warn('[Analytics] gtag is not available.');
15
+ }
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.8.0-beta.14",
3
+ "version": "0.8.0-beta.16",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "keywords": [
6
6
  "dumi",