soma-kit 0.1.14 → 0.1.15

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 (287) hide show
  1. package/package.json +3 -3
  2. package/packs/finance/reconcile-desk/compile.ts +1 -1
  3. package/packs/finance/reconcile-desk/shell.ts +1 -1
  4. package/spec/generated/kit-app.schema.json +4 -2
  5. package/spec/generated/kit-page.schema.json +72 -2
  6. package/spec/kit-grammar.json +163 -57
  7. package/spec/kit-grammar.schema.json +0 -24
  8. package/src/app/app-config.ts +1 -1
  9. package/src/app/component-gate.ts +2 -2
  10. package/src/app/compose-apps.ts +5 -2
  11. package/src/app/define-kit-actions.ts +82 -10
  12. package/src/app/define-kit-app.ts +6 -5
  13. package/src/app/define-kit-view.ts +1 -1
  14. package/src/app/index.ts +7 -7
  15. package/src/app/kit-view-context.ts +11 -2
  16. package/src/app/theme-endpoint.ts +1 -1
  17. package/src/app/theme-runtime.ts +7 -2
  18. package/src/base/alert.ts +23 -20
  19. package/src/base/anchored-layer.ts +1 -1
  20. package/src/base/button.ts +30 -15
  21. package/src/base/cascader.ts +8 -4
  22. package/src/base/check-core.ts +9 -6
  23. package/src/base/color-picker.ts +10 -6
  24. package/src/base/command-palette.ts +10 -4
  25. package/src/base/context-menu.ts +5 -2
  26. package/src/base/date-range.ts +9 -6
  27. package/src/base/date.ts +10 -6
  28. package/src/base/delta.ts +4 -2
  29. package/src/base/divider.ts +15 -66
  30. package/src/base/fab.ts +11 -6
  31. package/src/base/gap-value.ts +1 -1
  32. package/src/base/hint-tips.ts +1 -1
  33. package/src/base/index.ts +15 -4
  34. package/src/base/inline-error.ts +84 -0
  35. package/src/base/input.ts +54 -18
  36. package/src/base/kbd.ts +4 -3
  37. package/src/base/link.ts +1 -1
  38. package/src/base/listbox-core.ts +70 -22
  39. package/src/base/mentions.ts +6 -3
  40. package/src/base/menu-button.ts +63 -27
  41. package/src/base/menu-core.ts +9 -2
  42. package/src/base/motion/hover-3d.ts +4 -1
  43. package/src/base/motion/hover-gallery.ts +4 -1
  44. package/src/base/otp.ts +7 -3
  45. package/src/base/overlay-runtime.ts +3 -2
  46. package/src/base/overlay-shell.ts +141 -0
  47. package/src/base/popover.ts +2 -2
  48. package/src/base/popup.ts +47 -41
  49. package/src/base/qty-stepper.ts +14 -9
  50. package/src/base/reason-tip.ts +2 -2
  51. package/src/{frames → base}/resize-handle.ts +1 -1
  52. package/src/base/segmented.ts +35 -36
  53. package/src/base/select.ts +1 -0
  54. package/src/base/shared.ts +43 -7
  55. package/src/base/status-tone.ts +1 -1
  56. package/src/base/tag-input.ts +13 -8
  57. package/src/base/tag.ts +53 -59
  58. package/src/base/text.ts +37 -13
  59. package/src/base/textarea.ts +1 -1
  60. package/src/base/time-picker.ts +9 -5
  61. package/src/base/tree-select.ts +12 -9
  62. package/src/base/upload.ts +21 -13
  63. package/src/biz/approval-desk/compile.ts +28 -1
  64. package/src/biz/approval-desk/shell.ts +2 -2
  65. package/src/biz/auth-panel/compile.ts +1 -1
  66. package/src/biz/auth-panel/shell.ts +2 -2
  67. package/src/biz/category-crud/compile.ts +17 -4
  68. package/src/biz/category-crud/shell.ts +7 -5
  69. package/src/biz/checkout-page/compile.ts +1 -1
  70. package/src/biz/checkout-page/shell.ts +7 -6
  71. package/src/biz/compose.ts +3 -3
  72. package/src/biz/define.ts +1 -1
  73. package/src/biz/import-wizard/compile.ts +1 -1
  74. package/src/biz/import-wizard/shell.ts +6 -4
  75. package/src/biz/index.ts +4 -3
  76. package/src/biz/landing-page/compile.ts +1 -1
  77. package/src/biz/landing-page/shell.ts +5 -4
  78. package/src/biz/link/shared.ts +8 -1
  79. package/src/biz/master-sub/compile.ts +162 -19
  80. package/src/biz/master-sub/detail-head.ts +7 -6
  81. package/src/biz/master-sub/index.ts +3 -3
  82. package/src/biz/master-sub/shell.ts +90 -53
  83. package/src/biz/multi-board/compile.ts +3 -3
  84. package/src/biz/multi-board/index.ts +24 -9
  85. package/src/biz/multi-board/prose-fold.ts +2 -2
  86. package/src/biz/multi-board/shell.ts +17 -13
  87. package/src/biz/names.ts +1 -0
  88. package/src/biz/notification-center/compile.ts +9 -2
  89. package/src/biz/notification-center/shell.ts +9 -2
  90. package/src/biz/page-templates/domain-templates.ts +6 -2
  91. package/src/biz/page-templates/result-page/compile.ts +1 -1
  92. package/src/biz/page-templates/result-page/shell.ts +4 -3
  93. package/src/biz/page-templates/shared.ts +1 -1
  94. package/src/biz/page-templates/sign-in-page/compile.ts +1 -1
  95. package/src/biz/page-templates/sign-in-page/shell.ts +4 -4
  96. package/src/biz/record-detail/compile.ts +5 -2
  97. package/src/biz/record-detail/shell.ts +4 -4
  98. package/src/biz/settings-center/compile.ts +1 -1
  99. package/src/biz/settings-center/shell.ts +8 -5
  100. package/src/biz/shared/action-host.ts +12 -5
  101. package/src/biz/shared/compile-helpers.ts +4 -4
  102. package/src/biz/shared/coordinator.ts +104 -21
  103. package/src/biz/shared/overlay-compile.ts +48 -18
  104. package/src/biz/shared/overlay-shell.ts +63 -112
  105. package/src/biz/single-form/compile.ts +2 -2
  106. package/src/biz/single-form/shell.ts +8 -4
  107. package/src/biz/standard-crud/compile.ts +11 -4
  108. package/src/biz/standard-crud/shell.ts +26 -9
  109. package/src/biz/standard-crud/summary.ts +3 -1
  110. package/src/biz/step-form/compile.ts +1 -1
  111. package/src/biz/step-form/hub.ts +4 -0
  112. package/src/biz/step-form/shell.ts +6 -4
  113. package/src/biz/types.ts +11 -4
  114. package/src/cli/app-layer-check.ts +375 -0
  115. package/src/cli/kit-cli.ts +35 -8
  116. package/src/cli/kit-init.ts +149 -0
  117. package/src/compile/access-gate-attach.ts +1 -1
  118. package/src/compile/action-host-attach.ts +1 -1
  119. package/src/compile/compile-page.ts +29 -234
  120. package/src/compile/component-candidates.ts +2 -1
  121. package/src/compile/hints.ts +5 -58
  122. package/src/compile/index.ts +2 -2
  123. package/src/compile/layout-lint/index.ts +4 -1
  124. package/src/compile/layout-lint/rules-composition.ts +43 -13
  125. package/src/compile/page-composition.ts +33 -31
  126. package/src/compile/redirect.ts +1 -1
  127. package/src/compile/stages.ts +169 -0
  128. package/src/compile/styles.ts +70 -32
  129. package/src/compile/types.ts +2 -2
  130. package/src/data/amount-breakdown.ts +4 -2
  131. package/src/data/anchor-nav.ts +4 -1
  132. package/src/data/approval-flow.ts +9 -4
  133. package/src/data/assignment-picker.ts +28 -18
  134. package/src/data/async-result-panel.ts +6 -2
  135. package/src/data/breadcrumbs.ts +13 -9
  136. package/src/data/calendar.ts +4 -3
  137. package/src/data/carousel.ts +11 -5
  138. package/src/data/chart.ts +153 -23
  139. package/src/data/checklist.ts +5 -4
  140. package/src/data/code-view.ts +220 -26
  141. package/src/data/comment-thread.ts +7 -2
  142. package/src/data/confirm-dialog.ts +56 -13
  143. package/src/data/diff.ts +4 -1
  144. package/src/data/dock.ts +5 -1
  145. package/src/data/embed.ts +1 -1
  146. package/src/data/engine-ports.ts +126 -0
  147. package/src/data/field-mapper.ts +12 -6
  148. package/src/data/flow-editor.ts +105 -29
  149. package/src/data/footer.ts +6 -2
  150. package/src/data/gantt.ts +11 -8
  151. package/src/data/hero.ts +6 -2
  152. package/src/data/image-viewer.ts +7 -3
  153. package/src/data/index.ts +12 -5
  154. package/src/data/item-list.ts +6 -5
  155. package/src/data/json-view.ts +844 -0
  156. package/src/data/kanban.ts +11 -8
  157. package/src/data/markdown-view.ts +487 -0
  158. package/src/data/matrix.ts +23 -14
  159. package/src/data/media-grid.ts +5 -2
  160. package/src/data/mega-menu.ts +4 -3
  161. package/src/data/menu-dom.ts +9 -8
  162. package/src/data/menu.ts +15 -9
  163. package/src/data/mockup.ts +9 -5
  164. package/src/data/modal-dialog.ts +39 -88
  165. package/src/data/navbar.ts +11 -7
  166. package/src/data/notice-list.ts +1 -1
  167. package/src/data/notify-renderer.ts +21 -10
  168. package/src/data/object-form.ts +129 -48
  169. package/src/data/pager.ts +12 -8
  170. package/src/data/panel-head.ts +1 -1
  171. package/src/data/permission-matrix.ts +15 -8
  172. package/src/data/permission-tree.ts +24 -11
  173. package/src/data/pricing-table.ts +8 -3
  174. package/src/data/reaction-bar.ts +6 -3
  175. package/src/data/record-card.ts +13 -9
  176. package/src/data/record-picker.ts +8 -4
  177. package/src/data/redirect.ts +1 -1
  178. package/src/data/request-console.ts +20 -7
  179. package/src/data/resident.ts +0 -12
  180. package/src/data/result-panel.ts +2 -2
  181. package/src/data/rich-text.ts +58 -96
  182. package/src/data/row-editor.ts +10 -5
  183. package/src/data/rule-builder.ts +14 -8
  184. package/src/data/shape-util.ts +14 -3
  185. package/src/data/stat-group.ts +63 -22
  186. package/src/data/static-lazy.ts +3 -0
  187. package/src/data/static-registry.ts +8 -2
  188. package/src/data/steps.ts +6 -2
  189. package/src/data/survey.ts +9 -3
  190. package/src/data/system-switcher.ts +15 -6
  191. package/src/data/text-diff.ts +663 -0
  192. package/src/data/timeline.ts +1 -1
  193. package/src/data/tour-guide.ts +6 -3
  194. package/src/data/transfer.ts +19 -10
  195. package/src/data/tree-table.ts +77 -12
  196. package/src/data/tree.ts +5 -2
  197. package/src/data/virtual-rows.ts +17 -7
  198. package/src/data/wrap.ts +2 -2
  199. package/src/frames/index.ts +3 -2
  200. package/src/frames/inherited-shell.ts +178 -0
  201. package/src/frames/list-summary.ts +59 -36
  202. package/src/frames/page-bar.ts +4 -2
  203. package/src/frames/resident-components.ts +20 -0
  204. package/src/frames/shared.ts +18 -14
  205. package/src/frames/split-frame/shell.ts +17 -11
  206. package/src/frames/split-frame/wiring.ts +2 -2
  207. package/src/frames/tabs-frame/shell.ts +12 -6
  208. package/src/frames/types.ts +3 -2
  209. package/src/frames/workspace-frame/extras.ts +19 -5
  210. package/src/frames/workspace-frame/shell.ts +2 -1
  211. package/src/frames/workspace-frame/state.ts +8 -2
  212. package/src/frames/workspace-frame/view.ts +125 -76
  213. package/src/generated/kit-grammar-runtime.ts +61 -39
  214. package/src/i18n/kit-text.ts +114 -2
  215. package/src/i18n/resolve-text-refs.ts +1 -1
  216. package/src/object-renderer/action-group.ts +31 -1
  217. package/src/object-renderer/action-more.ts +28 -12
  218. package/src/object-renderer/arrange.ts +37 -7
  219. package/src/object-renderer/collection-parts.ts +38 -7
  220. package/src/object-renderer/collection-table.ts +68 -23
  221. package/src/object-renderer/collection.ts +63 -30
  222. package/src/object-renderer/compile-data.ts +1 -1
  223. package/src/object-renderer/defaults.ts +8 -0
  224. package/src/object-renderer/emit-events.ts +1 -1
  225. package/src/object-renderer/emit-object.ts +3 -0
  226. package/src/object-renderer/emit-static.ts +140 -37
  227. package/src/object-renderer/field-value.ts +12 -239
  228. package/src/object-renderer/filter-toolbar.ts +103 -0
  229. package/src/{compile → object-renderer}/fragment.ts +2 -2
  230. package/src/object-renderer/index.ts +1 -1
  231. package/src/object-renderer/layout-facts.ts +37 -5
  232. package/src/object-renderer/overlay-decide.ts +82 -0
  233. package/src/object-renderer/render-object.ts +1 -1
  234. package/src/object-renderer/table-actions.ts +70 -23
  235. package/src/object-renderer/table-tools.ts +12 -5
  236. package/src/object-renderer/types.ts +9 -15
  237. package/src/recipes/app-blocks.ts +66 -0
  238. package/src/recipes/code-view.ts +56 -0
  239. package/src/recipes/compact-group.ts +31 -0
  240. package/src/recipes/container.ts +25 -15
  241. package/src/recipes/control.ts +21 -3
  242. package/src/recipes/desc-list.ts +14 -0
  243. package/src/recipes/divider.ts +53 -0
  244. package/src/recipes/emphasis.ts +12 -8
  245. package/src/recipes/frame-bleed.ts +3 -3
  246. package/src/recipes/index.ts +11 -1
  247. package/src/recipes/inherited-shell.ts +37 -0
  248. package/src/recipes/json-view.ts +49 -0
  249. package/src/recipes/markdown.ts +86 -0
  250. package/src/recipes/overlay.ts +112 -26
  251. package/src/recipes/page-width.ts +20 -0
  252. package/src/recipes/placeholder.ts +1 -1
  253. package/src/recipes/stat-state.ts +1 -1
  254. package/src/recipes/state.ts +10 -8
  255. package/src/recipes/status.ts +13 -12
  256. package/src/recipes/strip.ts +72 -0
  257. package/src/recipes/surface.ts +10 -6
  258. package/src/recipes/table-gap.ts +1 -1
  259. package/src/recipes/table-native-edit.ts +4 -4
  260. package/src/recipes/table-row.ts +11 -8
  261. package/src/recipes/tabs.ts +108 -31
  262. package/src/recipes/text-diff.ts +90 -0
  263. package/src/recipes/title-row.ts +4 -2
  264. package/src/recipes/typography.ts +2 -2
  265. package/src/shared/diagnostics.ts +16 -0
  266. package/src/shared/envelope.ts +1 -1
  267. package/src/shared/field-value-format.ts +246 -0
  268. package/src/shared/focus-ring.ts +8 -0
  269. package/src/shared/hints.ts +56 -0
  270. package/src/{base → shared}/icons.ts +12 -0
  271. package/src/shared/kit-error.ts +1 -1
  272. package/src/{object-renderer → shared}/merge-class.ts +3 -2
  273. package/src/shared/path-guard.ts +1 -1
  274. package/src/shared/primitives-types.ts +8 -0
  275. package/src/shared/theme-runtime-shared.ts +19 -0
  276. package/src/theme/kit-theme-text.ts +1 -1
  277. package/src/theme/kit-theme.css +38 -14
  278. package/src/theme/kit-theme.tpl +38 -14
  279. package/src/theme/nine-dim-structure.ts +66 -41
  280. package/src/theme/surface-layers.ts +11 -3
  281. package/src/theme/theme-tokens.ts +5 -1
  282. package/src/app/envelope.ts +0 -1
  283. package/src/app/notify-renderer.ts +0 -1
  284. package/src/app/paged-list-adapter.ts +0 -1
  285. package/src/app/theme-runtime-shared.ts +0 -1
  286. package/src/compile/kit-error.ts +0 -1
  287. /package/src/{base → shared}/class-candidates.ts +0 -0
