@antv/dumi-theme-antv 0.8.0-beta.15 → 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
  }
@@ -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
  }
@@ -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
  };
@@ -277,7 +277,7 @@ function MsgBox(props) {
277
277
  var _derivedState$activeS6;
278
278
  var autoFixPromptText = "".concat(formatMessage({
279
279
  id: 'ai.msgbox.auto.fix.prompt'
280
- }), ": [").concat(snap.errorMsg, "]");
280
+ }), " [").concat(snap.errorMsg, "]");
281
281
  sendMessage({
282
282
  text: autoFixPromptText
283
283
  }, {
@@ -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',
@@ -72,11 +72,17 @@ export function generateDependencies(codeString) {
72
72
  dependencies[pkg] = "latest";
73
73
  }
74
74
  }
75
+
76
+ // f2的语法是jsx。VisionSnap限制只要是jsx就必须装React。
75
77
  } catch (err) {
76
78
  _iterator.e(err);
77
79
  } finally {
78
80
  _iterator.f();
79
81
  }
82
+ if (Object.prototype.hasOwnProperty.call(dependencies, "@antv/f2")) {
83
+ dependencies["react"] = "^18";
84
+ dependencies["react-dom"] = "^18";
85
+ }
80
86
  return dependencies;
81
87
  }
82
88
 
@@ -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,7 +49,7 @@ 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) {
@@ -50,11 +57,8 @@ function TaskBox() {
50
57
  }
51
58
  var wrappedVisionSnapCode = wrap2VisionSnap(snap.codeBlock);
52
59
  var handleEsmLoadFailed = function handleEsmLoadFailed(err) {
53
- // F2的异常没法修,VisionSnap的异常信息不准确
54
- if (!wrappedVisionSnapCode.modules["/package.json"].code.includes("@antv/f2")) {
55
- var _err$data;
56
- 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[1]) || JSON.stringify(err) || err.message;
57
- }
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;
58
62
  };
59
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")) {
60
64
  return /*#__PURE__*/React.createElement(ErrorBoundary, {
@@ -75,7 +79,7 @@ function TaskBox() {
75
79
  proxyOptions: {
76
80
  isWAN: true
77
81
  },
78
- 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"),
79
83
  onEsmLoadFailed: handleEsmLoadFailed
80
84
  }));
81
85
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.8.0-beta.15",
3
+ "version": "0.8.0-beta.16",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "keywords": [
6
6
  "dumi",