Skip to content

Commit f621a1a

Browse files
authored
feat(mobile): support online preview of codesandbox (#755)
1 parent 1cd7702 commit f621a1a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed
File renamed without changes.

packages/site-components/src/components/td-ai-button/utils.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ let sdkInstance;
55
let isGeneratingDemo = false;
66
let regExp = {
77
vue: /```vue(?:\w+)?\s*([\s\S]*?)```/g,
8+
react: /```jsx(?:\w+)?\s*([\s\S]*?)```/g,
9+
'mobile-vue': /```vue(?:\w+)?\s*([\s\S]*?)```/g,
10+
'mobile-react': /```jsx(?:\w+)?\s*([\s\S]*?)```/g,
811
};
912

1013
let frameworkKeys = {
@@ -18,10 +21,11 @@ let frameworkKeys = {
1821
let promptForGenerateDemo = {
1922
react: '请为我生成 ${component} 组件 ${selectedText} 属性的使用示例',
2023
vue: '请为我生成 ${component} 组件的 ${selectedText} 属性的使用示例,采用 script setup 语法糖',
21-
miniprogram: '请按照微信原生小程序代码规范,为我生成 ${component} 组件的 ${selectedText} 属性的使用示例,输出完整可用的代码片段,包括 wxml、wxss(可选)、js(可选)、json(可选)等文件',
24+
miniprogram:
25+
'请按照微信原生小程序代码规范,为我生成 ${component} 组件的 ${selectedText} 属性的使用示例,输出完整可用的代码片段,包括 wxml、wxss(可选)、js(可选)、json(可选)等文件',
2226
'mobile-vue': '请为我生成 ${component} 组件的 ${selectedText} 属性的使用示例,采用 script setup 语法糖',
23-
'mobile-react': "请为我生成 ${component} 组件的 ${selectedText} 属性的使用示例"
24-
}
27+
'mobile-react': '请为我生成 ${component} 组件的 ${selectedText} 属性的使用示例',
28+
};
2529

2630
const generatePrompt = (framework, component, selectedText) => {
2731
const template = promptForGenerateDemo[framework];
@@ -141,11 +145,13 @@ const webChatInteraction = (framework, demoRequestBody) => {
141145
let match;
142146
while ((match = codeRegex.exec(payload.content)) !== null) {
143147
const code = match[1];
148+
const fileExtension = framework.includes('react') ? 'tsx' : 'vue';
149+
const fileName = `src/demo.${fileExtension}`;
144150
body = {
145151
...body,
146152
files: {
147153
...body.files,
148-
'src/demo.vue': {
154+
[fileName]: {
149155
content: code,
150156
},
151157
},
@@ -161,7 +167,7 @@ const webChatInteraction = (framework, demoRequestBody) => {
161167
})
162168
.then((x) => x.json())
163169
.then(({ sandbox_id: sandboxId }) => {
164-
window.open(`https://codesandbox.io/s/${sandboxId}?file=/src/demo.vue`);
170+
window.open(`https://codesandbox.io/s/${sandboxId}?file=/${fileName}`);
165171
});
166172
}
167173
});

0 commit comments

Comments
 (0)