Skip to content

Commit

Permalink
refa: migrate loader usage
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 25, 2024
1 parent 2c61921 commit 99eadfc
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:

globals:
NodeJS: true
KOISHI_CONFIG: true
CLIENT_CONFIG: true

extends:
- '@cordisjs/eslint-config'
Expand Down
22 changes: 11 additions & 11 deletions plugins/manager/client/components/forks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<table>
<tr v-for="id in plugins.forks[dialogFork!]" :key="id">
<td class="text-left">
<span class="status-light" :class="ctx.manager.getStatus(plugins.paths[id])"></span>
<span class="path">{{ getFullPath(plugins.paths[id]) }}</span>
<span class="status-light" :class="ctx.manager.getStatus(plugins.entries[id])"></span>
<span class="path">{{ getFullPath(plugins.entries[id]) }}</span>
</td>
<td class="text-right">
<span class="actions">
<span class="action" @click.stop="configure(id)"><k-icon name="arrow-right"></k-icon></span>
<span class="action" @click.stop="ctx.manager.remove(plugins.paths[id])"><k-icon name="delete"></k-icon></span>
<span class="action" @click.stop="ctx.manager.remove(plugins.entries[id])"><k-icon name="delete"></k-icon></span>
</span>
</td>
</tr>
Expand All @@ -43,7 +43,7 @@
import { computed } from 'vue'
import { send, router, useContext } from '@cordisjs/client'
import { Node } from '..'
import { EntryData } from '../../src'
const ctx = useContext()
const plugins = computed(() => ctx.manager.plugins.value)
Expand All @@ -54,15 +54,15 @@ const dialogFork = computed({
const local = computed(() => ctx.manager.data.value.packages[dialogFork.value!])
function getLabel(tree: Node) {
return `${tree.label ? `${tree.label} ` : ''}[${tree.path}]`
function getLabel(data: EntryData) {
return `${data.label ? `${data.label} ` : ''}[${data.id}]`
}
function getFullPath(tree: Node) {
const path = [getLabel(tree)]
while (tree.parent) {
tree = tree.parent
path.unshift(getLabel(tree))
function getFullPath(data: EntryData) {
const path = [getLabel(data)]
while (data.parent) {
data = ctx.manager.plugins.value.entries[data.parent]
path.unshift(getLabel(data))
}
return path.join(' > ')
}
Expand Down
50 changes: 24 additions & 26 deletions plugins/manager/client/components/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<template v-if="!current">插件配置</template>

<!-- group -->
<template v-else-if="current.children">
<template v-else-if="current.isGroup">
分组:{{ current.label || current.id }}
</template>

<!-- plugin -->
<template v-else>
{{ current.label || current.name }} [{{ current.path }}]
{{ current.label || current.name }} [{{ current.id }}]
</template>
</template>

Expand All @@ -23,7 +23,7 @@
<div>请在左侧选择插件</div>
</k-empty>
<k-content v-else class="plugin-view" :key="path">
<group-settings v-if="current.children" v-model="config"></group-settings>
<group-settings v-if="current.isGroup" v-model="config"></group-settings>
<plugin-settings v-else v-model="config"></plugin-settings>
</k-content>

Expand All @@ -34,7 +34,7 @@
@closed="remove = undefined"
>
<template v-if="remove">
确定要移除{{ remove.children ? `分组 ${remove.label || remove.path}` : `插件 ${remove.label || remove.name}` }} 吗?此操作不可撤销!
确定要移除{{ remove.isGroup ? `分组 ${remove.label || remove.id}` : `插件 ${remove.label || remove.name}` }} 吗?此操作不可撤销!
</template>
<template #footer>
<el-button @click="showRemove = false">取消</el-button>
Expand Down Expand Up @@ -83,6 +83,7 @@ import { Node } from '..'
import GroupSettings from './group.vue'
import TreeView from './tree.vue'
import PluginSettings from './plugin.vue'
import { EntryData } from '../../src'
const route = useRoute()
const router = useRouter()
Expand All @@ -99,10 +100,10 @@ const dialogFork = computed({
const path = computed<string>({
get() {
const name = route.path.slice(9)
return name in plugins.value.paths ? name : ''
return name in plugins.value.entries ? name : ''
},
set(name) {
if (!(name in plugins.value.paths)) name = ''
if (!(name in plugins.value.entries)) name = ''
router.replace('/plugins/' + name)
},
})
Expand All @@ -118,9 +119,9 @@ async function handleOpen() {
inputEl.value?.focus()
}
const remove = ref<Node>()
const remove = ref<EntryData>()
const showRemove = ref(false)
const rename = ref<Node>()
const rename = ref<EntryData>()
const showRename = ref(false)
const groupCreate = ref<string>()
Expand All @@ -132,22 +133,22 @@ watch(rename, (value) => {
if (value) showRename.value = true
})
watch(() => plugins.value.paths[path.value], (value) => {
watch(() => plugins.value.entries[path.value], (value) => {
ctx.manager.current.value = value
if (value) config.value = clone(value.config)
}, { immediate: true })
ctx.define('config.tree', ctx.manager.current)
ctx.action('config.tree.add-plugin', {
hidden: ({ config }) => config.tree && !config.tree.children,
hidden: ({ config }) => config.tree && !config.tree.isGroup,
action: ({ config }) => ctx.manager.dialogSelect.value = config.tree,
})
ctx.action('config.tree.add-group', {
hidden: ({ config }) => config.tree && !config.tree.children,
hidden: ({ config }) => config.tree && !config.tree.isGroup,
action: ({ config }) => {
groupCreate.value = config.tree.path
groupCreate.value = config.tree.id
},
})
Expand All @@ -162,25 +163,21 @@ async function createGroup(label: string) {
}
ctx.action('config.tree.clone', {
hidden: ({ config }) => !config.tree || !!config.tree.children,
hidden: ({ config }) => !config.tree || !!config.tree.isGroup,
action: async ({ config }) => {
const children = config.tree.parent!.path
? config.tree.parent!.children
: plugins.value.data.slice(1)
const index = children.findIndex(tree => tree.path === config.tree.path)
const id = await send('manager.config.create', {
name: config.tree.name,
config: config.tree.config,
disabled: true,
parent: config.tree.parent!.id,
index: index + 1,
parent: config.tree.parent,
position: config.tree.position + 1,
})
router.replace(`/plugins/${id}`)
},
})
ctx.action('config.tree.manage', {
hidden: ({ config }) => !config.tree || !!config.tree.children,
hidden: ({ config }) => !config.tree || !!config.tree.isGroup,
action: async ({ config }) => {
dialogFork.value = config.tree.name
},
Expand All @@ -189,7 +186,7 @@ ctx.action('config.tree.manage', {
ctx.action('config.tree.rename', {
disabled: ({ config }) => !config.tree,
action: ({ config }) => {
input.value = config.tree.label || (config.tree.name === 'group' ? config.tree.path : config.tree.name)
input.value = config.tree.label || (config.tree.name === 'group' ? config.tree.id : config.tree.name)
rename.value = config.tree
},
})
Expand Down Expand Up @@ -240,18 +237,19 @@ ctx.action('config.tree.toggle', {
},
})
async function execute(tree: Node, disabled: true | null) {
async function execute(data: EntryData, disabled: true | null) {
await send('manager.config.update', {
id: tree.id,
id: data.id,
disabled,
config: config.value,
})
}
async function renameItem(tree: Node, name: string) {
async function renameItem(data: EntryData, name: string) {
showRename.value = false
tree.label = name
data.label = name
await send('manager.config.update', {
id: tree.path,
id: data.id,
label: name || null,
})
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/manager/client/components/plugin.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<template v-if="current?.name in data.packages">
<template v-if="current && current.name in data.packages">
<k-comment v-if="!local.runtime">
<p>正在加载插件配置……</p>
</k-comment>
Expand Down Expand Up @@ -53,7 +53,7 @@
<!-- implements -->
<k-slot-item :order="300">
<template v-for="(activity, key) in ctx.$router.pages" :key="key">
<k-comment type="success" v-if="activity.ctx.$entry?.paths.includes(current.path) && !activity.disabled()">
<k-comment type="success" v-if="activity.ctx.$entry?.paths.includes(current.id) && !activity.disabled()">
<p>
<span>此插件提供了页面:</span>
<k-activity-link :id="activity.id" />
Expand Down Expand Up @@ -117,7 +117,7 @@ const config = computed({
set: value => emit('update:modelValue', value),
})
const env = computed(() => ctx.manager.getEnvInfo(current.value?.name))
const env = computed(() => ctx.manager.getEnvInfo(current.value?.name)!)
const local = computed(() => data.value.packages[current.value?.name!])
const hint = computed(() => local.value.workspace ? '请检查插件源代码。' : '请联系插件作者并反馈此问题。')
Expand Down
6 changes: 2 additions & 4 deletions plugins/manager/client/components/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ const dialogSelect = computed({
const keyword = ref('')
const input = ref()
const filter = inject('plugin-select-filter', (local: LocalObject) => true)
const packages = computed(() => Object.values(ctx.manager.data.value.packages).filter((local) => {
return local.package.name.includes(keyword.value.toLowerCase()) && filter(local)
return local.package.name.includes(keyword.value.toLowerCase())
}))
function joinName(name: string, base: string) {
Expand All @@ -64,7 +62,7 @@ function joinName(name: string, base: string) {
}
async function configure(name: string) {
const parent = dialogSelect.value!.path
const parent = dialogSelect.value!.id
dialogSelect.value = undefined
keyword.value = ''
const id = await send('manager.config.create', {
Expand Down
Loading

0 comments on commit 99eadfc

Please sign in to comment.