-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OIA-39: Update Plugin Example & Test with Vue-Router (#60)
* support vue-router in plugin test app * update sample plugin with pinia/router/ability to run itself * externalze vue-router to dedup
- Loading branch information
1 parent
ae99fb4
commit 2207d61
Showing
16 changed files
with
210 additions
and
107 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,31 +1,6 @@ | ||
<script setup lang="ts"> | ||
// @ts-ignore | ||
import * as Vue from 'vue/dist/vue.esm-bundler' | ||
import * as Pinia from 'pinia' | ||
import PluginContainer from './PluginContainer.vue' | ||
import addStylesheet from './utils/externalStyles' | ||
(window as any).Vue = Vue; | ||
(window as any).Pinia = Pinia; | ||
// list of external js files | ||
const externalScripts = [ | ||
'http://localhost:5002/uiextension.es.js' | ||
] | ||
// list of external css assets | ||
const externalStylesheets = [ | ||
'http://localhost:5002/style.css' | ||
] | ||
for (const stylesheet of externalStylesheets) { | ||
addStylesheet(stylesheet) | ||
} | ||
</script> | ||
|
||
<template> | ||
This is the UI Extension APP used as an extension container | ||
<div v-for="script of externalScripts" :key="script"> | ||
<PluginContainer :script="script" /> | ||
</div> | ||
<router-view></router-view> | ||
</template> |
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,25 @@ | ||
<script setup lang="ts"> | ||
import PluginContainer from './PluginContainer.vue' | ||
import addStylesheet from './utils/externalStyles' | ||
// list of external js files | ||
const externalScripts = [ | ||
'http://localhost:5002/uiextension.es.js' | ||
] | ||
// list of external css assets | ||
const externalStylesheets = [ | ||
'http://localhost:5002/style.css' | ||
] | ||
for (const stylesheet of externalStylesheets) { | ||
addStylesheet(stylesheet) | ||
} | ||
</script> | ||
|
||
<template> | ||
This is the UI Extension APP used as an extension container | ||
<div v-for="script of externalScripts" :key="script"> | ||
<PluginContainer :script="script" /> | ||
</div> | ||
</template> |
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 |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
import { createPinia } from 'pinia' | ||
import * as Vue from 'vue/dist/vue.esm-bundler' | ||
import * as Pinia from 'pinia' | ||
import * as VueRouter from 'vue-router' | ||
import externalComponent from './utils/externalComponent' | ||
import Router from './router' | ||
|
||
createApp(App).use(createPinia()).mount('#app') | ||
(window as any)['VRouter'] = Router; | ||
(window as any).Vue = Vue; | ||
(window as any).Pinia = Pinia; | ||
(window as any).VueRouter = VueRouter; | ||
|
||
await externalComponent('http://localhost:5002/uiextension.es.js') | ||
|
||
createApp(App) | ||
.use(createPinia()) | ||
.use(Router) | ||
.mount('#app') | ||
|
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,19 @@ | ||
import { createRouter, createWebHistory } from 'vue-router' | ||
import PluginVue from '../Plugin.vue' | ||
|
||
const router = createRouter({ | ||
history: createWebHistory(), | ||
routes: [ | ||
{ | ||
path: '/', | ||
name: 'Plugin', | ||
component: PluginVue, | ||
}, | ||
{ | ||
path: '/:pathMatch(.*)*', // catch other paths and redirect | ||
redirect: '/' | ||
} | ||
] | ||
}) | ||
|
||
export default router |
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
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
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
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,9 @@ | ||
import router from '../router' | ||
import { Router } from 'vue-router' | ||
|
||
// for plugin routing, use this hook | ||
const useRouter = (): Router => { | ||
return (window as any).VRouter || router | ||
} | ||
|
||
export default useRouter |
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 |
---|---|---|
@@ -1,4 +1,14 @@ | ||
import App from './App.vue' | ||
import { createApp } from 'vue' | ||
import router from './router' | ||
import { createPinia } from 'pinia' | ||
|
||
const envMode = import.meta.env.MODE | ||
|
||
//@ts-ignore | ||
window['uiextension'] = App | ||
|
||
// used to run plugin by itself | ||
if (envMode === 'development') { | ||
createApp(App).use(router).use(createPinia()).mount('#app') | ||
} |
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,25 @@ | ||
import { createRouter, createWebHistory, Router } from 'vue-router' | ||
import HelloWorld from '../components/HelloWorld.vue' | ||
|
||
const routes = [ | ||
{ | ||
path: '/', | ||
name: 'hello', | ||
component: HelloWorld, | ||
}, | ||
] | ||
|
||
const VRouter: Router = (window as any).VRouter | ||
if (VRouter) { | ||
for (const route of routes) { | ||
const { path, name, component } = route | ||
VRouter.addRoute('Plugin', { path: path.slice(1), name, component }) | ||
} | ||
} | ||
|
||
const router = createRouter({ | ||
history: createWebHistory(), | ||
routes, | ||
}) | ||
|
||
export default router |
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
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,6 @@ | ||
import { defineConfig } from 'vite' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
export default defineConfig({ | ||
plugins: [vue()] | ||
}) |
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