@antv/dumi-theme-antv 0.7.9 → 0.8.0-beta.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.
Files changed (70) hide show
  1. package/dist/builtins/Playground/index.js +1 -1
  2. package/dist/common/styles/Common.js +1 -1
  3. package/dist/common/styles/theme.js +1 -1
  4. package/dist/components/AI/HomeDialog/AntVBanner/index.js +4 -0
  5. package/dist/components/AI/HomeDialog/AntVBanner/index.module.less +35 -0
  6. package/dist/components/AI/HomeDialog/ModeSelector/index.js +29 -0
  7. package/dist/components/AI/HomeDialog/ModeSelector/index.module.less +272 -0
  8. package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.js +51 -0
  9. package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.module.less +5 -0
  10. package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.js +25 -0
  11. package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.module.less +42 -0
  12. package/dist/components/AI/HomeDialog/PromptTextarea/SendButton.js +23 -0
  13. package/dist/components/AI/HomeDialog/PromptTextarea/SendButton.module.less +9 -0
  14. package/dist/components/AI/HomeDialog/PromptTextarea/index.js +132 -0
  15. package/dist/components/AI/HomeDialog/PromptTextarea/index.module.less +127 -0
  16. package/dist/components/AI/HomeDialog/RecommendCase/Card.js +70 -0
  17. package/dist/components/AI/HomeDialog/RecommendCase/card.module.less +131 -0
  18. package/dist/components/AI/HomeDialog/RecommendCase/index.js +76 -0
  19. package/dist/components/AI/HomeDialog/RecommendCase/index.module.less +43 -0
  20. package/dist/components/AI/HomeDialog/RecommendCase/recommend.json +42 -0
  21. package/dist/components/AI/HomeDialog/index.js +65 -0
  22. package/dist/components/AI/HomeDialog/index.module.less +3 -0
  23. package/dist/components/AI/constant.js +35 -0
  24. package/dist/components/AI/index.js +1 -0
  25. package/dist/components/AI/types.js +1 -0
  26. package/dist/components/AI/utils.js +38 -0
  27. package/dist/hooks/useProducts.js +18 -0
  28. package/dist/hooks/useStreamingText.js +119 -0
  29. package/dist/hooks/useVisionsnapSdk.js +159 -0
  30. package/dist/layouts/DocLayout.js +0 -1
  31. package/dist/layouts/GlobalLayout/index.js +15 -0
  32. package/dist/model/AIChat.js +214 -0
  33. package/dist/pages/AIPlayground/components/ConversationsMenu/index.js +146 -0
  34. package/dist/pages/AIPlayground/components/ConversationsMenu/index.module.less +44 -0
  35. package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +65 -0
  36. package/dist/pages/AIPlayground/components/MarkdownComponent/index.js +47 -0
  37. package/dist/pages/AIPlayground/components/MsgBox/index.js +187 -0
  38. package/dist/pages/AIPlayground/components/MsgBox/index.module.less +42 -0
  39. package/dist/pages/AIPlayground/components/SessionLayout/index.js +25 -0
  40. package/dist/pages/AIPlayground/components/SessionLayout/index.module.less +34 -0
  41. package/dist/pages/AIPlayground/components/TaskBox/generateCode.js +110 -0
  42. package/dist/pages/AIPlayground/components/TaskBox/index.js +60 -0
  43. package/dist/pages/AIPlayground/components/TaskBox/index.module.less +8 -0
  44. package/dist/pages/AIPlayground/demo.js +34 -0
  45. package/dist/pages/AIPlayground/index.js +9 -0
  46. package/dist/pages/AIPlayground/index.module.less +0 -0
  47. package/dist/pages/Examples/index.module.less +2 -2
  48. package/dist/pages/Index/components/Cases/index.module.less +1 -1
  49. package/dist/pages/Index/components/Companies/index.module.less +1 -1
  50. package/dist/pages/Index/components/Features/index.module.less +1 -1
  51. package/dist/pages/Index/index.js +1 -1
  52. package/dist/plugin/index.js +14 -6
  53. package/dist/slots/Banner/index.module.less +1 -1
  54. package/dist/slots/CodeEditor/Toolbar.js +6 -2
  55. package/dist/slots/CodeEditor/Toolbar.module.less +6 -0
  56. package/dist/slots/CodeEditor/index.js +28 -2
  57. package/dist/slots/CodeEditor/index.module.less +22 -0
  58. package/dist/{pages/Index/components → slots}/Detail/News.js +1 -1
  59. package/dist/{pages/Index/components → slots}/Detail/index.js +11 -28
  60. package/dist/{pages/Index/components → slots}/Detail/index.module.less +13 -7
  61. package/dist/slots/Footer/index.module.less +1 -1
  62. package/dist/slots/Header/Products/Product.module.less +1 -1
  63. package/dist/slots/Header/Products/getProducts.js +20 -26
  64. package/dist/slots/Header/Products/index.js +20 -16
  65. package/dist/slots/Header/Search/SearchResult.js +35 -14
  66. package/dist/slots/Header/Search/index.js +2 -1
  67. package/dist/slots/Header/index.module.less +2 -2
  68. package/dist/typings.d.ts +5 -0
  69. package/package.json +21 -2
  70. /package/dist/{pages/Index/components → slots}/Detail/News.module.less +0 -0
