openprototype 1.0.2 → 1.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/README.md +77 -31
- package/README.zh-CN.md +78 -30
- package/bin/cli.js +72 -4
- package/package.json +1 -1
- package/product/demo/pc/customer//350/256/242/345/215/225/order_list.html +25 -0
- package/product/demo/pc/customer//350/256/242/345/215/225/order_list.md +18 -0
- package/product/demo/pc/index.html +104 -24
- package/product/demo/pc/nav-tree.json +9 -0
- package/runtime/server.js +96 -2
- package/runtime/shell/onboarding.css +184 -0
- package/runtime/shell/onboarding.js +422 -0
- package/scripts/check/sync-nav-tree.js +1 -0
- package/templates/product-shell/index.html +104 -24
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
<!-- agent-panel:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
8
8
|
<link rel="stylesheet" href="/_kit/shell/agent-panel.css">
|
|
9
9
|
<!-- agent-panel:end -->
|
|
10
|
+
<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
11
|
+
<link rel="stylesheet" href="/_kit/shell/onboarding.css">
|
|
12
|
+
<!-- onboarding:end -->
|
|
10
13
|
<style>
|
|
11
14
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
12
15
|
|
|
@@ -284,6 +287,11 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
284
287
|
.file-row.tree-drag-before::before { top: -1px; }
|
|
285
288
|
.folder-head.tree-drag-after::after,
|
|
286
289
|
.file-row.tree-drag-after::after { bottom: -1px; }
|
|
290
|
+
.folder-head.tree-drag-into {
|
|
291
|
+
color: #0958d9;
|
|
292
|
+
background: #e6f4ff;
|
|
293
|
+
box-shadow: inset 0 0 0 1px #1677ff;
|
|
294
|
+
}
|
|
287
295
|
|
|
288
296
|
/* ── Folder ── */
|
|
289
297
|
.folder-head {
|
|
@@ -597,12 +605,8 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
597
605
|
<div class="create-modal-title" id="createModalTitle">新建页面</div>
|
|
598
606
|
<div class="create-modal-location" id="createModalLocation"></div>
|
|
599
607
|
<div class="create-modal-field">
|
|
600
|
-
<label for="createNameInput"
|
|
601
|
-
<input id="createNameInput" type="text" placeholder="如
|
|
602
|
-
</div>
|
|
603
|
-
<div class="create-modal-field" id="createTitleField">
|
|
604
|
-
<label for="createTitleInput">页面标题(可选,用于页面 <title> 与 PRD)</label>
|
|
605
|
-
<input id="createTitleInput" type="text" placeholder="如 订单列表" autocomplete="off">
|
|
608
|
+
<label for="createNameInput" id="createNameLabel">名称</label>
|
|
609
|
+
<input id="createNameInput" type="text" placeholder="如 订单列表" autocomplete="off">
|
|
606
610
|
</div>
|
|
607
611
|
<div class="create-modal-error" id="createModalError"></div>
|
|
608
612
|
<div class="create-modal-actions">
|
|
@@ -822,7 +826,8 @@ const breadcrumbMap = {};
|
|
|
822
826
|
function buildBreadcrumbs(nodes, trail) {
|
|
823
827
|
nodes.forEach(n => {
|
|
824
828
|
if (n.file) {
|
|
825
|
-
|
|
829
|
+
const label = n.title || n.file;
|
|
830
|
+
breadcrumbMap[n.path] = trail ? trail + ' / ' + label : label;
|
|
826
831
|
} else {
|
|
827
832
|
buildBreadcrumbs(n.children || [], trail ? trail + ' / ' + n.name : n.name);
|
|
828
833
|
}
|
|
@@ -1072,24 +1077,24 @@ function treeSortingBlocked() {
|
|
|
1072
1077
|
}
|
|
1073
1078
|
|
|
1074
1079
|
function clearTreeDragStyles() {
|
|
1075
|
-
document.querySelectorAll('.dragging, .tree-drag-before, .tree-drag-after').forEach(element => {
|
|
1076
|
-
element.classList.remove('dragging', 'tree-drag-before', 'tree-drag-after');
|
|
1080
|
+
document.querySelectorAll('.dragging, .tree-drag-before, .tree-drag-after, .tree-drag-into').forEach(element => {
|
|
1081
|
+
element.classList.remove('dragging', 'tree-drag-before', 'tree-drag-after', 'tree-drag-into');
|
|
1077
1082
|
delete element.dataset.dropPosition;
|
|
1078
1083
|
});
|
|
1079
1084
|
}
|
|
1080
1085
|
|
|
1081
1086
|
function clearTreeDropStyles() {
|
|
1082
|
-
document.querySelectorAll('.tree-drag-before, .tree-drag-after').forEach(element => {
|
|
1083
|
-
element.classList.remove('tree-drag-before', 'tree-drag-after');
|
|
1087
|
+
document.querySelectorAll('.tree-drag-before, .tree-drag-after, .tree-drag-into').forEach(element => {
|
|
1088
|
+
element.classList.remove('tree-drag-before', 'tree-drag-after', 'tree-drag-into');
|
|
1084
1089
|
delete element.dataset.dropPosition;
|
|
1085
1090
|
});
|
|
1086
1091
|
}
|
|
1087
1092
|
|
|
1088
|
-
function setupTreeDrag(element, parentKey, nodeKey) {
|
|
1093
|
+
function setupTreeDrag(element, parentKey, nodeKey, targetFolderKey) {
|
|
1089
1094
|
element.draggable = true;
|
|
1090
1095
|
element.dataset.parentKey = parentKey;
|
|
1091
1096
|
element.dataset.nodeKey = nodeKey;
|
|
1092
|
-
element.title = element.title || '拖动调整同级排序';
|
|
1097
|
+
element.title = element.title || (targetFolderKey ? '拖动调整同级排序,或将页面拖入此文件夹' : '拖动调整同级排序');
|
|
1093
1098
|
|
|
1094
1099
|
element.addEventListener('dragstart', event => {
|
|
1095
1100
|
if (treeSortingBlocked()) {
|
|
@@ -1097,7 +1102,12 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1097
1102
|
showToast(reorderSaving ? '正在保存排序' : '请先清除搜索或版本筛选再排序');
|
|
1098
1103
|
return;
|
|
1099
1104
|
}
|
|
1100
|
-
dragState = {
|
|
1105
|
+
dragState = {
|
|
1106
|
+
parentKey,
|
|
1107
|
+
nodeKey,
|
|
1108
|
+
sourcePath: element.dataset.path || '',
|
|
1109
|
+
isPage: nodeKey.startsWith('file:')
|
|
1110
|
+
};
|
|
1101
1111
|
suppressTreeClickUntil = Date.now() + 400;
|
|
1102
1112
|
element.classList.add('dragging');
|
|
1103
1113
|
event.dataTransfer.effectAllowed = 'move';
|
|
@@ -1105,7 +1115,17 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1105
1115
|
});
|
|
1106
1116
|
|
|
1107
1117
|
element.addEventListener('dragover', event => {
|
|
1108
|
-
if (!dragState
|
|
1118
|
+
if (!dragState) return;
|
|
1119
|
+
const isMoveIntoFolder = targetFolderKey && dragState.isPage && dragState.parentKey !== targetFolderKey;
|
|
1120
|
+
if (isMoveIntoFolder) {
|
|
1121
|
+
event.preventDefault();
|
|
1122
|
+
event.stopPropagation();
|
|
1123
|
+
clearTreeDropStyles();
|
|
1124
|
+
element.classList.add('tree-drag-into');
|
|
1125
|
+
event.dataTransfer.dropEffect = 'move';
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
if (dragState.parentKey !== parentKey || dragState.nodeKey === nodeKey) return;
|
|
1109
1129
|
event.preventDefault();
|
|
1110
1130
|
event.stopPropagation();
|
|
1111
1131
|
clearTreeDropStyles();
|
|
@@ -1115,11 +1135,22 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1115
1135
|
});
|
|
1116
1136
|
|
|
1117
1137
|
element.addEventListener('drop', event => {
|
|
1118
|
-
if (!dragState
|
|
1138
|
+
if (!dragState) return;
|
|
1139
|
+
const currentDrag = dragState;
|
|
1140
|
+
const isMoveIntoFolder = targetFolderKey && currentDrag.isPage && currentDrag.parentKey !== targetFolderKey;
|
|
1141
|
+
if (isMoveIntoFolder) {
|
|
1142
|
+
event.preventDefault();
|
|
1143
|
+
event.stopPropagation();
|
|
1144
|
+
clearTreeDragStyles();
|
|
1145
|
+
dragState = null;
|
|
1146
|
+
movePageToFolder(currentDrag.sourcePath, targetFolderKey);
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
if (currentDrag.parentKey !== parentKey || currentDrag.nodeKey === nodeKey) return;
|
|
1119
1150
|
event.preventDefault();
|
|
1120
1151
|
event.stopPropagation();
|
|
1121
1152
|
const position = element.dataset.dropPosition || 'before';
|
|
1122
|
-
const sourceKey =
|
|
1153
|
+
const sourceKey = currentDrag.nodeKey;
|
|
1123
1154
|
clearTreeDragStyles();
|
|
1124
1155
|
dragState = null;
|
|
1125
1156
|
reorderTreeNodes(parentKey, sourceKey, nodeKey, position);
|
|
@@ -1131,6 +1162,50 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1131
1162
|
});
|
|
1132
1163
|
}
|
|
1133
1164
|
|
|
1165
|
+
function movePageLocalState(sourcePath, targetPath) {
|
|
1166
|
+
if (Object.prototype.hasOwnProperty.call(versionCache, sourcePath)) {
|
|
1167
|
+
versionCache[targetPath] = versionCache[sourcePath];
|
|
1168
|
+
delete versionCache[sourcePath];
|
|
1169
|
+
saveVersionCache();
|
|
1170
|
+
}
|
|
1171
|
+
if (reviewStatus[sourcePath]) {
|
|
1172
|
+
reviewStatus[targetPath] = reviewStatus[sourcePath];
|
|
1173
|
+
delete reviewStatus[sourcePath];
|
|
1174
|
+
saveReviewStatus();
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
async function movePageToFolder(sourcePath, targetFolder) {
|
|
1179
|
+
if (!sourcePath || !targetFolder) return;
|
|
1180
|
+
const wasActive = !!(activeRow && activeRow.dataset.path === sourcePath);
|
|
1181
|
+
reorderSaving = true;
|
|
1182
|
+
try {
|
|
1183
|
+
const res = await fetch('/api/move-page', {
|
|
1184
|
+
method: 'POST',
|
|
1185
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1186
|
+
body: JSON.stringify({ base: PAGE_BASE, sourcePath, targetFolder })
|
|
1187
|
+
});
|
|
1188
|
+
const data = await res.json().catch(() => ({}));
|
|
1189
|
+
if (!res.ok || !data.ok) throw new Error(data.error || '移动失败:' + res.status);
|
|
1190
|
+
movePageLocalState(sourcePath, data.path);
|
|
1191
|
+
await loadTree();
|
|
1192
|
+
renderTree();
|
|
1193
|
+
expandFolderTrail(targetFolder);
|
|
1194
|
+
if (wasActive) {
|
|
1195
|
+
const row = document.querySelector(`.file-row[data-path="${CSS.escape(data.path)}"]`);
|
|
1196
|
+
if (row) loadPreview(data.path, row);
|
|
1197
|
+
}
|
|
1198
|
+
fetchAllVersions();
|
|
1199
|
+
showToast('页面已移入:' + targetFolder);
|
|
1200
|
+
} catch (err) {
|
|
1201
|
+
try { await loadTree(); } catch {}
|
|
1202
|
+
renderTree();
|
|
1203
|
+
showToast(err.message);
|
|
1204
|
+
} finally {
|
|
1205
|
+
reorderSaving = false;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1134
1209
|
async function reorderTreeNodes(parentKey, sourceKey, targetKey, position) {
|
|
1135
1210
|
const level = getTreeLevel(parentKey);
|
|
1136
1211
|
const beforeOrder = level.map(navNodeKey);
|
|
@@ -1177,12 +1252,13 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1177
1252
|
const row = document.createElement('div');
|
|
1178
1253
|
row.className = 'file-row';
|
|
1179
1254
|
row.dataset.path = node.path;
|
|
1180
|
-
|
|
1255
|
+
const pageLabel = node.title || node.file;
|
|
1256
|
+
row.dataset.searchText = [pageLabel, node.file, node.path, breadcrumbMap[node.path] || ''].join(' ');
|
|
1181
1257
|
setupTreeDrag(row, trail, navNodeKey(node));
|
|
1182
1258
|
row.innerHTML = `
|
|
1183
1259
|
<div class="file-main">
|
|
1184
1260
|
<span class="file-icon">${I_FILE}</span>
|
|
1185
|
-
<span class="file-name" title="${node.file}">${
|
|
1261
|
+
<span class="file-name" title="${node.file}">${pageLabel}</span>
|
|
1186
1262
|
<span class="version-badge"></span>
|
|
1187
1263
|
<!-- review-btn:start (个人审核标记,本地开发专用;发布时可自动剥离) -->
|
|
1188
1264
|
${renderReviewButton(node.path, 'md', 'PRD')}
|
|
@@ -1212,7 +1288,7 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1212
1288
|
|
|
1213
1289
|
const head = document.createElement('div');
|
|
1214
1290
|
head.className = 'folder-head';
|
|
1215
|
-
setupTreeDrag(head, trail, navNodeKey(node));
|
|
1291
|
+
setupTreeDrag(head, trail, navNodeKey(node), folderKey);
|
|
1216
1292
|
head.innerHTML = `<span class="folder-arrow">${I_ARROW}</span><span class="folder-icon">${I_FOLDER}</span><span class="folder-name">${node.name}</span><button type="button" class="tree-add-btn" data-create="page" title="在此文件夹新建页面">+页</button><button type="button" class="tree-add-btn" data-create="folder" title="在此文件夹新建子文件夹">+夹</button>`;
|
|
1217
1293
|
head.addEventListener('click', () => {
|
|
1218
1294
|
if (Date.now() >= suppressTreeClickUntil) folder.classList.toggle('collapsed');
|
|
@@ -1273,9 +1349,11 @@ function openCreateModal(type, parentPath) {
|
|
|
1273
1349
|
createModalState = { type, parentPath: parentPath || '' };
|
|
1274
1350
|
document.getElementById('createModalTitle').textContent = type === 'folder' ? '新建文件夹' : '新建页面';
|
|
1275
1351
|
document.getElementById('createModalLocation').textContent = '位置:' + (parentPath ? parentPath + '/' : '根目录');
|
|
1276
|
-
document.getElementById('
|
|
1352
|
+
document.getElementById('createNameLabel').textContent = type === 'folder'
|
|
1353
|
+
? '名称(作为文件夹名和左侧导航名称;支持中文、字母、数字、_ 和 -)'
|
|
1354
|
+
: '名称(用于文件名、左侧导航、页面 <title> 与 PRD;支持中文、字母、数字、_ 和 -)';
|
|
1355
|
+
document.getElementById('createNameInput').placeholder = type === 'folder' ? '如 customer' : '如 订单列表';
|
|
1277
1356
|
document.getElementById('createNameInput').value = '';
|
|
1278
|
-
document.getElementById('createTitleInput').value = '';
|
|
1279
1357
|
document.getElementById('createModalError').textContent = '';
|
|
1280
1358
|
document.getElementById('createModalMask').classList.add('show');
|
|
1281
1359
|
document.getElementById('createNameInput').focus();
|
|
@@ -1308,7 +1386,6 @@ async function submitCreateModal() {
|
|
|
1308
1386
|
errorEl.textContent = '';
|
|
1309
1387
|
try {
|
|
1310
1388
|
const payload = { base: PAGE_BASE, parent: parentPath, name };
|
|
1311
|
-
if (type === 'page') payload.title = document.getElementById('createTitleInput').value.trim();
|
|
1312
1389
|
const res = await fetch(type === 'folder' ? '/api/create-folder' : '/api/create-page', {
|
|
1313
1390
|
method: 'POST',
|
|
1314
1391
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -1431,7 +1508,7 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1431
1508
|
document.getElementById('createModalMask').addEventListener('click', e => {
|
|
1432
1509
|
if (e.target === e.currentTarget) closeCreateModal();
|
|
1433
1510
|
});
|
|
1434
|
-
[document.getElementById('createNameInput')
|
|
1511
|
+
[document.getElementById('createNameInput')].forEach(input => {
|
|
1435
1512
|
input.addEventListener('keydown', e => {
|
|
1436
1513
|
if (e.key === 'Enter') { e.preventDefault(); submitCreateModal(); }
|
|
1437
1514
|
else if (e.key === 'Escape') closeCreateModal();
|
|
@@ -1445,5 +1522,8 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1445
1522
|
<script>window.PROTO_KIT = { productId: 'demo', productTitle: 'Demo' };</script>
|
|
1446
1523
|
<script src="/_kit/shell/agent-panel.js"></script>
|
|
1447
1524
|
<!-- agent-panel:end -->
|
|
1525
|
+
<!-- onboarding:start (本地开发专用;发布时可由 openprototype publish 自动剥离) -->
|
|
1526
|
+
<script src="/_kit/shell/onboarding.js"></script>
|
|
1527
|
+
<!-- onboarding:end -->
|
|
1448
1528
|
</body>
|
|
1449
1529
|
</html>
|
package/runtime/server.js
CHANGED
|
@@ -232,6 +232,99 @@ function navNodeKey(node) {
|
|
|
232
232
|
return node.file ? `file:${node.file}` : `folder:${node.name}`;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
function resolvePageFile(rootDir, inputPath) {
|
|
236
|
+
const relPath = String(inputPath || '').replace(/^\/+|\/+$/g, '');
|
|
237
|
+
const segments = relPath.split('/').filter(Boolean);
|
|
238
|
+
const fileName = segments.pop();
|
|
239
|
+
if (!fileName || !fileName.toLowerCase().endsWith('.html')) {
|
|
240
|
+
throw new Error('仅允许移动 .html 页面');
|
|
241
|
+
}
|
|
242
|
+
const pageName = fileName.slice(0, -'.html'.length);
|
|
243
|
+
assertValidSegment(pageName, '页面名');
|
|
244
|
+
segments.forEach((seg) => assertValidSegment(seg, '页面目录名'));
|
|
245
|
+
const parent = segments.join('/');
|
|
246
|
+
const dir = path.join(rootDir, ...segments);
|
|
247
|
+
const file = path.join(dir, fileName);
|
|
248
|
+
if (file !== rootDir && !file.startsWith(rootDir + path.sep)) throw new Error('页面路径超出产品范围');
|
|
249
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new Error('源页面不存在');
|
|
250
|
+
return { dir, parent, file, fileName, pageName, relPath: [...segments, fileName].join('/') };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function saveNavTreeAtomically(rootDir, tree) {
|
|
254
|
+
const file = path.join(rootDir, 'nav-tree.json');
|
|
255
|
+
const tempFile = path.join(rootDir, `.nav-tree-${process.pid}-${Date.now()}.tmp`);
|
|
256
|
+
try {
|
|
257
|
+
fs.writeFileSync(tempFile, JSON.stringify(tree, null, 2) + '\n');
|
|
258
|
+
fs.renameSync(tempFile, file);
|
|
259
|
+
} finally {
|
|
260
|
+
if (fs.existsSync(tempFile)) fs.unlinkSync(tempFile);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function handleMovePage(req, res) {
|
|
265
|
+
readJsonBody(req, 64 * 1024, (parseErr, data) => {
|
|
266
|
+
const moved = [];
|
|
267
|
+
try {
|
|
268
|
+
if (parseErr) throw parseErr;
|
|
269
|
+
const rootDir = resolveProductRootDir(data.base);
|
|
270
|
+
const source = resolvePageFile(rootDir, data.sourcePath);
|
|
271
|
+
const { dir: targetDir, rel: targetFolder } = resolveParentDir(rootDir, data.targetFolder);
|
|
272
|
+
if (source.parent === targetFolder) throw new Error('页面已在目标文件夹中');
|
|
273
|
+
|
|
274
|
+
const bundleNames = [`${source.pageName}.html`, `${source.pageName}.js`, `${source.pageName}.md`];
|
|
275
|
+
const conflicts = bundleNames.filter((name) => fs.existsSync(path.join(targetDir, name)));
|
|
276
|
+
if (conflicts.length) throw new Error(`目标文件夹已存在同名文件:${conflicts.join('、')}`);
|
|
277
|
+
|
|
278
|
+
const bundle = bundleNames
|
|
279
|
+
.map((name) => ({ source: path.join(source.dir, name), target: path.join(targetDir, name), name }))
|
|
280
|
+
.filter((item) => fs.existsSync(item.source) && fs.statSync(item.source).isFile());
|
|
281
|
+
if (!bundle.some((item) => item.name === source.fileName)) throw new Error('源页面不存在');
|
|
282
|
+
|
|
283
|
+
const tree = loadNavTree(rootDir);
|
|
284
|
+
const sourceLevel = getNavLevel(tree, source.parent);
|
|
285
|
+
const sourceIndex = sourceLevel.findIndex((node) => node.file === source.fileName && node.path === source.relPath);
|
|
286
|
+
if (sourceIndex < 0) throw new Error('导航树中不存在源页面,请刷新后重试');
|
|
287
|
+
const sourceNode = sourceLevel[sourceIndex];
|
|
288
|
+
const targetLevel = getNavLevel(tree, targetFolder);
|
|
289
|
+
const targetPath = targetFolder ? `${targetFolder}/${source.fileName}` : source.fileName;
|
|
290
|
+
|
|
291
|
+
bundle.forEach((item) => {
|
|
292
|
+
fs.renameSync(item.source, item.target);
|
|
293
|
+
moved.push(item);
|
|
294
|
+
});
|
|
295
|
+
sourceLevel.splice(sourceIndex, 1);
|
|
296
|
+
targetLevel.push({
|
|
297
|
+
file: source.fileName,
|
|
298
|
+
path: targetPath,
|
|
299
|
+
...(sourceNode.title ? { title: sourceNode.title } : {})
|
|
300
|
+
});
|
|
301
|
+
saveNavTreeAtomically(rootDir, tree);
|
|
302
|
+
|
|
303
|
+
console.log(`[200] POST /api/move-page -> ${source.relPath} => ${targetPath}`);
|
|
304
|
+
sendJson(res, 200, {
|
|
305
|
+
ok: true,
|
|
306
|
+
sourcePath: source.relPath,
|
|
307
|
+
path: targetPath,
|
|
308
|
+
movedFiles: moved.map((item) => targetFolder ? `${targetFolder}/${item.name}` : item.name)
|
|
309
|
+
});
|
|
310
|
+
} catch (err) {
|
|
311
|
+
const rollbackErrors = [];
|
|
312
|
+
moved.reverse().forEach((item) => {
|
|
313
|
+
try {
|
|
314
|
+
if (fs.existsSync(item.target) && !fs.existsSync(item.source)) fs.renameSync(item.target, item.source);
|
|
315
|
+
} catch (rollbackErr) {
|
|
316
|
+
rollbackErrors.push(rollbackErr.message);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
const errorMessage = rollbackErrors.length
|
|
320
|
+
? `${err.message};回滚失败:${rollbackErrors.join('、')}`
|
|
321
|
+
: err.message;
|
|
322
|
+
console.log(`[400] POST /api/move-page -> ${errorMessage}`);
|
|
323
|
+
sendJson(res, 400, { ok: false, error: errorMessage });
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
235
328
|
function todayString() {
|
|
236
329
|
const now = new Date();
|
|
237
330
|
const pad = (n) => String(n).padStart(2, '0');
|
|
@@ -321,7 +414,7 @@ function handleCreatePage(req, res) {
|
|
|
321
414
|
const { dir: parentDir, rel: parentRel } = resolveParentDir(rootDir, data.parent);
|
|
322
415
|
const name = String(data.name || '').trim().replace(/\.html$/i, '');
|
|
323
416
|
assertValidSegment(name, '页面名');
|
|
324
|
-
const title =
|
|
417
|
+
const title = name;
|
|
325
418
|
const htmlFile = path.join(parentDir, `${name}.html`);
|
|
326
419
|
const mdFile = path.join(parentDir, `${name}.md`);
|
|
327
420
|
if (fs.existsSync(htmlFile)) throw new Error('同名页面已存在');
|
|
@@ -331,7 +424,7 @@ function handleCreatePage(req, res) {
|
|
|
331
424
|
const tree = loadNavTree(rootDir);
|
|
332
425
|
const children = ensureNavFolder(tree, parentRel);
|
|
333
426
|
if (!children.some((n) => n.file === `${name}.html`)) {
|
|
334
|
-
children.push({ file: `${name}.html`, path: relPath });
|
|
427
|
+
children.push({ file: `${name}.html`, path: relPath, title });
|
|
335
428
|
}
|
|
336
429
|
saveNavTree(rootDir, tree);
|
|
337
430
|
console.log(`[200] POST /api/create-page -> ${htmlFile}`);
|
|
@@ -857,6 +950,7 @@ const server = http.createServer(async (req, res) => {
|
|
|
857
950
|
if (req.method === 'POST' && urlPath === '/api/create-folder') return requireLoopback(req, res) && handleCreateFolder(req, res);
|
|
858
951
|
if (req.method === 'POST' && urlPath === '/api/create-page') return requireLoopback(req, res) && handleCreatePage(req, res);
|
|
859
952
|
if (req.method === 'POST' && urlPath === '/api/reorder-nav') return requireLoopback(req, res) && handleReorderNav(req, res);
|
|
953
|
+
if (req.method === 'POST' && urlPath === '/api/move-page') return requireLoopback(req, res) && handleMovePage(req, res);
|
|
860
954
|
if (req.method === 'POST' && urlPath === '/api/build-update-page-prompt') return requireLoopback(req, res) && handleBuildUpdatePagePrompt(req, res);
|
|
861
955
|
if (req.method === 'POST' && urlPath === '/api/update-page-from-prd') return requireLoopback(req, res) && handleUpdatePageFromPrd(req, res);
|
|
862
956
|
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/* 新手引导 — 首次打开工作台时的分步气泡提示。
|
|
2
|
+
层级说明:blocker(10040) < spotlight(10050) < bubble(10060)。
|
|
3
|
+
外壳内现有最高层级是新建弹窗遮罩 10000、toast 9999,故整体压在它们之上。 */
|
|
4
|
+
|
|
5
|
+
/* 吃掉引导期间的所有点击;spotlight 自身不接收事件,靠这一层拦截 */
|
|
6
|
+
.tour-blocker {
|
|
7
|
+
position: fixed;
|
|
8
|
+
inset: 0;
|
|
9
|
+
z-index: 10040;
|
|
10
|
+
cursor: default;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* 高亮框:用一个超大扩散的 box-shadow 直接在遮罩上"挖洞",
|
|
14
|
+
省掉切四块遮罩的麻烦,且天生跟随目标矩形 */
|
|
15
|
+
.tour-spotlight {
|
|
16
|
+
position: fixed;
|
|
17
|
+
z-index: 10050;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
border-radius: 8px;
|
|
20
|
+
outline: 2px solid #1677ff;
|
|
21
|
+
outline-offset: 0;
|
|
22
|
+
box-shadow: 0 0 0 9999px rgba(16, 22, 32, 0.45);
|
|
23
|
+
transition: top 0.18s ease, left 0.18s ease, width 0.18s ease, height 0.18s ease;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.tour-bubble {
|
|
27
|
+
position: fixed;
|
|
28
|
+
z-index: 10060;
|
|
29
|
+
width: 320px;
|
|
30
|
+
max-width: calc(100vw - 24px);
|
|
31
|
+
padding: 14px 16px 12px;
|
|
32
|
+
border-radius: 10px;
|
|
33
|
+
background: #fff;
|
|
34
|
+
color: #20242d;
|
|
35
|
+
font-size: 13px;
|
|
36
|
+
line-height: 1.6;
|
|
37
|
+
box-shadow: 0 8px 24px rgba(16, 22, 32, 0.18);
|
|
38
|
+
transition: top 0.18s ease, left 0.18s ease;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* 箭头:8px 实心三角,四个方向各自贴边 */
|
|
42
|
+
.tour-bubble-arrow {
|
|
43
|
+
position: absolute;
|
|
44
|
+
width: 0;
|
|
45
|
+
height: 0;
|
|
46
|
+
border: 8px solid transparent;
|
|
47
|
+
}
|
|
48
|
+
.tour-bubble-arrow.is-top {
|
|
49
|
+
bottom: -16px;
|
|
50
|
+
border-top-color: #fff;
|
|
51
|
+
}
|
|
52
|
+
.tour-bubble-arrow.is-bottom {
|
|
53
|
+
top: -16px;
|
|
54
|
+
border-bottom-color: #fff;
|
|
55
|
+
}
|
|
56
|
+
.tour-bubble-arrow.is-left {
|
|
57
|
+
right: -16px;
|
|
58
|
+
border-left-color: #fff;
|
|
59
|
+
}
|
|
60
|
+
.tour-bubble-arrow.is-right {
|
|
61
|
+
left: -16px;
|
|
62
|
+
border-right-color: #fff;
|
|
63
|
+
}
|
|
64
|
+
/* 气泡被 clamp 回视口后箭头可能指偏,此时干脆藏掉,别指错地方 */
|
|
65
|
+
.tour-bubble-arrow.is-hidden {
|
|
66
|
+
display: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.tour-step-index {
|
|
70
|
+
font-size: 11px;
|
|
71
|
+
color: #7b8495;
|
|
72
|
+
letter-spacing: 0.02em;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.tour-title {
|
|
76
|
+
margin: 2px 0 6px;
|
|
77
|
+
font-size: 14px;
|
|
78
|
+
font-weight: 600;
|
|
79
|
+
color: #20242d;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.tour-body {
|
|
83
|
+
color: #4a5262;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.tour-body b {
|
|
87
|
+
color: #20242d;
|
|
88
|
+
font-weight: 600;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.tour-actions {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
gap: 6px;
|
|
95
|
+
margin-top: 12px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.tour-actions-spacer {
|
|
99
|
+
flex: 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.tour-btn {
|
|
103
|
+
padding: 4px 12px;
|
|
104
|
+
border: 1px solid #dfe5ee;
|
|
105
|
+
border-radius: 4px;
|
|
106
|
+
background: #fff;
|
|
107
|
+
color: #4a5262;
|
|
108
|
+
font-family: inherit;
|
|
109
|
+
font-size: 12px;
|
|
110
|
+
line-height: 1.5;
|
|
111
|
+
cursor: pointer;
|
|
112
|
+
transition: background 0.12s, color 0.12s, border-color 0.12s;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.tour-btn:hover {
|
|
116
|
+
background: #f0f5ff;
|
|
117
|
+
border-color: #bfdbff;
|
|
118
|
+
color: #1677ff;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.tour-btn-primary {
|
|
122
|
+
border-color: #1677ff;
|
|
123
|
+
background: #1677ff;
|
|
124
|
+
color: #fff;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.tour-btn-primary:hover {
|
|
128
|
+
background: #0d5edb;
|
|
129
|
+
border-color: #0d5edb;
|
|
130
|
+
color: #fff;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.tour-skip {
|
|
134
|
+
padding: 4px 2px;
|
|
135
|
+
border: 0;
|
|
136
|
+
background: transparent;
|
|
137
|
+
color: #7b8495;
|
|
138
|
+
font-family: inherit;
|
|
139
|
+
font-size: 12px;
|
|
140
|
+
cursor: pointer;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.tour-skip:hover {
|
|
144
|
+
color: #1677ff;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.tour-btn:focus-visible,
|
|
148
|
+
.tour-skip:focus-visible,
|
|
149
|
+
.tour-replay-btn:focus-visible {
|
|
150
|
+
outline: 2px solid #1677ff;
|
|
151
|
+
outline-offset: 2px;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/* 侧栏标题行里的「?」重放入口,由 onboarding.js 运行时注入。
|
|
155
|
+
尺寸与 .copy-address-btn 对齐,保证同一行视觉齐平 */
|
|
156
|
+
.tour-replay-btn {
|
|
157
|
+
flex-shrink: 0;
|
|
158
|
+
width: 24px;
|
|
159
|
+
height: 24px;
|
|
160
|
+
padding: 0;
|
|
161
|
+
border: 1px solid #dfe5ee;
|
|
162
|
+
border-radius: 50%;
|
|
163
|
+
background: #fff;
|
|
164
|
+
color: #7b8495;
|
|
165
|
+
font-family: inherit;
|
|
166
|
+
font-size: 12px;
|
|
167
|
+
line-height: 1;
|
|
168
|
+
cursor: pointer;
|
|
169
|
+
transition: background 0.12s, color 0.12s, border-color 0.12s;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.tour-replay-btn:hover {
|
|
173
|
+
background: #edf6ff;
|
|
174
|
+
border-color: #1677ff;
|
|
175
|
+
color: #1677ff;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* 低动效偏好下去掉位移过渡,避免引导跳来跳去引起不适 */
|
|
179
|
+
@media (prefers-reduced-motion: reduce) {
|
|
180
|
+
.tour-spotlight,
|
|
181
|
+
.tour-bubble {
|
|
182
|
+
transition: none;
|
|
183
|
+
}
|
|
184
|
+
}
|