soma-kit 0.1.18 → 0.1.19

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.
Files changed (53) hide show
  1. package/package.json +1 -1
  2. package/spec/generated/kit-page.schema.json +11 -1
  3. package/spec/kit-grammar.json +133 -13
  4. package/spec/kit-grammar.schema.json +4 -0
  5. package/src/app/component-gate.ts +247 -16
  6. package/src/app/index.ts +4 -1
  7. package/src/app/kit-view-context.ts +44 -2
  8. package/src/app/server.ts +11 -2
  9. package/src/biz/compose.ts +66 -0
  10. package/src/biz/define.ts +8 -0
  11. package/src/biz/index.ts +1 -0
  12. package/src/biz/layout-contracts.ts +119 -4
  13. package/src/biz/link/hub.ts +31 -0
  14. package/src/biz/master-sub/compile.ts +45 -3
  15. package/src/biz/master-sub/index.ts +3 -1
  16. package/src/biz/record-detail/compile.ts +120 -10
  17. package/src/biz/shared/coordinator.ts +245 -48
  18. package/src/biz/shared/index.ts +5 -1
  19. package/src/biz/shared/object-aliases.ts +14 -3
  20. package/src/biz/shared/overlay-compile.ts +56 -5
  21. package/src/biz/shared/overlay-shell.ts +5 -2
  22. package/src/biz/shared/page-form.ts +9 -5
  23. package/src/biz/shared/page-overlay-host.ts +126 -0
  24. package/src/biz/shared/page-overlay-names.ts +27 -0
  25. package/src/biz/shared/runtime-hub.ts +37 -2
  26. package/src/biz/single-form/compile.ts +60 -5
  27. package/src/biz/single-form/index.ts +2 -1
  28. package/src/biz/standard-crud/compile.ts +9 -2
  29. package/src/biz/types.ts +18 -0
  30. package/src/cli/kit-cli.ts +1 -0
  31. package/src/cli/view-writes.ts +130 -3
  32. package/src/compile/compile-page.ts +49 -4
  33. package/src/compile/page-pipeline.ts +4 -0
  34. package/src/compile/parse.ts +14 -0
  35. package/src/compile/stages.ts +5 -4
  36. package/src/compile/types.ts +1 -1
  37. package/src/compile/view-check.ts +49 -17
  38. package/src/data/comment-thread.ts +78 -18
  39. package/src/data/navbar.ts +4 -0
  40. package/src/data/object-form.ts +17 -3
  41. package/src/data/prompt-dialog.ts +102 -15
  42. package/src/frames/page-header.ts +11 -2
  43. package/src/frames/shared.ts +6 -0
  44. package/src/frames/types.ts +2 -0
  45. package/src/generated/kit-grammar-runtime.ts +43 -5
  46. package/src/i18n/kit-text.ts +1 -0
  47. package/src/object-renderer/request-actions.ts +145 -17
  48. package/src/object-renderer/types.ts +7 -0
  49. package/src/shared/dom-attrs-registry.ts +5 -3
  50. package/src/shared/dom-attrs.ts +2 -0
  51. package/src/spatial/declared-actions.ts +6 -3
  52. package/src/spatial/emit.ts +1 -1
  53. package/src/spatial/expand.ts +7 -2
@@ -3,13 +3,16 @@
3
3
  // 数据:`data` 是 [{ id, author, time, text, avatar?, likes? }];键名可由 `map` 改写。
4
4
  // 发布框草稿在组件内(只在一个组件内流转归该组件),不进区域切片:
5
5
  // 点「发表」或 Ctrl/Cmd+Enter 抛 `send { text }`(已 trim,空串不抛,超出 max_length 的部分截断),随后清空草稿;
6
- // `sending` 为真时发布框禁用。点「回复」抛 `reply { id }`;`likable` 为真时每条有赞钮,抛 `like { id }`。
7
- // `readonly` 为真时不出发布框。重绘只重画评论列表,不动发布框(保住草稿与焦点)。
6
+ // `sending` 为真时发布框禁用;`stoppable` 为真且 `sending` 时底栏出「停止」钮,抛 `stop {}`(取消等待由页面处理)。
7
+ // 点「回复」抛 `reply { id }`;`likable` 为真时每条有赞钮,抛 `like { id }`。
8
+ // `readonly` 为真时不出发布框;`disabled` 为真时保留发布框但输入框与各钮禁用,`disabled_reason` 显示在输入框下方(readonly 优先)。
9
+ // 角色标签:数据 `role` 非空时 thread 与 chat 两种变体都在作者旁画小标签,`tone` 给语气(neutral / primary / info / success / warning / danger)。
10
+ // 重绘只重画评论列表,不动发布框(保住草稿与焦点)。
8
11
 
9
12
  import { kitApplyLevelClass } from './level-class';
10
13
  import type { SomaComponentDefinition } from 'soma-core';
11
14
  import { matchSubmitKey } from 'soma-core/keyboard';
12
- import { bool, createKitController, formatValue, joinClass, num, str, toggleKitHidden } from '../base/shared';
15
+ import { bool, createKitController, formatValue, joinClass, nextUid, num, str, toggleKitHidden } from '../base/shared';
13
16
  import { kitText } from '../i18n/kit-text';
14
17
  import { setKitFace } from '../recipes';
15
18
  import { KIT_FOCUS_RING } from '../recipes/state';
@@ -30,7 +33,7 @@ import { wireMenu, type MenuItemSpec } from '../base/menu-core';
30
33
  import { KIT_MENU_BUTTON_CLASS_CANDIDATES, KIT_MENU_ITEM_CLASSES, KIT_MENU_PANEL } from '../base/menu-button';
31
34
  import { KIT_POPUP_PLACE_CLASS_CANDIDATES, type PopPlace } from '../base/popup';
32
35
  import { createPanelPortal, KIT_PANEL_PORTAL_CLASS_CANDIDATES } from './overlay-portal';
33
- import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, rowsOf, textOf } from './shape-util';
36
+ import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, rowsOf, shapeToneOf, textOf, type ShapeTone } from './shape-util';
34
37
  import { kitMarkDataFacts, kitMarkLevel, kitMarkPart } from './kit-contract';
35
38
  import { attrEsc, AVATAR_CLASS_TOKENS, avatarNode } from './d9-util';
36
39
  import { CHAT_FOLLOW_RATIO, CHAT_MAX_LENGTH, CHAT_MAX_MESSAGES, CHAT_STATUSES } from './d9-limits';