@@ -0,0 +1,187 @@
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 React, { useEffect, useState } from 'react';
8
+ 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
+ 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";
18
+ import { MarkdownComponent } from "../MarkdownComponent";
19
+ var avatar = {
20
+ icon: /*#__PURE__*/React.createElement("img", {
21
+ draggable: false,
22
+ src: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*7svFR6wkPMoAAAAAAAAAAAAADmJ7AQ/original',
23
+ alt: "AntV"
24
+ }),
25
+ style: {
26
+ borderRadius: 0,
27
+ backgroundColor: "transparent"
28
+ }
29
+ };
30
+ var chatScrollIntoView = function chatScrollIntoView() {
31
+ setTimeout(function () {
32
+ var nodeList = document.querySelectorAll(".ant-bubble");
33
+ nodeList[nodeList.length - 1].scrollIntoView({
34
+ behavior: "smooth",
35
+ block: "center"
36
+ });
37
+ });
38
+ };
39
+ function MsgBox(props) {
40
+ var _derivedSnap$activeSe, _findLast, _derivedSnap$activeSe2, _ref, _props$messages, _derivedSnap$activeSe3;
41
+ var _useState = useState(''),
42
+ _useState2 = _slicedToArray(_useState, 2),
43
+ promptText = _useState2[0],
44
+ setPromptText = _useState2[1];
45
+ var _useState3 = useState(false),
46
+ _useState4 = _slicedToArray(_useState3, 2),
47
+ isStreaming = _useState4[0],
48
+ setIsStreaming = _useState4[1]; // trigger
49
+ var _useState5 = useState(false),
50
+ _useState6 = _slicedToArray(_useState5, 2),
51
+ loading = _useState6[0],
52
+ setLoading = _useState6[1];
53
+ var snap = useSnapshot(AIChatStore);
54
+ var derivedSnap = useSnapshot(derivedState);
55
+ var streamingText = useStreamingText({
56
+ url: 'http://127.0.0.1:7001/ai/chat',
57
+ method: 'POST',
58
+ 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
63
+ },
64
+ trigger: isStreaming,
65
+ // 将 isStreaming 状态作为 trigger
66
+ headers: {
67
+ 'Content-Type': 'application/json'
68
+ },
69
+ beforeStart: function beforeStart() {
70
+ setLoading(true);
71
+ },
72
+ onFinish: function onFinish(finalText) {
73
+ try {
74
+ var _derivedState$activeS;
75
+ var finalJSON = JSON.parse(finalText);
76
+ (_derivedState$activeS = derivedState.activeSession) === null || _derivedState$activeS === void 0 || (_derivedState$activeS = _derivedState$activeS.messages) === null || _derivedState$activeS === void 0 || _derivedState$activeS.push({
77
+ id: crypto.randomUUID(),
78
+ role: 'assistant',
79
+ content: finalJSON.content,
80
+ createdAt: Date.now()
81
+ // mode,
82
+ // lib,
83
+ });
84
+ } catch (e) {
85
+ // 说明不是JSON格式
86
+ } finally {
87
+ // 当流结束时,更新最后一条消息并重置 trigger
88
+ setIsStreaming(false); // **关键:流结束后,关闭 trigger**
89
+ setLoading(false);
90
+ chatScrollIntoView();
91
+ }
92
+ },
93
+ onError: function onError(error) {
94
+ // 处理错误
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**
101
+ }
102
+ });
103
+
104
+ // 3. 处理用户提交
105
+ var handleSubmit = function handleSubmit() {
106
+ var _derivedState$activeS2;
107
+ if (props.simple) {
108
+ createNewSession({
109
+ promptText: promptText
110
+ });
111
+ return;
112
+ }
113
+ if (!promptText.trim() || isStreaming) return; // 如果正在流式输出,则不允许发送
114
+ setPromptText('');
115
+ (_derivedState$activeS2 = derivedState.activeSession) === null || _derivedState$activeS2 === void 0 || (_derivedState$activeS2 = _derivedState$activeS2.messages) === null || _derivedState$activeS2 === void 0 || _derivedState$activeS2.push({
116
+ id: crypto.randomUUID(),
117
+ role: 'user',
118
+ content: promptText,
119
+ createdAt: Date.now()
120
+ // mode,
121
+ // lib,
122
+ });
123
+ // **关键:开启 trigger,开始请求**
124
+ setIsStreaming(true);
125
+ chatScrollIntoView();
126
+ };
127
+ useEffect(function () {
128
+ // 检查是否存在临时消息
129
+ if (snap.tempMessage) {
130
+ var activeSession = derivedState.activeSession;
131
+ if (activeSession) {
132
+ // 1. 将临时消息正式添加到当前会话中
133
+ activeSession.messages.push(snap.tempMessage);
134
+ setIsStreaming(true);
135
+ AIChatStore.tempMessage = null;
136
+ }
137
+ }
138
+ }, []);
139
+ useEffect(function () {
140
+ if (derivedState.activeSession && Date.now() - derivedState.activeSession.createdAt > 5000) {
141
+ setLoading(false);
142
+ setIsStreaming(false);
143
+ }
144
+ }, [snap.activeSessionId]);
145
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Flex, {
146
+ gap: "middle",
147
+ vertical: true,
148
+ 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) {
150
+ return /*#__PURE__*/React.createElement(Bubble, {
151
+ key: index,
152
+ content: /*#__PURE__*/React.createElement(MarkdownComponent, {
153
+ content: msg.content
154
+ }),
155
+ avatar: msg.role === 'assistant' ? avatar : null,
156
+ placement: msg.role === 'user' ? 'end' : 'start'
157
+ });
158
+ }), loading && /*#__PURE__*/React.createElement(Bubble, {
159
+ placement: "start",
160
+ avatar: avatar,
161
+ loading: loading
162
+ })), /*#__PURE__*/React.createElement("div", null, !props.simple && /*#__PURE__*/React.createElement("div", {
163
+ className: styles.newButtonContainer
164
+ }, /*#__PURE__*/React.createElement("button", {
165
+ type: "button",
166
+ onClick: function onClick() {
167
+ return history.push('/');
168
+ },
169
+ className: styles.newButton
170
+ }, /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(PlusSquareOutlined, null), "\u5F00\u59CB\u65B0\u5BF9\u8BDD"))), /*#__PURE__*/React.createElement(PromptTextarea, {
171
+ size: "compact",
172
+ mode: "implement",
173
+ value: promptText,
174
+ onChange: setPromptText,
175
+ loading: loading,
176
+ onCancel: function onCancel() {
177
+ setIsStreaming(false);
178
+ setLoading(false);
179
+ },
180
+ showAction: !props.simple,
181
+ style: {
182
+ marginBottom: 0
183
+ },
184
+ onConfirm: handleSubmit
185
+ })));
186
+ }
187
+ export default MsgBox;
@@ -0,0 +1,42 @@
1
+ .msg {
2
+ display: flex;
3
+ justify-content: flex-end;
4
+ }
5
+
6
+ .query {
7
+ background: #c9dfff;
8
+ box-shadow: 0 4px 10px rgba(51, 113, 242, .1);
9
+ border-radius: 8px;
10
+ padding: 8px 16px;
11
+ max-width: calc(100% - 100px);
12
+ word-break: break-all;
13
+ font-size: 14px;
14
+ line-height: 26px;
15
+ font-weight: 400;
16
+ color: #1d2129;
17
+ }
18
+
19
+ .newButton {
20
+ display: inline-flex;
21
+ align-items: center;
22
+ cursor: pointer;
23
+ border: none;
24
+ outline: none;
25
+ height: 30px;
26
+ padding: 0 8px;
27
+ color: var(--primary-color);
28
+ font-size: 14px;
29
+ background: rgba(135, 59, 244, .145);
30
+ border-radius: 6px;
31
+ line-height: 22px;
32
+ margin: 12px auto;
33
+ }
34
+
35
+ .newButtonContainer {
36
+ display: flex;
37
+ }
38
+
39
+ .chatContainer {
40
+ height: 100%;
41
+ overflow: auto;
42
+ }
@@ -0,0 +1,25 @@
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); }
5
+ import React from 'react';
6
+ import styles from "./index.module.less";
7
+ import { ConversationsMenu } from "../ConversationsMenu";
8
+ import { AIChatStore } from "../../../../model/AIChat";
9
+ import { useSnapshot } from "valtio";
10
+ import classnames from "classnames";
11
+ function SessionLayout(props) {
12
+ var children = props.children;
13
+ var snap = useSnapshot(AIChatStore);
14
+ if (!Array.isArray(children)) {
15
+ return null;
16
+ }
17
+ return /*#__PURE__*/React.createElement("div", {
18
+ className: styles.container
19
+ }, /*#__PURE__*/React.createElement(ConversationsMenu, null), /*#__PURE__*/React.createElement("div", {
20
+ className: classnames(styles.msgBox, _defineProperty(_defineProperty({}, styles.msgBoxHalf, snap.codeBlock), styles.msgBoxFull, !snap.codeBlock))
21
+ }, children[0]), snap.codeBlock && /*#__PURE__*/React.createElement("div", {
22
+ className: styles.taskBox
23
+ }, children[1]));
24
+ }
25
+ export { SessionLayout };
@@ -0,0 +1,34 @@
1
+ .container {
2
+ display: flex;
3
+ gap: 12px;
4
+ background: #f6f7fb;
5
+ height: calc(100vh - 64px);
6
+ padding: 0;
7
+ }
8
+
9
+ .msgBox, .taskBox{
10
+ box-shadow: 0 2px 7px #e0e0e080;
11
+ border-radius: 12px;
12
+ display: flex;
13
+ flex-direction: column;
14
+ }
15
+
16
+ .msgBox {
17
+ padding: 16px;
18
+ min-width: 400px;
19
+ justify-content: space-between;
20
+ }
21
+
22
+ .msgBoxHalf {
23
+ max-width: 30vw;
24
+ }
25
+
26
+ .msgBoxFull {
27
+ width: 100%;
28
+ }
29
+
30
+ .taskBox {
31
+ margin: 16px;
32
+ flex-grow: 1;
33
+ background: #ffffff;
34
+ }
@@ -0,0 +1,110 @@
1
+ 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
+ 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
+ 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; }
4
+ /**
5
+ * 从代码字符串中提取依赖,并生成 package.json 的 dependencies 对象。
6
+ *
7
+ * @param {string} codeString 包含代码的字符串。
8
+ * @returns {object} 一个符合 package.json dependencies 格式的对象。
9
+ */
10
+ export function generateDependencies(codeString) {
11
+ // 1. 初始化固定的依赖
12
+ var dependencies = {};
13
+
14
+ // 2. 定义正则表达式来匹配 import 语句的来源
15
+ // 这个正则表达式可以处理以下情况:
16
+ // - import defaultExport from 'package-name';
17
+ // - import { namedExport } from 'package-name';
18
+ // - import * as name from 'package-name';
19
+ // - import 'package-name'; (用于副作用)
20
+ // - import defaultExport from '@scoped/package-name/sub-path';
21
+ //
22
+ // 解析:
23
+ // - `import(?:.*from)?` : 匹配 "import" 关键字,以及可选的 "... from" 部分。
24
+ // - `\s+` : 匹配一个或多个空格。
25
+ // - `['"]` : 匹配单引号或双引号。
26
+ // - `([^'"]+)` : 核心捕获组。匹配引号内的所有字符,这就是我们需要的包路径。
27
+ // - `['"]` : 匹配结束的引号。
28
+ // - `/g` : 全局匹配,查找所有符合条件的导入。
29
+ var importRegex = /import(?:.*from)?\s+['"]([^'"]+)['"]/g;
30
+
31
+ // 使用 Set 来存储找到的包,可以自动去重
32
+ var foundPackages = new Set();
33
+
34
+ // 3. 遍历所有匹配项
35
+ var match;
36
+ while ((match = importRegex.exec(codeString)) !== null) {
37
+ // 捕获组 match[1] 包含了完整的导入路径,例如 '@antv/g2' 或 'react-dom/client'
38
+ var importPath = match[1];
39
+
40
+ // 4. 过滤掉相对路径和绝对路径
41
+ if (importPath.startsWith('.') || importPath.startsWith('/')) {
42
+ continue;
43
+ }
44
+
45
+ // 5. 提取根包名
46
+ // 这可以处理像 'react-dom/client' 这样的深层导入,我们只需要 'react-dom'
47
+ // 或者像 '@antv/g2/es/chart',我们只需要 '@antv/g2'
48
+ var rootPackage = void 0;
49
+ var pathParts = importPath.split('/');
50
+ if (importPath.startsWith('@')) {
51
+ // 对于作用域包 (scoped package),例如 @antv/g2,根包名是前两部分
52
+ rootPackage = "".concat(pathParts[0], "/").concat(pathParts[1]);
53
+ } else {
54
+ // 对于普通包,根包名是第一部分
55
+ rootPackage = pathParts[0];
56
+ }
57
+ foundPackages.add(rootPackage);
58
+ }
59
+
60
+ // 6. 将找到的包添加到最终的依赖对象中
61
+ var _iterator = _createForOfIteratorHelper(foundPackages),
62
+ _step;
63
+ try {
64
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
65
+ var pkg = _step.value;
66
+ // 如果不是固定的依赖,就添加并设置为 'latest'
67
+ if (!Object.prototype.hasOwnProperty.call(dependencies, pkg)) {
68
+ dependencies[pkg] = "latest";
69
+ }
70
+ }
71
+ } catch (err) {
72
+ _iterator.e(err);
73
+ } finally {
74
+ _iterator.f();
75
+ }
76
+ return dependencies;
77
+ }
78
+ export function wrap2VisionSnap() {
79
+ var codeBlock = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
80
+ return {
81
+ modules: {
82
+ '/package.json': {
83
+ fpath: '/package.json',
84
+ code: "{\n \"name\": \"AntV-master\",\n \"version\": \"1.0.0\",\n \"main\": \"/src/index.jsx\",\n \"dependencies\": ".concat(JSON.stringify(generateDependencies(codeBlock), null, 2), "\n}")
85
+ },
86
+ '/src/index.jsx': {
87
+ fpath: '/src/index.jsx',
88
+ code: codeBlock
89
+ }
90
+ }
91
+ };
92
+ }
93
+ export function wrap2Sandpack() {
94
+ var codeBlock = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
95
+ // const regex = /^```[\w-]*\n([\s\S]*?)\n?```$/m;
96
+ // const match = codeBlock.match(regex);
97
+ // if (match) {
98
+ return {
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 }")
101
+ },
102
+ "/index.js": {
103
+ // 入口文件是纯 JS
104
+ code: codeBlock
105
+ },
106
+ "/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>"
108
+ }
109
+ };
110
+ }
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import { Sandpack } from "@codesandbox/sandpack-react";
3
+ import styles from "./index.module.less";
4
+ import { AIChatStore } from "../../../../model/AIChat";
5
+ import { useSnapshot } from "valtio";
6
+ import { wrap2Sandpack } from "./generateCode";
7
+ // import {code} from "../../demo";
8
+ // import {requestProxy, useVisionsnapSdk} from "../../../../hooks/useVisionsnapSdk";
9
+
10
+ function TaskBox() {
11
+ var snap = useSnapshot(AIChatStore);
12
+
13
+ // const { sdk, loading } = useVisionsnapSdk('3.2.4');
14
+ //
15
+ // if (loading) {
16
+ // return <div>Loading...</div>;
17
+ // }
18
+ //
19
+ // return (
20
+ // <sdk.VisionPreview id="visionIframe"
21
+ // bizCode="vision-preview-demo"
22
+ // style={{ height: '100vh' }}
23
+ // userId="263347"
24
+ // displayMode="preview-only"
25
+ // editable={false}
26
+ // code={code}
27
+ // // requestProxy={requestProxy}
28
+ // isStreaming={false} />
29
+ // );
30
+
31
+ return /*#__PURE__*/React.createElement(Sandpack, {
32
+ template: "vanilla" // 指定项目模板,Sandpack 会据此配置环境
33
+ ,
34
+ files: wrap2Sandpack(snap.codeBlock),
35
+ options: {
36
+ showLineNumbers: true,
37
+ // 显示行号
38
+ showTabs: true,
39
+ closableTabs: false,
40
+ editorHeight: 'calc(100vh - 150px)',
41
+ rtl: true,
42
+ classes: {
43
+ 'sp-layout': styles['antv-sp-layout']
44
+ }
45
+ },
46
+ theme: "light" // 主题:dark, light, auto
47
+ ,
48
+ customSetup: {
49
+ npmRegistries: [{
50
+ limitToScopes: false,
51
+ // 设为 false 使所有包都从自定义 registry 获取
52
+ registryUrl: 'https://registry.npmmirror.com',
53
+ // 使用淘宝镜像
54
+ enabledScopes: [],
55
+ proxyEnabled: false
56
+ }]
57
+ }
58
+ });
59
+ }
60
+ export default TaskBox;
@@ -0,0 +1,8 @@
1
+ div.antv-sp-layout {
2
+ border: unset;
3
+ :global {
4
+ .sp-c-hluGOI:has(button:focus) {
5
+ outline: none !important;
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,34 @@
1
+ export var projectFiles = {
2
+ "/package.json": {
3
+ code: "{\n \"name\": \"antv-g2-example\",\n \"version\": \"1.0.0\",\n \"main\": \"/index.js\",\n \"dependencies\": {\n \"@antv/g2\": \"^5\"\n }\n }"
4
+ },
5
+ "/index.js": {
6
+ // 入口文件是纯 JS
7
+ code: "import { Chart } from '@antv/g2';\n\n const chart = new Chart({\n container: 'root',\n });\n\n chart.options({\n type: 'interval',\n autoFit: true,\n data: [\n { grade: '\u4E00\u5E74\u7EA7', count: 200 },\n { grade: '\u4E8C\u5E74\u7EA7', count: 250 },\n { grade: '\u4E09\u5E74\u7EA7', count: 300 },\n { grade: '\u56DB\u5E74\u7EA7', count: 350 },\n ],\n encode: { x: 'grade', y: 'count' },\n });\n\n chart.render();\n "
8
+ },
9
+ "/index.html": {
10
+ 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>"
11
+ }
12
+ };
13
+ export var code = {
14
+ modules: {
15
+ // package.json 文件是必须要的,其中 name, version, main, dependencies 必填
16
+ '/package.json': {
17
+ fpath: '/package.json',
18
+ code: "{\n \"name\": \"dark-card-app\",\n \"version\": \"1.0.0\",\n \"private\": true,\n \"dependencies\": {\n \"@ant-design/icons\": \"^5.2.6\",\n \"@alipay/bigfish\": \"^4.3.0\"\n },\n\"main\": \"src/index.jsx\"\n}\n"
19
+ },
20
+ // 入口文件默认是 /src/index.tsx,也可以配合 package.json main 字段指定其他入口
21
+ '/src/index.jsx': {
22
+ fpath: '/src/index.jsx',
23
+ code: "import React from '@alipay/bigfish/react';\n import ReactDOM from '@alipay/bigfish/react-dom';\nimport { ConfigProvider, theme } from '@alipay/bigfish/antd';\nimport App from './App';\nReactDOM.createRoot(document.getElementById('root')).render(\n <React.StrictMode>\n <ConfigProvider\n theme={{\n algorithm: theme.darkAlgorithm,\n token: {\n colorBgContainer: '#141414',\n colorBorderSecondary: '#303030',\n }\n }}\n >\n <App />\n </ConfigProvider>\n </React.StrictMode>\n);\n"
24
+ },
25
+ '/src/App.jsx': {
26
+ fpath: '/src/App.jsx',
27
+ code: "import React from '@alipay/bigfish/react';\nimport { Card, Avatar, Typography, Space } from '@alipay/bigfish/antd';\nimport { UserOutlined, ClockCircleOutlined, HeartOutlined, MessageOutlined } from '@ant-design/icons';\nimport './App.less';\nimport {styled} from '@alipay/bigfish';\nconst Title = styled.div`\n color: palevioletred;\n`;\n\nconst { Text } = Typography;\n\nconst DarkCard = () => {\n return (\n <div className=\"dark-card-container\">\n <Card\n className=\"dark-card\"\n cover={\n <div className=\"card-cover\">\n <div className=\"cover-image-placeholder\" />\n </div>\n }\n actions={[\n <Space key=\"time\">\n <ClockCircleOutlined />\n <Text className=\"action-text\">2 hours ago</Text>\n </Space>,\n <Space key=\"likes\">\n <HeartOutlined />\n <Text className=\"action-text\">128</Text>\n </Space>,\n <Space key=\"comments\">\n <MessageOutlined />\n <Text className=\"action-text\">24</Text>\n </Space>\n ]}\n >\n <Card.Meta\n avatar={<Avatar size={40} icon={<UserOutlined />} />}\n title={<Title>Dark Theme Card</Title>}\n description={\n <Text className=\"card-description\">\n This is a dark themed card with modern design elements.\n Perfect for displaying content in low-light interfaces.\n </Text>\n }\n />\n </Card>\n </div>\n );\n};\n\nexport default DarkCard;\n"
28
+ },
29
+ '/src/App.less': {
30
+ fpath: '/src/App.less',
31
+ code: ".dark-card-container {\n display: flex;\n justify-content: center;\n align-items: center;\n min-height: 100vh;\n background-color: #0a0a0a;\n padding: 20px;\n}\n\n.dark-card {\n width: 100%;\n max-width: 400px;\n border-radius: 12px;\n overflow: hidden;\n box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);\n\n .ant-card-head {\n border-bottom: 1px solid #303030;\n }\n\n .ant-card-actions {\n background: #1a1a1a;\n border-top: 1px solid #303030;\n\n > li {\n border-right: 1px solid #303030 !important;\n }\n }\n}\n\n.card-cover {\n height: 200px;\n background: linear-gradient(135deg, #2c2c2c, #1a1a1a);\n position: relative;\n overflow: hidden;\n\n .cover-image-placeholder {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background:\n radial-gradient(circle at center, #3a3a3a 0%, #1f1f1f 100%);\n }\n}\n\n.card-description {\n color: rgba(255, 255, 255, 0.65) !important;\n}\n\n.action-text {\n color: rgba(255, 255, 255, 0.45) !important;\n font-size: 12px;\n}\n"
32
+ }
33
+ }
34
+ };
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { SessionLayout } from "./components/SessionLayout";
3
+ import MsgBox from "./components/MsgBox";
4
+ import TaskBox from "./components/TaskBox";
5
+ import Header from "dumi/theme/slots/Header";
6
+ function AIPlayground() {
7
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Header, null), /*#__PURE__*/React.createElement(SessionLayout, null, /*#__PURE__*/React.createElement(MsgBox, null), /*#__PURE__*/React.createElement(TaskBox, null)));
8
+ }
9
+ export default AIPlayground;
File without changes
@@ -232,10 +232,10 @@
232
232
  }
