dsh-postapi 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +139 -2
- package/cordis.patch.yml +3 -0
- package/dist/client.js +5651 -0
- package/docs/DETAIL.md +27 -0
- package/docs/apifox-design-spec.md +101 -0
- package/docs/apifox-research/analysis.md +254 -0
- package/docs/apifox-ui-delivery.md +150 -0
- package/docs/apifox-visual-parity-spec.md +353 -0
- package/docs/feature-matrix.md +112 -0
- package/docs/flow-reference/sequence-reference.html +163 -0
- package/docs/interface-contract-v2.md +175 -0
- package/docs/interface-contract.md +105 -0
- package/docs/nav-layout-v2-spec.md +107 -0
- package/docs/preview.svg +9 -0
- package/docs/probe-client.legacy.js +31 -0
- package/docs/rootcause-sidebar-vanish.md +95 -0
- package/docs/rootcause.md +86 -0
- package/docs/sidebar-notes.md +153 -0
- package/docs/ui-audit.md +197 -0
- package/docs/ui-notes.md +98 -0
- package/docs/v2-delivery.md +99 -0
- package/icon.svg +4 -0
- package/index.js +5 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +73 -4
- package/src/client/index.js +132 -0
- package/src/client/jsx-shim.js +9 -0
- package/src/client/pages/__tests__/heights.test.js +135 -0
- package/src/client/pages/components/AssertTable.jsx +122 -0
- package/src/client/pages/components/BodyEditor.jsx +91 -0
- package/src/client/pages/components/EmptyState.jsx +52 -0
- package/src/client/pages/components/FolderTree.jsx +109 -0
- package/src/client/pages/components/JsonEditor.jsx +45 -0
- package/src/client/pages/components/ParamTable.jsx +226 -0
- package/src/client/pages/components/ResponsePanel.jsx +278 -0
- package/src/client/pages/components/ScriptPanel.jsx +99 -0
- package/src/client/pages/components/StatusPill.jsx +35 -0
- package/src/client/pages/components/__tests__/apifox-ui.test.js +291 -0
- package/src/client/pages/components/__tests__/pages-a.test.js +392 -0
- package/src/client/pages/components/__tests__/tree.test.js +379 -0
- package/src/client/pages/components/headerPresets.js +63 -0
- package/src/client/pages/debug.jsx +576 -0
- package/src/client/pages/design-tokens.css +2604 -0
- package/src/client/pages/doc.jsx +552 -0
- package/src/client/pages/env.jsx +378 -0
- package/src/client/pages/flow.jsx +349 -0
- package/src/client/pages/history.jsx +238 -0
- package/src/client/pages/import.jsx +396 -0
- package/src/client/pages/mock.jsx +316 -0
- package/src/client/pages/overview.jsx +348 -0
- package/src/client/pages/schema.jsx +317 -0
- package/src/client/pages/search.jsx +216 -0
- package/src/client/pages/sequence.jsx +344 -0
- package/src/client/pages/settings.jsx +205 -0
- package/src/client/pages/test.jsx +470 -0
- package/src/client/pages/theme.js +27 -0
- package/src/client/pages-entry.js +20 -0
- package/src/client/shell/ApiTitle.js +19 -0
- package/src/client/shell/Body.js +492 -0
- package/src/client/shell/definition.js +57 -0
- package/src/client/shell/locales.js +185 -0
- package/src/client/shell/menu.js +174 -0
- package/src/client/shell/registry.js +530 -0
- package/src/host/bridge.js +407 -0
- package/src/host/codegen.js +356 -0
- package/src/host/import-export.js +1044 -0
- package/src/host/index.js +102 -0
- package/src/host/mock-server.js +303 -0
- package/src/host/request.js +336 -0
- package/src/host/script-sandbox.js +272 -0
- package/src/host/storage.js +803 -0
- package/src/host/test-runner.js +126 -0
- package/src/host/variables.js +108 -0
package/package.json
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-postapi",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "DSH plugin: Apifox-style API workspace (docs, debug, mock, schema, env, history, tests, import/export, flow, search) inside the official right sidebar",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"author": "mengqi1436",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"dsh",
|
|
11
|
+
"deepseek-harness",
|
|
12
|
+
"dsh-plugin",
|
|
13
|
+
"apifox",
|
|
14
|
+
"api-client",
|
|
15
|
+
"postman",
|
|
16
|
+
"openapi",
|
|
17
|
+
"mock-server"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/mengqi1436/dsh-postapi.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/mengqi1436/dsh-postapi/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/mengqi1436/dsh-postapi#readme",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22",
|
|
29
|
+
"dsh": ">=0.2.1-rc.2 <0.3.0-0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "node build.mjs",
|
|
33
|
+
"test": "node tests/run.js",
|
|
34
|
+
"smoke": "node scripts/smoke-host.mjs",
|
|
35
|
+
"verify": "node build.mjs && node tests/run.js && node scripts/smoke-host.mjs",
|
|
36
|
+
"prepack": "node build.mjs",
|
|
37
|
+
"prepublishOnly": "node build.mjs && node tests/run.js"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": "./index.js",
|
|
41
|
+
"./client": "./dist/client.js",
|
|
42
|
+
"./package.json": "./package.json",
|
|
43
|
+
"./locale/*.json": "./locale/*.json",
|
|
44
|
+
"./icon": "./icon.svg"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"index.js",
|
|
48
|
+
"src",
|
|
49
|
+
"dist/client.js",
|
|
50
|
+
"cordis.patch.yml",
|
|
51
|
+
"locale/*.json",
|
|
52
|
+
"docs",
|
|
53
|
+
"icon.svg",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE"
|
|
56
|
+
],
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"esbuild": "0.28.2"
|
|
62
|
+
},
|
|
63
|
+
"dsh": {
|
|
64
|
+
"bundle": {
|
|
65
|
+
"patch": "./cordis.patch.yml"
|
|
66
|
+
},
|
|
67
|
+
"client": {
|
|
68
|
+
"platform": "web",
|
|
69
|
+
"inject": [
|
|
70
|
+
"@deepseek-ai/dsh-client-locale",
|
|
71
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right"
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-postapi 客户端入口:官方右侧栏接线 + 同源 HTTP 桥 api + 页面注册表 +
|
|
3
|
+
* composer.dock 徽章(契约 §4 保留)。
|
|
4
|
+
*
|
|
5
|
+
* 接线对照样板 @deepseek-ai/dsh-client-ui-sidebar-files@0.2.2-rc.3
|
|
6
|
+
* src/client/index.ts 的 apply():所有 register/inject 返回的 disposer 都由
|
|
7
|
+
* ctx.effect 包裹,插件卸载即随 effect 释放。
|
|
8
|
+
*/
|
|
9
|
+
import { createElement } from 'react'
|
|
10
|
+
import { POSTAPI_ID, postapiDefinition } from './shell/definition.js'
|
|
11
|
+
import { POSTAPI_NS, zh, en } from './shell/locales.js'
|
|
12
|
+
import { PostApiBody } from './shell/Body.js'
|
|
13
|
+
import { ApiTitle } from './shell/ApiTitle.js'
|
|
14
|
+
import { ensureGlobals, installApi } from './shell/registry.js'
|
|
15
|
+
import designTokensCss from './pages/design-tokens.css'
|
|
16
|
+
import './pages-entry.js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 把 design-tokens.css 注入页面。
|
|
20
|
+
*
|
|
21
|
+
* 宿主 __ModuleLoader__ 只加载 CJS 模块、没有 CSS 入口,样式表必须以文本形式打进产物
|
|
22
|
+
* 再由 client 自己插 <style>(带 data-plugin 标记,宿主卸载插件时会一并清掉)。
|
|
23
|
+
* 缺这一步所有 .pp-* 类都不生效,页面退化成无样式裸 HTML。
|
|
24
|
+
* @returns 卸载函数(移除本插件注入的 style 节点)。
|
|
25
|
+
*/
|
|
26
|
+
function installStyles() {
|
|
27
|
+
if (typeof document === 'undefined') return () => {}
|
|
28
|
+
const existing = document.querySelector('style[data-plugin="dsh-postapi"]')
|
|
29
|
+
if (existing) return () => { existing.remove() }
|
|
30
|
+
const el = document.createElement('style')
|
|
31
|
+
el.setAttribute('data-plugin', 'dsh-postapi')
|
|
32
|
+
el.setAttribute('data-plugin-css', 'design-tokens')
|
|
33
|
+
el.textContent = designTokensCss
|
|
34
|
+
document.head.append(el)
|
|
35
|
+
return () => { el.remove() }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 客户端依赖的宿主 face:全部为内置 face(宿主总线不提供插件自定义 face)。 */
|
|
39
|
+
export const inject = ['slots', 'locale', 'sidebarRightTabs']
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* ctx.effect 的安全包装。
|
|
43
|
+
*
|
|
44
|
+
* cordis 的 Fiber#_execute 只接受 effect body 返回「函数 / null / Promise / 同步或异步迭代器」;
|
|
45
|
+
* 返回普通对象(例如 register 把注册记录对象当返回值)会抛 TypeError('Invalid effect'),
|
|
46
|
+
* 整个 apply 随之失败,宿主回滚本 entry 的全部注册——页签因此完全消失且只有一条
|
|
47
|
+
* 「1 entry did not activate」警告。这里把任何非函数、非 null 的返回值丢掉并记一条 warn,
|
|
48
|
+
* 让单个注册点的形态差异不至于拖垮整条注册链。
|
|
49
|
+
* @param ctx - 客户端根上下文。
|
|
50
|
+
* @param label - effect 标签(诊断用)。
|
|
51
|
+
* @param body - effect body,返回值被归一化。
|
|
52
|
+
* @returns 无。
|
|
53
|
+
*/
|
|
54
|
+
function safeEffect(ctx, label, body) {
|
|
55
|
+
ctx.effect(() => {
|
|
56
|
+
const result = body()
|
|
57
|
+
if (result === undefined || result === null) return undefined
|
|
58
|
+
if (typeof result === 'function') return result
|
|
59
|
+
if (typeof result.then === 'function' || typeof result[Symbol.iterator] === 'function' || typeof result[Symbol.asyncIterator] === 'function') return result
|
|
60
|
+
console.warn('[dsh-postapi] ' + label + ' 返回了非 disposer 值(已忽略):', typeof result)
|
|
61
|
+
return undefined
|
|
62
|
+
}, label)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 会话输入框底栏徽章(conversation.composer.dock,骨架已验证的官方 slot)。 */
|
|
66
|
+
function ComposerBadge() {
|
|
67
|
+
return createElement('svg', {
|
|
68
|
+
viewBox: '0 0 64 64', width: 16, height: 16, 'aria-hidden': true,
|
|
69
|
+
style: { display: 'block', pointerEvents: 'none' },
|
|
70
|
+
}, createElement('path', { d: 'M6 50 L54 26 L6 8 L6 24 L36 26 L6 28 Z', fill: 'currentColor' }))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 客户端插件体。
|
|
75
|
+
* @param ctx - 客户端根上下文(携带 slots/locale/sidebarRightTabs 与 postapi.* face)。
|
|
76
|
+
*/
|
|
77
|
+
export function apply(ctx) {
|
|
78
|
+
// 自诊断:确认 client 半边是否被宿主执行(定位「右栏无入口」时用,稳定后可删)。
|
|
79
|
+
console.info('[dsh-postapi] client apply 已执行', { hasTabs: !!ctx.sidebarRightTabs, hasSlots: !!ctx.slots, hasLocale: !!ctx.locale })
|
|
80
|
+
ensureGlobals()
|
|
81
|
+
// 服务缺失时 warn 后返回(不抛错、不注册):与 db-tool 一致。宿主 ctx 若未提供
|
|
82
|
+
// 右侧栏两件套,硬调 register 会抛错并被宿主记为加载失败,整插件连字典都不生效。
|
|
83
|
+
if (!ctx.sidebarRightTabs || !ctx.slots) {
|
|
84
|
+
console.warn('[dsh-postapi] 宿主未提供 sidebarRightTabs / slots 服务,右侧栏页签不会挂载')
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
// locale 为内置 face,正常必在;缺失时回落中文原文,不让文案取用拖垮注册链。
|
|
88
|
+
const t = ctx.locale ? ctx.locale.bind(POSTAPI_NS) : (key) => zh[key] ?? key
|
|
89
|
+
|
|
90
|
+
// 0. 样式表注入:先于任何注册执行,保证页面首次渲染就带样式。
|
|
91
|
+
safeEffect(ctx, 'dsh-postapi: design tokens', () => installStyles())
|
|
92
|
+
// 1. 页签类型声明:keepMounted + guide 单入口直开(契约 §4)。
|
|
93
|
+
safeEffect(ctx, 'dsh-postapi: postapi tab type', () => ctx.sidebarRightTabs.register(postapiDefinition(t)))
|
|
94
|
+
// 2. 'postapi' 命名空间字典。
|
|
95
|
+
if (ctx.locale) {
|
|
96
|
+
safeEffect(ctx, 'dsh-postapi: dictionaries', () => ctx.locale.register(POSTAPI_NS, { zh, en }))
|
|
97
|
+
}
|
|
98
|
+
// 3. 页签 body:席位 key = definition.id(POSTAPI_ID,不拼 localeKey)。
|
|
99
|
+
safeEffect(ctx, 'dsh-postapi: tab body', () => ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register(
|
|
100
|
+
{ name: 'sidebar.right.pane.tab', key: POSTAPI_ID, locale: POSTAPI_NS },
|
|
101
|
+
PostApiBody,
|
|
102
|
+
)))
|
|
103
|
+
// 4. 页签 chip 标题。
|
|
104
|
+
safeEffect(ctx, 'dsh-postapi: tab title', () => ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register(
|
|
105
|
+
{ name: 'sidebar.right.pane.tab.title', key: POSTAPI_ID },
|
|
106
|
+
ApiTitle,
|
|
107
|
+
)))
|
|
108
|
+
// 5. composer.dock 徽章:该 slot 由 conversation 插件提供,未安装时 inject 会抛错;
|
|
109
|
+
// 软失败处理,任何异常都不允许拖垮页签注册链(页签是主功能)。
|
|
110
|
+
try {
|
|
111
|
+
safeEffect(ctx, 'dsh-postapi: composer badge', () => ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register(
|
|
112
|
+
{ name: 'conversation.composer.dock', id: 'dsh-postapi', order: 5 },
|
|
113
|
+
ComposerBadge,
|
|
114
|
+
)))
|
|
115
|
+
} catch (err) {
|
|
116
|
+
console.warn('[dsh-postapi] composer 徽章未注册(slot 提供方缺失):', err && err.message)
|
|
117
|
+
}
|
|
118
|
+
// 6. 同源 HTTP 桥(db-tool 同款):宿主 face 总线只提供内置 face,postapi.*
|
|
119
|
+
// 无法注册为自定义 face;window.__postapiApi 经 fetch('/dsh-postapi/api/…')
|
|
120
|
+
// 调用宿主桥路由,桥不可达时自动降级内存桩(契约 §2 签名不变)。
|
|
121
|
+
//
|
|
122
|
+
// 注意 effect body 必须返回「disposer 函数 / null / Promise / 迭代器」之一:
|
|
123
|
+
// cordis 的 Fiber#_execute 收到普通对象会抛 TypeError('Invalid effect'),
|
|
124
|
+
// 整个 apply 随之失败,宿主回滚本 entry 的全部注册(页签因此消失)。
|
|
125
|
+
// installApi() 的返回值是 api 对象,只能丢弃,disposer 里清掉挂载点。
|
|
126
|
+
safeEffect(ctx, 'dsh-postapi: bridge api install', () => {
|
|
127
|
+
installApi()
|
|
128
|
+
return () => {
|
|
129
|
+
if (typeof window !== 'undefined' && window.__postapiApi) delete window.__postapiApi
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX 工厂注入源(esbuild inject)。
|
|
3
|
+
*
|
|
4
|
+
* build.mjs 用 jsx: 'transform'(classic runtime)出包,产物只 require('react'),
|
|
5
|
+
* 不依赖 react/jsx-runtime —— 宿主 __ModuleLoader__ 的 require 只保证给到 react。
|
|
6
|
+
* 页面/骨架源码里的 JSX 编译成 createElement(...) / Fragment,这两个自由标识符
|
|
7
|
+
* 由本 shim 提供(esbuild 官方 inject 用法)。
|
|
8
|
+
*/
|
|
9
|
+
export { createElement, Fragment } from 'react'
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// heights.test.js — 等高一致性静态检查(契约 §7「所有控件高度来自 token」)
|
|
2
|
+
// 双模式运行:
|
|
3
|
+
// 1) node src/client/pages/__tests__/heights.test.js —— 自建 mini runner 直接执行(参考 tests/run.js 模式)
|
|
4
|
+
// 2) vitest 环境 —— import { run } 后在 test() 中断言 run().failures.length === 0(lead 统一接线)
|
|
5
|
+
// 扫描范围:design-tokens.css 全部 height 类声明 + 六个页面组件的内联 style 高度
|
|
6
|
+
import { readFileSync, existsSync } from 'node:fs'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
import { dirname, join, resolve } from 'node:path'
|
|
9
|
+
|
|
10
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
11
|
+
const PAGES_DIR = resolve(__dirname, '..')
|
|
12
|
+
|
|
13
|
+
const CSS_FILE = join(PAGES_DIR, 'design-tokens.css')
|
|
14
|
+
// 参与高度纪律扫描的页面组件(theme.js 无样式,不参与)
|
|
15
|
+
const PAGE_FILES = [
|
|
16
|
+
'overview.jsx', 'doc.jsx', 'debug.jsx', 'mock.jsx', 'schema.jsx', 'env.jsx',
|
|
17
|
+
'history.jsx', 'test.jsx', 'import.jsx', 'flow.jsx', 'search.jsx', 'settings.jsx',
|
|
18
|
+
'sequence.jsx',
|
|
19
|
+
]
|
|
20
|
+
const REGISTERED_PAGES = [
|
|
21
|
+
'overview', 'doc', 'debug', 'mock', 'schema', 'env',
|
|
22
|
+
'history', 'test', 'import', 'flow', 'search', 'settings',
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
// 允许的高度值:尺寸 token 引用 / 含 token 或 100% 的 calc / 自适应关键字
|
|
26
|
+
// 尺寸 token 家族:主控件 / 小控件 / 大控件 / 行 / 胶囊 / 顶栏(Apifox 版新增三档控件高)
|
|
27
|
+
const TOKEN_HEIGHT_RE = /^var\(--(ctl-h|ctl-h-sm|ctl-h-lg|row-h|tree-row-h|pill-h|topbar-h|tabbar-h|sider-item-h|sider-group-h|hit|sider-w|content-max-w)\)$/
|
|
28
|
+
const AUTO_VALUES = new Set(['100%', 'auto', 'inherit', 'fit-content', 'min-content', 'max-content'])
|
|
29
|
+
|
|
30
|
+
function checkHeightValue(value) {
|
|
31
|
+
const v = String(value).trim()
|
|
32
|
+
if (TOKEN_HEIGHT_RE.test(v)) return null
|
|
33
|
+
if (AUTO_VALUES.has(v)) return null
|
|
34
|
+
if (v === '0') return null
|
|
35
|
+
// calc 里只要引用 token 变量或 100% 就算合规(滚动条、分段高度等派生值都走 calc)
|
|
36
|
+
if (/^calc\(/.test(v) && /var\(--|100%/.test(v)) return null
|
|
37
|
+
return '高度值未引用尺寸 token(--ctl-h/--row-h/--pill-h)'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// CSS 逐行扫描(design-tokens.css 每行一条声明;token 定义 --x: 28px 不匹配 height 属性名)
|
|
41
|
+
const CSS_LINE_RE = /^\s*(min-height|max-height|height)\s*:\s*(.+?);?\s*$/
|
|
42
|
+
// JSX 内联样式扫描:style={{ height: '...' }} 或 style="height: ..."(字符串值)
|
|
43
|
+
const JSX_LINE_RE = /\b(minHeight|maxHeight|height|min-height|max-height|height)\s*:\s*['"`]([^'"`]+)['"`]/g
|
|
44
|
+
|
|
45
|
+
export function run() {
|
|
46
|
+
const failures = []
|
|
47
|
+
let checks = 0
|
|
48
|
+
|
|
49
|
+
// 1) 尺寸 token 定义存在且取值正确(契约 §5)
|
|
50
|
+
if (!existsSync(CSS_FILE)) {
|
|
51
|
+
failures.push('design-tokens.css 不存在')
|
|
52
|
+
return { failures, checks }
|
|
53
|
+
}
|
|
54
|
+
const css = readFileSync(CSS_FILE, 'utf8')
|
|
55
|
+
const tokenDefs = {
|
|
56
|
+
'--ctl-h': /--ctl-h:\s*32px/.test(css),
|
|
57
|
+
'--ctl-h-sm': /--ctl-h-sm:\s*24px/.test(css),
|
|
58
|
+
'--ctl-h-lg': /--ctl-h-lg:\s*40px/.test(css),
|
|
59
|
+
'--row-h': /--row-h:\s*32px/.test(css),
|
|
60
|
+
'--tree-row-h': /--tree-row-h:\s*22px/.test(css),
|
|
61
|
+
'--pill-h': /--pill-h:\s*22px/.test(css),
|
|
62
|
+
'--topbar-h': /--topbar-h:\s*48px/.test(css),
|
|
63
|
+
'--tabbar-h': /--tabbar-h:\s*44px/.test(css),
|
|
64
|
+
'--sider-w': /--sider-w:\s*240px/.test(css),
|
|
65
|
+
'--sider-item-h': /--sider-item-h:\s*32px/.test(css),
|
|
66
|
+
'--sider-group-h': /--sider-group-h:\s*24px/.test(css),
|
|
67
|
+
'--content-max-w': /--content-max-w:\s*1512px/.test(css),
|
|
68
|
+
'--hit': /--hit:\s*28px/.test(css),
|
|
69
|
+
}
|
|
70
|
+
for (const [name, ok] of Object.entries(tokenDefs)) {
|
|
71
|
+
checks++
|
|
72
|
+
if (!ok) failures.push(`design-tokens.css: 尺寸 token ${name} 缺失或取值偏离契约(28/32/20)`)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 2) CSS 中所有高度声明必须引用 token
|
|
76
|
+
for (const [i, line] of css.split('\n').entries()) {
|
|
77
|
+
const m = CSS_LINE_RE.exec(line)
|
|
78
|
+
if (!m) continue
|
|
79
|
+
checks++
|
|
80
|
+
const err = checkHeightValue(m[2])
|
|
81
|
+
if (err) failures.push(`design-tokens.css:${i + 1}: ${m[1]}: ${m[2].trim()} — ${err}`)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 3) 页面组件内联高度必须合规;4) 五页面自注册
|
|
85
|
+
for (const file of PAGE_FILES) {
|
|
86
|
+
const full = join(PAGES_DIR, file)
|
|
87
|
+
if (!existsSync(full)) {
|
|
88
|
+
failures.push(`${file} 不存在`)
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
const src = readFileSync(full, 'utf8')
|
|
92
|
+
let m
|
|
93
|
+
JSX_LINE_RE.lastIndex = 0
|
|
94
|
+
while ((m = JSX_LINE_RE.exec(src))) {
|
|
95
|
+
checks++
|
|
96
|
+
const err = checkHeightValue(m[2])
|
|
97
|
+
if (err) {
|
|
98
|
+
const lineNo = src.slice(0, m.index).split('\n').length
|
|
99
|
+
failures.push(`${file}:${lineNo}: 内联 ${m[1]}: ${m[2]} — ${err}`)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const pageId of REGISTERED_PAGES) {
|
|
104
|
+
checks++
|
|
105
|
+
const full = join(PAGES_DIR, pageId + '.jsx')
|
|
106
|
+
const src = existsSync(full) ? readFileSync(full, 'utf8') : ''
|
|
107
|
+
// 两种合法形态:直接注册(window.__postapiPages?.register?.)或队列注册(ensureGlobals 统一重放)
|
|
108
|
+
const direct = new RegExp(`window\\.__postapiPages\\?\\.register\\?\\.\\('${pageId}'`)
|
|
109
|
+
const queued = new RegExp(`__postapiQueue[^;\\n]*\\.push\\(\\['${pageId}'`)
|
|
110
|
+
if (!direct.test(src) && !queued.test(src)) failures.push(`${pageId}.jsx: 缺少自注册(register 或 __postapiQueue push)`)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return { failures, checks }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// —— mini runner:node 直接执行时输出结果并返回退出码 ——
|
|
117
|
+
const isMain = (() => {
|
|
118
|
+
try {
|
|
119
|
+
const argv1 = process.argv[1]
|
|
120
|
+
return Boolean(argv1) && resolve(argv1) === fileURLToPath(import.meta.url)
|
|
121
|
+
} catch {
|
|
122
|
+
return false
|
|
123
|
+
}
|
|
124
|
+
})()
|
|
125
|
+
|
|
126
|
+
if (isMain) {
|
|
127
|
+
const { failures, checks } = run()
|
|
128
|
+
for (const f of failures) console.error('FAIL ' + f)
|
|
129
|
+
if (failures.length === 0) {
|
|
130
|
+
console.log(`heights.test: PASS (${checks} checks)`)
|
|
131
|
+
} else {
|
|
132
|
+
console.log(`heights.test: ${failures.length} failure(s) / ${checks} checks`)
|
|
133
|
+
}
|
|
134
|
+
process.exit(failures.length === 0 ? 0 : 1)
|
|
135
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// AssertTable — 断言表(调试台「脚本」页签的一段:来源 / 路径 / 操作 / 期望值 / 说明 / 操作)
|
|
2
|
+
// 与 ParamTable 同口径:表格整体横向滚动交给外层 .pp-table-wrap,窄容器里不压塌列;
|
|
3
|
+
// 组件是纯受控渲染,任何增删改都把「完整新数组」回传给 onChange(不传 patch)。
|
|
4
|
+
// 常量与选项放在本文件,由 ScriptPanel 再导出,避免两个组件互相 import 形成环。
|
|
5
|
+
|
|
6
|
+
/** 断言来源:与 Apifox 的断言目标一致(状态码 / 响应体 / 响应头 / 耗时)。 */
|
|
7
|
+
export const ASSERT_SOURCES = ['status', 'body', 'header', 'time']
|
|
8
|
+
|
|
9
|
+
/** 断言操作符:eq / neq / gt / lt / contains / notContains / exists / notExists / regex。 */
|
|
10
|
+
export const ASSERT_OPS = ['eq', 'neq', 'gt', 'lt', 'contains', 'notContains', 'exists', 'notExists', 'regex']
|
|
11
|
+
|
|
12
|
+
/** 列定义:标题一处写死,表头与单元格共用(宽度合计由 .pp-table-wide 的 min-width 兜住)。 */
|
|
13
|
+
export const ASSERT_COLUMNS = [
|
|
14
|
+
{ field: 'source', title: '来源' },
|
|
15
|
+
{ field: 'path', title: '路径', mono: true },
|
|
16
|
+
{ field: 'op', title: '操作' },
|
|
17
|
+
{ field: 'value', title: '期望值', mono: true },
|
|
18
|
+
{ field: 'message', title: '说明' },
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
/** 新增断言行模板:默认断言状态码等于某值,用户只需要填期望值。 */
|
|
22
|
+
export function blankAssertRow() {
|
|
23
|
+
return { source: 'status', path: '', op: 'eq', value: '', message: '' }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 单元格输入框类名:表格内编辑无边框,聚焦才显边框(与 ParamTable 的 .pp-cell-input 一致)。 */
|
|
27
|
+
function cellInputClass(mono) {
|
|
28
|
+
return 'pp-cell-input pp-input-sm' + (mono ? ' pp-input-mono' : '')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function renderCell(row, column, index, patch) {
|
|
32
|
+
const value = row ? row[column.field] : undefined
|
|
33
|
+
const text = value == null ? '' : String(value)
|
|
34
|
+
|
|
35
|
+
if (column.field === 'source') {
|
|
36
|
+
return (
|
|
37
|
+
<select className="pp-cell-input pp-input-sm" value={text || ASSERT_SOURCES[0]}
|
|
38
|
+
onChange={(e) => patch(index, column.field, e.target.value)}>
|
|
39
|
+
{ASSERT_SOURCES.map((s) => <option key={s} value={s}>{s}</option>)}
|
|
40
|
+
</select>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
if (column.field === 'op') {
|
|
44
|
+
return (
|
|
45
|
+
<select className="pp-cell-input pp-input-sm" value={text || ASSERT_OPS[0]}
|
|
46
|
+
onChange={(e) => patch(index, column.field, e.target.value)}>
|
|
47
|
+
{ASSERT_OPS.map((o) => <option key={o} value={o}>{o}</option>)}
|
|
48
|
+
</select>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
return (
|
|
52
|
+
<input
|
|
53
|
+
className={cellInputClass(column.mono)}
|
|
54
|
+
value={text}
|
|
55
|
+
onChange={(e) => patch(index, column.field, e.target.value)}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param rows 断言行数组,缺省按空表处理
|
|
62
|
+
* @param onChange 收到完整新数组(增行 / 删行 / 改字段都是整表回传)
|
|
63
|
+
*/
|
|
64
|
+
export function AssertTable({ rows, onChange }) {
|
|
65
|
+
const list = Array.isArray(rows) ? rows : []
|
|
66
|
+
const emit = (next) => {
|
|
67
|
+
if (typeof onChange === 'function') onChange(next)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 单字段改动:整表浅拷贝后替换本行,保持 onChange 的「完整数组」语义。 */
|
|
71
|
+
const patch = (index, field, value) => {
|
|
72
|
+
const next = list.slice()
|
|
73
|
+
next[index] = { ...next[index], [field]: value }
|
|
74
|
+
emit(next)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const remove = (index) => {
|
|
78
|
+
const next = list.slice()
|
|
79
|
+
next.splice(index, 1)
|
|
80
|
+
emit(next)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const add = () => emit(list.concat([blankAssertRow()]))
|
|
84
|
+
|
|
85
|
+
const colSpan = ASSERT_COLUMNS.length + 1
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<table className="pp-table pp-table-wide">
|
|
89
|
+
<thead>
|
|
90
|
+
<tr>
|
|
91
|
+
{ASSERT_COLUMNS.map((column) => (
|
|
92
|
+
<th key={column.field} data-col={column.field}>{column.title}</th>
|
|
93
|
+
))}
|
|
94
|
+
<th data-col="op-cell">操作</th>
|
|
95
|
+
</tr>
|
|
96
|
+
</thead>
|
|
97
|
+
<tbody>
|
|
98
|
+
{list.length === 0 ? (
|
|
99
|
+
<tr>
|
|
100
|
+
<td colSpan={colSpan}>
|
|
101
|
+
<div className="pp-meta">暂无断言</div>
|
|
102
|
+
</td>
|
|
103
|
+
</tr>
|
|
104
|
+
) : list.map((row, index) => (
|
|
105
|
+
<tr key={index}>
|
|
106
|
+
{ASSERT_COLUMNS.map((column) => (
|
|
107
|
+
<td key={column.field} data-col={column.field}>{renderCell(row, column, index, patch)}</td>
|
|
108
|
+
))}
|
|
109
|
+
<td data-col="op-cell">
|
|
110
|
+
<button className="pp-btn pp-btn-sm pp-btn-ghost pp-btn-danger" onClick={() => remove(index)}>删除</button>
|
|
111
|
+
</td>
|
|
112
|
+
</tr>
|
|
113
|
+
))}
|
|
114
|
+
<tr>
|
|
115
|
+
<td colSpan={colSpan}>
|
|
116
|
+
<button className="pp-btn pp-btn-sm pp-btn-ghost pp-table-add" onClick={add}>+ 添加断言</button>
|
|
117
|
+
</td>
|
|
118
|
+
</tr>
|
|
119
|
+
</tbody>
|
|
120
|
+
</table>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// BodyEditor — 请求体编辑器(Apifox Body 页签:类型下拉 + 按类型切换编辑形态)
|
|
2
|
+
// 受控组件:value = { type, content, fields };任何改动都以「完整 value」回抛 onChange,
|
|
3
|
+
// 切类型只改 type,不清空用户已填的 content / fields(Apifox 切回来内容还在)。
|
|
4
|
+
// 纪律:不写颜色/字号字面量(走 .pp-* 类与 token);类名只用已存在的 .pp-* 与 .pp-body-*。
|
|
5
|
+
import { EmptyState } from './EmptyState.jsx'
|
|
6
|
+
import { ParamTable } from './ParamTable.jsx'
|
|
7
|
+
import { JsonEditor } from './JsonEditor.jsx'
|
|
8
|
+
|
|
9
|
+
/** Body 七种类型(Apifox Body 页签下拉口径,顺序即下拉顺序)。 */
|
|
10
|
+
export const BODY_TYPES = [
|
|
11
|
+
{ id: 'none', label: 'none' },
|
|
12
|
+
{ id: 'form', label: 'form-data' },
|
|
13
|
+
{ id: 'urlencoded', label: 'x-www-form-urlencoded' },
|
|
14
|
+
{ id: 'json', label: 'json' },
|
|
15
|
+
{ id: 'xml', label: 'xml' },
|
|
16
|
+
{ id: 'raw', label: 'raw' },
|
|
17
|
+
{ id: 'graphql', label: 'GraphQL' },
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
/** 键值表列:与 debug 页其它参数组同一套列定义(操作列由 ParamTable 自己追加)。 */
|
|
21
|
+
export const BODY_FIELD_COLUMNS = ['enabled', 'key', 'type', 'value', 'description']
|
|
22
|
+
|
|
23
|
+
/** 走键值表的两种类型,其余类型走文本编辑。 */
|
|
24
|
+
const TABLE_TYPES = ['form', 'urlencoded']
|
|
25
|
+
|
|
26
|
+
/** 文本编辑占位符:按类型给最小示例,避免四种类型共用 '{}' 误导用户。 */
|
|
27
|
+
const PLACEHOLDER = {
|
|
28
|
+
json: '{\n "key": "value"\n}',
|
|
29
|
+
xml: '<root>\n <item>value</item>\n</root>',
|
|
30
|
+
raw: '原始文本',
|
|
31
|
+
graphql: 'query {\n field\n}',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 归一化 value:缺字段按 none / 空串 / 空数组补齐;非法 type 回落 none(不让脏数据打崩页面)。 */
|
|
35
|
+
function normalize(value) {
|
|
36
|
+
const src = value && typeof value === 'object' ? value : {}
|
|
37
|
+
const type = BODY_TYPES.some((t) => t.id === src.type) ? src.type : 'none'
|
|
38
|
+
return {
|
|
39
|
+
type,
|
|
40
|
+
content: src.content == null ? '' : String(src.content),
|
|
41
|
+
fields: Array.isArray(src.fields) ? src.fields : [],
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param value { type, content, fields }
|
|
47
|
+
* @param onChange (next) => void,next 恒为完整 value
|
|
48
|
+
*/
|
|
49
|
+
export function BodyEditor({ value, onChange }) {
|
|
50
|
+
const body = normalize(value)
|
|
51
|
+
// 任何分支都回抛完整 value:调用方直接存盘即可,不用自己拼字段。
|
|
52
|
+
const emit = (patch) => {
|
|
53
|
+
if (typeof onChange === 'function') onChange({ ...body, ...patch })
|
|
54
|
+
}
|
|
55
|
+
const isTable = TABLE_TYPES.indexOf(body.type) >= 0
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div>
|
|
59
|
+
<div className="pp-body-head">
|
|
60
|
+
<label className="pp-form-label">类型</label>
|
|
61
|
+
<select
|
|
62
|
+
className="pp-select pp-input-sm"
|
|
63
|
+
value={body.type}
|
|
64
|
+
onChange={(e) => emit({ type: e.target.value })}
|
|
65
|
+
>
|
|
66
|
+
{BODY_TYPES.map((t) => <option key={t.id} value={t.id}>{t.label}</option>)}
|
|
67
|
+
</select>
|
|
68
|
+
</div>
|
|
69
|
+
{body.type === 'none' ? (
|
|
70
|
+
<EmptyState text="无请求体" hint="Body 类型选 none 时不发送请求体" />
|
|
71
|
+
) : isTable ? (
|
|
72
|
+
<div className="pp-table-wrap">
|
|
73
|
+
<ParamTable
|
|
74
|
+
rows={body.fields}
|
|
75
|
+
columns={BODY_FIELD_COLUMNS}
|
|
76
|
+
onChange={(rows) => emit({ fields: rows })}
|
|
77
|
+
emptyText="无表单字段"
|
|
78
|
+
addLabel="+ 添加字段"
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
81
|
+
) : (
|
|
82
|
+
<JsonEditor
|
|
83
|
+
value={body.content}
|
|
84
|
+
rows={10}
|
|
85
|
+
placeholder={PLACEHOLDER[body.type] || ''}
|
|
86
|
+
onChange={(next) => emit({ content: next })}
|
|
87
|
+
/>
|
|
88
|
+
)}
|
|
89
|
+
</div>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// EmptyState — 统一空态(居中图标 + 主文案 + 提示 + 可选动作,样式全部来自 .pp-empty)
|
|
2
|
+
// 之前是 1px 虚线大框 + 两行字,宽 460px 只放一句话,视觉上像一块未完成的占位。
|
|
3
|
+
// 现在收窄到 --empty-w、加图标位与可选按钮,信息层级更清楚(图标 → 文案 → 提示 → 动作)。
|
|
4
|
+
// 纪律:不引图标库(用内联 SVG path),颜色/字号/尺寸全部走 token。
|
|
5
|
+
import { createElement } from 'react'
|
|
6
|
+
|
|
7
|
+
/** 空态图标:24×24 stroke 风格,默认用「空盒子」。 */
|
|
8
|
+
const EMPTY_ICONS = {
|
|
9
|
+
box: ['M4 8.5L12 4l8 4.5v7L12 20l-8-4.5z', 'M12 12l8-4.5', 'M12 12v8', 'M12 12L4 7.5'],
|
|
10
|
+
search: ['M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14z', 'M20 20l-4.2-4.2'],
|
|
11
|
+
file: ['M6 3h8l4 4v14H6z', 'M14 3v4h4'],
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function EmptyIcon({ name = 'box' }) {
|
|
15
|
+
const paths = EMPTY_ICONS[name] || EMPTY_ICONS.box
|
|
16
|
+
return createElement('svg', {
|
|
17
|
+
viewBox: '0 0 24 24',
|
|
18
|
+
width: 28,
|
|
19
|
+
height: 28,
|
|
20
|
+
fill: 'none',
|
|
21
|
+
stroke: 'currentColor',
|
|
22
|
+
strokeWidth: 1.4,
|
|
23
|
+
strokeLinecap: 'round',
|
|
24
|
+
strokeLinejoin: 'round',
|
|
25
|
+
'aria-hidden': true,
|
|
26
|
+
className: 'pp-empty-icon',
|
|
27
|
+
}, paths.map((d, i) => createElement('path', { key: i, d })))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param text 主文案
|
|
32
|
+
* @param hint 次要提示
|
|
33
|
+
* @param icon 图标名(box / search / file),传 null 不显示
|
|
34
|
+
* @param action 可选动作 { label, onClick } 或 { label, href }
|
|
35
|
+
*/
|
|
36
|
+
export function EmptyState({ text = '暂无数据', hint = '', icon = 'box', action = null }) {
|
|
37
|
+
const node = action
|
|
38
|
+
? (action.href
|
|
39
|
+
? createElement('a', { className: 'pp-btn pp-btn-sm pp-btn-primary', href: action.href }, action.label)
|
|
40
|
+
: createElement('button', {
|
|
41
|
+
type: 'button',
|
|
42
|
+
className: 'pp-btn pp-btn-sm pp-btn-primary',
|
|
43
|
+
onClick: action.onClick,
|
|
44
|
+
}, action.label))
|
|
45
|
+
: null
|
|
46
|
+
return createElement('div', { className: 'pp-empty' },
|
|
47
|
+
icon ? createElement(EmptyIcon, { name: icon }) : null,
|
|
48
|
+
createElement('div', { className: 'pp-empty-text' }, text),
|
|
49
|
+
hint ? createElement('div', { className: 'pp-meta' }, hint) : null,
|
|
50
|
+
node ? createElement('div', { className: 'pp-empty-action' }, node) : null,
|
|
51
|
+
)
|
|
52
|
+
}
|