dsh-design-studio 1.3.0 → 1.4.1

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.en.md CHANGED
@@ -52,6 +52,7 @@ If DSH can't reach the npm registry, it falls back to a mirror in China. To upda
52
52
  - **Your brand, and real code:** give a site URL to extract a brand design system and design with it from then on; turn a finished design into React / Vue / HTML (mini programs straight into uni-app or native WeChat code, HBuilderX projects included), compared screen by screen against the design.
53
53
  - **Built-in photo library:** for designs that rely on photos (hotels, food, cafes, fitness, beauty, fashion, education, travel), the model uses real-looking photos instead of only drawing illustrations. About 8 MB is downloaded the first time it is needed. All of them are AI-generated placeholders, so replace them with real photos before launch.
54
54
  - **Built-in font library:** click a font row in the Look panel to pick from 18 free, commercially usable fonts (Noto Sans / Serif SC, Smiley Sans, the ZCOOL family, brush and running-script calligraphy, plus Latin faces such as Inter). The page updates at once; saving copies the font files into the design folder, so exports and remote viewing keep them. You can also just ask the model, e.g. "use brush calligraphy for the headline". About 19 MB is downloaded the first time it is needed.
55
+ - **Real components:** parts repeated across screens (tab bars, top bars, cards) live as components in `components/`, and each screen uses them as `<c-name>`. Change one component and every screen using it follows; exports are still plain HTML that opens offline. The model pulls out components on its own when it builds several screens, and can convert an existing design too; a broken component shows as a red box in the preview, and the check says exactly where.
55
56
  - **A style that fits the subject:** when you have not chosen a style, the model first picks a style card for the subject (colors, fonts, corner radius) and builds with it, so a homestay app, a bubble-tea shop and a review deck no longer all come out beige. If you name a style or colors, it follows yours.