@@ -16,7 +16,7 @@
16
16
  // { panel: '' | 'form' | 'overlay', mode, open_form, creating, editing, ov: {<浮层名>: true}, row, id, prefill, seq }
17
17
 
18
18
  import type { SomaComponentDefinition, SomaDataPort, SomaRegionPort } from 'soma-core';
19
- import { lockDocumentScroll } from 'soma-core/behavior';
19
+ import { createDismissableLayer, lockDocumentScroll, type DismissableLayer } from 'soma-core/behavior';
20
20
  import { createKitController } from '../../base/shared';
21
21
  import { KIT_CORE_MAPPING, KIT_GRAMMAR } from '../../object-renderer/defaults';
22
22
  import { pickPath } from '../../object-renderer/path-pick';
@@ -25,6 +25,7 @@ import { askKitConfirm } from '../../data/confirm-dialog';
25
25
  import { beginKitAction } from '../../base/action-busy';
26
26
  import { trapTab } from '../../base/popup';
27
27
  import { kitText } from '../../i18n/kit-text';
28
+ import { clearKitInlineError, reportKitInlineError } from '../../base/inline-error';
28
29
  import { rowBusyName, removeKeyOf } from '../../object-renderer/table-actions';
29
30
  import { defaultPageSize, registerKitHub, type KitNotifyTone } from './runtime-hub';