233
233
 
234
234
  .content {
235
- .contentReset;
235
+ .contentReset();
236
236
 
237
237
  > div {
238
- .contentReset;
238
+ .contentReset();
239
239
  }
240
240
  }
241
241
  }
@@ -9,7 +9,7 @@
9
9
  background: rgba(250, 251, 252, 1);
10
10
 
11
11
  .slider {
12
- .container1440;
12
+ .container1440();
13
13
  }
14
14
 
15
15
  .appWrapper {
@@ -13,7 +13,7 @@
13
13
  height: 100%;
14
14
  margin-bottom: 5%;
15
15
  position: relative;
16
- .container1440;
16
+ .container1440();
17
17
  padding-left: 4.5%;
18
18
  }
19
19
 
@@ -16,7 +16,7 @@
16
16
  height: 100%;
17
17
  margin-left: 4.2%;
18
18
  position: relative;
19
- .container1440;
19
+ .container1440();
20
20
  }
21
21
 
22
22
  .title {
@@ -11,7 +11,7 @@ import CommonHelmet from "../../common/CommonHelmet";
11
11
  import { ic } from "../../slots/hooks";
12
12
  import { Cases } from "./components/Cases";
13
13
  import { Companies } from "./components/Companies";
14
- import { Detail } from "./components/Detail";
14
+ import { Detail } from "dumi/theme/slots/Detail";
15
15
  import { Features } from "./components/Features";
16
16
  var Index = function Index() {
17
17
  var _useSiteData = useSiteData(),
@@ -47,12 +47,14 @@ var MOCK_META = { frontmatter: { title: "mock-meta" }, texts: [], toc: [] };
47
47
  var plugin_default = (api) => {
48
48
  api.describe({ key: `dumi-theme:${require("../../package.json").name}` });
49
49
  api.chainWebpack((config) => {
50
- config.plugin("critters").use(import_critters_webpack_plugin.default, [
51
- {
52
- preload: "js-lazy",
53
- inlineThreshold: 10240
54
- }
55
- ]);
50
+ if (api.env === "production") {
51
+ config.plugin("critters").use(import_critters_webpack_plugin.default, [
52
+ {
53
+ preload: "js-lazy",
54
+ inlineThreshold: 10240
55
+ }
56
+ ]);
57
+ }
56
58
  });
57
59
  api.modifyDefaultConfig((memo) => {
58
60
  memo.resolve.codeBlockMode = "passive";
@@ -163,6 +165,12 @@ export default function ThemeAntVContextWrapper() {
163
165
  absPath: "/:language/examples/:topic/:example",
164
166
  path: ":language/examples/:topic/:example",
165
167
  file: `${PAGES_DIR}/Example`
168
+ },
169
+ {
170
+ id: "dumi-theme-antv-ai-playground-lang",
171
+ absPath: "/:language/ai-playground/:id",
172
+ path: ":language/ai-playground/:id",
173
+ file: `${PAGES_DIR}/AIPlayground`
166
174
  }
167
175
  ];
168
176
  extraRoutesList.forEach((itemRoute) => {
@@ -9,7 +9,7 @@
9
9
  overflow: hidden;
10
10
 
11
11
  .content {
12
- .container1440;
12
+ .container1440();
13
13
  height: 100%;
14
14
  position: relative;
15
15
  }
@@ -42,7 +42,8 @@ export var Toolbar = function Toolbar(_ref) {
42
42
  onEditorTabChange = _ref.onEditorTabChange,
43
43
  _ref$onToggleFullscre = _ref.onToggleFullscreen,
44
44
  onToggleFullscreen = _ref$onToggleFullscre === void 0 ? null : _ref$onToggleFullscre,
45
- onExecuteCode = _ref.onExecuteCode;
45
+ onExecuteCode = _ref.onExecuteCode,
46
+ onClickAI = _ref.onClickAI;
46
47
  var locale = useLocale();
47
48
  var exampleTitle = _typeof(title) === 'object' ? title[locale.id] : title;
48
49
 
@@ -78,7 +79,10 @@ export var Toolbar = function Toolbar(_ref) {
78
79
  return onEditorTabChange(tab);
79
80
  }
80
81
  }, tab, " ", slot && slot);
81
- })), riddleVisible ? /*#__PURE__*/React.createElement("form", {
82
+ })), /*#__PURE__*/React.createElement("a", {
83
+ className: styles.ai,
84
+ onClick: onClickAI
85
+ }, "AI \u52A9\u624B"), riddleVisible ? /*#__PURE__*/React.createElement("form", {
82
86
  action: "//riddle.alibaba-inc.com/riddles/define",
83
87
  method: "POST",
84
88
  target: "_blank"
@@ -80,3 +80,9 @@
80
80
  }
81
81
  }
82
82
  }
83
+
84
+
85
+ .ai {
86
+ margin-right: 10px;
87
+ font-size: 12px;
88
+ }