-
Notifications
You must be signed in to change notification settings - Fork 199
feat: add a playground to easy test repl different scenarios #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zenHeart
wants to merge
7
commits into
vuejs:main
Choose a base branch
from
zenHeart:playground
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5e90b94
feat: add a playground to easy test repl different scenarios
zenHeart b6b2da5
fix: fix readme error
zenHeart 8dde63c
fix: support Repl props config
zenHeart 43fcf80
fix: remove unused import
zenHeart c5fd475
fix: add html case
zenHeart b7bcdb9
fix: add a VueUse demo
zenHeart a2910dd
fix: fix style reset margin
zenHeart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,84 @@ | ||
# Vue REPL Playground | ||
|
||
Optimize `test/main` to support dynamically adding scenario validations for the REPL. Use `npm run dev:playground` to try it out. | ||
|
||
## Playground Architecture | ||
|
||
### Directory Structure | ||
|
||
``` | ||
playground/ | ||
├── index.html # HTML entry file with scenario switcher | ||
├── vite.config.ts # Standalone Vite config | ||
├── vite-plugin-scenario.js # Parse scenarios directory and generate REPL configuration | ||
├── scenarios/ # Scenario directory, add dynamically | ||
│ ├── basic/ # Basic example | ||
│ ├── customMain/ # Custom main entry | ||
│ ├── html/ # html as entry example | ||
│ ├── pinia/ # Pinia state management example | ||
│ └── vueRouter/ # Vue Router example | ||
│ └── vueUse/ # Vue Use example | ||
└── src/ | ||
└── App.vue # Main application component | ||
``` | ||
|
||
### How It Works | ||
|
||
The playground uses a directory-based scenario system, where each scenario is an independent folder under `scenarios/`. Core features include: | ||
|
||
- **Virtual Module System**: A Vite plugin scans the scenario directory and generates a virtual module `virtual:playground-files` | ||
- **Dynamic Scenario Loading**: Users can switch scenarios via the UI, which automatically loads the corresponding configuration | ||
|
||
### Scenario Structure | ||
|
||
Each scenario directory typically contains the following files: | ||
|
||
``` | ||
scenarios/example-scenario/ | ||
├── App.vue # Main component | ||
├── main.ts # Entry file | ||
├── import-map.json # Dependency mapping | ||
├── tsconfig.json # TypeScript config | ||
└── _meta.js # Metadata config for REPL settings | ||
``` | ||
|
||
The `_meta.js` file exports the scenario configuration: | ||
|
||
```javascript | ||
export default { | ||
mainFile: 'main.ts', // Specify the main entry file | ||
} | ||
``` | ||
|
||
## Usage Example | ||
|
||
### Start the Playground | ||
|
||
```bash | ||
# Enter the project directory | ||
cd vue-repl | ||
|
||
# Install dependencies | ||
npm install | ||
|
||
# Start the development server | ||
npm run dev:playground | ||
``` | ||
|
||
Visit the displayed local address (usually http://localhost:5174/) to use the playground. | ||
|
||
### Add a New Scenario | ||
|
||
1. Create a new folder under the `scenarios/` directory, e.g. `myScenario` | ||
2. Add the required files: | ||
|
||
``` | ||
myScenario/ | ||
├── App.vue # Main component | ||
├── main.ts # Entry file (default entry) | ||
├── import-map.json # Dependency config | ||
├── tsconfig.json # TypeScript config | ||
└── _meta.js # Config with mainFile: 'main.ts' | ||
``` | ||
|
||
3. Refresh the browser, and the new scenario will automatically appear in the dropdown menu. |
This file contains hidden or 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,18 @@ | ||
<!doctype html> | ||
<html lang="en" class="dark"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Playground</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
</style> | ||
<script type="module" src="./main.ts"></script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains hidden or 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,5 @@ | ||
import { createApp } from 'vue' | ||
// @ts-ignore | ||
import App from './src/App.vue' | ||
|
||
createApp(App).mount('#app') |
This file contains hidden or 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,15 @@ | ||
<template> | ||
<div> | ||
<button @click="increment">Increment</button> | ||
<p>Counter: {{ counter }}</p> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
// a simple demo check Repl default config | ||
import { ref } from 'vue' | ||
const counter = ref(0) | ||
const increment = () => { | ||
counter.value++ | ||
} | ||
</script> |
This file contains hidden or 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,6 @@ | ||
export default { | ||
mainFile: 'App.vue', | ||
ReplOptions: { | ||
theme: 'dark', | ||
}, | ||
} |
This file contains hidden or 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,6 @@ | ||
<template> | ||
<div> | ||
<h1>custom main</h1> | ||
<button @click="$hi">test globalProperties</button> | ||
</div> | ||
</template> |
This file contains hidden or 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,3 @@ | ||
export default { | ||
mainFile: 'main.ts', | ||
} |
This file contains hidden or 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,5 @@ | ||
{ | ||
"imports": { | ||
"vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js" | ||
} | ||
} |
This file contains hidden or 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,6 @@ | ||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
|
||
const app = createApp(App) | ||
app.config.globalProperties.$hi = () => alert('hi Vue') | ||
app.mount('#app') |
This file contains hidden or 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,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true | ||
} | ||
} |
This file contains hidden or 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,6 @@ | ||
export default { | ||
mainFile: 'index.html', | ||
ReplOptions: { | ||
theme: 'dark', | ||
}, | ||
} |
This file contains hidden or 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,5 @@ | ||
{ | ||
"imports": { | ||
"vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js" | ||
} | ||
} |
This file contains hidden or 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,41 @@ | ||
<script type="module"> | ||
import { createApp } from 'vue' | ||
|
||
// give each todo a unique id | ||
let id = 0 | ||
|
||
createApp({ | ||
data() { | ||
return { | ||
newTodo: '', | ||
todos: [ | ||
{ id: id++, text: 'Learn HTML' }, | ||
{ id: id++, text: 'Learn JavaScript' }, | ||
{ id: id++, text: 'Learn Vue' }, | ||
], | ||
} | ||
}, | ||
methods: { | ||
addTodo() { | ||
this.todos.push({ id: id++, text: this.newTodo }) | ||
this.newTodo = '' | ||
}, | ||
removeTodo(todo) { | ||
this.todos = this.todos.filter((t) => t !== todo) | ||
}, | ||
}, | ||
}).mount('#app') | ||
</script> | ||
|
||
<div id="app"> | ||
<form @submit.prevent="addTodo"> | ||
<input v-model="newTodo" required placeholder="new todo" /> | ||
<button>Add Todo</button> | ||
</form> | ||
<ul> | ||
<li v-for="todo in todos" :key="todo.id"> | ||
{{ todo.text }} | ||
<button @click="removeTodo(todo)">X</button> | ||
</li> | ||
</ul> | ||
</div> |
This file contains hidden or 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,17 @@ | ||
<template> | ||
<div> | ||
<h1>Welcome to Pinia Demo</h1> | ||
<p>Store message: {{ store.message }}</p> | ||
<button @click="updateMessage">Update Message</button> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useMainStore } from './store' | ||
|
||
const store = useMainStore() | ||
|
||
function updateMessage() { | ||
store.updateMessage('Message updated at ' + new Date().toLocaleTimeString()) | ||
} | ||
</script> |
This file contains hidden or 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,3 @@ | ||
export default { | ||
mainFile: 'main.ts', | ||
} |
This file contains hidden or 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,8 @@ | ||
{ | ||
"imports": { | ||
"vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js", | ||
"pinia": "https://unpkg.com/pinia@2/dist/pinia.esm-browser.js", | ||
"vue-demi": "https://cdn.jsdelivr.net/npm/[email protected]/lib/v3/index.mjs", | ||
"@vue/devtools-api": "https://cdn.jsdelivr.net/npm/@vue/[email protected]/lib/esm/index.js" | ||
} | ||
} |
This file contains hidden or 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,8 @@ | ||
import { createApp } from 'vue' | ||
import { createPinia } from 'pinia' | ||
import App from './App.vue' | ||
|
||
const pinia = createPinia() | ||
const app = createApp(App) | ||
app.use(pinia) | ||
app.mount('#app') |
This file contains hidden or 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,12 @@ | ||
import { defineStore } from 'pinia' | ||
|
||
export const useMainStore = defineStore('main', { | ||
state: () => ({ | ||
message: 'Hello from Pinia!', | ||
}), | ||
actions: { | ||
updateMessage(newMessage: string) { | ||
this.message = newMessage | ||
}, | ||
}, | ||
}) |
This file contains hidden or 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,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true | ||
} | ||
} |
This file contains hidden or 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,17 @@ | ||
<template> | ||
<div> | ||
<h3>About Page</h3> | ||
<p>This is a demo of Vue Router in a sandbox environment</p> | ||
<button @click="goHome">Go Home</button> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useRouter } from 'vue-router' | ||
|
||
const router = useRouter() | ||
|
||
function goHome() { | ||
router.push('/') | ||
} | ||
</script> |
This file contains hidden or 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,15 @@ | ||
<template> | ||
<div> | ||
<h2>Vue Router Demo</h2> | ||
<nav> | ||
<RouterLink to="/">Home</RouterLink> | | ||
<RouterLink to="/about">About</RouterLink> | ||
</nav> | ||
<router-view /> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { RouterLink } from 'vue-router' | ||
// Add your setup code here | ||
</script> |
This file contains hidden or 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,5 @@ | ||
<template> | ||
<div> | ||
<h1>Welcome to Vue Router Demo</h1> | ||
</div> | ||
</template> |
This file contains hidden or 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,3 @@ | ||
export default { | ||
mainFile: 'main.ts', | ||
} |
This file contains hidden or 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,9 @@ | ||
{ | ||
"imports": { | ||
"vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js", | ||
"vue/server-renderer": "http://localhost:5173/src/vue-server-renderer-dev-proxy", | ||
"vue-router": "https://unpkg.com/vue-router@4/dist/vue-router.esm-browser.js", | ||
"@vue/devtools-api": "https://cdn.jsdelivr.net/npm/@vue/[email protected]/lib/esm/index.js" | ||
}, | ||
"scopes": {} | ||
} |
This file contains hidden or 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,25 @@ | ||
import { createApp } from 'vue' | ||
import { createRouter, createMemoryHistory } from 'vue-router' | ||
import App from './App.vue' | ||
import Home from './Home.vue' | ||
import About from './About.vue' | ||
|
||
const routes = [ | ||
{ path: '/', component: Home }, | ||
{ path: '/about', component: About }, | ||
] | ||
|
||
// Use createMemoryHistory instead of createWebHistory in the sandbox environment | ||
const router = createRouter({ | ||
history: createMemoryHistory(), | ||
routes, | ||
}) | ||
|
||
// Add router error handling | ||
router.onError((error) => { | ||
console.error('Vue Router error:', error) | ||
}) | ||
|
||
const app = createApp(App) | ||
app.use(router) | ||
app.mount('#app') |
This file contains hidden or 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,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.