|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { DevframeInspectCommandInfo } from '@devframes/plugin-inspect/client' |
| 3 | +import ActionButton from '@antfu/design/components/Action/ActionButton.vue' |
| 4 | +import { computed, ref } from 'vue' |
| 5 | +import JsonView from './JsonView.vue' |
| 6 | +
|
| 7 | +defineOptions({ name: 'CommandRow' }) |
| 8 | +
|
| 9 | +const props = defineProps<{ |
| 10 | + cmd: DevframeInspectCommandInfo |
| 11 | + argsInput: Record<string, string> |
| 12 | + results: Record<string, any> |
| 13 | + pending: Record<string, boolean> |
| 14 | + isStatic: boolean |
| 15 | + /** Nesting depth — 0 for top-level commands, 1 for their children. */ |
| 16 | + depth?: number |
| 17 | +}>() |
| 18 | +
|
| 19 | +const emit = defineEmits<{ |
| 20 | + (e: 'execute', cmd: DevframeInspectCommandInfo): void |
| 21 | + (e: 'updateArgs', id: string, value: string): void |
| 22 | +}>() |
| 23 | +
|
| 24 | +const expanded = ref(false) |
| 25 | +
|
| 26 | +const clickable = computed(() => |
| 27 | + props.cmd.hasHandler || !!props.cmd.description || !!props.cmd.children?.length, |
| 28 | +) |
| 29 | +
|
| 30 | +function toggle(): void { |
| 31 | + expanded.value = !expanded.value |
| 32 | +} |
| 33 | +</script> |
| 34 | + |
| 35 | +<template> |
| 36 | + <div class="fn-row" :class="{ 'cmd-row-child': depth }"> |
| 37 | + <div class="fn-head" :class="{ clickable }" @click="toggle"> |
| 38 | + <div class="chev i-ph-caret-right" :class="{ open: expanded }" /> |
| 39 | + <span v-if="cmd.icon" :class="typeof cmd.icon === 'string' ? cmd.icon : 'i-ph-terminal-window-duotone'" class="cmd-icon" /> |
| 40 | + <span class="cmd-title">{{ cmd.title }}</span> |
| 41 | + <span class="cmd-id mono">{{ cmd.id }}</span> |
| 42 | + <span class="fn-flags"> |
| 43 | + <span v-if="cmd.category" class="badge flag">{{ cmd.category }}</span> |
| 44 | + <span v-if="!cmd.hasHandler" class="badge flag" title="No handler — a group for its children">group</span> |
| 45 | + <span v-if="cmd.children?.length" class="badge flag">{{ cmd.children.length }} children</span> |
| 46 | + </span> |
| 47 | + </div> |
| 48 | + |
| 49 | + <div v-if="expanded" class="fn-detail"> |
| 50 | + <p v-if="cmd.description" class="desc"> |
| 51 | + {{ cmd.description }} |
| 52 | + </p> |
| 53 | + |
| 54 | + <template v-if="cmd.hasHandler"> |
| 55 | + <div class="label"> |
| 56 | + Execute — positional args as a JSON array |
| 57 | + </div> |
| 58 | + <textarea :value="argsInput[cmd.id]" class="args" spellcheck="false" placeholder="[]" @input="emit('updateArgs', cmd.id, ($event.target as HTMLTextAreaElement).value)" /> |
| 59 | + <div style="margin-top: 8px; display: flex; gap: 8px; align-items: center;"> |
| 60 | + <ActionButton |
| 61 | + variant="primary" |
| 62 | + size="sm" |
| 63 | + icon="i-ph-play-duotone" |
| 64 | + :loading="pending[cmd.id]" |
| 65 | + :disabled="pending[cmd.id] || isStatic" |
| 66 | + @click.stop="emit('execute', cmd)" |
| 67 | + > |
| 68 | + {{ pending[cmd.id] ? 'Running…' : 'Run' }} |
| 69 | + </ActionButton> |
| 70 | + <span v-if="isStatic" class="note">read-only static backend — execution disabled</span> |
| 71 | + </div> |
| 72 | + <div v-if="results[cmd.id]" class="result"> |
| 73 | + <div class="result-head"> |
| 74 | + <span v-if="results[cmd.id].ok" class="ok">✓ resolved</span> |
| 75 | + <span v-else class="fail">✕ threw</span> |
| 76 | + <span v-if="'durationMs' in results[cmd.id]" class="muted">{{ results[cmd.id].durationMs }}ms</span> |
| 77 | + </div> |
| 78 | + <JsonView |
| 79 | + v-if="results[cmd.id].ok" |
| 80 | + :value="results[cmd.id].result" |
| 81 | + :expand-depth="2" |
| 82 | + /> |
| 83 | + <JsonView v-else :value="results[cmd.id].error" :expand-depth="2" /> |
| 84 | + </div> |
| 85 | + </template> |
| 86 | + <p v-else-if="!cmd.children?.length" class="note"> |
| 87 | + Group-only command — no handler to run. |
| 88 | + </p> |
| 89 | + |
| 90 | + <template v-if="cmd.children?.length"> |
| 91 | + <div class="label"> |
| 92 | + Children |
| 93 | + </div> |
| 94 | + <div class="cmd-children"> |
| 95 | + <CommandRow |
| 96 | + v-for="child in cmd.children" |
| 97 | + :key="child.id" |
| 98 | + :cmd="child" |
| 99 | + :args-input="argsInput" |
| 100 | + :results="results" |
| 101 | + :pending="pending" |
| 102 | + :is-static="isStatic" |
| 103 | + :depth="(depth ?? 0) + 1" |
| 104 | + @execute="emit('execute', $event)" |
| 105 | + @update-args="(id, value) => emit('updateArgs', id, value)" |
| 106 | + /> |
| 107 | + </div> |
| 108 | + </template> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | +</template> |
0 commit comments