Files
pixelheros/extensions/pixelhero-config-editor/src/panels/default/app.ts
panFD 24b5c49891 feat(config-editor): extension entry + minimal Vue panel proving end-to-end IPC
Task 12 of plan 2026-06-20-config-editor-foundation. Adds:
- src/main/index.ts: onLoad + message handlers (return value = request resolve,
  per Cocos 3.x verified IPC mechanism; fallback note left in plan)
- src/panels/default/{index,app}.ts: Editor.Panel.define host + Vue 3 minimal
  app (table switcher, key list, record JSON dump)
- static/template/default/index.html + static/style/default/index.css

Deviation from plan (necessary, flagged): esbuild.config.mjs now marks
node:fs/node:path as external for the panel entry (platform:'browser').
The plan's panel reads static template/style at runtime via Node fs, which
requires these builtins; Cocos panel runs in an Electron renderer that
provides them. Without this, esbuild errors with 'Could not resolve node:fs'.

Build verified: dist/main.js (9.5mb, typescript compiler API bundled) and
dist/panels/default.js (628kb, vue.esm-bundler bundled) both generate.
2026-06-21 09:56:02 +08:00

39 lines
1.5 KiB
TypeScript

import { createApp, defineComponent, reactive } from 'vue';
export const App = defineComponent({
setup() {
const state = reactive({ table: 'hero' as string, keys: [] as string[], picked: '' as string, detail: '' as string });
async function load() {
const keys = await Editor.Message.request('pixelhero-config-editor', 'query-keys', state.table);
state.keys = keys || [];
state.picked = ''; state.detail = '';
}
async function pick(k: string) {
state.picked = k;
const v = await Editor.Message.request('pixelhero-config-editor', 'query-record', state.table, k);
state.detail = JSON.stringify(v, null, 2);
}
load();
return { state, load, pick };
},
template: `
<div>
<div class="row">
<label>表:</label>
<select v-model="state.table" @change="load">
<option value="hero">英雄/怪物</option>
<option value="skill">技能</option>
<option value="field">驻场技能</option>
</select>
<span style="margin-left:12px;color:#888">共 {{ state.keys.length }} 条(端到端 IPC 已打通)</span>
</div>
<ul>
<li v-for="k in state.keys" :key="k" @click="pick(k)" :style="state.picked===k ? 'font-weight:bold' : ''">{{ k }}</li>
</ul>
<pre v-if="state.detail" style="white-space:pre-wrap;background:var(--color-normal-fill);padding:8px">{{ state.detail }}</pre>
</div>
`,
});
export function mount(el: HTMLElement) { createApp(App).mount(el); }