Skip to content

Commit

Permalink
fix(manager): support scoped plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jun 24, 2022
1 parent 36c9c19 commit f4c8d86
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugins/frontend/manager/client/settings/group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<span class="right">
<k-button solid @click="addItem(current.path, 'unload', '')">添加插件</k-button>
<k-button solid @click="addItem(current.path, 'group', 'group')">添加分组</k-button>
<k-button solid type="error" @click="removeItem(current.path)">移除分组</k-button>
<k-button v-if="current.path" solid type="error" @click="removeItem(current.path)">移除分组</k-button>
</span>
</h1>
<div class="k-form" v-if="current.config.$isolate?.length">
Expand Down
8 changes: 4 additions & 4 deletions plugins/frontend/manager/client/settings/plugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
import { send, store, clone, router } from '@koishijs/client'
import { computed, ref, watch } from 'vue'
import { envMap, Tree, removeItem } from './utils'
import { envMap, Tree, removeItem, separator } from './utils'
import KAlias from './alias.vue'
import KDepLink from './dep-link.vue'
Expand Down Expand Up @@ -114,8 +114,8 @@ const type = computed(() => {
})
const name = computed(() => {
const { label, target: temporary } = props.current
const shortname = temporary || label
const { label, target } = props.current
const shortname = target || label
if (shortname.includes('/')) {
const [left, right] = shortname.split('/')
return [`${left}/koishi-plugin-${right}`].find(name => name in store.packages)
Expand All @@ -139,7 +139,7 @@ const hasUpdate = computed(() => {
function execute(event: 'unload' | 'reload') {
send(`manager/${event}`, props.current.path, config.value, props.current.target)
if (props.current.target) {
const segments = props.current.path.split('/')
const segments = props.current.path.split(separator)
segments[segments.length - 1] = props.current.target
router.replace('/plugins/' + segments.join('/'))
}
Expand Down
9 changes: 5 additions & 4 deletions plugins/frontend/manager/client/settings/tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import { ref, computed, onActivated, nextTick, watch } from 'vue'
import { send } from '@koishijs/client'
import { Tree, plugins, setPath, addItem } from './utils'
import { Tree, plugins, setPath, addItem, separator } from './utils'
const props = defineProps<{
modelValue: string
Expand Down Expand Up @@ -73,7 +73,7 @@ interface Node {
function allowDrop(source: Node, target: Node, type: 'inner' | 'prev' | 'next') {
if (type !== 'inner') return target.data.path !== ''
const segments = target.data.path.split('/')
const segments = target.data.path.split(separator)
return segments[segments.length - 1].startsWith('group:')
}
Expand All @@ -95,10 +95,11 @@ function handleDrop(source: Node, target: Node, position: 'before' | 'after' | '
const ctxPath = parent.data.path
const index = parent.childNodes.findIndex(node => node.data.path === oldPath)
send('manager/teleport', oldPath, ctxPath, index)
const segments1 = oldPath.split('/')
const segments2 = ctxPath ? ctxPath.split('/') : []
const segments1 = oldPath.split(separator)
const segments2 = ctxPath ? ctxPath.split(separator) : []
segments2.push(segments1.pop())
setPath(oldPath, segments2.join('/'))
;/(?<!dsa)/
}
function getClass(tree: Tree) {
Expand Down
4 changes: 3 additions & 1 deletion plugins/frontend/manager/client/settings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export function setPath(oldPath: string, newPath: string) {
router.replace('/plugins/' + newPath)
}

export const separator = /(?<!@[\w-]+)\//g

export function addItem(path: string, action: 'group' | 'unload', name: string) {
const id = Math.random().toString(36).slice(2, 8)
if (path) path += '/'
Expand All @@ -158,7 +160,7 @@ export function addItem(path: string, action: 'group' | 'unload', name: string)

export function removeItem(path: string) {
send('manager/remove', path)
const segments = path.split('/')
const segments = path.split(separator)
segments.pop()
router.replace('/plugins/' + segments.join('/'))
}
4 changes: 3 additions & 1 deletion plugins/frontend/manager/src/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ declare module '@koishijs/plugin-console' {
}
}

const separator = /(?<!@[\w-]+)\//g

function insertKey(object: {}, temp: {}, rest: string[]) {
for (const key of rest) {
temp[key] = object[key]
Expand Down Expand Up @@ -121,7 +123,7 @@ class ConfigWriter extends DataService<App.Config> {
}

private resolve(path: string) {
const segments = path.split('/')
const segments = path.split(separator)
let ctx = this.loader.entry
let name = segments.shift()
while (segments.length) {
Expand Down

0 comments on commit f4c8d86

Please sign in to comment.