-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demo): add CodeSandbox integration
Added CodeSandbox integration to the PixiJSContainer component with separate functions for generating codesandbox parameters for a standalone Vue app and a component demo. Also updated the demo in the guide to use the PixiJSContainer component without an app.
- Loading branch information
Mr.Mao
committed
Jun 3, 2023
1 parent
6c9fa3f
commit 9f8a130
Showing
3 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
docs/.vitepress/theme/components/PixiJSContainer/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { getParameters } from 'codesandbox/lib/api/define' | ||
|
||
const indexHtml = `<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Naive UI Demo</title> | ||
<style> | ||
body { | ||
padding: 24px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> | ||
` | ||
|
||
const appVue = `<template> | ||
<demo /> | ||
</template> | ||
<script> | ||
import { defineComponent } from "vue"; | ||
import Demo from "./Demo.vue"; | ||
export default defineComponent({ | ||
components: { | ||
Demo, | ||
}, | ||
}); | ||
</script>` | ||
|
||
const appProviderVue = `<template> | ||
<Application :width="300" :height="300"> | ||
<demo /> | ||
</Application> | ||
</template> | ||
<script> | ||
import { defineComponent } from "vue"; | ||
import { Application } from 'vue3-pixi' | ||
import Demo from "./Demo.vue"; | ||
export default defineComponent({ | ||
components: { | ||
Demo, | ||
}, | ||
}); | ||
</script>` | ||
|
||
const mainJs = `import { createApp } from "vue"; | ||
import App from "./App.vue"; | ||
const app = createApp(App); | ||
app.mount("#app"); | ||
` | ||
|
||
function getDependencies(code: string) { | ||
return (code.match(/from '([^']+)'\n/g) || []) | ||
.map(v => v.slice(6, v.length - 2)) | ||
.reduce((prevV, dep) => { | ||
prevV[dep] = 'latest' | ||
return prevV | ||
}, {}) | ||
} | ||
|
||
export function getWithAppCodeSandboxParams(code: string) { | ||
return (getParameters as any)({ | ||
files: { | ||
'package.json': { | ||
content: { | ||
dependencies: { | ||
...getDependencies(code), | ||
'vue': 'next', | ||
'vue-router': 'next', | ||
'vue3-pixi': 'latest', | ||
}, | ||
devDependencies: { '@vue/cli-plugin-babel': '~4.5.0', 'typescript': '~4.6.3' }, | ||
}, | ||
}, | ||
'index.html': { content: indexHtml }, | ||
'src/Demo.vue': { content: code }, | ||
'src/App.vue': { content: appProviderVue }, | ||
'src/main.js': { content: mainJs }, | ||
}, | ||
}) | ||
} | ||
|
||
export function getCodeSandboxParams(code: string) { | ||
return (getParameters as any)({ | ||
files: { | ||
'package.json': { | ||
content: { | ||
dependencies: { | ||
...getDependencies(code), | ||
'vue': 'next', | ||
'vue-router': 'next', | ||
'vue3-pixi': 'latest', | ||
}, | ||
devDependencies: { '@vue/cli-plugin-babel': '~4.5.0', 'typescript': '~4.6.3' }, | ||
}, | ||
}, | ||
'index.html': { content: indexHtml }, | ||
'src/Demo.vue': { content: code }, | ||
'src/App.vue': { content: appVue }, | ||
'src/main.js': { content: mainJs }, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
<demo src="./demo/basic.vue" :app="false" /> |