-
Notifications
You must be signed in to change notification settings - Fork 138
/
codesandbox.ts
185 lines (166 loc) · 4.13 KB
/
codesandbox.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { getParameters } from 'codesandbox/lib/api/define'
export const getCsbParams = (code: string): string => {
return getParameters({
template: 'node',
files: {
'package.json': {
content: {
scripts: {
dev: 'vite',
},
dependencies: {
vue: 'next',
'@idux/components': 'latest',
'@idux/pro': 'latest',
'@idux/cdk': 'latest',
},
devDependencies: {
'@vitejs/plugin-vue': 'latest',
less: 'latest',
typescript: 'latest',
vite: 'latest',
},
},
isBinary: false,
},
'tsconfig.json': {
content: tsconfigJson,
isBinary: false,
},
'vite.config.ts': {
content: viteConfigTs,
isBinary: false,
},
'index.html': {
content: indexHtml,
isBinary: false,
},
'src/Demo.vue': {
content: decodeURIComponent(code),
isBinary: false,
},
'src/App.vue': {
content: appVue,
isBinary: false,
},
'src/main.ts': {
content: mainTs,
isBinary: false,
},
'src/idux.ts': {
content: iduxTs,
isBinary: false,
},
'src/env.d.ts': {
content: envDTs,
isBinary: false,
},
},
})
}
const indexHtml = `
<!DOCTYPE html>
<html>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>`
const mainTs = `
import { createApp } from 'vue';
import Idux from './idux';
import App from './App.vue';
createApp(App).use(Idux).mount('#app');`
const appVue = `
<template>
<IxDrawerProvider ref="drawerProviderRef">
<IxModalProvider ref="modalProviderRef">
<IxNotificationProvider>
<IxMessageProvider>
<Demo />
</IxMessageProvider>
</IxNotificationProvider>
</IxModalProvider>
</IxDrawerProvider>
</template>
<script>
import { defineComponent } from 'vue';
import Demo from './Demo.vue';
export default defineComponent({
components: {
Demo,
},
});
</script>
<style>
#app {
margin-top: 40px;
margin-left: 20px;
}
</style>`
const iduxTs = `
import { App } from 'vue';
import IduxCdk from '@idux/cdk';
import IduxComponents from '@idux/components';
import IduxPro from '@idux/pro';
import '@idux/components/default.css';
import '@idux/pro/default.css';
import { createGlobalConfig } from "@idux/components/config";
import {
IDUX_ICON_DEPENDENCIES,
addIconDefinitions
} from '@idux/components/icon';
// import { enUS } from "@idux/components/locales";
addIconDefinitions(IDUX_ICON_DEPENDENCIES);
const loadIconDynamically = (iconName: string) => {
return fetch(\`https://idux-cdn.sangfor.com.cn/icons/\${iconName}.svg\`).then((res) => res.text());
};
const globalConfig = createGlobalConfig({
// 默认为中文,可以打开注释设置为其他语言
// locale: enUS,
icon: { loadIconDynamically },
});
const install = (app: App): void => {
app.use(IduxCdk).use(IduxComponents).use(IduxPro).use(globalConfig);
};
export default { install };`
const envDTs = `
/// <reference types="vite/client" />
/// <reference types="@idux/cdk/types" />
/// <reference types="@idux/components/types" />
/// <reference types="@idux/pro/types" />
declare module '*.vue' {
import { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}`
const tsconfigJson = `
{
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"]
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}`
const viteConfigTs = `
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
additionalData: "@import '@idux/components/style/variable/index.less';",
},
},
},
})`