56
57
  - **Business annotations (experimental, off by default):** turn on "Business annotations" under Design Studio on the Plugins page, and the model also writes `annotations.json` with the rules, states and edge cases the UI does not show. Numbered markers appear on the page and cards in the sidebar, and clicking either one finds the other. Code handoff passes the rules on to developers (#15).
57
58
 
package/README.md CHANGED
@@ -52,6 +52,7 @@
52
52
  - **照品牌风格做、转成代码**:给官网地址,提一套品牌设计系统,以后都照它做;做好的设计转成 React / Vue / HTML,小程序直接转成 uni-app 或原生小程序代码(HBuilderX 建的项目也认得出),逐屏和设计稿比对。
53
53
  - **自带照片库**:民宿酒店、餐饮、奶茶咖啡、健身、美妆、服饰、教育、旅行风景这些靠照片说话的设计,模型会直接用上照片,不再只画插画。第一次用到时下载约 8 MB。都是 AI 生成的示意图,上线前请换成真实照片。
54
54
  - **自带字体库**:外观面板里点字体那行,就能从 18 款免费可商用字体里挑(思源黑体 / 宋体、得意黑、站酷系列、毛笔楷书、行书,加上 Inter 等英文字体),页面马上换,保存后字体文件放进设计目录,导出、远程看都带着。也可以直接跟模型说「标题用毛笔字」。第一次用到时下载约 19 MB。
55
+ - **真组件**:几屏重复的部分(标签栏、顶栏、卡片)写成 `components/` 里的组件,各屏用 `<c-名>` 引用;改一个组件,用到它的屏一起变,导出的成品照样是普通 HTML、离线能开。新做好几屏时模型会自己抽组件,也可以让它把老设计改成组件;组件写错了预览里画红框、体检说清在哪。
55
56
  - **按题材挑风格**:没定风格时,模型先按题材挑一张风格卡(配色、字体、圆角)再动手,民宿、奶茶店、复盘幻灯片不再都是一个米色调;你自己说了风格或配色就照你的。
56
57
  - **业务标注(试验,默认关)**:在「插件」页的设计工作台里打开「业务标注」,模型做设计时同时写一份 `annotations.json`,记界面上看不出来的规则、状态和边界。页面上出编号,右侧栏列卡片,点哪边都能定位到另一边;转成代码时这些规则一起交给开发(#15)。
57
58
 
package/lib/bundle.js CHANGED
@@ -40,15 +40,17 @@ const DATA_IMG = /\.(png|jpe?g|gif|webp|avif|bmp|ico|svg)$/i
40
40
  * 运行时设 src / href 这类地址时查表。地址从设计目录根算;读不到的不进表(预览里本来也是坏的)。
41
41
  * 同一张图(img/a.jpg、./img/a.jpg 写法不同也算)只放一份、只算一次大小。
42
42
  * over:有这个文件、但太大换不下的放进这里(调用方据此报错,不能悄悄留个坏图);
43
- * isBig(rel):read 给了 null 是因为文件太大(不是没有)——这种也算换不下
43
+ * isBig(rel):read 给了 null 是因为文件太大(不是没有)——这种也算换不下;
44
+ * gone:数据里写了这张图、设计目录里却没有的放进这里:{ rel, paths: 写在数据的哪些路径上(下标记成 [*]) }
44
45
  */
45
- export function dataAssets(data, read, max = 8 * 1024 * 1024, over = null, isBig = null) {
46
+ export function dataAssets(data, read, max = 8 * 1024 * 1024, over = null, isBig = null, gone = null) {
46
47
  let left = max
47
48
  let nodes = 0
48
49
  const done = new Map() // 相对路径 → data: 地址(换不下 / 没有:'')
50
+ const goneAt = new Map() // 没有的图 → 写在数据的哪些路径上(acts[1].cover 这种,记真下标;调用方据此判断是不是绑到了 src:绑的是列表别名 / 变量下标就对所有下标,写死 [0] 就只对 [0])
49
51
  const f = {}
50
52
  const r = {}
51
- const one = (s) => {
53
+ const one = (s, at) => {
52
54
  if (Object.prototype.hasOwnProperty.call(r, s)) return
53
55
  const ref = localRef(s)
54
56
  if (!ref || !DATA_IMG.test(ref)) return
@@ -64,18 +66,21 @@ export function dataAssets(data, read, max = 8 * 1024 * 1024, over = null, isBig
64
66
  d = `data:${t};base64,${buf.toString('base64')}`
65
67
  left -= d.length
66
68
  } else if (over && (buf || (isBig && isBig(rel)))) over.push(rel)
69
+ else if (gone && !buf && !(isBig && isBig(rel))) goneAt.set(rel, new Set()) // 数据里写了、文件却没有(#30 组件 :cover 这类动态图):调用方报出来
67
70
  done.set(rel, d)
68
71
  }
72
+ if (at && goneAt.has(rel)) goneAt.get(rel).add(at) // 全记(walk 总共最多 2 万个节点):只截报错里展示的条数
69
73
  const d = done.get(rel)
70
74
  if (d) { f[rel] = d; r[s] = rel }
71
75
  }
72
- const walk = (v, depth) => {
76
+ const walk = (v, depth, at) => {
73
77
  if (++nodes > 20000 || depth > 40) return
74
- if (typeof v === 'string') { if (v.length < 600) one(v); return }
75
- if (Array.isArray(v)) { for (const x of v) walk(x, depth + 1); return }
76
- if (v && typeof v === 'object') for (const k of Object.keys(v)) walk(v[k], depth + 1)
78
+ if (typeof v === 'string') { if (v.length < 600) one(v, at); return }
79
+ if (Array.isArray(v)) { v.forEach((x, i) => walk(x, depth + 1, `${at}[${i}]`)); return }
80
+ if (v && typeof v === 'object') for (const k of Object.keys(v)) walk(v[k], depth + 1, at ? at + '.' + k : k)
77
81
  }
78
- walk(data, 0)
82
+ walk(data, 0, '')
83
+ if (gone) for (const [rel, paths] of goneAt) gone.push({ rel, paths: [...paths] })
79
84
  return { f, r }
80
85
  }
81
86
  const escScript = (s) => String(s).replace(/<\/(script)/gi, '<\\/$1').replace(/<!--/g, '<\\!--')
package/lib/canvthumb.js CHANGED
@@ -73,8 +73,8 @@ export function assetScan(root, { maxFiles = 3000, depth = 6 } = {}) {
73
73
  export const assetStamp = (root, opts) => assetScan(root, opts).v
74
74
 
75
75
  // 这屏会不会把别的 HTML 嵌进来 / 载进来(iframe、fetch…):会的话别的 HTML 改了它的样子也可能变。宁可多算:
76
- // 引了本地脚本(<script src="app.js">,脚本里可能 fetch)、module 脚本(可能 import 本地脚本)也算;只引 CDN 上的脚本(http(s):、//、data:)不算
77
- const DEPS_RE = /<(?:iframe|frame|embed|object|portal)\b|\bfetch\s*\(|XMLHttpRequest|\bimport\s*\(|\bhx-(?:get|post|put|patch|delete)\b|\.load\s*\(|<link\b[^>]*\bimport\b|<script\b[^>]*\btype\s*=\s*["']?module\b|<script\b[^>]*?\bsrc\s*=\s*(?:["']|(?=[^\s"'>]))(?!\s*(?:(?:https?:)?\/\/|data:))/i
76
+ // 用了组件(#30,<c-…>:组件文件改了它的样子就变)也算;引了本地脚本(<script src="app.js">,脚本里可能 fetch)、module 脚本(可能 import 本地脚本)也算;只引 CDN 上的脚本(http(s):、//、data:)不算
77
+ const DEPS_RE = /<c-[a-z]|<(?:iframe|frame|embed|object|portal)\b|\bfetch\s*\(|XMLHttpRequest|\bimport\s*\(|\bhx-(?:get|post|put|patch|delete)\b|\.load\s*\(|<link\b[^>]*\bimport\b|<script\b[^>]*\btype\s*=\s*["']?module\b|<script\b[^>]*?\bsrc\s*=\s*(?:["']|(?=[^\s"'>]))(?!\s*(?:(?:https?:)?\/\/|data:))/i
78
78
  const DEPS_MAX = 4 << 20
79
79
 
80
80
  /**
package/lib/client.js CHANGED
@@ -205,6 +205,8 @@ window.__ModuleLoader__.load({
205
205
  exportedHtml: '已导出 {name}({n} 屏,发给别人双击就能看)',
206
206
  exportedHtmlMiss: '已导出 {name}({n} 屏,{miss} 屏没读到)',
207
207
  exportedHtmlSkip: '。{n} 个文件太大没放进去,演示里会缺({files}):单个文件最多 12 MB、一屏的图和字体加起来最多 48 MB',
208
+ exportedHtmlGone: '。mock.json 里写的 {n} 张图在设计目录里找不到,演示里会是坏图({files})',
209
+ htmlImgMissing: '没导出:组件绑的图在设计目录里找不到({files})。补上图片,或改 mock.json 里的路径',
208
210
  htmlTooBig: '图片太多,演示包超过 150 MB,没导出。少放几屏再试',
209
211
  htmlImgBig: '模拟数据(mock.json)里绑的图太大(单张最多 12 MB、加起来最多 60 MB),放不进演示,没导出。换小一点的图再试',
210
212
  htmlMockBig: 'mock.json 太大(超过 1 MB),演示里的数据带不上,没导出。把里面的大段内容(比如图片的 base64)换成图片文件路径再试',
@@ -374,11 +376,14 @@ window.__ModuleLoader__.load({
374
376
  exported: '已导出 {name}',
375
377
  exportedCopied: '已导出 {name},也复制到剪贴板了',
376
378
  exportFail: '导出失败:{msg}',
379
+ compXErr: '没导出:{n} 屏的组件有错({list}){msg}',
380
+ compXOpen: '去看{name}',
377
381
  reveal: '在文件夹里显示',
378
382
  madeWith: '用 DSH 设计台做的',
379
383
  showSub: '{n} 屏 · {kind} · {date}',
380
384
  history: '版本',
381
385
  histSub: '{n} 个',
386
+ histSkip: '最近一次没存成版本:设计目录太大(超过 {files} 个文件或 {mb} MB)。删掉用不到的大文件就能接着存,之前的版本还在。',
382
387
  histEmptyT: '还没有版本',
383
388
  histEmpty: '模型每轮改完、你每次手调保存,都会自动存一版,随时能回去。',
384
389
  vNowTm: '文件里现在的样子',
@@ -491,6 +496,12 @@ window.__ModuleLoader__.load({
491
496
  edUndoFail: '没撤销成:文件可能刚被改过,去版本里找改前那一版',
492
497
  edUndoChanged: '这一屏后来又被改过(编辑器或模型),撤销不了了:去版本里找改前那一版',
493
498
  textAsk: '把页面上的「{before}」改成「{after}」({where};只改这一处文字,别的不动)。\n',
499
+ textAskComp: '这段字在组件 components/{name}.html 里:是这屏 <c-{name}> 传进去的参数,就只改这屏的参数;是组件里写死的字,就改组件(用到它的屏会一起变)。\n',
500
+ styleComp: '这屏用了组件,改动交给模型改',
501
+ styleCompN: '用了组件,点「让模型改」',
502
+ edComp: '这屏用了组件',
503
+ edAsk: '交给模型',
504
+ styleAskComp: '这个元素在组件 components/{name}.html 里:所有屏都要改就改组件里的 <style>;只改这一屏就给这屏的 <c-{name}> 加 class 或 data-variant。\n',
494
505
  styleEdit: '调样式:点页面里的元素,拖滑块改字号、颜色、圆角、间距(Esc 退出)',
495
506
  styleAny: '点任意一屏里的元素调样式 · Esc 退出',
496
507
  styleOne: '点页面里的元素调样式 · Esc 退出',
@@ -645,8 +656,8 @@ window.__ModuleLoader__.load({
645
656
  pubScreens: '会放出这 {n} 屏:{names}。之后新加的屏不会自动放出去。',
646
657
  pubMoreNames: '…等',
647
658
  pubShared: '放出去的是这 {n} 屏:{names}',
648
- pubBrokenShort: '对方现在打不开',
649
- pubBroken: '对方现在打开会看到「暂时打不开」:{why}。改好后对方刷新就行,也可以先停止分享。',
659
+ pubBrokenShort: '新版本没发布',
660
+ pubBroken: '新版本没发布,对方看到的还是上一版:{why}。改好后自动发布,对方刷新就是新的。',
650
661
  pubDlStalled: '下载卡住了(30 秒没动),多半是连不上 GitHub。可以再试,或者按下面的方法自己装。',
651
662
  pubDlNoBuild: '这台电脑的系统没有现成的 cloudflared,要自己装。',
652
663
  pubReconnecting: '正在重连',
@@ -656,6 +667,8 @@ window.__ModuleLoader__.load({
656
667
  pubFailHint: '公司网络、代理软件有时会拦;换个网络或关掉代理再试。',
657
668
  pubTooBig: '图片太多,演示超过 150 MB,发不了。少放几屏再试',
658
669
  pubNoScreens: '一屏都没读到(文件被挪走或删了?)',
670
+ pubComp: '有屏的组件有错(预览里有红框),改好再发布',
671
+ pubCompAt: '{msg}。打开那屏看红框照着改,改好再发布',
659
672
  pubEndExpired: '上一个链接到 2 小时,自动关了。',
660
673
  pubEndDropped: '上一个链接断了(网络变了或电脑睡着了),已经失效。',
661
674
  pubEndMoved: '换了设计,上一个链接关了。',
@@ -1228,6 +1241,7 @@ window.__ModuleLoader__.load({
1228
1241
  pkFlags: '提醒一下(不拦):',
1229
1242
  pkSkipped: '没打进包里:{list}',
1230
1243
  pkNoDesign: '先打开一套本地的设计',
1244
+ pkComp: '这套设计用了组件(components/),打包和投稿下一版才支持。现在要给人看,用「导出 HTML 演示」',
1231
1245
  prepText: '〔准备分享〕打包前查出 {n} 个问题,照着改(改完我再打包):\n{list}\n只改这些地方,别动别的设计;改完调 check_design 体检一遍。',
1232
1246
  chipPrep: '准备分享 · {n} 个问题',
1233
1247
  shTip: '交上去的东西是公开的:别人能看、能拿去用。先查一遍,过了就能投。',
@@ -1453,6 +1467,8 @@ window.__ModuleLoader__.load({
1453
1467
  exportedHtml: 'Exported {name} ({n} screens; anyone can open it with a double-click)',
1454
1468
  exportedHtmlMiss: 'Exported {name} ({n} screens, {miss} could not be read)',
1455
1469
  exportedHtmlSkip: '. {n} file(s) were too big to include and will be missing ({files}): 12 MB per file and 48 MB of images and fonts per screen at most',
1470
+ exportedHtmlGone: '. {n} image(s) named in mock.json are not in the design folder and will show broken ({files})',
1471
+ htmlImgMissing: 'Not exported: images bound in components are missing from the design folder ({files}). Add them or fix the paths in mock.json',
1456
1472
  htmlTooBig: 'Too many images: the demo would be over 150 MB, so nothing was exported. Try with fewer screens',
1457
1473
  htmlImgBig: 'An image referenced in the mock data (mock.json) is too big (12 MB each, 60 MB in total at most) to fit in the demo, so nothing was exported. Try a smaller image',
1458
1474
  htmlMockBig: 'mock.json is too big (over 1 MB) to carry its data into the demo, so nothing was exported. Replace large content (like base64 images) with image file paths and try again',
@@ -1622,11 +1638,14 @@ window.__ModuleLoader__.load({
1622
1638
  exported: 'Exported {name}',
1623
1639
  exportedCopied: 'Exported {name} and copied it',
1624
1640
  exportFail: 'Export failed: {msg}',
1641
+ compXErr: 'Not exported: components have errors on {n} screen(s) ({list}){msg}',
1642
+ compXOpen: 'Open {name}',
1625
1643
  reveal: 'Show in folder',
1626
1644
  madeWith: 'Made with DSH Design Studio',
1627
1645
  showSub: '{n} screens · {kind} · {date}',
1628
1646
  history: 'Versions',
1629
1647
  histSub: '{n} saved',
1648
+ histSkip: 'The latest version was not saved: the design folder is too big (over {files} files or {mb} MB). Remove large files you do not need to keep saving; earlier versions are still here.',
1630
1649
  histEmptyT: 'No versions yet',
1631
1650
  histEmpty: 'A version is saved after every model turn and every manual save, so you can always go back.',
1632
1651
  vNowTm: 'What the files look like now',
@@ -1739,6 +1758,12 @@ window.__ModuleLoader__.load({
1739
1758
  edUndoFail: 'Could not undo: the file may have just changed. Find the earlier version in History',
1740
1759
  edUndoChanged: 'This screen was changed elsewhere since (an editor or the model), so it can\'t be undone. Find the earlier version in History',
1741
1760
  textAsk: 'Change the text "{before}" to "{after}" on the page ({where}; only this text, nothing else).\n',
1761
+ textAskComp: 'This text is inside the component components/{name}.html: if it is a parameter passed by this screen\'s <c-{name}>, change only that parameter; if it is fixed text in the component, edit the component (every screen using it changes too).\n',
1762
+ styleComp: 'This screen uses components; changes go to the model',
1763
+ styleCompN: 'uses components, click "Ask the model"',
1764
+ edComp: 'Uses components',
1765
+ edAsk: 'Send to model',
1766
+ styleAskComp: 'This element is inside the component components/{name}.html: to change every screen, edit the <style> in the component; for this screen only, add a class or data-variant to this screen\'s <c-{name}>.\n',
1742
1767
  styleEdit: 'Style: click an element, then drag sliders for size, colors, radius and spacing (Esc to stop)',
1743
1768
  styleAny: 'Click an element in any screen to style it · Esc to stop',
1744
1769
  styleOne: 'Click an element in the page to style it · Esc to stop',
@@ -1893,8 +1918,8 @@ window.__ModuleLoader__.load({
1893
1918
  pubScreens: 'Shares these {n} screens: {names}. Screens added later are not shared automatically.',
1894
1919
  pubMoreNames: ' and more',
1895
1920
  pubShared: 'Sharing these {n} screens: {names}',
1896
- pubBrokenShort: 'Visitors can\'t open it now',
1897
- pubBroken: 'Visitors currently see "Not available": {why}. Once fixed they can just refresh, or you can stop sharing.',
1921
+ pubBrokenShort: 'New version not published',
1922
+ pubBroken: 'The new version was not published; visitors still see the previous one: {why}. It publishes automatically once fixed, and a refresh shows it.',
1898
1923
  pubDlStalled: 'The download stalled (no progress for 30 seconds), probably because GitHub is unreachable. Try again, or install it yourself as below.',
1899
1924
  pubDlNoBuild: 'There is no ready-made cloudflared for this system. Please install it yourself.',
1900
1925
  pubReconnecting: 'Reconnecting',
@@ -1904,6 +1929,8 @@ window.__ModuleLoader__.load({
1904
1929
  pubFailHint: 'Office networks and proxy apps sometimes block it. Try another network or turn off the proxy.',
1905
1930
  pubTooBig: 'Too many images: the demo would be over 150 MB. Try with fewer screens',
1906
1931
  pubNoScreens: 'None of the screens could be read (moved or deleted?)',
1932
+ pubComp: 'Components have errors on some screens (red boxes in the preview); fix them, then publish',
1933
+ pubCompAt: '{msg}. Open that screen and fix the red boxes, then publish',
1907
1934
  pubEndExpired: 'The last link closed after 2 hours.',
1908
1935
  pubEndDropped: 'The last link dropped (network changed or the computer slept) and no longer works.',
1909
1936
  pubEndMoved: 'You switched designs, so the last link was closed.',
@@ -2474,6 +2501,7 @@ window.__ModuleLoader__.load({
2474
2501
  pkFlags: 'Heads-up (not blocking):',
2475
2502
  pkSkipped: 'Left out: {list}',
2476
2503
  pkNoDesign: 'Open a local design first',
2504
+ pkComp: 'This design uses components (components/); packing and submitting will come in the next version. To show it to someone now, use "Export HTML demo"',
2477
2505
  prepText: '[Prepare to share] Packing found {n} problems. Fix them (I will pack again afterwards):\n{list}\nChange only these places and nothing else in the design; then run check_design once.',
2478
2506
  chipPrep: 'Prepare to share · {n} problems',
2479
2507
  shTip: 'What you share is public: anyone can see and reuse it. It is checked first; once it passes you can submit it.',
@@ -4951,7 +4979,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
4951
4979
  body: JSON.stringify(body),
4952
4980
  })
4953
4981
  const data = await r.json().catch(() => ({}))
4954
- if (!r.ok) throw new Error(data.error || `HTTP ${r.status}`)
4982
+ if (!r.ok) { const e = new Error(data.error || `HTTP ${r.status}`); e.data = data; throw e }
4955
4983
  return data
4956
4984
  }
4957
4985
 
@@ -5191,13 +5219,15 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
5191
5219
  const both = (key, sp) => L.map((x) => tplSrc(x[key], sp))
5192
5220
  const lit = (keys) => '(?:' + keys.flatMap((k) => L.map((x) => reEsc(x[k].replace(/\n+$/, '')))).join('|') + ')'
5193
5221
  const quote = (t, s) => t('lang') === 'en' ? `"${s}"` : `「${s}」`
5222
+ // 改字 / 调样式落在组件里(#30)时后面多一行「这段在组件 …」:整段照样认成一个标签
5223
+ const compTail = (x, key) => `(?:\\n${noCap(tplSrc(x[key], { name: '[a-z][a-z0-9-]*' }).src)})?`
5194
5224
  chipKinds = [
5195
5225
  { i: 'mark', label: (v, t) => t('chipMark'),
5196
5226
  alts: L.map((x) => tplSrc(x.mkAsk, { where: '[^\\n]*', notes: `(?:${noCap(tplSrc(x.mkNotes).src)}\\n)?` })),
5197
5227
  card: (v, t) => [['b', t('chipMark')], ['img', chipThumbs.get(v.path)], ['p', String(v.notes || '').trim().replace(/^[^::]*[::]\s*/, '')], ['span', v.where], ['span', baseName(v.path)]] },
5198
- { i: 'text', label: (v, t) => t('chipText'), alts: both('textAsk'),
5228
+ { i: 'text', label: (v, t) => t('chipText'), alts: L.map((x) => { const a = tplSrc(x.textAsk); return { src: a.src + compTail(x, 'textAskComp'), keys: a.keys } }),
5199
5229
  card: (v, t) => [['b', t('chipText')], ['p', `${quote(t, v.before)} → ${quote(t, v.after)}`], ['span', fileOf(v)]] },
5200
- { i: 'style', label: (v, t) => t('chipStyle'), alts: both('styleAskText', { rules: '(?:\\n- [^\\n]*)*\\n|' }),
5230
+ { i: 'style', label: (v, t) => t('chipStyle'), alts: L.map((x) => { const a = tplSrc(x.styleAskText, { rules: '(?:\\n- [^\\n]*)*\\n|' }); return { src: a.src + compTail(x, 'styleAskComp'), keys: a.keys } }),
5201
5231
  card: (v, t) => [['b', t('chipStyle')], ['code', v.sel && v.sel !== v.name ? `${v.name} · ${v.sel}` : v.name], ['p', v.list], ['span', fileOf(v)]] },
5202
5232
  { i: 'layers', label: (v, t) => t('chipVariant'), alts: both('variantText'),
5203
5233
  card: (v, t) => [['b', t('chipVariant')], ['code', v.name], ['span', fileOf(v)]] },
@@ -8027,7 +8057,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
8027
8057
  if (isCur && p.onEditDone) p.onEditDone()
8028
8058
  break
8029
8059
  case 'editing': // 页面里正点开一段字在改:灵动条上方换成按键提示
8030
- if (isCur && p.textEdit && p.onEditing) p.onEditing(!!d.on)
8060
+ if (isCur && p.textEdit && p.onEditing) p.onEditing(!!d.on, !!d.comp)
8031
8061
  break
8032
8062
  case 'checked':
8033
8063
  case 'measured':
@@ -9611,10 +9641,11 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
9611
9641
  slider('stylePadX', ['padding-left', 'padding-right'], 48, 'space'),
9612
9642
  sty.layout ? slider('styleGap', ['gap'], 48, 'space') : null)),
9613
9643
  h('footer', null,
9614
- h('span', { className: 'note', title: n ? where : '' }, n ? `${t('styleN', { n: styleChanges(t, sty).length })} · ${where}` : ''),
9644
+ h('span', { className: 'note', title: n && !sty.comp ? where : '' }, n ? `${t('styleN', { n: styleChanges(t, sty).length })} · ${sty.comp ? t('styleCompN') : where}` : sty.comp ? t('styleComp') : ''),
9615
9645
  h('button', { className: 'dd-bt ghost', disabled: !n, onClick: onReset }, t('styleReset')),
9616
- h('button', { className: 'dd-bt', disabled: !n, ...tipA(t('styleAsk'), t('styleAskTip')), onClick: onAsk }, h(I.spark), t('styleAsk')),
9617
- h('button', { className: 'dd-bt pri go', disabled: !n || !write.ok, ...tipA(t('styleSave'), write.ok ? t('styleSaveTip') : write.tip), onClick: onSave }, t('styleSave'))))
9646
+ // 用了组件的屏(#30):只能交给模型,「让模型改」当主按钮,「保存」不出
9647
+ h('button', { className: sty.comp ? 'dd-bt pri go' : 'dd-bt', disabled: !n, ...tipA(t('styleAsk'), t('styleAskTip')), onClick: onAsk }, h(I.spark), t('styleAsk')),
9648
+ sty.comp ? null : h('button', { className: 'dd-bt pri go', disabled: !n || !write.ok, ...tipA(t('styleSave'), write.ok ? t('styleSaveTip') : write.tip), onClick: onSave }, t('styleSave'))))
9618
9649
  }
