@antv/dumi-theme-antv 0.8.0-beta.17 → 0.8.0-beta.19
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.
- package/dist/hooks/useProducts.js +1 -3
- package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +3 -3
- package/dist/pages/AIPlayground/components/TaskBox/generateCode.js +70 -39
- package/dist/pages/AIPlayground/components/TaskBox/index.js +4 -4
- package/dist/slots/CodeEditor/Toolbar.js +2 -22
- package/dist/slots/CodeEditor/utils.js +2 -1
- package/package.json +3 -3
|
@@ -31,10 +31,8 @@ export function useAntVConfig() {
|
|
|
31
31
|
return useQuery({
|
|
32
32
|
queryKey: ['antv-config'],
|
|
33
33
|
queryFn: getAntVConfig,
|
|
34
|
-
staleTime: 24 * 60 * 60 * 1000,
|
|
35
|
-
// 一天内数据不会被认为是 "stale",不会触发后台刷新
|
|
36
34
|
initialData: {
|
|
37
|
-
"VisionSnapVersion": "3.4.
|
|
35
|
+
"VisionSnapVersion": "3.4.11",
|
|
38
36
|
"library": ["G2", "F2", "G6"]
|
|
39
37
|
}
|
|
40
38
|
});
|
|
@@ -6,7 +6,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
9
|
-
import {
|
|
9
|
+
import { oneLight } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
|
10
10
|
import { AIChatStore } from "../../../../model/AIChat";
|
|
11
11
|
import { useCopyToClipboard } from 'react-use';
|
|
12
12
|
import { CheckOutlined, CopyOutlined, PlaySquareOutlined } from '@ant-design/icons';
|
|
@@ -83,8 +83,8 @@ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
|
|
|
83
83
|
id: 'ai.markdown.run'
|
|
84
84
|
})
|
|
85
85
|
}, /*#__PURE__*/React.createElement(PlaySquareOutlined, null)))), /*#__PURE__*/React.createElement(SyntaxHighlighter, {
|
|
86
|
-
style:
|
|
87
|
-
language: language,
|
|
86
|
+
style: oneLight,
|
|
87
|
+
language: language === 'vue' ? 'html' : language,
|
|
88
88
|
PreTag: "div" // 使用 div 作为外层标签,避免 pre 标签的默认样式冲突
|
|
89
89
|
,
|
|
90
90
|
showLineNumbers: false // (可选) 显示行号
|
|
@@ -1,4 +1,6 @@
|
|
|
1
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2
4
|
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
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
4
6
|
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); }
|
|
@@ -11,7 +13,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
11
13
|
* @param {string} codeString 包含代码的字符串。
|
|
12
14
|
* @returns {object} 一个符合 package.json dependencies 格式的对象。
|
|
13
15
|
*/
|
|
14
|
-
export function generateDependencies(
|
|
16
|
+
export function generateDependencies() {
|
|
17
|
+
var codeString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
18
|
+
var ext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'js';
|
|
15
19
|
// 1. 初始化固定的依赖
|
|
16
20
|
var dependencies = {};
|
|
17
21
|
|
|
@@ -73,73 +77,99 @@ export function generateDependencies(codeString) {
|
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
//
|
|
80
|
+
// VisionSnap限制只要是jsx就必须装React。
|
|
77
81
|
} catch (err) {
|
|
78
82
|
_iterator.e(err);
|
|
79
83
|
} finally {
|
|
80
84
|
_iterator.f();
|
|
81
85
|
}
|
|
82
|
-
if (
|
|
86
|
+
if (ext === 'jsx' || ext === 'tsx') {
|
|
83
87
|
dependencies["react"] = "^18";
|
|
84
88
|
dependencies["react-dom"] = "^18";
|
|
85
89
|
}
|
|
90
|
+
if (ext === 'vue') {
|
|
91
|
+
dependencies["vue"] = "^3";
|
|
92
|
+
}
|
|
93
|
+
if (dependencies['@antv/s2'] || dependencies['@antv/s2-react'] || dependencies['@antv/s2-react-components']) {
|
|
94
|
+
dependencies = _objectSpread(_objectSpread({}, dependencies), {}, {
|
|
95
|
+
"@ant-design/icons": "^6.1.0",
|
|
96
|
+
"@antv/s2": "^2.4.9",
|
|
97
|
+
"@antv/s2-react": "^2.2.3",
|
|
98
|
+
"@antv/s2-react-components": "^2.1.2",
|
|
99
|
+
"antd": "^5.27.6",
|
|
100
|
+
"insert-css": "^2.0.0",
|
|
101
|
+
"react": "^18.3.1",
|
|
102
|
+
"react-color": "^2.19.3",
|
|
103
|
+
"react-dom": "^18.3.1",
|
|
104
|
+
"@antv/g2": "^5.4.2"
|
|
105
|
+
});
|
|
106
|
+
}
|
|
86
107
|
return dependencies;
|
|
87
108
|
}
|
|
88
109
|
|
|
89
110
|
/**
|
|
90
111
|
* 基于代码内容,启发式地判断其最合适的文件扩展名。
|
|
91
112
|
* @param {string} code - 要分析的前端代码字符串。
|
|
92
|
-
* @returns {'tsx' | 'jsx' | 'ts' | 'js'} - 推断出的文件扩展名(不含点)。
|
|
113
|
+
* @returns {'vue' | 'tsx' | 'jsx' | 'ts' | 'js'} - 推断出的文件扩展名(不含点)。
|
|
93
114
|
*/
|
|
94
115
|
export function getLanguageExtension(code) {
|
|
95
116
|
// --- 特征检测函数 ---
|
|
96
117
|
|
|
97
118
|
/**
|
|
98
|
-
* 检查代码是否包含
|
|
99
|
-
*
|
|
100
|
-
* - 匹配 <div...>, <MyComponent...>, </tag>, <Component/>, <>
|
|
119
|
+
* 检查代码是否包含 Vue 单文件组件 (SFC) 的特征。
|
|
120
|
+
* 这是最优先的检查,因为Vue的SFC结构非常独特。
|
|
101
121
|
*/
|
|
102
|
-
var
|
|
103
|
-
// 1
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return jsxRegex.test(text);
|
|
110
|
-
};
|
|
122
|
+
var containsVue = function containsVue(text) {
|
|
123
|
+
// 检查点 1: Vue 3 <script setup> 语法(最强信号)
|
|
124
|
+
// 匹配 <script setup> 或 <script lang="ts" setup>
|
|
125
|
+
var scriptSetupRegex = /<script\s+(?:lang="ts"\s+)?setup>/;
|
|
126
|
+
if (scriptSetupRegex.test(text)) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
111
129
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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)) {
|
|
130
|
+
// 检查点 2: 顶层 <template> 块(非常强的信号)
|
|
131
|
+
// 使用 'm' (multiline) 标志,'^' 匹配每行的开头。
|
|
132
|
+
var templateRegex = /^\s*<template.*>/m;
|
|
133
|
+
if (templateRegex.test(text)) {
|
|
121
134
|
return true;
|
|
122
135
|
}
|
|
123
136
|
|
|
124
|
-
// 检查点
|
|
125
|
-
// 匹配
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (typeAnnotationRegex.test(text)) {
|
|
137
|
+
// 检查点 3: 导入 Vue 核心库(通用信号)
|
|
138
|
+
// 匹配 import ... from 'vue'
|
|
139
|
+
var vueImportRegex = /import\s+.*?\s+from\s*['"]vue['"]/;
|
|
140
|
+
if (vueImportRegex.test(text)) {
|
|
129
141
|
return true;
|
|
130
142
|
}
|
|
131
143
|
|
|
132
|
-
// 检查点
|
|
133
|
-
// 匹配
|
|
134
|
-
var
|
|
135
|
-
if (
|
|
144
|
+
// 检查点 4: Vue 2 Options API 特征(辅助信号)
|
|
145
|
+
// 匹配 export default { ... data|methods|computed ... } 结构
|
|
146
|
+
var optionsApiRegex = /\bexport\s+default\s*{[\s\S]*?\b(data|methods|computed|watch)\b/;
|
|
147
|
+
if (optionsApiRegex.test(text)) {
|
|
136
148
|
return true;
|
|
137
149
|
}
|
|
138
150
|
return false;
|
|
139
151
|
};
|
|
152
|
+
var containsJsx = function containsJsx(text) {
|
|
153
|
+
var jsxRegex = /<(?![\s!=])([a-zA-Z][a-zA-Z0-9-]*|\/|)/;
|
|
154
|
+
return jsxRegex.test(text);
|
|
155
|
+
};
|
|
156
|
+
var containsTypeScript = function containsTypeScript(text) {
|
|
157
|
+
var typeDefinitionRegex = /\b(interface|type)\s+[A-Z][a-zA-Z0-9]*\b/;
|
|
158
|
+
if (typeDefinitionRegex.test(text)) return true;
|
|
159
|
+
var typeAnnotationRegex = /:\s*([A-Z][a-zA-Z0-9<>.]*|string|number|boolean|any\[?\]?)/;
|
|
160
|
+
if (typeAnnotationRegex.test(text)) return true;
|
|
161
|
+
var tsKeywordsRegex = /\b(as|implements|private|public|protected|readonly)\s+[a-zA-Z]/;
|
|
162
|
+
if (tsKeywordsRegex.test(text)) return true;
|
|
163
|
+
return false;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// --- 决策逻辑(Vue优先) ---
|
|
140
167
|
|
|
141
|
-
|
|
168
|
+
if (containsVue(code)) {
|
|
169
|
+
return 'vue';
|
|
170
|
+
}
|
|
142
171
|
|
|
172
|
+
// 如果不是Vue,则回退到原有的React/JS逻辑
|
|
143
173
|
if (containsJsx(code)) {
|
|
144
174
|
if (containsTypeScript(code)) {
|
|
145
175
|
return 'tsx';
|
|
@@ -155,9 +185,9 @@ export function getLanguageExtension(code) {
|
|
|
155
185
|
export function wrap2VisionSnap() {
|
|
156
186
|
var codeBlock = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
157
187
|
var ext = getLanguageExtension(codeBlock);
|
|
158
|
-
var mainFile = "/src/index.".concat(ext);
|
|
188
|
+
var mainFile = ext === 'vue' ? "/src/index.js" : "/src/index.".concat(ext);
|
|
159
189
|
var appFile = "/src/App.".concat(ext);
|
|
160
|
-
var dependencies = generateDependencies(codeBlock);
|
|
190
|
+
var dependencies = generateDependencies(codeBlock, ext);
|
|
161
191
|
var rootElementType = dependencies['@antv/f2'] ? 'canvas' : 'div';
|
|
162
192
|
var dependenciesJSON = {
|
|
163
193
|
"name": "AntV-adapted-project",
|
|
@@ -165,6 +195,7 @@ export function wrap2VisionSnap() {
|
|
|
165
195
|
"main": mainFile,
|
|
166
196
|
"dependencies": dependencies
|
|
167
197
|
};
|
|
198
|
+
var mainFileCode = ext === 'vue' ? "import { createApp } from 'vue';\nimport App from './App.vue';\n\nconst app = createApp(App);\napp.mount('#app');\n" : "\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 ");
|
|
168
199
|
return {
|
|
169
200
|
modules: _defineProperty(_defineProperty({
|
|
170
201
|
'/package.json': {
|
|
@@ -173,9 +204,9 @@ export function wrap2VisionSnap() {
|
|
|
173
204
|
}
|
|
174
205
|
}, mainFile, {
|
|
175
206
|
fpath: mainFile,
|
|
176
|
-
code:
|
|
207
|
+
code: mainFileCode
|
|
177
208
|
}), appFile, {
|
|
178
|
-
fpath:
|
|
209
|
+
fpath: appFile,
|
|
179
210
|
code: codeBlock
|
|
180
211
|
})
|
|
181
212
|
};
|
|
@@ -14,7 +14,7 @@ function TaskBox() {
|
|
|
14
14
|
var _useAntVConfig = useAntVConfig(),
|
|
15
15
|
_useAntVConfig$data = _useAntVConfig.data,
|
|
16
16
|
_useAntVConfig$data2 = _useAntVConfig$data === void 0 ? {
|
|
17
|
-
VisionSnapVersion: '3.4.
|
|
17
|
+
VisionSnapVersion: '3.4.11'
|
|
18
18
|
} : _useAntVConfig$data,
|
|
19
19
|
version = _useAntVConfig$data2.VisionSnapVersion;
|
|
20
20
|
var snap = useSnapshot(AIChatStore);
|
|
@@ -65,11 +65,11 @@ function TaskBox() {
|
|
|
65
65
|
FallbackComponent: ErrorFallback
|
|
66
66
|
}, /*#__PURE__*/React.createElement(sdk.VisionPreview, {
|
|
67
67
|
id: "visionIframe",
|
|
68
|
-
bizCode: "
|
|
68
|
+
bizCode: "antv",
|
|
69
69
|
style: {
|
|
70
70
|
height: '100vh'
|
|
71
71
|
},
|
|
72
|
-
userId: "
|
|
72
|
+
userId: "antv",
|
|
73
73
|
displayMode: "code-and-preview",
|
|
74
74
|
initialView: "preview",
|
|
75
75
|
theme: "light",
|
|
@@ -79,7 +79,7 @@ function TaskBox() {
|
|
|
79
79
|
proxyOptions: {
|
|
80
80
|
isWAN: true
|
|
81
81
|
},
|
|
82
|
-
src: "https://www.weavefox.cn/_visionsnap_render/index.html?version=".concat(version, "&enableInspector=1"),
|
|
82
|
+
src: "https://www.weavefox.cn/_visionsnap_render".concat(wrappedVisionSnapCode.modules["/package.json"].code.includes("vue") ? '_vue' : '', "/index.html?version=").concat(version, "&enableInspector=1"),
|
|
83
83
|
onEsmLoadFailed: handleEsmLoadFailed
|
|
84
84
|
}));
|
|
85
85
|
} else {
|
|
@@ -10,10 +10,9 @@ 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 {
|
|
13
|
+
import { PlayCircleOutlined, ReloadOutlined, ThunderboltOutlined } from '@ant-design/icons';
|
|
14
14
|
import stackblitzSdk from '@stackblitz/sdk';
|
|
15
15
|
import { Tooltip, Typography } from 'antd';
|
|
16
|
-
import { getParameters } from 'codesandbox/lib/api/define';
|
|
17
16
|
import { FormattedMessage, useLocale } from 'dumi';
|
|
18
17
|
import React, { useEffect, useState } from 'react';
|
|
19
18
|
import { ping } from "../utils";
|
|
@@ -119,26 +118,7 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
119
118
|
onClick: function onClick() {
|
|
120
119
|
stackblitzSdk.openProject(stackblitzPrefillConfig);
|
|
121
120
|
}
|
|
122
|
-
})), /*#__PURE__*/React.createElement(
|
|
123
|
-
title: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
124
|
-
id: "ai.toolbar.open.codesandbox"
|
|
125
|
-
})
|
|
126
|
-
}, /*#__PURE__*/React.createElement("form", {
|
|
127
|
-
action: "https://codesandbox.io/api/v1/sandboxes/define",
|
|
128
|
-
method: "POST",
|
|
129
|
-
target: "_blank"
|
|
130
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
131
|
-
type: "hidden",
|
|
132
|
-
name: "parameters",
|
|
133
|
-
value: getParameters(codeSandboxConfig)
|
|
134
|
-
}), /*#__PURE__*/React.createElement("button", {
|
|
135
|
-
type: "submit",
|
|
136
|
-
className: styles.codesandbox
|
|
137
|
-
}, /*#__PURE__*/React.createElement(CodeSandboxOutlined, {
|
|
138
|
-
style: {
|
|
139
|
-
marginLeft: 8
|
|
140
|
-
}
|
|
141
|
-
})))), /*#__PURE__*/React.createElement(Paragraph, {
|
|
121
|
+
})), /*#__PURE__*/React.createElement(Paragraph, {
|
|
142
122
|
copyable: {
|
|
143
123
|
text: sourceCode
|
|
144
124
|
},
|
|
@@ -75,7 +75,8 @@ export function getStackblitzConfig(title, sourceCode, fileExtension, deps, devD
|
|
|
75
75
|
return {
|
|
76
76
|
title: title || '',
|
|
77
77
|
description: '',
|
|
78
|
-
|
|
78
|
+
// https://developer.stackblitz.com/platform/api/javascript-sdk-options#projecttemplate
|
|
79
|
+
template: playground.template || 'typescript',
|
|
79
80
|
dependencies: deps,
|
|
80
81
|
files: _defineProperty(_defineProperty({}, "index.".concat(fileExtension.startsWith('ts') ? 'ts' : 'js'), sourceCode), 'index.html', playground.container || '<div id="container" />')
|
|
81
82
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/dumi-theme-antv",
|
|
3
|
-
"version": "0.8.0-beta.
|
|
3
|
+
"version": "0.8.0-beta.19",
|
|
4
4
|
"description": "AntV website theme based on dumi2.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dumi",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@docsearch/react": "^3.8.0",
|
|
67
67
|
"@emotion/server": "^11.11.0",
|
|
68
68
|
"@fingerprintjs/fingerprintjs": "^4.6.2",
|
|
69
|
-
"@monaco-editor/react": "
|
|
69
|
+
"@monaco-editor/react": "4.7.0",
|
|
70
70
|
"@petercatai/assistant": "^2.0.24",
|
|
71
71
|
"@stackblitz/sdk": "^1.11.0",
|
|
72
72
|
"@tanstack/react-query": "^5.90.2",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"lodash.merge": "^4.6.2",
|
|
97
97
|
"mini-css-extract-plugin": "^2.9.2",
|
|
98
98
|
"moment": "^2.30.1",
|
|
99
|
-
"monaco-editor": "
|
|
99
|
+
"monaco-editor": "0.51.0",
|
|
100
100
|
"nprogress": "^0.2.0",
|
|
101
101
|
"p-limit": "^3.1.0",
|
|
102
102
|
"parse-github-url": "^1.0.3",
|