30
31
 
@@ -77,6 +78,8 @@ export interface KitRowActionTarget {
77
78
  ids: readonly string[];
78
79
  /** 该处同时抛 row_pick(整行点击):行操作列、虚拟滚动表、树表为 true,右键菜单为 false */
79
80
  pick?: boolean;
81
+ /** 事件表里原本没有这处的槽位事件也照路由写(主从页详情头动作区:由编译新增的页面直接实例,不是 emitObject 先发的) */
82
+ force?: boolean;
80
83
  }
81
84
 
82
85
  /**
@@ -102,7 +105,7 @@ export function rewriteRowActions(args: {
102
105
  for (const key of Object.keys(bag)) {
103
106
  if (key.startsWith(`${own}${slotPrefix}`)) { delete bag[key]; existed = true; }
104
107
  }
105
- if (!existed && !force) return;
108
+ if (!existed && !force && target.force !== true) return;
106
109
  for (const route of args.routes) {
107
110
  if (route.id === 'select') {
108
111
  if (target.pick === true) bag[`${own}row_pick`] = route.pipe;
@@ -419,14 +422,25 @@ export function createKitCoordinator(): SomaComponentDefinition {
419
422
  };
420
423
  // 第一步:聚焦正文里第一个可填写控件(头部的「×」在文档顺序上先于表单),成功返回真
421
424
  // 遍历候选而非只取第一个:跳过隐藏 / 不可聚焦 / 只读 / 上传的文件输入;focus() 后确认真的拿到焦点才算数
425
+ // 可编辑控件 = 原生输入 + 自绘的同类角色(单选组 / 复选 / 开关 / 组合框 / 数值 / 滑块,KT-K-overlay-4,§6.1 G-8);
426
+ // 单选组只认当前项(已选中的那个;组内都未选时取第一个),不逐项停
422
427
  const focusBodyField = (dlg: HTMLElement): boolean => {
423
428
  const scopeEl = dlg.querySelector('[data-kit-dialog-body], [data-kit-overlay-body]') ?? dlg;
424
- const candidates = scopeEl.querySelectorAll<HTMLElement>('input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [contenteditable="true"], [contenteditable=""]');
429
+ const candidates = scopeEl.querySelectorAll<HTMLElement>('input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [contenteditable="true"], [contenteditable=""], [role="radio"]:not(:disabled), [role="checkbox"]:not(:disabled), [role="switch"]:not(:disabled), [role="combobox"], [role="spinbutton"], [role="slider"], [role="textbox"]');
425
430
  for (const field of candidates) {
426
431
  const type = field instanceof HTMLInputElement ? field.type : '';
427
432
  if (type === 'hidden' || type === 'file') continue;
428
433
  if (unusableIn(dlg, field)) continue;
429
- if ((field as HTMLInputElement).readOnly) continue;
434
+ if ((field as HTMLInputElement).readOnly || field.getAttribute('aria-disabled') === 'true' || field.getAttribute('aria-readonly') === 'true') continue;
435
+ if (field.getAttribute('role') === 'radio') {
436
+ const group = field.closest('[role="radiogroup"]');
437
+ const checked = group?.querySelector<HTMLElement>('[role="radio"][aria-checked="true"]');
438
+ if (checked && checked !== field) continue;
439
+ }
440
+ if (field instanceof HTMLInputElement && field.type === 'radio' && !field.checked && field.name !== '') {
441
+ const peers = Array.from(scopeEl.querySelectorAll<HTMLInputElement>('input[type="radio"]')).filter((r) => r.name === field.name);
442
+ if (peers.some((r) => r.checked)) continue;
443
+ }
430
444
  field.focus();
431
445
  if (holdsFocus(field)) return true;
432
446
  }
@@ -434,8 +448,18 @@ export function createKitCoordinator(): SomaComponentDefinition {
434
448
  };
435
449
  // 第二步:回退聚焦,返回实际拿到焦点的元素;沿用同一套排除规则,弹窗内确无可聚焦元素时落在弹窗自身
436
450
  // (无 tabindex 先补 -1,对话框的标准做法)并返回弹窗
451
+ // 顺序(KT-K-overlay-4,§6.1 G-8):正文里的可聚焦元素 → 底栏主钮(提交)→ 底栏其余钮 → 其它(含头部「×」,最后才轮到)
437
452
  const focusFallback = (dlg: HTMLElement): HTMLElement => {
438
- const fallbacks = dlg.querySelectorAll<HTMLElement>('input:not(:disabled), select:not(:disabled), textarea:not(:disabled), button:not(:disabled), [tabindex]:not([tabindex="-1"])');
453
+ const sel = 'input:not(:disabled), select:not(:disabled), textarea:not(:disabled), button:not(:disabled), [tabindex]:not([tabindex="-1"])';
454
+ const body = dlg.querySelector('[data-kit-dialog-body], [data-kit-overlay-body]');
455
+ const foot = dlg.querySelector('[data-kit-overlay-foot]');
456
+ const ordered = [
457
+ ...(body ? Array.from(body.querySelectorAll<HTMLElement>(sel)) : []),
458
+ ...(foot ? Array.from(foot.querySelectorAll<HTMLElement>('[data-soma-scoped-id="kit_submit"] button:not(:disabled)')) : []),
459
+ ...(foot ? Array.from(foot.querySelectorAll<HTMLElement>(sel)) : []),
460
+ ...Array.from(dlg.querySelectorAll<HTMLElement>(sel)),
461
+ ];
462
+ const fallbacks = ordered.filter((el, i) => ordered.indexOf(el) === i);
439
463
  for (const el of fallbacks) {
440
464
  const type = el instanceof HTMLInputElement ? el.type : '';
441
465
  if (type === 'hidden' || type === 'file') continue;
@@ -567,11 +591,55 @@ export function createKitCoordinator(): SomaComponentDefinition {
567
591
  const focus = port?.slice('focus');
568
592
  if (!port || !focus) return;
569
593
  focus.set(closedFocus(0));
594
+ const doc = api.host?.ownerDocument ?? (typeof document !== 'undefined' ? document : null);
595
+ /** 栈顶判定:把声明式浮层纳入 core 统一层栈(DismissableLayer),避免被下层浮层截走 Escape 或无法分层收口 */
596
+ let escapeLayer: DismissableLayer | null = null;
597
+ let closeOverlayByUser: (() => void) | null = null;
598
+ const isPopupExpanded = (el: HTMLElement | null): boolean => {
599
+ if (!el || el.getAttribute('aria-expanded') !== 'true') return false;
600
+ // 表单可折叠分组标题、树节点、JSON 树展开钮是行内展开而非弹出浮层,聚焦其上按 Esc 仍应关闭弹窗
601
+ if (el.hasAttribute('data-kit-group-toggle') || el.hasAttribute('data-kit-tree-toggle')) return false;
602
+ const role = el.getAttribute('role');
603
+ if (role === 'treeitem' || role === 'row') return false;
604
+ return true;
605
+ };
606
+ const syncEscapeLayer = (open: boolean): void => {
607
+ if (!doc) return;
608
+ if (!open) {
609
+ escapeLayer?.unmount();
610
+ escapeLayer = null;
611
+ return;
612
+ }
613
+ if (escapeLayer === null) {
614
+ escapeLayer = createDismissableLayer(null, {
615
+ document: doc,
616
+ dismissOnEscape: true,
617
+ dismissOnOutside: false,
618
+ onEscapeKeyDown: (e) => {
619
+ if (e.defaultPrevented || focusOf(focus.get()).panel === '') return false;
620
+ const active = doc.activeElement as HTMLElement | null;
621
+ if (isPopupExpanded(active)) return false;
622
+ // 流程画布内有选中项或右键菜单时先让画布自己取消,二次 Esc 再关窗
623
+ const target = e.target as Element | null;
624
+ const flowStage = target?.closest?.('[role="group"][aria-roledescription]');
625
+ if (flowStage && (flowStage.querySelector('[data-flow-selected]') !== null || flowStage.querySelector('[data-flow-act^="menu-"]') !== null)) {
626
+ return false;
627
+ }
628
+ return undefined;
629
+ },
630
+ onDismiss: () => { closeOverlayByUser?.(); },
631
+ });
632
+ }
633
+ if (escapeLayer.mounted) escapeLayer.bringToFront();
634
+ else escapeLayer.mount();
635
+ };
570
636
  const setFocus = (f: ReturnType<typeof nextFocus>): void => {
571
637
  focus.set(f);
638
+ const open = focusOf(f).panel !== '';
572
639
  // 面板已关:还在等弹窗变可见的初始焦点作废
573
- if (focusOf(f).panel === '') cancelDialogWait();
574
- syncScrollLock(focusOf(f).panel !== '');
640
+ if (!open) cancelDialogWait();
641
+ syncScrollLock(open);
642
+ syncEscapeLayer(open);
575
643
  };
