mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 18:01:24 +08:00
d28d0701d7
* docs: remove unused code * refactor(docs): improve code
39 lines
797 B
TypeScript
39 lines
797 B
TypeScript
import { utoa } from '../utils'
|
|
|
|
const scriptRe = /<script[^>]*>([\s\S]*)<\/script>/
|
|
|
|
const MAIN_FILE_NAME = 'App.vue'
|
|
const SETUP_CODE = `import { setupElementPlus } from './element-plus.js'
|
|
setupElementPlus()`
|
|
|
|
export const usePlayGround = (source: string) => {
|
|
const decodeCode = decodeURIComponent(source)
|
|
const result = decodeCode.match(scriptRe)
|
|
let code: string
|
|
if (result) {
|
|
code = decodeCode.replace(
|
|
scriptRe,
|
|
`<script lang="ts" setup>
|
|
${SETUP_CODE}
|
|
$1
|
|
</script>`
|
|
)
|
|
} else {
|
|
code = `${decodeCode}
|
|
<script lang="ts" setup>
|
|
${SETUP_CODE}
|
|
</script>
|
|
`
|
|
}
|
|
const originCode = {
|
|
[MAIN_FILE_NAME]: code,
|
|
}
|
|
|
|
const encoded = utoa(JSON.stringify(originCode))
|
|
const link = `https://element-plus.run/#${encoded}`
|
|
return {
|
|
encoded,
|
|
link,
|
|
}
|
|
}
|