@@ -39,13 +42,15 @@ import {
39
42
  KIT_ATTR_ACTION, KIT_ATTR_ANCHOR, KIT_ATTR_ATTACH, KIT_ATTR_CANCEL, KIT_ATTR_COMMENT, KIT_ATTR_COMPOSER, KIT_ATTR_COMPOSER_AVATAR,
40
43
  KIT_ATTR_CONTAINER, KIT_ATTR_COUNT, KIT_ATTR_DELETED, KIT_ATTR_EARLIER, KIT_ATTR_EDITED, KIT_ATTR_GROUP, KIT_ATTR_LIKE, KIT_ATTR_LIST,
41
44
  KIT_ATTR_LOADING, KIT_ATTR_MENTION, KIT_ATTR_MORE, KIT_ATTR_NEW, KIT_ATTR_ORDER, KIT_ATTR_ORDER_GIVEN, KIT_ATTR_RELOAD, KIT_ATTR_REPLIES,
42
- KIT_ATTR_REPLIES_KEY, KIT_ATTR_REPLIES_LABEL, KIT_ATTR_REPLIES_TOGGLE, KIT_ATTR_REPLY, KIT_ATTR_REPLY_OF, KIT_ATTR_RETRY, KIT_ATTR_SEND,
43
- KIT_ATTR_SIDE, KIT_ATTR_SORT, KIT_ATTR_STAMP, KIT_ATTR_STATUS, KIT_ATTR_THREAD_HEAD, KIT_ATTR_UNREAD, kitAttrHtml, kitAttrSel,
45
+ KIT_ATTR_REASON, KIT_ATTR_REPLIES_KEY, KIT_ATTR_REPLIES_LABEL, KIT_ATTR_REPLIES_TOGGLE, KIT_ATTR_REPLY, KIT_ATTR_REPLY_OF, KIT_ATTR_RETRY,
46
+ KIT_ATTR_SEND, KIT_ATTR_SIDE, KIT_ATTR_SORT, KIT_ATTR_STAMP, KIT_ATTR_STATUS, KIT_ATTR_STOP, KIT_ATTR_THREAD_HEAD, KIT_ATTR_UNREAD,
47
+ kitAttrHtml, kitAttrSel,
44
48
  } from '../shared/dom-attrs';
45
49
 
46
50
  export const KIT_COMMENT_DEFAULT_MAP = Object.freeze({
47
51
  id: 'id', author: 'author', time: 'time', text: 'text', avatar: 'avatar', likes: 'likes', mine: 'mine', status: 'status',
48
52
  parent: 'parent', replies: 'replies', edited: 'edited', deleted: 'deleted', role: 'role', can_edit: 'can_edit', can_delete: 'can_delete',
53
+ tone: 'tone',
49
54
  });
50
55
 
51
56
  // variant: chat(对话气泡):同一份数据形状,评论项换成左右对齐的气泡,Enter 发送、Shift+Enter 换行,另有附件钮与失败重试
@@ -54,6 +59,8 @@ const CHAT_MSG_MINE = 'flex-row-reverse';
54
59
  const CHAT_COL = 'flex min-w-0 max-w-xl flex-col gap-1';
55
60
  const CHAT_COL_MINE = 'items-end';
56
61
  const CHAT_NAME = mergeClass(mergeClass('px-1', kitTypographyRecipe('captionPlain')), 'text-fg-muted');
62
+ // chat 变体的名字行:作者名 + 角色小标签(数据 role 非空才出这一行容器;没有 role 时仍只画作者名,DOM 与旧版一致)
63
+ const CHAT_HEAD = 'flex flex-wrap items-center gap-1';
57
64
  const CHAT_BUBBLE = 'whitespace-pre-wrap break-words rounded-card px-3 py-2';
58
65
  // 对方气泡 = 子块底色令牌(--soma-layer-sub),不直写井色;子块工具类带同心圆角会盖掉气泡尾角,故只取其底色类
59
66
  const CHAT_THEM = 'rounded-es-item bg-layer-sub text-fg';
@@ -75,7 +82,7 @@ const CHAT_ATTACH = kitEmphasisButtonRecipe('button.toolbar');
75
82
  const CHAT_NEW = mergeClass(mergeClass('self-center rounded-full bg-primary px-3 py-1 text-primary-fg shadow-md transition-opacity hover:opacity-90', kitTypographyRecipe('deltaSm')), KIT_FOCUS_RING.button);
76
83
  const CHAT_CLASS_TOKENS = classTokens(
77
84
  CHAT_MSG, CHAT_MSG_MINE, CHAT_COL, CHAT_COL_MINE, CHAT_NAME, CHAT_BUBBLE, CHAT_THEM, CHAT_ME, CHAT_META, CHAT_META_FAILED, CHAT_RETRY,
78
- CHAT_LIST, CHAT_ATTACH, CHAT_NEW, AVATAR_CLASS_TOKENS, CHAT_GROUP, CHAT_STAMP, CHAT_AVATAR_GAP, CHAT_STATUS_ICON,
85
+ CHAT_LIST, CHAT_ATTACH, CHAT_NEW, AVATAR_CLASS_TOKENS, CHAT_GROUP, CHAT_STAMP, CHAT_AVATAR_GAP, CHAT_STATUS_ICON, CHAT_HEAD,
79
86
  );
80
87
 
81
88
  const ROOT_CLASS = mergeClass('flex flex-col gap-4', kitTypographyRecipe('text'));