9619
9650
 
9620
9651
  /** 风格样板:用这个风格画的一小屏(顶栏、标题、按钮、商品卡、数据卡);卡片上缩小着放,点开是原大 */
@@ -9733,7 +9764,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
9733
9764
  async function getJson(path) {
9734
9765
  const r = await fetch(API + path, { credentials: 'same-origin' })
9735
9766
  const data = await r.json().catch(() => ({}))
9736
- if (!r.ok) throw new Error(data.error || `HTTP ${r.status}`)
9767
+ if (!r.ok) { const e = new Error(data.error || `HTTP ${r.status}`); e.data = data; throw e }
9737
9768
  return data
9738
9769
  }
9739
9770
 
@@ -10739,7 +10770,8 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10739
10770
  // 几百屏的设计(#29):只列前 12 个名字
10740
10771
  return t('pubScreens', { n: list.length, names: list.slice(0, 12).join(t('sep')) + (list.length > 12 ? t('pubMoreNames') : '') })
10741
10772
  })()
10742
- const errText = (r) => (r.error === 'tooBig' ? t('pubTooBig') : r.error === 'imgTooBig' ? t('htmlImgBig') : r.error === 'mockTooBig' ? t('htmlMockBig') : r.error === 'noScreens' ? t('pubNoScreens') : t('pubFail', { msg: r.message || r.error || '' }))
10773
+ const compWhy = (msg) => (msg && t('lang') !== 'en' ? t('pubCompAt', { msg: String(msg).replace(/^新版本没发布:/, '') }) : t('pubComp'))
10774
+ const errText = (r) => (r.error === 'compErr' ? compWhy(r.message) : r.error === 'tooBig' ? t('pubTooBig') : r.error === 'imgTooBig' ? t('htmlImgBig') : r.error === 'mockTooBig' ? t('htmlMockBig') : r.error === 'noScreens' ? t('pubNoScreens') : t('pubFail', { msg: r.message || r.error || '' }))
10743
10775
  // 接口拒了(点生成的那一刻换了设计、或者现在看的不是本地文件):别说成「没连上 Cloudflare」
