openprototype 0.2.0 → 1.0.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/README.md +1 -1
- package/package.json +1 -1
- package/product/demo/pc/customer/customer_form.html +3 -0
- package/product/demo/pc/customer/customer_list.html +3 -0
- package/product/demo/pc/index.html +217 -8
- package/proto-kit.config.json +1 -1
- package/runtime/server.js +174 -0
- package/runtime/shared/common/prd-panel.css +401 -0
- package/runtime/shared/common/prd-panel.js +328 -9
- package/scripts/check/sync-nav-tree.js +11 -6
- package/templates/gitignore +2 -0
- package/templates/product-shell/index.html +217 -8
|
@@ -3,12 +3,100 @@
|
|
|
3
3
|
* 管理 PRD 文档的加载、渲染和交互
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
// 页面可在引入本模块前声明这些全局以覆盖默认行为;未声明时使用默认值。
|
|
7
|
+
// PRD_OVERVIEW_VERSION 启用“当前版本”虚拟页签,PRD_WORKSPACE_MAP 配置多文档工作区。
|
|
8
|
+
var PRD_BASE_PATH = typeof PRD_BASE_PATH !== 'undefined' ? PRD_BASE_PATH : './';
|
|
9
|
+
var PRD_FILE_MAP = typeof PRD_FILE_MAP !== 'undefined' ? PRD_FILE_MAP : {};
|
|
10
|
+
var PRD_CACHE = typeof PRD_CACHE !== 'undefined' ? PRD_CACHE : {};
|
|
11
|
+
|
|
6
12
|
var prdPanelInitialized = false;
|
|
7
13
|
var prdPanelWidth = null;
|
|
8
14
|
var PRD_PANEL_DEFAULT_WIDTH = 680;
|
|
9
15
|
var PRD_PANEL_MIN_WIDTH = 360;
|
|
10
16
|
var PRD_PANEL_MAX_RATIO = 0.86;
|
|
11
17
|
|
|
18
|
+
// 记录本文件自身的 <script src>,用于定位同目录的 prd-panel.css 并自动注入
|
|
19
|
+
var PRD_PANEL_SCRIPT_SRC = document.currentScript ? document.currentScript.getAttribute('src') : '';
|
|
20
|
+
|
|
21
|
+
var PRD_PANEL_NO_ANIM_CLASS = 'prd-panel-no-anim';
|
|
22
|
+
|
|
23
|
+
function arePrdPanelStylesReady() {
|
|
24
|
+
var link = document.getElementById('prdPanelStyles');
|
|
25
|
+
return !!(link && link.sheet);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getPrdPanelChromeElements() {
|
|
29
|
+
return ['prdFloatBtn', 'prdPanel'].map(function(id) {
|
|
30
|
+
return document.getElementById(id);
|
|
31
|
+
}).filter(Boolean);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 样式就绪前先禁用过渡:注入 prd-panel.css 的那一帧 transform 由 none 变为 translateX(100%),
|
|
35
|
+
// 过渡若已生效,浏览器会把这次变化当成动画播放,面板就会闪现在右侧再滑走。
|
|
36
|
+
function preparePrdPanelChrome(element) {
|
|
37
|
+
if (!element) return;
|
|
38
|
+
element.classList.add(PRD_PANEL_NO_ANIM_CLASS);
|
|
39
|
+
hidePrdPanelUntilStylesReady(element);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function restorePrdPanelAnimation() {
|
|
43
|
+
var pending = getPrdPanelChromeElements().filter(function(element) {
|
|
44
|
+
return element.classList.contains(PRD_PANEL_NO_ANIM_CLASS);
|
|
45
|
+
});
|
|
46
|
+
if (!pending.length) return;
|
|
47
|
+
|
|
48
|
+
var restore = function() {
|
|
49
|
+
pending.forEach(function(element) {
|
|
50
|
+
// 先读一次布局,确保初始 transform 在过渡恢复前已落定,否则恢复过渡时仍会补出动画
|
|
51
|
+
element.getBoundingClientRect();
|
|
52
|
+
element.classList.remove(PRD_PANEL_NO_ANIM_CLASS);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (window.requestAnimationFrame) {
|
|
57
|
+
window.requestAnimationFrame(restore);
|
|
58
|
+
} else {
|
|
59
|
+
setTimeout(restore, 0);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function revealPrdPanelDom() {
|
|
64
|
+
getPrdPanelChromeElements().forEach(function(element) {
|
|
65
|
+
if (element.dataset.prdPanelPending === 'true') {
|
|
66
|
+
element.style.visibility = '';
|
|
67
|
+
delete element.dataset.prdPanelPending;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
restorePrdPanelAnimation();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function hidePrdPanelUntilStylesReady(element) {
|
|
74
|
+
if (!element || arePrdPanelStylesReady()) return;
|
|
75
|
+
element.dataset.prdPanelPending = 'true';
|
|
76
|
+
element.style.visibility = 'hidden';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function ensurePrdPanelStyles() {
|
|
80
|
+
var link = document.getElementById('prdPanelStyles');
|
|
81
|
+
if (!link) {
|
|
82
|
+
var href = PRD_PANEL_SCRIPT_SRC
|
|
83
|
+
? PRD_PANEL_SCRIPT_SRC.replace(/prd-panel\.js(?:\?.*)?$/, 'prd-panel.css')
|
|
84
|
+
: 'common/prd-panel.css';
|
|
85
|
+
link = document.createElement('link');
|
|
86
|
+
link.id = 'prdPanelStyles';
|
|
87
|
+
link.rel = 'stylesheet';
|
|
88
|
+
link.href = href;
|
|
89
|
+
document.head.appendChild(link);
|
|
90
|
+
}
|
|
91
|
+
// 已存在的 link 也要绑定:样式可能由页面自己引入,此时同样需要在加载完成后揭示面板
|
|
92
|
+
if (link.dataset.prdPanelBound !== 'true') {
|
|
93
|
+
link.dataset.prdPanelBound = 'true';
|
|
94
|
+
link.addEventListener('load', revealPrdPanelDom);
|
|
95
|
+
link.addEventListener('error', revealPrdPanelDom);
|
|
96
|
+
}
|
|
97
|
+
return link;
|
|
98
|
+
}
|
|
99
|
+
|
|
12
100
|
function getPrdPanelMaxWidth() {
|
|
13
101
|
return Math.floor(window.innerWidth * PRD_PANEL_MAX_RATIO);
|
|
14
102
|
}
|
|
@@ -85,22 +173,31 @@ function ensurePrdPanelStructure(prdPanel) {
|
|
|
85
173
|
function ensurePrdPanelDom() {
|
|
86
174
|
if (!document.body) return null;
|
|
87
175
|
|
|
176
|
+
ensurePrdPanelStyles();
|
|
177
|
+
|
|
88
178
|
var prdFloatBtn = document.getElementById('prdFloatBtn');
|
|
89
179
|
if (!prdFloatBtn) {
|
|
90
180
|
prdFloatBtn = document.createElement('div');
|
|
91
181
|
prdFloatBtn.id = 'prdFloatBtn';
|
|
92
182
|
prdFloatBtn.className = 'prd-float-btn';
|
|
93
183
|
prdFloatBtn.textContent = 'PRD';
|
|
184
|
+
preparePrdPanelChrome(prdFloatBtn);
|
|
94
185
|
document.body.appendChild(prdFloatBtn);
|
|
95
186
|
}
|
|
96
187
|
|
|
97
188
|
var prdPanel = document.getElementById('prdPanel');
|
|
98
189
|
if (!prdPanel) {
|
|
99
190
|
prdPanel = document.createElement('div');
|
|
191
|
+
preparePrdPanelChrome(prdPanel);
|
|
100
192
|
document.body.appendChild(prdPanel);
|
|
101
193
|
}
|
|
102
194
|
|
|
103
|
-
|
|
195
|
+
var structuredPanel = ensurePrdPanelStructure(prdPanel);
|
|
196
|
+
// 样式已就绪(多为缓存命中)时 link 的 load 不会再触发,这里直接恢复过渡
|
|
197
|
+
if (arePrdPanelStylesReady()) {
|
|
198
|
+
revealPrdPanelDom();
|
|
199
|
+
}
|
|
200
|
+
return structuredPanel;
|
|
104
201
|
}
|
|
105
202
|
|
|
106
203
|
function initPrdPanel() {
|
|
@@ -198,8 +295,9 @@ function initPrdPanel() {
|
|
|
198
295
|
if (prdEditMode) return;
|
|
199
296
|
|
|
200
297
|
var target = e.target;
|
|
201
|
-
var
|
|
202
|
-
var
|
|
298
|
+
var eventPath = typeof e.composedPath === 'function' ? e.composedPath() : [];
|
|
299
|
+
var isInsidePanel = eventPath.indexOf(prdPanel) !== -1 || target.closest('#prdPanel');
|
|
300
|
+
var isFloatBtn = eventPath.indexOf(prdFloatBtn) !== -1 || target.closest('.prd-float-btn');
|
|
203
301
|
|
|
204
302
|
if (!isInsidePanel && !isFloatBtn) {
|
|
205
303
|
prdPanel.classList.remove('open');
|
|
@@ -231,13 +329,18 @@ var prdCurrentPath = '';
|
|
|
231
329
|
var prdCurrentRawContent = '';
|
|
232
330
|
var prdWorkspaceTabs = [];
|
|
233
331
|
var prdEditMode = false;
|
|
332
|
+
var prdWorkspaceRootPath = '';
|
|
333
|
+
var prdOverviewMarkdown = '';
|
|
334
|
+
var prdOverviewBuildToken = 0;
|
|
335
|
+
var PRD_OVERVIEW_PATH = './__openprototype_current_version__.md';
|
|
234
336
|
|
|
235
337
|
function notifyNavigatorPrdContext() {
|
|
236
338
|
if (window.parent === window) return;
|
|
237
339
|
var targetOrigin = window.location.origin === 'null' ? '*' : window.location.origin;
|
|
238
340
|
var prdPath = '';
|
|
239
|
-
|
|
240
|
-
|
|
341
|
+
var contextPath = isPrdOverviewPath(prdCurrentPath) ? prdWorkspaceRootPath : prdCurrentPath;
|
|
342
|
+
if (contextPath) {
|
|
343
|
+
prdPath = decodeURIComponent(new URL(contextPath, window.location.href).pathname);
|
|
241
344
|
}
|
|
242
345
|
window.parent.postMessage({
|
|
243
346
|
type: 'pak-prd-context',
|
|
@@ -321,6 +424,188 @@ function getPrdDisplayName(filePath) {
|
|
|
321
424
|
return (filePath || '').split('/').pop().replace(/\.md(?:#.*)?$/i, '').replace(/_/g, ' ');
|
|
322
425
|
}
|
|
323
426
|
|
|
427
|
+
function getPrdOverviewVersion() {
|
|
428
|
+
if (typeof PRD_OVERVIEW_VERSION === 'undefined') return '';
|
|
429
|
+
return String(PRD_OVERVIEW_VERSION || '').trim();
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function isPrdOverviewPath(filePath) {
|
|
433
|
+
return normalizePrdPath(filePath) === normalizePrdPath(PRD_OVERVIEW_PATH);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function escapePrdRegExp(text) {
|
|
437
|
+
return String(text || '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function containsPrdVersion(text, version) {
|
|
441
|
+
var normalizedVersion = String(version || '').replace(/^v/i, '');
|
|
442
|
+
if (!normalizedVersion) return false;
|
|
443
|
+
var pattern = '(^|[^0-9.])v?' + escapePrdRegExp(normalizedVersion) + '(?=$|[^0-9.])';
|
|
444
|
+
return new RegExp(pattern, 'i').test(String(text || ''));
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function getPrdHeadingBefore(lines, index) {
|
|
448
|
+
for (var lineIndex = index - 1; lineIndex >= 0; lineIndex -= 1) {
|
|
449
|
+
var match = String(lines[lineIndex] || '').match(/^#{1,6}\s+(.+)$/);
|
|
450
|
+
if (match) return match[1].replace(/<[^>]+>/g, '').trim();
|
|
451
|
+
}
|
|
452
|
+
return '';
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function isPrdTableDivider(line) {
|
|
456
|
+
return /^\s*\|(?:\s*:?-{3,}:?\s*\|)+\s*$/.test(String(line || ''));
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function collectPrdVersionSections(content, version) {
|
|
460
|
+
var lines = String(content || '').split(/\r?\n/);
|
|
461
|
+
var sections = [];
|
|
462
|
+
|
|
463
|
+
for (var index = 0; index < lines.length; index += 1) {
|
|
464
|
+
var line = lines[index];
|
|
465
|
+
if (/^\s*\|.*\|\s*$/.test(line)) {
|
|
466
|
+
var tableStart = index;
|
|
467
|
+
var tableLines = [];
|
|
468
|
+
while (index < lines.length && /^\s*\|.*\|\s*$/.test(lines[index])) {
|
|
469
|
+
tableLines.push(lines[index]);
|
|
470
|
+
index += 1;
|
|
471
|
+
}
|
|
472
|
+
index -= 1;
|
|
473
|
+
|
|
474
|
+
if (tableLines.length >= 3 && isPrdTableDivider(tableLines[1])) {
|
|
475
|
+
var matchedRows = tableLines.slice(2).filter(function(row) {
|
|
476
|
+
return containsPrdVersion(row, version);
|
|
477
|
+
});
|
|
478
|
+
if (matchedRows.length) {
|
|
479
|
+
sections.push({
|
|
480
|
+
heading: getPrdHeadingBefore(lines, tableStart),
|
|
481
|
+
markdown: [tableLines[0], tableLines[1]].concat(matchedRows).join('\n')
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
var headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
|
|
489
|
+
if (headingMatch && containsPrdVersion(line, version)) {
|
|
490
|
+
var headingLevel = headingMatch[1].length;
|
|
491
|
+
var sectionLines = [line];
|
|
492
|
+
var nextIndex = index + 1;
|
|
493
|
+
while (nextIndex < lines.length) {
|
|
494
|
+
var nextHeading = lines[nextIndex].match(/^(#{1,6})\s+/);
|
|
495
|
+
if (nextHeading && nextHeading[1].length <= headingLevel) break;
|
|
496
|
+
sectionLines.push(lines[nextIndex]);
|
|
497
|
+
nextIndex += 1;
|
|
498
|
+
}
|
|
499
|
+
sections.push({ heading: '', markdown: sectionLines.join('\n').trim() });
|
|
500
|
+
index = nextIndex - 1;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (containsPrdVersion(line, version)) {
|
|
505
|
+
sections.push({
|
|
506
|
+
heading: getPrdHeadingBefore(lines, index),
|
|
507
|
+
markdown: line
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return sections;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function buildPrdOverviewMarkdown(tabs, contents, version) {
|
|
516
|
+
var documentSections = [];
|
|
517
|
+
|
|
518
|
+
tabs.forEach(function(tab, index) {
|
|
519
|
+
var sections = collectPrdVersionSections(contents[index], version);
|
|
520
|
+
if (sections.length) documentSections.push({ tab: tab, sections: sections });
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
if (!documentSections.length) return '';
|
|
524
|
+
|
|
525
|
+
var markdown = [
|
|
526
|
+
'# ' + version + ' 更新总览',
|
|
527
|
+
'',
|
|
528
|
+
'> 自动汇总当前页面工作区内各 PRD 中标注为 ' + version + ' 的修订说明与详细规则。',
|
|
529
|
+
''
|
|
530
|
+
];
|
|
531
|
+
|
|
532
|
+
documentSections.forEach(function(documentItem) {
|
|
533
|
+
var tab = documentItem.tab;
|
|
534
|
+
var documentTitle = tab.title === '主文档' ? getPrdDisplayName(tab.path) : tab.title;
|
|
535
|
+
markdown.push('## ' + documentTitle, '', '来源:`' + tab.path.split('/').pop() + '`', '');
|
|
536
|
+
|
|
537
|
+
documentItem.sections.forEach(function(section) {
|
|
538
|
+
if (section.heading) markdown.push('### ' + section.heading, '');
|
|
539
|
+
markdown.push(section.markdown, '');
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
return markdown.join('\n').trim();
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function renderPrdOverview() {
|
|
547
|
+
var version = getPrdOverviewVersion();
|
|
548
|
+
var contentEl = document.getElementById('prdPanelContent');
|
|
549
|
+
var titleEl = document.getElementById('prdPanelTitle');
|
|
550
|
+
var fileNameEl = document.getElementById('prdPanelFileName');
|
|
551
|
+
var editBtn = document.getElementById('prdPanelEditBtn');
|
|
552
|
+
if (!contentEl || !prdOverviewMarkdown) return;
|
|
553
|
+
|
|
554
|
+
prdCurrentFileName = version + ' 当前版本';
|
|
555
|
+
prdCurrentPath = PRD_OVERVIEW_PATH;
|
|
556
|
+
prdCurrentRawContent = prdOverviewMarkdown;
|
|
557
|
+
if (titleEl) titleEl.textContent = version + ' 更新总览 - PRD';
|
|
558
|
+
if (fileNameEl) fileNameEl.textContent = '';
|
|
559
|
+
if (editBtn) editBtn.style.display = 'none';
|
|
560
|
+
|
|
561
|
+
contentEl.innerHTML = renderMarkdownToHtml(prdOverviewMarkdown);
|
|
562
|
+
wrapPrdTables(contentEl);
|
|
563
|
+
renderPrdTabs(PRD_OVERVIEW_PATH);
|
|
564
|
+
bindPrdTabs();
|
|
565
|
+
notifyNavigatorPrdContext();
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function preparePrdOverview(rootPath, options) {
|
|
569
|
+
options = options || {};
|
|
570
|
+
var version = getPrdOverviewVersion();
|
|
571
|
+
var realTabs = prdWorkspaceTabs.filter(function(tab) {
|
|
572
|
+
return !isPrdOverviewPath(tab.path);
|
|
573
|
+
});
|
|
574
|
+
var contentOverrides = options.contentOverrides || {};
|
|
575
|
+
var buildToken = ++prdOverviewBuildToken;
|
|
576
|
+
var normalizedRootPath = normalizePrdPath(rootPath);
|
|
577
|
+
|
|
578
|
+
if (!version || !realTabs.length) {
|
|
579
|
+
prdOverviewMarkdown = '';
|
|
580
|
+
prdWorkspaceTabs = realTabs;
|
|
581
|
+
return Promise.resolve('');
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
return Promise.all(realTabs.map(function(tab) {
|
|
585
|
+
var normalizedPath = normalizePrdPath(tab.path);
|
|
586
|
+
if (Object.prototype.hasOwnProperty.call(contentOverrides, normalizedPath)) {
|
|
587
|
+
return Promise.resolve(contentOverrides[normalizedPath]);
|
|
588
|
+
}
|
|
589
|
+
return loadMarkdownFile(tab.path);
|
|
590
|
+
})).then(function(contents) {
|
|
591
|
+
if (buildToken !== prdOverviewBuildToken) return '';
|
|
592
|
+
|
|
593
|
+
prdOverviewMarkdown = buildPrdOverviewMarkdown(realTabs, contents, version);
|
|
594
|
+
prdWorkspaceTabs = prdOverviewMarkdown ? [{
|
|
595
|
+
title: '当前版本',
|
|
596
|
+
path: PRD_OVERVIEW_PATH
|
|
597
|
+
}].concat(realTabs) : realTabs;
|
|
598
|
+
|
|
599
|
+
if (prdOverviewMarkdown && options.activateWhenReady && normalizePrdPath(prdCurrentPath) === normalizedRootPath) {
|
|
600
|
+
renderPrdOverview();
|
|
601
|
+
} else {
|
|
602
|
+
renderPrdTabs(prdCurrentPath);
|
|
603
|
+
bindPrdTabs();
|
|
604
|
+
}
|
|
605
|
+
return prdOverviewMarkdown;
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
324
609
|
function normalizePrdPath(filePath) {
|
|
325
610
|
var path = decodeURIComponent(String(filePath || '')).split('#')[0].split('?')[0];
|
|
326
611
|
var hasDotPrefix = path.indexOf('./') === 0;
|
|
@@ -476,12 +761,22 @@ function renderLoadedPrd(result, options) {
|
|
|
476
761
|
var currentPath = normalizePrdPath(result.path || result.fileName);
|
|
477
762
|
setPrdHeader(currentPath, options && options.title);
|
|
478
763
|
prdCurrentRawContent = result.content;
|
|
764
|
+
var editBtn = document.getElementById('prdPanelEditBtn');
|
|
765
|
+
if (editBtn && !prdEditMode) editBtn.style.display = '';
|
|
479
766
|
prdContentEl.innerHTML = renderMarkdownToHtml(result.content);
|
|
480
767
|
wrapPrdTables(prdContentEl);
|
|
481
768
|
|
|
482
769
|
if (options && options.resetWorkspace) {
|
|
483
770
|
var configuredTabs = buildWorkspaceTabsFromConfig(options.workspaceConfig, currentPath);
|
|
484
771
|
prdWorkspaceTabs = configuredTabs.length ? configuredTabs : buildWorkspaceTabsFromContent(prdContentEl, currentPath);
|
|
772
|
+
prdWorkspaceRootPath = currentPath;
|
|
773
|
+
prdOverviewMarkdown = '';
|
|
774
|
+
var contentOverrides = {};
|
|
775
|
+
contentOverrides[currentPath] = result.content;
|
|
776
|
+
preparePrdOverview(currentPath, {
|
|
777
|
+
activateWhenReady: true,
|
|
778
|
+
contentOverrides: contentOverrides
|
|
779
|
+
});
|
|
485
780
|
} else if (options && options.title) {
|
|
486
781
|
var targetPath = normalizePrdPath(currentPath);
|
|
487
782
|
var exists = prdWorkspaceTabs.some(function(tab) {
|
|
@@ -506,6 +801,11 @@ function openPrdPath(filePath, options) {
|
|
|
506
801
|
var normalizedPath = normalizePrdPath(filePath);
|
|
507
802
|
if (!prdContentEl || !normalizedPath) return Promise.resolve(null);
|
|
508
803
|
|
|
804
|
+
if (isPrdOverviewPath(normalizedPath)) {
|
|
805
|
+
renderPrdOverview();
|
|
806
|
+
return Promise.resolve({ path: PRD_OVERVIEW_PATH, content: prdOverviewMarkdown });
|
|
807
|
+
}
|
|
808
|
+
|
|
509
809
|
prdContentEl.innerHTML = '<div style="padding:20px;text-align:center;color:var(--text-secondary);">加载中...</div>';
|
|
510
810
|
|
|
511
811
|
return loadMarkdownFile(normalizedPath).then(function(content) {
|
|
@@ -539,6 +839,9 @@ function updatePrdContent() {
|
|
|
539
839
|
var prdFileCandidates = getPrdFileCandidates(currentPage, mode);
|
|
540
840
|
var prdFileName = prdFileCandidates[0];
|
|
541
841
|
var workspaceConfig = getPrdWorkspaceConfig(currentPage);
|
|
842
|
+
prdOverviewBuildToken += 1;
|
|
843
|
+
prdWorkspaceRootPath = '';
|
|
844
|
+
prdOverviewMarkdown = '';
|
|
542
845
|
|
|
543
846
|
if (!prdFileName) {
|
|
544
847
|
prdContentEl.innerHTML = '<div class="error" style="padding:20px;color:var(--text-secondary);">当前页面暂无对应的PRD文档</div>';
|
|
@@ -602,6 +905,10 @@ function showPrdEditorMsg(text, isError) {
|
|
|
602
905
|
}
|
|
603
906
|
|
|
604
907
|
function enterPrdEditMode() {
|
|
908
|
+
if (isPrdOverviewPath(prdCurrentPath)) {
|
|
909
|
+
showPrdToast('“当前版本”由关联 PRD 自动汇总,请在原文页签中编辑', true);
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
605
912
|
if (isLocalFileProtocol()) {
|
|
606
913
|
showPrdToast('请通过本地服务器(npm run serve)打开原型后再编辑', true);
|
|
607
914
|
return;
|
|
@@ -659,7 +966,7 @@ function applyPrdRedColor() {
|
|
|
659
966
|
|
|
660
967
|
function wrapPrdSelectionWithRed(text) {
|
|
661
968
|
if (!isPrdMarkdownTableSelection(text)) {
|
|
662
|
-
return '<span style="color
|
|
969
|
+
return '<span style="color:red">' + text + '</span>';
|
|
663
970
|
}
|
|
664
971
|
|
|
665
972
|
return text.split('\n').map(function(line) {
|
|
@@ -697,7 +1004,7 @@ function wrapPrdMarkdownTableRowCells(line) {
|
|
|
697
1004
|
if (!content || /<span\b[^>]*\bstyle\s*=\s*["'][^"']*\bcolor\s*:\s*(?:#e53935|red)\b[^"']*["'][^>]*>[\s\S]*<\/span>/i.test(content)) {
|
|
698
1005
|
return cell;
|
|
699
1006
|
}
|
|
700
|
-
return left + '<span style="color
|
|
1007
|
+
return left + '<span style="color:red">' + content + '</span>' + right;
|
|
701
1008
|
}).join('|') + '|' + trailing;
|
|
702
1009
|
}
|
|
703
1010
|
|
|
@@ -811,8 +1118,15 @@ function savePrdEdits() {
|
|
|
811
1118
|
wrapPrdTables(contentEl);
|
|
812
1119
|
bindPrdContentLinks(contentEl);
|
|
813
1120
|
exitPrdEditMode();
|
|
814
|
-
|
|
815
|
-
|
|
1121
|
+
var contentOverrides = {};
|
|
1122
|
+
contentOverrides[normalizePrdPath(prdCurrentPath)] = newContent;
|
|
1123
|
+
return preparePrdOverview(prdWorkspaceRootPath || prdCurrentPath, {
|
|
1124
|
+
activateWhenReady: false,
|
|
1125
|
+
contentOverrides: contentOverrides
|
|
1126
|
+
}).then(function() {
|
|
1127
|
+
showPrdToast('已保存', false);
|
|
1128
|
+
return true;
|
|
1129
|
+
});
|
|
816
1130
|
}).catch(function(err) {
|
|
817
1131
|
showPrdEditorMsg('保存失败:' + err.message, true);
|
|
818
1132
|
throw err;
|
|
@@ -999,6 +1313,11 @@ function renderMarkdownToHtml(markdown) {
|
|
|
999
1313
|
return html;
|
|
1000
1314
|
}
|
|
1001
1315
|
|
|
1316
|
+
// 解析到本脚本就开始下载样式,而不是等到 DOMContentLoaded,尽量让样式先于面板建好
|
|
1317
|
+
if (document.head) {
|
|
1318
|
+
ensurePrdPanelStyles();
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1002
1321
|
if (document.readyState === 'loading') {
|
|
1003
1322
|
document.addEventListener('DOMContentLoaded', function() {
|
|
1004
1323
|
if (!prdPanelInitialized) {
|
|
@@ -31,19 +31,22 @@ function collectRegisteredPaths(nodes, out) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function listDiskPaths(dir) {
|
|
34
|
-
const
|
|
34
|
+
const files = [];
|
|
35
|
+
const dirs = [];
|
|
35
36
|
const walk = (p) => {
|
|
36
37
|
for (const name of fs.readdirSync(p)) {
|
|
38
|
+
if (name.startsWith('.')) continue; // 隐藏目录 / 文件不进导航树
|
|
37
39
|
const full = path.join(p, name);
|
|
38
40
|
if (fs.statSync(full).isDirectory()) {
|
|
41
|
+
dirs.push(path.relative(dir, full).split(path.sep).join('/'));
|
|
39
42
|
walk(full);
|
|
40
43
|
} else if (name.endsWith('.html') && full !== path.join(dir, 'index.html')) {
|
|
41
|
-
|
|
44
|
+
files.push(path.relative(dir, full).split(path.sep).join('/'));
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
};
|
|
45
48
|
walk(dir);
|
|
46
|
-
return
|
|
49
|
+
return { files: files.sort((a, b) => a.localeCompare(b, 'zh-Hans-CN')), dirs };
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
function ensureFolderChildren(tree, folderNames) {
|
|
@@ -72,8 +75,10 @@ function sortTree(nodes) {
|
|
|
72
75
|
return nodes;
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
function buildTree(paths) {
|
|
78
|
+
function buildTree(paths, dirs) {
|
|
76
79
|
const tree = [];
|
|
80
|
+
// 先登记磁盘上的所有目录(含空目录,保住导航页刚创建、还没放页面的文件夹)
|
|
81
|
+
for (const relDir of dirs || []) ensureFolderChildren(tree, relDir.split('/'));
|
|
77
82
|
for (const relPath of paths) {
|
|
78
83
|
const segments = relPath.split('/');
|
|
79
84
|
const fileName = segments.pop();
|
|
@@ -88,9 +93,9 @@ function syncTarget(target) {
|
|
|
88
93
|
? JSON.parse(fs.readFileSync(target.treePath, 'utf8'))
|
|
89
94
|
: [];
|
|
90
95
|
const previous = collectRegisteredPaths(previousTree, new Set());
|
|
91
|
-
const diskPaths = listDiskPaths(target.dir);
|
|
96
|
+
const { files: diskPaths, dirs } = listDiskPaths(target.dir);
|
|
92
97
|
const onDisk = new Set(diskPaths);
|
|
93
|
-
const tree = buildTree(diskPaths);
|
|
98
|
+
const tree = buildTree(diskPaths, dirs);
|
|
94
99
|
const next = collectRegisteredPaths(tree, new Set());
|
|
95
100
|
const added = [...next].filter((p) => !previous.has(p));
|
|
96
101
|
const removed = [...previous].filter((p) => !onDisk.has(p));
|