@@ -87,6 +94,9 @@ const SORT_BUTTON_CLASS = kitPlainActionRecipe('sort', { shape: 'button', tight:
87
94
  const REPLIES_CLASS = 'mt-2 flex flex-col gap-3 ps-control-lg';
88
95
  const REPLY_TOGGLE_CLASS = kitPlainActionRecipe('expand', { shape: 'button', tight: true });
89
96
  const ROLE_TAG_CLASS = kitMarkRecipe('tone', 'neutral');
97
+ /** 角色标签按数据 tone 取语气淡底(缺省 neutral = ROLE_TAG_CLASS) */
98
+ const ROLE_TAG_TONES: readonly ShapeTone[] = ['neutral', 'primary', 'info', 'success', 'warning', 'danger'];
99
+ const roleTagClass = (tone: ShapeTone): string => kitMarkRecipe('tone', tone);
90
100
  const EDITED_CLASS = kitTypographyRecipe('captionPlain');
91
101
  const DELETED_CLASS = 'text-fg-subtle';
92
102
  const MENTION_CLASS = kitMarkRecipe('tone', 'primary');
@@ -106,11 +116,14 @@ const COMPOSER_ROW_CLASS = 'flex gap-3';
106
116
  const COMPOSER_MAIN_CLASS = 'flex min-w-0 flex-1 flex-col gap-2';
107
117
  const COMPOSER_ACTIONS_CLASS = 'flex items-center gap-2';
108
118
  const CANCEL_BUTTON_CLASS = kitActionRecipe('cancel', { size: 'sm' });
119
+ // 禁用原因(disabled_reason):输入框下方一行说明小字
120
+ const REASON_CLASS = mergeClass(kitTypographyRecipe('captionPlain'), 'text-fg-muted');
109
121
  const THREAD_CLASS_TOKENS = classTokens(
110
122
  THREAD_HEAD_CLASS, THREAD_TITLE_CLASS, SORT_BUTTON_CLASS, REPLIES_CLASS, REPLY_TOGGLE_CLASS, ROLE_TAG_CLASS, EDITED_CLASS, DELETED_CLASS,
111
123
  MENTION_CLASS, ANCHOR_CLASS, MORE_WRAP_CLASS, MORE_TRIGGER_CLASS, MORE_SHOWN, 'hidden', LOAD_EARLIER_CLASS, LOAD_EARLIER_ROW_CLASS,
112
124
  SKELETON_ROW_CLASS, SKELETON_AVATAR_CLASS, SKELETON_LINES_CLASS, KIT_SKELETON_BAR_LINE, KIT_SKELETON_BAR_TITLE_MAIN, KIT_SKELETON_BAR_TITLE_SUB,
113
125
  ERROR_BAR_CLASS, ERROR_RETRY_CLASS, COMPOSER_ROW_CLASS, COMPOSER_MAIN_CLASS, COMPOSER_ACTIONS_CLASS, CANCEL_BUTTON_CLASS,
126
+ REASON_CLASS, ROLE_TAG_TONES.map(roleTagClass),
114
127
  KIT_ICON_CLASS_CANDIDATES, Object.values(KIT_MENU_ITEM_CLASSES), KIT_MENU_BUTTON_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, KIT_PANEL_PORTAL_CLASS_CANDIDATES,
115
128
  );
116
129
  // 评论项间距 20、头像 32(取值表 06「评论列表」:Ant Comment / Arco / TDesign 头像 32、项距 16–24 取中)
@@ -150,8 +163,10 @@ export interface KitCommentEntry {
150
163
  status: string;
151
164
  /** 上级评论 id(空 = 顶层);回复只嵌一级,更深的挂到顶层祖先 */
152
165
  parent: string;
153
- /** 作者角色标签(评论流 meta 行) */
166
+ /** 作者角色 / 消息类型标签(thread 变体 meta 行、chat 变体名字行) */
154
167
  role: string;
168
+ /** 角色标签语气(数据 tone,闭集外与缺省为 neutral) */
169
+ tone: ShapeTone;
155
170
  /** 已编辑:真值 = 画「已编辑」;字符串(编辑时间)同时作悬停提示 */
156
171
  edited: string;
157
172
  /** 已删除:画占位并保留回复结构,无正文无动作 */
@@ -217,6 +232,7 @@ export function commentEntriesOf(data: unknown, mapRaw: unknown, timeFormat = ''
217
232
  return {
218
233
  parent,
219
234
  role: textOf(raw[m.role]),
235
+ tone: shapeToneOf(raw[m.tone]),
220
236
  edited: edited === true || edited === 'true' ? '1' : typeof edited === 'string' || typeof edited === 'number' ? textOf(edited) : '',
221
237
  deleted: raw[m.deleted] === true || raw[m.deleted] === 'true',
222
238
  canEdit: raw[m.can_edit] === true || raw[m.can_edit] === 'true',
@@ -251,6 +267,8 @@ interface Composer {
251
267
  composer: HTMLElement;
252
268
  avatarSlot: HTMLElement;
253
269
  actions: HTMLElement;
270
+ /** 禁用原因行(disabled 且 disabled_reason 非空才显示) */
271
+ reason: HTMLElement;
254
272
  }
255
273
 
256
274
  /** 输入框行数随内容长高:行数夹在真源 kit-limits#dataLimits.commentThread 的 composerMinRows 到 composerMaxRows,超出在框内滚动 */
@@ -323,9 +341,13 @@ export function createCommentThread(): SomaComponentDefinition {
323
341
  data: { type: 'array', default: [], desc: '评论 [{ id, author, time, text, avatar?, likes? }]' },
324
342
  map: { type: 'object', default: {}, desc: '键名对照:id / author / time / text / avatar / likes -> 数据里的键' },
325
343
  sending: { type: 'boolean', default: false, desc: '发送中:发布框与发表钮禁用' },
326
- readonly: { type: 'boolean', default: false, desc: '不出发布框' },
344
+ readonly: { type: 'boolean', default: false, desc: '不出发布框(优先于 disabled)' },
345
+ disabled: { type: 'boolean', default: false, desc: '保留发布框但禁用:输入框、发表 / 附件 / 取消钮都禁用,不抛 send;readonly 为真时不生效' },
346
+ disabled_reason: { type: 'string', default: '', desc: 'disabled 为真时显示在输入框下方的原因说明(空则不出这一行)' },
347
+ stoppable: { type: 'boolean', default: false, desc: 'sending 为真时底栏出「停止」钮,点击抛 stop(取消等待);缺省关闭' },
348
+ stop_text: { type: 'string', default: '', desc: '停止钮文案,空取缺省文案' },
327
349
  likable: { type: 'boolean', default: false, desc: '每条出赞钮,抛 like' },
328
- variant: { type: 'enum', values: ['thread', 'chat'], default: 'thread', desc: 'thread = 评论流;chat = 对话气泡(左右对齐、状态与重试、Enter 发送 Shift+Enter 换行,数据多 mine / status 两键)' },
350
+ variant: { type: 'enum', values: ['thread', 'chat'], default: 'thread', desc: 'thread = 评论流;chat = 对话气泡(左右对齐、状态与重试、Enter 发送 Shift+Enter 换行,数据多 mine / status 两键);两种变体都认 role(作者旁小标签)与 tone(标签语气)' },
329
351
  me: { type: 'string', default: '', desc: 'chat 变体:当前用户的 author 值,author 等于它的消息靠右(也可数据里给 mine)' },
330
352
  show_list: { type: 'boolean', default: true, desc: '假 = 只出输入区不出消息列表(仅输入区的用法)' },
331
353
  attachable: { type: 'boolean', default: false, desc: 'chat 变体:输入区出附件钮,抛 attach' },
@@ -373,6 +395,7 @@ export function createCommentThread(): SomaComponentDefinition {
373
395
  load_earlier: { payload: {}, desc: '点列表顶部「加载更早」' },
374
396
  sort: { payload: { order: { type: 'string' } }, desc: '点线程头排序切换(asc / desc)' },
375
397
  cancel: { payload: {}, desc: '点发布框「取消」' },
398
+ stop: { payload: {}, desc: '发送在途(sending)时点「停止」(stoppable 时):取消等待由页面接具名动作或展示对象方法处理' },
376
399
  edit: { payload: { id: { type: 'string' } }, desc: '「更多」菜单选编辑' },
377
400
  delete: { payload: { id: { type: 'string' } }, desc: '「更多」菜单选删除' },
378
401
  },
@@ -385,7 +408,7 @@ export function createCommentThread(): SomaComponentDefinition {
385
408
  const c = parts.get(root);
386
409
  if (!c) return;
387
410
  const p = api.props();
388
- if (bool(p.sending) || bool(p.readonly)) return;
411
+ if (bool(p.sending) || bool(p.readonly) || bool(p.disabled)) return;
389
412
  const text = draftToSend(c.area.value, num(p.max_length) ?? 500);
390
413
  if (text === null) return;
391
414
  api.emit('send', { text });
@@ -401,7 +424,8 @@ export function createCommentThread(): SomaComponentDefinition {
401
424
  root.querySelector(kitAttrSel(KIT_ATTR_NEW))?.remove();
402
425
  return;
403
426
  }
404
- if (target?.closest(kitAttrSel(KIT_ATTR_ATTACH))) { if (!bool(api.props().sending)) api.emit('attach', {}); return; }
427
+ if (target?.closest(kitAttrSel(KIT_ATTR_ATTACH))) { const q = api.props(); if (!bool(q.sending) && !bool(q.disabled)) api.emit('attach', {}); return; }
428
+ if (target?.closest(kitAttrSel(KIT_ATTR_STOP))) { const q = api.props(); if (bool(q.sending) && bool(q.stoppable) && !bool(q.disabled)) api.emit('stop', {}); return; }
405
429
  if (target?.closest(kitAttrSel(KIT_ATTR_RELOAD))) { api.emit('reload', {}); return; }
406
430
  if (target?.closest(kitAttrSel(KIT_ATTR_EARLIER))) { api.emit('load_earlier', {}); return; }
407
431
  if (target?.closest(kitAttrSel(KIT_ATTR_SORT))) {
@@ -412,6 +436,7 @@ export function createCommentThread(): SomaComponentDefinition {
412
436
  return;
413
437
  }
414
438
  if (target?.closest(kitAttrSel(KIT_ATTR_CANCEL))) {
439
+ if (bool(api.props().disabled)) return;
415
440
  const c = parts.get(root);
416
441
  if (c) { c.area.value = ''; syncComposer(c, api.props()); }
417
442
  api.emit('cancel', {});
@@ -497,6 +522,11 @@ export function createCommentThread(): SomaComponentDefinition {
497
522
  setKitFace(area, 'field');
498
523
  kitMarkPart(area, 'control');
499
524
  area.rows = COMPOSER_MIN_ROWS;
525
+ // 禁用原因行:建一次,按 disabled / disabled_reason 显隐
526
+ const reason = mk('p', REASON_CLASS);
527
+ reason.id = nextUid('kit-ct-reason');
528
+ reason.setAttribute(KIT_ATTR_REASON, '');
529
+ toggleKitHidden(reason, true);
500
530
  const foot = mk('div', COMPOSER_FOOT);
501
531
  // 发布框底栏(计数 + 取消 / 发表)
502
532
  kitMarkLevel(foot, 'foot'); kitApplyLevelClass(foot);
@@ -509,13 +539,14 @@ export function createCommentThread(): SomaComponentDefinition {
509
539
  foot.appendChild(counter);
510
540
  foot.appendChild(actions);
511
541
  main.appendChild(area);
542
+ main.appendChild(reason);
512
543
  main.appendChild(foot);
513
544
  composer.appendChild(avatarSlot);
514
545
  composer.appendChild(main);
515
546
  root.textContent = '';
516
547
  root.appendChild(list);
517
548
  root.appendChild(composer);
518
- c = { area, send, counter, list, composer, avatarSlot, actions };
549
+ c = { area, send, counter, list, composer, avatarSlot, actions, reason };
519
550
  parts.set(root, c);
520
551
  }
521
552
 
@@ -655,7 +686,16 @@ export function createCommentThread(): SomaComponentDefinition {
655
686
  kitMarkLevel(row, 'item', 'line'); kitApplyLevelClass(row);
656
687
  if (!e.mine) row.appendChild(sameSender ? mk('span', CHAT_AVATAR_GAP) : avatarNode(e.author, e.avatar, 'md'));
657
688
  const col = mk('div', e.mine ? `${CHAT_COL} ${CHAT_COL_MINE}` : CHAT_COL);
658
- if (!e.mine && !sameSender && e.author !== '') col.appendChild(mk('span', CHAT_NAME, e.author));
689
+ const showName = !e.mine && !sameSender && e.author !== '';
690
+ if (e.role === '') {
691
+ if (showName) col.appendChild(mk('span', CHAT_NAME, e.author));
692
+ } else {
693
+ // 有消息类型 / 角色:名字行 = 作者名(同组首条、对方消息才有)+ 小标签(每条都出,自己的消息随列靠右)
694
+ const headRow = mk('div', CHAT_HEAD);
695
+ if (showName) headRow.appendChild(mk('span', CHAT_NAME, e.author));
696
+ headRow.appendChild(mk('span', roleTagClass(e.tone), e.role));
697
+ col.appendChild(headRow);
698
+ }
659
699
  col.appendChild(mk('p', `${CHAT_BUBBLE} ${e.mine ? CHAT_ME : CHAT_THEM}`, e.text));
660
700
  if (e.status !== '') {
661
701
  // 时间戳已按组出,消息自带的只有状态:发送中 = 转圈图标、已发送 / 已读 = 对勾、失败 = 文字 + 重试
@@ -725,7 +765,7 @@ export function createCommentThread(): SomaComponentDefinition {
725
765
  const author = mk('span', AUTHOR_CLASS, e.author);
726
766
  kitMarkPart(author, 'field-name');
727
767
  head.appendChild(author);
728
- if (e.role !== '') head.appendChild(mk('span', ROLE_TAG_CLASS, e.role));
768
+ if (e.role !== '') head.appendChild(mk('span', e.tone === 'neutral' ? ROLE_TAG_CLASS : roleTagClass(e.tone), e.role));
729
769
  if (e.time !== '') {
730
770
  const t = mk('time', TIME_CLASS, e.time);
731
771
  if (e.iso !== '') t.setAttribute('datetime', e.iso);
@@ -832,7 +872,26 @@ export function createCommentThread(): SomaComponentDefinition {
832
872
  c.actions.insertBefore(cancel, c.actions.firstChild);
833
873
  }
834
874
  cancel.textContent = str(p.cancel_text, kitText('soma.kit.cancel', undefined, root));
875
+ cancel.disabled = bool(p.disabled);
835
876
  } else if (cancel) cancel.remove();
877
+ // 停止钮:stoppable 且 sending(且未 disabled)才有,插在发表钮前(发表钮仍最右,发送中禁用)
878
+ let stop = c.actions.querySelector<HTMLButtonElement>(kitAttrSel(KIT_ATTR_STOP));
879
+ if (bool(p.stoppable) && bool(p.sending) && !bool(p.disabled)) {
880
+ if (!stop) {
881
+ stop = mk('button', CANCEL_BUTTON_CLASS);
882
+ stop.type = 'button';
883
+ stop.setAttribute(KIT_ATTR_STOP, '');
884
+ kitMarkPart(stop, 'action');
885
+ c.actions.insertBefore(stop, c.send);
886
+ }
887
+ stop.textContent = str(p.stop_text, kitText('soma.kit.ct_stop', undefined, root));
888
+ } else if (stop) stop.remove();
889
+ // 禁用原因:disabled 且原因非空才显示,并经 aria-describedby 关联到输入框
890
+ const reasonText = bool(p.disabled) ? str(p.disabled_reason) : '';
891
+ c.reason.textContent = reasonText;
892
+ toggleKitHidden(c.reason, reasonText === '');
893
+ if (reasonText !== '') c.area.setAttribute('aria-describedby', c.reason.id);
894
+ else c.area.removeAttribute('aria-describedby');
836
895
  c.area.placeholder = str(p.placeholder, kitText('soma.kit.ct_placeholder', undefined, root));
837
896
  // maxLength 为 0 会让文本框一个字也输不进,负数直接抛 IndexSizeError:上限非正 = 不限;chat 受真源上限约束
838
897
  const maxLen = num(p.max_length) ?? 500;
@@ -848,7 +907,7 @@ export function createCommentThread(): SomaComponentDefinition {
848
907
  c.send.parentElement?.insertBefore(attach, c.send);
849
908
  }
850
909
  attach.textContent = str(p.attach_text, kitText('soma.kit.ct_attach', undefined, root));
851
- attach.disabled = bool(p.sending);
910
+ attach.disabled = bool(p.sending) || bool(p.disabled);
852
911
  } else if (attach) attach.remove();
853
912
  c.area.setAttribute('aria-label', str(p.placeholder, kitText('soma.kit.ct_placeholder', undefined, root)));
854
913
  c.send.textContent = str(p.send_text, kitText('soma.kit.ct_send', undefined, root));
@@ -861,10 +920,11 @@ export function createCommentThread(): SomaComponentDefinition {
861
920
  function syncComposer(c: Composer, p: Record<string, unknown>): void {
862
921
  c.area.rows = composerRowsOf(c.area.value);
863
922
  const sending = bool(p.sending);
923
+ const disabled = bool(p.disabled);
864
924
  const max = num(p.max_length) ?? 500;
865
- c.area.disabled = sending;
925
+ c.area.disabled = sending || disabled;
866
926
  const empty = c.area.value.trim() === '';
867
- const off = sending || empty;
927
+ const off = sending || disabled || empty;
868
928
  c.send.disabled = off;
869
929
  if (off) c.send.setAttribute('aria-disabled', 'true'); else c.send.removeAttribute('aria-disabled');
870
930
  c.counter.textContent = max > 0 ? `${c.area.value.length} / ${Math.floor(max)}` : String(c.area.value.length);
@@ -3,6 +3,7 @@
3
3
  // 数据:`data` 是 { brand?, start?, center?, end?, env?, menu_button? }:
4
4
  // - brand: { text, logo?, href? },logo 是一个短字符(缺省取品牌首字,画在主色方块里);点品牌抛 `brand`;
5
5
  // - start / center / end:左、中、右三槽,各是动作项数组 [{ id, label, icon?, badge?, href?, variant?, disabled?, children? }]:
6
+ // 可选 current: true 标当前导航项(输出 aria-current="page",不改外观;高亮仍用 variant);
6
7
  // variant 取 ghost(缺省)/ outline / primary / text(纯文字,不可点);右槽是一条条带(条带求解,载体 toolbar):放不下时
7
8
  // 除实心主钮外的动作按声明序从后往前收进末尾的「更多」下拉(容器查询,编译期估宽;旧的 show_from 固定档已删);
8
9
  // 带 children [{ id, label, disabled?, separator?, danger?, header? }] 的项是下拉菜单,点子项抛 `action { item, parent }`;
@@ -210,6 +211,9 @@ export function mountKitNavbar(root: HTMLElement, emit: KitNavbarEmit, options:
210
211
  // 可点的导航项(链接 / 按钮 / 下拉触发钮)是动作部件;纯文字项不是
211
212
  const trig = el.hasAttribute(KIT_ATTR_NAV_ITEM) ? el : el.querySelector(`:scope > ${kitAttrSel(KIT_ATTR_NAV_ITEM)}`);
212
213
  if (trig !== null) kitMarkPart(trig, 'action');
214
+ // 当前导航项(项上写 current: true,可选):可点元素(链接 / 按钮 / 下拉触发钮;纯文字项取自身)输出 aria-current="page"。
215
+ // 每次重画都新建节点,非当前项天然不带;外观仍由 variant 决定,这里只补无障碍语义
216
+ if (item.current === true) (trig ?? el).setAttribute('aria-current', 'page');
213
217
  return el;
214
218
  };
215
219
 
@@ -229,6 +229,8 @@ export interface KitObjectFormProps {
229
229
  /** 写入结果范围(`data.submit` 载荷里的 scope);缺省按对象名 */
230
230
  scope: string;
231
231
  mode: KitObjectFormMode;
232
+ /** 禁止切到 filter 模式(modeFrom 绑地址参数 / 展示对象成员的表单使用):为真时 mode 仅认 edit,其余值(含 filter)一律按 create 处理 */
233
+ forbidFilterMode?: boolean;
232
234
  fields: KitCell[];
233
235
  /** 初值:create 是默认值,edit 是被编辑的整行 */
234
236
  initial: Record<string, unknown>;
@@ -337,8 +339,10 @@ function strOf(raw: unknown, fallback = ''): string {
337
339
  return typeof raw === 'string' ? raw : String(raw);
338
340
  }
339
341
 
340
- function modeOf(raw: unknown): KitObjectFormMode {
341
- return raw === 'edit' || raw === 'filter' ? raw : 'create';
342
+ function modeOf(raw: unknown, forbidFilter = false): KitObjectFormMode {
343
+ if (raw === 'edit') return 'edit';
344
+ if (!forbidFilter && raw === 'filter') return 'filter';
345
+ return 'create';
342
346
  }
343
347
 
344
348
  function isBlank(value: unknown): boolean {
@@ -905,6 +909,7 @@ export function createKitObjectForm(registered: Readonly<Record<string, SomaComp
905
909
  dictObject: { type: 'string', default: '', desc: '校验字典所在的数据对象名;空则取 object' },
906
910
  scope: { type: 'string', default: '', desc: '写入结果范围;缺省按对象名' },
907
911
  mode: { type: 'enum', values: ['create', 'edit', 'filter'], default: 'create', desc: '新建 / 编辑 / 筛选' },
912
+ forbidFilterMode: { type: 'boolean', default: false, desc: '禁止进入 filter 模式(modeFrom 运行期绑定用):为真时 mode 仅认 edit,其余值(含 filter)一律按 create 处理' },
908
913
  fields: { type: 'array', default: [], desc: '编译器给出的字段格(KitCell[])' },
909
914
  initial: { type: 'object', default: {}, desc: '初值:新建是默认值,编辑是整行' },
910
915
  classes: { type: 'object', default: {}, desc: '编译器给出的容器类 { wrap, grid, actions, pad, notice }' },
@@ -1319,7 +1324,7 @@ function createController(
1319
1324
  const s = strOf(P().scope);
1320
1325
  return s !== '' ? s : objectName();
1321
1326
  };
1322
- const mode = (): KitObjectFormMode => modeOf(P().mode);
1327
+ const mode = (): KitObjectFormMode => modeOf(P().mode, P().forbidFilterMode === true);
1323
1328
  const cells = (): KitCell[] => cellsOf(P().fields);
1324
1329
  const createOnly = (): Set<string> => new Set(stringList(P().createOnly));
1325
1330
  const initialOf = (): Rec => (isRec(P().initial) ? (P().initial as Rec) : {});
@@ -3229,6 +3234,15 @@ function createController(
3229
3234
  (ctrl.onFieldChange as (r: unknown, p: unknown) => boolean)({ name: field }, { value: res.value, __viaHandle: true });
3230
3235
  return res.cleared;
3231
3236
  },
3237
+ /**
3238
+ * 放弃未保存修改,还原到当前初值(ctx.form(对象).discard();与用户确认「放弃修改」同一条通道 discardDraft:不清详情、不重发请求)。
3239
+ * 草稿保留(浮层 draft: keep)的表单据此显式清空;表单已卸载 / 筛选表单返回 false
3240
+ */
3241
+ discard: (): boolean => {
3242
+ if (!alive || mode() === 'filter') return false;
3243
+ discardDraft();
3244
+ return true;
3245
+ },
3232
3246
  },
3233
3247
  get rows(): KitFormRow[] {
3234
3248
  syncDraft();
@@ -2,7 +2,9 @@
2
2
  //
3
3
  // 壳用 mountKitModal(经 core 浮层端口挂出:Esc 走层栈只关栈顶、Tab 焦点陷阱、关闭后回焦);本文件只补字段与按钮:
4
4
  // - 返回 Promise<Record<string, string> | null>:确认 = { 字段名: 值 };取消 / Esc / 点遮罩 / 关闭 = null。调用方一律 await;
5
- // - 字段 type 只有 text(单行,Enter 提交)与 textarea(多行,Ctrl / ⌘ + Enter 提交);required 的字段空白时就地报错、不关窗;
5
+ // - 字段 type:text(单行,缺省,Enter 提交)、textarea(多行,Ctrl / ⌘ + Enter 提交)、select(从 options 里选一个,
6
+ // 用官方 Select 组件经 mountKitSelectField 画,不手写控件,结果值 = 选中项的 value 字符串,未选为空串);
7
+ // required 的字段空白(select 未选)时就地报错、不关窗;
6
8
  // - 文案只用 textContent / value 写入,不经 innerHTML;
7
9
  // - 值一律是字符串(原样,不 trim);调用方按需处理空串;
8
10
  // - 无 DOM 环境(SSR / 测试)时不弹,直接 resolve whenNoDom(缺省 null)。
@@ -16,6 +18,8 @@ import { KIT_ERROR_TEXT } from '../recipes/typography';
16
18
  import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal, watchKitModalDetached } from './modal-dialog';
17
19
  import { closeAndDestroyKitModal, KIT_DIALOG_HINT_CLASS, KIT_DIALOG_INPUT_CLASS, KIT_DIALOG_MESSAGE_CLASS, kitDialogButton } from './confirm-dialog';
18
20
  import { classTokens } from './shape-util';
21
+ import { createKitEmbedBag, mountKitSelectField } from './embed';
22
+ import { KIT_SELECT_CLASS_CANDIDATES } from '../base/select';
19
23
  import { kitMarkLevel, kitMarkPart } from './kit-contract';
20
24
  import { mergeClass } from '../shared/merge-class';
21
25
 
@@ -29,15 +33,19 @@ const PROMPT_BODY_CLASS = 'p-card gap-4';
29
33
  export const KIT_PROMPT_CLASS_CANDIDATES: readonly string[] = classTokens(
30
34
  FIELD_CLASS, LABEL_CLASS, TEXTAREA_CLASS, ERROR_CLASS, DIALOG_TITLE_TIGHT, PROMPT_BODY_CLASS,
31
35
  KIT_DIALOG_INPUT_CLASS, KIT_DIALOG_MESSAGE_CLASS, KIT_DIALOG_HINT_CLASS, KIT_MODAL_CLASS_CANDIDATES,
36
+ KIT_SELECT_CLASS_CANDIDATES,
32
37
  );
33
38
 
34
39
  export interface KitPromptField {
35
40
  /** 结果里的键 */
36
41
  name: string;
37
42
  label?: string;
38
- /** text(单行,缺省)/ textarea(多行) */
39
- type?: 'text' | 'textarea';
43
+ /** text(单行,缺省)/ textarea(多行)/ select(从 options 选一个) */
44
+ type?: 'text' | 'textarea' | 'select';
45
+ /** type 为 select 时的选项(value 即结果值;其他类型忽略) */
46
+ options?: ReadonlyArray<{ value: string; label: string; disabled?: boolean }>;
40
47
  placeholder?: string;
48
+ /** 初值;select 时为初选项的 value(不在 options 里则视为未选) */
41
49
  initial?: string;
42
50
  /** 必填:空白(去空格后为空)时就地报错、不关窗 */
43
51
  required?: boolean;
@@ -63,6 +71,18 @@ export interface KitPromptOptions {
63
71
 
64
72
  type Control = HTMLInputElement | HTMLTextAreaElement;
65
73
 
74
+ /** 每个字段的统一读写口:文本类直接是输入框;select 是 Select 组件的可聚焦 combobox 与闭包里记下的选中值 */
75
+ interface FieldSlot {
76
+ field: KitPromptField;
77
+ /** 写 aria-invalid / aria-describedby、取焦点的元素 */
78
+ control: HTMLElement;
79
+ read(): string;
80
+ /** 报错 / 清错的无障碍同步 */
81
+ setInvalid(invalid: boolean, errorId: string, helpId: string): void;
82
+ error: HTMLElement;
83
+ helpId: string;
84
+ }
85
+
66
86
  export function askKitPrompt(opts: KitPromptOptions): Promise<Record<string, string> | null> {
67
87
  if (opts.signal?.aborted === true) return Promise.resolve(null);
68
88
  if (typeof document === 'undefined' || document.body === null) return Promise.resolve(opts.whenNoDom ?? null);
@@ -78,12 +98,15 @@ export function askKitPrompt(opts: KitPromptOptions): Promise<Record<string, str
78
98
  onClose: () => finish(null),
79
99
  }, doc);
80
100
  let stopWatch: () => void = () => {};
101
+ // 嵌入的 Select 组件:关窗时统一卸载并清扫锚在窗口里的残留下拉
102
+ const embeds = createKitEmbedBag();
81
103
  const finish = (value: Record<string, string> | null): void => {
82
104
  if (settled) return;
83
105
  settled = true;
84
106
  stopWatch();
85
107
  stopWatch = () => {};
86
108
  opts.signal?.removeEventListener('abort', onAbort);
109
+ embeds.release(modal.scrim);
87
110
  closeAndDestroyKitModal(modal, doc);
88
111
  resolve(value);
89
112
  };
@@ -100,7 +123,7 @@ export function askKitPrompt(opts: KitPromptOptions): Promise<Record<string, str
100
123
  modal.body.appendChild(msg);
101
124
  }
102
125
 
103
- const controls: Array<{ field: KitPromptField; control: Control; error: HTMLElement; helpId: string }> = [];
126
+ const controls: FieldSlot[] = [];
104
127
  const syncValidityA11y = (control: Control, errorId: string, helpId: string, invalid: boolean): void => {
105
128
  if (invalid) control.setAttribute('aria-invalid', 'true');
106
129
  else control.removeAttribute('aria-invalid');
@@ -108,20 +131,80 @@ export function askKitPrompt(opts: KitPromptOptions): Promise<Record<string, str
108
131
  if (ids.length > 0) control.setAttribute('aria-describedby', ids.join(' '));
109
132
  else control.removeAttribute('aria-describedby');
110
133
  };
134
+ // 错误行与说明行(文本类与 select 共用同一种写法)
135
+ const errorAndHelp = (wrap: HTMLElement, id: string, field: KitPromptField): { error: HTMLElement; helpId: string } => {
136
+ const error = doc.createElement('p');
137
+ error.id = `${id}-err`;
138
+ error.className = ERROR_CLASS;
139
+ error.hidden = true;
140
+ error.setAttribute('role', 'alert');
141
+ wrap.appendChild(error);
142
+ let helpId = '';
143
+ if (field.help !== undefined && field.help !== '') {
144
+ const help = doc.createElement('p');
145
+ help.id = `${id}-help`;
146
+ helpId = help.id;
147
+ help.className = KIT_DIALOG_HINT_CLASS;
148
+ help.textContent = field.help;
149
+ wrap.appendChild(help);
150
+ }
151
+ return { error, helpId };
152
+ };
153
+ // select:官方 Select 组件(mountKitSelectField,与页面里的 Select 同一份实现),选中值记在闭包里
154
+ const appendSelect = (field: KitPromptField, wrap: HTMLElement, id: string, hasLabel: boolean): void => {
155
+ const options = (field.options ?? []).map((o) => ({ value: String(o.value), label: String(o.label), ...(o.disabled === true ? { disabled: true } : {}) }));
156
+ const initial = field.initial ?? '';
157
+ let current = options.some((o) => o.value === initial) ? initial : '';
158
+ const errorId = `${id}-err`;
159
+ const helpIdOf = field.help !== undefined && field.help !== '' ? `${id}-help` : '';
160
+ const describedOf = (invalid: boolean): string => [...(invalid ? [errorId] : []), ...(helpIdOf !== '' ? [helpIdOf] : [])].join(' ');
161
+ let error: HTMLElement | null = null;
162
+ const sel = embeds.add(mountKitSelectField({
163
+ options,
164
+ value: current,
165
+ ...(field.placeholder !== undefined ? { placeholder: field.placeholder } : {}),
166
+ ...(hasLabel ? { labelledby: `${id}-label` } : { ariaLabel: field.name }),
167
+ ...(describedOf(false) !== '' ? { describedby: describedOf(false) } : {}),
168
+ ...(field.required === true ? { required: true } : {}),
169
+ id,
170
+ doc,
171
+ onChange: (next) => {
172
+ current = next;
173
+ if (error !== null) { error.hidden = true; error.textContent = ''; }
174
+ sel.setState({ invalid: false, describedby: describedOf(false) });
175
+ },
176
+ }));
177
+ wrap.appendChild(sel.el);
178
+ const eh = errorAndHelp(wrap, id, field);
179
+ error = eh.error;
180
+ modal.body.appendChild(wrap);
181
+ controls.push({
182
+ field, control: sel.field, error: eh.error, helpId: eh.helpId,
183
+ read: () => current,
184
+ setInvalid: (invalid) => sel.setState({ invalid, describedby: describedOf(invalid) }),
185
+ });
186
+ };
111
187
  opts.fields.forEach((field) => {
112
188
  const wrap = doc.createElement('div');
113
189
  wrap.className = FIELD_CLASS;
114
190
  // 每个输入项是窗口里的一个字段(层级角色「条目」),标签是字段名、输入框是控件
115
191
  kitMarkLevel(wrap, 'item'); kitApplyLevelClass(wrap);
116
192
  const id = nextUid('kit-prompt');
117
- if (field.label !== undefined && field.label !== '') {
193
+ const labelText = field.label;
194
+ const hasLabel = labelText !== undefined && labelText !== '';
195
+ if (labelText !== undefined && labelText !== '') {
118
196
  const label = doc.createElement('label');
119
197
  label.className = LABEL_CLASS;
120
198
  label.htmlFor = id;
199
+ label.id = `${id}-label`;
121
200
  kitMarkPart(label, 'field-name');
122
- label.textContent = field.required === true ? `${field.label} *` : field.label;
201
+ label.textContent = field.required === true ? `${labelText} *` : labelText;
123
202
  wrap.appendChild(label);
124
203
  }
204
+ if (field.type === 'select') {
205
+ appendSelect(field, wrap, id, hasLabel);
206
+ return;
207
+ }
125
208
  const multi = field.type === 'textarea';
126
209
  const control: Control = multi ? doc.createElement('textarea') : doc.createElement('input');
127
210
  if (control instanceof HTMLInputElement) { control.type = 'text'; control.autocomplete = 'off'; }
@@ -159,22 +242,26 @@ export function askKitPrompt(opts: KitPromptOptions): Promise<Record<string, str
159
242
  if (multi ? (e.ctrlKey || e.metaKey) : !e.isComposing) { e.preventDefault(); submit(); }
160
243
  });
161
244
  modal.body.appendChild(wrap);
162
- controls.push({ field, control, error, helpId });
245
+ controls.push({
246
+ field, control, error, helpId,
247
+ read: () => control.value,
248
+ setInvalid: (invalid, errorId, hid) => syncValidityA11y(control, errorId, hid, invalid),
249
+ });
163
250
  });
164
251
 
165
252
  const submit = (): void => {
166
- let first: Control | null = null;
167
- for (const { field, control, error, helpId } of controls) {
168
- if (field.required === true && control.value.trim() === '') {
169
- error.textContent = field.requiredMessage ?? kitText('soma.kit.field_required', undefined, opts.at);
170
- error.hidden = false;
171
- syncValidityA11y(control, error.id, helpId, true);
172
- first ??= control;
253
+ let first: HTMLElement | null = null;
254
+ for (const slot of controls) {
255
+ if (slot.field.required === true && slot.read().trim() === '') {
256
+ slot.error.textContent = slot.field.requiredMessage ?? kitText('soma.kit.field_required', undefined, opts.at);
257
+ slot.error.hidden = false;
258
+ slot.setInvalid(true, slot.error.id, slot.helpId);
259
+ first ??= slot.control;
173
260
  }
174
261
  }
175
262
  if (first !== null) { first.focus(); return; }
176
263
  const out: Record<string, string> = {};
177
- for (const { field, control } of controls) out[field.name] = control.value;
264
+ for (const slot of controls) out[slot.field.name] = slot.read();
178
265
  finish(out);
179
266
  };
180
267
 
@@ -61,13 +61,21 @@ function parseActions(raw: unknown, out: KitDiagnostic[]): KitPageAction[] | und
61
61
  return;
62
62
  }
63
63
  unknownKeys(a, PAGE_HEADER.actionKeys, at, out);
64
- const { id, label, action, href, variant, icon, disabled } = a;
64
+ const { id, label, action, href, openOverlay, variant, icon, disabled } = a;
65
65
  if (typeof id !== 'string' || !ID_RE.test(id)) shape(`${at}.id`, `${at}.id 必须是字母开头的字母数字下划线`, out);
66
66
  else if (seen.has(id)) shape(`${at}.id`, `${at}.id 重复:${id}`, out);
67
67
  else seen.add(id);
68
68
  if (typeof label !== 'string' || label.trim() === '') shape(`${at}.label`, `${at}.label 必填`, out);
69
69
  else if ([...label].length > L.actionLabel) tooLong(`${at}.label`, `${at}.label 不得超过 ${L.actionLabel} 字`, out);
70
- if ((action === undefined) === (href === undefined)) shape(at, `${at} 必须在 action(应用登记的具名动作)与 href(链接)中二选一`, out);
70
+ // openOverlay(打开页面级浮层 page.overlays.<名>)是第三种去处;没写它时判据与提示与改前一致
71
+ if (openOverlay === undefined) {
72
+ if ((action === undefined) === (href === undefined)) shape(at, `${at} 必须在 action(应用登记的具名动作)与 href(链接)中二选一`, out);
73
+ } else if (action !== undefined || href !== undefined) {
74
+ shape(at, `${at} 必须在 action(应用登记的具名动作)、href(链接)与 openOverlay(页面级浮层名)中三选一`, out);
75
+ }
76
+ if (openOverlay !== undefined && (typeof openOverlay !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(openOverlay))) {
77
+ shape(`${at}.openOverlay`, `${at}.openOverlay 必须是 page.overlays 里声明的浮层名`, out);
78
+ }
71
79
  if (action !== undefined && (typeof action !== 'string' || !ACTION_RE.test(action))) shape(`${at}.action`, `${at}.action 必须是具名动作名`, out);
72
80
  if (href !== undefined) {
73
81
  if (typeof href !== 'string' || safeHref(href) === '') {
@@ -85,6 +93,7 @@ function parseActions(raw: unknown, out: KitDiagnostic[]): KitPageAction[] | und
85
93
  const item: KitPageAction = { id, label };
86
94
  if (typeof action === 'string') item.action = action;
87
95
  if (typeof href === 'string') item.href = href;
96
+ if (typeof openOverlay === 'string') item.openOverlay = openOverlay;
88
97
  if (typeof variant === 'string') item.variant = variant;
89
98
  if (typeof icon === 'string' && icon !== '') item.icon = icon;
90
99
  if (disabled === true) item.disabled = true;
@@ -1,6 +1,7 @@
1
1
  // 页面框共用件:转义、页头、槽位片段合并、类检查。纯函数。
2
2
 
3
3
  import { kitNeutralClass } from '../biz/shared/pipeline';
4
+ import { kitPageOverlayOpenPipe } from '../biz/shared/page-overlay-names';
4
5
  import { emptyFragment, mergeFragments, type KitFragment } from '../object-renderer/fragment';
5
6
  import { classesInHtml } from '../object-renderer/candidates';
6
7
  import { KIT_ACTION_SLOT_BASE, actionSlotEvent, actionSlotOverflow } from '../base/action-slots';
@@ -181,6 +182,11 @@ export function headerFragment(input: KitFrameInput, prefix = ''): KitFragment {
181
182
  const overflow = actionSlotOverflow(page.actions.length, 'page.actions');
182
183
  if (overflow !== null) out.diagnostics.push({ code: 'KIT-EVT-001', path: 'page.actions', message: overflow });
183
184
  page.actions.forEach((a, i) => {
185
+ // 打开页面级浮层(page.overlays.<名>):交页面级浮层宿主的协调组件,以空行打开;名字是否声明由 compile-page 核对(KIT-PAGE-007)
186
+ if (a.openOverlay !== undefined) {
187
+ out.events[`${id}.${actionSlotEvent(KIT_ACTION_SLOT_BASE.header, i)}`] = kitPageOverlayOpenPipe(a.openOverlay);
188
+ return;
189
+ }
184
190
  if (a.action === undefined) return;
185
191
  if (input.registeredActions !== undefined && !input.registeredActions.has(a.action)) {
186
192
  out.diagnostics.push({ code: 'KIT-EVT-001', path: `page.actions[${i}].action`, message: `页头动作 ${a.id} 的 action "${a.action}" 未在应用的具名动作中登记` });
@@ -33,6 +33,8 @@ export interface KitPageAction {
33
33
  action?: string;
34
34
  /** 链接地址(站内外链,过 safeHref) */
35
35
  href?: string;
36
+ /** 打开页面级浮层 page.overlays.<名>(无行打开;与 action / href 三选一,名字由 compile-page 核对,KIT-PAGE-007) */
37
+ openOverlay?: string;
36
38
  variant?: string;
37
39
  icon?: string;
38
40
  disabled?: boolean;