10744
10776
  const errMsg = (m) => (m === 'designChanged' || m === 'not-file' ? t('pubGone') : t('pubFail', { msg: m }))
10745
10777
  const ended = (r) => (r.ended === 'expired' ? t('pubEndExpired') : r.ended === 'dropped' ? t('pubEndDropped') : r.ended === 'moved' ? t('pubEndMoved') : '')
@@ -10774,7 +10806,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10774
10806
  h('button', { type: 'button', className: 'dd-bt pri', onClick: () => onCopy(res.url) }, h(I.copy), t('phoneCopy')),
10775
10807
  h('button', { type: 'button', className: 'dd-bt danger', onClick: stop }, h(I.stopSq), t('pubStop'))),
10776
10808
  res.state === 'reconnecting' ? h('p', { className: 'fine warn' }, t('pubReconnectingFine')) : null,
10777
- res.broken ? h('p', { className: 'fine warn' }, t('pubBroken', { why: res.broken === 'tooBig' ? t('pubTooBig') : res.broken === 'imgTooBig' ? t('htmlImgBig') : res.broken === 'mockTooBig' ? t('htmlMockBig') : res.broken === 'noScreens' ? t('pubNoScreens') : res.broken })) : null,
10809
+ res.broken ? h('p', { className: 'fine warn' }, t('pubBroken', { why: res.broken === 'compErr' ? compWhy(res.brokenMsg) : res.broken === 'tooBig' ? t('pubTooBig') : res.broken === 'imgTooBig' ? t('htmlImgBig') : res.broken === 'mockTooBig' ? t('htmlMockBig') : res.broken === 'noScreens' ? t('pubNoScreens') : res.brokenMsg ? String(res.brokenMsg).replace(/^新版本没发布:/, '') : res.broken })) : null,
10778
10810
  res.screens && res.screens.length ? h('p', { className: 'fine' }, t('pubShared', { n: res.screens.length, names: res.screens.join(t('sep')) })) : null),