576
644
  const notifySvc = (api.services as { notify?: { toast?: (o: { level: string; message: string }) => void } } | undefined)?.notify;
577
645
  const rawInstanceId = (api as { instanceId?: unknown }).instanceId;
@@ -741,6 +809,10 @@ export function createKitCoordinator(): SomaComponentDefinition {
741
809
  if (inFlightRemovals.has(flightKey)) return;
742
810
  inFlightRemovals.add(flightKey);
743
811
 
812
+ const reportRemoveFailure = (raw: string): void => {
813
+ const text = raw !== '' ? raw : kitText('soma.kit.action_failed_plain', { name: kitText('soma.kit.delete', undefined, api.host ?? null) }, api.host ?? null);
814
+ reportKitInlineError(api.host ?? null, text, `remove:${object}`, () => notifySvc?.toast?.({ level: 'danger', message: text }));
815
+ };
744
816
  const doRemove = (): void => {
745
817
  if (!data || object === '') {
746
818
  inFlightRemovals.delete(flightKey);
@@ -758,6 +830,7 @@ export function createKitCoordinator(): SomaComponentDefinition {
758
830
  void pending.then((r) => {
759
831
  if (!alive) return undefined;
760
832
  if (r.ok) {
833
+ clearKitInlineError(api.host ?? null, `remove:${object}`);
761
834
  // 删除成功:被删行不再处于已选(取消确认 / 删除失败时已选行保持原样)
762
835
  // 已选集合只属于主对象:删的是成员对象的行时不动它
763
836
  if (isMain) {
@@ -773,13 +846,14 @@ export function createKitCoordinator(): SomaComponentDefinition {
773
846
  return undefined;
774
847
  }
775
848
  console.error(`[soma-kit] 删除失败:${r.message}`);
776
- notifySvc?.toast?.({ level: 'danger', message: r.message !== '' ? r.message : kitText('soma.kit.action_failed_plain', { name: kitText('soma.kit.delete', undefined, api.host ?? null) }, api.host ?? null) });
849
+ // 错误不用轻提示(KT-K-feedback-3,§6.1 G-17):行删除失败进页面就地提示条,无槽才回退轻提示
850
+ reportRemoveFailure(r.message);
777
851
  return undefined;
778
852
  }, (err: unknown) => {
779
853
  // 删除请求本身被拒绝(Promise 拒绝):与「返回失败结果」走同一条失败提示;只挂在删除请求上,成功后的重取失败不会落到这里
780
854
  const message = err instanceof Error ? err.message : '';
781
855
  console.error(`[soma-kit] 删除失败:${message}`);
782
- if (alive) notifySvc?.toast?.({ level: 'danger', message: message !== '' ? message : kitText('soma.kit.action_failed_plain', { name: kitText('soma.kit.delete', undefined, api.host ?? null) }, api.host ?? null) });
856
+ if (alive) reportRemoveFailure(message);
783
857
  return undefined;
784
858
  }).catch((err: unknown) => {
785
859
  // 删除已成功之后的重取被拒绝:只记日志,可见提示由列表自己的失败态呈现
@@ -813,7 +887,7 @@ export function createKitCoordinator(): SomaComponentDefinition {
813
887
  }
814
888
  };
815
889
  off = port.onSemantic((rawName, rawPayload) => handleSemantic(rawName, rawPayload));
816
- if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
890
+ if (doc && typeof doc.addEventListener === 'function') {
817
891
  // 用户发起的关窗(Esc / 点遮罩):与头部「关闭」同一裁决,有未保存修改先问
818
892
  const closeByUser = (): void => {
819
893
  const now = focusOf(focus.get());
@@ -829,21 +903,24 @@ export function createKitCoordinator(): SomaComponentDefinition {
829
903
  .then((ok) => { if (ok && alive && !formBusy && focusOf(focus.get()).panel !== '') finish(); })
830
904
  .catch((err: unknown) => { console.error('[soma-kit] 放弃修改确认失败:', err instanceof Error ? err.message : String(err)); });
831
905
  };
906
+ closeOverlayByUser = closeByUser;
832
907
  const onKeyDown = (e: KeyboardEvent): void => {
833
908
  // Tab 陷阱:只管本协调组件最上层的可见弹窗;焦点在别处挂载的浮层(下拉 / 日期面板 / 确认框)里时不干预
834
909
  if (e.key === 'Tab') {
835
910
  if (e.defaultPrevented || focusOf(focus.get()).panel === '') return;
836
911
  const dlg = visibleDialog();
837
912
  if (!dlg) return;
838
- const active = document.activeElement;
839
- if (active !== null && active !== document.body && !dlg.contains(active)) return;
913
+ const active = doc.activeElement;
914
+ if (active !== null && active !== doc.body && !dlg.contains(active)) return;
840
915
  trapTab(e, dlg);
841
916
  return;
842
917
  }
918
+ // Escape 优先由核心层栈(DismissableLayer)处理;此处兜底仅当层栈未挂载时生效
843
919
  if (e.key !== 'Escape' || e.defaultPrevented || e.isComposing || e.keyCode === 229) return;
920
+ if (escapeLayer?.mounted) return;
844
921
  if (focusOf(focus.get()).panel === '') return;
845
- const active = document.activeElement as HTMLElement | null;
846
- if (active?.getAttribute('aria-expanded') === 'true') return;
922
+ const active = doc.activeElement as HTMLElement | null;
923
+ if (isPopupExpanded(active)) return;
847
924
  e.preventDefault();
848
925
  closeByUser();
849
926
  };
@@ -852,19 +929,23 @@ export function createKitCoordinator(): SomaComponentDefinition {
852
929
  const onMouseDown = (e: MouseEvent): void => {
853
930
  downOnScrim = scrimOf(e.target, api.host?.parentElement) !== null;
854
931
  };
932
+ // 含输入的窗口(表单、带搜索的选择)不因点击遮罩关闭(knowledge/Kit主题规则与算法.md KT-K-overlay-2,2026-11-25 裁决):
933
+ // 只看窗口里有没有可编辑控件(结构判定,不测量);纯信息 / 只读窗口照常点遮罩关闭;Esc 与关闭钮不受影响
934
+ // 遮罩元素包着窗口面板(base/overlay-shell):在被点的这层遮罩里找
935
+ const hasInput = (scrim: HTMLElement): boolean => scrim.querySelector('input:not([type=hidden]), textarea, select, [contenteditable="true"], [role="combobox"]') !== null;
855
936
  const onClick = (e: MouseEvent): void => {
856
937
  const hit = scrimOf(e.target, api.host?.parentElement);
857
938
  const was = downOnScrim;
858
939
  downOnScrim = false;
859
- if (hit !== null && was) closeByUser();
940
+ if (hit !== null && was && !hasInput(hit)) closeByUser();
860
941
  };
861
- document.addEventListener('keydown', onKeyDown);
862
- document.addEventListener('mousedown', onMouseDown);
863
- document.addEventListener('click', onClick);
942
+ doc.addEventListener('keydown', onKeyDown);
943
+ doc.addEventListener('mousedown', onMouseDown);
944
+ doc.addEventListener('click', onClick);
864
945
  offKey = () => {
865
- document.removeEventListener('keydown', onKeyDown);
866
- document.removeEventListener('mousedown', onMouseDown);
867
- document.removeEventListener('click', onClick);
946
+ doc.removeEventListener('keydown', onKeyDown);
947
+ doc.removeEventListener('mousedown', onMouseDown);
948
+ doc.removeEventListener('click', onClick);
868
949
  };
869
950
  }
870
951
  return () => {
@@ -873,6 +954,8 @@ export function createKitCoordinator(): SomaComponentDefinition {
873
954
  formBusy = false;
874
955
  syncAriaBusy();
875
956
  syncScrollLock(false);
957
+ syncEscapeLayer(false);
958
+ closeOverlayByUser = null;
876
959
  for (const end of removalBusyEnds.values()) end();
877
960
  removalBusyEnds.clear();
878
961
  inFlightRemovals.clear();
@@ -22,8 +22,8 @@ import type { KitBizContext, KitOverlayDecl, KitOverlayEventAction } from '../ty
22
22
  import { KIT_COORD_EVENTS, KIT_COORD_MIRRORS, overlayMirrorKey } from './coordinator';
23
23
  import { addEmit, IDENT, isRec, labelDiagnostics, mirrorPath, patchProps, type Parts, type Rec } from '../link/shared';
24
24
  import { semanticPipe, wireDialogForm } from './pipes';
25
- import { dialogWidthOf, overlayHtml, overlayIds, type KitDialogWidth } from './overlay-shell';
26
- import { KIT_DIALOG_WIDTH_TIERS, KIT_DRAWER_WIDTHS, isKitDialogWidth, isKitDrawerWidth, type KitDrawerWidth } from '../../recipes/overlay';
25
+ import { overlayHtml, overlayIds } from './overlay-shell';
26
+ import { dialogWidthOf, drawerWidthOf, footerPlanOf } from '../../object-renderer/overlay-decide';
27
27
 
28
28
  /**
29
29
  * 抽屉里有没有提交动作:返回原因(无则 null)。判据:表单视图、behavior.write、事件接到具名动作 / saved 语义、
@@ -45,6 +45,28 @@ export function drawerSubmitReason(decl: KitOverlayDecl, view: KitView, staticCo
45
45
  return null;
46
46
  }
47
47
 
48
+ const FOOTER_REASON: Readonly<Record<string, string>> = Object.freeze({
49
+ 'left-over': '左侧次级动作超过上限',
50
+ extras: '有动作想放进底栏却没有位置',
51
+ 'visible-over': '底栏可见按钮总数超过上限',
52
+ });
53
+
54
+ /**
55
+ * 窗口底栏排法(KIT-OVL-004,先以告警落地):右侧固定「取消 + 一个主动作」,左侧至多一个次级动作,其余进「更多」或改成正文控件。
56
+ * 判定在引擎(arrangeOverlayFooter,规则 kit-arrange#overlay.footer),这里只取事实(表单的 footerActions 数)并出诊断。
57
+ */
58
+ export function adviseDialogFooter(ctx: KitBizContext, formView: unknown, path: string): void {
59
+ if (ctx.advise === undefined) return;
60
+ const plan = footerPlanOf(formView);
61
+ if (plan.ok) return;
62
+ ctx.advise({
63
+ code: 'KIT-OVL-004',
64
+ path,
65
+ message: `窗口底栏排不下:${FOOTER_REASON[plan.reason] ?? plan.reason}(按钮 ${plan.visible} 个)`,
66
+ hint: '底栏右侧只放「取消 + 主动作」,左侧至多一个次级动作;其余收进更多,或改成正文里的控件',
67
+ });
68
+ }
69
+
48
70
  /** 浮层里数据组件的约定事件 -> 角色(K-1) */
49
71
  const OVERLAY_EVENT_ROLES: Record<string, string> = KIT_GRAMMAR.overlayEventRoles.conventional as Record<string, string>;
50
72
  const OVERLAY_ROLE_SEMANTIC: Record<string, string> = {
@@ -130,18 +152,14 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
130
152
  const at = `product.overlays.${name}`;
131
153
  if (!IDENT.test(name)) return undefined;
132
154
  // 抽屉宽度档:width 只对 kind: drawer 有效(对话框宽度由内容定档),取值闭集 narrow / default / wide
133
- let drawerWidth: KitDrawerWidth = 'default';
134
- let dialogTier: KitDialogWidth | undefined;
135
- if (decl.width !== undefined) {
136
- if (decl.kind === 'drawer') {
137
- if (!isKitDrawerWidth(decl.width)) fail('KIT-BIZ-003', `浮层 ${name} 的 width "${String(decl.width)}" 不在抽屉档内(${KIT_DRAWER_WIDTHS.join(' / ')})`, `${at}.width`);
138
- else drawerWidth = decl.width;
139
- } else if (decl.kind === 'dialog') {
140
- if (!isKitDialogWidth(decl.width)) fail('KIT-BIZ-003', `浮层 ${name} 的 width "${String(decl.width)}" 不在对话框档内(${KIT_DIALOG_WIDTH_TIERS.join(' / ')})`, `${at}.width`);
141
- else dialogTier = decl.width;
142
- } else {
143
- fail('KIT-BIZ-003', `浮层 ${name} 的 width 只对 kind: drawer / dialog 有效`, `${at}.width`);
144
- }
155
+ // 窗口的大小与外观由框架按内容推导(确认 400、表单 480 / 640 / 800、只读抽屉 480 / 640,尺寸规格 §5),页面不写 width / class(KIT-OVL-003)
156
+ // 过渡期:KIT-OVL-002 / 003 先以告警落地(不挡编译,kit check 的弃用提示段带出),应用按 apps-todo 改完后升为错误
157
+ const warn = (code: string, message: string, path: string, hint: string): void => {
158
+ if (ctx.advise !== undefined) ctx.advise({ code, path, message, hint });
159
+ else fail(code, message, path);
160
+ };
161
+ for (const key of ['width', 'class'] as const) {
162
+ if (decl[key] !== undefined) warn('KIT-OVL-003', `浮层 ${name} 写了 ${key}:窗口的宽度与外观由框架按内容推导,该键已不生效`, `${at}.${key}`, `删掉 ${key};要换档请改内容(栏数 arrange、组件):单列 480、两列或宽组件 640、三列或画布 800、只读抽屉 480 / 640`);
145
163
  }
146
164
  const view = normalizeOverlayView(decl.view);
147
165
  if (view === undefined) {
@@ -152,9 +170,13 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
152
170
  if (decl.kind === 'drawer') {
153
171
  const why = drawerSubmitReason(decl, view, ctx.staticComponents);
154
172
  if (why !== null) {
155
- fail('KIT-OVL-001', `浮层 ${name} 是抽屉却承载提交动作(${why}):填写并提交、或确认后写入的浮层改写 kind: dialog(内容多的加 width: wide),抽屉只用于只读详情`, `${at}.kind`);
173
+ fail('KIT-OVL-001', `浮层 ${name} 是抽屉却承载提交动作(${why}):填写并提交、或确认后写入的浮层改写 kind: dialog(宽度由栏数与宽组件推导),抽屉只用于只读详情`, `${at}.kind`);
156
174
  }
175
+ } else if (decl.kind === 'dialog' && drawerSubmitReason(decl, view, ctx.staticComponents) === null) {
176
+ // 只读内容一律抽屉(KIT-OVL-002):没有表单、写入、提交动作的居中窗口是错类型
177
+ warn('KIT-OVL-002', `浮层 ${name} 是居中窗口却只读(没有表单视图、behavior.write、具名动作或 saved 事件)`, `${at}.kind`, '只读内容改写 kind: drawer;居中窗口只给确认与带提交的表单');
157
178
  }
179
+ if (decl.kind === 'dialog') adviseDialogFooter(ctx, view.form, `${at}.view.form.footerActions`);
158
180
  // 编辑详情(behavior.detail)与读通道(behavior.from)二选一:from 已是「按关联键取浮层对象」的读口
159
181
  if (decl.behavior?.from !== undefined && decl.behavior?.detail !== undefined) {
160
182
  fail('KIT-DET-001', `附加浮层 ${name} 同时写了 behavior.from 与 behavior.detail:二选一(from 已按关联键取浮层对象,detail 用于以当前行为初值的编辑表单)`, `${at}.behavior.detail`);
@@ -199,6 +221,7 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
199
221
  }
200
222
  // K-1 / M1-3:浮层里的写死形状数据组件(应用组件)按约定抛 saved / cancel / close / reload,由协调组件接;
201
223
  // overlays.<名>.events 可再把自定义事件名映射到这四种之一。组件没抛的事件不会触发(core 对未声明的 emit 选择器惰性)
224
+ const submitActions = new Set<string>();
202
225
  for (const slot of ['list', 'summary'] as const) {
203
226
  const staticComp = view[slot]?.staticComponent;
204
227
  if (staticComp === undefined) continue;
@@ -235,6 +258,8 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
235
258
  }
236
259
  out.events[`${anchor}.${emitName}`] = actionPipe;
237
260
  namedOn[emitName] = role.action;
261
+ // 提交类事件(saved 语义)绑的应用具名动作:登记为本浮层的提交动作,成功后框架默认关窗 + 成功反馈(request 类已由宿主 closeOnSuccess)
262
+ if (declared === undefined && (emitName === 'saved' || OVERLAY_EVENT_ROLES[emitName] === 'saved')) submitActions.add(role.action);
238
263
  continue;
239
264
  }
240
265
  // view.<方法>:浮层里组件抛出的事件调展示对象方法(载荷 = 组件 emit 的载荷;不关窗不重取,要请求走 ctx.request / ctx.action)
@@ -269,12 +294,17 @@ export function compileOverlay(h: OverlayHostArgs, name: string, decl: KitOverla
269
294
  out.events[`${ids.edit}.click`] = semanticPipe(scope, KIT_COORD_EVENTS.showEdit);
270
295
  }
271
296
  return {
272
- // 对话框宽度只由内容定档(480 / 720 / 960,见 dialogWidthOf),抽屉由 width 三档(缺省 560);页面写的宽度类(class / areaClass)被壳忽略
273
- html: overlayHtml(ids, decl.kind === 'drawer' ? 'drawer' : 'dialog', decl.title ?? name, ovEmit.html, decl.class, areaClass, withEdit, h.closeLabel, '', dialogTier ?? dialogWidthOf({
297
+ // 窗口宽度档只由内容经引擎推导(overlay-decide),外壳只渲染档名;页面写的宽度类(class / areaClass)被壳忽略
298
+ html: overlayHtml(ids, decl.kind === 'drawer' ? 'drawer' : 'dialog', decl.title ?? name, ovEmit.html, undefined, areaClass, withEdit, h.closeLabel, '', dialogWidthOf({
299
+ form: view.form,
300
+ schema: decl.schema,
301
+ staticComponent: view.list?.staticComponent ?? view.summary?.staticComponent,
302
+ }), drawerWidthOf({
274
303
  form: view.form,
275
304
  schema: decl.schema,
276
305
  staticComponent: view.list?.staticComponent ?? view.summary?.staticComponent,
277
- }), drawerWidth),
306
+ tableList: view.list !== undefined && view.list.staticComponent === undefined && (view.list.collection === undefined || view.list.collection.type === 'table'),
307
+ }), [...submitActions]),
278
308
  mirror: { key: overlayMirrorKey(name), slice: 'focus', path: `ov.${name}`, as: 'truthy' },
279
309
  object: ovObject,
280
310
  };
@@ -1,22 +1,14 @@
1
- import { esc } from '../../shared/escape';
2
- // 业务组件共用的弹窗外壳:类名常量、关闭钮、弹窗 id / 标题、弹窗 HTML 生成。
1
+ // 业务组件共用的弹窗外壳(声明式调用方):浮层 id / 标题、显隐宿主、弹窗 HTML 生成。
2
+ // 外壳结构只在 base/overlay-shell 一份(命令式的确认 / 提示 / 选择器 / 抽屉调同一份),这里只传「决定」:哪种窗口、哪一档宽度、标题与正文是什么。
3
3
  // 增删改查(standard-crud)、分类增删改查、主从、记录详情都用同一套弹窗壳,放在这里避免业务组件横向依赖增删改查的外壳;
4
4
  // standard-crud/shell.ts 从这里 import 并原样 re-export。只有结构和 Tailwind 类,不写原生 CSS。
5
5
  // 显隐层统一用 `fixed inset-0` 的遮罩 + 内层 flex 容器:显隐只靠 core 写 `hidden` 属性,不在遮罩自身叠 display 类。
6
6
 
7
- import { mergeClass } from '../../object-renderer/merge-class';
8
- import { KIT_OVERLAY_LIMITS } from 'soma-foundation/kit-limits';
9
- import { KIT_DIALOG_SURFACE_CLASS, KIT_OVERLAY_SCROLL_ATTR, KIT_OVERLAY_WIDTH_CLASS, kitDrawerPanelClass, type KitDrawerWidth } from '../../recipes/overlay';
10
- import { kitIconHtml } from '../../base/icons';
11
- import {
12
- KIT_FIXED_ATTRIBUTE, KIT_PART_DIALOG, KIT_PART_DRAWER, KIT_PART_TITLE_DIALOG,
13
- kitOverlayBodyRecipe, kitOverlayFooterRecipe, kitOverlayHeaderRecipe, kitTypographyRecipe,
14
- } from '../../recipes';
15
-
16
- /** 对话框面板类串:只在这里写一份,三档宽度各传自己的宽度类(480 / 720 / 960) */
17
- function dialogPanelClass(width: string): string {
18
- return `flex max-h-full w-full ${width} flex-col ${KIT_DIALOG_SURFACE_CLASS} motion-safe:animate-kit-dialog-in`;
19
- }
7
+ import { esc } from '../../shared/escape';
8
+ import { mergeClass } from '../../shared/merge-class';
9
+ import type { KitDialogTier, KitDrawerWidth } from '../../recipes/overlay';
10
+ import { kitShellClasses, kitShellHtml } from '../../base/overlay-shell';
11
+ import { kitIconHtml } from '../../shared/icons';
20
12
 
21
13
  /**
22
14
  * 浮层显隐外层(只放 core 写的 hidden 属性):定位类 fixed 让它出流——它自己 0 高,留在业务壳根的 flex 流里就会为每个浮层多量出一份 gap
@@ -26,8 +18,15 @@ function dialogPanelClass(width: string): string {
26
18
  */
27
19
  export const LAYER_HOST_CLASS_ATTR = ' class="fixed z-50"';
28
20
 
29
- /** 对话框宽度档:default 480、wide 720(长表单 / 穿梭框)、xwide 960(画布类) */
30
- export type KitDialogWidth = 'default' | 'wide' | 'xwide';
21
+ /**
22
+ * 浮层显隐外层上的「提交动作」标记:值是空格分隔的具名动作名。具名动作从这个浮层里触发且成功时,
23
+ * 框架默认关窗并给成功反馈(每个处理函数都要记得写的事归框架);处理函数调 keepOpen() 可显式不关。
24
+ */
25
+ export const KIT_SUBMIT_ACTIONS_ATTR = 'data-kit-submit-actions';
26
+
27
+ /** 表单窗口宽度档:default 480、wide 640(两列 / 宽组件)、xwide 800(三列 / 画布) */
28
+ import type { KitDialogWidth } from '../../object-renderer/overlay-decide';
29
+ export type { KitDialogWidth };
31
30
 
32
31
  /** 宽度类(`w-*` / `min-w-*` / `max-w-*`,含任意变体前缀):浮层宽度只由内容档位决定,页面写的宽度类不参与 */
33
32
  const WIDTH_CLASS_TOKEN = /^(?:[^:]+:)*-?(?:min-w|max-w|w)-/;
@@ -39,77 +38,27 @@ export function stripOverlayWidthClasses(cls: string | undefined): string | unde
39
38
  return kept.length === 0 ? undefined : kept.join(' ');
40
39
  }
41
40
 
41
+ const DIALOG = kitShellClasses({ kind: 'dialog', dialogTier: 'default' });
42
+ const DRAWER = kitShellClasses({ kind: 'drawer', drawerWidth: 'default' });
43
+
44
+ /** 外壳各段类串(候选类收集与测试读;全部来自 base/overlay-shell 的一份配方) */
42
45
  export const OVERLAY_SHELL_CLASS = {
43
- // 最外层只放 core 写的 hidden 属性,不带任何类(core 样式引擎没有 preflight,hidden 与 flex 同元素会失效);fixed / flex 在内层
44
- // 入场动画:core 切 hidden(display:none → 显示)时 CSS 动画自动重播;遮罩淡入、对话框缩放淡入、抽屉从 end 侧滑入(RTL 换向)
45
- // 退场:显隐外层(_layer)经 core 的 renderPorts.hideTransition 钩子(base/overlay-runtime)退场:关闭时先标 data-kit-leaving 等退场动画结束再真隐藏(退场关键帧由主题侧补,没有则立即隐藏)
46
- dialogRow: 'fixed inset-0 z-50 flex items-center justify-center bg-scrim p-card motion-safe:animate-kit-fade',
47
- // 宽度两档 + 抽屉一档读 design 真源(kit-limits#overlay):对话框 480 默认、720 长表单(dialogWide)、抽屉 560
48
- dialog: dialogPanelClass(KIT_OVERLAY_WIDTH_CLASS.dialog),
49
- dialogWide: dialogPanelClass(KIT_OVERLAY_WIDTH_CLASS.dialogWide),
50
- dialogXWide: dialogPanelClass(KIT_OVERLAY_WIDTH_CLASS.dialogXWide),
51
- drawerRow: 'fixed inset-0 z-50 flex justify-end bg-scrim motion-safe:animate-kit-fade',
52
- // 抽屉三档(narrow / default / wide)读 kit-limits#overlay.drawerPx;面板类串与命令式 mountKitDrawer 同一份(recipes/overlay.ts#kitDrawerPanelClass)
53
- drawer: kitDrawerPanelClass('default'),
54
- header: kitOverlayHeaderRecipe(),
55
- title: kitTypographyRecipe('dialogTitle'),
56
- close: 'inline-flex size-8 shrink-0 border-0 bg-transparent p-0 cursor-pointer items-center justify-center rounded-md text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
57
- headerActions: 'flex items-center gap-cluster',
58
- body: kitOverlayBodyRecipe(),
59
- footer: kitOverlayFooterRecipe(),
46
+ dialogRow: DIALOG.scrim,
47
+ dialog: DIALOG.panel,
48
+ dialogWide: kitShellClasses({ kind: 'dialog', dialogTier: 'wide' }).panel,
49
+ dialogXWide: kitShellClasses({ kind: 'dialog', dialogTier: 'xwide' }).panel,
50
+ drawerRow: DRAWER.scrim,
51
+ drawer: DRAWER.panel,
52
+ header: DIALOG.header,
53
+ title: DIALOG.title,
54
+ close: DIALOG.close,
55
+ headerActions: DIALOG.headActions,
56
+ body: DIALOG.body,
57
+ footer: DIALOG.footer,
60
58
  } as const;
61
59
 
62
- /**
63
- * 对话框用哪一档宽度(U1b):表单字段数超过 kit-limits#overlay.wideFieldCount、或含穿梭框(component: Transfer)的长表单走 720,其余 480。
64
- * 入参是 form 视图声明(view.form);读不出字段时回 480 档。
65
- */
66
- export function dialogIsWide(formView: unknown, schema?: SchemaLike): boolean {
67
- const fields = formFieldsOf(formView);
68
- if (fields.length > KIT_OVERLAY_LIMITS.wideFieldCount) return true;
69
- return fields.some((f) => componentOfField(f, schema) === 'Transfer');
70
- }
71
-
72
- /** 字段声明所在的 schema(只读 edit / component 两个键:字段控件常常写在 schema 里,而不是视图字段项里) */
73
- type SchemaLike = Readonly<Record<string, { edit?: unknown; component?: unknown } | undefined>>;
74
-
75
- /** 字段声明用的控件名:字段项自己写的 component 优先,其次 schema 里该字段的 edit / component */
76
- function componentOfField(decl: unknown, schema: SchemaLike | undefined): string {
77
- const name = typeof decl === 'string' ? decl : decl !== null && typeof decl === 'object' ? (decl as { name?: unknown }).name : undefined;
78
- const own = decl !== null && typeof decl === 'object' ? (decl as { component?: unknown }).component : undefined;
79
- if (typeof own === 'string' && own !== '') return own;
80
- const fromSchema = typeof name === 'string' ? schema?.[name] : undefined;
81
- const c = fromSchema?.edit ?? fromSchema?.component;
82
- return typeof c === 'string' ? c : '';
83
- }
84
-
85
- /** form 视图的全部字段声明:顶层 fields 与 groups[].fields 合并(分组表单的字段在 groups 里,也算长表单) */
86
- function formFieldsOf(formView: unknown): unknown[] {
87
- if (formView === null || typeof formView !== 'object') return [];
88
- const v = formView as { fields?: unknown; groups?: unknown };
89
- const out: unknown[] = Array.isArray(v.fields) ? [...v.fields] : [];
90
- if (Array.isArray(v.groups)) {
91
- for (const g of v.groups) {
92
- const gf = g !== null && typeof g === 'object' ? (g as { fields?: unknown }).fields : undefined;
93
- if (Array.isArray(gf)) out.push(...gf);
94
- }
95
- }
96
- return out;
97
- }
98
-
99
- /**
100
- * 对话框宽度三档:form 含画布(component: FlowEditor)走 960;含穿梭框(Transfer,字段或浮层的静态组件)或字段数超阈值走 720;其余 480。
101
- * 入参是浮层内容:form 视图声明与静态组件名;页面写的宽度类不参与(见 stripOverlayWidthClasses)。
102
- */
103
- export function dialogWidthOf(content: { form?: unknown; staticComponent?: unknown; schema?: SchemaLike }): KitDialogWidth {
104
- const fields = formFieldsOf(content.form);
105
- if (fields.some((f) => componentOfField(f, content.schema) === 'FlowEditor')) return 'xwide';
106
- if (content.staticComponent === 'Transfer') return 'wide';
107
- return dialogIsWide(content.form, content.schema) ? 'wide' : 'default';
108
- }
109
-
110
- function dialogPanelOf(width: boolean | KitDialogWidth): string {
111
- const tier: KitDialogWidth = width === true ? 'wide' : width === false ? 'default' : width;
112
- return tier === 'xwide' ? OVERLAY_SHELL_CLASS.dialogXWide : tier === 'wide' ? OVERLAY_SHELL_CLASS.dialogWide : OVERLAY_SHELL_CLASS.dialog;
60
+ function tierOf(width: boolean | KitDialogWidth): KitDialogTier {
61
+ return width === true ? 'wide' : width === false ? 'default' : width;
113
62
  }
114
63
 
115
64
  /** 空串不出 class 属性,否则 ` class="..."` */
@@ -117,9 +66,9 @@ export function classAttr(value: string): string {
117
66
  return value === '' ? '' : ` class="${esc(value)}"`;
118
67
  }
119
68
 
120
- /** 弹窗关闭钮(SVG 图标钮,类串与 data/modal-dialog 的关闭钮同一套):各弹窗外壳共用 */
69
+ /** 弹窗关闭钮(SVG 图标钮,类串与命令式浮层的关闭钮同一份):各弹窗外壳共用 */
121
70
  export function closeButtonHtml(id: string, label: string): string {
122
- return `<button type="button" data-soma-id="${esc(id)}" aria-label="${esc(label)}" class="${OVERLAY_SHELL_CLASS.close}">${kitIconHtml('close', 'md')}</button>`;
71
+ return `<button type="button" data-soma-id="${esc(id)}" aria-label="${esc(label)}"${classAttr(OVERLAY_SHELL_CLASS.close)}>${kitIconHtml('close', 'md')}</button>`;
123
72
  }
124
73
 
125
74
  export interface DialogShellIds {
@@ -155,18 +104,17 @@ export function dialogTitles(formTitle: unknown, dflt: { create: string; edit: s
155
104
 
156
105
  /** 新增 / 编辑弹窗:标题按 creating / editing 两个真值显隐,正文是 KitObjectForm */
157
106
  export function dialogHtml(ids: DialogShellIds, copy: { create: string; edit: string }, body: string, areaClass: Record<string, string>, closeLabel = 'Close', footer = '', wide: boolean | KitDialogWidth = false): string {
158
- const panel = mergeClass(dialogPanelOf(wide), stripOverlayWidthClasses(areaClass.dialog));
159
- return `<div data-soma-id="${esc(ids.dialogLayer)}"${LAYER_HOST_CLASS_ATTR}>`
160
- + `<div data-kit-scrim="" ${KIT_FIXED_ATTRIBUTE}=""${classAttr(OVERLAY_SHELL_CLASS.dialogRow)}>`
161
- + `<div role="dialog" aria-modal="true"${classAttr(panel)} aria-labelledby="${esc(ids.dialogTitle)}">`
162
- + `<div data-kit-dialog-header=""${classAttr(OVERLAY_SHELL_CLASS.header)}>`
163
- + `<h2 id="${esc(ids.dialogTitle)}"${classAttr(OVERLAY_SHELL_CLASS.title)}><span data-soma-id="${esc(ids.dialogTitleCreate)}">${esc(copy.create)}</span>`
164
- + `<span data-soma-id="${esc(ids.dialogTitleEdit)}">${esc(copy.edit)}</span></h2>`
165
- + closeButtonHtml(ids.dialogClose, closeLabel)
166
- + '</div>'
167
- + `<div data-kit-dialog-body="" ${KIT_OVERLAY_SCROLL_ATTR}=""${classAttr(OVERLAY_SHELL_CLASS.body)}>${body}</div>`
168
- + (footer !== '' ? `<div data-kit-dialog-footer=""${classAttr(OVERLAY_SHELL_CLASS.footer)}>${footer}</div>` : '')
169
- + '</div></div></div>';
107
+ const decision = { kind: 'dialog', dialogTier: tierOf(wide) } as const;
108
+ const panelClass = mergeClass(kitShellClasses(decision).panel, stripOverlayWidthClasses(areaClass.dialog));
109
+ return `<div data-soma-id="${esc(ids.dialogLayer)}"${LAYER_HOST_CLASS_ATTR}>${kitShellHtml({
110
+ ...decision,
111
+ panelClass,
112
+ titleId: ids.dialogTitle,
113
+ titleHtml: `<span data-soma-id="${esc(ids.dialogTitleCreate)}">${esc(copy.create)}</span><span data-soma-id="${esc(ids.dialogTitleEdit)}">${esc(copy.edit)}</span>`,
114
+ close: { label: closeLabel, somaId: ids.dialogClose },
115
+ bodyHtml: body,
116
+ footerHtml: footer !== '' ? footer : null,
117
+ })}</div>`;
170
118
  }
171
119
 
172
120
  // ---------------------------------------------------------------- 附加浮层(dialog / drawer)
@@ -193,19 +141,22 @@ export function overlayHtml(
193
141
  wide: boolean | KitDialogWidth = false,
194
142
  /** 抽屉宽度档(页面 DSL 浮层声明的 width;只对 kind: drawer 有效,缺省 default) */
195
143
  drawerWidth: KitDrawerWidth = 'default',
144
+ /** 本浮层的「提交」具名动作(提交类事件绑的应用动作):成功后由框架默认关窗并给成功反馈(见 app/define-kit-actions) */
145
+ submitActions: readonly string[] = [],
196
146
  ): string {
197
- const isDrawer = kind === 'drawer';
198
- const base = isDrawer ? kitDrawerPanelClass(drawerWidth) : dialogPanelOf(wide);
199
- const panel = mergeClass(mergeClass(base, stripOverlayWidthClasses(areaClass[kind])), stripOverlayWidthClasses(panelClass));
147
+ const decision = kind === 'drawer' ? { kind, drawerWidth } as const : { kind, dialogTier: tierOf(wide) } as const;
148
+ const panel = mergeClass(mergeClass(kitShellClasses(decision).panel, stripOverlayWidthClasses(areaClass[kind])), stripOverlayWidthClasses(panelClass));
200
149
  const editHost = `<div data-soma-component="Button" data-soma-id="${esc(ids.edit)}"></div>`;
201
- return `<div data-soma-id="${esc(ids.layer)}"${LAYER_HOST_CLASS_ATTR}>`
202
- + `<div data-kit-scrim="" ${KIT_FIXED_ATTRIBUTE}=""${classAttr(isDrawer ? OVERLAY_SHELL_CLASS.drawerRow : OVERLAY_SHELL_CLASS.dialogRow)}>`
203
- + `<div role="dialog" aria-modal="true"${classAttr(panel)} data-kit-part="${isDrawer ? KIT_PART_DRAWER : KIT_PART_DIALOG}" aria-labelledby="${esc(ids.title)}">`
204
- + `<div data-kit-overlay-header=""${classAttr(OVERLAY_SHELL_CLASS.header)}>`
205
- + `<h2 id="${esc(ids.title)}" data-soma-id="${esc(ids.title)}"${classAttr(OVERLAY_SHELL_CLASS.title)} data-kit-part="${KIT_PART_TITLE_DIALOG}">${esc(title)}</h2>`
206
- + (withEdit ? `<div${classAttr(OVERLAY_SHELL_CLASS.headerActions)}>${editHost}${closeButtonHtml(ids.close, closeLabel)}</div>` : closeButtonHtml(ids.close, closeLabel))
207
- + '</div>'
208
- + `<div data-kit-overlay-body="" ${KIT_OVERLAY_SCROLL_ATTR}=""${classAttr(OVERLAY_SHELL_CLASS.body)}>${body}</div>`
209
- + (footer !== '' ? `<div data-kit-overlay-footer=""${classAttr(OVERLAY_SHELL_CLASS.footer)}>${footer}</div>` : '')
210
- + '</div></div></div>';
150
+ const submitMark = submitActions.length > 0 ? ` ${KIT_SUBMIT_ACTIONS_ATTR}="${esc(submitActions.join(' '))}"` : '';
151
+ return `<div data-soma-id="${esc(ids.layer)}"${submitMark}${LAYER_HOST_CLASS_ATTR}>${kitShellHtml({
152
+ ...decision,
153
+ panelClass: panel,
154
+ titleId: ids.title,
155
+ titleSomaId: ids.title,
156
+ titleHtml: esc(title),
157
+ ...(withEdit ? { headActionsHtml: editHost } : {}),
158
+ close: { label: closeLabel, somaId: ids.close },
159
+ bodyHtml: body,
160
+ footerHtml: footer !== '' ? footer : null,
161
+ })}</div>`;
211
162
  }
@@ -17,9 +17,9 @@ import { emitObject } from '../../object-renderer/emit-object';
17
17
  import { savedNoticePipe } from '../../object-renderer/form-notify';
18
18
  import { viewAnchor } from '../../object-renderer/emit-static';
19
19
  import type { KitDiagnostic, KitObject, KitViewForm } from '../../object-renderer/types';
20
- import type { KitFragment } from '../../compile/fragment';
20
+ import type { KitFragment } from '../../object-renderer/fragment';
21
21
  import type { KitBizContext, KitBizInput } from '../types';
22
- import { mergeClass } from '../../object-renderer/merge-class';
22
+ import { mergeClass } from '../../shared/merge-class';
23
23
  import {
24
24
  bizObjectName, checkRoleAllowedViews, finishBizCompile, validateBizAreaClass,
25
25
  } from '../shared/compile-helpers';