@antv/dumi-theme-antv 0.8.0-beta.0 → 0.8.0-beta.1

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.
@@ -20,10 +20,12 @@ import { AIMode, FileIcons } from "../../constant";
20
20
  import { ChooseLib } from "./ChooseLib";
21
21
  import { useSiteData } from 'dumi';
22
22
  import { ic } from "../../../../slots/hooks";
23
+ import { useTypewriter } from "../../../../hooks/useTypewriter";
23
24
  var PLACEHOLDER = {
24
25
  implement: '今天,你想可视化什么?',
25
26
  solve: '今天,你想解决什么可视化问题?'
26
27
  };
28
+ var uploadFileTooltip = '仅支持csv,json,tsv,txt文件,为了性能和成本,只会使用您数据的前几行作为样本';
27
29
  function PromptTextarea(props) {
28
30
  var value = props.value,
29
31
  size = props.size,
@@ -48,6 +50,9 @@ function PromptTextarea(props) {
48
50
  var isCompact = size === 'compact';
49
51
  var _useSiteData = useSiteData(),
50
52
  themeConfig = _useSiteData.themeConfig;
53
+ var typedPlaceholder = useTypewriter({
54
+ texts: ["".concat(themeConfig.title, "\u662F\u4EC0\u4E48\uFF1F"), ic(themeConfig.metas.description)]
55
+ });
51
56
  function renderDatasourceCard() {
52
57
  if (((fileMeta === null || fileMeta === void 0 ? void 0 : fileMeta.type) === 'FILE' || (fileMeta === null || fileMeta === void 0 ? void 0 : fileMeta.type) === 'IMAGE') && fileMeta !== null && fileMeta !== void 0 && fileMeta.fileName) {
53
58
  return /*#__PURE__*/React.createElement(DatasourceCard, {
@@ -92,7 +97,9 @@ function PromptTextarea(props) {
92
97
  },
93
98
  id: "prompt-textarea",
94
99
  className: classnames(styles.promptTextarea),
95
- placeholder: !isCompact && !themeConfig.isAntVSite && ic(themeConfig.metas.description) || _.get(PLACEHOLDER, mode, '今天,你想可视化什么?'),
100
+ placeholder:
101
+ // (!isCompact && !themeConfig.isAntVSite && ic(themeConfig.metas.description)) ||
102
+ !isCompact && !themeConfig.isAntVSite ? typedPlaceholder : _.get(PLACEHOLDER, mode, '今天,你想可视化什么?'),
96
103
  value: value,
97
104
  onChange: function onChange(evt) {
98
105
  _onChange(evt.target.value);
@@ -106,7 +113,7 @@ function PromptTextarea(props) {
106
113
  onChange: onLibChange,
107
114
  size: size
108
115
  }), mode === AIMode.implement && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip, {
109
- title: isCompact && '上传数据'
116
+ title: isCompact ? "\u4E0A\u4F20\u6570\u636E\u3002".concat(uploadFileTooltip) : uploadFileTooltip
110
117
  }, /*#__PURE__*/React.createElement(Upload, null, /*#__PURE__*/React.createElement("button", {
111
118
  type: "button"
112
119
  }, /*#__PURE__*/React.createElement("img", {
@@ -12,7 +12,7 @@ import { Spin } from 'antd';
12
12
  import React, { useCallback, useEffect, useState } from 'react';
13
13
  import { Card } from "./Card";
14
14
  import styles from "./index.module.less";
15
- import { RedoOutlined } from "@ant-design/icons";
15
+ import { ReloadOutlined } from "@ant-design/icons";
16
16
  import RecommendJson from "./recommend.json";
17
17
  import classnames from "classnames";
18
18
  export var RecommendCase = function RecommendCase(props) {
@@ -61,7 +61,7 @@ export var RecommendCase = function RecommendCase(props) {
61
61
  onClick: function onClick() {
62
62
  return fetchList();
63
63
  }
64
- }, /*#__PURE__*/React.createElement(RedoOutlined, null), "\u6362\u4E00\u6279")), /*#__PURE__*/React.createElement(Spin, {
64
+ }, /*#__PURE__*/React.createElement(ReloadOutlined, null), "\u6362\u4E00\u6279")), /*#__PURE__*/React.createElement(Spin, {
65
65
  spinning: loading,
66
66
  wrapperClassName: classnames(styles.listContainer, props.className)
67
67
  }, /*#__PURE__*/React.createElement("div", {
@@ -55,7 +55,8 @@ export function HomeDialog(props) {
55
55
  createNewSession({
56
56
  promptText: promptText,
57
57
  mode: mode,
58
- lib: lib
58
+ lib: lib,
59
+ jump: true
59
60
  });
60
61
  },
61
62
  style: props.promptTextareaStyle
@@ -61,49 +61,69 @@ export var useStreamingText = function useStreamingText(_ref) {
61
61
  }
62
62
  throw new Error('Response body is null');
63
63
  case 8:
64
+ if (!(response.headers.get("content-type") === "application/json")) {
65
+ _context.next = 19;
66
+ break;
67
+ }
68
+ _context.t0 = onFinish === null || onFinish === void 0;
69
+ if (_context.t0) {
70
+ _context.next = 18;
71
+ break;
72
+ }
73
+ _context.t1 = onFinish;
74
+ _context.t2 = JSON;
75
+ _context.next = 15;
76
+ return response.json();
77
+ case 15:
78
+ _context.t3 = _context.sent;
79
+ _context.t4 = _context.t2.stringify.call(_context.t2, _context.t3);
80
+ (0, _context.t1)(_context.t4);
81
+ case 18:
82
+ return _context.abrupt("return");
83
+ case 19:
64
84
  reader = response.body.getReader();
65
85
  decoder = new TextDecoder();
66
86
  accumulatedText = '';
67
- case 11:
87
+ case 22:
68
88
  if (!true) {
69
- _context.next = 25;
89
+ _context.next = 36;
70
90
  break;
71
91
  }
72
- _context.next = 14;
92
+ _context.next = 25;
73
93
  return reader.read();
74
- case 14:
94
+ case 25:
75
95
  _yield$reader$read = _context.sent;
76
96
  done = _yield$reader$read.done;
77
97
  value = _yield$reader$read.value;
78
98
  if (!done) {
79
- _context.next = 20;
99
+ _context.next = 31;
80
100
  break;
81
101
  }
82
102
  onFinish === null || onFinish === void 0 || onFinish(accumulatedText); // 流结束时调用 onFinish
83
- return _context.abrupt("break", 25);
84
- case 20:
103
+ return _context.abrupt("break", 36);
104
+ case 31:
85
105
  chunk = decoder.decode(value, {
86
106
  stream: true
87
107
  });
88
108
  accumulatedText += chunk;
89
109
  setText(accumulatedText);
90
- _context.next = 11;
110
+ _context.next = 22;
91
111
  break;
92
- case 25:
93
- _context.next = 30;
112
+ case 36:
113
+ _context.next = 41;
94
114
  break;
95
- case 27:
96
- _context.prev = 27;
97
- _context.t0 = _context["catch"](0);
98
- if (_context.t0.name !== 'AbortError') {
99
- console.error('Streaming fetch error:', _context.t0);
100
- onError === null || onError === void 0 || onError(_context.t0);
115
+ case 38:
116
+ _context.prev = 38;
117
+ _context.t5 = _context["catch"](0);
118
+ if (_context.t5.name !== 'AbortError') {
119
+ console.error('Streaming fetch error:', _context.t5);
120
+ onError === null || onError === void 0 || onError(_context.t5);
101
121
  }
102
- case 30:
122
+ case 41:
103
123
  case "end":
104
124
  return _context.stop();
105
125
  }
106
- }, _callee, null, [[0, 27]]);
126
+ }, _callee, null, [[0, 38]]);
107
127
  }));
108
128
  return function fetchData() {
109
129
  return _ref2.apply(this, arguments);
@@ -0,0 +1,69 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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
+ 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
+ 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
+ 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
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useState, useEffect } from 'react';
8
+
9
+ // Hook的参数类型定义
10
+
11
+ /**
12
+ * 一个自定义React Hook,用于实现打字机效果。
13
+ * @param {TypewriterOptions} options - 配置选项
14
+ * @returns {string} 当前应显示的文本
15
+ */
16
+ export var useTypewriter = function useTypewriter(_ref) {
17
+ var texts = _ref.texts,
18
+ _ref$typingSpeed = _ref.typingSpeed,
19
+ typingSpeed = _ref$typingSpeed === void 0 ? 150 : _ref$typingSpeed,
20
+ _ref$pauseDelay = _ref.pauseDelay,
21
+ pauseDelay = _ref$pauseDelay === void 0 ? 2000 : _ref$pauseDelay;
22
+ // 当前显示第几个字符串
23
+ var _useState = useState(0),
24
+ _useState2 = _slicedToArray(_useState, 2),
25
+ textIndex = _useState2[0],
26
+ setTextIndex = _useState2[1];
27
+ // 当前字符串显示到第几个字符
28
+ var _useState3 = useState(0),
29
+ _useState4 = _slicedToArray(_useState3, 2),
30
+ charIndex = _useState4[0],
31
+ setCharIndex = _useState4[1];
32
+ useEffect(function () {
33
+ // 获取当前要处理的完整字符串
34
+ var currentText = texts[textIndex];
35
+
36
+ // 如果当前字符索引小于字符串长度,说明还在打字过程中
37
+ if (charIndex < currentText.length) {
38
+ var typingTimeout = setTimeout(function () {
39
+ setCharIndex(function (prev) {
40
+ return prev + 1;
41
+ });
42
+ }, typingSpeed);
43
+
44
+ // 清除定时器,防止内存泄漏
45
+ return function () {
46
+ return clearTimeout(typingTimeout);
47
+ };
48
+ }
49
+ // 如果字已经打完
50
+ else {
51
+ var pauseTimeout = setTimeout(function () {
52
+ // 切换到下一个字符串
53
+ setTextIndex(function (prev) {
54
+ return (prev + 1) % texts.length;
55
+ });
56
+ // 重置字符索引,从头开始
57
+ setCharIndex(0);
58
+ }, pauseDelay);
59
+
60
+ // 清除定时器
61
+ return function () {
62
+ return clearTimeout(pauseTimeout);
63
+ };
64
+ }
65
+ }, [charIndex, textIndex, texts, typingSpeed, pauseDelay]);
66
+
67
+ // 根据当前状态截取并返回应该显示的字符串
68
+ return texts[textIndex].substring(0, charIndex);
69
+ };
@@ -48,6 +48,11 @@ subscribe(AIChatStore, function () {
48
48
  // 异步保存,不阻塞UI
49
49
  localforage.setItem(STORAGE_KEY, stateToPersist);
50
50
  });
51
+ export var clearEmptySession = function clearEmptySession() {
52
+ AIChatStore.sessions = AIChatStore.sessions.filter(function (s) {
53
+ return s.messages.length > 0;
54
+ });
55
+ };
51
56
 
52
57
  // --- 初始化逻辑 ---
53
58
  export var initializeStore = /*#__PURE__*/function () {
@@ -113,11 +118,12 @@ export var initializeStore = /*#__PURE__*/function () {
113
118
  })) {
114
119
  AIChatStore.activeSessionId = ((_AIChatStore$sessions = AIChatStore.sessions[0]) === null || _AIChatStore$sessions === void 0 ? void 0 : _AIChatStore$sessions.id) || null;
115
120
  }
121
+ clearEmptySession();
116
122
 
117
123
  // 4. 标记初始化完成,这将触发持久化订阅
118
124
  AIChatStore.isInitialized = true;
119
125
  // console.log('Valtio store initialized:', snapshot(AIChatStore));
120
- case 21:
126
+ case 22:
121
127
  case "end":
122
128
  return _context.stop();
123
129
  }
@@ -188,18 +194,20 @@ export var handlePinSession = function handlePinSession(sessionId) {
188
194
  subscribeKey(AIChatStore, 'activeSessionId', function () {
189
195
  AIChatStore.codeBlock = null;
190
196
  });
191
- export var createNewSession = function createNewSession(config) {
192
- // todo 埋点
193
- // 1. 创建一个新的会话
197
+ export var createPureNewSession = function createPureNewSession(title) {
194
198
  var newSessionId = crypto.randomUUID();
195
199
  AIChatStore.sessions.unshift({
196
200
  id: newSessionId,
197
- title: config.promptText.substring(0, 20),
198
- // 使用输入内容作为初始标题
201
+ title: title !== null && title !== void 0 ? title : 'New Conversation',
199
202
  createdAt: Date.now(),
200
203
  messages: []
201
204
  });
202
205
  AIChatStore.activeSessionId = newSessionId;
206
+ };
207
+ export var createNewSession = function createNewSession(config) {
208
+ // todo 埋点
209
+ // 1. 创建一个新的会话
210
+ createPureNewSession();
203
211
 
204
212
  // 2. 创建临时消息并存入 store
205
213
  AIChatStore.tempMessage = {
@@ -210,5 +218,7 @@ export var createNewSession = function createNewSession(config) {
210
218
  mode: config.mode,
211
219
  lib: config.lib
212
220
  };
213
- history.push("/zh/ai-playground/2");
221
+ if (config.jump) {
222
+ history.push("/zh/ai-playground/2");
223
+ }
214
224
  };
@@ -132,6 +132,9 @@ export var ConversationsMenu = function ConversationsMenu() {
132
132
  return setState({
133
133
  open: false
134
134
  });
135
+ },
136
+ okButtonProps: {
137
+ disabled: !state.rename
135
138
  }
136
139
  }, /*#__PURE__*/React.createElement(Input, {
137
140
  showCount: true,
@@ -1,7 +1,17 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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
+ 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
+ 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
+ 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
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
7
  import React from 'react';
2
8
  import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
3
9
  import { a11yLight } from "react-syntax-highlighter/dist/cjs/styles/hljs";
4
10
  import { AIChatStore } from "../../../../model/AIChat";
11
+ import { useCopyToClipboard } from "react-use";
12
+ import { CheckOutlined, CopyOutlined, PlaySquareOutlined } from "@ant-design/icons";
13
+ import { Space, Tooltip } from "antd";
14
+ import styles from "./MarkdownCodeBlock.module.less";
5
15
 
6
16
  // 定义 props 类型,它将接收 react-markdown 传递的所有属性
7
17
 
@@ -9,6 +19,10 @@ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
9
19
  var inline = _ref.inline,
10
20
  className = _ref.className,
11
21
  children = _ref.children;
22
+ var _useCopyToClipboard = useCopyToClipboard(),
23
+ _useCopyToClipboard2 = _slicedToArray(_useCopyToClipboard, 2),
24
+ copyState = _useCopyToClipboard2[0],
25
+ copyToClipboard = _useCopyToClipboard2[1];
12
26
  // 1. 处理行内代码:如果是行内代码,不做特殊处理,直接返回一个 <code> 标签
13
27
  if (inline || typeof children === 'string' && !children.includes("\n")) {
14
28
  return /*#__PURE__*/React.createElement("code", {
@@ -23,8 +37,8 @@ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
23
37
  // 3. 将 children 转换为字符串,并移除末尾的换行符
24
38
  var codeString = String(children).replace(/\n$/, '');
25
39
 
26
- // 4. 实现核心逻辑:判断是否显示“运行”按钮
27
- var showRunButton = codeString.trim().startsWith('import');
40
+ // 4. 判断是否显示“运行”按钮
41
+ var showRunButton = /\bimport\b/.test(codeString);
28
42
 
29
43
  // 5. 定义运行代码的逻辑
30
44
  var handleRunCode = function handleRunCode() {
@@ -38,24 +52,23 @@ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
38
52
  position: 'relative',
39
53
  margin: '1em 0'
40
54
  }
41
- }, showRunButton && /*#__PURE__*/React.createElement("button", {
55
+ }, /*#__PURE__*/React.createElement(Space, {
56
+ className: styles.button
57
+ }, /*#__PURE__*/React.createElement(Tooltip, {
58
+ title: "\u590D\u5236"
59
+ }, /*#__PURE__*/React.createElement("button", {
42
60
  type: "button",
43
- onClick: handleRunCode,
44
- style: {
45
- position: 'absolute',
46
- top: '0.5em',
47
- right: '0.5em',
48
- zIndex: 1,
49
- padding: '5px 10px',
50
- border: 'none',
51
- borderRadius: '5px',
52
- backgroundColor: '#4a4a4a',
53
- color: 'white',
54
- cursor: 'pointer',
55
- fontSize: '0.8em'
61
+ onClick: function onClick() {
62
+ return copyToClipboard(codeString);
56
63
  },
64
+ title: "\u590D\u5236"
65
+ }, copyState.value === codeString ? /*#__PURE__*/React.createElement(CheckOutlined, null) : /*#__PURE__*/React.createElement(CopyOutlined, null))), showRunButton && /*#__PURE__*/React.createElement(Tooltip, {
66
+ title: "\u8FD0\u884C\u6B64\u4EE3\u7801\u7247\u6BB5"
67
+ }, /*#__PURE__*/React.createElement("button", {
68
+ type: "button",
69
+ onClick: handleRunCode,
57
70
  title: "\u8FD0\u884C\u6B64\u4EE3\u7801\u7247\u6BB5"
58
- }, "\u8FD0\u884C"), /*#__PURE__*/React.createElement(SyntaxHighlighter, {
71
+ }, /*#__PURE__*/React.createElement(PlaySquareOutlined, null)))), /*#__PURE__*/React.createElement(SyntaxHighlighter, {
59
72
  style: a11yLight,
60
73
  language: language,
61
74
  PreTag: "div" // 使用 div 作为外层标签,避免 pre 标签的默认样式冲突
@@ -0,0 +1,14 @@
1
+ .button {
2
+ position: absolute;
3
+ top: 0.5em;
4
+ right: 0.5em;
5
+ z-index: 1;
6
+ button {
7
+ background-color: #4a4a4a;
8
+ color: white;
9
+ border: none;
10
+ border-radius: 5px;
11
+ cursor: pointer;
12
+ font-size: 0.8em;
13
+ }
14
+ }
@@ -20,7 +20,7 @@ export var MarkdownComponent = function MarkdownComponent(_ref) {
20
20
  rest = _objectWithoutProperties(props, _excluded);
21
21
  return /*#__PURE__*/React.createElement("p", _extends({
22
22
  style: {
23
- marginBottom: '1em',
23
+ marginBottom: 'unset',
24
24
  lineHeight: '1.6'
25
25
  }
26
26
  }, rest));
@@ -1,21 +1,27 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1
5
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
6
  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
7
  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
8
  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
9
  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
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import { CheckOutlined, CopyOutlined, DislikeOutlined, LikeOutlined, PlusSquareOutlined, SyncOutlined } from '@ant-design/icons';
12
+ import { Bubble } from '@ant-design/x';
13
+ import { Button, Flex, Space, Tooltip } from 'antd';
14
+ import { history, useSiteData } from 'dumi';
15
+ import { findLast } from 'lodash-es';
7
16
  import React, { useEffect, useState } from 'react';
17
+ import { useCopyToClipboard } from 'react-use';
18
+ import { useSnapshot } from 'valtio';
8
19
  import { PromptTextarea } from "../../../../components/AI/HomeDialog/PromptTextarea";
9
- import { Flex, Space } from 'antd';
10
- import { Bubble } from '@ant-design/x';
11
- import { history } from 'dumi';
12
20
  import { useStreamingText } from "../../../../hooks/useStreamingText";
13
- import { PlusSquareOutlined } from "@ant-design/icons";
14
- import styles from "./index.module.less";
15
- import { useSnapshot } from 'valtio';
16
- import { AIChatStore, createNewSession, derivedState } from "../../../../model/AIChat";
17
- import { findLast } from "lodash-es";
21
+ import { AIChatStore, clearEmptySession, createPureNewSession, derivedState } from "../../../../model/AIChat";
22
+ import { getCodeFromMarkdown, isPreviewable } from "../../../../utils/code";
18
23
  import { MarkdownComponent } from "../MarkdownComponent";
24
+ import styles from "./index.module.less";
19
25
  var avatar = {
20
26
  icon: /*#__PURE__*/React.createElement("img", {
21
27
  draggable: false,
@@ -24,47 +30,72 @@ var avatar = {
24
30
  }),
25
31
  style: {
26
32
  borderRadius: 0,
27
- backgroundColor: "transparent"
33
+ backgroundColor: 'transparent'
28
34
  }
29
35
  };
30
36
  var chatScrollIntoView = function chatScrollIntoView() {
31
37
  setTimeout(function () {
32
- var nodeList = document.querySelectorAll(".ant-bubble");
38
+ var nodeList = document.querySelectorAll('.ant-bubble');
33
39
  nodeList[nodeList.length - 1].scrollIntoView({
34
- behavior: "smooth",
35
- block: "center"
40
+ behavior: 'smooth'
36
41
  });
37
42
  });
38
43
  };
39
44
  function MsgBox(props) {
40
- var _derivedSnap$activeSe, _findLast, _derivedSnap$activeSe2, _ref, _props$messages, _derivedSnap$activeSe3;
41
- var _useState = useState(''),
45
+ var _derivedSnap$activeSe, _derivedSnap$activeSe2, _derivedSnap$activeSe3;
46
+ var _props$messages = props.messages,
47
+ messages = _props$messages === void 0 ? [] : _props$messages,
48
+ _props$simple = props.simple,
49
+ simple = _props$simple === void 0 ? false : _props$simple,
50
+ _props$context = props.context,
51
+ context = _props$context === void 0 ? '' : _props$context,
52
+ onCodegen = props.onCodegen,
53
+ title = props.title;
54
+ var _useSiteData = useSiteData(),
55
+ themeConfig = _useSiteData.themeConfig;
56
+ var _useState = useState(!themeConfig.isAntVSite ? themeConfig.title : undefined),
42
57
  _useState2 = _slicedToArray(_useState, 2),
43
- promptText = _useState2[0],
44
- setPromptText = _useState2[1];
45
- var _useState3 = useState(false),
58
+ lib = _useState2[0],
59
+ setLib = _useState2[1];
60
+ var _useState3 = useState(''),
46
61
  _useState4 = _slicedToArray(_useState3, 2),
47
- isStreaming = _useState4[0],
48
- setIsStreaming = _useState4[1]; // trigger
62
+ promptText = _useState4[0],
63
+ setPromptText = _useState4[1];
49
64
  var _useState5 = useState(false),
50
65
  _useState6 = _slicedToArray(_useState5, 2),
51
- loading = _useState6[0],
52
- setLoading = _useState6[1];
66
+ isStreaming = _useState6[0],
67
+ setIsStreaming = _useState6[1]; // trigger
68
+ var _useState7 = useState(false),
69
+ _useState8 = _slicedToArray(_useState7, 2),
70
+ loading = _useState8[0],
71
+ setLoading = _useState8[1];
53
72
  var snap = useSnapshot(AIChatStore);
54
73
  var derivedSnap = useSnapshot(derivedState);
74
+ var _useCopyToClipboard = useCopyToClipboard(),
75
+ _useCopyToClipboard2 = _slicedToArray(_useCopyToClipboard, 2),
76
+ copyState = _useCopyToClipboard2[0],
77
+ copyToClipboard = _useCopyToClipboard2[1];
78
+ var latestUserMessage = findLast((_derivedSnap$activeSe = derivedSnap.activeSession) === null || _derivedSnap$activeSe === void 0 ? void 0 : _derivedSnap$activeSe.messages, function (msg) {
79
+ return msg.role === 'user';
80
+ });
55
81
  var streamingText = useStreamingText({
56
- url: 'http://127.0.0.1:7001/ai/chat',
82
+ url: 'https://webgw-pre.alipay.com/visqaservice/external/chat',
57
83
  method: 'POST',
58
84
  body: {
59
- "gptConversationId": (_derivedSnap$activeSe = derivedSnap.activeSession) === null || _derivedSnap$activeSe === void 0 ? void 0 : _derivedSnap$activeSe.id,
60
- "query": (_findLast = findLast((_derivedSnap$activeSe2 = derivedSnap.activeSession) === null || _derivedSnap$activeSe2 === void 0 ? void 0 : _derivedSnap$activeSe2.messages, function (msg) {
61
- return msg.role === 'user';
62
- })) === null || _findLast === void 0 ? void 0 : _findLast.content
85
+ gptConversationId: (_derivedSnap$activeSe2 = derivedSnap.activeSession) === null || _derivedSnap$activeSe2 === void 0 ? void 0 : _derivedSnap$activeSe2.id,
86
+ query: latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.content,
87
+ library: (latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.lib) || lib,
88
+ mode: latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.mode,
89
+ anonymousUserId: snap.anonymousUserId,
90
+ context: (latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.context) || context,
91
+ mountId: "container"
63
92
  },
64
93
  trigger: isStreaming,
65
94
  // 将 isStreaming 状态作为 trigger
66
95
  headers: {
67
- 'Content-Type': 'application/json'
96
+ 'Content-Type': 'application/json',
97
+ 'x-webgw-version': '2.0',
98
+ 'x-webgw-appid': '180020010001210065'
68
99
  },
69
100
  beforeStart: function beforeStart() {
70
101
  setLoading(true);
@@ -81,6 +112,11 @@ function MsgBox(props) {
81
112
  // mode,
82
113
  // lib,
83
114
  });
115
+ if (isPreviewable(finalJSON.content)) {
116
+ var codeBlock = getCodeFromMarkdown(finalJSON.content).code;
117
+ AIChatStore.codeBlock = codeBlock;
118
+ onCodegen === null || onCodegen === void 0 || onCodegen(codeBlock);
119
+ }
84
120
  } catch (e) {
85
121
  // 说明不是JSON格式
86
122
  } finally {
@@ -91,34 +127,33 @@ function MsgBox(props) {
91
127
  }
92
128
  },
93
129
  onError: function onError(error) {
130
+ var _derivedState$activeS2;
131
+ console.log('回答失败', error);
94
132
  // 处理错误
95
- console.error("AI stream failed:", error);
96
- // setMessages(prev => [
97
- // ...prev,
98
- // { id: Date.now(), role: 'assistant', content: `Sorry, an error occurred: ${error.message}` }
99
- // ]);
100
- setIsStreaming(false); // **关键:出错后,也要关闭 trigger**
133
+ (_derivedState$activeS2 = derivedState.activeSession) === null || _derivedState$activeS2 === void 0 || (_derivedState$activeS2 = _derivedState$activeS2.messages) === null || _derivedState$activeS2 === void 0 || _derivedState$activeS2.push({
134
+ id: crypto.randomUUID(),
135
+ role: 'assistant',
136
+ content: "\u62B1\u6B49\uFF0C\u6211\u6CA1\u80FD\u6210\u529F\u5904\u7406\u60A8\u7684\u8BF7\u6C42\uFF0C\u8BF7\u7A0D\u540E\u518D\u6B21\u63D0\u95EE",
137
+ createdAt: Date.now()
138
+ // mode,
139
+ // lib,
140
+ });
141
+ setIsStreaming(false);
142
+ setLoading(false);
101
143
  }
102
144
  });
103
145
 
104
146
  // 3. 处理用户提交
105
147
  var handleSubmit = function handleSubmit() {
106
- var _derivedState$activeS2;
107
- if (props.simple) {
108
- createNewSession({
109
- promptText: promptText
110
- });
111
- return;
112
- }
148
+ var _derivedState$activeS3;
113
149
  if (!promptText.trim() || isStreaming) return; // 如果正在流式输出,则不允许发送
114
150
  setPromptText('');
115
- (_derivedState$activeS2 = derivedState.activeSession) === null || _derivedState$activeS2 === void 0 || (_derivedState$activeS2 = _derivedState$activeS2.messages) === null || _derivedState$activeS2 === void 0 || _derivedState$activeS2.push({
151
+ (_derivedState$activeS3 = derivedState.activeSession) === null || _derivedState$activeS3 === void 0 || (_derivedState$activeS3 = _derivedState$activeS3.messages) === null || _derivedState$activeS3 === void 0 || _derivedState$activeS3.push({
116
152
  id: crypto.randomUUID(),
117
153
  role: 'user',
118
154
  content: promptText,
119
- createdAt: Date.now()
120
- // mode,
121
- // lib,
155
+ createdAt: Date.now(),
156
+ lib: lib
122
157
  });
123
158
  // **关键:开启 trigger,开始请求**
124
159
  setIsStreaming(true);
@@ -135,6 +170,12 @@ function MsgBox(props) {
135
170
  AIChatStore.tempMessage = null;
136
171
  }
137
172
  }
173
+ if (simple) {
174
+ createPureNewSession(title);
175
+ }
176
+ return function () {
177
+ clearEmptySession();
178
+ };
138
179
  }, []);
139
180
  useEffect(function () {
140
181
  if (derivedState.activeSession && Date.now() - derivedState.activeSession.createdAt > 5000) {
@@ -142,17 +183,56 @@ function MsgBox(props) {
142
183
  setIsStreaming(false);
143
184
  }
144
185
  }, [snap.activeSessionId]);
186
+ var showMessages = [].concat(_toConsumableArray(messages), _toConsumableArray((_derivedSnap$activeSe3 = derivedSnap.activeSession) === null || _derivedSnap$activeSe3 === void 0 ? void 0 : _derivedSnap$activeSe3.messages));
145
187
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Flex, {
146
188
  gap: "middle",
147
189
  vertical: true,
148
190
  className: styles.chatContainer
149
- }, (_ref = (_props$messages = props.messages) !== null && _props$messages !== void 0 ? _props$messages : (_derivedSnap$activeSe3 = derivedSnap.activeSession) === null || _derivedSnap$activeSe3 === void 0 ? void 0 : _derivedSnap$activeSe3.messages) === null || _ref === void 0 ? void 0 : _ref.map(function (msg, index) {
191
+ }, showMessages === null || showMessages === void 0 ? void 0 : showMessages.map(function (msg, index) {
150
192
  return /*#__PURE__*/React.createElement(Bubble, {
151
193
  key: index,
152
194
  content: /*#__PURE__*/React.createElement(MarkdownComponent, {
153
195
  content: msg.content
154
196
  }),
155
197
  avatar: msg.role === 'assistant' ? avatar : null,
198
+ footer: msg.role === 'assistant' && index > 0 ? /*#__PURE__*/React.createElement(Space, {
199
+ size: "small"
200
+ }, /*#__PURE__*/React.createElement(Tooltip, {
201
+ title: "\u70B9\u8D5E"
202
+ }, /*#__PURE__*/React.createElement(Button, {
203
+ color: "default",
204
+ variant: "text",
205
+ size: "small",
206
+ icon: /*#__PURE__*/React.createElement(LikeOutlined, null)
207
+ })), /*#__PURE__*/React.createElement(Tooltip, {
208
+ title: "\u70B9\u8E29"
209
+ }, /*#__PURE__*/React.createElement(Button, {
210
+ color: "default",
211
+ variant: "text",
212
+ size: "small",
213
+ icon: /*#__PURE__*/React.createElement(DislikeOutlined, null)
214
+ })), index === showMessages.length - 1 && /*#__PURE__*/React.createElement(Tooltip, {
215
+ title: "\u518D\u6765\u4E00\u6B21"
216
+ }, /*#__PURE__*/React.createElement(Button, {
217
+ onClick: function onClick() {
218
+ derivedState.activeSession.messages.pop();
219
+ setIsStreaming(true);
220
+ },
221
+ color: "default",
222
+ variant: "text",
223
+ size: "small",
224
+ icon: /*#__PURE__*/React.createElement(SyncOutlined, null)
225
+ })), /*#__PURE__*/React.createElement(Tooltip, {
226
+ title: "\u590D\u5236"
227
+ }, /*#__PURE__*/React.createElement(Button, {
228
+ color: "default",
229
+ variant: "text",
230
+ size: "small",
231
+ onClick: function onClick() {
232
+ return copyToClipboard(msg.content);
233
+ },
234
+ icon: copyState.value === msg.content ? /*#__PURE__*/React.createElement(CheckOutlined, null) : /*#__PURE__*/React.createElement(CopyOutlined, null)
235
+ }))) : null,
156
236
  placement: msg.role === 'user' ? 'end' : 'start'
157
237
  });
158
238
  }), loading && /*#__PURE__*/React.createElement(Bubble, {
@@ -181,7 +261,9 @@ function MsgBox(props) {
181
261
  style: {
182
262
  marginBottom: 0
183
263
  },
184
- onConfirm: handleSubmit
264
+ onConfirm: handleSubmit,
265
+ lib: lib,
266
+ onLibChange: setLib
185
267
  })));
186
268
  }
187
269
  export default MsgBox;
@@ -97,14 +97,13 @@ export function wrap2Sandpack() {
97
97
  // if (match) {
98
98
  return {
99
99
  "/package.json": {
100
- code: "{\n \"name\": \"AntV-AI-Code\",\n \"version\": \"1.0.0\",\n \"main\": \"/index.js\",\n \"dependencies\": ".concat(JSON.stringify(generateDependencies(codeBlock), null, 2), "\n }")
100
+ code: "{\n \"name\": \"AntV-AI-Code\",\n \"version\": \"1.0.0\",\n \"main\": \"/index.tsx\",\n \"dependencies\": ".concat(JSON.stringify(generateDependencies(codeBlock), null, 2), "\n }")
101
101
  },
102
- "/index.js": {
103
- // 入口文件是纯 JS
102
+ "/index.tsx": {
104
103
  code: codeBlock
105
104
  },
106
105
  "/index.html": {
107
- code: "<!DOCTYPE html>\n<html>\n<head>\n <title>Vanilla JS Example</title>\n</head>\n<body>\n <div id=\"root\"></div>\n <div id=\"container\"></div>\n <script src=\"index.js\"></script>\n</body>\n</html>"
106
+ code: "<!DOCTYPE html>\n<html>\n<head>\n <title>Vanilla JS Example</title>\n</head>\n<body>\n <div id=\"root\"></div>\n <div id=\"container\"></div>\n <script src=\"index.tsx\"></script>\n</body>\n</html>"
108
107
  }
109
108
  };
110
109
  }
@@ -46,6 +46,7 @@ function TaskBox() {
46
46
  theme: "light" // 主题:dark, light, auto
47
47
  ,
48
48
  customSetup: {
49
+ entry: "/index.tsx",
49
50
  npmRegistries: [{
50
51
  limitToScopes: false,
51
52
  // 设为 false 使所有包都从自定义 registry 获取
@@ -10,7 +10,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
10
10
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
11
11
  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); }
12
12
  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); }
13
- import { CodeSandboxOutlined, PlayCircleOutlined, ThunderboltOutlined } from '@ant-design/icons';
13
+ import { CodeSandboxOutlined, PlayCircleOutlined, ReloadOutlined, ThunderboltOutlined } from '@ant-design/icons';
14
14
  import stackblitzSdk from '@stackblitz/sdk';
15
15
  import { Tooltip, Typography } from 'antd';
16
16
  import { getParameters } from 'codesandbox/lib/api/define';
@@ -43,7 +43,8 @@ export var Toolbar = function Toolbar(_ref) {
43
43
  _ref$onToggleFullscre = _ref.onToggleFullscreen,
44
44
  onToggleFullscreen = _ref$onToggleFullscre === void 0 ? null : _ref$onToggleFullscre,
45
45
  onExecuteCode = _ref.onExecuteCode,
46
- onClickAI = _ref.onClickAI;
46
+ onClickAI = _ref.onClickAI,
47
+ onReload = _ref.onReload;
47
48
  var locale = useLocale();
48
49
  var exampleTitle = _typeof(title) === 'object' ? title[locale.id] : title;
49
50
 
@@ -82,7 +83,12 @@ export var Toolbar = function Toolbar(_ref) {
82
83
  })), /*#__PURE__*/React.createElement("a", {
83
84
  className: styles.ai,
84
85
  onClick: onClickAI
85
- }, "AI \u52A9\u624B"), riddleVisible ? /*#__PURE__*/React.createElement("form", {
86
+ }, "AI \u52A9\u624B"), /*#__PURE__*/React.createElement(Tooltip, {
87
+ title: "\u8FD8\u539F"
88
+ }, /*#__PURE__*/React.createElement("span", {
89
+ className: styles.ai,
90
+ onClick: onReload
91
+ }, /*#__PURE__*/React.createElement(ReloadOutlined, null))), riddleVisible ? /*#__PURE__*/React.createElement("form", {
86
92
  action: "//riddle.alibaba-inc.com/riddles/define",
87
93
  method: "POST",
88
94
  target: "_blank"
@@ -83,6 +83,7 @@
83
83
 
84
84
 
85
85
  .ai {
86
+ cursor: pointer;
86
87
  margin-right: 10px;
87
88
  font-size: 12px;
88
89
  }
@@ -280,6 +280,7 @@ var CodeEditor = function CodeEditor(_ref) {
280
280
  // 用于更新当前 example 的 spec 和 data
281
281
  useEffect(function () {
282
282
  setCurrentEditorTab(EDITOR_TABS.JAVASCRIPT);
283
+ setShowAI(false);
283
284
  }, [exampleId]);
284
285
 
285
286
  // hook 用户的数据
@@ -385,6 +386,9 @@ var CodeEditor = function CodeEditor(_ref) {
385
386
  var onClickAI = function onClickAI() {
386
387
  setShowAI(true);
387
388
  };
389
+ var onReload = function onReload() {
390
+ setCode(source);
391
+ };
388
392
  return /*#__PURE__*/React.createElement("div", {
389
393
  className: styles.editor
390
394
  }, /*#__PURE__*/React.createElement(Toolbar, {
@@ -402,6 +406,7 @@ var CodeEditor = function CodeEditor(_ref) {
402
406
  onEditorTabChange: onTabChange,
403
407
  onToggleFullscreen: onFullscreen,
404
408
  onClickAI: onClickAI,
409
+ onReload: onReload,
405
410
  slots: {
406
411
  Spec: /*#__PURE__*/React.createElement("span", {
407
412
  style: {
@@ -461,7 +466,8 @@ var CodeEditor = function CodeEditor(_ref) {
461
466
  onClose: function onClose() {
462
467
  return setShowAI(false);
463
468
  },
464
- rootClassName: styles.drawer
469
+ rootClassName: styles.drawer,
470
+ width: '90%'
465
471
  }, /*#__PURE__*/React.createElement(MsgBox, {
466
472
  simple: true,
467
473
  messages: [{
@@ -469,7 +475,12 @@ var CodeEditor = function CodeEditor(_ref) {
469
475
  role: 'assistant',
470
476
  content: "\u6211\u662FAntV AI\u52A9\u624B\u3002\u60A8\u53EF\u4EE5\u968F\u65F6\u5411\u6211\u63D0\u95EE\uFF0C\u8BA9\u6211\u4E3A\u60A8\uFF1A\n \n1\u3001\u89E3\u8BFB\u5F53\u524D\u56FE\u8868\u7684\u4EE3\u7801\u914D\u7F6E\u3002\n \n2\u3001\u901A\u8FC7\u81EA\u7136\u8BED\u8A00\u5BF9\u8BDD\uFF0C\u57FA\u4E8E\u5F53\u524D\u6848\u4F8B\u751F\u6210\u65B0\u4EE3\u7801\u4EE5\u5B9A\u5236\u56FE\u8868\u3002",
471
477
  createdAt: Date.now()
472
- }]
478
+ }],
479
+ context: valueOf(tab),
480
+ onCodegen: function onCodegen(codeBlock) {
481
+ setCode(codeBlock);
482
+ },
483
+ title: title
473
484
  })));
474
485
  }));
475
486
  };
@@ -79,7 +79,8 @@ var CodeRunner = function CodeRunner(_ref) {
79
79
  onFullscreen: setFullscreen,
80
80
  onDestroy: noop,
81
81
  onReady: noop,
82
- playground: playground
82
+ playground: playground,
83
+ title: ic(title)
83
84
  }))));
84
85
  };
85
86
  export default CodeRunner;
@@ -38,7 +38,8 @@ export var SearchResult = function SearchResult(_ref) {
38
38
  createNewSession({
39
39
  promptText: keywords,
40
40
  mode: "solve",
41
- lib: !themeConfig.isAntVSite ? themeConfig.title : undefined
41
+ lib: !themeConfig.isAntVSite ? themeConfig.title : undefined,
42
+ jump: true
42
43
  });
43
44
  }
44
45
  }, /*#__PURE__*/React.createElement("div", {
@@ -0,0 +1,35 @@
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 _wrapRegExp() { _wrapRegExp = function _wrapRegExp(e, r) { return new BabelRegExp(e, void 0, r); }; var e = RegExp.prototype, r = new WeakMap(); function BabelRegExp(e, t, p) { var o = new RegExp(e, t); return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype); } function buildGroups(e, t) { var p = r.get(t); return Object.keys(p).reduce(function (r, t) { var o = p[t]; if ("number" == typeof o) r[t] = e[o];else { for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) i++; r[t] = e[o[i]]; } return r; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) { var t = e.exec.call(this, r); if (t) { t.groups = buildGroups(t, this); var p = t.indices; p && (p.groups = buildGroups(p, this)); } return t; }, BabelRegExp.prototype[Symbol.replace] = function (t, p) { if ("string" == typeof p) { var o = r.get(this); return e[Symbol.replace].call(this, t, p.replace(/\$<([^>]+)>/g, function (e, r) { var t = o[r]; return "$" + (Array.isArray(t) ? t.join("$") : t); })); } if ("function" == typeof p) { var i = this; return e[Symbol.replace].call(this, t, function () { var e = arguments; return "object" != _typeof(e[e.length - 1]) && (e = [].slice.call(e)).push(buildGroups(e, i)), p.apply(this, e); }); } return e[Symbol.replace].call(this, t, p); }, _wrapRegExp.apply(this, arguments); }
3
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
4
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
5
+ export function isPreviewable(str) {
6
+ if (typeof str !== 'string') {
7
+ return false;
8
+ }
9
+ var trimmedStr = str.trim();
10
+
11
+ // \b 是一个“单词边界”,确保我们匹配的是完整的 "import" 单词
12
+ // 而不是 "important" 的一部分
13
+ var hasImportStatement = /\bimport\b/.test(trimmedStr);
14
+ if (trimmedStr.startsWith('```') && trimmedStr.endsWith('```') && hasImportStatement) {
15
+ return true;
16
+ }
17
+ return false;
18
+ }
19
+ export function getCodeFromMarkdown() {
20
+ var md = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
21
+ var regex = /*#__PURE__*/_wrapRegExp(/```(\w*)\n?([\s\S]*?)```/, {
22
+ lang: 1,
23
+ code: 2
24
+ });
25
+ var match = md.match(regex);
26
+ if (match) {
27
+ return {
28
+ lang: match.groups.lang || 'plaintext',
29
+ code: match.groups.code.trim()
30
+ };
31
+ }
32
+ return {
33
+ code: ''
34
+ };
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.8.0-beta.0",
3
+ "version": "0.8.0-beta.1",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "keywords": [
6
6
  "dumi",