dsh-devdock 2.0.0 → 2.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/client.js CHANGED
@@ -641,6 +641,72 @@ window.__ModuleLoader__.load({
641
641
  relYesterday: '昨天',
642
642
  relDays: '{n} 天前',
643
643
 
644
+ /* Cloudflare */
645
+ cfSection: 'Cloudflare',
646
+ cfAuthGlobal: 'Global API Key(全权限,免勾选)',
647
+ cfAuthToken: 'API Token(可细粒度)',
648
+ cfAuthGlobalShort: 'Global API Key',
649
+ cfAuthTokenShort: 'API Token',
650
+ cfTokenPlaceholder: '粘贴 Cloudflare API Token',
651
+ cfKeyPlaceholder: 'cfk_... 或旧版十六进制',
652
+ cfEmailPlaceholder: 'Cloudflare 账户邮箱',
653
+ cfGlobalHint: 'Global API Key 拥有账户全部权限,只需邮箱 + Key,不用逐个勾选。在 My Profile › API Tokens 页底部「Global API Key」处点 View 获取(新版以 cfk_ 开头)。',
654
+ cfAdd: '添加账号',
655
+ cfCurrent: '当前',
656
+ cfSwitch: '切换',
657
+ cfRemove: '移除',
658
+ cfTokenHint: 'Token 需含 Account:Read、Workers Scripts:Edit、Pages:Edit、Zone:Read 等权限组',
659
+ cfTokenPage: '去 Cloudflare 生成 Token',
660
+ cfNoAccountHint: '在设置里添加一个 API Token 或 Global API Key',
661
+ cfOverviewTitle: '项目概览',
662
+ cfOverviewPages: 'Pages 项目',
663
+ cfOverviewWorkers: 'Workers',
664
+ cfOverviewZones: '域名',
665
+ cfOverviewLoading: '正在读取概览…',
666
+ cfSelectAccount: '选择账户',
667
+ cfSelectAccountHint: '一个凭据可能属于多个账户,选一个作为当前账户',
668
+ cfProjectsTitle: 'Pages 项目',
669
+ cfWorkersTitle: 'Workers',
670
+ cfZonesTitle: '域名',
671
+ cfOpenDash: '在控制台打开',
672
+ cfEmpty: '没有数据',
673
+ cfNeedAccount: '请先登录 Cloudflare 账号',
674
+ cfNoAccountLong: '在 设置 › DevDock › Cloudflare 里添加一个 API Token 或 Global API Key。',
675
+ cfNewProject: '新建项目',
676
+ cfNewProjectHint: '项目名会成为 <名称>.pages.dev 的默认站点;之后可在控制台绑定自定义域名。',
677
+ cfProjectName: '项目名',
678
+ cfCreate: '创建',
679
+ cfDelete: '删除',
680
+ cfDeleteConfirm: '确认删除',
681
+ cfDeployTitle: '部署',
682
+ cfDetecting: '正在探测目录…',
683
+ cfDetectPages: '识别为 Pages 静态站点',
684
+ cfDetectWorker: '识别为 Worker 项目',
685
+ cfDetectNone: '这个目录既不是 Pages 静态产物,也不是 Worker 项目',
686
+ cfNeedDir: '先选一个目录',
687
+ cfNeedDirHint: '部署需要读取这个目录里的产物或 Worker 源码。可以在上方「选择目录」里指定。',
688
+ cfPickProject: '选择 Pages 项目…',
689
+ cfBranchOptional: '分支(可选,留空用生产分支)',
690
+ cfDeployAction: '部署',
691
+ cfDeploying: '部署中…',
692
+ cfDeployedPages: 'Pages 部署完成',
693
+ cfDeployedWorker: 'Worker 部署完成',
694
+ cfDeployUrl: '访问地址',
695
+ cfDeployOpenDash: '在控制台查看',
696
+ cfReviewOpen: '部署前审查',
697
+ cfReviewHint: '先检查即将上传的文件,再决定是否部署。规则扫描(敏感信息)始终执行,模型审查可选。',
698
+ cfReviewBlocker: '存在阻断级问题。仍可部署,但请确认这些内容确实要公开。',
699
+ cfReviewNone: '未发现明显问题',
700
+ cfNeedWorker: '请填写 Worker 名',
701
+ cfSource: '关联仓库',
702
+ cfBranch: '分支',
703
+ gitDirPick: '选择目录',
704
+ gitDirChange: '更换目录',
705
+ gitDirReset: '跟随会话',
706
+ gitDirPicked: '已指定',
707
+ gitDirNone: '未选择目录',
708
+ tabNotRepoHint: '如果 Git 仓库在子目录里,可以用「选择目录」直接指过去。',
709
+
644
710
  /* contract error codes */
645
711
  errForbidden: '请求被拒绝(缺少插件校验头)',
646
712
  errBadRequest: '请求参数不正确',
@@ -1221,6 +1287,71 @@ window.__ModuleLoader__.load({
1221
1287
  relYesterday: 'yesterday',
1222
1288
  relDays: '{n} d ago',
1223
1289
 
1290
+ cfSection: 'Cloudflare',
1291
+ cfAuthGlobal: 'Global API Key (full access)',
1292
+ cfAuthToken: 'API Token (scoped)',
1293
+ cfAuthGlobalShort: 'Global API Key',
1294
+ cfAuthTokenShort: 'API Token',
1295
+ cfTokenPlaceholder: 'Paste a Cloudflare API Token',
1296
+ cfKeyPlaceholder: 'cfk_... or legacy hex',
1297
+ cfEmailPlaceholder: 'Cloudflare account email',
1298
+ cfGlobalHint: 'A Global API Key carries every account permission — just email + key. Get it under My Profile › API Tokens, bottom section (new keys start with cfk_).',
1299
+ cfAdd: 'Add account',
1300
+ cfCurrent: 'Current',
1301
+ cfSwitch: 'Switch',
1302
+ cfRemove: 'Remove',
1303
+ cfTokenHint: 'The token needs Account:Read, Workers Scripts:Edit, Pages:Edit, Zone:Read and similar permission groups',
1304
+ cfTokenPage: 'Create a token on Cloudflare',
1305
+ cfNoAccountHint: 'Add a Cloudflare API Token or Global API Key in Settings',
1306
+ cfOverviewTitle: 'Project overview',
1307
+ cfOverviewPages: 'Pages projects',
1308
+ cfOverviewWorkers: 'Workers',
1309
+ cfOverviewZones: 'Zones',
1310
+ cfOverviewLoading: 'Reading overview…',
1311
+ cfSelectAccount: 'Choose account',
1312
+ cfSelectAccountHint: 'A credential can belong to several accounts — pick the current one',
1313
+ cfProjectsTitle: 'Pages projects',
1314
+ cfWorkersTitle: 'Workers',
1315
+ cfZonesTitle: 'Zones',
1316
+ cfOpenDash: 'Open in dashboard',
1317
+ cfEmpty: 'No data',
1318
+ cfNeedAccount: 'Sign in to Cloudflare first',
1319
+ cfNoAccountLong: 'Add a Cloudflare API Token or Global API Key under Settings › DevDock › Cloudflare.',
1320
+ cfNewProject: 'New project',
1321
+ cfNewProjectHint: 'The name becomes the default <name>.pages.dev site; add a custom domain in the dashboard later.',
1322
+ cfProjectName: 'Project name',
1323
+ cfCreate: 'Create',
1324
+ cfDelete: 'Delete',
1325
+ cfDeleteConfirm: 'Confirm delete',
1326
+ cfDeployTitle: 'Deploy',
1327
+ cfDetecting: 'Detecting folder…',
1328
+ cfDetectPages: 'Detected a Pages static site',
1329
+ cfDetectWorker: 'Detected a Worker project',
1330
+ cfDetectNone: 'This folder is neither a Pages static build nor a Worker project',
1331
+ cfNeedDir: 'Choose a folder first',
1332
+ cfNeedDirHint: 'Deploying reads the build output or Worker source from this folder. Use Choose folder above.',
1333
+ cfPickProject: 'Pick a Pages project…',
1334
+ cfBranchOptional: 'Branch (optional, defaults to production)',
1335
+ cfDeployAction: 'Deploy',
1336
+ cfDeploying: 'Deploying…',
1337
+ cfDeployedPages: 'Pages deployment finished',
1338
+ cfDeployedWorker: 'Worker deployment finished',
1339
+ cfDeployUrl: 'URL',
1340
+ cfDeployOpenDash: 'Open in dashboard',
1341
+ cfReviewOpen: 'Pre-deploy review',
1342
+ cfReviewHint: 'Review the files that would be uploaded before deploying. Secret scanning always runs; model review is optional.',
1343
+ cfReviewBlocker: 'Blocking issues found. You can still deploy, but make sure this content is meant to be public.',
1344
+ cfReviewNone: 'No problems found',
1345
+ cfNeedWorker: 'Enter a Worker name',
1346
+ cfSource: 'Linked repo',
1347
+ cfBranch: 'Branch',
1348
+ gitDirPick: 'Choose folder',
1349
+ gitDirChange: 'Change folder',
1350
+ gitDirReset: 'Follow session',
1351
+ gitDirPicked: 'Pinned',
1352
+ gitDirNone: 'No folder chosen',
1353
+ tabNotRepoHint: 'If the repository lives in a subfolder, point this panel at it with Choose folder.',
1354
+
1224
1355
  errForbidden: 'Request rejected (missing plugin header)',
1225
1356
  errBadRequest: 'Invalid request parameters',
1226
1357
  errNotFound: 'Not found',
@@ -2188,6 +2319,8 @@ window.__ModuleLoader__.load({
2188
2319
  color: var(--dsw-alias-label-primary); }
2189
2320
  /* 菜单浮在内容之上,不挤压布局。 */
2190
2321
  /* 菜单是浮层,父级不能裁。tab-head / page-head 都可能有 overflow。 */
2322
+ .dsh-push-tab-dirbar { flex: none; padding: 6px var(--dsh-push-pad-x);
2323
+ border-bottom: 1px solid var(--dsw-alias-border-l1); }
2191
2324
  .dsh-push-tab-head, .dsh-push-page-head { overflow: visible; }
2192
2325
  /* 头部里的切换器是定位基准。 */
2193
2326
  .dsh-push-tab-head .dsh-push-pswitch,
@@ -2498,6 +2631,36 @@ window.__ModuleLoader__.load({
2498
2631
  color: var(--dsw-alias-label-primary); }
2499
2632
  .dsh-push-assetlist { display: flex; flex-direction: column; gap: 4px; font-size: 11px; }
2500
2633
  .dsh-push-assetrow { display: flex; align-items: center; gap: 6px; }
2634
+
2635
+ /* ── Cloudflare 模块 ───────────────────────────────────────────────── */
2636
+ .dsh-push-cf-accounts { display: flex; flex-direction: column; gap: 8px; }
2637
+ .dsh-push-acc-cards { display: flex; flex-direction: column; gap: 8px; }
2638
+ .dsh-push-row-main { display: flex; align-items: center; gap: 8px; flex: 1 1 auto;
2639
+ min-width: 0; overflow: hidden; }
2640
+ .dsh-push-row-main > * { min-width: 0; }
2641
+ .dsh-push-cf-overview-grid { display: grid; grid-template-columns: repeat(3, 1fr);
2642
+ gap: 10px; padding: 4px 0 2px; }
2643
+ .dsh-push-cf-overview-cell { display: flex; flex-direction: column; gap: 2px;
2644
+ padding: 12px 10px; border: 1px solid var(--dsw-alias-border-l1);
2645
+ border-radius: 10px; background: var(--dsw-alias-bg-subtle); }
2646
+ .dsh-push-cf-overview-value { font-size: 20px; font-weight: 700;
2647
+ color: var(--dsw-alias-label-primary); font-variant-numeric: tabular-nums; }
2648
+ .dsh-push-cf-overview-label { font-size: 11px; color: var(--dsw-alias-label-secondary); }
2649
+ .dsh-push-cf-picker { display: flex; align-items: center; gap: 6px; }
2650
+ .dsh-push-cf-picker .dsh-push-select { min-width: 150px; }
2651
+ .dsh-push-cf-kind { font-size: 12px; color: var(--dsw-alias-label-secondary);
2652
+ padding: 4px 0 2px; }
2653
+ .dsh-push-cf-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
2654
+ font-size: 11px; opacity: .8; padding-top: 2px; }
2655
+ .dsh-push-cf-deploy-url { display: flex; align-items: center; gap: 6px;
2656
+ font-size: 11px; padding: 2px 0; }
2657
+ .dsh-push-cf-deploy-url a { color: var(--dsw-alias-brand-primary); text-decoration: none;
2658
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2659
+ .dsh-push-cf-deploy-url a:hover { text-decoration: underline; }
2660
+ .dsh-push-cf-review { display: flex; flex-direction: column; gap: 8px; }
2661
+ .dsh-push-linklike { background: none; border: none; padding: 0; cursor: pointer;
2662
+ color: var(--dsw-alias-brand-primary); font-size: 11px; }
2663
+ .dsh-push-linklike:hover { text-decoration: underline; }
2501
2664
  `;
2502
2665
 
2503
2666
  /** One <style> element in document.head; no client.css route is owned here. */
@@ -5221,6 +5384,14 @@ window.__ModuleLoader__.load({
5221
5384
  h(NpmSection, { ctx })));
5222
5385
  }
5223
5386
 
5387
+ if (platform === 'cloudflare') {
5388
+ return h('div', { className: 'dsh-push-root dsh-push-settings', style: densityStyle(density) },
5389
+ h('div', { className: 'dsh-push-settings-head' },
5390
+ h(PlatformSwitcher, { value: platform, onChange: switchPlatform, variant: 'settings' })),
5391
+ h('div', { className: 'dsh-push-settings-body' },
5392
+ h(CloudflareSection, { ctx })));
5393
+ }
5394
+
5224
5395
  return h('div', { className: 'dsh-push-root dsh-push-settings', style: densityStyle(density) },
5225
5396
  // GitHub 的一页,顶部同样有平台切换器。
5226
5397
  h('div', { className: 'dsh-push-settings-head' },
@@ -5368,6 +5539,7 @@ window.__ModuleLoader__.load({
5368
5539
  const PLATFORMS = [
5369
5540
  { id: 'github', label: 'GitHub' },
5370
5541
  { id: 'npm', label: 'npm' },
5542
+ { id: 'cloudflare', label: 'Cloudflare' },
5371
5543
  ];
5372
5544
 
5373
5545
  /** 每个入口各自记住自己的平台:在设置页切到 npm 不该影响工作区标签页。 */
@@ -5381,17 +5553,41 @@ function writePlatform(surface, id) {
5381
5553
  }
5382
5554
 
5383
5555
 
5384
- /** npm 标记:品牌红底 + 三个字母,和 GitHub 的八爪猫一样是「可辨识的图标」。 */
5556
+ /**
5557
+ * npm 标记:官方品牌图标(红底圆角 + 白色 n)。
5558
+ *
5559
+ * 与 GithubMark / CloudflareMark 同一规则:可辨识、能缩到 14px 仍清楚。
5560
+ * PNG 已内嵌成 data URI,自包含、无外部依赖;红底白 n 在深浅主题下都成立。
5561
+ */
5562
+ const NPM_PNG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAEHElEQVR4nO3cW0ojUQBF0UQckmKc/4cRnZNNd6P4yKOMiUXdvda3CYVwdm5VIOvVBTxt7l4u8b5Qdrt9XJ/7Pc/yhgYPywzCj97A8GHZITjphYYPY4TgWy8wfBgrBFdT/9D4YRm+s9VJATB+WJapmz0aAOOHZZqy3YMBMH5YtmMb3hsA44cxHNryzgAYP4xl36a/BMD4YUy7tj35a0BgPB8C4NMfxvZ5404AEPYWAJ/+0PB+604AEPYvAD79oeV1804AECYAECYAELZ2/w9dTgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQJgAQdr0a2M3Ddu5LYADP95vVqJwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIOx67gvgv+f7TepfcfOwnfsScAKANrcAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAELZ+2ty9zH0RwDycACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACDs6nb7uJ77IoDf93f7TgAQJgAQJgBQD4DnANDyunknAAh7C4BTADS837oTAIR9CIBTAIzt88adACDsSwCcAmBMu7a98wQgAjCWfZveewsgAjCGQ1s++AxABGDZjm346ENAEYBlmrLdSd8CiAAsy9TNTv4aUARgGb6z1ZN+DORpc/dyyuuAyznlQ/pHvwYkBDC/n5zOz/JzYEIAv+8ct+UX+T1AQYDV2V3iOdwf+quD+kvYR1cAAAAASUVORK5CYII=';
5563
+
5385
5564
  function NpmMark(props) {
5386
- const size = (props && props.size) || 16;
5387
- return h('span', {
5388
- className: 'dsh-push-npm-mark',
5389
- style: {
5390
- width: size + 'px',
5391
- height: size + 'px',
5392
- fontSize: Math.max(6, Math.round(size * 0.46)) + 'px',
5393
- },
5394
- }, 'npm');
5565
+ const px = (props && props.size) || 16;
5566
+ return h('img', {
5567
+ src: NPM_PNG,
5568
+ width: px,
5569
+ height: px,
5570
+ alt: 'npm',
5571
+ style: { display: 'block', flex: 'none', objectFit: 'contain' },
5572
+ });
5573
+ }
5574
+
5575
+ /**
5576
+ * Cloudflare 标记:内嵌的官方图标 PNG(32×32 RGBA)。
5577
+ *
5578
+ * 与 GithubMark / NpmMark 同一规则:可辨识、随主题可读、无外部依赖。
5579
+ */
5580
+ const CLOUDFLARE_PNG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAA65JREFUWIXtlV1oHFUUx3/3zuzsZ5pmm2xSU20qRKUSjQSsRakx1CJKxJZWRalVUCFWREGK2jcfAvqgWKw+iMlLhQoitvRF0TZECgWL2IdCS7UByZdpPjbJ7szsfNzrwyZmbbJLAvXjYX8w3JkL95z/Pf9zGKhSpcp/jPgHzut/SUB34tXO0Vt2dMTqY0oaUzOuffCUNWJPnh1bi4i1ChCwNTL0QXRPSzzXQxBuIWKm0VqitUuoRjHig+KVxLvw0wSgbqQAAXfW6d7wMCm3B0/H8BDaKwkUByIo4tbVH4bSL+98P/4jDASVghqrz39/jT4ydxTTewlbW3kH4YfgU/IEYBQQkjB9a8btWp+SZ769ODZeKaqsfONdSehMAfKL5ya70P4ebC3zhfKHXCDIA/mg+fWd6gh0RisJKGNBS0x/lHwH030YpcXIfPxsc1x1UbDb826lcEskAdIivDBS+0z7exe+okw/mMu37krqT9zPCXJ7sTFQ0Gzk7sWFSje/Hh+IFLS4ewNPQuzcfZ1PyHMDx68BDsUp0SsJEP3P+m3gP4KNUXLbNY+rBFBwJW9c1acf6iPh3Iza/ce1KdWf6T5xnKJbelkPDI/l1uGoZLDKUpfDiKOxjNnD54PTmLKDebeVXPaBhrrgMz24uw8SG2GpAhLuaZrvdV5MWuJRPFtWqra1sAqWSrP4LiwggiaK/fOvsbe2NLg+EZHA9gQeENgGiXCfHuxKiB2nnhew1brUKx6/PW1/jKPqKSB9F+EtZhNCx4yIMqJSI+RiNoVQIRoFOkSrEE1xlSrAktP5fLw/9fbFT2sbGzdmv97ejx+04XhRQmUiQ4t1SffyJX1A9O1v3fbCtuAEjmoM80Vj/oa0RgdmGr5BmF5oGr7vGV4+0IW8HbhzBeXaPu7EbOiOZT1nciawh7K/Z0cnpoeAcYqNJoFNvYe6H2ytr9/cHJ9r6WjK7rNqdYraDWeEPnrbl7iFveE8ciXbo4Ah0KJc3XXJnkQTkyGe1SfeuPwaEPNPPtZjNlhvkp9N42lBCLgIksBNTYHJuppuvIIwoguzq0uC/2XDwtf1s6BL9jSgEPhKkiwcqInWfzj3fdshYnI/OcdE6WIUA0gAEUB4pgn2OJG1/ULLIii2tTCcg0/fkWJ9bTtuOIxpAPGl7kVpTANq6ubMY8Ny18ljIcOrGDshRFmhBYA5yGQgdPC++y0xnTGzT52/osTo1C/Lzm1ujOlNme1eqaM3kpWMrFKlyv+TPwEkF4Sv0tp2CgAAAABJRU5ErkJggg==';
5581
+
5582
+ function CloudflareMark(props) {
5583
+ const px = (props && props.size) || 16;
5584
+ return h('img', {
5585
+ src: CLOUDFLARE_PNG,
5586
+ width: px,
5587
+ height: px,
5588
+ alt: 'Cloudflare',
5589
+ style: { display: 'block', flex: 'none', objectFit: 'contain' },
5590
+ });
5395
5591
  }
5396
5592
 
5397
5593
  /**
@@ -5435,6 +5631,7 @@ function PlatformMark(props) {
5435
5631
  const id = props && props.id;
5436
5632
  const size = (props && props.size) || 14;
5437
5633
  if (id === 'npm') return h(NpmMark, { size });
5634
+ if (id === 'cloudflare') return h(CloudflareMark, { size });
5438
5635
  return h(GithubMark, { size });
5439
5636
  }
5440
5637
 
@@ -7577,6 +7774,832 @@ function NpmProjectPanel(props) {
7577
7774
  }));
7578
7775
  }
7579
7776
 
7777
+ /* ───────────── Cloudflare 模块:账号卡片 + 概览 ───────────── */
7778
+
7779
+ /** 由 CloudflareAccountCards 等刷新。 */
7780
+ const cloudflareAccountCache = [];
7781
+
7782
+ /**
7783
+ * Cloudflare 账号卡片(设置页用)。
7784
+ *
7785
+ * 两种登录方式:Global API Key(邮箱 + Key,全权限免勾选)与 API Token
7786
+ * (可细粒度,需勾权限)。默认 Global Key —— 用户不必逐个勾权限组。
7787
+ *
7788
+ * @param {{ctx: object, onChanged?: () => void}} props
7789
+ */
7790
+ function CloudflareAccountCards(props) {
7791
+ const ctx = props.ctx;
7792
+ const [data, setData] = useState(null);
7793
+ const [adding, setAdding] = useState(false);
7794
+ const [authKind, setAuthKind] = useState(() => readViewPref('cf.authKind', 'global'));
7795
+ const [token, setToken] = useState('');
7796
+ const [email, setEmail] = useState('');
7797
+ const [busy, setBusy] = useState('');
7798
+ const [error, setError] = useState('');
7799
+ const aliveRef = useRef(true);
7800
+
7801
+ useEffect(() => {
7802
+ aliveRef.current = true;
7803
+ return () => { aliveRef.current = false; };
7804
+ }, []);
7805
+
7806
+ const load = useCallback(async () => {
7807
+ try {
7808
+ const next = await api(ctx, API + '/cf/accounts');
7809
+ cloudflareAccountCache.length = 0;
7810
+ if (next && Array.isArray(next.accounts)) cloudflareAccountCache.push(...next.accounts);
7811
+ if (aliveRef.current) setData(next || { accounts: [], activeId: null });
7812
+ } catch (err) {
7813
+ if (aliveRef.current) setError(err.message);
7814
+ }
7815
+ }, [ctx]);
7816
+
7817
+ useEffect(() => { load(); }, [load]);
7818
+
7819
+ const run = async (label, action) => {
7820
+ setBusy(label);
7821
+ setError('');
7822
+ try {
7823
+ await action();
7824
+ await load();
7825
+ if (typeof props.onChanged === 'function') props.onChanged();
7826
+ } catch (err) {
7827
+ if (aliveRef.current) setError(err.message);
7828
+ } finally {
7829
+ if (aliveRef.current) setBusy('');
7830
+ }
7831
+ };
7832
+
7833
+ const add = () => run('add', async () => {
7834
+ const value = String(token || '').trim();
7835
+ const mail = String(email || '').trim();
7836
+ if (value === '') return;
7837
+ if (authKind === 'global' && mail === '') return;
7838
+ const body = authKind === 'global'
7839
+ ? { authKind: 'global', email: mail, key: value }
7840
+ : { authKind: 'token', token: value };
7841
+ await api(ctx, API + '/cf/account', { method: 'POST', body });
7842
+ if (aliveRef.current) { setToken(''); setEmail(''); setAdding(false); }
7843
+ });
7844
+
7845
+ const list = (data && data.accounts) || [];
7846
+ const activeId = data ? data.activeId : null;
7847
+
7848
+ const tokenField = h('input', {
7849
+ className: 'dsh-push-input dsh-push-acc-token',
7850
+ type: 'password',
7851
+ value: token,
7852
+ placeholder: authKind === 'global' ? t('cfKeyPlaceholder') : t('cfTokenPlaceholder'),
7853
+ spellCheck: false,
7854
+ onChange: (e) => setToken(e.target.value),
7855
+ });
7856
+
7857
+ const kindSwitch = h('div', { className: 'dsh-push-inline' },
7858
+ h(Btn, {
7859
+ mini: true,
7860
+ active: authKind === 'global',
7861
+ onClick: () => { setAuthKind('global'); writeViewPref('cf.authKind', 'global'); },
7862
+ }, t('cfAuthGlobal')),
7863
+ h(Btn, {
7864
+ mini: true,
7865
+ active: authKind === 'token',
7866
+ onClick: () => { setAuthKind('token'); writeViewPref('cf.authKind', 'token'); },
7867
+ }, t('cfAuthToken')));
7868
+
7869
+ const emailField = h('input', {
7870
+ className: 'dsh-push-input',
7871
+ type: 'email',
7872
+ value: email,
7873
+ placeholder: t('cfEmailPlaceholder'),
7874
+ spellCheck: false,
7875
+ onChange: (e) => setEmail(e.target.value),
7876
+ });
7877
+
7878
+ const addPanel = h('div', { className: 'dsh-push-acc-panel' },
7879
+ kindSwitch,
7880
+ authKind === 'global' ? emailField : null,
7881
+ tokenField,
7882
+ h('div', { className: 'dsh-push-hint' }, authKind === 'global' ? t('cfGlobalHint') : t('cfTokenHint')),
7883
+ h('div', { className: 'dsh-push-inline' },
7884
+ h(Btn, {
7885
+ kind: 'primary',
7886
+ disabled: busy === 'add' || token.trim() === '' || (authKind === 'global' && email.trim() === ''),
7887
+ onClick: add,
7888
+ }, t('cfAdd')),
7889
+ h(Btn, { disabled: Boolean(busy), onClick: () => { setAdding(false); setToken(''); setEmail(''); } }, t('cancel')),
7890
+ h('button', {
7891
+ type: 'button',
7892
+ className: 'dsh-push-linklike',
7893
+ onClick: () => { try { window.open('https://dash.cloudflare.com/profile/api-tokens', '_blank'); } catch { /* ignore */ } },
7894
+ }, t('cfTokenPage'))));
7895
+
7896
+ const addRow = h('button', {
7897
+ type: 'button',
7898
+ className: 'dsh-push-acc-addrow',
7899
+ onClick: () => setAdding(true),
7900
+ }, h(Icon, { name: 'plus', size: 12 }), t('cfAdd'));
7901
+
7902
+ const emptyCard = h('button', {
7903
+ type: 'button',
7904
+ className: 'dsh-push-acc-card dsh-push-acc-card--empty',
7905
+ onClick: () => setAdding(true),
7906
+ },
7907
+ h(CloudflareMark, { size: 20 }),
7908
+ h('span', { className: 'dsh-push-acc-card-empty' }, t('cfAdd')),
7909
+ h('span', { className: 'dsh-push-acc-card-hint' }, t('cfNoAccountHint')));
7910
+
7911
+ const accountCard = (account) => h('div', {
7912
+ key: account.id,
7913
+ className: 'dsh-push-acc-card',
7914
+ },
7915
+ h(CloudflareMark, { size: 22 }),
7916
+ h('div', { className: 'dsh-push-acc-card-main' },
7917
+ h('div', { className: 'dsh-push-acc-card-name' }, account.login),
7918
+ h('div', { className: 'dsh-push-acc-card-sub' },
7919
+ h('span', { className: 'dsh-push-acc-card-login' },
7920
+ account.authKind === 'global' ? t('cfAuthGlobalShort') : t('cfAuthTokenShort')),
7921
+ account.accountName
7922
+ ? h('span', { className: 'dsh-push-acc-card-login' }, account.accountName)
7923
+ : null,
7924
+ account.id === activeId
7925
+ ? h('span', { className: 'dsh-push-pill' }, t('cfCurrent'))
7926
+ : null)),
7927
+ h('div', { className: 'dsh-push-inline' },
7928
+ account.id === activeId
7929
+ ? null
7930
+ : h(Btn, {
7931
+ mini: true,
7932
+ disabled: Boolean(busy),
7933
+ onClick: () => run('switch', () => api(ctx, API + '/cf/account/active', {
7934
+ method: 'POST',
7935
+ body: { id: account.id },
7936
+ })),
7937
+ }, t('cfSwitch')),
7938
+ h('button', {
7939
+ type: 'button',
7940
+ className: 'dsh-push-iconbtn',
7941
+ title: t('cfRemove'),
7942
+ 'aria-label': t('cfRemove'),
7943
+ disabled: Boolean(busy),
7944
+ onClick: () => run('remove', () => api(ctx, API + '/cf/account/remove', {
7945
+ method: 'POST',
7946
+ body: { id: account.id },
7947
+ })),
7948
+ }, h(Icon, { name: 'close', size: 12 }))));
7949
+
7950
+ return h('div', { className: 'dsh-push-cf-accounts' },
7951
+ error ? h('div', { className: 'dsh-push-error' }, error) : null,
7952
+ list.length === 0
7953
+ ? (adding ? addPanel : emptyCard)
7954
+ : h('div', { className: 'dsh-push-acc-cards' },
7955
+ list.map(accountCard),
7956
+ adding ? addPanel : addRow));
7957
+ }
7958
+
7959
+ /**
7960
+ * 设置页的项目概览卡:Pages / Workers / Zones 三格计数。
7961
+ * @param {{ctx: object, reloadKey?: number}} props
7962
+ */
7963
+ function CloudflareOverviewCard(props) {
7964
+ const ctx = props.ctx;
7965
+ const [data, setData] = useState(null);
7966
+ const [error, setError] = useState('');
7967
+ const aliveRef = useRef(true);
7968
+
7969
+ useEffect(() => {
7970
+ aliveRef.current = true;
7971
+ return () => { aliveRef.current = false; };
7972
+ }, []);
7973
+
7974
+ const load = useCallback(async () => {
7975
+ setError('');
7976
+ try {
7977
+ const next = await api(ctx, API + '/cf/overview');
7978
+ if (aliveRef.current) setData(next);
7979
+ } catch (err) {
7980
+ if (aliveRef.current) setData(null);
7981
+ if (err.code !== 'NO_ACCOUNT' && aliveRef.current) setError(err.message);
7982
+ }
7983
+ }, [ctx]);
7984
+
7985
+ useEffect(() => { load(); }, [load, props.reloadKey]);
7986
+
7987
+ const cells = [
7988
+ { key: 'pages', label: t('cfOverviewPages'), value: data ? data.pages.count : null },
7989
+ { key: 'workers', label: t('cfOverviewWorkers'), value: data ? data.workers.count : null },
7990
+ { key: 'zones', label: t('cfOverviewZones'), value: data ? data.zones.count : null },
7991
+ ];
7992
+
7993
+ const body = data === null && error === ''
7994
+ ? h('div', { className: 'dsh-push-hint' }, t('cfOverviewLoading'))
7995
+ : h('div', { className: 'dsh-push-cf-overview-grid' },
7996
+ cells.map((cell) => h('div', { key: cell.key, className: 'dsh-push-cf-overview-cell' },
7997
+ h('div', { className: 'dsh-push-cf-overview-value' }, cell.value === null ? '—' : String(cell.value)),
7998
+ h('div', { className: 'dsh-push-cf-overview-label' }, cell.label))));
7999
+
8000
+ return h('div', { className: 'dsh-push-group' },
8001
+ h('div', { className: 'dsh-push-group-head' },
8002
+ h('span', null, t('cfOverviewTitle')),
8003
+ h(Btn, { mini: true, onClick: load }, t('refresh'))),
8004
+ error ? h('div', { className: 'dsh-push-error' }, error) : null,
8005
+ body);
8006
+ }
8007
+
8008
+ /**
8009
+ * 设置页的 Cloudflare 一页:账号卡片 + 项目概览。
8010
+ * @param {{ctx: object, reloadKey?: number}} props
8011
+ */
8012
+ function CloudflareSection(props) {
8013
+ const ctx = props.ctx;
8014
+ const [reloadKey, setReloadKey] = useState(0);
8015
+ return h('div', { className: 'dsh-push-npm-settings' },
8016
+ h(CloudflareAccountCards, { ctx, onChanged: () => setReloadKey((n) => n + 1) }),
8017
+ h(CloudflareOverviewCard, { ctx, reloadKey }));
8018
+ }
8019
+
8020
+ /**
8021
+ * Cloudflare 账户下拉(一个凭据可能属于多个账户)。
8022
+ * @param {{ctx: object, onChange?: () => void, onError?: (m: string) => void}} props
8023
+ */
8024
+ function CloudflareAccountPicker(props) {
8025
+ const ctx = props.ctx;
8026
+ const [accounts, setAccounts] = useState([]);
8027
+ const [activeAccountId, setActiveAccountId] = useState('');
8028
+ const [busy, setBusy] = useState(false);
8029
+
8030
+ const loadAccountList = useCallback(async () => {
8031
+ try {
8032
+ const next = await api(ctx, API + '/cf/accounts/list');
8033
+ if (next && Array.isArray(next.items)) setAccounts(next.items);
8034
+ if (next && next.activeAccountId) setActiveAccountId(next.activeAccountId);
8035
+ } catch { /* 保留旧值 */ }
8036
+ }, [ctx]);
8037
+
8038
+ useEffect(() => { loadAccountList(); }, [loadAccountList]);
8039
+
8040
+ const switchTo = async (accountId, accountName) => {
8041
+ if (!accountId) return;
8042
+ setBusy(true);
8043
+ try {
8044
+ await api(ctx, API + '/cf/account/select', { method: 'POST', body: { accountId, accountName } });
8045
+ setActiveAccountId(accountId);
8046
+ if (typeof props.onChange === 'function') props.onChange();
8047
+ } catch (err) {
8048
+ if (typeof props.onError === 'function') props.onError(err.message);
8049
+ } finally {
8050
+ setBusy(false);
8051
+ }
8052
+ };
8053
+
8054
+ if (accounts.length === 0) return null;
8055
+ return h('div', { className: 'dsh-push-cf-picker', title: t('cfSelectAccountHint') },
8056
+ h(CloudflareMark, { size: 14 }),
8057
+ h('span', { className: 'dsh-push-hint' }, t('cfSelectAccount')),
8058
+ h('select', {
8059
+ className: 'dsh-push-select',
8060
+ value: activeAccountId,
8061
+ disabled: busy,
8062
+ onChange: (e) => {
8063
+ const row = accounts.find((a) => a.id === e.target.value);
8064
+ switchTo(e.target.value, row ? row.name : '');
8065
+ },
8066
+ }, accounts.map((account) => h('option', {
8067
+ key: account.id,
8068
+ value: account.id,
8069
+ }, account.name || account.id))));
8070
+ }
8071
+
8072
+ /* ───────────── Cloudflare 左栏仪表盘 ───────────── */
8073
+
8074
+ /**
8075
+ * Cloudflare 面板(左栏 main 页):Pages / Workers / Zones 三块仪表盘。
8076
+ * @param {{ctx: object, reloadKey?: number}} props
8077
+ */
8078
+ function CloudflarePanel(props) {
8079
+ const ctx = props.ctx;
8080
+ const [tab, setTab] = useState('pages');
8081
+ const [projects, setProjects] = useState(null);
8082
+ const [workers, setWorkers] = useState(null);
8083
+ const [zones, setZones] = useState(null);
8084
+ const [accountId, setAccountId] = useState('');
8085
+ const [error, setError] = useState('');
8086
+ const [busy, setBusy] = useState('');
8087
+ const [loading, setLoading] = useState(true);
8088
+ const [needAccount, setNeedAccount] = useState(false);
8089
+ const [newOpen, setNewOpen] = useState(false);
8090
+ const [newName, setNewName] = useState('');
8091
+ const [deleteArm, setDeleteArm] = useState('');
8092
+ const aliveRef = useRef(true);
8093
+
8094
+ useEffect(() => {
8095
+ aliveRef.current = true;
8096
+ return () => { aliveRef.current = false; };
8097
+ }, []);
8098
+
8099
+ const load = useCallback(async () => {
8100
+ setError('');
8101
+ try {
8102
+ const [pages, workerData, zoneData] = await Promise.all([
8103
+ api(ctx, API + '/cf/projects'),
8104
+ api(ctx, API + '/cf/workers'),
8105
+ api(ctx, API + '/cf/zones'),
8106
+ ]);
8107
+ if (!aliveRef.current) return;
8108
+ setProjects(pages.items || []);
8109
+ setWorkers(workerData.items || []);
8110
+ setZones(zoneData.items || []);
8111
+ setAccountId(pages.accountId || workerData.accountId || '');
8112
+ setNeedAccount(false);
8113
+ } catch (err) {
8114
+ if (!aliveRef.current) return;
8115
+ if (err.code === 'NO_ACCOUNT') setNeedAccount(true);
8116
+ else setError(err.message);
8117
+ setProjects((prev) => prev ?? []);
8118
+ setWorkers((prev) => prev ?? []);
8119
+ setZones((prev) => prev ?? []);
8120
+ } finally {
8121
+ if (aliveRef.current) setLoading(false);
8122
+ }
8123
+ }, [ctx]);
8124
+
8125
+ useEffect(() => { setLoading(true); load(); }, [load, props.reloadKey]);
8126
+
8127
+ const refresh = async () => {
8128
+ setBusy('refresh');
8129
+ await load();
8130
+ if (aliveRef.current) setBusy('');
8131
+ };
8132
+
8133
+ const runAction = async (label, fn) => {
8134
+ setBusy(label);
8135
+ setError('');
8136
+ try {
8137
+ await fn();
8138
+ await load();
8139
+ } catch (err) {
8140
+ if (aliveRef.current) setError(err.message);
8141
+ } finally {
8142
+ if (aliveRef.current) setBusy('');
8143
+ }
8144
+ };
8145
+
8146
+ const createProject = () => {
8147
+ const name = newName.trim();
8148
+ if (!name) return;
8149
+ return runAction('create', async () => {
8150
+ await api(ctx, API + '/cf/projects/create', { method: 'POST', body: { name } });
8151
+ if (aliveRef.current) { setNewName(''); setNewOpen(false); }
8152
+ });
8153
+ };
8154
+
8155
+ const openDash = (path) => {
8156
+ try { window.open('https://dash.cloudflare.com/' + encodeURIComponent(accountId) + '/' + path, '_blank', 'noopener'); } catch { /* ignore */ }
8157
+ };
8158
+
8159
+ /** 一个资源行:主信息 + 副信息 + 右侧动作。 */
8160
+ const resourceRow = (key, title, subtitle, dashPath, extraActions) => h('div', { key, className: 'dsh-push-row' },
8161
+ h('div', { className: 'dsh-push-row-label' },
8162
+ h('div', { className: 'dsh-push-row-title dsh-push-mono', title }, title),
8163
+ subtitle ? h('div', { className: 'dsh-push-row-hint' }, subtitle) : null),
8164
+ h('div', { className: 'dsh-push-row-control' },
8165
+ extraActions || null,
8166
+ h(Btn, { mini: true, title: t('cfOpenDash'), onClick: () => openDash(dashPath) },
8167
+ h(Icon, { name: 'external', size: 11 }))));
8168
+
8169
+ const deleteButton = (kind, name) => h('button', {
8170
+ type: 'button',
8171
+ className: 'dsh-push-iconbtn',
8172
+ title: deleteArm === kind + ':' + name ? t('cfDeleteConfirm') : t('cfDelete'),
8173
+ 'aria-label': t('cfDelete'),
8174
+ disabled: Boolean(busy),
8175
+ onClick: () => {
8176
+ const armKey = kind + ':' + name;
8177
+ if (deleteArm !== armKey) { setDeleteArm(armKey); return; }
8178
+ setDeleteArm('');
8179
+ const route = kind === 'projects' ? '/cf/projects/delete' : '/cf/workers/delete';
8180
+ runAction('delete', () => api(ctx, API + route, {
8181
+ method: 'POST',
8182
+ body: { name, confirm: true },
8183
+ }));
8184
+ },
8185
+ }, h(Icon, { name: 'close', size: 12 }));
8186
+
8187
+ if (needAccount) {
8188
+ return h('div', { className: 'dsh-push-pickguide' },
8189
+ h(CloudflareMark, { size: 28 }),
8190
+ h('div', { className: 'dsh-push-pickguide-title' }, t('cfNeedAccount')),
8191
+ h('div', { className: 'dsh-push-pickguide-text' }, t('cfNoAccountLong')));
8192
+ }
8193
+
8194
+ if (loading) {
8195
+ return h('div', { className: 'dsh-push-skel', 'aria-hidden': 'true' },
8196
+ CONTRIB_SKELETON.map((row) => h('div', { key: row, className: 'dsh-push-skel-row' })));
8197
+ }
8198
+
8199
+ const tabOptions = [
8200
+ { value: 'pages', label: t('cfProjectsTitle') + (projects ? ' ' + projects.length : '') },
8201
+ { value: 'workers', label: t('cfWorkersTitle') + (workers ? ' ' + workers.length : '') },
8202
+ { value: 'zones', label: t('cfZonesTitle') + (zones ? ' ' + zones.length : '') },
8203
+ ];
8204
+
8205
+ const pagesList = (projects || []).length === 0
8206
+ ? h('div', { className: 'dsh-push-hint' }, t('cfEmpty'))
8207
+ : h('div', { className: 'dsh-push-rows' }, projects.map((p) => {
8208
+ const sub = [
8209
+ p.latestUrl ? p.latestUrl : null,
8210
+ p.repoName ? p.repoOwner + '/' + p.repoName : null,
8211
+ ].filter(Boolean).join(' · ');
8212
+ return resourceRow(p.name, p.name, sub, 'workers-and-pages/view/pages/' + p.name, deleteButton('projects', p.name));
8213
+ }));
8214
+
8215
+ const workersList = (workers || []).length === 0
8216
+ ? h('div', { className: 'dsh-push-hint' }, t('cfEmpty'))
8217
+ : h('div', { className: 'dsh-push-rows' }, workers.map((w) => resourceRow(
8218
+ w.name, w.name, relativeTime(w.modifiedOn), 'workers/view/' + w.name,
8219
+ deleteButton('workers', w.name),
8220
+ )));
8221
+
8222
+ const zonesList = (zones || []).length === 0
8223
+ ? h('div', { className: 'dsh-push-hint' }, t('cfEmpty'))
8224
+ : h('div', { className: 'dsh-push-rows' }, zones.map((z) => resourceRow(
8225
+ z.id, z.name, z.status, 'zones/' + z.id, null,
8226
+ )));
8227
+
8228
+ const newModal = newOpen
8229
+ ? h(Modal, {
8230
+ open: true,
8231
+ onClose: () => { setNewOpen(false); setNewName(''); },
8232
+ title: t('cfNewProject'),
8233
+ footer: [
8234
+ h(Btn, { key: 'create', kind: 'primary', disabled: busy === 'create' || newName.trim() === '', onClick: createProject }, t('cfCreate')),
8235
+ h(Btn, { key: 'close', onClick: () => { setNewOpen(false); setNewName(''); } }, t('cancel')),
8236
+ ],
8237
+ },
8238
+ h('div', { className: 'dsh-push-form' },
8239
+ h('input', {
8240
+ className: 'dsh-push-input',
8241
+ value: newName,
8242
+ placeholder: t('cfProjectName'),
8243
+ spellCheck: false,
8244
+ onChange: (e) => setNewName(e.target.value),
8245
+ }),
8246
+ h('div', { className: 'dsh-push-hint' }, t('cfNewProjectHint'))))
8247
+ : null;
8248
+
8249
+ return h('div', null,
8250
+ h('div', { className: 'dsh-push-group' },
8251
+ h('div', { className: 'dsh-push-group-head' },
8252
+ h('span', null, t('cfOverviewTitle')),
8253
+ h('div', { className: 'dsh-push-inline' },
8254
+ tab === 'pages'
8255
+ ? h(Btn, { mini: true, disabled: Boolean(busy), onClick: () => setNewOpen(true) }, t('cfNewProject'))
8256
+ : null,
8257
+ h(Btn, { mini: true, disabled: Boolean(busy), onClick: refresh }, busy ? t('loading') : t('refresh')))),
8258
+ h(CloudflareAccountPicker, { ctx, onError: setError, onChange: refresh }),
8259
+ error ? h('div', { className: 'dsh-push-error' }, error) : null,
8260
+ h('div', { className: 'dsh-push-modal-tabs' }, h(TabRow, { options: tabOptions, value: tab, onChange: setTab })),
8261
+ tab === 'pages' ? pagesList : (tab === 'workers' ? workersList : zonesList)),
8262
+ newModal);
8263
+ }
8264
+
8265
+ /* ───────────── Cloudflare 工作区标签页(部署) ───────────── */
8266
+
8267
+ /**
8268
+ * 工作区标签页的 Cloudflare 一页:项目级部署。
8269
+ * @param {{ctx: object, scope?: {cwd: string, repoRoot?: string}}} props
8270
+ */
8271
+ function CloudflareWorkspaceTab(props) {
8272
+ const ctx = props.ctx;
8273
+ const cwd = (props.scope && (props.scope.repoRoot || props.scope.cwd)) || '';
8274
+ const [kind, setKind] = useState(null);
8275
+ const [detecting, setDetecting] = useState(false);
8276
+ const [projects, setProjects] = useState(null);
8277
+ const [project, setProject] = useState('');
8278
+ const [workerName, setWorkerName] = useState('');
8279
+ const [branch, setBranch] = useState('');
8280
+ const [busy, setBusy] = useState('');
8281
+ const [error, setError] = useState('');
8282
+ const [result, setResult] = useState(null);
8283
+ const [reviewOpen, setReviewOpen] = useState(false);
8284
+ const [notice, setNotice] = useState('');
8285
+ const aliveRef = useRef(true);
8286
+
8287
+ useEffect(() => {
8288
+ aliveRef.current = true;
8289
+ return () => { aliveRef.current = false; };
8290
+ }, []);
8291
+
8292
+ useEffect(() => {
8293
+ if (!notice) return undefined;
8294
+ const id = setTimeout(() => { if (aliveRef.current) setNotice(''); }, TOAST_MS);
8295
+ return () => clearTimeout(id);
8296
+ }, [notice]);
8297
+
8298
+ const detect = useCallback(async () => {
8299
+ if (!cwd) return;
8300
+ setDetecting(true);
8301
+ setError('');
8302
+ try {
8303
+ const data = await api(ctx, API + '/cf/detect?path=' + encodeURIComponent(cwd));
8304
+ if (aliveRef.current) setKind(data && data.kind ? data.kind.type : null);
8305
+ } catch (err) {
8306
+ if (aliveRef.current) { setError(err.message); setKind(null); }
8307
+ } finally {
8308
+ if (aliveRef.current) setDetecting(false);
8309
+ }
8310
+ }, [ctx, cwd]);
8311
+
8312
+ const loadProjects = useCallback(async () => {
8313
+ try {
8314
+ const data = await api(ctx, API + '/cf/projects');
8315
+ if (!aliveRef.current) return;
8316
+ const items = data.items || [];
8317
+ setProjects(items);
8318
+ if (items.length === 1) setProject(items[0].name);
8319
+ } catch (err) {
8320
+ if (aliveRef.current && err.code !== 'NO_ACCOUNT') setError(err.message);
8321
+ if (aliveRef.current) setProjects([]);
8322
+ }
8323
+ }, [ctx]);
8324
+
8325
+ useEffect(() => { detect(); loadProjects(); }, [detect, loadProjects]);
8326
+
8327
+ const deploy = async () => {
8328
+ setBusy('deploy');
8329
+ setError('');
8330
+ setResult(null);
8331
+ try {
8332
+ const body = {
8333
+ path: cwd,
8334
+ kind,
8335
+ project: kind === 'pages' ? project.trim() : undefined,
8336
+ name: kind === 'worker' ? workerName.trim() : undefined,
8337
+ branch: kind === 'pages' && branch.trim() !== '' ? branch.trim() : undefined,
8338
+ };
8339
+ const data = await api(ctx, API + '/cf/deploy', { method: 'POST', body });
8340
+ if (aliveRef.current) setResult(data);
8341
+ } catch (err) {
8342
+ if (aliveRef.current) setError(err.message);
8343
+ } finally {
8344
+ if (aliveRef.current) setBusy('');
8345
+ }
8346
+ };
8347
+
8348
+ const copyUrl = async (url) => {
8349
+ const ok = await copyText(url);
8350
+ if (aliveRef.current) setNotice(ok ? t('copied') : t('copyFailed'));
8351
+ };
8352
+
8353
+ if (!cwd) {
8354
+ return h('div', { className: 'dsh-push-pickguide' },
8355
+ h(CloudflareMark, { size: 28 }),
8356
+ h('div', { className: 'dsh-push-pickguide-title' }, t('cfNeedDir')),
8357
+ h('div', { className: 'dsh-push-pickguide-text' }, t('cfNeedDirHint')));
8358
+ }
8359
+
8360
+ const kindHint = detecting
8361
+ ? h('div', { className: 'dsh-push-hint' }, t('cfDetecting'))
8362
+ : kind === 'pages'
8363
+ ? h('div', { className: 'dsh-push-cf-kind' }, t('cfDetectPages'))
8364
+ : kind === 'worker'
8365
+ ? h('div', { className: 'dsh-push-cf-kind' }, t('cfDetectWorker'))
8366
+ : h('div', { className: 'dsh-push-hint' }, t('cfDetectNone'));
8367
+
8368
+ const projectSelect = kind === 'pages' && projects && projects.length > 0
8369
+ ? h('select', {
8370
+ className: 'dsh-push-select',
8371
+ value: project,
8372
+ onChange: (e) => setProject(e.target.value),
8373
+ },
8374
+ h('option', { value: '' }, t('cfPickProject')),
8375
+ projects.map((p) => h('option', { key: p.name, value: p.name }, p.name)))
8376
+ : null;
8377
+
8378
+ const deployForm = kind === null
8379
+ ? null
8380
+ : h('div', { className: 'dsh-push-group' },
8381
+ kind === 'pages'
8382
+ ? (projectSelect || h('input', {
8383
+ className: 'dsh-push-input',
8384
+ value: project,
8385
+ placeholder: t('cfProjectName'),
8386
+ spellCheck: false,
8387
+ onChange: (e) => setProject(e.target.value),
8388
+ }))
8389
+ : h('input', {
8390
+ className: 'dsh-push-input',
8391
+ value: workerName,
8392
+ placeholder: t('cfNeedWorker'),
8393
+ spellCheck: false,
8394
+ onChange: (e) => setWorkerName(e.target.value),
8395
+ }),
8396
+ kind === 'pages'
8397
+ ? h('input', {
8398
+ className: 'dsh-push-input',
8399
+ value: branch,
8400
+ placeholder: t('cfBranchOptional'),
8401
+ spellCheck: false,
8402
+ onChange: (e) => setBranch(e.target.value),
8403
+ })
8404
+ : null,
8405
+ h('div', { className: 'dsh-push-inline' },
8406
+ h(Btn, {
8407
+ kind: 'primary',
8408
+ disabled: Boolean(busy) || (kind === 'pages' && project.trim() === '') || (kind === 'worker' && workerName.trim() === ''),
8409
+ onClick: deploy,
8410
+ }, busy === 'deploy' ? t('cfDeploying') : t('cfDeployAction')),
8411
+ h(Btn, { disabled: Boolean(busy), onClick: () => setReviewOpen(true) }, t('cfReviewOpen'))));
8412
+
8413
+ const deployUrl = result
8414
+ ? (result.kind === 'pages' ? (result.deployment && result.deployment.url) : result.url)
8415
+ : '';
8416
+
8417
+ const resultBlock = result
8418
+ ? h('div', { className: 'dsh-push-group' },
8419
+ h('div', { className: 'dsh-push-group-head' },
8420
+ h('span', null, result.kind === 'pages' ? t('cfDeployedPages') : t('cfDeployedWorker'))),
8421
+ deployUrl
8422
+ ? h('div', { className: 'dsh-push-cf-deploy-url' },
8423
+ h('a', {
8424
+ href: deployUrl,
8425
+ target: '_blank',
8426
+ rel: 'noopener',
8427
+ className: 'dsh-push-mono',
8428
+ title: deployUrl,
8429
+ }, deployUrl),
8430
+ h(Btn, { mini: true, onClick: () => copyUrl(deployUrl) }, t('copy')))
8431
+ : null,
8432
+ result.dashUrl
8433
+ ? h('div', { className: 'dsh-push-inline' },
8434
+ h(Btn, { mini: true, onClick: () => { try { window.open(result.dashUrl, '_blank', 'noopener'); } catch { /* ignore */ } } }, t('cfDeployOpenDash')))
8435
+ : null)
8436
+ : null;
8437
+
8438
+ return h('div', null,
8439
+ h('div', { className: 'dsh-push-group' },
8440
+ h('div', { className: 'dsh-push-group-head' },
8441
+ h('span', null, t('cfDeployTitle')),
8442
+ h(Btn, { mini: true, disabled: detecting, onClick: () => { detect(); loadProjects(); } },
8443
+ detecting ? t('cfDetecting') : t('refresh'))),
8444
+ kindHint,
8445
+ h('div', { className: 'dsh-push-hint dsh-push-cf-path', title: cwd }, cwd)),
8446
+ deployForm,
8447
+ resultBlock,
8448
+ notice ? h('div', { className: 'dsh-push-hint' }, notice) : null,
8449
+ error ? h('div', { className: 'dsh-push-error' }, error) : null,
8450
+ h(CloudflareReviewDialog, {
8451
+ open: reviewOpen,
8452
+ ctx,
8453
+ cwd,
8454
+ kind,
8455
+ onClose: () => setReviewOpen(false),
8456
+ onReviewed: () => {},
8457
+ }));
8458
+ }
8459
+
8460
+ /**
8461
+ * 部署前审查弹窗(Cloudflare 版)。
8462
+ * @param {{ctx: object, open: boolean, cwd: string, kind: string|null,
8463
+ * onClose: () => void, onReviewed?: (data: object) => void}} props
8464
+ */
8465
+ function CloudflareReviewDialog(props) {
8466
+ const ctx = props.ctx;
8467
+ const [running, setRunning] = useState(false);
8468
+ const [result, setResult] = useState(null);
8469
+ const [error, setError] = useState('');
8470
+ const aliveRef = useRef(true);
8471
+
8472
+ useEffect(() => {
8473
+ aliveRef.current = true;
8474
+ return () => { aliveRef.current = false; };
8475
+ }, []);
8476
+
8477
+ useEffect(() => {
8478
+ if (props.open) { setResult(null); setError(''); }
8479
+ }, [props.open]);
8480
+
8481
+ if (!props.open) return null;
8482
+
8483
+ const run = async () => {
8484
+ setRunning(true);
8485
+ setError('');
8486
+ setResult(null);
8487
+ try {
8488
+ const data = await api(ctx, API + '/cf/review', {
8489
+ method: 'POST',
8490
+ body: { path: props.cwd, kind: props.kind || undefined },
8491
+ });
8492
+ if (aliveRef.current) {
8493
+ setResult(data);
8494
+ if (typeof props.onReviewed === 'function') props.onReviewed(data);
8495
+ }
8496
+ } catch (err) {
8497
+ if (aliveRef.current) setError(err.message);
8498
+ } finally {
8499
+ if (aliveRef.current) setRunning(false);
8500
+ }
8501
+ };
8502
+
8503
+ const findings = result ? result.findings || [] : [];
8504
+ const blockers = findings.filter((f) => f.severity === 'blocker').length;
8505
+
8506
+ const body = running
8507
+ ? h('div', { className: 'dsh-push-hint' }, t('rvRunning'))
8508
+ : result
8509
+ ? h('div', { className: 'dsh-push-cf-review' },
8510
+ blockers > 0 ? h('div', { className: 'dsh-push-error' }, t('cfReviewBlocker')) : null,
8511
+ findings.length === 0
8512
+ ? h('div', { className: 'dsh-push-hint' }, t('cfReviewNone'))
8513
+ : h('div', { className: 'dsh-push-rv-findings' },
8514
+ findings.map((f, i) => h('div', { key: i, className: 'dsh-push-rv-finding' },
8515
+ h('span', { className: 'dsh-push-rv-sev dsh-push-rv-sev--' + f.severity },
8516
+ h('span', { className: 'dsh-push-rv-dot' }),
8517
+ t(SEVERITY_LABEL[f.severity] || 'rvSeverityInfo')),
8518
+ h('span', { className: 'dsh-push-rv-finding-body' },
8519
+ h('span', { className: 'dsh-push-rv-finding-head' },
8520
+ h('span', { className: 'dsh-push-rv-finding-title' }, f.title)),
8521
+ f.detail ? h('span', { className: 'dsh-push-rv-finding-detail' }, f.detail) : null,
8522
+ f.file ? h('span', { className: 'dsh-push-rv-finding-file' }, f.file) : null)))),
8523
+ h('div', { className: 'dsh-push-hint' }, result.summary))
8524
+ : h('div', { className: 'dsh-push-hint' }, t('cfReviewHint'));
8525
+
8526
+ return h(Modal, {
8527
+ open: true,
8528
+ onClose: props.onClose,
8529
+ title: t('cfReviewOpen'),
8530
+ footer: [
8531
+ h(Btn, { key: 'run', kind: 'primary', disabled: running, onClick: run }, running ? t('rvRunning') : t('pjRun')),
8532
+ h(Btn, { key: 'close', onClick: props.onClose }, t('close')),
8533
+ ],
8534
+ },
8535
+ error ? h('div', { className: 'dsh-push-error' }, error) : null,
8536
+ body);
8537
+ }
8538
+
8539
+ /* ───────────── Git 目录选择(工作区标签页) ───────────── */
8540
+
8541
+ /**
8542
+ * 目录条:显示当前 Git 面板指向哪个目录,并提供「选择目录 / 跟随会话」。
8543
+ *
8544
+ * 会话目录经常是「装了几个仓库的容器」,根目录没有 .git,Git 面板只会显示
8545
+ * 「不是仓库」。这条目录条把「换一个目录看」变成一次点击。
8546
+ *
8547
+ * @param {{dir: string, source: string, onPick: () => void, onClear: () => void,
8548
+ * compact?: boolean}} props
8549
+ */
8550
+ function DirPickerBar(props) {
8551
+ const dir = props.dir || '';
8552
+ const picked = props.source === 'picked';
8553
+ return h('div', { className: 'dsh-push-npm-dirbar' + (props.compact ? ' dsh-push-npm-dirbar--compact' : '') },
8554
+ h(Icon, { name: 'branch', size: 12 }),
8555
+ dir === ''
8556
+ ? h('span', { className: 'dsh-push-npm-dirbar-empty' }, t('gitDirNone'))
8557
+ : h('span', { className: 'dsh-push-npm-dirbar-path', title: dir }, dir),
8558
+ picked
8559
+ ? h('span', { className: 'dsh-push-pill dsh-push-pill--muted' }, t('gitDirPicked'))
8560
+ : null,
8561
+ h('span', { className: 'dsh-push-page-spacer' }),
8562
+ h(Btn, { mini: true, onClick: props.onPick },
8563
+ picked || dir === '' ? t('gitDirPick') : t('gitDirChange')),
8564
+ picked ? h(Btn, { mini: true, onClick: props.onClear }, t('gitDirReset')) : null);
8565
+ }
8566
+
8567
+ /**
8568
+ * Git 标签页使用的目录:默认跟随会话,选过之后以选中的为准。
8569
+ * @param {object} ctx
8570
+ * @param {string} scopeDir
8571
+ * @returns {{dir: string, override: string, pick: () => Promise<string>,
8572
+ * clear: () => void, source: 'scope'|'picked'|'none'}}
8573
+ */
8574
+ function useTabDir(ctx, scopeDir) {
8575
+ const [own, setOwn] = useState(() => readViewPref('gitDir', ''));
8576
+ const dir = own !== '' ? own : (scopeDir || '');
8577
+ const source = own !== '' ? 'picked' : (scopeDir ? 'scope' : 'none');
8578
+
8579
+ const pick = async () => {
8580
+ let chosen = null;
8581
+ try {
8582
+ const workspace = typeof ctx.get === 'function' ? ctx.get('uiWorkspace') : null;
8583
+ if (workspace && typeof workspace.pickDirectory === 'function') {
8584
+ chosen = await workspace.pickDirectory();
8585
+ }
8586
+ } catch { /* 用户取消或服务不可用 */ }
8587
+ if (typeof chosen === 'string' && chosen !== '') {
8588
+ setOwn(chosen);
8589
+ writeViewPref('gitDir', chosen);
8590
+ return chosen;
8591
+ }
8592
+ return '';
8593
+ };
8594
+
8595
+ const clear = () => {
8596
+ setOwn('');
8597
+ writeViewPref('gitDir', '');
8598
+ };
8599
+
8600
+ return { dir, override: own, pick, clear, source };
8601
+ }
8602
+
7580
8603
  /* ───────────── npm 设置页:账号卡片 + 我的包 ───────────── */
7581
8604
 
7582
8605
  /**
@@ -8193,6 +9216,17 @@ function NpmDepsSection(props) {
8193
9216
  })));
8194
9217
  }
8195
9218
 
9219
+ if (platform === 'cloudflare') {
9220
+ return h('div', { className: 'dsh-push-root dsh-push-page dsh-push-page--panel', style: densityStyle(density) },
9221
+ h('div', { className: 'dsh-push-page-head' },
9222
+ h(PlatformSwitcher, { value: platform, onChange: switchPlatform }),
9223
+ h('span', { className: 'dsh-push-page-spacer' }),
9224
+ h(Btn, { mini: true, onClick: () => setNpmReload((n) => n + 1), title: t('refresh') },
9225
+ h(Icon, { name: 'refresh', size: 12 }))),
9226
+ h('div', { className: 'dsh-push-page-body' },
9227
+ h(CloudflarePanel, { ctx, reloadKey: npmReload })));
9228
+ }
9229
+
8196
9230
  return h('div', { className: 'dsh-push-root dsh-push-page dsh-push-page--panel', style: densityStyle(density) },
8197
9231
  h('div', { className: 'dsh-push-page-head' },
8198
9232
  // 标题位置放平台切换器:它同时说明「现在看的是哪个平台」和
@@ -10222,7 +11256,11 @@ function ReviewDialog(props) {
10222
11256
  // `repoRoot` is the selected Git repository when `cwd` is a workspace
10223
11257
  // container holding several; it is the path git commands must target,
10224
11258
  // while `cwd` alone would be the folder that merely contains them.
10225
- const cwd = (props.scope && (props.scope.repoRoot || props.scope.cwd)) || '';
11259
+ const scopeDir = (props.scope && (props.scope.repoRoot || props.scope.cwd)) || '';
11260
+ // 会话目录可能是「装了几个仓库的容器」,本身不是仓库。给它一个可覆盖的
11261
+ // 目录选择:选过之后 Git 面板指向选中的目录,而不是干巴巴一句「不是仓库」。
11262
+ const tabDir = useTabDir(ctx, scopeDir);
11263
+ const cwd = tabDir.dir;
10226
11264
 
10227
11265
  const [status, setStatus] = useState(null);
10228
11266
  const [log, setLog] = useState(null);
@@ -10603,6 +11641,20 @@ function ReviewDialog(props) {
10603
11641
  h(NpmProjectPanel, { ctx, cwd })));
10604
11642
  }
10605
11643
 
11644
+ if (platform === 'cloudflare') {
11645
+ return h('div', { className: 'dsh-push-root dsh-push-tab', style: densityStyle(density) },
11646
+ reviewDialog,
11647
+ h('div', { className: 'dsh-push-tab-head' },
11648
+ h('div', { className: 'dsh-push-tab-repo' },
11649
+ h(PlatformSwitcher, { value: platform, onChange: switchPlatform }),
11650
+ h('span', { className: 'dsh-push-page-spacer' }),
11651
+ h(CloudflareAccountPicker, { ctx }),
11652
+ h(Btn, { mini: true, onClick: () => refresh(false), title: t('refresh') },
11653
+ h(Icon, { name: 'refresh', size: 12 })))),
11654
+ h('div', { className: 'dsh-push-scroll' },
11655
+ h(CloudflareWorkspaceTab, { ctx, scope: props.scope })));
11656
+ }
11657
+
10606
11658
  /* ── no workspace path: nothing can be asked of git without one ── */
10607
11659
  if (!cwd) {
10608
11660
  return h('div', { className: 'dsh-push-root dsh-push-tab', style: densityStyle(density) },
@@ -10627,11 +11679,20 @@ function ReviewDialog(props) {
10627
11679
  h(PlatformSwitcher, { value: platform, onChange: switchPlatform }),
10628
11680
  h('span', { className: 'dsh-push-tab-repo-name' }, t('tabTitle')))),
10629
11681
 
11682
+ h('div', { className: 'dsh-push-tab-dirbar' },
11683
+ h(DirPickerBar, {
11684
+ dir: tabDir.dir,
11685
+ source: tabDir.source,
11686
+ onPick: async () => { await tabDir.pick(); refresh(false); },
11687
+ onClear: () => { tabDir.clear(); refresh(false); },
11688
+ compact: true,
11689
+ })),
10630
11690
  h('div', { className: 'dsh-push-scroll' },
10631
11691
  h('div', { className: 'dsh-push-repoempty' },
10632
11692
  h('div', { className: 'dsh-push-repoempty-icon' }, h(Icon, { name: 'branch', size: 32 })),
10633
11693
  h('div', { className: 'dsh-push-repoempty-title' }, t('tabNotRepo')),
10634
11694
  h('div', { className: 'dsh-push-hint dsh-push-repoempty-path', title: resolved }, resolved),
11695
+ h('div', { className: 'dsh-push-hint' }, t('tabNotRepoHint')),
10635
11696
 
10636
11697
  initOpen
10637
11698
  ? h('div', { className: 'dsh-push-repoempty-form' },
@@ -10711,6 +11772,15 @@ function ReviewDialog(props) {
10711
11772
  : null,
10712
11773
  !cwd ? h('span', { className: 'dsh-push-error' }, t('tabNoCwd')) : null,
10713
11774
  error ? h('span', { className: 'dsh-push-error', title: error }, error) : null)),
11775
+ /* ── 目录条:换一个目录看,或恢复跟随会话 ── */
11776
+ h('div', { className: 'dsh-push-tab-dirbar' },
11777
+ h(DirPickerBar, {
11778
+ dir: tabDir.dir,
11779
+ source: tabDir.source,
11780
+ onPick: async () => { await tabDir.pick(); refresh(false); },
11781
+ onClear: () => { tabDir.clear(); refresh(false); },
11782
+ compact: true,
11783
+ })),
10714
11784
  /* ── toolbar ── */
10715
11785
  /* ── 关联远端 / 更换远端 ── */
10716
11786
  remoteBar,