Skip to content
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

feat(components): support for automatic component import #1794

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/desktop/electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import VueRouter from 'unplugin-vue-router/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
main: {
Expand All @@ -25,6 +27,12 @@ export default defineConfig({
],
}),
vue(),
Components({
dts: true,
directoryAsNamespace: true,
dirs: ['src/components', '../../../../packages/ui/src/components'],
resolvers: [ElementPlusResolver()],
}),
],
},
})
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"sass": "^1.69.3",
"tailwindcss": "^3.3.3",
"typescript": "^5.1.6",
"unplugin-vue-components": "^0.27.4",
"unplugin-vue-router": "^0.10.8",
"vite": "^4.4.9",
"vitest": "^0.34.6",
Expand Down
23 changes: 23 additions & 0 deletions apps/desktop/src/renderer/components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}

/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
CommonEmptyView: typeof import('./../../../../packages/ui/src/components/common/EmptyView.vue')['default']
CommonLeftMenu: typeof import('./../../../../packages/ui/src/components/common/LeftMenu.vue')['default']
CommonMainView: typeof import('./../../../../packages/ui/src/components/common/MainView.vue')['default']
CommonSplitView: typeof import('./../../../../packages/ui/src/components/common/SplitView.vue')['default']
ConnectionsDetailsView: typeof import('./../../../../packages/ui/src/components/connections/DetailsView.vue')['default']
ConnectionsListView: typeof import('./../../../../packages/ui/src/components/connections/ListView.vue')['default']
ElAside: typeof import('element-plus/es')['ElAside']
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElMain: typeof import('element-plus/es')['ElMain']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
}
}
14 changes: 6 additions & 8 deletions apps/desktop/src/renderer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ console.log('MQTTX Desktop App init...')
</script>

<template>
<el-config-provider :locale="ElementI18nMap[settingsStore.lang]">
<el-container>
<left-menu />
<main-view />
</el-container>
</el-config-provider>
<ElConfigProvider :locale="ElementI18nMap[settingsStore.lang]">
<ElContainer>
<CommonLeftMenu />
<CommonMainView />
</ElContainer>
</ElConfigProvider>
</template>

<style lang="scss" scoped></style>
8 changes: 0 additions & 8 deletions apps/desktop/src/renderer/src/configs/router.ts

This file was deleted.

8 changes: 3 additions & 5 deletions apps/desktop/src/renderer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import './assets/scss/main.scss'
import { createApp } from 'vue'
import App from './App.vue'

import ElementPlus from 'element-plus'

import { router } from './router'
import MqttxUI, { pinia, i18n, useSettingsStore } from '@mqttx/ui'
import { pinia, i18n, useSettingsStore } from '@mqttx/ui'

// Create Vue
const app = createApp(App)

app.use(router).use(pinia).use(MqttxUI)
app.use(router).use(pinia)

// I18n
const settingsStore = useSettingsStore()
i18n.global.locale = settingsStore.lang

app.use(ElementPlus).use(i18n).mount('#app')
app.use(i18n).mount('#app')
13 changes: 7 additions & 6 deletions apps/desktop/src/renderer/src/pages/connections/[id].vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
// import { computed } from 'vue'
// import { useRoute } from 'vue-router'

const route = useRoute()
const id = computed(() => route.name === '/connections/[id]' && route.params.id)
// const route = useRoute()
// const id = computed(() => route.name === '/connections/[id]' && route.params.id)
</script>

<template>
<connection-details-view
TODO: Connection Details View
<!-- <ConnectionsDetailsView
:connection="{
name: 'test',
id,
}"
/>
/> -->
</template>
10 changes: 5 additions & 5 deletions apps/desktop/src/renderer/src/pages/connections/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const { connections } = useMockData()
</script>

<template>
<split-view class="connections-container" min-size="180px" max-size="400px">
<CommonSplitView class="connections-container" min-size="180px" max-size="400px">
<template #panel-1>
<div class="connections-list">
<connection-list-view :data="connections" />
<ConnectionsListView :data="connections" />
</div>
</template>
<template #panel-2>
<div class="connection-detail">
<router-view v-if="connections.length" />
<empty-view v-else />
<RouterView v-if="connections.length" />
<CommonEmptyView v-else />
</div>
</template>
</split-view>
</CommonSplitView>
</template>
3 changes: 2 additions & 1 deletion apps/desktop/tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"src/renderer/src/**/*",
"src/renderer/src/**/*.vue",
"src/preload/*.d.ts",
"./typed-router.d.ts"
"./typed-router.d.ts",
"src/renderer/components.d.ts"
],
"compilerOptions": {
"composite": true,
Expand Down
23 changes: 23 additions & 0 deletions apps/web/components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}

