docs(ctx-menu): 右键菜单规范化 + 静态守卫,防止再被插件注入回一长串
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 2m42s

用户要求把这次右键菜单精简记成规范,避免以后反复。

- docs/standards/ctx-menu.md(新增):当前菜单结构、排除名单表、名单位置与匹配规则
  (id 尾段 + 中文标题兜底)、增删流程、验证方法、历史与「为什么会反复」
- scripts/ctx-menu-audit.js(新增):静态断言名单常量、两处过滤、关键 id 仍在;
  已接进 verify:ci(build → check-dist 之后跑,失败即红)
- docs/README.md / docs/standards/ui-change-checklist.md:加索引与「动右键菜单先读本篇」提示
This commit is contained in:
qiqi committed 2026-11-27 22:55:56 +08:00
1 parent b901d3deb1
commit af86fa503e
5 files changed
+92 -1

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
'use strict'
// 右键菜单守卫(v3.26.109):插件会自动往菜单里注入节点类型与命令,宿主的排除名单一旦被
// 顺手删掉,菜单就会悄悄变回一长串用不到的入口(2026-11-27 刚按使用频率精简过一轮)。
// 这里做静态断言:名单常量在、两项过滤在、关键 id 在名单里。文档见 docs/standards/ctx-menu.md。
const fs = require('fs')
const path = require('path')
const app = fs.readFileSync(path.join(__dirname, '..', 'app.js'), 'utf8')
let fail = 0
const check = (name, cond, hint) => {
if (cond) { console.log(' PASS ' + name); return }
fail++
console.error(' FAIL ' + name + (hint ? ' —— ' + hint : ''))
}
console.log('ctx-menu: 右键菜单排除名单与过滤点')
check('CTX_SKIP_VARIANTS 名单存在', /const CTX_SKIP_VARIANTS = \[/.test(app), 'app.js 顶部应保留该常量(见 docs/standards/ctx-menu.md)')
check('CTX_SKIP_COMMANDS 名单存在', /const CTX_SKIP_COMMANDS = \[/.test(app))
check('插件节点过滤已应用', app.indexOf('pluginNodeVariants.filter((v) => !ctxSkippedVariant(v))') >= 0, '插件节点渲染处必须过滤')
check('插件命令过滤已应用', app.indexOf('wPluginCommands.filter((c) => !ctxSkippedCommand(c))') >= 0, '插件命令渲染处必须过滤')
const variants = (/const CTX_SKIP_VARIANTS = \[([^\]]*)\]/.exec(app) || [])[1] || ''
const commands = (/const CTX_SKIP_COMMANDS = \[([^\]]*)\]/.exec(app) || [])[1] || ''
for (const id of ['ptpl', 'style']) check('变体名单含 ' + id, variants.indexOf("'" + id + "'") >= 0)
for (const id of ['image-annotate', 'image-vectorize', 'collect-selected']) check('命令名单含 ' + id, commands.indexOf("'" + id + "'") >= 0)
if (fail) { console.error('ctx-menu-audit: ' + fail + ' 项失败'); process.exit(1) }
console.log('ctx-menu-audit: 通过')