openprototype 1.3.0 → 1.5.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 +8 -1
- package/README.zh-CN.md +8 -1
- package/bin/cli.js +12 -1
- package/lib/config.js +2 -1
- package/package.json +1 -1
- package/product/demo/pc/index.html +63 -18
- package/proto-kit.config.json +1 -1
- package/runtime/server.js +15 -0
- package/templates/product-shell/index.html +63 -18
package/README.md
CHANGED
|
@@ -150,6 +150,7 @@ You type in the panel ──▶ local server (/api/agent) ──▶ OpenCode
|
|
|
150
150
|
- **Context carried automatically**: click any page on the left and the top of the panel shows "This message will carry: page X / PRD Y" — no need to paste paths manually.
|
|
151
151
|
- **Incremental update per PRD red-marks**: one click sends the PRD content marked `<span style="color:red">…</span>` as the **only edit scope** to the Agent — it edits only the red-marked parts, treats un-marked history as background, and won't rewrite or "optimize on the side."
|
|
152
152
|
- **Local by default**: the server listens on `127.0.0.1` by default; all writes and the Agent interface (`/api/*`) accept local requests only.
|
|
153
|
+
- **No creation tools after publishing**: the product shell only exposes "New folder / New page" and per-folder creation controls after confirming a local openprototype service. On static SVN or similar published URLs, those controls and the creation dialog are absent from the DOM.
|
|
153
154
|
- **LAN exposure boundary**: with `--host 0.0.0.0`, LAN clients still cannot call write or Agent endpoints, but they can read non-hidden files that the static server can reach under the project root—not only prototype pages. Use this only on a trusted network and in a dedicated prototype project with no secrets or other sensitive files.
|
|
154
155
|
|
|
155
156
|
### Install OpenCode (prerequisite for the AI panel)
|
|
@@ -245,12 +246,17 @@ When Playwright or Chromium is missing, do not rely on browser-layer results; in
|
|
|
245
246
|
"startTimeoutMs": 15000
|
|
246
247
|
},
|
|
247
248
|
"products": [
|
|
248
|
-
{
|
|
249
|
+
{
|
|
250
|
+
"id": "demo",
|
|
251
|
+
"roots": ["pc"],
|
|
252
|
+
"lanAddress": "http://192.168.1.23:8082/product/demo/pc/index.html"
|
|
253
|
+
}
|
|
249
254
|
]
|
|
250
255
|
}
|
|
251
256
|
```
|
|
252
257
|
|
|
253
258
|
`host` defaults to `127.0.0.1`. Setting it to `0.0.0.0` exposes static file reads to the LAN, so review the security boundary above first. A long-running background service also requires an explicit `npx openprototype service install --allow-lan`.
|
|
259
|
+
“Copy LAN address” in the product navigator copies that product's `lanAddress` verbatim. The downstream business using openprototype owns this value; the framework does not infer it from the current browser URL. Restart the background service with `npx openprototype service restart` after changing it.
|
|
254
260
|
|
|
255
261
|
Environment variables can override temporarily: `PROTO_KIT_PORT` · `PROTO_KIT_HOST` · `OPENCODE_BIN` · `OPENCODE_MODEL` · `OPENCODE_PORT`.
|
|
256
262
|
You can also use `npx openprototype serve --port 9000 --host 0.0.0.0` to specify the port / listen address ad hoc.
|
|
@@ -271,6 +277,7 @@ The table uses `npx` for the default local-project installation. You can omit `n
|
|
|
271
277
|
| `npx openprototype check [--changed] [--static-only] [path]` | Check all pages, Git changes, or a path; optionally run static rules only |
|
|
272
278
|
| `npx openprototype nav:sync` | Scan product directories and rebuild `nav-tree.json` |
|
|
273
279
|
| `npx openprototype doctor` | Check Node / OpenCode / config / Playwright / background service health |
|
|
280
|
+
| `npx openprototype --version` | Print the installed openprototype version (also available as `-v` or `version`) |
|
|
274
281
|
| `npm update openprototype` | Upgrade the runtime package within the version range in `package.json` |
|
|
275
282
|
| `npx openprototype update` | Print manual editable-asset comparison and merge guidance; does not upgrade |
|
|
276
283
|
|
package/README.zh-CN.md
CHANGED
|
@@ -150,6 +150,7 @@ npx openprototype service uninstall
|
|
|
150
150
|
- **自动带上下文**:点左侧任一页面,面板顶部就显示「本条消息将携带:页面 X / PRD Y」,无需你手动贴路径。
|
|
151
151
|
- **按 PRD 标红增量更新**:一键把 PRD 里 `<span style="color:red">…</span>` 标红的内容作为**唯一改动范围**发给 Agent —— 只改标红处,未标红的历史内容当背景,不重写、不"顺手优化"。
|
|
152
152
|
- **默认仅本机访问**:服务器默认只监听 `127.0.0.1`;所有写入与 Agent 接口(`/api/*`)只接受本机请求。
|
|
153
|
+
- **发布态不提供创建能力**:产品壳仅在确认连接到本机 openprototype 服务后显示“新建文件夹 / 新建页面”及目录内新增入口;发布到 SVN 等静态地址后,这些入口和创建弹窗不会进入页面 DOM。
|
|
153
154
|
- **局域网开放边界**:使用 `--host 0.0.0.0` 后,局域网设备虽然不能调用写入与 Agent 接口,但能读取项目根目录下服务器可访问的非隐藏文件,不仅是原型页面。只应在可信网络和专用原型项目中使用,并确保项目中没有密钥或其他敏感文件。
|
|
154
155
|
|
|
155
156
|
### 安装 OpenCode(AI 面板前置)
|
|
@@ -247,12 +248,17 @@ npx playwright install chromium
|
|
|
247
248
|
"startTimeoutMs": 15000
|
|
248
249
|
},
|
|
249
250
|
"products": [
|
|
250
|
-
{
|
|
251
|
+
{
|
|
252
|
+
"id": "demo",
|
|
253
|
+
"roots": ["pc"],
|
|
254
|
+
"lanAddress": "http://192.168.1.23:8082/product/demo/pc/index.html"
|
|
255
|
+
}
|
|
251
256
|
]
|
|
252
257
|
}
|
|
253
258
|
```
|
|
254
259
|
|
|
255
260
|
`host` 默认为 `127.0.0.1`。设为 `0.0.0.0` 会向局域网开放静态文件读取,请先阅读上面的安全边界;长期运行的常驻服务还需显式执行 `npx openprototype service install --allow-lan`。
|
|
261
|
+
产品导航中的“复制局域网地址”会原样复制该产品的 `lanAddress`;地址由引用 openprototype 的业务配置,框架不会根据当前浏览器地址自动推断。修改后,常驻服务需执行一次 `npx openprototype service restart`。
|
|
256
262
|
|
|
257
263
|
环境变量可临时覆盖:`PROTO_KIT_PORT` · `PROTO_KIT_HOST` · `OPENCODE_BIN` · `OPENCODE_MODEL` · `OPENCODE_PORT`。
|
|
258
264
|
也可用 `npx openprototype serve --port 9000 --host 0.0.0.0` 临时指定端口 / 监听地址。
|
|
@@ -273,6 +279,7 @@ npx playwright install chromium
|
|
|
273
279
|
| `npx openprototype check [--changed] [--static-only] [路径]` | 检查全部、Git 改动或指定范围;可只跑静态规则 |
|
|
274
280
|
| `npx openprototype nav:sync` | 扫描产品目录并重建 `nav-tree.json` |
|
|
275
281
|
| `npx openprototype doctor` | 体检 Node / OpenCode / 配置 / Playwright / 常驻服务 |
|
|
282
|
+
| `npx openprototype --version` | 查看当前安装的 openprototype 版本号(也可使用 `-v` 或 `version`) |
|
|
276
283
|
| `npm update openprototype` | 按 `package.json` 的版本范围升级框架运行时包 |
|
|
277
284
|
| `npx openprototype update` | 仅打印可编辑资产的手工对比与合并指引,不执行升级 |
|
|
278
285
|
|
package/bin/cli.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* openprototype nav:sync 重建各产品 nav-tree.json
|
|
14
14
|
* openprototype doctor 体检:Node / OpenCode / 配置 / Playwright
|
|
15
15
|
* openprototype update 提示如何更新框架(运行时随 npm,可编辑资产按需覆盖)
|
|
16
|
+
* openprototype --version 查看当前版本号
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
const fs = require('fs');
|
|
@@ -311,7 +312,7 @@ function cmdAddProduct(argv) {
|
|
|
311
312
|
const config = loadOrInitConfig(root);
|
|
312
313
|
config.products = config.products || [];
|
|
313
314
|
if (!config.products.some((p) => p.id === id)) {
|
|
314
|
-
config.products.push({ id, roots: ['pc'] });
|
|
315
|
+
config.products.push({ id, roots: ['pc'], lanAddress: '' });
|
|
315
316
|
saveConfig(root, config);
|
|
316
317
|
ok(`已在 ${CONFIG_FILENAME} 注册产品 ${id}`);
|
|
317
318
|
} else info(C.dim(` 产品 ${id} 已在配置中`));
|
|
@@ -470,6 +471,12 @@ function cmdUpdate() {
|
|
|
470
471
|
info(C.dim(' (建议先 git commit,再用 diff 工具挑选要更新的内容,保护你的本地改动)\n'));
|
|
471
472
|
}
|
|
472
473
|
|
|
474
|
+
function cmdVersion() {
|
|
475
|
+
const pkg = readJson(path.join(PKG_ROOT, 'package.json'), {});
|
|
476
|
+
if (!pkg.version) die('无法读取 openprototype 版本号');
|
|
477
|
+
info(pkg.version);
|
|
478
|
+
}
|
|
479
|
+
|
|
473
480
|
// ── 入口 ────────────────────────────────────────────────
|
|
474
481
|
function help() {
|
|
475
482
|
info(`
|
|
@@ -485,6 +492,7 @@ ${C.b('openprototype')} — 本地原型工作台脚手架
|
|
|
485
492
|
${C.g('openprototype nav:sync')} 重建各产品 nav-tree.json
|
|
486
493
|
${C.g('openprototype doctor')} 体检(Node / OpenCode / 配置 / Playwright)
|
|
487
494
|
${C.g('openprototype update')} 如何更新框架
|
|
495
|
+
${C.g('openprototype --version')} 查看当前版本号(也可使用 -v 或 version)
|
|
488
496
|
`);
|
|
489
497
|
}
|
|
490
498
|
|
|
@@ -501,6 +509,9 @@ async function main() {
|
|
|
501
509
|
case 'nav-sync': return runNode('scripts/check/sync-nav-tree.js', argv);
|
|
502
510
|
case 'doctor': return cmdDoctor();
|
|
503
511
|
case 'update': return cmdUpdate();
|
|
512
|
+
case '-v':
|
|
513
|
+
case '--version':
|
|
514
|
+
case 'version': return cmdVersion();
|
|
504
515
|
case undefined:
|
|
505
516
|
case '-h':
|
|
506
517
|
case '--help':
|
package/lib/config.js
CHANGED
|
@@ -29,8 +29,9 @@ const DEFAULTS = {
|
|
|
29
29
|
port: 4097,
|
|
30
30
|
startTimeoutMs: 15000
|
|
31
31
|
},
|
|
32
|
+
// lanAddress 由引用 openprototype 的业务配置,导航壳的“复制局域网地址”会原样复制该值。
|
|
32
33
|
// 每个产品一个入口目录;roots 目前只支持 'pc'('h5' 后续再加)
|
|
33
|
-
products: [{ id: 'demo', roots: ['pc'] }]
|
|
34
|
+
products: [{ id: 'demo', roots: ['pc'], lanAddress: '' }]
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
function deepMerge(base, override) {
|
package/package.json
CHANGED
|
@@ -553,7 +553,7 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
553
553
|
<div class="sidebar-header">
|
|
554
554
|
<div class="sidebar-title-row">
|
|
555
555
|
<div class="sidebar-title">Demo 原型导航</div>
|
|
556
|
-
<button class="copy-address-btn" id="copyAddressBtn" type="button"
|
|
556
|
+
<button class="copy-address-btn" id="copyAddressBtn" type="button">复制局域网地址</button>
|
|
557
557
|
</div>
|
|
558
558
|
<div class="version-row">
|
|
559
559
|
<span class="version-label">版本</span>
|
|
@@ -577,8 +577,8 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
577
577
|
</label>
|
|
578
578
|
<button class="btn" id="expandAllBtn">全部展开</button>
|
|
579
579
|
<button class="btn" id="collapseAllBtn">全部折叠</button>
|
|
580
|
-
<button class="btn" id="newFolderBtn">新建文件夹</button>
|
|
581
|
-
<button class="btn" id="newPageBtn">新建页面</button>
|
|
580
|
+
<button class="btn" id="newFolderBtn" hidden>新建文件夹</button>
|
|
581
|
+
<button class="btn" id="newPageBtn" hidden>新建页面</button>
|
|
582
582
|
</div>
|
|
583
583
|
</div>
|
|
584
584
|
|
|
@@ -638,8 +638,31 @@ const VERSION_KEY = NAV_NS + '-version';
|
|
|
638
638
|
const VERSION_HISTORY_KEY = NAV_NS + '-version-history';
|
|
639
639
|
const REVIEW_KEY = NAV_NS + '-review-status';
|
|
640
640
|
const SIDEBAR_WIDTH_KEY = NAV_NS + '-sidebar-width';
|
|
641
|
-
// 复制当前页面地址(供分享本地/局域网预览地址)
|
|
642
641
|
const navStorage = window['localStorage'];
|
|
642
|
+
let localEditingEnabled = false;
|
|
643
|
+
|
|
644
|
+
async function detectLocalEditing() {
|
|
645
|
+
try {
|
|
646
|
+
const res = await fetch('/api/health', { cache: 'no-store' });
|
|
647
|
+
const data = await res.json().catch(() => ({}));
|
|
648
|
+
return res.ok && data.ok === true && typeof data.version === 'string' && Number.isFinite(data.port);
|
|
649
|
+
} catch {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function applyLocalEditingState() {
|
|
655
|
+
const createControls = ['newFolderBtn', 'newPageBtn']
|
|
656
|
+
.map(id => document.getElementById(id))
|
|
657
|
+
.filter(Boolean);
|
|
658
|
+
if (localEditingEnabled) {
|
|
659
|
+
createControls.forEach(control => { control.hidden = false; });
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
createControls.forEach(control => control.remove());
|
|
663
|
+
const createModal = document.getElementById('createModalMask');
|
|
664
|
+
if (createModal) createModal.remove();
|
|
665
|
+
}
|
|
643
666
|
|
|
644
667
|
function loadReviewStatus() {
|
|
645
668
|
try { return JSON.parse(navStorage.getItem(REVIEW_KEY) || '{}'); } catch { return {}; }
|
|
@@ -1289,7 +1312,10 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1289
1312
|
const head = document.createElement('div');
|
|
1290
1313
|
head.className = 'folder-head';
|
|
1291
1314
|
setupTreeDrag(head, trail, navNodeKey(node), folderKey);
|
|
1292
|
-
|
|
1315
|
+
const createActions = localEditingEnabled
|
|
1316
|
+
? '<button type="button" class="tree-add-btn" data-create="page" title="在此文件夹新建页面">+页</button><button type="button" class="tree-add-btn" data-create="folder" title="在此文件夹新建子文件夹">+夹</button>'
|
|
1317
|
+
: '';
|
|
1318
|
+
head.innerHTML = `<span class="folder-arrow">${I_ARROW}</span><span class="folder-icon">${I_FOLDER}</span><span class="folder-name">${node.name}</span>${createActions}`;
|
|
1293
1319
|
head.addEventListener('click', () => {
|
|
1294
1320
|
if (Date.now() >= suppressTreeClickUntil) folder.classList.toggle('collapsed');
|
|
1295
1321
|
});
|
|
@@ -1439,11 +1465,22 @@ function copyText(text, successMsg) {
|
|
|
1439
1465
|
});
|
|
1440
1466
|
}
|
|
1441
1467
|
|
|
1468
|
+
async function loadLanAddress() {
|
|
1469
|
+
const productId = window.PROTO_KIT && window.PROTO_KIT.productId;
|
|
1470
|
+
const params = new URLSearchParams({ productId: productId || '' });
|
|
1471
|
+
const res = await fetch('/api/lan-address?' + params.toString(), { cache: 'no-store' });
|
|
1472
|
+
const data = await res.json().catch(() => ({}));
|
|
1473
|
+
if (!res.ok || !data.ok) throw new Error(data.error || '局域网地址读取失败');
|
|
1474
|
+
return String(data.lanAddress || '').trim();
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1442
1477
|
// ─────────────────────────────────────────────
|
|
1443
1478
|
// Init
|
|
1444
1479
|
// ─────────────────────────────────────────────
|
|
1445
1480
|
window.addEventListener('DOMContentLoaded', async () => {
|
|
1446
1481
|
initSidebarResize();
|
|
1482
|
+
localEditingEnabled = await detectLocalEditing();
|
|
1483
|
+
applyLocalEditingState();
|
|
1447
1484
|
try {
|
|
1448
1485
|
await loadTree();
|
|
1449
1486
|
} catch (e) {
|
|
@@ -1496,24 +1533,32 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1496
1533
|
document.getElementById('collapseAllBtn').addEventListener('click', () => {
|
|
1497
1534
|
treeWrap.querySelectorAll('.folder').forEach(f => f.classList.add('collapsed'));
|
|
1498
1535
|
});
|
|
1499
|
-
document.getElementById('copyAddressBtn').addEventListener('click', () => {
|
|
1500
|
-
|
|
1536
|
+
document.getElementById('copyAddressBtn').addEventListener('click', async () => {
|
|
1537
|
+
try {
|
|
1538
|
+
const lanAddress = await loadLanAddress();
|
|
1539
|
+
if (!lanAddress) {
|
|
1540
|
+
showToast('请先在 proto-kit.config.json 配置该产品的 lanAddress');
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
copyText(lanAddress, '局域网地址已复制到剪贴板');
|
|
1544
|
+
} catch (err) {
|
|
1545
|
+
showToast(err.message || '局域网地址读取失败');
|
|
1546
|
+
}
|
|
1501
1547
|
});
|
|
1502
1548
|
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
input.addEventListener('keydown', e => {
|
|
1549
|
+
if (localEditingEnabled) {
|
|
1550
|
+
document.getElementById('newFolderBtn').addEventListener('click', () => openCreateModal('folder', ''));
|
|
1551
|
+
document.getElementById('newPageBtn').addEventListener('click', () => openCreateModal('page', ''));
|
|
1552
|
+
document.getElementById('createCancelBtn').addEventListener('click', closeCreateModal);
|
|
1553
|
+
document.getElementById('createConfirmBtn').addEventListener('click', submitCreateModal);
|
|
1554
|
+
document.getElementById('createModalMask').addEventListener('click', e => {
|
|
1555
|
+
if (e.target === e.currentTarget) closeCreateModal();
|
|
1556
|
+
});
|
|
1557
|
+
document.getElementById('createNameInput').addEventListener('keydown', e => {
|
|
1513
1558
|
if (e.key === 'Enter') { e.preventDefault(); submitCreateModal(); }
|
|
1514
1559
|
else if (e.key === 'Escape') closeCreateModal();
|
|
1515
1560
|
});
|
|
1516
|
-
}
|
|
1561
|
+
}
|
|
1517
1562
|
|
|
1518
1563
|
});
|
|
1519
1564
|
</script>
|
package/proto-kit.config.json
CHANGED
package/runtime/server.js
CHANGED
|
@@ -136,6 +136,17 @@ function requireLoopback(req, res) {
|
|
|
136
136
|
return false;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
function handleLanAddress(req, res) {
|
|
140
|
+
const requestUrl = new URL(req.url, 'http://localhost');
|
|
141
|
+
const productId = String(requestUrl.searchParams.get('productId') || '').trim();
|
|
142
|
+
const product = CONFIG.products.find((item) => item.id === productId);
|
|
143
|
+
if (!product) return sendJson(res, 404, { ok: false, error: '未找到对应产品的局域网地址配置' });
|
|
144
|
+
return sendJson(res, 200, {
|
|
145
|
+
ok: true,
|
|
146
|
+
lanAddress: typeof product.lanAddress === 'string' ? product.lanAddress.trim() : ''
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
139
150
|
// ── PRD 保存 ───────────────────────────────────────────
|
|
140
151
|
function handleSavePrd(req, res) {
|
|
141
152
|
readJsonBody(req, 5 * 1024 * 1024, (parseErr, data) => {
|
|
@@ -944,6 +955,10 @@ const server = http.createServer(async (req, res) => {
|
|
|
944
955
|
});
|
|
945
956
|
}
|
|
946
957
|
|
|
958
|
+
if (req.method === 'GET' && urlPath === '/api/lan-address') {
|
|
959
|
+
return handleLanAddress(req, res);
|
|
960
|
+
}
|
|
961
|
+
|
|
947
962
|
if (await handleAgentApi(req, res, urlPath)) return;
|
|
948
963
|
|
|
949
964
|
if (req.method === 'POST' && urlPath === '/api/save-prd') return requireLoopback(req, res) && handleSavePrd(req, res);
|
|
@@ -553,7 +553,7 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
553
553
|
<div class="sidebar-header">
|
|
554
554
|
<div class="sidebar-title-row">
|
|
555
555
|
<div class="sidebar-title">{{PRODUCT_TITLE}} 原型导航</div>
|
|
556
|
-
<button class="copy-address-btn" id="copyAddressBtn" type="button"
|
|
556
|
+
<button class="copy-address-btn" id="copyAddressBtn" type="button">复制局域网地址</button>
|
|
557
557
|
</div>
|
|
558
558
|
<div class="version-row">
|
|
559
559
|
<span class="version-label">版本</span>
|
|
@@ -577,8 +577,8 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
577
577
|
</label>
|
|
578
578
|
<button class="btn" id="expandAllBtn">全部展开</button>
|
|
579
579
|
<button class="btn" id="collapseAllBtn">全部折叠</button>
|
|
580
|
-
<button class="btn" id="newFolderBtn">新建文件夹</button>
|
|
581
|
-
<button class="btn" id="newPageBtn">新建页面</button>
|
|
580
|
+
<button class="btn" id="newFolderBtn" hidden>新建文件夹</button>
|
|
581
|
+
<button class="btn" id="newPageBtn" hidden>新建页面</button>
|
|
582
582
|
</div>
|
|
583
583
|
</div>
|
|
584
584
|
|
|
@@ -638,8 +638,31 @@ const VERSION_KEY = NAV_NS + '-version';
|
|
|
638
638
|
const VERSION_HISTORY_KEY = NAV_NS + '-version-history';
|
|
639
639
|
const REVIEW_KEY = NAV_NS + '-review-status';
|
|
640
640
|
const SIDEBAR_WIDTH_KEY = NAV_NS + '-sidebar-width';
|
|
641
|
-
// 复制当前页面地址(供分享本地/局域网预览地址)
|
|
642
641
|
const navStorage = window['localStorage'];
|
|
642
|
+
let localEditingEnabled = false;
|
|
643
|
+
|
|
644
|
+
async function detectLocalEditing() {
|
|
645
|
+
try {
|
|
646
|
+
const res = await fetch('/api/health', { cache: 'no-store' });
|
|
647
|
+
const data = await res.json().catch(() => ({}));
|
|
648
|
+
return res.ok && data.ok === true && typeof data.version === 'string' && Number.isFinite(data.port);
|
|
649
|
+
} catch {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function applyLocalEditingState() {
|
|
655
|
+
const createControls = ['newFolderBtn', 'newPageBtn']
|
|
656
|
+
.map(id => document.getElementById(id))
|
|
657
|
+
.filter(Boolean);
|
|
658
|
+
if (localEditingEnabled) {
|
|
659
|
+
createControls.forEach(control => { control.hidden = false; });
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
createControls.forEach(control => control.remove());
|
|
663
|
+
const createModal = document.getElementById('createModalMask');
|
|
664
|
+
if (createModal) createModal.remove();
|
|
665
|
+
}
|
|
643
666
|
|
|
644
667
|
function loadReviewStatus() {
|
|
645
668
|
try { return JSON.parse(navStorage.getItem(REVIEW_KEY) || '{}'); } catch { return {}; }
|
|
@@ -1289,7 +1312,10 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1289
1312
|
const head = document.createElement('div');
|
|
1290
1313
|
head.className = 'folder-head';
|
|
1291
1314
|
setupTreeDrag(head, trail, navNodeKey(node), folderKey);
|
|
1292
|
-
|
|
1315
|
+
const createActions = localEditingEnabled
|
|
1316
|
+
? '<button type="button" class="tree-add-btn" data-create="page" title="在此文件夹新建页面">+页</button><button type="button" class="tree-add-btn" data-create="folder" title="在此文件夹新建子文件夹">+夹</button>'
|
|
1317
|
+
: '';
|
|
1318
|
+
head.innerHTML = `<span class="folder-arrow">${I_ARROW}</span><span class="folder-icon">${I_FOLDER}</span><span class="folder-name">${node.name}</span>${createActions}`;
|
|
1293
1319
|
head.addEventListener('click', () => {
|
|
1294
1320
|
if (Date.now() >= suppressTreeClickUntil) folder.classList.toggle('collapsed');
|
|
1295
1321
|
});
|
|
@@ -1439,11 +1465,22 @@ function copyText(text, successMsg) {
|
|
|
1439
1465
|
});
|
|
1440
1466
|
}
|
|
1441
1467
|
|
|
1468
|
+
async function loadLanAddress() {
|
|
1469
|
+
const productId = window.PROTO_KIT && window.PROTO_KIT.productId;
|
|
1470
|
+
const params = new URLSearchParams({ productId: productId || '' });
|
|
1471
|
+
const res = await fetch('/api/lan-address?' + params.toString(), { cache: 'no-store' });
|
|
1472
|
+
const data = await res.json().catch(() => ({}));
|
|
1473
|
+
if (!res.ok || !data.ok) throw new Error(data.error || '局域网地址读取失败');
|
|
1474
|
+
return String(data.lanAddress || '').trim();
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1442
1477
|
// ─────────────────────────────────────────────
|
|
1443
1478
|
// Init
|
|
1444
1479
|
// ─────────────────────────────────────────────
|
|
1445
1480
|
window.addEventListener('DOMContentLoaded', async () => {
|
|
1446
1481
|
initSidebarResize();
|
|
1482
|
+
localEditingEnabled = await detectLocalEditing();
|
|
1483
|
+
applyLocalEditingState();
|
|
1447
1484
|
try {
|
|
1448
1485
|
await loadTree();
|
|
1449
1486
|
} catch (e) {
|
|
@@ -1496,24 +1533,32 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1496
1533
|
document.getElementById('collapseAllBtn').addEventListener('click', () => {
|
|
1497
1534
|
treeWrap.querySelectorAll('.folder').forEach(f => f.classList.add('collapsed'));
|
|
1498
1535
|
});
|
|
1499
|
-
document.getElementById('copyAddressBtn').addEventListener('click', () => {
|
|
1500
|
-
|
|
1536
|
+
document.getElementById('copyAddressBtn').addEventListener('click', async () => {
|
|
1537
|
+
try {
|
|
1538
|
+
const lanAddress = await loadLanAddress();
|
|
1539
|
+
if (!lanAddress) {
|
|
1540
|
+
showToast('请先在 proto-kit.config.json 配置该产品的 lanAddress');
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
copyText(lanAddress, '局域网地址已复制到剪贴板');
|
|
1544
|
+
} catch (err) {
|
|
1545
|
+
showToast(err.message || '局域网地址读取失败');
|
|
1546
|
+
}
|
|
1501
1547
|
});
|
|
1502
1548
|
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
input.addEventListener('keydown', e => {
|
|
1549
|
+
if (localEditingEnabled) {
|
|
1550
|
+
document.getElementById('newFolderBtn').addEventListener('click', () => openCreateModal('folder', ''));
|
|
1551
|
+
document.getElementById('newPageBtn').addEventListener('click', () => openCreateModal('page', ''));
|
|
1552
|
+
document.getElementById('createCancelBtn').addEventListener('click', closeCreateModal);
|
|
1553
|
+
document.getElementById('createConfirmBtn').addEventListener('click', submitCreateModal);
|
|
1554
|
+
document.getElementById('createModalMask').addEventListener('click', e => {
|
|
1555
|
+
if (e.target === e.currentTarget) closeCreateModal();
|
|
1556
|
+
});
|
|
1557
|
+
document.getElementById('createNameInput').addEventListener('keydown', e => {
|
|
1513
1558
|
if (e.key === 'Enter') { e.preventDefault(); submitCreateModal(); }
|
|
1514
1559
|
else if (e.key === 'Escape') closeCreateModal();
|
|
1515
1560
|
});
|
|
1516
|
-
}
|
|
1561
|
+
}
|
|
1517
1562
|
|
|
1518
1563
|
});
|
|
1519
1564
|
</script>
|