dsh-postapi 0.0.0-stage → 0.0.2
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
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostAPI 页签 body(sidebar.right.pane.tab 席位):Apifox 同构工作台骨架。
|
|
3
|
+
*
|
|
4
|
+
* 规范:docs/apifox-visual-parity-spec.md(全部数值取自 Apifox 2.8.55 的 CSS 原文)
|
|
5
|
+
* 结构 = 顶栏 48px + 左侧 240px 常驻文字菜单 + 主区(44px 页签条 + 页头 + 页面)。
|
|
6
|
+
* 历史:v1 是 240px 左树 + 主区 + 240px 右栏三段式,窄容器里必然拥挤;
|
|
7
|
+
* v2 换成 64px 图标轨 + 浮层二级菜单,解决了宽度但图标认不出功能、二级要多点一次;
|
|
8
|
+
* v3(当前)照 Apifox 用 240px 常驻文字菜单,分组标题 + 路由文字全部直读。
|
|
9
|
+
*
|
|
10
|
+
* 路由形态:#/overview、#/doc/:endpointId、#/debug、#/flow、#/settings…(契约 §3)。
|
|
11
|
+
* 颜色 / 字号 / 尺寸一律引用 design-tokens.css 的 var(--*) token,内联 style 只写 layout。
|
|
12
|
+
*/
|
|
13
|
+
import { createElement, useEffect, useMemo, useRef, useState } from 'react'
|
|
14
|
+
import { zh } from './locales.js'
|
|
15
|
+
import { pageRegistry } from './registry.js'
|
|
16
|
+
import { NEW_MENU, actionHash } from './menu.js'
|
|
17
|
+
|
|
18
|
+
/** 主题与环境的本地设置键(与 pages/theme.js 共用同一套键,切页不丢)。 */
|
|
19
|
+
const THEME_KEY = 'postapi.settings.theme'
|
|
20
|
+
const ENV_KEY = 'postapi.settings.env'
|
|
21
|
+
|
|
22
|
+
/** 12 条路由(顺序 = 契约 §3 页面清单)。 */
|
|
23
|
+
/**
|
|
24
|
+
* 12 条路由。每条自带 icon:此前侧栏所有条目复用「所属分组」的图标,
|
|
25
|
+
* 导致文档 / 调试 / Mock 三个图标一模一样、数据模型 / 环境也一样,等于没有图标。
|
|
26
|
+
*/
|
|
27
|
+
export const ROUTES = [
|
|
28
|
+
{ name: 'overview', hash: '#/overview', labelKey: 'nav.overview', icon: 'grid' },
|
|
29
|
+
{ name: 'doc', hash: '#/doc', labelKey: 'nav.doc', icon: 'book' },
|
|
30
|
+
{ name: 'debug', hash: '#/debug', labelKey: 'nav.debug', icon: 'send' },
|
|
31
|
+
{ name: 'mock', hash: '#/mock', labelKey: 'nav.mock', icon: 'cube' },
|
|
32
|
+
{ name: 'schema', hash: '#/schema', labelKey: 'nav.schema', icon: 'db' },
|
|
33
|
+
{ name: 'env', hash: '#/env', labelKey: 'nav.env', icon: 'sliders' },
|
|
34
|
+
{ name: 'history', hash: '#/history', labelKey: 'nav.history', icon: 'clock' },
|
|
35
|
+
{ name: 'test', hash: '#/test', labelKey: 'nav.test', icon: 'check' },
|
|
36
|
+
{ name: 'import', hash: '#/import', labelKey: 'nav.import', icon: 'swap' },
|
|
37
|
+
{ name: 'flow', hash: '#/flow', labelKey: 'nav.flow', icon: 'flow' },
|
|
38
|
+
{ name: 'search', hash: '#/search', labelKey: 'nav.search', icon: 'search' },
|
|
39
|
+
{ name: 'settings', hash: '#/settings', labelKey: 'nav.settings', icon: 'gear' },
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
/** 带参数的路由(hash 形态 #/name/:arg)。 */
|
|
43
|
+
export const PARAM_ROUTES = ['doc', 'schema']
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 五个导航分组(v2):每条路由只出现在一个分组里,一级只显示分组图标。
|
|
47
|
+
* glyph 用等宽符号而非 emoji:emoji 在不同系统字号/基线上抖动,会破坏轨的对齐。
|
|
48
|
+
*/
|
|
49
|
+
export const NAV_GROUPS = [
|
|
50
|
+
{ id: 'project', labelKey: 'group.project', icon: 'grid', routes: ['overview'] },
|
|
51
|
+
{ id: 'api', labelKey: 'group.api', icon: 'layers', routes: ['doc', 'debug', 'mock'] },
|
|
52
|
+
{ id: 'data', labelKey: 'group.data', icon: 'db', routes: ['schema', 'env'] },
|
|
53
|
+
{ id: 'quality', labelKey: 'group.quality', icon: 'check', routes: ['test', 'history', 'flow'] },
|
|
54
|
+
{ id: 'tools', labelKey: 'group.tools', icon: 'sliders', routes: ['import', 'search', 'settings'] },
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 图标路径表(24×24 视图,stroke 风格)。
|
|
59
|
+
* 用 SVG 而非符号字符:符号在 Windows/不同字体下基线与粗细不一致,轨会看起来歪。
|
|
60
|
+
*/
|
|
61
|
+
const ICON_PATHS = {
|
|
62
|
+
grid: ['M4 4h6v6H4z', 'M14 4h6v6h-6z', 'M4 14h6v6H4z', 'M14 14h6v6h-6z'],
|
|
63
|
+
layers: ['M4 7h16', 'M4 12h16', 'M4 17h10'],
|
|
64
|
+
db: ['M5 6c0-1.1 3.1-2 7-2s7 .9 7 2-3.1 2-7 2-7-.9-7-2z', 'M5 6v12c0 1.1 3.1 2 7 2s7-.9 7-2V6', 'M5 12c0 1.1 3.1 2 7 2s7-.9 7-2'],
|
|
65
|
+
check: ['M4 12l5 5L20 6'],
|
|
66
|
+
sliders: ['M4 7h10', 'M18 7h2', 'M4 17h4', 'M12 17h8', 'M14 4v6', 'M8 14v6'],
|
|
67
|
+
sun: ['M12 4v2', 'M12 18v2', 'M4 12h2', 'M18 12h2', 'M6.3 6.3l1.4 1.4', 'M16.3 16.3l1.4 1.4', 'M6.3 17.7l1.4-1.4', 'M16.3 7.7l1.4-1.4'],
|
|
68
|
+
moon: ['M20 14.5A8.5 8.5 0 0 1 9.5 4a8.5 8.5 0 1 0 10.5 10.5z'],
|
|
69
|
+
gear: ['M12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6z', 'M19 12a7 7 0 0 0-.1-1l2-1.5-2-3.4-2.3 1a7 7 0 0 0-1.7-1L14.5 3h-4l-.4 2.6a7 7 0 0 0-1.7 1l-2.3-1-2 3.4 2 1.5a7 7 0 0 0 0 2l-2 1.5 2 3.4 2.3-1a7 7 0 0 0 1.7 1l.4 2.6h4l.4-2.6a7 7 0 0 0 1.7-1l2.3 1 2-3.4-2-1.5c.1-.3.1-.7.1-1z'],
|
|
70
|
+
help: ['M12 18h.01', 'M9.1 9a3 3 0 1 1 4.2 2.7c-.8.5-1.3 1.1-1.3 2.3', 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18z'],
|
|
71
|
+
plus: ['M12 5v14', 'M5 12h14'],
|
|
72
|
+
close: ['M6 6l12 12', 'M18 6L6 18'],
|
|
73
|
+
book: ['M4 5.5A2.5 2.5 0 0 1 6.5 3H20v18H6.5A2.5 2.5 0 0 1 4 18.5z', 'M8 3v18'],
|
|
74
|
+
send: ['M21 3L10 14', 'M21 3l-7 18-4-7-7-4z'],
|
|
75
|
+
cube: ['M12 3l8 4.5v9L12 21l-8-4.5v-9z', 'M12 12l8-4.5', 'M12 12v9', 'M12 12L4 7.5'],
|
|
76
|
+
clock: ['M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18z', 'M12 7v5l3 2'],
|
|
77
|
+
swap: ['M4 8h13l-3-3', 'M20 16H7l3 3'],
|
|
78
|
+
flow: ['M5 6h5', 'M14 6h5', 'M7.5 6v12', 'M16.5 6v12', 'M5 18h5', 'M14 18h5'],
|
|
79
|
+
search: ['M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14z', 'M20 20l-4.2-4.2'],
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 渲染一个 SVG 图标。
|
|
84
|
+
* @param name - ICON_PATHS 的键。
|
|
85
|
+
* @param size - 边长(默认 --rail-icon 的 20px)。
|
|
86
|
+
*/
|
|
87
|
+
export function Icon({ name, size = 20 }) {
|
|
88
|
+
const paths = ICON_PATHS[name] || ICON_PATHS.grid
|
|
89
|
+
return createElement('svg', {
|
|
90
|
+
viewBox: '0 0 24 24',
|
|
91
|
+
width: size,
|
|
92
|
+
height: size,
|
|
93
|
+
fill: 'none',
|
|
94
|
+
stroke: 'currentColor',
|
|
95
|
+
strokeWidth: 1.6,
|
|
96
|
+
strokeLinecap: 'round',
|
|
97
|
+
strokeLinejoin: 'round',
|
|
98
|
+
'aria-hidden': true,
|
|
99
|
+
style: { display: 'block' },
|
|
100
|
+
}, paths.map((d, i) => createElement('path', { key: i, d })))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 三级菜单树(Apifox「+」同构)。
|
|
105
|
+
*
|
|
106
|
+
* 结构:一个面板里渲染当前层的全部项;有 children 的项点击后把该层 id 记进
|
|
107
|
+
* openPath,下一层面板以绝对定位浮出到父项左侧(.pp-menu .pp-menu 的 CSS 规则)。
|
|
108
|
+
* 层级由 openPath 的长度决定,因此天然支持 1~3 级,不需要为每级写一份 JSX。
|
|
109
|
+
*
|
|
110
|
+
* @param items 当前层节点数组(NEW_MENU 的某一段)
|
|
111
|
+
* @param openPath 从根到当前展开项的 id 数组
|
|
112
|
+
* @param onOpen 展开某个子层(传入该层 id 数组)
|
|
113
|
+
* @param onPick 选中叶子(node, hash)
|
|
114
|
+
* @param depth 当前层深度(1 起),仅用于 aria 与测试断言
|
|
115
|
+
*/
|
|
116
|
+
function MenuTree({ items, openPath, onOpen, onPick, depth = 1, pos }) {
|
|
117
|
+
// openId 取「本层应展开的项」:openPath 是从根到最深展开项的完整 id 链,
|
|
118
|
+
// 本层对应第 depth 个元素。子层复用同一份 openPath(不截断),否则子层看不到自己要展开谁。
|
|
119
|
+
const openId = openPath.length >= depth ? openPath[depth - 1] : null
|
|
120
|
+
const openNode = openId ? items.find((n) => n && n.id === openId) : null
|
|
121
|
+
// fixed 定位:坐标由上层算好传进来(顶层贴按钮,子层贴触发项)
|
|
122
|
+
const style = pos ? { top: pos.top + 'px', left: pos.left + 'px' } : undefined
|
|
123
|
+
// 触发项元素引用:子面板坐标需要它的 getBoundingClientRect
|
|
124
|
+
const itemRef = useRef(null)
|
|
125
|
+
const childPos = useMemo(() => {
|
|
126
|
+
const el = itemRef.current
|
|
127
|
+
if (!el || typeof el.getBoundingClientRect !== 'function') return undefined
|
|
128
|
+
const r = el.getBoundingClientRect()
|
|
129
|
+
const w = 200 // 与 --menu-w 一致
|
|
130
|
+
const gap = 4
|
|
131
|
+
// 默认向左开;左侧放不下就向右翻(Apifox 同样按边界翻转)
|
|
132
|
+
const left = r.left - w - gap >= gap ? r.left - w - gap : r.right + gap
|
|
133
|
+
// 垂直对齐到触发项上沿,并夹到视口内(面板高按最多 12 项估)
|
|
134
|
+
const maxTop = (typeof window !== 'undefined' ? window.innerHeight : 800) - 12 * 32 - 16
|
|
135
|
+
const top = Math.max(8, Math.min(r.top - 4, maxTop))
|
|
136
|
+
return { top, left }
|
|
137
|
+
}, [openId])
|
|
138
|
+
return (
|
|
139
|
+
<div className="pp-menu" role="menu" data-depth={depth} style={style}>
|
|
140
|
+
{items.map((node) => {
|
|
141
|
+
if (!node || node.separator) return <div key={node && node.id ? node.id : 'sep'} className="pp-menu-sep" role="separator" />
|
|
142
|
+
const hasKids = Array.isArray(node.children) && node.children.length > 0
|
|
143
|
+
const isOpen = Boolean(openNode) && openNode.id === node.id
|
|
144
|
+
if (hasKids) {
|
|
145
|
+
return (
|
|
146
|
+
<div key={node.id} className="pp-menu-anchor" data-index={items.indexOf(node)}>
|
|
147
|
+
<button type="button" className="pp-menu-item" role="menuitem"
|
|
148
|
+
data-open={isOpen ? 'true' : 'false'}
|
|
149
|
+
aria-haspopup="menu" aria-expanded={isOpen ? 'true' : 'false'}
|
|
150
|
+
ref={(el) => { if (el && isOpen) itemRef.current = el }}
|
|
151
|
+
onClick={(event) => {
|
|
152
|
+
event.stopPropagation()
|
|
153
|
+
itemRef.current = event.currentTarget
|
|
154
|
+
onOpen(openPath.slice(0, depth - 1).concat([node.id]))
|
|
155
|
+
}}>
|
|
156
|
+
<span className="pp-menu-label">{zh[node.labelKey]}</span>
|
|
157
|
+
<span className="pp-menu-arrow" aria-hidden="true">›</span>
|
|
158
|
+
</button>
|
|
159
|
+
{isOpen ? (
|
|
160
|
+
<MenuTree items={node.children}
|
|
161
|
+
openPath={openPath}
|
|
162
|
+
onOpen={onOpen} onPick={onPick} depth={depth + 1}
|
|
163
|
+
pos={childPos} />
|
|
164
|
+
) : null}
|
|
165
|
+
</div>
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
const hash = actionHash(node.action)
|
|
169
|
+
return (
|
|
170
|
+
<a key={node.id} className="pp-menu-item" role="menuitem"
|
|
171
|
+
href={hash || '#'}
|
|
172
|
+
onClick={(event) => { event.preventDefault(); onPick(node, hash) }}>
|
|
173
|
+
<span className="pp-menu-label">{zh[node.labelKey]}</span>
|
|
174
|
+
</a>
|
|
175
|
+
)
|
|
176
|
+
})}
|
|
177
|
+
</div>
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** 解析 hash 为 { name, arg, query };未知路由回落 overview。 */
|
|
182
|
+
export function parseHash(raw) {
|
|
183
|
+
const source = raw === undefined ? (typeof location !== 'undefined' ? location.hash : '') : raw
|
|
184
|
+
const clean = String(source || '#/overview').replace(/^#\/?/, '')
|
|
185
|
+
const qAt = clean.indexOf('?')
|
|
186
|
+
const pathPart = qAt >= 0 ? clean.slice(0, qAt) : clean
|
|
187
|
+
const query = qAt >= 0 ? clean.slice(qAt + 1) : ''
|
|
188
|
+
const [first, ...rest] = pathPart.split('/')
|
|
189
|
+
if (PARAM_ROUTES.indexOf(first) >= 0) {
|
|
190
|
+
return { name: first, arg: rest.length ? decodeURIComponent(rest.join('/')) : '', query }
|
|
191
|
+
}
|
|
192
|
+
if (ROUTES.some((r) => r.name === first)) return { name: first, arg: '', query }
|
|
193
|
+
return { name: 'overview', arg: '', query }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** 路由跳转目标:参数路由带上当前 arg(#/doc/:id),其余取静态 hash。 */
|
|
197
|
+
export function routeHref(item, route) {
|
|
198
|
+
if (PARAM_ROUTES.indexOf(item.name) >= 0 && route && route.arg) {
|
|
199
|
+
return item.hash + '/' + encodeURIComponent(route.arg)
|
|
200
|
+
}
|
|
201
|
+
return item.hash
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** 搜索跳转 hash:#/search?q=<keyword>(空关键字返回 #/search)。 */
|
|
205
|
+
export function searchHash(keyword) {
|
|
206
|
+
const q = String(keyword === undefined || keyword === null ? '' : keyword).trim()
|
|
207
|
+
return q === '' ? '#/search' : '#/search?q=' + encodeURIComponent(q)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** 当前路由属于哪个分组(未知路由归第一组)。 */
|
|
211
|
+
export function groupOfRoute(name) {
|
|
212
|
+
const hit = NAV_GROUPS.find((g) => g.routes.indexOf(name) >= 0)
|
|
213
|
+
return hit || NAV_GROUPS[0]
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** 分组内的路由对象列表(保持 ROUTES 顺序)。 */
|
|
217
|
+
export function routesOfGroup(group) {
|
|
218
|
+
if (!group || !Array.isArray(group.routes)) return []
|
|
219
|
+
return group.routes.map((name) => ROUTES.find((r) => r.name === name)).filter(Boolean)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** 读本地设置(隐私模式下回落默认值,不抛错)。 */
|
|
223
|
+
export function readSetting(key, fallback) {
|
|
224
|
+
try {
|
|
225
|
+
if (typeof localStorage === 'undefined') return fallback
|
|
226
|
+
const value = localStorage.getItem(key)
|
|
227
|
+
return value === null || value === undefined || value === '' ? fallback : value
|
|
228
|
+
} catch {
|
|
229
|
+
return fallback
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** 写本地设置(隐私模式下静默忽略)。 */
|
|
234
|
+
export function writeSetting(key, value) {
|
|
235
|
+
try {
|
|
236
|
+
if (typeof localStorage !== 'undefined') localStorage.setItem(key, value)
|
|
237
|
+
} catch { /* 忽略隐私模式 */ }
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** 主题取反:light <-> dark。 */
|
|
241
|
+
export function nextTheme(theme) {
|
|
242
|
+
return theme === 'dark' ? 'light' : 'dark'
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 主题同步:把 data-theme 写到所有 .pp-scope 根(骨架自身 + 已挂载页面根)。
|
|
247
|
+
* 页面根自带 data-theme(applyTheme 只在挂载时写一次),顶栏切主题后需一并刷新。
|
|
248
|
+
*/
|
|
249
|
+
export function syncTheme(theme) {
|
|
250
|
+
if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return
|
|
251
|
+
const nodes = document.querySelectorAll('.pp-scope')
|
|
252
|
+
for (const el of nodes) {
|
|
253
|
+
if (el && typeof el.setAttribute === 'function') el.setAttribute('data-theme', theme)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** hashchange 订阅式路由 hook。 */
|
|
258
|
+
function useHashRoute() {
|
|
259
|
+
const [route, setRoute] = useState(() => parseHash())
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
const onChange = () => setRoute(parseHash())
|
|
262
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
263
|
+
window.addEventListener('hashchange', onChange)
|
|
264
|
+
return () => window.removeEventListener('hashchange', onChange)
|
|
265
|
+
}
|
|
266
|
+
return undefined
|
|
267
|
+
}, [])
|
|
268
|
+
return route
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** 页面未注册时的占位。 */
|
|
272
|
+
function Placeholder({ route }) {
|
|
273
|
+
const title = zh['placeholder.title'] + ': ' + route.name + (route.arg ? '/' + route.arg : '')
|
|
274
|
+
return (
|
|
275
|
+
<div className="pp-page">
|
|
276
|
+
<div className="pp-empty">
|
|
277
|
+
<div className="pp-card-title">{title}</div>
|
|
278
|
+
<div>{zh['placeholder.body']}</div>
|
|
279
|
+
<div className="pp-meta">{zh['placeholder.hint']}</div>
|
|
280
|
+
</div>
|
|
281
|
+
</div>
|
|
282
|
+
)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 页面说明行已删除。
|
|
287
|
+
*
|
|
288
|
+
* 原来顶栏「总览」→ 页签条「总览」→ 说明行「项目总览:项目卡片…」→ 页面内
|
|
289
|
+
* 「项目总览」四层标题叠在一起,是当前最明显的视觉噪音。Apifox 只有两层:
|
|
290
|
+
* 页签条(当前打开的工作项)+ 页头标题(18px/700,带动作区)。
|
|
291
|
+
* 说明文案保留在帮助卡片里(侧栏底部「当前页面」),不再常驻占一行高度。
|
|
292
|
+
*/
|
|
293
|
+
const PAGE_DESC = (name) => zh['aside.page.' + name] || zh['aside.noContext']
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* 页签 body 组件。props 来自 slots runtime:useTabInfo + 注入的 locale t(若有)。
|
|
297
|
+
* v2 骨架:顶栏(面包屑 + 搜索 + 动作)+ 图标轨(分组)+ 主区(页头 + 页面)。
|
|
298
|
+
*/
|
|
299
|
+
export function PostApiBody({ useTabInfo }) {
|
|
300
|
+
const route = useHashRoute()
|
|
301
|
+
const [theme, setTheme] = useState(() => readSetting(THEME_KEY, 'light'))
|
|
302
|
+
const [env, setEnv] = useState(() => readSetting(ENV_KEY, ''))
|
|
303
|
+
const [keyword, setKeyword] = useState('')
|
|
304
|
+
// 帮助卡片(原右上下文栏的内容,收进侧栏底部一项)
|
|
305
|
+
const [helpOpen, setHelpOpen] = useState(false)
|
|
306
|
+
// 新建三级菜单:menuOpen 控制一级面板,menuPath 是从根到当前展开层的 id 链
|
|
307
|
+
const [menuOpen, setMenuOpen] = useState(false)
|
|
308
|
+
const [menuPath, setMenuPath] = useState([])
|
|
309
|
+
// fixed 定位的顶层面板坐标(贴按钮下方);子层坐标由 MenuTree 自己算
|
|
310
|
+
const [menuPos, setMenuPos] = useState(null)
|
|
311
|
+
const menuBtnRef = useRef(null)
|
|
312
|
+
const shellRef = useRef(null)
|
|
313
|
+
// 页面组件每次渲染查注册表:页面可能在 body 已挂载后才自注册。
|
|
314
|
+
const Page = pageRegistry.get(route.name)
|
|
315
|
+
const active = ROUTES.find((r) => r.name === route.name) || ROUTES[0]
|
|
316
|
+
const activeGroup = groupOfRoute(route.name)
|
|
317
|
+
const api = typeof window !== 'undefined' ? window.__postapiApi : undefined
|
|
318
|
+
|
|
319
|
+
// Esc 关闭帮助卡片;点卡片外关闭。
|
|
320
|
+
useEffect(() => {
|
|
321
|
+
const onKey = (event) => {
|
|
322
|
+
if (!event) return
|
|
323
|
+
if (event.key === 'Escape') {
|
|
324
|
+
// Esc 逐级收起:先关最深一层,路径空了再关面板
|
|
325
|
+
setMenuPath((prev) => (prev.length > 0 ? prev.slice(0, -1) : prev))
|
|
326
|
+
setHelpOpen(false)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const onDown = (event) => {
|
|
330
|
+
const target = event && event.target
|
|
331
|
+
if (!target || !shellRef.current) return
|
|
332
|
+
if (typeof shellRef.current.contains === 'function' && shellRef.current.contains(target)) {
|
|
333
|
+
// 点在侧栏 / 帮助卡 / 菜单内部:交给各自的 onClick 处理
|
|
334
|
+
if (target.closest && (target.closest('.pp-sider') || target.closest('.pp-help-card') || target.closest('.pp-menu-anchor'))) return
|
|
335
|
+
}
|
|
336
|
+
setHelpOpen(false)
|
|
337
|
+
setMenuOpen(false)
|
|
338
|
+
setMenuPath([])
|
|
339
|
+
}
|
|
340
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
341
|
+
window.addEventListener('keydown', onKey)
|
|
342
|
+
window.addEventListener('mousedown', onDown)
|
|
343
|
+
return () => {
|
|
344
|
+
window.removeEventListener('keydown', onKey)
|
|
345
|
+
window.removeEventListener('mousedown', onDown)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return undefined
|
|
349
|
+
}, [])
|
|
350
|
+
|
|
351
|
+
// 路由变化时收起帮助卡片(跳转后说明卡不该留在屏幕上)。
|
|
352
|
+
useEffect(() => { setHelpOpen(false) }, [route.name, route.arg])
|
|
353
|
+
|
|
354
|
+
const toggleTheme = () => {
|
|
355
|
+
const next = nextTheme(theme)
|
|
356
|
+
writeSetting(THEME_KEY, next)
|
|
357
|
+
syncTheme(next)
|
|
358
|
+
setTheme(next)
|
|
359
|
+
}
|
|
360
|
+
const pickEnv = (event) => {
|
|
361
|
+
const value = event && event.target ? event.target.value : ''
|
|
362
|
+
writeSetting(ENV_KEY, value)
|
|
363
|
+
setEnv(value)
|
|
364
|
+
}
|
|
365
|
+
const goto = (hash) => {
|
|
366
|
+
if (typeof location !== 'undefined') location.hash = hash
|
|
367
|
+
}
|
|
368
|
+
const onSearchKey = (event) => {
|
|
369
|
+
if (!event || event.key !== 'Enter') return
|
|
370
|
+
const q = String(keyword === undefined || keyword === null ? '' : keyword).trim()
|
|
371
|
+
if (q === '') return
|
|
372
|
+
goto(searchHash(q))
|
|
373
|
+
}
|
|
374
|
+
const toggleHelp = () => setHelpOpen((prev) => !prev)
|
|
375
|
+
|
|
376
|
+
return (
|
|
377
|
+
<div className="pp-scope pp-workbench-v2" data-theme={theme} data-route={route.name}>
|
|
378
|
+
{/* 顶栏:Apifox 是「产品标识 + 面包屑(分组/当前页)+ 搜索 + 动作」。
|
|
379
|
+
原来这里还单独显示当前页名,与页签条、页面页头三重重复,已去掉。 */}
|
|
380
|
+
<header className="pp-topbar">
|
|
381
|
+
<span className="pp-topbar-brand">
|
|
382
|
+
<Icon name="layers" size={16} />
|
|
383
|
+
<span>{zh['type.label']}</span>
|
|
384
|
+
</span>
|
|
385
|
+
<span className="pp-crumb">
|
|
386
|
+
{zh[activeGroup.labelKey]}
|
|
387
|
+
<span className="pp-crumb-sep">/</span>
|
|
388
|
+
{zh[active.labelKey]}
|
|
389
|
+
</span>
|
|
390
|
+
<span className="pp-topbar-spacer" />
|
|
391
|
+
<input
|
|
392
|
+
className="pp-input pp-input-sm pp-topbar-search"
|
|
393
|
+
type="search"
|
|
394
|
+
value={keyword}
|
|
395
|
+
placeholder={zh['topbar.searchPlaceholder']}
|
|
396
|
+
aria-label={zh['topbar.search']}
|
|
397
|
+
onChange={(event) => setKeyword(event.target.value)}
|
|
398
|
+
onKeyDown={onSearchKey}
|
|
399
|
+
/>
|
|
400
|
+
{/* 新建:三级下拉菜单(Apifox 左侧「+」同构) */}
|
|
401
|
+
<span className="pp-menu-anchor">
|
|
402
|
+
<button className="pp-btn pp-btn-sm pp-btn-primary" type="button"
|
|
403
|
+
ref={menuBtnRef}
|
|
404
|
+
aria-haspopup="menu" aria-expanded={menuOpen ? 'true' : 'false'}
|
|
405
|
+
onClick={() => {
|
|
406
|
+
if (!menuOpen && menuBtnRef.current) {
|
|
407
|
+
const r = menuBtnRef.current.getBoundingClientRect()
|
|
408
|
+
const w = 200
|
|
409
|
+
// 顶层面板贴按钮下方,右缘与按钮对齐;左侧放不下就贴视口左边界
|
|
410
|
+
setMenuPos({ top: Math.round(r.bottom + 4), left: Math.round(Math.max(8, r.right - w)) })
|
|
411
|
+
}
|
|
412
|
+
setMenuOpen((v) => !v)
|
|
413
|
+
setMenuPath([])
|
|
414
|
+
}}>
|
|
415
|
+
{zh['topbar.new']}
|
|
416
|
+
</button>
|
|
417
|
+
{menuOpen ? (
|
|
418
|
+
<MenuTree items={NEW_MENU} openPath={menuPath} pos={menuPos}
|
|
419
|
+
onOpen={(path) => setMenuPath(path)}
|
|
420
|
+
onPick={(node, hash) => {
|
|
421
|
+
setMenuOpen(false)
|
|
422
|
+
setMenuPath([])
|
|
423
|
+
if (hash) goto(hash)
|
|
424
|
+
}} />
|
|
425
|
+
) : null}
|
|
426
|
+
</span>
|
|
427
|
+
<select className="pp-select pp-input-sm" value={env} onChange={pickEnv}
|
|
428
|
+
title={zh['topbar.env']} aria-label={zh['topbar.env']}>
|
|
429
|
+
<option value="">{zh['topbar.envDefault']}</option>
|
|
430
|
+
</select>
|
|
431
|
+
<button className="pp-icon-btn" type="button" onClick={toggleTheme}
|
|
432
|
+
title={zh['topbar.themeHint']} aria-label={zh['topbar.themeHint']}>
|
|
433
|
+
<Icon name={theme === 'dark' ? 'moon' : 'sun'} size={18} />
|
|
434
|
+
</button>
|
|
435
|
+
<button className="pp-icon-btn" type="button" onClick={() => goto('#/settings')}
|
|
436
|
+
title={zh['topbar.settings']} aria-label={zh['topbar.settings']}>
|
|
437
|
+
<Icon name="gear" size={18} />
|
|
438
|
+
</button>
|
|
439
|
+
<button className="pp-icon-btn" type="button" onClick={toggleHelp}
|
|
440
|
+
data-active={helpOpen ? 'true' : 'false'}
|
|
441
|
+
title={zh['aside.about']} aria-label={zh['aside.about']}>
|
|
442
|
+
<Icon name="help" size={18} />
|
|
443
|
+
</button>
|
|
444
|
+
</header>
|
|
445
|
+
<div className="pp-shell" ref={shellRef}>
|
|
446
|
+
{/* 左侧 240px 常驻文字菜单(Apifox .sider-bxNtfB 同规格):
|
|
447
|
+
分组标题 + 组内路由,全部文字直接可见,不再有「图标看不懂」与「二级要点开」两个问题。 */}
|
|
448
|
+
<nav className="pp-sider" aria-label={zh['aside.nav']}>
|
|
449
|
+
{NAV_GROUPS.map((group) => (
|
|
450
|
+
<div key={group.id}>
|
|
451
|
+
<div className="pp-sider-group">{zh[group.labelKey]}</div>
|
|
452
|
+
{routesOfGroup(group).map((item) => (
|
|
453
|
+
<a key={item.name} className="pp-sider-item"
|
|
454
|
+
href={routeHref(item, route)}
|
|
455
|
+
data-active={route.name === item.name ? 'true' : 'false'}>
|
|
456
|
+
<Icon name={item.icon || group.icon} size={16} />
|
|
457
|
+
<span className="pp-sider-label">{zh[item.labelKey]}</span>
|
|
458
|
+
</a>
|
|
459
|
+
))}
|
|
460
|
+
</div>
|
|
461
|
+
))}
|
|
462
|
+
</nav>
|
|
463
|
+
<main className="pp-main-v2">
|
|
464
|
+
{/* 页签条:Apifox 主页签条 44px(docs/apifox-visual-parity-spec.md §6)。
|
|
465
|
+
当前只承载「当前页」一个页签,结构按卡片式页签建好,后续多开接口时直接复用。 */}
|
|
466
|
+
<div className="pp-tabbar" role="tablist" aria-label={zh[active.labelKey]}>
|
|
467
|
+
<button type="button" className="pp-tabbar-item" role="tab"
|
|
468
|
+
data-active="true" aria-selected="true">
|
|
469
|
+
<span className="pp-sider-label">{zh[active.labelKey]}</span>
|
|
470
|
+
</button>
|
|
471
|
+
</div>
|
|
472
|
+
{helpOpen ? (
|
|
473
|
+
<div className="pp-help-card" role="dialog" aria-label={zh['aside.about']}>
|
|
474
|
+
<div className="pp-help-card-head">
|
|
475
|
+
<span className="pp-help-card-title">{zh['aside.about']}</span>
|
|
476
|
+
<button type="button" className="pp-icon-btn" onClick={() => setHelpOpen(false)}
|
|
477
|
+
aria-label={zh['aside.shortcuts']}>
|
|
478
|
+
<Icon name="close" size={14} />
|
|
479
|
+
</button>
|
|
480
|
+
</div>
|
|
481
|
+
<div className="pp-help">{PAGE_DESC(route.name)}</div>
|
|
482
|
+
</div>
|
|
483
|
+
) : null}
|
|
484
|
+
{Page ? <Page route={route} api={api} /> : <Placeholder route={route} />}
|
|
485
|
+
</main>
|
|
486
|
+
</div>
|
|
487
|
+
</div>
|
|
488
|
+
)
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// useTabInfo 属于可选信息:骨架不读 tab 上下文,props 形态与样板保持一致
|
|
492
|
+
// (该形参仅存在于 PostApiBody 函数签名内,勿在模块顶层引用)。
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostAPI 右栏页签类型声明(stage one):这个类型"是什么"。
|
|
3
|
+
*
|
|
4
|
+
* 对照样板 @deepseek-ai/dsh-client-ui-sidebar-files@0.2.2-rc.3 src/client/definition.tsx:
|
|
5
|
+
* - id 是 tab 系统里的实现身份,也是 sidebar.right.pane.tab / .title 两个
|
|
6
|
+
* keyed 席位的注册 key(官方注释:"it is the key its body registers under")。
|
|
7
|
+
* - kind 是类型判别符,openTab(kind) 用它命名。
|
|
8
|
+
* - priority 不写即 'extension'(tab-registry.ts DEFAULT_BAND),契约 §4 同款。
|
|
9
|
+
* - keepMounted: true 让访问过的 body 在隐藏、切会话、停靠变换时不卸载。
|
|
10
|
+
* - guide 单入口:一项 entry,点开即直开本页签(guide 单入口直开)。
|
|
11
|
+
*/
|
|
12
|
+
import { createElement } from 'react'
|
|
13
|
+
import { POSTAPI_NS } from './locales.js'
|
|
14
|
+
|
|
15
|
+
/** 实现身份与席位 key(不拼 localeKey)。 */
|
|
16
|
+
export const POSTAPI_ID = 'postapi'
|
|
17
|
+
|
|
18
|
+
/** 类型判别符:ctx.sidebarRight.openTab('postapi') 即打开本页。 */
|
|
19
|
+
export const POSTAPI_KIND = 'postapi'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* guide 入口图标:宿主按 <Icon size className /> 渲染,故必须是 React 组件。
|
|
23
|
+
* 内联 svg(同 db-tool DbIcon 形态),不引 @deepseek-ai/dsh-client-ui-primitives。
|
|
24
|
+
* @param props - { size } 由宿主传入。
|
|
25
|
+
*/
|
|
26
|
+
export function PostApiIcon(props) {
|
|
27
|
+
const s = (props && props.size) || 16
|
|
28
|
+
return createElement('svg', {
|
|
29
|
+
viewBox: '0 0 64 64', width: s, height: s, 'aria-hidden': true,
|
|
30
|
+
style: { display: 'block' },
|
|
31
|
+
}, createElement('path', { d: 'M6 50 L54 26 L6 8 L6 24 L36 26 L6 28 Z', fill: 'currentColor' }))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 产出注册定义。
|
|
36
|
+
* @param t - 命名空间绑定的翻译函数(每次取值即时读取,语言切换无需重注册)。
|
|
37
|
+
* @returns sidebarRightTabs.register 的入参。
|
|
38
|
+
*/
|
|
39
|
+
export function postapiDefinition(t) {
|
|
40
|
+
return {
|
|
41
|
+
id: POSTAPI_ID,
|
|
42
|
+
kind: POSTAPI_KIND,
|
|
43
|
+
keepMounted: true,
|
|
44
|
+
// 页类型(无 patterns),priority 不参与路由排序;显式写 'extension' 与 db-tool 一致。
|
|
45
|
+
priority: 'extension',
|
|
46
|
+
title: () => t('type.label'),
|
|
47
|
+
guide: [{
|
|
48
|
+
// guide 条目 id 与类型 id 一致(db-tool 同款):空态入口卡片按它打开本页签。
|
|
49
|
+
id: POSTAPI_ID,
|
|
50
|
+
order: 10,
|
|
51
|
+
title: () => t('guide.title'),
|
|
52
|
+
description: () => t('guide.description'),
|
|
53
|
+
// icon 是 React 组件;缺它时官方 guide 只画立方体占位图。
|
|
54
|
+
icon: PostApiIcon,
|
|
55
|
+
}],
|
|
56
|
+
}
|
|
57
|
+
}
|