From 275d7c8e97ea5d7b46eb78860bab6e0395f199f8 Mon Sep 17 00:00:00 2001 From: Shigma Date: Wed, 31 Jan 2024 02:43:33 +0800 Subject: [PATCH] refa: refactor client into plugins, fix #305 --- packages/client/app/index.ts | 4 +- packages/client/app/status/loading.vue | 2 +- packages/client/app/theme/activity/index.vue | 5 +- .../client/app/theme/activity/separator.vue | 5 +- packages/client/client/activity.ts | 95 --------- packages/client/client/components/link.ts | 4 +- packages/client/client/components/slot.ts | 2 +- packages/client/client/context.ts | 72 ++----- packages/client/client/data.ts | 8 +- packages/client/client/index.ts | 66 +------ packages/client/client/loader.ts | 87 -------- packages/client/client/plugins/action.ts | 4 +- packages/client/client/plugins/i18n.ts | 28 +++ packages/client/client/plugins/loader.ts | 100 ++++++++++ packages/client/client/plugins/router.ts | 187 ++++++++++++++++++ packages/client/client/plugins/setting.ts | 10 +- packages/client/client/plugins/theme.ts | 15 +- packages/online/app/index.ts | 2 +- plugins/config/client/components/plugin.vue | 6 +- plugins/market/client/components/progress.vue | 4 +- 20 files changed, 382 insertions(+), 324 deletions(-) delete mode 100644 packages/client/client/activity.ts delete mode 100644 packages/client/client/loader.ts create mode 100644 packages/client/client/plugins/i18n.ts create mode 100644 packages/client/client/plugins/loader.ts create mode 100644 packages/client/client/plugins/router.ts diff --git a/packages/client/app/index.ts b/packages/client/app/index.ts index 9144f7ed..3ac07de8 100644 --- a/packages/client/app/index.ts +++ b/packages/client/app/index.ts @@ -16,9 +16,9 @@ root.plugin(status) root.plugin(styles) root.plugin(theme) -root.app.mount('#app') +root.start() if (!global.static) { const endpoint = new URL(global.endpoint, location.origin).toString() - connect(() => new WebSocket(endpoint.replace(/^http/, 'ws'))) + connect(root, () => new WebSocket(endpoint.replace(/^http/, 'ws'))) } diff --git a/packages/client/app/status/loading.vue b/packages/client/app/status/loading.vue index 951dff19..03865f96 100644 --- a/packages/client/app/status/loading.vue +++ b/packages/client/app/status/loading.vue @@ -14,7 +14,7 @@ import { computed } from 'vue' const ctx = useContext() const progress = computed(() => { - const states = Object.values(ctx.internal.extensions) + const states = Object.values(ctx.$loader.extensions) return states.filter(state => state.done.value).length / states.length }) diff --git a/packages/client/app/theme/activity/index.vue b/packages/client/app/theme/activity/index.vue index 50805313..3bdc12a2 100644 --- a/packages/client/app/theme/activity/index.vue +++ b/packages/client/app/theme/activity/index.vue @@ -21,10 +21,11 @@ import { computed, provide } from 'vue' import { useWindowSize } from '@vueuse/core' -import { activities, Activity, useConfig, useMenu } from '@koishijs/client' +import { Activity, useConfig, useContext, useMenu } from '@koishijs/client' import ActivityItem from './item.vue' import ActivitySeparator from './separator.vue' +const ctx = useContext() const config = useConfig() const trigger = useMenu('theme.activity') const { height, width } = useWindowSize() @@ -34,7 +35,7 @@ const groups = computed(() => { const unit = width.value <= 768 ? 52 : 56 const total = height.value - (width.value <= 768 ? 4 : 8) const available = Object.fromEntries(Object - .entries(activities) + .entries(ctx.$router.pages) .filter(([, data]) => !data.disabled()) .map(([key, data]) => [key, [data]])) for (const id of Object.keys(available)) { diff --git a/packages/client/app/theme/activity/separator.vue b/packages/client/app/theme/activity/separator.vue index 962c8bb3..171d34a8 100644 --- a/packages/client/app/theme/activity/separator.vue +++ b/packages/client/app/theme/activity/separator.vue @@ -12,7 +12,7 @@