openprototype 1.8.3 → 1.8.4
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/package.json
CHANGED
|
@@ -4,11 +4,21 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// 页面可在引入本模块前声明这些全局以覆盖默认行为;未声明时使用默认值。
|
|
7
|
+
// 在直接引入 prd-panel.js 的旧页面中,同步补齐并行版本工具,保持向后兼容。
|
|
8
|
+
if (typeof window !== 'undefined' && !window.OpenPrototypePrdVersions && document.currentScript) {
|
|
9
|
+
var prdPanelScriptSource = document.currentScript.getAttribute('src') || '';
|
|
10
|
+
var prdVersionUtilsSource = prdPanelScriptSource.replace(/prd-panel\.js(?:\?.*)?$/, 'prd-version-utils.js');
|
|
11
|
+
if (prdVersionUtilsSource) document.write('<script src="' + prdVersionUtilsSource + '"><\/script>');
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
// “当前版本”优先读取主 PRD 版本记录表的最后一条;PRD_OVERVIEW_VERSION 仅作兼容兜底。
|
|
8
15
|
// PRD_WORKSPACE_MAP 配置多文档工作区。
|
|
9
16
|
var PRD_BASE_PATH = typeof PRD_BASE_PATH !== 'undefined' ? PRD_BASE_PATH : './';
|
|
10
17
|
var PRD_FILE_MAP = typeof PRD_FILE_MAP !== 'undefined' ? PRD_FILE_MAP : {};
|
|
11
18
|
var PRD_CACHE = typeof PRD_CACHE !== 'undefined' ? PRD_CACHE : {};
|
|
19
|
+
var PRD_DEVELOPMENT_VERSION_COLORS = typeof PRD_DEVELOPMENT_VERSION_COLORS !== 'undefined'
|
|
20
|
+
? PRD_DEVELOPMENT_VERSION_COLORS
|
|
21
|
+
: {};
|
|
12
22
|
|
|
13
23
|
var prdPanelInitialized = false;
|
|
14
24
|
var prdPanelWidth = null;
|
|
@@ -341,6 +351,7 @@ var prdEditMode = false;
|
|
|
341
351
|
var prdWorkspaceRootPath = '';
|
|
342
352
|
var prdOverviewMarkdown = '';
|
|
343
353
|
var prdOverviewVersion = '';
|
|
354
|
+
var prdOverviewVersions = [];
|
|
344
355
|
var prdOverviewBuildToken = 0;
|
|
345
356
|
var PRD_OVERVIEW_PATH = './__openprototype_current_version__.md';
|
|
346
357
|
|
|
@@ -480,6 +491,9 @@ function escapePrdRegExp(text) {
|
|
|
480
491
|
function containsPrdVersion(text, version) {
|
|
481
492
|
var normalizedVersion = String(version || '').replace(/^v/i, '');
|
|
482
493
|
if (!normalizedVersion) return false;
|
|
494
|
+
if (window.OpenPrototypePrdVersions) {
|
|
495
|
+
return window.OpenPrototypePrdVersions.contains(text, version);
|
|
496
|
+
}
|
|
483
497
|
var pattern = '(^|[^0-9.])v?' + escapePrdRegExp(normalizedVersion) + '(?=$|[^0-9.])';
|
|
484
498
|
return new RegExp(pattern, 'i').test(String(text || ''));
|
|
485
499
|
}
|
|
@@ -552,53 +566,67 @@ function collectPrdVersionSections(content, version) {
|
|
|
552
566
|
return sections;
|
|
553
567
|
}
|
|
554
568
|
|
|
555
|
-
function buildPrdOverviewMarkdown(tabs, contents,
|
|
556
|
-
var documentSections = [];
|
|
557
|
-
|
|
558
|
-
tabs.forEach(function(tab, index) {
|
|
559
|
-
var sections = collectPrdVersionSections(contents[index], version);
|
|
560
|
-
if (sections.length) documentSections.push({ tab: tab, sections: sections });
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
if (!documentSections.length) return '';
|
|
564
|
-
|
|
569
|
+
function buildPrdOverviewMarkdown(tabs, contents, versions) {
|
|
565
570
|
var markdown = [
|
|
566
|
-
'# '
|
|
571
|
+
'# 当前开发版本更新总览',
|
|
567
572
|
'',
|
|
568
|
-
'>
|
|
573
|
+
'> 自动汇总当前页面工作区内所有带颜色标记的开发版本;版本颜色与各 PRD 的详细变更保持一致。',
|
|
569
574
|
''
|
|
570
575
|
];
|
|
576
|
+
var hasContent = false;
|
|
577
|
+
var colorConflicts = versions.filter(function(item) { return item.hasColorConflict; });
|
|
578
|
+
if (colorConflicts.length) {
|
|
579
|
+
markdown.push('> ⚠️ ' + colorConflicts.map(function(item) {
|
|
580
|
+
return item.version + ' 在多个 PRD 中存在颜色冲突,已按项目配置显示。';
|
|
581
|
+
}).join(' '), '');
|
|
582
|
+
}
|
|
571
583
|
|
|
572
|
-
|
|
573
|
-
var
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
584
|
+
versions.forEach(function(versionItem) {
|
|
585
|
+
var documentSections = [];
|
|
586
|
+
tabs.forEach(function(tab, index) {
|
|
587
|
+
var sections = collectPrdVersionSections(contents[index], versionItem.version);
|
|
588
|
+
if (sections.length) documentSections.push({ tab: tab, sections: sections });
|
|
589
|
+
});
|
|
590
|
+
if (!documentSections.length) return;
|
|
591
|
+
|
|
592
|
+
hasContent = true;
|
|
593
|
+
markdown.push('## <span style="color:' + versionItem.color + '">' + versionItem.version + '</span>', '');
|
|
594
|
+
documentSections.forEach(function(documentItem) {
|
|
595
|
+
var documentTitle = documentItem.tab.title === '主文档'
|
|
596
|
+
? getPrdDisplayName(documentItem.tab.path)
|
|
597
|
+
: documentItem.tab.title;
|
|
598
|
+
markdown.push('### ' + documentTitle, '', '来源:`' + documentItem.tab.path.split('/').pop() + '`', '');
|
|
599
|
+
documentItem.sections.forEach(function(section) {
|
|
600
|
+
if (section.heading) markdown.push('#### ' + section.heading, '');
|
|
601
|
+
markdown.push(section.markdown, '');
|
|
602
|
+
});
|
|
580
603
|
});
|
|
581
604
|
});
|
|
582
605
|
|
|
583
|
-
return markdown.join('\n').trim();
|
|
606
|
+
return hasContent ? markdown.join('\n').trim() : '';
|
|
584
607
|
}
|
|
585
608
|
|
|
586
609
|
function renderPrdOverview() {
|
|
587
|
-
var version = prdOverviewVersion;
|
|
588
610
|
var contentEl = document.getElementById('prdPanelContent');
|
|
589
611
|
var titleEl = document.getElementById('prdPanelTitle');
|
|
590
612
|
var fileNameEl = document.getElementById('prdPanelFileName');
|
|
591
613
|
var editBtn = document.getElementById('prdPanelEditBtn');
|
|
592
614
|
if (!contentEl || !prdOverviewMarkdown) return;
|
|
593
615
|
|
|
594
|
-
|
|
616
|
+
var versionNames = prdOverviewVersions.map(function(item) { return item.version; });
|
|
617
|
+
prdCurrentFileName = versionNames.join(' / ') + ' 当前版本';
|
|
595
618
|
prdCurrentPath = PRD_OVERVIEW_PATH;
|
|
596
619
|
prdCurrentRawContent = prdOverviewMarkdown;
|
|
597
|
-
if (titleEl) titleEl.textContent =
|
|
620
|
+
if (titleEl) titleEl.textContent = versionNames.join(' / ') + ' 更新总览 - PRD';
|
|
598
621
|
if (fileNameEl) fileNameEl.textContent = '';
|
|
599
622
|
if (editBtn) editBtn.style.display = 'none';
|
|
600
623
|
|
|
601
|
-
|
|
624
|
+
var renderedMarkdown = window.OpenPrototypePrdVersions
|
|
625
|
+
? window.OpenPrototypePrdVersions.synchronizeHistoryColors(prdOverviewMarkdown, {
|
|
626
|
+
versionColors: PRD_DEVELOPMENT_VERSION_COLORS
|
|
627
|
+
})
|
|
628
|
+
: prdOverviewMarkdown;
|
|
629
|
+
contentEl.innerHTML = renderMarkdownToHtml(renderedMarkdown);
|
|
602
630
|
wrapPrdTables(contentEl);
|
|
603
631
|
renderPrdTabs(PRD_OVERVIEW_PATH);
|
|
604
632
|
bindPrdTabs();
|
|
@@ -613,14 +641,10 @@ function preparePrdOverview(rootPath, options) {
|
|
|
613
641
|
var contentOverrides = options.contentOverrides || {};
|
|
614
642
|
var buildToken = ++prdOverviewBuildToken;
|
|
615
643
|
var normalizedRootPath = normalizePrdPath(rootPath);
|
|
616
|
-
var rootContent = Object.prototype.hasOwnProperty.call(contentOverrides, normalizedRootPath)
|
|
617
|
-
? contentOverrides[normalizedRootPath]
|
|
618
|
-
: '';
|
|
619
|
-
var version = getPrdOverviewVersion(rootContent);
|
|
620
|
-
prdOverviewVersion = version;
|
|
621
644
|
|
|
622
|
-
if (!
|
|
645
|
+
if (!realTabs.length) {
|
|
623
646
|
prdOverviewMarkdown = '';
|
|
647
|
+
prdOverviewVersions = [];
|
|
624
648
|
prdWorkspaceTabs = realTabs;
|
|
625
649
|
return Promise.resolve('');
|
|
626
650
|
}
|
|
@@ -634,7 +658,23 @@ function preparePrdOverview(rootPath, options) {
|
|
|
634
658
|
})).then(function(contents) {
|
|
635
659
|
if (buildToken !== prdOverviewBuildToken) return '';
|
|
636
660
|
|
|
637
|
-
|
|
661
|
+
prdOverviewVersions = window.OpenPrototypePrdVersions
|
|
662
|
+
? window.OpenPrototypePrdVersions.collectWorkspace(contents, {
|
|
663
|
+
versionColors: PRD_DEVELOPMENT_VERSION_COLORS
|
|
664
|
+
})
|
|
665
|
+
: [];
|
|
666
|
+
if (!prdOverviewVersions.length) {
|
|
667
|
+
var rootContentIndex = realTabs.findIndex(function(tab) {
|
|
668
|
+
return normalizePrdPath(tab.path) === normalizedRootPath;
|
|
669
|
+
});
|
|
670
|
+
var rootContent = rootContentIndex >= 0 ? contents[rootContentIndex] : '';
|
|
671
|
+
var fallbackVersion = getPrdHistoryLatestVersion(rootContent)
|
|
672
|
+
|| (typeof PRD_OVERVIEW_VERSION === 'undefined' ? '' : String(PRD_OVERVIEW_VERSION || '').trim());
|
|
673
|
+
if (fallbackVersion) prdOverviewVersions = [{ version: fallbackVersion, color: 'inherit' }];
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
prdOverviewVersion = prdOverviewVersions.length ? prdOverviewVersions[0].version : '';
|
|
677
|
+
prdOverviewMarkdown = buildPrdOverviewMarkdown(realTabs, contents, prdOverviewVersions);
|
|
638
678
|
prdWorkspaceTabs = prdOverviewMarkdown ? [{
|
|
639
679
|
title: '当前版本',
|
|
640
680
|
path: PRD_OVERVIEW_PATH
|
|
@@ -807,7 +847,12 @@ function renderLoadedPrd(result, options) {
|
|
|
807
847
|
prdCurrentRawContent = result.content;
|
|
808
848
|
var editBtn = document.getElementById('prdPanelEditBtn');
|
|
809
849
|
if (editBtn && !prdEditMode) editBtn.style.display = '';
|
|
810
|
-
|
|
850
|
+
var renderedContent = window.OpenPrototypePrdVersions
|
|
851
|
+
? window.OpenPrototypePrdVersions.synchronizeHistoryColors(result.content, {
|
|
852
|
+
versionColors: PRD_DEVELOPMENT_VERSION_COLORS
|
|
853
|
+
})
|
|
854
|
+
: result.content;
|
|
855
|
+
prdContentEl.innerHTML = renderMarkdownToHtml(renderedContent);
|
|
811
856
|
wrapPrdTables(prdContentEl);
|
|
812
857
|
|
|
813
858
|
if (options && options.resetWorkspace) {
|
|
@@ -887,6 +932,7 @@ function updatePrdContent() {
|
|
|
887
932
|
prdWorkspaceRootPath = '';
|
|
888
933
|
prdOverviewMarkdown = '';
|
|
889
934
|
prdOverviewVersion = '';
|
|
935
|
+
prdOverviewVersions = [];
|
|
890
936
|
|
|
891
937
|
if (!prdFileName) {
|
|
892
938
|
prdContentEl.innerHTML = '<div class="error" style="padding:20px;color:var(--text-secondary);">当前页面暂无对应的PRD文档</div>';
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* PRD 并行开发版本工具。
|
|
3
|
+
*
|
|
4
|
+
* 解析详细变更中的颜色与版本号,供 PRD 面板和产品导航共用。版本信息表本身
|
|
5
|
+
* 不参与版本发现,避免由渲染后的表格颜色反向污染当前开发版本。
|
|
6
|
+
*/
|
|
7
|
+
(function (root) {
|
|
8
|
+
function stripHtml(text) {
|
|
9
|
+
return String(text || '').replace(/<[^>]+>/g, '');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function normalizeVersion(version) {
|
|
13
|
+
return stripHtml(version).trim().replace(/^v/i, '').toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function extractVersion(text) {
|
|
17
|
+
var match = stripHtml(text).match(/\b[vV]?\d+(?:\.\d+)+\b/);
|
|
18
|
+
return match ? 'V' + match[0].replace(/^v/i, '') : '';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function compareVersions(left, right) {
|
|
22
|
+
var leftParts = normalizeVersion(left).split('.').map(function (part) { return Number(part) || 0; });
|
|
23
|
+
var rightParts = normalizeVersion(right).split('.').map(function (part) { return Number(part) || 0; });
|
|
24
|
+
var length = Math.max(leftParts.length, rightParts.length);
|
|
25
|
+
for (var index = 0; index < length; index += 1) {
|
|
26
|
+
var difference = (leftParts[index] || 0) - (rightParts[index] || 0);
|
|
27
|
+
if (difference) return difference;
|
|
28
|
+
}
|
|
29
|
+
return String(left).localeCompare(String(right), undefined, { numeric: true, sensitivity: 'base' });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isTableDivider(line) {
|
|
33
|
+
return /^\s*\|(?:\s*:?-{3,}:?\s*\|)+\s*$/.test(String(line || ''));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isVersionHistoryTable(tableLines) {
|
|
37
|
+
if (!tableLines || tableLines.length < 2 || !isTableDivider(tableLines[1])) return false;
|
|
38
|
+
var firstHeader = (tableLines[0].split('|')[1] || '').replace(/<[^>]+>/g, '').trim();
|
|
39
|
+
return firstHeader.indexOf('版本') !== -1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function removeVersionHistoryTables(markdown) {
|
|
43
|
+
var lines = String(markdown || '').split(/\r?\n/);
|
|
44
|
+
var retained = [];
|
|
45
|
+
for (var index = 0; index < lines.length; index += 1) {
|
|
46
|
+
if (!/^\s*\|.*\|\s*$/.test(lines[index])) {
|
|
47
|
+
retained.push(lines[index]);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
var tableLines = [];
|
|
51
|
+
while (index < lines.length && /^\s*\|.*\|\s*$/.test(lines[index])) {
|
|
52
|
+
tableLines.push(lines[index]);
|
|
53
|
+
index += 1;
|
|
54
|
+
}
|
|
55
|
+
index -= 1;
|
|
56
|
+
if (!isVersionHistoryTable(tableLines)) retained = retained.concat(tableLines);
|
|
57
|
+
}
|
|
58
|
+
return retained.join('\n');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function collectColoredVersions(markdown) {
|
|
62
|
+
var content = removeVersionHistoryTables(markdown);
|
|
63
|
+
var pattern = /<span\b[^>]*style\s*=\s*["'][^"']*color\s*:\s*([^;"']+)[^"']*["'][^>]*>([\s\S]*?)<\/span>/gi;
|
|
64
|
+
var versions = [];
|
|
65
|
+
var positions = {};
|
|
66
|
+
var match;
|
|
67
|
+
while ((match = pattern.exec(content))) {
|
|
68
|
+
var version = extractVersion(match[2]);
|
|
69
|
+
var color = String(match[1] || '').trim();
|
|
70
|
+
var key = normalizeVersion(version);
|
|
71
|
+
if (!key || !/^[#(),.%\w\s-]+$/.test(color)) continue;
|
|
72
|
+
if (!Object.prototype.hasOwnProperty.call(positions, key)) {
|
|
73
|
+
positions[key] = versions.length;
|
|
74
|
+
versions.push({ version: version, color: color });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return versions;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getConfiguredColor(version, versionColors) {
|
|
81
|
+
var key = normalizeVersion(version);
|
|
82
|
+
var configured = versionColors || {};
|
|
83
|
+
var matchedKey = Object.keys(configured).find(function (candidate) {
|
|
84
|
+
return normalizeVersion(candidate) === key;
|
|
85
|
+
});
|
|
86
|
+
return matchedKey ? String(configured[matchedKey] || '').trim() : '';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function collectWorkspaceVersions(contents, options) {
|
|
90
|
+
var optionsValue = options || {};
|
|
91
|
+
var records = {};
|
|
92
|
+
(contents || []).forEach(function (content) {
|
|
93
|
+
collectColoredVersions(content).forEach(function (item) {
|
|
94
|
+
var key = normalizeVersion(item.version);
|
|
95
|
+
if (!records[key]) records[key] = { version: item.version, colors: [] };
|
|
96
|
+
if (records[key].colors.indexOf(item.color) === -1) records[key].colors.push(item.color);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
return Object.keys(records).map(function (key) {
|
|
100
|
+
var record = records[key];
|
|
101
|
+
var configuredColor = getConfiguredColor(record.version, optionsValue.versionColors);
|
|
102
|
+
return {
|
|
103
|
+
version: record.version,
|
|
104
|
+
color: configuredColor || record.colors[0] || 'inherit',
|
|
105
|
+
colors: record.colors,
|
|
106
|
+
hasColorConflict: record.colors.length > 1
|
|
107
|
+
};
|
|
108
|
+
}).sort(function (left, right) {
|
|
109
|
+
return compareVersions(left.version, right.version);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function unwrapCellColor(cell) {
|
|
114
|
+
return String(cell || '').replace(/<span\b[^>]*style\s*=\s*["'][^"']*color\s*:[^"']*["'][^>]*>([\s\S]*?)<\/span>/gi, '$1').trim();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function synchronizeVersionHistoryColors(markdown, options) {
|
|
118
|
+
var detected = collectColoredVersions(markdown);
|
|
119
|
+
var colors = {};
|
|
120
|
+
detected.forEach(function (item) {
|
|
121
|
+
colors[normalizeVersion(item.version)] = getConfiguredColor(item.version, options && options.versionColors) || item.color;
|
|
122
|
+
});
|
|
123
|
+
if (!Object.keys(colors).length) return markdown;
|
|
124
|
+
|
|
125
|
+
var lines = String(markdown || '').split(/\r?\n/);
|
|
126
|
+
var output = [];
|
|
127
|
+
for (var index = 0; index < lines.length; index += 1) {
|
|
128
|
+
if (!/^\s*\|.*\|\s*$/.test(lines[index])) {
|
|
129
|
+
output.push(lines[index]);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
var tableLines = [];
|
|
133
|
+
while (index < lines.length && /^\s*\|.*\|\s*$/.test(lines[index])) {
|
|
134
|
+
tableLines.push(lines[index]);
|
|
135
|
+
index += 1;
|
|
136
|
+
}
|
|
137
|
+
index -= 1;
|
|
138
|
+
if (isVersionHistoryTable(tableLines)) {
|
|
139
|
+
tableLines = tableLines.map(function (row, rowIndex) {
|
|
140
|
+
if (rowIndex < 2) return row;
|
|
141
|
+
var cells = row.split('|').slice(1, -1);
|
|
142
|
+
var version = extractVersion(cells[0]);
|
|
143
|
+
var color = colors[normalizeVersion(version)];
|
|
144
|
+
if (!color) return row;
|
|
145
|
+
return '| ' + cells.map(function (cell) {
|
|
146
|
+
return '<span style="color:' + color + '">' + unwrapCellColor(cell) + '</span>';
|
|
147
|
+
}).join(' | ') + ' |';
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
output = output.concat(tableLines);
|
|
151
|
+
}
|
|
152
|
+
return output.join('\n');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
root.OpenPrototypePrdVersions = {
|
|
156
|
+
compare: compareVersions,
|
|
157
|
+
contains: function (text, version) {
|
|
158
|
+
var normalized = normalizeVersion(version);
|
|
159
|
+
if (!normalized) return false;
|
|
160
|
+
var pattern = '(^|[^0-9.])v?' + normalized.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '(?=$|[^0-9.])';
|
|
161
|
+
return new RegExp(pattern, 'i').test(String(text || ''));
|
|
162
|
+
},
|
|
163
|
+
collectColored: collectColoredVersions,
|
|
164
|
+
collectWorkspace: collectWorkspaceVersions,
|
|
165
|
+
synchronizeHistoryColors: synchronizeVersionHistoryColors,
|
|
166
|
+
extractVersion: extractVersion,
|
|
167
|
+
normalize: normalizeVersion
|
|
168
|
+
};
|
|
169
|
+
})(window);
|