10779
10811
  notes(['pubHow', 'pubLive', 'pubWarn']))
10780
10812
  } else if (res.dl && !res.dl.done && !res.tool) {
@@ -10832,7 +10864,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10832
10864
  * 1.0 版本面板:一排卡片,左边是「现在」,往右越来越早;卡片上是那一版的缩略图(后台截,看得到才要)、第几版、什么时候、
10833
10865
  * 谁改的(手调 / 模型)和改了什么。点一张就在画布上看那一版(底下灵动条换成「对比 · 回到这一版」),←/→ 换着看
10834
10866
  */
10835
- function HistoryPanel({ t, head, versions, ver, onPick, thumb, nowThumb, curKey, tall }) {
10867
+ function HistoryPanel({ t, head, versions, ver, onPick, thumb, nowThumb, curKey, tall, skip }) {
10836
10868
  const row = useRef(null)
10837
10869
  // 选中的那张滚进来(←/→ 一张张往下翻时)
10838
10870
  useEffect(() => {
@@ -10872,8 +10904,12 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
10872
10904
  if (!el || Math.abs(e.deltaX) > Math.abs(e.deltaY) || el.scrollWidth <= el.clientWidth) return
10873
10905
  el.scrollLeft += e.deltaY
10874
10906
  }
10907
+ // 最近一次没存成(比最新那版还新):说一句原因,不然看着像「改了没存」
10908
+ const last = versions[0] // 新的在前
10909
+ const skipNote = skip && (!last || Number(skip.at) > Number(last.at)) ? h('p', { className: 'fine warn', role: 'status' }, t('histSkip', { files: skip.files || 300, mb: skip.mb || 30 })) : null
10875
10910
  return h('div', { className: 'ddp-tokens ddp-hist', onPointerDown: (e) => e.stopPropagation() },
10876
10911
  head,
10912
+ skipNote,
10877
10913
  versions.length
10878
10914
  ? h('div', { className: 'bd dd-vrow', ref: row, role: 'listbox', 'aria-label': t('history'), onKeyDown: onKey, onWheel },
10879
10915
  h('button', { key: 'now', className: 'dd-vc now' + (!ver ? ' on' : ''), role: 'option', 'aria-selected': !ver, style: { '--i': 0 }, onClick: () => onPick(null) },
@@ -11821,7 +11857,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
11821
11857
  lic === 'CC-BY-4.0' ? h('input', { key: 'who', className: 'who dd-xin', value: who, maxLength: 40, placeholder: t('pkWho'), 'aria-label': t('pkWho'), onChange: (e) => setWho(e.target.value) }) : null,
11822
11858
  demo ? h('button', { key: 'go', type: 'button', className: 'dd-bt wide', disabled: !canGo, onClick: go }, h(I.box), t(busy ? 'pkChecking' : res && res.ok === false ? 'pkAgain' : 'pkGoZip')) : null,
11823
11859
  busy && !demo ? h('p', { key: 'busy', className: 'fine' }, t('pkChecking')) : null,
11824
- res && res.error ? h('p', { key: 'err', className: 'warn' }, res.error === 'noScreens' ? t('pkNoDesign') : t('libFail', { msg: res.error })) : null,
11860
+ res && res.error ? h('p', { key: 'err', className: 'warn' }, res.error === 'noScreens' ? t('pkNoDesign') : res.error === 'compShare' ? t('pkComp') : t('libFail', { msg: res.error })) : null,
11825
11861
  res && res.ok ? h('div', { key: 'ok', className: 'okbox' },
11826
11862
  h('div', null, h(I.check), h('span', null, t('pkOk', { name: baseName(res.path) }))),
11827
11863
  h('button', { type: 'button', className: 'lk', onClick: () => post('reveal', { path: res.path }).catch(() => {}) }, t('pkReveal'))) : null,
@@ -11917,7 +11953,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
11917
11953
  }, [root])
11918
11954
  // 预填回来之前不能查(不然用的是没对上这一套的表单)
11919
11955
  const voc = { categories: (info && info.vocab && Array.isArray(info.vocab.categories) && info.vocab.categories) || [], tags: (info && info.vocab && Array.isArray(info.vocab.tags) && info.vocab.tags) || [] }
11920
- const ready = !!root && !!info && !!title.trim() && !!desc.trim() && (!voc.categories.length || cats.length > 0) && SHARE_AGREE.every(([k]) => agree[k])
11956
+ const ready = !!root && !!info && !info.error && !!title.trim() && !!desc.trim() && (!voc.categories.length || cats.length > 0) && SHARE_AGREE.every(([k]) => agree[k])
11921
11957
  // 点一下选上、再点取消;选满了别的点不动
11922
11958
  const toggle = (set, key, max) => (id) => { edited.current[key] = true; set((cur) => (cur.includes(id) ? cur.filter((x) => x !== id) : cur.length < max ? [...cur, id] : cur)) }
11923
11959
  const [openAll, setOpenAll] = useState({}) // 分类 / 标签:展开了「全部」的
@@ -12044,7 +12080,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12044
12080
  ...items.map(([k, text, tip]) => h('button', { key: k, type: 'button', role: 'radio', 'aria-checked': cur === k, className: cur === k ? 'on' : '', title: tip || undefined, disabled: busy, onClick: () => on(k) }, text)))
12045
12081
  const field = (k, kids) => h('div', { className: 'dd-f', key: k }, ...kids)
12046
12082
  const head6 = (k, hint) => h('h6', null, t(k), hint ? h('small', null, t(hint)) : null)
12047
- const form = done ? null : [
12083
+ const form = done || (info && info.error) ? null : [
12048
12084
  h('div', { className: 'dd-col', key: 'c1' },
12049
12085
  field('n', [h('div', { className: 'lbl' }, h('span', null, t('shName'))), h('input', { className: 'who dd-xin', value: title, maxLength: 24, disabled: busy, 'aria-label': t('shName'), onChange: (e) => { edited.current.title = true; setTitle(e.target.value) } })]),
12050
12086
  field('d', [h('div', { className: 'lbl' }, h('span', null, t('shDesc'))), h('input', { className: 'who dd-xin', value: desc, maxLength: 120, disabled: busy, placeholder: t('shDescPh'), 'aria-label': t('shDesc'), onChange: (e) => { edited.current.desc = true; setDesc(e.target.value) } })]),
@@ -12064,9 +12100,9 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12064
12100
  head,
12065
12101
  h('div', { className: 'dd-cols dd-shf' + (done ? ' dd-two' : '') },
12066
12102
  root ? null : h('p', { key: 'no' }, t('pkNoDesign')),
12067
- info && info.error ? h('p', { key: 'ie', className: 'err' }, info.error === 'noScreens' ? t('pkNoDesign') : t('libFail', { msg: info.error })) : null,
12103
+ info && info.error ? h('p', { key: 'ie', className: 'err' }, info.error === 'noScreens' ? t('pkNoDesign') : info.error === 'compShare' ? t('pkComp') : t('libFail', { msg: info.error })) : null,
12068
12104
  lost && !res && !busy ? h('p', { key: 'lost', className: 'err' }, t('shSubErr_notShared')) : null,
12069
- res && res.error ? h('p', { key: 're', className: 'err' }, res.error === 'noScreens' ? t('pkNoDesign') : t('libFail', { msg: res.error })) : null,
12105
+ res && res.error ? h('p', { key: 're', className: 'err' }, res.error === 'noScreens' ? t('pkNoDesign') : res.error === 'compShare' ? t('pkComp') : t('libFail', { msg: res.error })) : null,
12070
12106
  res && res.ok === false ? h('div', { key: 'errs', className: 'errs' },
12071
12107
  h('p', null, t('pkFail', { n: res.errors.length + (res.more || 0) })),
12072
12108
  h('ol', null, ...res.errors.slice(0, 30).map((e, i) => h('li', { key: i }, e.msg))),
@@ -12615,6 +12651,25 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12615
12651
  function makeExporter(x) {
12616
12652
  const { sid, st, kind, size, dark, meta, tokens, t, say, canvas, focus, sel, shown, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned, onWarn, apiOf, targetKey, tops, tweak, webFit, statesFor } = x
12617
12653
  const sayErr = (m, a) => say(m, a, true) // 没成的事:红色消息条,不自己走
12654
+ // 组件有错(#30):整次不导,说哪几屏、第一条错是什么,消息条上点一下去看那屏
12655
+ const compErrSay = (pages) => {
12656
+ const p0 = pages[0]
12657
+ const e0 = p0 && p0.errors && p0.errors[0]
12658
+ // 诊断是中文写的(给模型看):英文界面只说哪几屏,点「去看」那屏的红框里有原因
12659
+ const msg = e0 && t('lang') !== 'en' ? ':' + String(e0.message || '') + (e0.fix ? ' → ' + String(e0.fix) : '') : ''
12660
+ sayErr(t('compXErr', { n: pages.length, list: pages.slice(0, 3).map((p) => String(p.page).replace(/\.html?$/i, '')).join(t('sep')) + (pages.length > 3 ? '…' : ''), msg }),
12661
+ p0 && x.openKey ? { label: t('compXOpen', { name: String(p0.page).replace(/\.html?$/i, '') }), run: () => x.openKey(p0.page) } : undefined)
12662
+ }
12663
+ // 导出前先查要导的屏(某一版就查那一版):截图不经打包,红框会被当成正常画面存下来。查不了也不导(不然红框被当成画面存下来)
12664
+ const compOk = async (keys) => {
12665
+ if (!fileTarget) return true
12666
+ let r = null
12667
+ try { r = await post('compcheck', { session: sid, keys, v: ver ? ver.n : 0 }) } catch (e) { sayErr(t('exportFail', { msg: String((e && e.message) || '') })); return false }
12668
+ const pages = r && Array.isArray(r.pages) ? r.pages : []
12669
+ if (!pages.length) return true
12670
+ compErrSay(pages)
12671
+ return false
12672
+ }
12618
12673
  // 导出用的全部屏(#29):屏多过上限时右侧栏只显示最新的 60 屏,收起来的那些接在前面;没收起来就是显示的这些
12619
12674
  let every = x.every || shown
12620
12675
  // 导出前再问一次收起来的是哪些(不用缓存:右侧栏刚加了屏、收起来的改了名,都还没轮询到)
@@ -12704,6 +12759,14 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12704
12759
  const design = designNow.current
12705
12760
  const stamp = designSeq.current
12706
12761
  const gone = () => designSeq.current !== stamp
12762
+ {
12763
+ // 只查这次要导的屏:单屏图片查那一屏、展示图查显示着的这些,PDF / PPT 没挑就查全部(别让无关屏的错拦住)
12764
+ const one = mode !== 'show' && mode !== 'pdf' && mode !== 'pptx'
12765
+ const k1 = one && (shown.find((s) => s.key === (key || (canvas ? sel || focus : focus))) || shown[0])
12766
+ const keys = key ? [key] : opts && Array.isArray(opts.keys) ? opts.keys : mode === 'show' ? shown.map((s) => s.key) : one ? (k1 ? [k1.key] : []) : null
12767
+ if (!(await compOk(keys || undefined))) return
12768
+ if (gone()) { sayErr(t('xoGone')); return }
12769
+ }
12707
12770
  const aiShot = new Set() // 这次导出截到的 AI 示意图(每次导出各记各的,连着导出不串)
12708
12771
  try {
12709
12772
  const prefix = ver ? `v${ver.n}-` : ''
@@ -12869,10 +12932,15 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
12869
12932
  const file = String(r.path || '').split(/[\\/]/).pop()
12870
12933
  const miss = Array.isArray(r.missing) ? r.missing.length : 0
12871
12934
  const skip = Array.isArray(r.skipped) ? r.skipped : []
12872
- say((miss ? t('exportedHtmlMiss', { name: file, n: r.count, miss }) : t('exportedHtml', { name: file, n: r.count })) + (skip.length ? t('exportedHtmlSkip', { n: r.skippedN || skip.length, files: skip.slice(0, 3).map((x) => String(x).split('/').pop()).join('、') + ((r.skippedN || skip.length) > 3 ? '…' : '') }) : '') + cutTail() + (r.ai ? ' · ' + t('xoAi', { n: r.ai }) : ''), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
12935
+ const gone = Array.isArray(r.gone) ? r.gone : []
12936
+ const goneN = r.goneN || gone.length
12937
+ const goneTail = gone.length ? t('exportedHtmlGone', { n: goneN, files: gone.slice(0, 3).join(t('sep')) + (goneN > 3 ? '…' : '') }) : ''
12938
+ say((miss ? t('exportedHtmlMiss', { name: file, n: r.count, miss }) : t('exportedHtml', { name: file, n: r.count })) + (skip.length ? t('exportedHtmlSkip', { n: r.skippedN || skip.length, files: skip.slice(0, 3).map((x) => String(x).split('/').pop()).join('、') + ((r.skippedN || skip.length) > 3 ? '…' : '') }) : '') + goneTail + cutTail() + (r.ai ? ' · ' + t('xoAi', { n: r.ai }) : ''), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
12873
12939
  } catch (e) {
12874
12940
  const m = String((e && e.message) || '')
12875
12941
  if (m === 'designChanged' || m === 'not-file') sayErr(t('xoGone'))
12942
+ else if (m === 'compErr' && e.data && Array.isArray(e.data.pages) && e.data.pages.length) compErrSay(e.data.pages)
12943
+ else if (m === 'imgMissing') { const fl = e.data && Array.isArray(e.data.files) ? e.data.files : []; sayErr(t('htmlImgMissing', { files: fl.slice(0, 3).join(t('sep')) + (fl.length > 3 ? '…' : '') })) }
12876
12944
  else if (m === 'tooBig' || m === 'noScreens' || m === 'imgTooBig' || m === 'mockTooBig') sayErr(t(m === 'tooBig' ? 'htmlTooBig' : m === 'imgTooBig' ? 'htmlImgBig' : m === 'mockTooBig' ? 'htmlMockBig' : 'htmlNoScreens'))
12877
12945
  else sayErr(t('exportFail', { msg: m }), { label: t('retry'), run: () => exportHtml() })
12878
12946
  }
@@ -13174,7 +13242,9 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13174
13242
  if (canvas) setSel(sc.key)
13175
13243
  const pg = pageOf(sc, p.href)
13176
13244
  const rules = p.rules && typeof p.rules === 'object' ? p.rules : {}
13177
- setSty({ key: pg.key, url: pg.url, name: p.name, selector: p.selector, text: p.text, loc: p.loc, base: p.css || {}, vars: p.vars || {}, rules, gradient: !!p.gradient, layout: !!p.layout, live: {}, shareSeen: {} })
13245
+ // comp(#30):这屏用了组件,保存交给模型;是组件名的话交给模型时说是哪个组件
13246
+ const comp = typeof p.comp === 'string' && /^[a-z][a-z0-9-]*$/.test(p.comp) ? p.comp : p.comp ? true : false
13247
+ setSty({ key: pg.key, url: pg.url, name: p.name, selector: p.selector, text: p.text, loc: p.loc, base: p.css || {}, vars: p.vars || {}, rules, gradient: !!p.gradient, layout: !!p.layout, live: {}, shareSeen: {}, comp })
13178
13248
  // 各屏一起改默认勾不勾:问服务端各屏带这个 class 的是不是都同一种(问到之前不勾)
13179
13249
  if (!fileTarget) return
13180
13250
  const seen = new Map()
@@ -13198,12 +13268,12 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13198
13268
  located = new Map(items.map((x, i) => [`${x.href}|${x.sel}|${x.n}`, r && Array.isArray(r.items) ? r.items[i] : null]))
13199
13269
  } catch { /* 找不到行号就只写文件名 */ }
13200
13270
  }
13201
- insert(formatStyleAsk(t, s0, stRef.current, located), 'insertedSend')
13271
+ insert(formatStyleAsk(t, s0, stRef.current, located) + (typeof s0.comp === 'string' ? t('styleAskComp', { name: s0.comp }) : ''), 'insertedSend')
13202
13272
  }
13203
13273
  const saveStyle = () => {
13204
13274
  const s0 = sty
13205
13275
  if (!s0 || !Object.keys(s0.live).length) return
13206
- if (!fileTarget) return askStyle()
13276
+ if (!fileTarget || s0.comp) return askStyle()
13207
13277
  const saved = s0.live
13208
13278
  const tk = targetKey // 点保存时是哪套设计:两次保存(规则不行退回行内)都带上,中途换了设计服务端就不写
13209
13279
  // src:写完以后这几项由谁决定(行内 / 那条规则)、带不带 !important。面板不重新选也照这个算下一次(不然还按旧的带不带 !important)
@@ -13221,6 +13291,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13221
13291
  const inline = () => post('style', { session: sid, target: tk, key: s0.key, loc: s0.loc, css: saved, name: s0.name, ...(imp.length ? { imp } : {}) }).then((r) => {
13222
13292
  if (r && r.ok) done(r, t('styleSaved', { file: r.file }), (k, v) => ({ ...v, inline: true, imp: imp.includes(k) }))
13223
13293
  else if (r && r.reason === 'busy') say(t('styleBusyTip'))
13294
+ else if (r && r.reason === 'comp') askStyle() // 服务端才发现用了组件:直接交给模型(插进输入框那一下自己会说)
13224
13295
  else if (r && r.reason === 'moved') say(t('styleMoved'))
13225
13296
  else { sayErr(t('styleMiss')); askStyle() }
13226
13297
  }, () => askStyle())
@@ -13232,6 +13303,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13232
13303
  if (r && r.ok) done(r, r.others ? t('styleSavedOthers', { file: r.file || at.file, sel: at.sel, n: r.others }) : t('styleSavedRule', { file: r.file || at.file, sel: at.sel }), (k, v) => ({ ...v, sel: rule.sel, href: rule.href, n: rule.n, cls: rule.cls, inline: false, imp: Array.isArray(r.imp) && r.imp.includes(k) }))
13233
13304
  else if (r && r.reason === 'busy') say(t('styleBusyTip'))
13234
13305
  else if (r && r.reason === 'moved') say(t('styleMoved'))
13306
+ else if (r && r.reason === 'comp') askStyle() // 服务端才发现用了组件:直接交给模型(插进输入框那一下自己会说)
13235
13307
  else inline()
13236
13308
  }, () => inline())
13237
13309
  }
@@ -13351,6 +13423,8 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13351
13423
  const [picking, setPicking] = useState(false)
13352
13424
  const [textEdit, setTextEdit] = useState(false) // 改字:点页面里的文字直接改
13353
13425
  const [txOn, setTxOn] = useState(false) // 改字时页面里正点开一段字在改
13426
+ const [txComp, setTxComp] = useState(false) // 正在改的那屏用了组件(#30):回车是交给模型,不是保存
13427
+ const onTxEditing = (on, comp) => { setTxOn(on); if (on) setTxComp(!!comp) }
13354
13428
  const [txLog, setTxLog] = useState([]) // 这次改字写回了哪几处(撤销用):[{ key, before, after, nth }]
13355
13429
  const textEditR = useRef(false)
13356
13430
  textEditR.current = textEdit
@@ -13389,6 +13463,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
13389
13463
  if (!brandMem.current) brandMem.current = loadBrands()
13390
13464
  const [hist, setHist] = useState(false) // 版本面板
13391
13465
  const [versions, setVersions] = useState([])
13466
+ const [verSkip, setVerSkip] = useState(null) // 最近一次版本没存成(目录太大)
13392
13467
  const [ver, setVer] = useState(null) // 正在看的旧版本
13393
13468
  const [cmp, setCmp] = useState(false) // 和现在左右对比
13394
13469
  const [cx, setCx] = useState(50)
@@ -14017,7 +14092,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14017
14092
  let dead = false
14018
14093
  fetch(`${API}history?session=${encodeURIComponent(sid)}`, { credentials: 'same-origin', cache: 'no-store' })
14019
14094
  .then((r) => r.json())
14020
- .then((d) => { if (!dead) setVersions(Array.isArray(d.versions) ? d.versions : []) }, () => {})
14095
+ .then((d) => { if (!dead) { setVersions(Array.isArray(d.versions) ? d.versions : []); setVerSkip(d.skip && typeof d.skip === 'object' ? d.skip : null) } }, () => {})
14021
14096
  return () => { dead = true }
14022
14097
  }, [hist, sid, vrev, origin])
14023
14098
 
@@ -14091,7 +14166,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14091
14166
  setTextEdit(true)
14092
14167
  }
14093
14168
 
14094
- const askText = (sc, d) => insert(t('textAsk', { before: d.before, after: d.after, where: whereOf(pageOf(sc, d.href).url, stRef.current) }), 'insertedSend')
14169
+ const askText = (sc, d) => insert(t('textAsk', { before: d.before, after: d.after, where: whereOf(pageOf(sc, d.href).url, stRef.current) }) + (typeof d.comp === 'string' && /^[a-z][a-z0-9-]*$/.test(d.comp) ? t('textAskComp', { name: d.comp }) : ''), 'insertedSend')
14095
14170
 
14096
14171
  // 改字开着时写回了不弹消息(会挤掉灵动条上方的「这次改了几处 · 撤销」),关掉后那一下才弹
14097
14172
  const onEdited = (sc, d) => {
@@ -14352,7 +14427,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14352
14427
  onCancelled: () => setPicking(false),
14353
14428
  onEdited: (d) => onEdited(sc, d),
14354
14429
  onEditDone: () => setTextEdit(false),
14355
- onEditing: setTxOn,
14430
+ onEditing: onTxEditing,
14356
14431
  lang: t('lang'),
14357
14432
  onNote: (n) => note(n, sc),
14358
14433
  onMeta: (m, title, toks, dk, links, nat, err, ext) => remember(ik(sc), m, title, toks, dk, links, nat, err, ext),
@@ -14410,7 +14485,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
14410
14485
  const every = hidSig && hid.sig === hidSig ? everyOf(shown, hid.list) : shown
14411
14486
  // 导出用:某屏写了哪几个状态(本地文件问服务端的;别的用页面报上来的)
14412
14487
  const statesForX = (key) => (fileTarget ? (xStates && xStates.target === targetKey && xStates.map[key]) || [] : statesOf(key))
14413
- const { withFrames, measureAll, precheck, exportShots, exportHtml, htmlBody, loadEvery } = makeExporter({ apiOf, targetKey, sid, st, kind, size, dark, meta, tokens, t, say, canvas: canvas && !implSc, focus: implSc ? implSc.key : focus, sel, shown, every, loadHidden, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned, tops, tweak, webFit, statesFor: statesForX, loadStates: fileTarget ? () => post('states', { session: sid }).then((d) => (d && d.map && typeof d.map === 'object' ? d.map : {})) : null,
14488
+ const { withFrames, measureAll, precheck, exportShots, exportHtml, htmlBody, loadEvery } = makeExporter({ apiOf, targetKey, sid, st, kind, size, dark, meta, tokens, t, say, canvas: canvas && !implSc, focus: implSc ? implSc.key : focus, sel, shown, every, loadHidden, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned, tops, tweak, webFit, statesFor: statesForX, loadStates: fileTarget ? () => post('states', { session: sid }).then((d) => (d && d.map && typeof d.map === 'object' ? d.map : {})) : null, openKey: (key) => { setPane(''); openByUser(key) },
14414
14489
  onWarn: (mode) => { setXFmt(mode === 'pptx' ? 'pptx' : 'pdf'); if (pane !== 'export') openPane('export') } })
14415
14490
  // 换了设计:导出面板里挑的屏不算了,回到「全部」
14416
14491
  useEffect(() => { setXo((o) => (o.scope && o.scope !== 'all' ? { ...o, scope: 'all', pick: [] } : o)) }, [targetKey])
@@ -15152,13 +15227,13 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
15152
15227
  const sheetBody = () => {
15153
15228
  const hd = (o) => sheetHead(t, { onClose: closeSheet, ...o })
15154
15229
  if (sheet === 'style') {
15155
- const okW = !!fileTarget && !busy
15230
+ const okW = !!fileTarget && !busy && !(sty && sty.comp) // 用了组件的屏不写文件(#30):「只改这一个 / 各屏一起改」没意义,不显示
15156
15231
  return h(StylePanel, {
15157
15232
  t,
15158
15233
  head: hd({ icon: I.sliders, title: t('style'), help: t('styleHelp'), sub: styleSub(t, sty), subTip: sty ? `${sty.name} · ${sty.selector}` : '', seg: styleSeg(t, sty, okW, (on) => setSty((c) => (c ? { ...c, shared: on } : c))) }),
15159
15234
  sty,
15160
15235
  tokens: (sty && (infoOf(sty.key) || {}).tokens) || tokens,
15161
- write: !fileTarget ? { ok: false, tip: t('styleNoWrite') } : busy ? { ok: false, tip: t('styleBusyTip') } : { ok: true, tip: t('styleSaveTip') },
15236
+ write: !fileTarget ? { ok: false, tip: t('styleNoWrite') } : sty && sty.comp ? { ok: false, tip: t('styleComp') } : busy ? { ok: false, tip: t('styleBusyTip') } : { ok: true, tip: t('styleSaveTip') },
15162
15237
  onSet: setStyleProp,
15163
15238
  onReset: () => setSty((c) => (c ? { ...c, live: {} } : c)),
15164
15239
  onAsk: askStyle,
@@ -15234,7 +15309,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
15234
15309
  // 地址带上项目目录和存版时间:同一会话换过项目(都有 home.html 第 1 版)时,浏览器缓存别把上一套的图当成这一套
15235
15310
  const thumb = fileTarget && sid ? (n, key, at) => `${API}verthumb?session=${encodeURIComponent(sid)}&root=${encodeURIComponent(curRoot)}&at=${at || 0}&n=${n}&key=${encodeURIComponent(key)}&${sz}` : null
15236
15311
  const nowThumb = fileTarget && sid ? { screens: screens.map((x) => x.key), url: (key) => `${API}scrthumb?session=${encodeURIComponent(sid)}&root=${encodeURIComponent(curRoot)}&${sz}&r=${(st && st.changedAt) || 0}&key=${encodeURIComponent(key)}` } : null
15237
- return h(HistoryPanel, { t, head: hd({ icon: I.history, title: t('history'), help: t('histHelp'), sub: versions.length ? t('histSub', { n: versions.length }) : '' }), versions, ver, thumb, nowThumb, curKey: focus || (screens[0] && screens[0].key) || '', tall: size[1] > size[0], onPick: (v) => { setVer(v); if (!v) setCmp(false) } })
15312
+ return h(HistoryPanel, { t, head: hd({ icon: I.history, title: t('history'), help: t('histHelp'), sub: versions.length ? t('histSub', { n: versions.length }) : '' }), versions, ver, thumb, nowThumb, curKey: focus || (screens[0] && screens[0].key) || '', tall: size[1] > size[0], skip: verSkip, onPick: (v) => { setVer(v); if (!v) setCmp(false) } })
15238
15313
  }
15239
15314
  if (sheet === 'share') {
15240
15315
  const tabs = [['phone', t('phoneShort'), I.scan], ...(fileTarget ? [['pub', t('pubShort'), I.web], ['demo', t('demoHtml'), I.box], ['submit', t('subT'), I.share]] : [])]
@@ -15577,7 +15652,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
15577
15652
  onCancelled: () => setPicking(false),
15578
15653
  onEdited: (d) => onEdited(base, d),
15579
15654
  onEditDone: () => setTextEdit(false),
15580
- onEditing: setTxOn,
15655
+ onEditing: onTxEditing,
15581
15656
  lang: t('lang'),
15582
15657
  onNote: (n) => note(n, base),
15583
15658
  onTop: (dk) => setTop(ik(base) + '|st' + i, dk),
@@ -15618,7 +15693,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
15618
15693
  onCancelled: () => setPicking(false),
15619
15694
  onEdited: (d) => onEdited(base, d),
15620
15695
  onEditDone: () => setTextEdit(false),
15621
- onEditing: setTxOn,
15696
+ onEditing: onTxEditing,
15622
15697
  lang: t('lang'),
15623
15698
  onNote: (n) => note(n, base),
15624
15699
  onTop: (dk) => setTop(ik(base) + '|' + i, dk),
@@ -15764,7 +15839,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
15764
15839
  // 提示只占一个位置:有新消息(toast)时它先让开,消息走了再回来
15765
15840
  textEdit && !toast ? h('div', { className: 'ddp-hint dd-msg dd-tip2 dd-edbar' + (txOn ? ' on' : ''), role: 'status' },
15766
15841
  txOn
15767
- ? h('span', { className: 'ks', key: 'k' }, h('span', null, h('kbd', null, '↵'), t('edSave')), h('span', null, h('kbd', null, 'Esc'), t('edCancel')))
15842
+ ? h('span', { className: 'ks', key: 'k' }, txComp ? h('span', null, t('edComp')) : null, h('span', null, h('kbd', null, '↵'), t(txComp ? 'edAsk' : 'edSave')), h('span', null, h('kbd', null, 'Esc'), t('edCancel')))
15768
15843
  : h('span', { className: 'tx', key: 't' }, hintText),
15769
15844
  txLog.length ? h('i', { className: 'sep' }) : null,
15770
15845
  txLog.length ? h('span', { className: 'n' }, t('edN', { n: txLog.length })) : null,