openprototype 0.1.0 → 0.2.0
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/AGENTS.md +58 -0
- package/CONVENTIONS.md +54 -0
- package/LICENSE +21 -0
- package/README.md +233 -2
- package/bin/cli.js +297 -0
- package/lib/config.js +162 -0
- package/package.json +32 -10
- package/product/demo/pc/customer/customer_form.html +134 -0
- package/product/demo/pc/customer/customer_form.md +33 -0
- package/product/demo/pc/customer/customer_list.html +129 -0
- package/product/demo/pc/customer/customer_list.md +35 -0
- package/product/demo/pc/demo-data.js +23 -0
- package/product/demo/pc/index.html +1069 -0
- package/product/demo/pc/nav-tree.json +15 -0
- package/proto-kit.config.json +13 -0
- package/runtime/server.js +664 -0
- package/runtime/shared/ai-polish.js +159 -0
- package/runtime/shared/base-manager.js +168 -0
- package/runtime/shared/common/component-renderer.js +917 -0
- package/runtime/shared/common/copy-manager.js +134 -0
- package/runtime/shared/common/data-bridge.js +45 -0
- package/runtime/shared/common/form-renderer.js +211 -0
- package/runtime/shared/common/form.js +357 -0
- package/runtime/shared/common/formatter.js +78 -0
- package/runtime/shared/common/index.js +37 -0
- package/runtime/shared/common/line-chart.js +357 -0
- package/runtime/shared/common/modal-manager.js +82 -0
- package/runtime/shared/common/prd-panel.js +1014 -0
- package/runtime/shared/common/prd-popup.js +168 -0
- package/runtime/shared/common/search-renderer.js +95 -0
- package/runtime/shared/common/table-renderer.js +177 -0
- package/runtime/shared/common/table.js +160 -0
- package/runtime/shared/common/toast.js +99 -0
- package/runtime/shared/common/ui-preference-manager.js +74 -0
- package/runtime/shared/common/view-mode.js +30 -0
- package/runtime/shared/common.js +43 -0
- package/runtime/shared/constants/icons.js +28 -0
- package/runtime/shared/constants/status.js +67 -0
- package/runtime/shared/libs/marked.min.js +69 -0
- package/runtime/shared/prd-content.js +9 -0
- package/runtime/shared/styles.css +7673 -0
- package/runtime/shared/utils.js +110 -0
- package/runtime/shared/view-controls.js +148 -0
- package/runtime/shell/agent-panel.css +429 -0
- package/runtime/shell/agent-panel.js +629 -0
- package/scripts/check/run-checks.js +58 -0
- package/scripts/check/smoke-test.js +244 -0
- package/scripts/check/static-check.js +248 -0
- package/scripts/check/sync-nav-tree.js +139 -0
- package/templates/AGENTS.md +58 -0
- package/templates/CONVENTIONS.md +54 -0
- package/templates/gitignore +10 -0
- package/templates/product-shell/index.html +1069 -0
- package/templates/skills/auto-test/SKILL.md +62 -0
- package/templates/skills/xiaojia/SKILL.md +299 -0
- package/cli.js +0 -4
|
@@ -0,0 +1,1069 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Demo 原型导航</title>
|
|
6
|
+
<!-- agent-panel:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
7
|
+
<link rel="stylesheet" href="/_kit/shell/agent-panel.css">
|
|
8
|
+
<!-- agent-panel:end -->
|
|
9
|
+
<style>
|
|
10
|
+
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
11
|
+
|
|
12
|
+
body {
|
|
13
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', sans-serif;
|
|
14
|
+
font-size: 13px;
|
|
15
|
+
color: #20242d;
|
|
16
|
+
display: flex;
|
|
17
|
+
height: 100vh;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* ══════════════════════════════
|
|
22
|
+
LEFT SIDEBAR
|
|
23
|
+
══════════════════════════════ */
|
|
24
|
+
.sidebar {
|
|
25
|
+
width: 290px;
|
|
26
|
+
flex-shrink: 0;
|
|
27
|
+
position: relative;
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
background: #fff;
|
|
31
|
+
border-right: 1px solid #dfe5ee;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.sidebar-resizer {
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 0;
|
|
38
|
+
right: 0;
|
|
39
|
+
width: 10px;
|
|
40
|
+
height: 100%;
|
|
41
|
+
display: block;
|
|
42
|
+
border: 0;
|
|
43
|
+
padding: 0;
|
|
44
|
+
background: rgba(255, 255, 255, 0.01);
|
|
45
|
+
cursor: ew-resize;
|
|
46
|
+
z-index: 1000;
|
|
47
|
+
}
|
|
48
|
+
.sidebar-resizer::after {
|
|
49
|
+
content: "";
|
|
50
|
+
position: absolute;
|
|
51
|
+
top: 0;
|
|
52
|
+
right: 0;
|
|
53
|
+
width: 2px;
|
|
54
|
+
height: 100%;
|
|
55
|
+
background: transparent;
|
|
56
|
+
transition: background 0.12s;
|
|
57
|
+
}
|
|
58
|
+
.sidebar-resizer:hover::after,
|
|
59
|
+
.sidebar-resizer.is-resizing::after {
|
|
60
|
+
background: #1677ff;
|
|
61
|
+
}
|
|
62
|
+
body.is-resizing-sidebar {
|
|
63
|
+
cursor: ew-resize;
|
|
64
|
+
user-select: none;
|
|
65
|
+
}
|
|
66
|
+
body.is-resizing-sidebar .preview-frame {
|
|
67
|
+
pointer-events: none;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.sidebar-header {
|
|
71
|
+
flex-shrink: 0;
|
|
72
|
+
padding: 12px 12px 8px;
|
|
73
|
+
border-bottom: 1px solid #edf0f5;
|
|
74
|
+
}
|
|
75
|
+
.sidebar-title {
|
|
76
|
+
font-size: 14px;
|
|
77
|
+
font-weight: 600;
|
|
78
|
+
color: #20242d;
|
|
79
|
+
margin-bottom: 8px;
|
|
80
|
+
}
|
|
81
|
+
.sidebar-title-row {
|
|
82
|
+
display: flex;
|
|
83
|
+
align-items: center;
|
|
84
|
+
gap: 8px;
|
|
85
|
+
margin-bottom: 8px;
|
|
86
|
+
}
|
|
87
|
+
.sidebar-title-row .sidebar-title {
|
|
88
|
+
flex: 1;
|
|
89
|
+
margin-bottom: 0;
|
|
90
|
+
}
|
|
91
|
+
.copy-address-btn {
|
|
92
|
+
flex-shrink: 0;
|
|
93
|
+
height: 24px;
|
|
94
|
+
padding: 0 8px;
|
|
95
|
+
border: 1px solid #1677ff;
|
|
96
|
+
border-radius: 8px;
|
|
97
|
+
background: #fff;
|
|
98
|
+
color: #1677ff;
|
|
99
|
+
font-size: 11px;
|
|
100
|
+
line-height: 1;
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
white-space: nowrap;
|
|
103
|
+
transition: background 0.12s, color 0.12s, border-color 0.12s;
|
|
104
|
+
}
|
|
105
|
+
.copy-address-btn:hover {
|
|
106
|
+
background: #edf6ff;
|
|
107
|
+
border-color: #0d5edb;
|
|
108
|
+
color: #0d5edb;
|
|
109
|
+
}
|
|
110
|
+
.version-row {
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
gap: 6px;
|
|
114
|
+
margin-bottom: 6px;
|
|
115
|
+
}
|
|
116
|
+
.version-label { font-size: 11px; color: #7b8495; white-space: nowrap; }
|
|
117
|
+
.version-search-control {
|
|
118
|
+
display: flex;
|
|
119
|
+
flex: 1 1 100px;
|
|
120
|
+
min-width: 100px;
|
|
121
|
+
}
|
|
122
|
+
.version-input {
|
|
123
|
+
flex: 1;
|
|
124
|
+
min-width: 0;
|
|
125
|
+
border: 1px solid #dfe5ee;
|
|
126
|
+
border-radius: 4px 0 0 4px;
|
|
127
|
+
padding: 3px 7px;
|
|
128
|
+
font-size: 12px;
|
|
129
|
+
color: #20242d;
|
|
130
|
+
outline: none;
|
|
131
|
+
}
|
|
132
|
+
.version-input:focus { border-color: #1677ff; }
|
|
133
|
+
.version-search-btn {
|
|
134
|
+
width: 34px;
|
|
135
|
+
flex-shrink: 0;
|
|
136
|
+
border: 1px solid #1677ff;
|
|
137
|
+
border-left: 0;
|
|
138
|
+
border-radius: 0 4px 4px 0;
|
|
139
|
+
background: #1677ff;
|
|
140
|
+
color: #fff;
|
|
141
|
+
font-size: 10px;
|
|
142
|
+
cursor: pointer;
|
|
143
|
+
}
|
|
144
|
+
.version-search-btn:hover { background: #0d5edb; }
|
|
145
|
+
.version-history {
|
|
146
|
+
display: flex;
|
|
147
|
+
align-items: center;
|
|
148
|
+
gap: 4px;
|
|
149
|
+
flex-shrink: 0;
|
|
150
|
+
}
|
|
151
|
+
.version-history-empty {
|
|
152
|
+
color: #a8b2c3;
|
|
153
|
+
font-size: 10px;
|
|
154
|
+
white-space: nowrap;
|
|
155
|
+
}
|
|
156
|
+
.version-history-tag {
|
|
157
|
+
max-width: 58px;
|
|
158
|
+
height: 22px;
|
|
159
|
+
padding: 0 5px;
|
|
160
|
+
overflow: hidden;
|
|
161
|
+
border: 1px solid #bfdbff;
|
|
162
|
+
border-radius: 4px;
|
|
163
|
+
background: #edf6ff;
|
|
164
|
+
color: #1677ff;
|
|
165
|
+
font-size: 10px;
|
|
166
|
+
line-height: 20px;
|
|
167
|
+
text-overflow: ellipsis;
|
|
168
|
+
white-space: nowrap;
|
|
169
|
+
cursor: pointer;
|
|
170
|
+
}
|
|
171
|
+
.version-history-tag:hover {
|
|
172
|
+
background: #d9ebff;
|
|
173
|
+
border-color: #7cb5ff;
|
|
174
|
+
}
|
|
175
|
+
.version-history-clear {
|
|
176
|
+
padding: 0;
|
|
177
|
+
border: 0;
|
|
178
|
+
background: transparent;
|
|
179
|
+
color: #7b8495;
|
|
180
|
+
font-size: 10px;
|
|
181
|
+
white-space: nowrap;
|
|
182
|
+
cursor: pointer;
|
|
183
|
+
}
|
|
184
|
+
.version-history-clear[hidden] { display: none; }
|
|
185
|
+
.version-history-clear:hover { color: #d91f2f; }
|
|
186
|
+
.nav-search-row {
|
|
187
|
+
display: flex;
|
|
188
|
+
align-items: center;
|
|
189
|
+
gap: 6px;
|
|
190
|
+
margin-bottom: 6px;
|
|
191
|
+
}
|
|
192
|
+
.nav-search-input {
|
|
193
|
+
flex: 1;
|
|
194
|
+
border: 1px solid #dfe5ee;
|
|
195
|
+
border-radius: 4px;
|
|
196
|
+
padding: 3px 7px;
|
|
197
|
+
font-size: 12px;
|
|
198
|
+
color: #20242d;
|
|
199
|
+
outline: none;
|
|
200
|
+
}
|
|
201
|
+
.nav-search-input:focus { border-color: #1677ff; }
|
|
202
|
+
|
|
203
|
+
.stats-row {
|
|
204
|
+
font-size: 11px;
|
|
205
|
+
color: #7b8495;
|
|
206
|
+
margin-bottom: 7px;
|
|
207
|
+
}
|
|
208
|
+
.stats-row b { color: #1677ff; font-weight: 600; }
|
|
209
|
+
|
|
210
|
+
.toolbar {
|
|
211
|
+
display: flex;
|
|
212
|
+
align-items: center;
|
|
213
|
+
gap: 5px;
|
|
214
|
+
flex-wrap: wrap;
|
|
215
|
+
}
|
|
216
|
+
.btn {
|
|
217
|
+
padding: 3px 9px;
|
|
218
|
+
border-radius: 4px;
|
|
219
|
+
font-size: 11px;
|
|
220
|
+
cursor: pointer;
|
|
221
|
+
border: 1px solid #dfe5ee;
|
|
222
|
+
background: #fff;
|
|
223
|
+
color: #4f5665;
|
|
224
|
+
white-space: nowrap;
|
|
225
|
+
transition: background 0.12s;
|
|
226
|
+
}
|
|
227
|
+
.btn:hover { background: #f0f5ff; color: #1677ff; border-color: #bfdbff; }
|
|
228
|
+
.btn-primary {
|
|
229
|
+
background: #1677ff;
|
|
230
|
+
border-color: #1677ff;
|
|
231
|
+
color: #fff;
|
|
232
|
+
margin-left: auto;
|
|
233
|
+
}
|
|
234
|
+
.btn-primary:hover { background: #0d5edb; }
|
|
235
|
+
|
|
236
|
+
.filter-toggle {
|
|
237
|
+
display: flex;
|
|
238
|
+
align-items: center;
|
|
239
|
+
gap: 4px;
|
|
240
|
+
font-size: 11px;
|
|
241
|
+
color: #4f5665;
|
|
242
|
+
cursor: pointer;
|
|
243
|
+
user-select: none;
|
|
244
|
+
}
|
|
245
|
+
.filter-toggle input { cursor: pointer; accent-color: #1677ff; }
|
|
246
|
+
|
|
247
|
+
/* ── Tree ── */
|
|
248
|
+
.sidebar-tree {
|
|
249
|
+
flex: 1;
|
|
250
|
+
overflow-y: auto;
|
|
251
|
+
padding: 6px 0 12px;
|
|
252
|
+
}
|
|
253
|
+
.sidebar-tree::-webkit-scrollbar { width: 4px; }
|
|
254
|
+
.sidebar-tree::-webkit-scrollbar-thumb { background: #dfe5ee; border-radius: 4px; }
|
|
255
|
+
|
|
256
|
+
.file-row.search-hidden,
|
|
257
|
+
.folder.search-hidden { display: none; }
|
|
258
|
+
.sidebar-tree.is-searching .folder.search-match-folder > .folder-children { display: block; }
|
|
259
|
+
.sidebar-tree.is-searching .folder.search-match-folder > .folder-head .folder-arrow { transform: none; }
|
|
260
|
+
|
|
261
|
+
/* ── Folder ── */
|
|
262
|
+
.folder-head {
|
|
263
|
+
display: flex;
|
|
264
|
+
align-items: center;
|
|
265
|
+
gap: 3px;
|
|
266
|
+
padding: 3px 8px;
|
|
267
|
+
cursor: pointer;
|
|
268
|
+
user-select: none;
|
|
269
|
+
color: #20242d;
|
|
270
|
+
font-weight: 500;
|
|
271
|
+
font-size: 12.5px;
|
|
272
|
+
}
|
|
273
|
+
.folder-head:hover { background: #f6f9ff; }
|
|
274
|
+
.folder-arrow {
|
|
275
|
+
display: inline-flex;
|
|
276
|
+
align-items: center;
|
|
277
|
+
justify-content: center;
|
|
278
|
+
width: 14px; height: 14px;
|
|
279
|
+
transition: transform 0.15s;
|
|
280
|
+
color: #7b8495;
|
|
281
|
+
flex-shrink: 0;
|
|
282
|
+
}
|
|
283
|
+
.folder-arrow svg { width: 9px; height: 9px; fill: currentColor; }
|
|
284
|
+
.folder.collapsed > .folder-children { display: none; }
|
|
285
|
+
.folder.collapsed > .folder-head .folder-arrow { transform: rotate(-90deg); }
|
|
286
|
+
.folder-icon { color: #f5a400; flex-shrink: 0; }
|
|
287
|
+
.folder-icon svg { width: 13px; height: 13px; fill: currentColor; display: block; }
|
|
288
|
+
|
|
289
|
+
/* ── File row ── */
|
|
290
|
+
.file-row {
|
|
291
|
+
display: flex;
|
|
292
|
+
flex-direction: column;
|
|
293
|
+
padding: 0 8px;
|
|
294
|
+
cursor: pointer;
|
|
295
|
+
border-radius: 0;
|
|
296
|
+
}
|
|
297
|
+
.file-row:hover .file-main { background: #f0f5ff; border-radius: 4px; }
|
|
298
|
+
.file-row.active .file-main {
|
|
299
|
+
background: #1677ff;
|
|
300
|
+
border-radius: 4px;
|
|
301
|
+
}
|
|
302
|
+
.file-row.active .file-name { color: #fff; }
|
|
303
|
+
.file-row.active .file-icon { color: #bfdbff; }
|
|
304
|
+
.file-row.active .review-btn { border-color: rgba(255,255,255,0.45); color: rgba(255,255,255,0.78); }
|
|
305
|
+
.file-row.active .review-btn.is-reviewed { background: rgba(255,255,255,0.18); color: #fff; }
|
|
306
|
+
|
|
307
|
+
.file-main {
|
|
308
|
+
display: flex;
|
|
309
|
+
align-items: center;
|
|
310
|
+
gap: 4px;
|
|
311
|
+
padding: 3px 5px;
|
|
312
|
+
border-radius: 4px;
|
|
313
|
+
min-width: 0;
|
|
314
|
+
}
|
|
315
|
+
.file-icon { color: #94c5ff; flex-shrink: 0; }
|
|
316
|
+
.file-icon svg { width: 12px; height: 12px; fill: currentColor; display: block; }
|
|
317
|
+
.file-name {
|
|
318
|
+
flex: 1;
|
|
319
|
+
font-size: 12px;
|
|
320
|
+
color: #20242d;
|
|
321
|
+
white-space: nowrap;
|
|
322
|
+
overflow: hidden;
|
|
323
|
+
text-overflow: ellipsis;
|
|
324
|
+
min-width: 0;
|
|
325
|
+
}
|
|
326
|
+
/* ══════════════════════════════
|
|
327
|
+
RIGHT PREVIEW
|
|
328
|
+
══════════════════════════════ */
|
|
329
|
+
.preview {
|
|
330
|
+
flex: 1;
|
|
331
|
+
min-width: 0;
|
|
332
|
+
display: flex;
|
|
333
|
+
flex-direction: column;
|
|
334
|
+
overflow: hidden;
|
|
335
|
+
background: #f3f3f3;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.preview-bar {
|
|
339
|
+
height: 38px;
|
|
340
|
+
background: #fff;
|
|
341
|
+
border-bottom: 1px solid #dfe5ee;
|
|
342
|
+
display: flex;
|
|
343
|
+
align-items: center;
|
|
344
|
+
padding: 0 14px;
|
|
345
|
+
gap: 8px;
|
|
346
|
+
flex-shrink: 0;
|
|
347
|
+
}
|
|
348
|
+
.preview-breadcrumb {
|
|
349
|
+
font-size: 12px;
|
|
350
|
+
color: #7b8495;
|
|
351
|
+
flex: 1;
|
|
352
|
+
overflow: hidden;
|
|
353
|
+
text-overflow: ellipsis;
|
|
354
|
+
white-space: nowrap;
|
|
355
|
+
}
|
|
356
|
+
.preview-breadcrumb b { color: #20242d; }
|
|
357
|
+
.preview-open-btn {
|
|
358
|
+
font-size: 11px;
|
|
359
|
+
color: #1677ff;
|
|
360
|
+
cursor: pointer;
|
|
361
|
+
text-decoration: none;
|
|
362
|
+
flex-shrink: 0;
|
|
363
|
+
padding: 3px 8px;
|
|
364
|
+
border: 1px solid #bfdbff;
|
|
365
|
+
border-radius: 4px;
|
|
366
|
+
background: #edf6ff;
|
|
367
|
+
}
|
|
368
|
+
.preview-open-btn:hover { background: #d9ebff; }
|
|
369
|
+
|
|
370
|
+
.preview-frame {
|
|
371
|
+
flex: 1;
|
|
372
|
+
border: none;
|
|
373
|
+
display: block;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
.preview-placeholder {
|
|
377
|
+
flex: 1;
|
|
378
|
+
display: flex;
|
|
379
|
+
flex-direction: column;
|
|
380
|
+
align-items: center;
|
|
381
|
+
justify-content: center;
|
|
382
|
+
gap: 10px;
|
|
383
|
+
color: #a8b2c3;
|
|
384
|
+
}
|
|
385
|
+
.preview-placeholder svg { width: 48px; height: 48px; fill: #dfe5ee; }
|
|
386
|
+
.preview-placeholder p { font-size: 13px; }
|
|
387
|
+
|
|
388
|
+
/* ── Toast ── */
|
|
389
|
+
.toast {
|
|
390
|
+
position: fixed;
|
|
391
|
+
bottom: 24px;
|
|
392
|
+
left: 50%;
|
|
393
|
+
transform: translateX(-50%);
|
|
394
|
+
background: #20242d;
|
|
395
|
+
color: #fff;
|
|
396
|
+
padding: 7px 18px;
|
|
397
|
+
border-radius: 6px;
|
|
398
|
+
font-size: 12px;
|
|
399
|
+
opacity: 0;
|
|
400
|
+
pointer-events: none;
|
|
401
|
+
transition: opacity 0.2s;
|
|
402
|
+
z-index: 9999;
|
|
403
|
+
}
|
|
404
|
+
.toast.show { opacity: 1; }
|
|
405
|
+
|
|
406
|
+
/* ── Version badge ── */
|
|
407
|
+
.version-badge {
|
|
408
|
+
flex-shrink: 0;
|
|
409
|
+
display: inline-block;
|
|
410
|
+
background: #edf6ff;
|
|
411
|
+
border: 1px solid #bfdbff;
|
|
412
|
+
border-radius: 3px;
|
|
413
|
+
padding: 0 5px;
|
|
414
|
+
font-size: 10px;
|
|
415
|
+
color: #1677ff;
|
|
416
|
+
white-space: nowrap;
|
|
417
|
+
font-weight: 600;
|
|
418
|
+
line-height: 16px;
|
|
419
|
+
visibility: hidden;
|
|
420
|
+
}
|
|
421
|
+
.version-badge.loaded { visibility: visible; }
|
|
422
|
+
.version-badge.match {
|
|
423
|
+
background: #e9faea;
|
|
424
|
+
border-color: #88e69e;
|
|
425
|
+
color: #0f9f31;
|
|
426
|
+
}
|
|
427
|
+
.review-btn {
|
|
428
|
+
flex-shrink: 0;
|
|
429
|
+
width: 18px;
|
|
430
|
+
height: 18px;
|
|
431
|
+
border: 1px solid #d8dfe9;
|
|
432
|
+
border-radius: 3px;
|
|
433
|
+
background: #fff;
|
|
434
|
+
color: #8a94a6;
|
|
435
|
+
display: inline-flex;
|
|
436
|
+
align-items: center;
|
|
437
|
+
justify-content: center;
|
|
438
|
+
font-size: 11px;
|
|
439
|
+
line-height: 1;
|
|
440
|
+
font-weight: 700;
|
|
441
|
+
cursor: pointer;
|
|
442
|
+
padding: 0;
|
|
443
|
+
}
|
|
444
|
+
.review-btn:hover { border-color: #1677ff; color: #1677ff; background: #f0f5ff; }
|
|
445
|
+
.review-btn.is-reviewed {
|
|
446
|
+
background: #e9faea;
|
|
447
|
+
border-color: #88e69e;
|
|
448
|
+
color: #0f9f31;
|
|
449
|
+
}
|
|
450
|
+
/* version filter: hide rows whose badge doesn't match */
|
|
451
|
+
.filter-by-version .file-row:not(.version-match) { display: none; }
|
|
452
|
+
</style>
|
|
453
|
+
</head>
|
|
454
|
+
<body>
|
|
455
|
+
|
|
456
|
+
<!-- ═══ LEFT SIDEBAR ═══ -->
|
|
457
|
+
<div class="sidebar">
|
|
458
|
+
<div class="sidebar-header">
|
|
459
|
+
<div class="sidebar-title-row">
|
|
460
|
+
<div class="sidebar-title">Demo 原型导航</div>
|
|
461
|
+
<button class="copy-address-btn" id="copyAddressBtn" type="button">复制地址</button>
|
|
462
|
+
</div>
|
|
463
|
+
<div class="version-row">
|
|
464
|
+
<span class="version-label">版本</span>
|
|
465
|
+
<div class="version-search-control">
|
|
466
|
+
<input class="version-input" id="versionInput" type="text" placeholder="V2.10.0">
|
|
467
|
+
<button class="version-search-btn" id="versionSearchBtn" type="button">搜索</button>
|
|
468
|
+
</div>
|
|
469
|
+
<div class="version-history" id="versionHistory" aria-label="历史版本"></div>
|
|
470
|
+
<button class="version-history-clear" id="clearVersionHistoryBtn" type="button" aria-label="清空历史版本" hidden>清空</button>
|
|
471
|
+
</div>
|
|
472
|
+
<div class="nav-search-row">
|
|
473
|
+
<span class="version-label">搜索</span>
|
|
474
|
+
<input class="nav-search-input" id="navSearchInput" type="search" placeholder="搜索标题">
|
|
475
|
+
</div>
|
|
476
|
+
<div class="stats-row">
|
|
477
|
+
共 <b id="totalCount">0</b> 个页面 · 该版本 <b id="versionMatchCount">0</b> 个
|
|
478
|
+
</div>
|
|
479
|
+
<div class="toolbar">
|
|
480
|
+
<label class="filter-toggle">
|
|
481
|
+
<input type="checkbox" id="versionFilterToggle"> 只显该版本
|
|
482
|
+
</label>
|
|
483
|
+
<button class="btn" id="expandAllBtn">全部展开</button>
|
|
484
|
+
<button class="btn" id="collapseAllBtn">全部折叠</button>
|
|
485
|
+
</div>
|
|
486
|
+
</div>
|
|
487
|
+
|
|
488
|
+
<div class="sidebar-tree" id="sidebarTree"></div>
|
|
489
|
+
<button class="sidebar-resizer" id="sidebarResizer" type="button" aria-label="拖动调整导航栏宽度"></button>
|
|
490
|
+
</div>
|
|
491
|
+
|
|
492
|
+
<!-- ═══ RIGHT PREVIEW ═══ -->
|
|
493
|
+
<div class="preview" id="previewArea">
|
|
494
|
+
<div class="preview-bar" id="previewBar" style="display:none">
|
|
495
|
+
<span class="preview-breadcrumb" id="previewBreadcrumb"></span>
|
|
496
|
+
<a class="preview-open-btn" id="previewOpenBtn" target="_blank">在新标签打开 ↗</a>
|
|
497
|
+
</div>
|
|
498
|
+
<div class="preview-placeholder" id="previewPlaceholder">
|
|
499
|
+
<svg viewBox="0 0 48 48"><rect x="6" y="8" width="36" height="32" rx="3"/><rect x="12" y="16" width="24" height="2" rx="1" fill="#fff" fill-opacity=".5"/><rect x="12" y="22" width="16" height="2" rx="1" fill="#fff" fill-opacity=".5"/></svg>
|
|
500
|
+
<p>← 点击左侧页面预览</p>
|
|
501
|
+
</div>
|
|
502
|
+
<iframe class="preview-frame" id="previewFrame" style="display:none"></iframe>
|
|
503
|
+
</div>
|
|
504
|
+
|
|
505
|
+
<div class="toast" id="toast"></div>
|
|
506
|
+
|
|
507
|
+
<script>
|
|
508
|
+
// ─────────────────────────────────────────────
|
|
509
|
+
// PAGE TREE — 运行时从同目录 nav-tree.json 拉取,由
|
|
510
|
+
// scripts/check/sync-nav-tree.js 自动同步文件系统新增/删除的页面
|
|
511
|
+
// ─────────────────────────────────────────────
|
|
512
|
+
let TREE = [];
|
|
513
|
+
async function loadTree() {
|
|
514
|
+
const res = await fetch('./nav-tree.json', { cache: 'no-cache' });
|
|
515
|
+
if (!res.ok) throw new Error('nav-tree.json 加载失败:' + res.status);
|
|
516
|
+
TREE = await res.json();
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// ─────────────────────────────────────────────
|
|
520
|
+
// Storage
|
|
521
|
+
// ─────────────────────────────────────────────
|
|
522
|
+
const NAV_NS = 'demo-navigator';
|
|
523
|
+
const VERSION_KEY = NAV_NS + '-version';
|
|
524
|
+
const VERSION_HISTORY_KEY = NAV_NS + '-version-history';
|
|
525
|
+
const REVIEW_KEY = NAV_NS + '-review-status';
|
|
526
|
+
const SIDEBAR_WIDTH_KEY = NAV_NS + '-sidebar-width';
|
|
527
|
+
// 复制当前页面地址(供分享本地/局域网预览地址)
|
|
528
|
+
const navStorage = window['localStorage'];
|
|
529
|
+
|
|
530
|
+
function loadReviewStatus() {
|
|
531
|
+
try { return JSON.parse(navStorage.getItem(REVIEW_KEY) || '{}'); } catch { return {}; }
|
|
532
|
+
}
|
|
533
|
+
function saveReviewStatus() { navStorage.setItem(REVIEW_KEY, JSON.stringify(reviewStatus)); }
|
|
534
|
+
|
|
535
|
+
function loadVersionHistory() {
|
|
536
|
+
try {
|
|
537
|
+
const history = JSON.parse(navStorage.getItem(VERSION_HISTORY_KEY) || '[]');
|
|
538
|
+
return Array.isArray(history) ? history.filter(Boolean).slice(0, 2) : [];
|
|
539
|
+
} catch {
|
|
540
|
+
return [];
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function saveVersionHistory() {
|
|
545
|
+
navStorage.setItem(VERSION_HISTORY_KEY, JSON.stringify(versionHistory));
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
let reviewStatus = loadReviewStatus();
|
|
549
|
+
let versionHistory = loadVersionHistory();
|
|
550
|
+
let activeRow = null;
|
|
551
|
+
|
|
552
|
+
// ─────────────────────────────────────────────
|
|
553
|
+
// Sidebar resize
|
|
554
|
+
// ─────────────────────────────────────────────
|
|
555
|
+
const SIDEBAR_MIN_WIDTH = 220;
|
|
556
|
+
const SIDEBAR_MAX_WIDTH = 520;
|
|
557
|
+
const SIDEBAR_DEFAULT_WIDTH = 290;
|
|
558
|
+
|
|
559
|
+
function clampSidebarWidth(width) {
|
|
560
|
+
return Math.min(SIDEBAR_MAX_WIDTH, Math.max(SIDEBAR_MIN_WIDTH, Math.round(width)));
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function setSidebarWidth(width, persist) {
|
|
564
|
+
const sidebar = document.querySelector('.sidebar');
|
|
565
|
+
if (!sidebar) return;
|
|
566
|
+
const nextWidth = clampSidebarWidth(width);
|
|
567
|
+
sidebar.style.width = nextWidth + 'px';
|
|
568
|
+
if (persist) navStorage.setItem(SIDEBAR_WIDTH_KEY, String(nextWidth));
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function initSidebarResize() {
|
|
572
|
+
const sidebar = document.querySelector('.sidebar');
|
|
573
|
+
const resizer = document.getElementById('sidebarResizer');
|
|
574
|
+
if (!sidebar || !resizer) return;
|
|
575
|
+
let resizing = false;
|
|
576
|
+
|
|
577
|
+
const savedWidth = parseInt(navStorage.getItem(SIDEBAR_WIDTH_KEY) || '', 10);
|
|
578
|
+
setSidebarWidth(Number.isFinite(savedWidth) ? savedWidth : SIDEBAR_DEFAULT_WIDTH, false);
|
|
579
|
+
|
|
580
|
+
function startResize(e, moveEvent, endEvent, cancelEvent) {
|
|
581
|
+
if (resizing || (e.button !== undefined && e.button !== 0)) return;
|
|
582
|
+
resizing = true;
|
|
583
|
+
e.preventDefault();
|
|
584
|
+
resizer.classList.add('is-resizing');
|
|
585
|
+
document.body.classList.add('is-resizing-sidebar');
|
|
586
|
+
if (e.pointerId !== undefined && resizer.setPointerCapture) resizer.setPointerCapture(e.pointerId);
|
|
587
|
+
|
|
588
|
+
const move = event => setSidebarWidth(event.clientX, false);
|
|
589
|
+
const stop = event => {
|
|
590
|
+
setSidebarWidth(sidebar.getBoundingClientRect().width, true);
|
|
591
|
+
resizing = false;
|
|
592
|
+
resizer.classList.remove('is-resizing');
|
|
593
|
+
document.body.classList.remove('is-resizing-sidebar');
|
|
594
|
+
if (event.pointerId !== undefined && resizer.releasePointerCapture) resizer.releasePointerCapture(event.pointerId);
|
|
595
|
+
document.removeEventListener(moveEvent, move);
|
|
596
|
+
document.removeEventListener(endEvent, stop);
|
|
597
|
+
if (cancelEvent) document.removeEventListener(cancelEvent, stop);
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
document.addEventListener(moveEvent, move);
|
|
601
|
+
document.addEventListener(endEvent, stop);
|
|
602
|
+
if (cancelEvent) document.addEventListener(cancelEvent, stop);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
resizer.addEventListener('pointerdown', e => {
|
|
606
|
+
if (e.pointerType === 'mouse') return;
|
|
607
|
+
startResize(e, 'pointermove', 'pointerup', 'pointercancel');
|
|
608
|
+
});
|
|
609
|
+
resizer.addEventListener('mousedown', e => startResize(e, 'mousemove', 'mouseup'));
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// ─────────────────────────────────────────────
|
|
613
|
+
// Version cache (path → latest PRD version string)
|
|
614
|
+
// ─────────────────────────────────────────────
|
|
615
|
+
const VER_CACHE_KEY = NAV_NS + '-prd-versions';
|
|
616
|
+
let versionCache = {};
|
|
617
|
+
function loadVersionCache() { try { return JSON.parse(navStorage.getItem(VER_CACHE_KEY) || '{}'); } catch { return {}; } }
|
|
618
|
+
function saveVersionCache() { navStorage.setItem(VER_CACHE_KEY, JSON.stringify(versionCache)); }
|
|
619
|
+
versionCache = loadVersionCache();
|
|
620
|
+
|
|
621
|
+
async function fetchPageVersion(htmlPath) {
|
|
622
|
+
const mdPath = htmlPath.replace(/\.html$/, '.md');
|
|
623
|
+
try {
|
|
624
|
+
const res = await fetch(mdPath, { cache: 'no-cache' });
|
|
625
|
+
if (!res.ok) return null;
|
|
626
|
+
const text = await res.text();
|
|
627
|
+
// find all version rows like "| V2.10.3 | ..." and take the last one
|
|
628
|
+
// strip inline HTML tags first so a highlighted version cell (e.g. <span style="color:...">V2.11.3</span>) still matches
|
|
629
|
+
const plainText = text.replace(/<[^>]+>/g, '');
|
|
630
|
+
const matches = [...plainText.matchAll(/^\|\s*(V[\d]+\.[\d.]+\w*)\s*\|/gm)];
|
|
631
|
+
return matches.length ? matches[matches.length - 1][1] : null;
|
|
632
|
+
} catch { return null; }
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function applyVersionBadge(path, ver) {
|
|
636
|
+
const row = document.querySelector(`.file-row[data-path="${CSS.escape(path)}"]`);
|
|
637
|
+
if (!row) return;
|
|
638
|
+
const badge = row.querySelector('.version-badge');
|
|
639
|
+
if (!badge) return;
|
|
640
|
+
if (ver) {
|
|
641
|
+
badge.textContent = ver;
|
|
642
|
+
badge.classList.add('loaded');
|
|
643
|
+
row.dataset.prdVersion = ver;
|
|
644
|
+
}
|
|
645
|
+
refreshVersionMatch(row);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function refreshVersionMatch(row) {
|
|
649
|
+
const currentVer = (document.getElementById('versionInput').value || '').trim();
|
|
650
|
+
const prdVer = row.dataset.prdVersion || '';
|
|
651
|
+
const isMatch = currentVer && prdVer && fuzzyVersionMatch(prdVer, currentVer);
|
|
652
|
+
row.classList.toggle('version-match', isMatch);
|
|
653
|
+
const badge = row.querySelector('.version-badge');
|
|
654
|
+
if (badge) badge.classList.toggle('match', isMatch);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
async function fetchAllVersions() {
|
|
658
|
+
// collect all file paths from tree
|
|
659
|
+
const paths = [];
|
|
660
|
+
function collect(nodes) { nodes.forEach(n => n.file ? paths.push(n.path) : collect(n.children || [])); }
|
|
661
|
+
collect(TREE);
|
|
662
|
+
|
|
663
|
+
// show cached values instantly, then always re-fetch for latest
|
|
664
|
+
paths.forEach(p => { if (versionCache[p]) applyVersionBadge(p, versionCache[p]); });
|
|
665
|
+
|
|
666
|
+
// always re-fetch all versions in batches of 8
|
|
667
|
+
for (let i = 0; i < paths.length; i += 8) {
|
|
668
|
+
const batch = paths.slice(i, i + 8);
|
|
669
|
+
await Promise.all(batch.map(async p => {
|
|
670
|
+
const ver = await fetchPageVersion(p);
|
|
671
|
+
versionCache[p] = ver || '';
|
|
672
|
+
applyVersionBadge(p, ver);
|
|
673
|
+
}));
|
|
674
|
+
}
|
|
675
|
+
saveVersionCache();
|
|
676
|
+
updateStats();
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// ─────────────────────────────────────────────
|
|
680
|
+
// Icons
|
|
681
|
+
// ─────────────────────────────────────────────
|
|
682
|
+
const I_ARROW = `<svg viewBox="0 0 10 10"><polygon points="2,2 8,5 2,8"/></svg>`;
|
|
683
|
+
const I_FOLDER = `<svg viewBox="0 0 16 16"><path d="M1 3a1 1 0 011-1h4.586a1 1 0 01.707.293L8.414 3.5H14a1 1 0 011 1v8a1 1 0 01-1 1H2a1 1 0 01-1-1V3z"/></svg>`;
|
|
684
|
+
const I_FILE = `<svg viewBox="0 0 16 16"><path d="M4 1h6l4 4v9a1 1 0 01-1 1H3a1 1 0 01-1-1V2a1 1 0 011-1z"/><path fill="#fff" fill-opacity=".5" d="M10 1v4h4"/></svg>`;
|
|
685
|
+
|
|
686
|
+
// ─────────────────────────────────────────────
|
|
687
|
+
// Breadcrumb path map (path → "folder / folder")
|
|
688
|
+
// ─────────────────────────────────────────────
|
|
689
|
+
const breadcrumbMap = {};
|
|
690
|
+
function buildBreadcrumbs(nodes, trail) {
|
|
691
|
+
nodes.forEach(n => {
|
|
692
|
+
if (n.file) {
|
|
693
|
+
breadcrumbMap[n.path] = trail ? trail + ' / ' + n.file : n.file;
|
|
694
|
+
} else {
|
|
695
|
+
buildBreadcrumbs(n.children || [], trail ? trail + ' / ' + n.name : n.name);
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// ─────────────────────────────────────────────
|
|
701
|
+
// Preview
|
|
702
|
+
// ─────────────────────────────────────────────
|
|
703
|
+
function loadPreview(path, row) {
|
|
704
|
+
// deactivate previous
|
|
705
|
+
if (activeRow) activeRow.classList.remove('active');
|
|
706
|
+
activeRow = row;
|
|
707
|
+
row.classList.add('active');
|
|
708
|
+
|
|
709
|
+
const frame = document.getElementById('previewFrame');
|
|
710
|
+
const placeholder = document.getElementById('previewPlaceholder');
|
|
711
|
+
const bar = document.getElementById('previewBar');
|
|
712
|
+
const breadcrumb = document.getElementById('previewBreadcrumb');
|
|
713
|
+
const openBtn = document.getElementById('previewOpenBtn');
|
|
714
|
+
|
|
715
|
+
const url = path;
|
|
716
|
+
frame.src = url;
|
|
717
|
+
frame.style.display = 'block';
|
|
718
|
+
placeholder.style.display = 'none';
|
|
719
|
+
bar.style.display = 'flex';
|
|
720
|
+
|
|
721
|
+
const parts = (breadcrumbMap[path] || path).split(' / ');
|
|
722
|
+
const last = parts.pop();
|
|
723
|
+
const prefix = parts.join(' / ');
|
|
724
|
+
breadcrumb.innerHTML = prefix
|
|
725
|
+
? `${prefix} / <b>${last}</b>`
|
|
726
|
+
: `<b>${last}</b>`;
|
|
727
|
+
openBtn.href = url;
|
|
728
|
+
window.dispatchEvent(new CustomEvent('pak-page-change', {
|
|
729
|
+
detail: {
|
|
730
|
+
htmlPath: decodeURIComponent(new URL(url, window.location.href).pathname),
|
|
731
|
+
title: last
|
|
732
|
+
}
|
|
733
|
+
}));
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// ─────────────────────────────────────────────
|
|
737
|
+
// Review status helpers
|
|
738
|
+
// ─────────────────────────────────────────────
|
|
739
|
+
function isReviewed(path, type) {
|
|
740
|
+
return !!(reviewStatus[path] && reviewStatus[path][type]);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function renderReviewButton(path, type, label) {
|
|
744
|
+
const reviewed = isReviewed(path, type);
|
|
745
|
+
const text = reviewed ? '✓' : '−';
|
|
746
|
+
const title = label + (reviewed ? ' 已审核' : ' 未审核');
|
|
747
|
+
return `<button type="button" class="review-btn${reviewed ? ' is-reviewed' : ''}" data-review-target="${type}" title="${title}" aria-label="${title}" aria-pressed="${reviewed ? 'true' : 'false'}">${text}</button>`;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function refreshReviewButton(button, node) {
|
|
751
|
+
const type = button.getAttribute('data-review-target');
|
|
752
|
+
const label = type === 'html' ? 'HTML' : 'MD';
|
|
753
|
+
const reviewed = isReviewed(node.path, type);
|
|
754
|
+
const title = label + (reviewed ? ' 已审核' : ' 未审核');
|
|
755
|
+
button.classList.toggle('is-reviewed', reviewed);
|
|
756
|
+
button.textContent = reviewed ? '✓' : '−';
|
|
757
|
+
button.title = title;
|
|
758
|
+
button.setAttribute('aria-label', title);
|
|
759
|
+
button.setAttribute('aria-pressed', reviewed ? 'true' : 'false');
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
function toggleReviewStatus(row, node, type) {
|
|
763
|
+
const current = isReviewed(node.path, type);
|
|
764
|
+
const next = !current;
|
|
765
|
+
const state = reviewStatus[node.path] || {};
|
|
766
|
+
state[type] = next;
|
|
767
|
+
if (!state.html && !state.md) delete reviewStatus[node.path];
|
|
768
|
+
else reviewStatus[node.path] = state;
|
|
769
|
+
saveReviewStatus();
|
|
770
|
+
const button = row.querySelector(`.review-btn[data-review-target="${type}"]`);
|
|
771
|
+
if (button) refreshReviewButton(button, node);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// ─────────────────────────────────────────────
|
|
775
|
+
// Search helpers
|
|
776
|
+
// ─────────────────────────────────────────────
|
|
777
|
+
function normalizeSearchText(text) {
|
|
778
|
+
return String(text || '').toLowerCase().replace(/\s+/g, '');
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function fuzzySearchMatch(text, keyword) {
|
|
782
|
+
const source = normalizeSearchText(text);
|
|
783
|
+
const target = normalizeSearchText(keyword);
|
|
784
|
+
if (!target) return true;
|
|
785
|
+
if (source.indexOf(target) !== -1) return true;
|
|
786
|
+
|
|
787
|
+
let index = 0;
|
|
788
|
+
for (const char of target) {
|
|
789
|
+
index = source.indexOf(char, index);
|
|
790
|
+
if (index === -1) return false;
|
|
791
|
+
index++;
|
|
792
|
+
}
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function normalizeVersionSearchText(text) {
|
|
797
|
+
return normalizeSearchText(text).replace(/[._-]/g, '');
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
function fuzzyVersionMatch(version, keyword) {
|
|
801
|
+
const source = normalizeVersionSearchText(version);
|
|
802
|
+
const target = normalizeVersionSearchText(keyword);
|
|
803
|
+
if (!target) return true;
|
|
804
|
+
if (source.indexOf(target) !== -1) return true;
|
|
805
|
+
|
|
806
|
+
let index = 0;
|
|
807
|
+
for (const char of target) {
|
|
808
|
+
index = source.indexOf(char, index);
|
|
809
|
+
if (index === -1) return false;
|
|
810
|
+
index++;
|
|
811
|
+
}
|
|
812
|
+
return true;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
function renderVersionHistory() {
|
|
816
|
+
const container = document.getElementById('versionHistory');
|
|
817
|
+
const clearButton = document.getElementById('clearVersionHistoryBtn');
|
|
818
|
+
const visibleHistory = versionHistory.slice(0, 2);
|
|
819
|
+
container.replaceChildren();
|
|
820
|
+
|
|
821
|
+
if (!visibleHistory.length) {
|
|
822
|
+
const emptyState = document.createElement('span');
|
|
823
|
+
emptyState.className = 'version-history-empty';
|
|
824
|
+
emptyState.textContent = '暂无历史';
|
|
825
|
+
container.appendChild(emptyState);
|
|
826
|
+
clearButton.hidden = true;
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
clearButton.hidden = false;
|
|
831
|
+
visibleHistory.forEach(version => {
|
|
832
|
+
const button = document.createElement('button');
|
|
833
|
+
button.type = 'button';
|
|
834
|
+
button.className = 'version-history-tag';
|
|
835
|
+
button.textContent = version;
|
|
836
|
+
button.title = `搜索版本 ${version}`;
|
|
837
|
+
button.setAttribute('aria-label', `搜索版本 ${version}`);
|
|
838
|
+
button.addEventListener('click', () => activateHistoryVersion(version));
|
|
839
|
+
container.appendChild(button);
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
function updateVersionHistory(version) {
|
|
844
|
+
versionHistory = [version, ...versionHistory]
|
|
845
|
+
.filter((item, index, list) => list.indexOf(item) === index)
|
|
846
|
+
.slice(0, 2);
|
|
847
|
+
saveVersionHistory();
|
|
848
|
+
renderVersionHistory();
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function activateHistoryVersion(version) {
|
|
852
|
+
const input = document.getElementById('versionInput');
|
|
853
|
+
input.value = version;
|
|
854
|
+
navStorage.setItem(VERSION_KEY, version);
|
|
855
|
+
updateVersionHistory(version);
|
|
856
|
+
input.dispatchEvent(new Event('input'));
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
function submitVersionSearch() {
|
|
860
|
+
const nextVersion = document.getElementById('versionInput').value.trim();
|
|
861
|
+
const matchCount = document.querySelectorAll('.file-row.version-match').length;
|
|
862
|
+
if (!nextVersion) {
|
|
863
|
+
showToast('请输入版本号');
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
if (!matchCount) {
|
|
867
|
+
showToast('未找到该版本页面');
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
updateVersionHistory(nextVersion);
|
|
872
|
+
navStorage.setItem(VERSION_KEY, nextVersion);
|
|
873
|
+
showToast(`找到 ${matchCount} 个页面`);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function applyTitleSearch() {
|
|
877
|
+
const treeWrap = document.getElementById('sidebarTree');
|
|
878
|
+
const keyword = normalizeSearchText(document.getElementById('navSearchInput').value);
|
|
879
|
+
treeWrap.classList.toggle('is-searching', !!keyword);
|
|
880
|
+
|
|
881
|
+
treeWrap.querySelectorAll('.folder').forEach(folder => {
|
|
882
|
+
folder.classList.remove('search-hidden', 'search-match-folder');
|
|
883
|
+
});
|
|
884
|
+
treeWrap.querySelectorAll('.file-row').forEach(row => {
|
|
885
|
+
const matched = fuzzySearchMatch(row.dataset.searchText, keyword);
|
|
886
|
+
row.classList.toggle('search-hidden', !matched);
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
if (!keyword) return;
|
|
890
|
+
|
|
891
|
+
Array.from(treeWrap.querySelectorAll('.folder')).reverse().forEach(folder => {
|
|
892
|
+
const folderMatched = fuzzySearchMatch(folder.dataset.searchText, keyword);
|
|
893
|
+
const hasMatchedChild = !!folder.querySelector(':scope > .folder-children .file-row:not(.search-hidden), :scope > .folder-children .folder:not(.search-hidden)');
|
|
894
|
+
const visible = folderMatched || hasMatchedChild;
|
|
895
|
+
folder.classList.toggle('search-hidden', !visible);
|
|
896
|
+
folder.classList.toggle('search-match-folder', visible);
|
|
897
|
+
if (folderMatched) {
|
|
898
|
+
folder.querySelectorAll('.file-row, .folder').forEach(child => child.classList.remove('search-hidden'));
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// ─────────────────────────────────────────────
|
|
904
|
+
// Render tree
|
|
905
|
+
// ─────────────────────────────────────────────
|
|
906
|
+
let totalCount = 0;
|
|
907
|
+
|
|
908
|
+
function renderNodes(nodes, depth) {
|
|
909
|
+
const wrap = document.createElement('div');
|
|
910
|
+
wrap.style.paddingLeft = depth === 0 ? '0' : '14px';
|
|
911
|
+
|
|
912
|
+
nodes.forEach(node => {
|
|
913
|
+
if (node.file) {
|
|
914
|
+
totalCount++;
|
|
915
|
+
|
|
916
|
+
const row = document.createElement('div');
|
|
917
|
+
row.className = 'file-row';
|
|
918
|
+
row.dataset.path = node.path;
|
|
919
|
+
row.dataset.searchText = [node.file, node.path, breadcrumbMap[node.path] || ''].join(' ');
|
|
920
|
+
row.innerHTML = `
|
|
921
|
+
<div class="file-main">
|
|
922
|
+
<span class="file-icon">${I_FILE}</span>
|
|
923
|
+
<span class="file-name" title="${node.file}">${node.file}</span>
|
|
924
|
+
<span class="version-badge"></span>
|
|
925
|
+
<!-- review-btn:start (个人审核标记,本地开发专用;发布时可自动剥离) -->
|
|
926
|
+
${renderReviewButton(node.path, 'html', 'HTML')}
|
|
927
|
+
${renderReviewButton(node.path, 'md', 'MD')}
|
|
928
|
+
<!-- review-btn:end -->
|
|
929
|
+
</div>`;
|
|
930
|
+
|
|
931
|
+
// click row → preview
|
|
932
|
+
row.querySelector('.file-main').addEventListener('click', () => loadPreview(node.path, row));
|
|
933
|
+
|
|
934
|
+
row.querySelectorAll('.review-btn').forEach(button => {
|
|
935
|
+
button.addEventListener('click', e => {
|
|
936
|
+
e.stopPropagation();
|
|
937
|
+
toggleReviewStatus(row, node, button.getAttribute('data-review-target'));
|
|
938
|
+
});
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
wrap.appendChild(row);
|
|
942
|
+
} else {
|
|
943
|
+
const folder = document.createElement('div');
|
|
944
|
+
folder.className = 'folder';
|
|
945
|
+
folder.dataset.searchText = node.name;
|
|
946
|
+
|
|
947
|
+
const head = document.createElement('div');
|
|
948
|
+
head.className = 'folder-head';
|
|
949
|
+
head.innerHTML = `<span class="folder-arrow">${I_ARROW}</span><span class="folder-icon">${I_FOLDER}</span><span>${node.name}</span>`;
|
|
950
|
+
head.addEventListener('click', () => folder.classList.toggle('collapsed'));
|
|
951
|
+
|
|
952
|
+
folder.appendChild(head);
|
|
953
|
+
folder.appendChild(renderNodes(node.children || [], depth + 1));
|
|
954
|
+
folder.classList.add('folder-children-wrap');
|
|
955
|
+
|
|
956
|
+
// wrap children into .folder-children div for collapse
|
|
957
|
+
const childrenDiv = folder.lastChild;
|
|
958
|
+
childrenDiv.classList = '';
|
|
959
|
+
childrenDiv.className = 'folder-children';
|
|
960
|
+
|
|
961
|
+
wrap.appendChild(folder);
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
return wrap;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// ─────────────────────────────────────────────
|
|
968
|
+
// Stats
|
|
969
|
+
// ─────────────────────────────────────────────
|
|
970
|
+
function updateStats() {
|
|
971
|
+
const currentVer = (document.getElementById('versionInput').value || '').trim();
|
|
972
|
+
const matchCount = currentVer
|
|
973
|
+
? document.querySelectorAll(`.file-row.version-match`).length
|
|
974
|
+
: 0;
|
|
975
|
+
document.getElementById('versionMatchCount').textContent = matchCount;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
function showToast(msg) {
|
|
979
|
+
const t = document.getElementById('toast');
|
|
980
|
+
t.textContent = msg;
|
|
981
|
+
t.classList.add('show');
|
|
982
|
+
setTimeout(() => t.classList.remove('show'), 2000);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
function copyText(text, successMsg) {
|
|
986
|
+
navigator.clipboard.writeText(text)
|
|
987
|
+
.then(() => showToast(successMsg))
|
|
988
|
+
.catch(() => {
|
|
989
|
+
const ta = document.createElement('textarea');
|
|
990
|
+
ta.value = text; document.body.appendChild(ta);
|
|
991
|
+
ta.select(); document.execCommand('copy'); ta.remove();
|
|
992
|
+
showToast(successMsg);
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// ─────────────────────────────────────────────
|
|
997
|
+
// Init
|
|
998
|
+
// ─────────────────────────────────────────────
|
|
999
|
+
window.addEventListener('DOMContentLoaded', async () => {
|
|
1000
|
+
initSidebarResize();
|
|
1001
|
+
try {
|
|
1002
|
+
await loadTree();
|
|
1003
|
+
} catch (e) {
|
|
1004
|
+
document.getElementById('sidebarTree').textContent = '页面树加载失败:' + e.message;
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
buildBreadcrumbs(TREE, '');
|
|
1008
|
+
|
|
1009
|
+
const savedVer = navStorage.getItem(VERSION_KEY);
|
|
1010
|
+
if (savedVer) document.getElementById('versionInput').value = savedVer;
|
|
1011
|
+
const versionInput = document.getElementById('versionInput');
|
|
1012
|
+
renderVersionHistory();
|
|
1013
|
+
|
|
1014
|
+
versionInput.addEventListener('keydown', e => {
|
|
1015
|
+
if (e.key !== 'Enter') return;
|
|
1016
|
+
e.preventDefault();
|
|
1017
|
+
submitVersionSearch();
|
|
1018
|
+
});
|
|
1019
|
+
document.getElementById('versionSearchBtn').addEventListener('click', submitVersionSearch);
|
|
1020
|
+
document.getElementById('clearVersionHistoryBtn').addEventListener('click', () => {
|
|
1021
|
+
versionHistory = [];
|
|
1022
|
+
saveVersionHistory();
|
|
1023
|
+
renderVersionHistory();
|
|
1024
|
+
});
|
|
1025
|
+
document.getElementById('navSearchInput').addEventListener('input', applyTitleSearch);
|
|
1026
|
+
|
|
1027
|
+
const treeWrap = document.getElementById('sidebarTree');
|
|
1028
|
+
treeWrap.appendChild(renderNodes(TREE, 0));
|
|
1029
|
+
document.getElementById('totalCount').textContent = totalCount;
|
|
1030
|
+
updateStats();
|
|
1031
|
+
|
|
1032
|
+
// version filter: re-evaluate all badges on input change
|
|
1033
|
+
document.getElementById('versionInput').addEventListener('input', () => {
|
|
1034
|
+
document.querySelectorAll('.file-row').forEach(row => refreshVersionMatch(row));
|
|
1035
|
+
updateStats();
|
|
1036
|
+
// keep filter active if checkbox is checked
|
|
1037
|
+
if (document.getElementById('versionFilterToggle').checked) {
|
|
1038
|
+
applyVersionFilter();
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
|
|
1042
|
+
function applyVersionFilter() {
|
|
1043
|
+
const active = document.getElementById('versionFilterToggle').checked;
|
|
1044
|
+
treeWrap.classList.toggle('filter-by-version', active);
|
|
1045
|
+
}
|
|
1046
|
+
document.getElementById('versionFilterToggle').addEventListener('change', applyVersionFilter);
|
|
1047
|
+
|
|
1048
|
+
// fetch PRD versions in background
|
|
1049
|
+
fetchAllVersions();
|
|
1050
|
+
|
|
1051
|
+
document.getElementById('expandAllBtn').addEventListener('click', () => {
|
|
1052
|
+
treeWrap.querySelectorAll('.folder').forEach(f => f.classList.remove('collapsed'));
|
|
1053
|
+
});
|
|
1054
|
+
document.getElementById('collapseAllBtn').addEventListener('click', () => {
|
|
1055
|
+
treeWrap.querySelectorAll('.folder').forEach(f => f.classList.add('collapsed'));
|
|
1056
|
+
});
|
|
1057
|
+
document.getElementById('copyAddressBtn').addEventListener('click', () => {
|
|
1058
|
+
copyText(window.location.href, '本页地址已复制到剪贴板');
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
});
|
|
1062
|
+
</script>
|
|
1063
|
+
<!-- agent-panel:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
1064
|
+
<aside class="agent-panel" id="agentPanel" aria-label="OpenCode Agent"></aside>
|
|
1065
|
+
<script>window.PROTO_KIT = { productId: 'demo', productTitle: 'Demo' };</script>
|
|
1066
|
+
<script src="/_kit/shell/agent-panel.js"></script>
|
|
1067
|
+
<!-- agent-panel:end -->
|
|
1068
|
+
</body>
|
|
1069
|
+
</html>
|