/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
CommonEmptyView: typeof import('./../../packages/ui/src/components/common/EmptyView.vue')['default']
CommonLeftMenu: typeof import('./../../packages/ui/src/components/common/LeftMenu.vue')['default']
CommonMainView: typeof import('./../../packages/ui/src/components/common/MainView.vue')['default']
CommonSplitView: typeof import('./../../packages/ui/src/components/common/SplitView.vue')['default']
ConnectionsDetailsView: typeof import('./../../packages/ui/src/components/connections/DetailsView.vue')['default']
ConnectionsListView: typeof import('./../../packages/ui/src/components/connections/ListView.vue')['default']
ElAside: typeof import('element-plus/es')['ElAside']
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElMain: typeof import('element-plus/es')['ElMain']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
}
}
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"sass": "^1.69.3",
"tailwindcss": "^3.3.3",
"typescript": "~5.2.0",
"unplugin-vue-components": "^0.27.4",
"unplugin-vue-router": "^0.10.8",
"vite": "^4.4.9",
"vitest": "^0.34.6",
Expand Down
14 changes: 6 additions & 8 deletions apps/web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ console.log('MQTTX Web App init...')
</script>

<template>
<el-config-provider :locale="ElementI18nMap[settingsStore.lang]">
<el-container>
<left-menu />
<main-view />
</el-container>
</el-config-provider>
<ElConfigProvider :locale="ElementI18nMap[settingsStore.lang]">
<ElContainer>
<CommonLeftMenu />
<CommonMainView />
</ElContainer>
</ElConfigProvider>
</template>

<style lang="scss" scoped></style>
8 changes: 3 additions & 5 deletions apps/web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import './assets/scss/main.scss'
import { createApp } from 'vue'
import App from './App.vue'

import ElementPlus from 'element-plus'

import { router } from './router'
import MqttxUI, { pinia, i18n, useSettingsStore } from '@mqttx/ui'
import { pinia, i18n, useSettingsStore } from '@mqttx/ui'

// Create Vue
const app = createApp(App)

app.use(router).use(pinia).use(MqttxUI)
app.use(router).use(pinia)

// I18n
const settingsStore = useSettingsStore()
i18n.global.locale = settingsStore.lang

app.use(ElementPlus).use(i18n).mount('#app')
app.use(i18n).mount('#app')
13 changes: 7 additions & 6 deletions apps/web/src/pages/connections/[id].vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
// import { computed } from 'vue'
// import { useRoute } from 'vue-router'

const route = useRoute()
const id = computed(() => route.name === '/connections/[id]' && route.params.id)
// const route = useRoute()
// const id = computed(() => route.name === '/connections/[id]' && route.params.id)
</script>

<template>
<connection-details-view
TODO: Connection Details View
<!-- <ConnectionsDetailsView
:connection="{
name: 'test',
id,
}"
/>
/> -->
</template>
10 changes: 5 additions & 5 deletions apps/web/src/pages/connections/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const { connections } = useMockData()
</script>

<template>
<split-view class="connections-container" min-size="180px" max-size="400px">
<CommonSplitView class="connections-container" min-size="180px" max-size="400px">
<template #panel-1>
<div class="connections-list">
<connection-list-view :data="connections" />
<ConnectionsListView :data="connections" />
</div>
</template>
<template #panel-2>
<div class="connection-detail">
<router-view v-if="connections.length" />
<empty-view v-else />
<RouterView v-if="connections.length" />
<CommonEmptyView v-else />
</div>
</template>
</split-view>
</CommonSplitView>
</template>
8 changes: 7 additions & 1 deletion apps/web/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue", "./typed-router.d.ts"],
"include": [
"env.d.ts",
"src/**/*",
"src/**/*.vue",
"./typed-router.d.ts",
"./components.d.ts"
],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"esModuleInterop": true,
Expand Down
14 changes: 13 additions & 1 deletion apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueRouter from 'unplugin-vue-router/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [VueRouter(), vue(), vueJsx()],
plugins: [
VueRouter(),
vue(),
vueJsx(),
Components({
dts: true,
directoryAsNamespace: true,
dirs: ['src/components', '../../packages/ui/src/components'],
resolvers: [ElementPlusResolver()],
}),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
Expand Down
4 changes: 0 additions & 4 deletions packages/ui/src/components/common/MainView.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<script setup lang="ts"></script>

<template>
<el-main>
<router-view></router-view>
</el-main>
</template>

<style lang="scss" scoped></style>
2 changes: 0 additions & 2 deletions packages/ui/src/components/common/SplitView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,3 @@ onMounted(() => {
</div>
</div>
</template>

<style scoped></style>
Loading
Loading