soma-kit 0.1.11 → 0.1.12

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 (302) hide show
  1. package/README.md +103 -110
  2. package/bin/soma-kit.mjs +1 -1
  3. package/bin/soma.mjs +22 -0
  4. package/package.json +13 -7
  5. package/packs/finance/reconcile-board.ts +5 -2
  6. package/packs/finance/reconcile-desk/compile.ts +3 -2
  7. package/spec/generated/kit-app.schema.json +776 -38
  8. package/spec/generated/kit-page.schema.json +1613 -224
  9. package/spec/kit-grammar.json +770 -529
  10. package/spec/kit-grammar.schema.json +1962 -392
  11. package/src/app/app-config.ts +371 -347
  12. package/src/app/component-gate.ts +12 -15
  13. package/src/app/compose-apps.ts +79 -8
  14. package/src/app/define-kit-actions.ts +245 -41
  15. package/src/app/define-kit-app.ts +174 -31
  16. package/src/app/define-kit-view.ts +100 -0
  17. package/src/app/envelope.ts +1 -161
  18. package/src/app/index.ts +13 -2
  19. package/src/app/kit-view-context.ts +290 -0
  20. package/src/app/notify-renderer.ts +1 -115
  21. package/src/app/paged-list-adapter.ts +1 -240
  22. package/src/app/server-pages.ts +8 -2
  23. package/src/app/server.ts +491 -101
  24. package/src/app/submit.types.ts +1 -1
  25. package/src/app/theme-endpoint.ts +63 -0
  26. package/src/app/theme-runtime-shared.ts +1 -0
  27. package/src/app/theme-runtime.ts +663 -0
  28. package/src/base/action-busy.ts +2 -2
  29. package/src/base/action-gate.ts +4 -255
  30. package/src/base/action-slots.ts +47 -0
  31. package/src/base/alert.ts +5 -3
  32. package/src/base/avatar.ts +2 -2
  33. package/src/base/button.ts +46 -29
  34. package/src/base/cascader.ts +11 -12
  35. package/src/base/check-core.ts +1 -1
  36. package/src/base/choice.ts +28 -26
  37. package/src/base/class-candidates.ts +17 -0
  38. package/src/base/color-picker.ts +6 -6
  39. package/src/base/combobox.ts +5 -3
  40. package/src/base/command-palette.ts +9 -5
  41. package/src/base/countdown.ts +1 -1
  42. package/src/base/date-range.ts +25 -11
  43. package/src/base/date.ts +85 -17
  44. package/src/base/divider.ts +2 -2
  45. package/src/base/fab.ts +11 -4
  46. package/src/base/image.ts +1 -1
  47. package/src/base/index.ts +9 -3
  48. package/src/base/input.ts +42 -13
  49. package/src/base/kbd.ts +3 -1
  50. package/src/base/link.ts +4 -4
  51. package/src/base/listbox-core.ts +50 -30
  52. package/src/base/loading-gate.ts +133 -0
  53. package/src/base/mentions.ts +5 -5
  54. package/src/base/menu-button.ts +6 -1
  55. package/src/base/menu-core.ts +4 -0
  56. package/src/base/motion/aura.ts +2 -2
  57. package/src/base/motion/hover-3d.ts +2 -2
  58. package/src/base/motion/hover-gallery.ts +2 -2
  59. package/src/base/motion/marquee.ts +2 -2
  60. package/src/base/motion/text-rotate.ts +2 -2
  61. package/src/base/number.ts +93 -80
  62. package/src/base/otp.ts +4 -1
  63. package/src/base/permission-gate.ts +6 -0
  64. package/src/base/popover.ts +40 -8
  65. package/src/base/popup.ts +79 -14
  66. package/src/base/price-text.ts +2 -2
  67. package/src/base/progress.ts +2 -2
  68. package/src/base/qr-code.ts +4 -4
  69. package/src/base/qty-stepper.ts +9 -3
  70. package/src/base/range.ts +2 -2
  71. package/src/base/rating.ts +1 -1
  72. package/src/base/segmented.ts +4 -0
  73. package/src/base/select.ts +4 -3
  74. package/src/base/shared.ts +221 -29
  75. package/src/base/swap.ts +4 -1
  76. package/src/base/switch.ts +1 -1
  77. package/src/base/tag-input.ts +14 -10
  78. package/src/base/tag.ts +5 -1
  79. package/src/base/text.ts +39 -6
  80. package/src/base/textarea.ts +37 -11
  81. package/src/base/time-picker.ts +12 -9
  82. package/src/base/tree-select.ts +15 -8
  83. package/src/base/upload.ts +34 -5
  84. package/src/base/virtual-list.ts +107 -1
  85. package/src/biz/approval-desk/compile.ts +23 -41
  86. package/src/biz/auth-panel/compile.ts +37 -52
  87. package/src/biz/auth-panel/index.ts +1 -1
  88. package/src/biz/category-crud/compile.ts +22 -36
  89. package/src/biz/checkout-page/compile.ts +21 -5
  90. package/src/biz/compose.ts +13 -27
  91. package/src/biz/define.ts +5 -4
  92. package/src/biz/import-wizard/compile.ts +22 -26
  93. package/src/biz/import-wizard/hub.ts +126 -61
  94. package/src/biz/import-wizard/shell.ts +3 -3
  95. package/src/biz/index.ts +3 -3
  96. package/src/biz/landing-page/compile.ts +19 -3
  97. package/src/biz/link/hub.ts +49 -20
  98. package/src/biz/link/shared.ts +115 -118
  99. package/src/biz/master-sub/compile.ts +31 -44
  100. package/src/biz/multi-board/compile.ts +34 -49
  101. package/src/biz/multi-board/index.ts +18 -1
  102. package/src/biz/multi-board/shell.ts +24 -15
  103. package/src/biz/notification-center/compile.ts +21 -33
  104. package/src/biz/page-templates/domain-templates.ts +80 -13
  105. package/src/biz/page-templates/result-page/compile.ts +11 -2
  106. package/src/biz/page-templates/shared.ts +34 -36
  107. package/src/biz/record-detail/compile.ts +47 -42
  108. package/src/biz/record-detail/index.ts +11 -1
  109. package/src/biz/settings-center/compile.ts +6 -5
  110. package/src/biz/shared/action-host.ts +91 -211
  111. package/src/biz/shared/compile-helpers.ts +80 -0
  112. package/src/biz/shared/coordinator.ts +486 -83
  113. package/src/biz/shared/index.ts +8 -2
  114. package/src/biz/shared/overlay-shell.ts +80 -0
  115. package/src/biz/shared/pipes.ts +43 -30
  116. package/src/biz/shared/remove-key.ts +6 -0
  117. package/src/biz/shared/remove-wire.ts +29 -0
  118. package/src/biz/shared/runtime-hub.ts +216 -24
  119. package/src/biz/single-form/compile.ts +15 -37
  120. package/src/biz/standard-crud/compile.ts +62 -107
  121. package/src/biz/standard-crud/shell.ts +16 -66
  122. package/src/biz/step-form/compile.ts +26 -97
  123. package/src/biz/step-form/hub.ts +34 -41
  124. package/src/biz/types.ts +4 -3
  125. package/src/cli/core-imports.ts +54 -0
  126. package/src/cli/kit-cli.ts +130 -26
  127. package/src/cli/kit-init.ts +222 -0
  128. package/src/cli/service-endpoint-check.ts +425 -0
  129. package/src/cli/source-path-check.d.mts +17 -0
  130. package/src/cli/source-path-check.mjs +334 -0
  131. package/src/cli/view-writes.ts +752 -0
  132. package/src/compile/action-host-attach.ts +21 -29
  133. package/src/compile/closed-set.ts +509 -0
  134. package/src/compile/compile-page.ts +219 -72
  135. package/src/compile/component-candidates.ts +1 -1
  136. package/src/compile/hints.ts +30 -1
  137. package/src/compile/index.ts +1 -0
  138. package/src/compile/kit-error.ts +1 -0
  139. package/src/compile/locate.ts +21 -1
  140. package/src/compile/parse.ts +370 -41
  141. package/src/compile/redirect.ts +6 -2
  142. package/src/compile/styles.ts +35 -2
  143. package/src/compile/types.ts +18 -2
  144. package/src/compile/view-check.ts +151 -0
  145. package/src/data/amount-breakdown.ts +2 -2
  146. package/src/data/anchor-nav.ts +2 -2
  147. package/src/data/approval-flow.ts +2 -2
  148. package/src/data/assignment-picker.ts +40 -29
  149. package/src/data/async-result-panel.ts +62 -6
  150. package/src/data/breadcrumbs.ts +2 -2
  151. package/src/data/calendar.ts +22 -25
  152. package/src/data/carousel.ts +5 -2
  153. package/src/data/chart.ts +42 -34
  154. package/src/data/checklist.ts +2 -2
  155. package/src/data/code-view.ts +4 -2
  156. package/src/data/comment-thread.ts +5 -2
  157. package/src/data/confirm-dialog.ts +10 -0
  158. package/src/data/context-menu.ts +29 -37
  159. package/src/data/d9-util.ts +2 -18
  160. package/src/data/diff.ts +4 -2
  161. package/src/data/dock.ts +2 -2
  162. package/src/data/embed.ts +2 -1
  163. package/src/data/field-mapper.ts +31 -26
  164. package/src/data/flow-editor-contract.ts +1 -1
  165. package/src/data/flow-editor.ts +89 -100
  166. package/src/data/flow-node-options.ts +90 -0
  167. package/src/data/flow-remote-options.ts +0 -103
  168. package/src/data/footer.ts +2 -2
  169. package/src/data/form-draft-registry.ts +2 -4
  170. package/src/data/gantt.ts +14 -17
  171. package/src/data/hero.ts +2 -2
  172. package/src/data/image-viewer.ts +20 -26
  173. package/src/data/index.ts +0 -2
  174. package/src/data/item-list.ts +31 -22
  175. package/src/data/kanban.ts +43 -42
  176. package/src/data/media-grid.ts +14 -19
  177. package/src/data/menu.ts +2 -2
  178. package/src/data/mockup.ts +2 -2
  179. package/src/data/modal-dialog.ts +22 -18
  180. package/src/data/navbar.ts +7 -2
  181. package/src/data/notify-renderer.ts +235 -0
  182. package/src/data/object-form.ts +1036 -648
  183. package/src/data/pager.ts +65 -29
  184. package/src/data/permission-matrix.ts +20 -21
  185. package/src/data/permission-tree.ts +28 -26
  186. package/src/data/pricing-table.ts +9 -3
  187. package/src/data/reaction-bar.ts +77 -88
  188. package/src/data/read-rollback.ts +73 -0
  189. package/src/data/record-card.ts +3 -3
  190. package/src/data/record-picker.ts +93 -50
  191. package/src/data/redirect.ts +32 -32
  192. package/src/data/remote-options.ts +13 -6
  193. package/src/data/request-console.ts +5 -3
  194. package/src/data/resident.ts +2 -1
  195. package/src/data/result-panel.ts +4 -2
  196. package/src/data/rich-text.ts +45 -55
  197. package/src/data/row-editor.ts +285 -52
  198. package/src/data/rule-builder.ts +18 -12
  199. package/src/data/shape-util.ts +4 -0
  200. package/src/data/stat-group.ts +243 -101
  201. package/src/data/static-registry.ts +22 -11
  202. package/src/data/steps.ts +2 -2
  203. package/src/data/survey.ts +24 -29
  204. package/src/data/system-switcher.ts +2 -2
  205. package/src/data/timeline.ts +2 -2
  206. package/src/data/tour-guide.ts +22 -29
  207. package/src/data/transfer.ts +27 -23
  208. package/src/data/tree-table.ts +96 -48
  209. package/src/data/tree.ts +27 -34
  210. package/src/data/trend-line.ts +6 -24
  211. package/src/data/virtual-rows.ts +118 -76
  212. package/src/data/watermark.ts +2 -2
  213. package/src/data/wrap.ts +63 -38
  214. package/src/frames/blank-frame.ts +1 -0
  215. package/src/frames/index.ts +2 -2
  216. package/src/frames/page-bar.ts +12 -11
  217. package/src/frames/page-header.ts +14 -5
  218. package/src/frames/page-status.ts +2 -2
  219. package/src/frames/shared.ts +23 -17
  220. package/src/frames/single-frame.ts +1 -0
  221. package/src/frames/split-frame/shell.ts +5 -5
  222. package/src/frames/split-frame/wiring.ts +2 -2
  223. package/src/frames/tabs-frame/shell.ts +2 -13
  224. package/src/frames/tabs-frame/wiring.ts +4 -8
  225. package/src/frames/top-main-frame.ts +1 -0
  226. package/src/frames/types.ts +13 -2
  227. package/src/frames/workspace-frame/extras.ts +20 -4
  228. package/src/frames/workspace-frame/index.ts +1 -1
  229. package/src/frames/workspace-frame/shell.ts +1 -0
  230. package/src/frames/workspace-frame/state.ts +13 -6
  231. package/src/frames/workspace-frame/view.ts +119 -25
  232. package/src/generated/kit-grammar-runtime.ts +430 -366
  233. package/src/generated/page-origin.ts +0 -11
  234. package/src/i18n/kit-text.ts +23 -27
  235. package/src/index.ts +2 -1
  236. package/src/object-renderer/action-gate.ts +11 -147
  237. package/src/object-renderer/arrange.ts +71 -77
  238. package/src/object-renderer/collapse-wiring.ts +2 -2
  239. package/src/object-renderer/collection-expand.ts +2 -2
  240. package/src/object-renderer/collection-parts.ts +216 -100
  241. package/src/object-renderer/collection-table.ts +180 -42
  242. package/src/object-renderer/collection.ts +95 -79
  243. package/src/object-renderer/compile-data.ts +85 -100
  244. package/src/object-renderer/crud-bridge.ts +32 -0
  245. package/src/object-renderer/defaults.ts +8 -14
  246. package/src/object-renderer/display-checks.ts +3 -24
  247. package/src/object-renderer/emit-events.ts +186 -172
  248. package/src/object-renderer/emit-object.ts +15 -2
  249. package/src/object-renderer/emit-static.ts +174 -132
  250. package/src/object-renderer/field-value.ts +593 -396
  251. package/src/object-renderer/filter-reload.ts +70 -0
  252. package/src/object-renderer/form-detail.ts +112 -2
  253. package/src/object-renderer/index.ts +26 -0
  254. package/src/object-renderer/key-field.ts +12 -0
  255. package/src/object-renderer/linkage.ts +7 -270
  256. package/src/object-renderer/merge-class.ts +18 -1
  257. package/src/object-renderer/path-pick.ts +27 -0
  258. package/src/object-renderer/render-object.ts +405 -86
  259. package/src/object-renderer/request-actions.ts +230 -249
  260. package/src/object-renderer/table-actions.ts +195 -95
  261. package/src/object-renderer/table-summary.ts +2 -2
  262. package/src/object-renderer/table-tools.ts +418 -84
  263. package/src/object-renderer/types.ts +128 -122
  264. package/src/object-renderer/view-binding.ts +196 -0
  265. package/src/page-target/ai-surface.ts +37 -0
  266. package/src/page-target/compile.ts +48 -8
  267. package/src/page-target/index.ts +8 -1
  268. package/src/page-target/intent-schema.ts +154 -28
  269. package/src/page-target/target.ts +257 -50
  270. package/src/page-target/writer-policy.ts +14 -3
  271. package/src/recipes/container.ts +165 -0
  272. package/src/recipes/control.ts +219 -0
  273. package/src/recipes/index.ts +263 -0
  274. package/src/recipes/overlay.ts +182 -0
  275. package/src/recipes/state.ts +70 -0
  276. package/src/recipes/table-row.ts +51 -0
  277. package/src/recipes/typography.ts +87 -0
  278. package/src/shared/action-field-guard.ts +41 -0
  279. package/src/shared/envelope.ts +207 -0
  280. package/src/shared/escape.ts +57 -0
  281. package/src/shared/kit-error.ts +21 -0
  282. package/src/shared/paged-list-adapter.ts +240 -0
  283. package/src/shared/path-guard.ts +127 -0
  284. package/src/shared/theme-runtime-shared.ts +175 -0
  285. package/src/shared/view-info.ts +10 -0
  286. package/src/theme/index.ts +12 -0
  287. package/src/theme/kit-theme-text.ts +1 -1
  288. package/src/theme/kit-theme.css +38 -1
  289. package/src/theme/kit-theme.tpl +38 -1
  290. package/src/theme/nine-dim-structure.ts +77 -0
  291. package/src/theme/surface-layers.ts +97 -0
  292. package/src/theme/theme-tokens.ts +85 -79
  293. package/src/theme/theme-types.ts +71 -0
  294. package/src/theme/typography.ts +17 -17
  295. package/src/biz/shared/step-values.ts +0 -25
  296. package/src/biz/step-form/steps-ref.ts +0 -112
  297. package/src/data/options-bus.ts +0 -24
  298. package/src/data/prompt-dialog.ts +0 -235
  299. package/src/object-renderer/adopt-gate.ts +0 -333
  300. package/src/object-renderer/field-policy.ts +0 -89
  301. package/src/object-renderer/outcome-draft.ts +0 -61
  302. package/src/theme/nine-dim-palettes.ts +0 -1473
@@ -16,12 +16,27 @@ import {
16
16
  isKitType,
17
17
  type KitFieldSetDefault,
18
18
  } from './defaults';
19
- import { adoptOf } from './adopt-gate';
20
19
  import { resultSlotOf } from './action-gate';
20
+ import {
21
+ KIT_PART_CARD,
22
+ KIT_PART_PANEL,
23
+ KIT_PART_SECTION,
24
+ KIT_PART_STAT_VALUE,
25
+ KIT_PART_TITLE_DIALOG,
26
+ KIT_PART_TITLE_PAGE,
27
+ KIT_PART_TITLE_SECTION,
28
+ KIT_PART_WELL,
29
+ kitTypographyRecipe,
30
+ KIT_VIEW_HIGHLIGHT_CLASS,
31
+ resolveContainerEmphasisClass,
32
+ resolveSurfaceRecipeClass,
33
+ } from './form-detail';
21
34
  import { checkDisplayProps } from './display-checks';
22
- import { checkFlowFields, checkViewFlowNodeOptions, checkViewRowColumns, collectFieldValues } from './field-value';
23
- import { fieldPolicyOf } from './field-policy';
24
- import { normalizeThen, predicateToCore } from './linkage';
35
+ import { checkOnDraft, checkSubmitDisabled, collectFieldState } from './view-binding';
36
+ import { checkEnumOptionsAndEditCompatibility, checkFieldRules, checkFlowFields, checkViewFlowNodeOptions, checkViewRowColumns, collectFieldValues, fieldNamesOf } from './field-value';
37
+ import { validateRequestAction } from './request-actions';
38
+ import { hasBehaviorFrom, readStatePathsOf } from './crud-bridge';
39
+ import { KIT_ACTION_TONES } from './emit-events';
25
40
  import { checkClasses, mergeClass, splitClasses } from './merge-class';
26
41
  import { slotModeOf } from './mode';
27
42
  import type {
@@ -44,10 +59,79 @@ import type {
44
59
  KitViewSlot,
45
60
  } from './types';
46
61
 
62
+ const ENTITY_REF_RE = /^\$entity\.([A-Za-z_][A-Za-z0-9_]*)$/;
63
+ const DICT_REF_RE = /^\$dict\.([A-Za-z_][A-Za-z0-9_]*)$/;
64
+
65
+ function expandRawSchemaIfNeeded(rawSchema: unknown, ctx: KitRenderContext, diags: KitDiagnostic[]): Record<string, KitFieldSchema> {
66
+ if (typeof rawSchema === 'string') {
67
+ const m = ENTITY_REF_RE.exec(rawSchema.trim());
68
+ if (!m) {
69
+ diags.push({ code: 'KIT-OBJ-001', path: 'schema', message: `schema 字符串引用必须为 $entity.<实体名>(收到 "${rawSchema}")` });
70
+ return {};
71
+ }
72
+ const entityDef = ctx.entities?.[m[1]!];
73
+ if (!entityDef || typeof entityDef !== 'object') {
74
+ diags.push({ code: 'KIT-OBJ-001', path: 'schema', message: `对象引用了未声明的实体 ${rawSchema}` });
75
+ return {};
76
+ }
77
+ const out: Record<string, KitFieldSchema> = {};
78
+ for (const [k, v] of Object.entries(entityDef)) {
79
+ if (v && typeof v === 'object') out[k] = { ...(v as KitFieldSchema) };
80
+ }
81
+ return out;
82
+ }
83
+ if (rawSchema !== null && typeof rawSchema === 'object' && !Array.isArray(rawSchema) && '$ref' in (rawSchema as Record<string, unknown>)) {
84
+ const refObj = rawSchema as { $ref?: unknown; pick?: unknown; omit?: unknown; override?: unknown };
85
+ const refStr = typeof refObj.$ref === 'string' ? refObj.$ref.trim() : '';
86
+ const m = ENTITY_REF_RE.exec(refStr);
87
+ if (!m) {
88
+ diags.push({ code: 'KIT-OBJ-001', path: 'schema.$ref', message: `schema.$ref 必须为 $entity.<实体名>(收到 "${String(refObj.$ref)}")` });
89
+ return {};
90
+ }
91
+ const entityDef = ctx.entities?.[m[1]!];
92
+ if (!entityDef || typeof entityDef !== 'object') {
93
+ diags.push({ code: 'KIT-OBJ-001', path: 'schema.$ref', message: `对象引用了未声明的实体 ${refStr}` });
94
+ return {};
95
+ }
96
+ let names = Object.keys(entityDef);
97
+ if (Array.isArray(refObj.pick)) {
98
+ const picks = refObj.pick.filter((x): x is string => typeof x === 'string');
99
+ for (const p of picks) {
100
+ if (!(p in entityDef)) diags.push({ code: 'KIT-OBJ-001', path: 'schema.pick', message: `schema.pick 引用了实体 ${refStr} 中不存在的字段 ${p}` });
101
+ }
102
+ names = picks.filter((p) => p in entityDef);
103
+ }
104
+ if (Array.isArray(refObj.omit)) {
105
+ const omits = new Set(refObj.omit.filter((x): x is string => typeof x === 'string'));
106
+ names = names.filter((n) => !omits.has(n));
107
+ }
108
+ const out: Record<string, KitFieldSchema> = {};
109
+ for (const n of names) {
110
+ const base = entityDef[n];
111
+ if (base && typeof base === 'object') out[n] = { ...(base as KitFieldSchema) };
112
+ }
113
+ if (refObj.override && typeof refObj.override === 'object' && !Array.isArray(refObj.override)) {
114
+ for (const [fName, over] of Object.entries(refObj.override as Record<string, unknown>)) {
115
+ if (over && typeof over === 'object') {
116
+ out[fName] = { ...(out[fName] ?? (entityDef[fName] as KitFieldSchema) ?? ({} as KitFieldSchema)), ...(over as Partial<KitFieldSchema>) };
117
+ }
118
+ }
119
+ }
120
+ return out;
121
+ }
122
+ return (rawSchema ?? {}) as Record<string, KitFieldSchema>;
123
+ }
124
+
47
125
  function resolveSchema(obj: KitObject, ctx: KitRenderContext, diags: KitDiagnostic[]): KitSchema {
48
126
  const out: KitSchema = {};
49
- for (const [key, raw] of Object.entries(obj.schema)) {
50
- let field: KitFieldSchema = raw;
127
+ const rawObj = obj as unknown as Record<string, unknown>;
128
+ const hasWrite = (obj.behavior?.write !== undefined && obj.behavior.write !== null)
129
+ || (rawObj.write !== undefined && rawObj.write !== null);
130
+ const primaryKey = typeof obj.primaryKey === 'string' && obj.primaryKey.trim() !== '' ? obj.primaryKey.trim() : 'id';
131
+ const sourceSchema = expandRawSchemaIfNeeded(obj.schema, ctx, diags);
132
+
133
+ for (const [key, raw] of Object.entries(sourceSchema)) {
134
+ let field: KitFieldSchema = { ...raw };
51
135
  if (raw.ref) {
52
136
  const shared = ctx.sharedSchema?.[raw.ref];
53
137
  if (!shared) {
@@ -56,6 +140,53 @@ function resolveSchema(obj: KitObject, ctx: KitRenderContext, diags: KitDiagnost
56
140
  field = { ...shared, ...raw };
57
141
  }
58
142
  }
143
+ if (typeof (field.options as unknown) === 'string') {
144
+ const optStr = String(field.options).trim();
145
+ const dm = DICT_REF_RE.exec(optStr);
146
+ if (!dm) {
147
+ diags.push({ code: 'KIT-FORM-003', path: `schema.${key}.options`, message: `字段 ${key} 的 options 字符串引用必须为 $dict.<字典名>(收到 "${optStr}")` });
148
+ } else {
149
+ const dictItems = ctx.dicts?.[dm[1]!];
150
+ if (!Array.isArray(dictItems) || dictItems.length === 0) {
151
+ diags.push({ code: 'KIT-FORM-003', path: `schema.${key}.options`, message: `字段 ${key} 引用了未声明的字典 ${optStr}` });
152
+ } else {
153
+ field.options = dictItems.map((it) => ({ ...it })) as KitFieldSchema['options'];
154
+ }
155
+ }
156
+ }
157
+ const rawAccess = field.access ?? field.permission;
158
+ if (rawAccess !== undefined) {
159
+ if (rawAccess === 'read' || rawAccess === 'r') {
160
+ field.permission = 'r';
161
+ field.access = 'read';
162
+ } else if (rawAccess === 'write' || rawAccess === 'w') {
163
+ field.permission = 'w';
164
+ field.access = 'write';
165
+ } else if (rawAccess === 'create') {
166
+ field.permission = 'create';
167
+ field.access = 'create';
168
+ } else {
169
+ const attrKey = field.access !== undefined ? 'access' : 'permission';
170
+ diags.push({ code: 'KIT-OBJ-006', path: `schema.${key}.${attrKey}`, message: `字段 ${key} 的 ${attrKey} "${String(rawAccess)}" 不合法(允许:read / write / create)` });
171
+ field.permission = 'r';
172
+ field.access = 'read';
173
+ }
174
+ } else if (field.readonly === true) {
175
+ field.permission = 'r';
176
+ field.access = 'read';
177
+ } else if (hasWrite) {
178
+ const isPrimaryKey = field.key === true || key === primaryKey;
179
+ if (isPrimaryKey) {
180
+ field.permission = 'r';
181
+ field.access = 'read';
182
+ } else {
183
+ field.permission = 'w';
184
+ field.access = 'write';
185
+ }
186
+ } else {
187
+ field.permission = 'r';
188
+ field.access = 'read';
189
+ }
59
190
  if (!isKitType(field.type)) {
60
191
  diags.push({ code: 'KIT-TYPE-001', path: `schema.${key}.type`, message: `type ${String(field.type)} 未在 types 表登记` });
61
192
  }
@@ -101,7 +232,6 @@ function layoutClasses(l: KitLayoutIR, out: string[]): void {
101
232
  out.push(l.wrapClass, l.innerClass, l.headClass, l.rowClass, l.selectClass, l.actionsClass, KIT_CLASS_DEFAULTS.tableActions, l.stripeClass);
102
233
  for (const h of l.head) out.push(h.class);
103
234
  // G2:表头里的选择 / 操作列类、合计行类(这些只经组件 props 下发,不在 HTML 里)
104
- for (const w of l.rowClassWhen ?? []) out.push(w.class);
105
235
  out.push(l.selectHeadClass ?? '', l.actionsHeadClass ?? '', l.summaryRowClass ?? '', ...(l.summaryCellClasses ?? []));
106
236
  if (l.expand !== null) layoutClasses(l.expand.layout, out);
107
237
  break;
@@ -123,7 +253,31 @@ const RESERVED_STATIC_PROPS: ReadonlySet<string> = new Set(['data', 'map', 'char
123
253
  const STATIC_PROP_KEY = /^[a-z][A-Za-z0-9_]*$/;
124
254
 
125
255
  /** view.props(配置类 prop 透传)与 view.value(值绑定路径)的校验;违规的键丢弃并记 KIT-STATIC-001 */
126
- function staticProps(form: KitViewForm, path: string, diags: KitDiagnostic[]): { props?: Record<string, unknown>; value?: string } {
256
+ /** 实际值的类型名(诊断用):null / array 单列,其余取 typeof */
257
+ function literalTypeName(v: unknown): string {
258
+ if (v === null) return 'null';
259
+ if (Array.isArray(v)) return 'array';
260
+ return typeof v;
261
+ }
262
+
263
+ /**
264
+ * 字面量配置值是否符合契约 type:string / number / boolean / array / object / enum(只核是字符串,propTypes 不含枚举值);
265
+ * 未知类型 / 空串不核。null / undefined 视作「未填」不核。返回期望类型名,符合或不核返回 null。
266
+ */
267
+ function propTypeMismatch(type: string | undefined, v: unknown): string | null {
268
+ if (type === undefined || type === '' || v === null || v === undefined) return null;
269
+ switch (type) {
270
+ case 'string': case 'number': case 'boolean': return typeof v === type ? null : type;
271
+ case 'array': return Array.isArray(v) ? null : type;
272
+ case 'object': return typeof v === 'object' && !Array.isArray(v) ? null : type;
273
+ case 'enum': return typeof v === 'string' ? null : 'string';
274
+ default: return null;
275
+ }
276
+ }
277
+
278
+ function staticProps(
279
+ form: KitViewForm, path: string, diags: KitDiagnostic[], contractProps?: readonly string[], propTypes?: Readonly<Record<string, string>>,
280
+ ): { props?: Record<string, unknown>; value?: string } {
127
281
  const out: { props?: Record<string, unknown>; value?: string } = {};
128
282
  if (form.props !== undefined) {
129
283
  if (form.props === null || typeof form.props !== 'object' || Array.isArray(form.props)) {
@@ -135,6 +289,17 @@ function staticProps(form: KitViewForm, path: string, diags: KitDiagnostic[]): {
135
289
  diags.push({ code: 'KIT-STATIC-001', path: `${path}.props.${k}`, message: `props 的键 ${k} 不合法或属保留键(data / map / chart / class / value 由编译器写)` });
136
290
  continue;
137
291
  }
292
+ // 闭集:组件契约登记了 props 时,键必须是契约里的 prop(已删除的写法 / 手误的键不静默透传给组件)
293
+ if (contractProps !== undefined && !contractProps.includes(k)) {
294
+ diags.push({ code: 'KIT-STATIC-001', path: `${path}.props.${k}`, message: `组件 ${form.staticComponent ?? ''} 没有 prop ${k}(契约 props:${contractProps.join(' / ')})` });
295
+ continue;
296
+ }
297
+ // 类型:契约给了 propTypes 才核(view.props 是配置类字面量,不含绑定路径);类型不符的键丢弃,不把错类型透传给组件
298
+ const expected = propTypeMismatch(propTypes?.[k], v);
299
+ if (expected !== null) {
300
+ diags.push({ code: 'KIT-STATIC-001', path: `${path}.props.${k}`, message: `组件 ${form.staticComponent ?? ''} 的 prop ${k} 期望 ${expected},实际是 ${literalTypeName(v)}` });
301
+ continue;
302
+ }
138
303
  kept[k] = v;
139
304
  }
140
305
  if (Object.keys(kept).length > 0) out.props = kept;
@@ -147,10 +312,8 @@ function staticProps(form: KitViewForm, path: string, diags: KitDiagnostic[]): {
147
312
  return out;
148
313
  }
149
314
 
150
- const VIEW_ON_THEN: ReadonlySet<string> = new Set(KIT_GRAMMAR.overlayEventRoles.actionForm.thenValues);
151
-
152
315
  /**
153
- * view.on(写死形状数据组件的事件接线)的形状与事件名校验:值是非空动作串,或 { action, then? };
316
+ * view.on(写死形状数据组件的事件接线)的形状与事件名校验:值是非空动作串,或 { action };
154
317
  * 事件名必须在组件契约 emits 里(契约没给 emits 时不核)。违规的项丢弃并记 KIT-STATIC-001;动作是否登记由 emitEvents 核。
155
318
  */
156
319
  function staticOn(
@@ -177,10 +340,10 @@ function staticOn(
177
340
  continue;
178
341
  }
179
342
  } else if (value === null || typeof value !== 'object' || Array.isArray(value) || typeof value.action !== 'string' || value.action === '') {
180
- diags.push({ code: 'KIT-STATIC-001', path: at, message: 'on 的值必须是动作名字符串,或 { action, then? }' });
343
+ diags.push({ code: 'KIT-STATIC-001', path: at, message: 'on 的值必须是动作名字符串,或 { action }' });
181
344
  continue;
182
- } else if (value.then !== undefined && !VIEW_ON_THEN.has(value.then)) {
183
- diags.push({ code: 'KIT-STATIC-001', path: `${at}.then`, message: `then = "${String(value.then)}" 不在 ${[...VIEW_ON_THEN].join(' / ')} 内` });
345
+ } else if (Object.keys(value).some((k) => k !== 'action')) {
346
+ diags.push({ code: 'KIT-STATIC-001', path: at, message: 'on 的对象形态只许 action 键(动作之后的提示 / 重取 / 跳转写在具名动作或展示对象方法里)' });
184
347
  continue;
185
348
  }
186
349
  kept[event] = value;
@@ -206,9 +369,9 @@ const GROUPS_AS = KIT_GRAMMAR.formLinkage.groupsAs as { values: string[] };
206
369
 
207
370
  /**
208
371
  * 表单 / 筛选的布局与行为参数(M 波 G3 D6 / D7):只许写在对应槽位上,枚举 / 范围 / 布尔不对记 KIT-FORM-006 并忽略该键;
209
- * afterSave(form 写入成功后的后续链)写法不对记 KIT-FORM-002。返回 IR 形态(只含写了的键)。
372
+ * 返回 IR 形态(只含写了的键)。
210
373
  */
211
- function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[], schema?: KitSchema): KitFormOpts {
374
+ function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[]): KitFormOpts {
212
375
  const out: KitFormOpts = {};
213
376
  const raw = form as unknown as Record<string, unknown>;
214
377
  const bad = (key: string, message: string): void => { diags.push({ code: 'KIT-FORM-006', path: `${path}.${key}`, message }); };
@@ -239,60 +402,50 @@ function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: K
239
402
  }
240
403
  bool('inline', ['form']);
241
404
  const scroll = bool('scrollToError', ['form']);
242
- if (scroll === true) out.scrollToError = true;
243
- if (raw.afterSave !== undefined) {
244
- if (slot !== 'form') bad('afterSave', 'afterSave 只用于 form 视图');
245
- else {
246
- const then = normalizeThen(raw.afterSave, `${path}.afterSave`, diags);
247
- if (then !== null) out.afterSave = then;
248
- }
249
- }
250
- // 采纳建议:只许 form 视图
251
- if (raw.adopt !== undefined) {
252
- if (slot !== 'form') diags.push({ code: 'KIT-FORM-009', path: `${path}.adopt`, message: 'adopt 只用于 form 视图' });
253
- else {
254
- const adopt = adoptOf(raw.adopt, `${path}.adopt`, schema, diags);
255
- if (adopt !== null) out.adopt = adopt;
256
- }
257
- }
405
+ if (scroll !== undefined) out.scrollToError = scroll;
258
406
  // 底栏动作:只许 form 视图,动作 id 的字符串数组(是否存在 / 是否 request·download 在 emit 阶段核对)
259
407
  if (raw.footerActions !== undefined) {
260
408
  const list = raw.footerActions as unknown;
261
409
  if (slot !== 'form') diags.push({ code: 'KIT-FORM-009', path: `${path}.footerActions`, message: 'footerActions 只用于 form 视图' });
262
410
  else if (!Array.isArray(list) || list.length === 0 || list.some((x) => typeof x !== 'string' || x === '')) {
263
411
  diags.push({ code: 'KIT-FORM-009', path: `${path}.footerActions`, message: 'footerActions 必须是非空的动作 id 数组' });
264
- } else out.footerActions = [...new Set(list as string[])];
265
- }
266
- // 字段变化触发请求(H1e):只许 form 视图;键是可编辑字段,值是动作 id(是否 read 的 request 动作在 emit 阶段核对)
267
- if (raw.onChange !== undefined) {
268
- const map = raw.onChange as unknown;
269
- const at = `${path}.onChange`;
270
- if (slot !== 'form') diags.push({ code: 'KIT-ACT-008', path: at, message: 'onChange 只用于 form 视图' });
271
- else if (map === null || typeof map !== 'object' || Array.isArray(map) || Object.keys(map).length === 0) {
272
- diags.push({ code: 'KIT-ACT-008', path: at, message: 'onChange 必须是非空对象 { 字段名: request 动作 id }' });
273
- } else {
274
- const kept: Record<string, string> = {};
275
- for (const [field, aid] of Object.entries(map as Record<string, unknown>)) {
276
- const f = schema?.[field];
277
- if (typeof aid !== 'string' || aid === '') diags.push({ code: 'KIT-ACT-008', path: `${at}.${field}`, message: 'onChange 的值必须是 request 动作 id(字符串)' });
278
- else if (schema !== undefined && f === undefined) diags.push({ code: 'KIT-ACT-008', path: `${at}.${field}`, message: `onChange 的字段 ${field} 不在对象 schema 里` });
279
- else if (f !== undefined && (f.permission ?? 'r') === 'r') diags.push({ code: 'KIT-ACT-008', path: `${at}.${field}`, message: `onChange 的字段 ${field} 是只读字段(permission: r),用户改不了它,没有"变化"可触发` });
280
- else kept[field] = aid;
281
- }
282
- if (Object.keys(kept).length > 0) out.onChange = kept;
283
- }
412
+ } else if (new Set(list).size !== list.length) {
413
+ diags.push({ code: 'KIT-FORM-009', path: `${path}.footerActions`, message: 'footerActions 含重复的动作 id' });
414
+ } else out.footerActions = [...(list as string[])];
284
415
  }
285
416
  // 请求结果常驻槽(GA3):form 视图画在字段与按钮之间;其它视图在 renderSlot 里改写成 AsyncResultPanel
286
417
  if (raw.result !== undefined && slot === 'form') {
287
418
  const result = resultSlotOf(raw.result, `${path}.result`, diags);
288
419
  if (result !== null) out.result = result;
289
420
  }
290
- // filter:折叠与触发
421
+ // filter:折叠与触发(P2:筛选字段数量 > 4 且未显式设置 collapsible / defaultCollapsedCount 时,默认前 4 项常驻、第 5 项起自动折叠)
291
422
  if (slot === 'filter') {
292
- const collapsible = raw.collapsible === undefined ? undefined : typeof raw.collapsible === 'boolean' ? raw.collapsible : (bad('collapsible', 'collapsible 必须是布尔'), undefined);
423
+ const filterFieldCount = Array.isArray(form.fields)
424
+ ? form.fields.map(normalizeRef).filter((r) => r.divider === undefined).length
425
+ : 0;
426
+ let residentLimit = 4;
427
+ if (raw.defaultCollapsedCount !== undefined) {
428
+ if (typeof raw.defaultCollapsedCount !== 'number' || !Number.isInteger(raw.defaultCollapsedCount) || raw.defaultCollapsedCount < 1) {
429
+ bad('defaultCollapsedCount', 'defaultCollapsedCount 须是正整数');
430
+ } else {
431
+ residentLimit = raw.defaultCollapsedCount;
432
+ out.defaultCollapsedCount = residentLimit;
433
+ }
434
+ }
435
+ const autoCollapse = raw.collapsible === undefined && filterFieldCount > residentLimit;
436
+ const collapsible = raw.collapsible === undefined
437
+ ? (autoCollapse ? true : undefined)
438
+ : typeof raw.collapsible === 'boolean'
439
+ ? raw.collapsible
440
+ : (bad('collapsible', 'collapsible 必须是布尔'), undefined);
293
441
  if (collapsible === true) {
294
442
  out.collapsible = true;
295
- const rows = raw.collapsedRows ?? FILTER_OPTS.collapsedRowsDefault;
443
+ if (autoCollapse || filterFieldCount > residentLimit) {
444
+ out.filterOverflow = true;
445
+ out.defaultCollapsedCount ??= residentLimit;
446
+ }
447
+ const defaultRows = raw.defaultCollapsedCount !== undefined ? Math.max(1, Math.min(FILTER_OPTS.collapsedRowsMax, Math.ceil(residentLimit / 4))) : FILTER_OPTS.collapsedRowsDefault;
448
+ const rows = raw.collapsedRows ?? defaultRows;
296
449
  if (typeof rows !== 'number' || !Number.isInteger(rows) || rows < 1 || rows > FILTER_OPTS.collapsedRowsMax) {
297
450
  bad('collapsedRows', `collapsedRows 须是 1~${FILTER_OPTS.collapsedRowsMax} 的整数`);
298
451
  out.collapsedRows = FILTER_OPTS.collapsedRowsDefault;
@@ -306,6 +459,7 @@ function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: K
306
459
  }
307
460
  } else {
308
461
  onlyOn('collapsedRows', ['filter']);
462
+ onlyOn('defaultCollapsedCount', ['filter']);
309
463
  onlyOn('trigger', ['filter']);
310
464
  }
311
465
  // groupsAs
@@ -321,11 +475,78 @@ function formOptsOf(slot: KitViewSlot, form: KitViewForm, path: string, diags: K
321
475
  }
322
476
 
323
477
  /** list 槽上的 contextMenu 并入集合声明(集合自己写了就以集合为准);其它槽原样返回,由 renderSlot 报 KIT-MENU-001 */
324
- function withViewContextMenu(c: KitCollection, form: KitViewForm, slot: KitViewSlot): KitCollection {
325
- if (slot !== 'list' || form.contextMenu === undefined || (c as { contextMenu?: unknown }).contextMenu !== undefined) return c;
478
+ function withViewContextMenu(c: KitCollection, form: KitViewForm, slot: KitViewSlot, diags?: KitDiagnostic[]): KitCollection {
479
+ if (slot !== 'list' || form.contextMenu === undefined) return c;
480
+ if ((c as { contextMenu?: unknown }).contextMenu !== undefined) {
481
+ diags?.push({ code: 'KIT-MENU-001', path: 'view.list.contextMenu', message: 'view.list.contextMenu 与 view.list.collection.contextMenu 不能同时声明' });
482
+ return c;
483
+ }
326
484
  return { ...c, contextMenu: form.contextMenu } as KitCollection;
327
485
  }
328
486
 
487
+ function resolveSlotKnobs(
488
+ slot: KitViewSlot,
489
+ form: KitViewForm,
490
+ obj: KitObject,
491
+ path: string,
492
+ diags: KitDiagnostic[],
493
+ ): { emphasis?: 'primary' | 'normal' | 'subtle'; surface?: 'card' | 'flush' | 'plain'; highlight?: boolean; extraWrapClass: string } {
494
+ const viewRec = (obj.view ?? {}) as Record<string, unknown>;
495
+ const rawEmphasis = form.emphasis ?? (viewRec.emphasis as unknown) ?? obj.emphasis;
496
+ const rawSurface = form.surface ?? (viewRec.surface as unknown) ?? obj.surface;
497
+ const rawHighlight = form.highlight ?? (viewRec.highlight as unknown) ?? obj.highlight;
498
+
499
+ let emphasis: 'primary' | 'normal' | 'subtle' | undefined;
500
+ if (rawEmphasis !== undefined) {
501
+ if (rawEmphasis === 'primary' || rawEmphasis === 'normal' || rawEmphasis === 'subtle') {
502
+ emphasis = rawEmphasis;
503
+ } else {
504
+ diags.push({ code: 'KIT-OBJ-009', path: `${path}.emphasis`, message: `emphasis 只许 primary / normal / subtle,收到 "${String(rawEmphasis)}"` });
505
+ }
506
+ }
507
+
508
+ let surface: 'card' | 'flush' | 'plain' | undefined;
509
+ if (rawSurface !== undefined) {
510
+ if (rawSurface === 'card' || rawSurface === 'flush' || rawSurface === 'plain') {
511
+ surface = rawSurface;
512
+ } else {
513
+ diags.push({ code: 'KIT-OBJ-009', path: `${path}.surface`, message: `surface 只许 card / flush / plain,收到 "${String(rawSurface)}"` });
514
+ }
515
+ }
516
+
517
+ let highlight: boolean | undefined;
518
+ if (rawHighlight !== undefined) {
519
+ if (typeof rawHighlight === 'boolean') {
520
+ if (rawHighlight) highlight = true;
521
+ } else {
522
+ diags.push({ code: 'KIT-OBJ-009', path: `${path}.highlight`, message: 'highlight 必须是布尔值' });
523
+ }
524
+ }
525
+
526
+ const classes: string[] = [];
527
+ if (surface !== undefined) classes.push(resolveSurfaceRecipeClass(surface));
528
+ if (emphasis !== undefined) classes.push(resolveContainerEmphasisClass(emphasis));
529
+ if (highlight === true) {
530
+ classes.push(KIT_VIEW_HIGHLIGHT_CLASS);
531
+ }
532
+
533
+ return {
534
+ ...(emphasis !== undefined ? { emphasis } : {}),
535
+ ...(surface !== undefined ? { surface } : {}),
536
+ ...(highlight === true ? { highlight: true } : {}),
537
+ extraWrapClass: classes.filter(Boolean).join(' '),
538
+ };
539
+ }
540
+
541
+ function applyWrapKnobClass(layout: KitLayoutIR, extraWrapClass: string): void {
542
+ if (extraWrapClass === '') return;
543
+ if (layout.kind === 'static') {
544
+ layout.class = mergeClass(extraWrapClass, layout.class);
545
+ } else {
546
+ layout.wrapClass = mergeClass(layout.wrapClass, extraWrapClass);
547
+ }
548
+ }
549
+
329
550
  function renderSlot(
330
551
  slot: KitViewSlot,
331
552
  form: KitViewForm,
@@ -355,7 +576,8 @@ function renderSlot(
355
576
  }
356
577
  }
357
578
  const emptyEnv = summaryEmpty(slot, form, path, diags);
358
- const fopts = formOptsOf(slot, form, path, diags, schema);
579
+ const fopts = formOptsOf(slot, form, path, diags);
580
+ const slotKnobs = resolveSlotKnobs(slot, form, obj, path, diags);
359
581
  // inline: true 等价 arrange: inline;与别的 arrange 同写报错
360
582
  if (slot === 'form' && form.inline === true) {
361
583
  if (form.arrange !== undefined && form.arrange !== 'inline' && !(typeof form.arrange === 'object' && 'inline' in (form.arrange as object))) {
@@ -365,8 +587,6 @@ function renderSlot(
365
587
  }
366
588
  }
367
589
  const requiredMark = form.requiredMark === 'start' ? 'start' : 'end';
368
- // 字段策略表:form 视图的 policy 规整成 IR,经 env 交给每个字段格并入 showWhen / disabledWhen / requiredWhen
369
- const policy = form.policy === undefined ? null : fieldPolicyOf(form.policy, slot, schema, `${path}.policy`, diags);
370
590
 
371
591
  if (form.staticComponent) {
372
592
  const contract = ctx.staticComponents?.[form.staticComponent];
@@ -380,25 +600,39 @@ function renderSlot(
380
600
  });
381
601
  }
382
602
  diags.push(...checkClasses(form.class, `${path}.class`));
383
- const extraProps = staticProps(form, path, diags);
603
+ const extraProps = staticProps(form, path, diags, contract?.props, contract?.propTypes);
384
604
  checkDisplayProps(form, obj, path, diags);
385
605
  const on = staticOn(form, contract?.emits, path, diags);
386
606
  const dataSubmit = obj.behavior.write !== undefined
387
607
  && contract?.emits?.includes('submit') === true
388
608
  && contract?.props?.includes('object') === true;
389
609
  const hasScopeProp = contract?.props?.includes('scope') === true;
610
+ // 读状态属性:契约声明了 loading / error_text 且对象有数据来源才标记(契约只给属性名,类型由组件契约自身保证)
611
+ const hasSource = hasBehaviorFrom(obj.behavior);
612
+ const hasLoadingProp = hasSource && contract?.props?.includes('loading') === true;
613
+ const hasErrorTextProp = hasSource && contract?.props?.includes('error_text') === true;
614
+ // 无 error_text 的组件(如 ItemList)用 string 型 error 属性承接读失败:契约给了 propTypes 才按类型认(没给不绑)
615
+ const hasErrorProp = hasSource && !hasErrorTextProp && contract?.props?.includes('error') === true && contract?.propTypes?.error === 'string';
616
+ // 读失败自动重试:绑了读取错误、契约有 retry 事件与 retry_text 属性(RecordPicker 只有 error_text 与自带 search 重试,无 retry 事件,不受影响)
617
+ const autoRetry = (hasErrorTextProp || hasErrorProp)
618
+ && contract?.emits?.includes('retry') === true
619
+ && contract?.props?.includes('retry_text') === true;
390
620
  // 右键菜单:只有带行级动作的写死形状组件(ItemList / Tree / Kanban)接受;其它(Chart 等)报 KIT-MENU-001
391
621
  let ctxActions: ReturnType<typeof resolveContextMenuItems> = [];
392
622
  if (form.contextMenu !== undefined) {
393
623
  if (!KIT_CONTEXT_MENU.staticComponents.includes(form.staticComponent)) {
394
- diags.push({ code: 'KIT-MENU-001', path: `${path}.contextMenu`, message: `组件 ${form.staticComponent} 没有行级动作,不能写 contextMenu(只用于 ${KIT_CONTEXT_MENU.staticComponents.join(' / ')} 与 table / treeTable / cards / stack 集合),已忽略` });
624
+ diags.push({ code: 'KIT-MENU-001', path: `${path}.contextMenu`, message: `组件 ${form.staticComponent} 没有行级动作,不能写 contextMenu(只用于 ${KIT_CONTEXT_MENU.staticComponents.join(' / ')} 与 table / treeTable / cards / stack 集合)` });
395
625
  } else {
396
626
  ctxActions = resolveContextMenuItems(form.contextMenu, [], obj.behavior.actions ?? [], `${path}.contextMenu`, diags);
397
627
  }
398
628
  }
629
+ const staticBase = mergeClass(KIT_CLASS_DEFAULTS.staticRoot, slotKnobs.extraWrapClass);
399
630
  return {
400
631
  ...viewTexts(slot, form, path, diags),
401
632
  mode: 'show',
633
+ ...(slotKnobs.emphasis !== undefined ? { emphasis: slotKnobs.emphasis } : {}),
634
+ ...(slotKnobs.surface !== undefined ? { surface: slotKnobs.surface } : {}),
635
+ ...(slotKnobs.highlight === true ? { highlight: true } : {}),
402
636
  layout: {
403
637
  kind: 'static',
404
638
  component: form.staticComponent,
@@ -409,8 +643,12 @@ function renderSlot(
409
643
  ...(extraProps.value !== undefined ? { value: extraProps.value } : {}),
410
644
  ...(on !== undefined ? { on } : {}),
411
645
  ...(dataSubmit ? { dataSubmit: true, ...(hasScopeProp ? { hasScopeProp: true } : {}) } : {}),
646
+ ...(hasLoadingProp ? { hasLoadingProp: true } : {}),
647
+ ...(hasErrorTextProp ? { hasErrorTextProp: true } : {}),
648
+ ...(hasErrorProp ? { hasErrorProp: true } : {}),
649
+ ...(autoRetry ? { autoRetry: true } : {}),
412
650
  ...(ctxActions.length > 0 ? { contextMenu: ctxActions } : {}),
413
- class: mergeClass(KIT_CLASS_DEFAULTS.staticRoot, form.class, form.replaceClass),
651
+ class: mergeClass(staticBase, form.class, form.replaceClass),
414
652
  },
415
653
  };
416
654
  }
@@ -428,9 +666,9 @@ function renderSlot(
428
666
  path,
429
667
  slot,
430
668
  requiredMark,
431
- ...(policy !== null ? { policy } : {}),
432
669
  ...(ctx.locale !== undefined ? { locale: ctx.locale } : {}),
433
670
  ...(emptyEnv !== undefined ? { empty: emptyEnv } : {}),
671
+ staticPropKeys: (component: string) => ctx.staticComponents?.[component]?.props,
434
672
  actions: obj.behavior.actions ?? [],
435
673
  ...(ctx.expandHosts !== undefined ? { expandHosts: ctx.expandHosts } : {}),
436
674
  renderExpand: (viewName: string, at: string): KitExpandIR | null => {
@@ -471,19 +709,29 @@ function renderSlot(
471
709
  if (grouped !== null) {
472
710
  layout = grouped;
473
711
  } else if (form.collection) {
474
- layout = collection(withViewContextMenu(form.collection, form, slot), refs, form, env);
712
+ layout = collection(withViewContextMenu(form.collection, form, slot, diags), refs, form, env);
475
713
  } else if (form.arrange) {
476
714
  layout = arrange(form.arrange, refs, form, env);
477
715
  } else if (dflt.collection) {
478
- layout = collection(withViewContextMenu(dflt.collection, form, slot), refs, form, env);
716
+ layout = collection(withViewContextMenu(dflt.collection, form, slot, diags), refs, form, env);
479
717
  } else {
480
718
  layout = arrange(dflt.arrange!, refs, form, env);
481
719
  }
482
720
  // 没有行级动作的视图(summary / form / filter、排布而非集合的 list)写了 contextMenu:KIT-MENU-001
483
721
  if (form.contextMenu !== undefined && !(slot === 'list' && (layout.kind === 'table' || layout.kind === 'cards' || layout.kind === 'stack'))) {
484
- diags.push({ code: 'KIT-MENU-001', path: `${path}.contextMenu`, message: `${slot} 视图没有行级动作,不能写 contextMenu(只用于 table / treeTable / cards / stack 集合与 ItemList / Tree / Kanban),已忽略` });
722
+ diags.push({ code: 'KIT-MENU-001', path: `${path}.contextMenu`, message: `${slot} 视图没有行级动作,不能写 contextMenu(只用于 table / treeTable / cards / stack 集合与 ItemList / Tree / Kanban)` });
485
723
  }
486
724
 
725
+ applyWrapKnobClass(layout, slotKnobs.extraWrapClass);
726
+ if (slot === 'filter' && fopts.filterOverflow === true) {
727
+ const limit = fopts.defaultCollapsedCount ?? 4;
728
+ let nonDividerIdx = 0;
729
+ for (const c of layoutCells(layout)) {
730
+ if (c.placeholder === true || c.divider === true || c.component === '') continue;
731
+ if (nonDividerIdx >= limit) c.overflow = true;
732
+ nonDividerIdx += 1;
733
+ }
734
+ }
487
735
  const modes = new Set(layoutCells(layout).filter((c) => !c.placeholder).map((c) => c.mode));
488
736
  const mode = modes.size === 0 ? (slot === 'filter' ? 'edit' : slotModeOf(slot, {}, ctx.formCtx)) : modes.size === 1 ? [...modes][0] : 'mixed';
489
737
  // view.loading: skeleton:只读的 summary / form 才有(可编辑 form 的初值来自协调组件,没有"数据未到"的瞬间)
@@ -493,11 +741,26 @@ function renderSlot(
493
741
  else skeleton = true;
494
742
  }
495
743
  const groupTabs = layout.kind === 'groups' && layout.tabs === true;
496
- const formOpts: KitFormOpts = { ...fopts, ...(groupTabs ? { groupTabs: true } : {}) };
744
+ // 展示对象的纯路径绑定:字段项 hidden / disabled / required、view.form.onDraft
745
+ const fieldState = collectFieldState(slot, form, path, diags, schema);
746
+ const onDraft = checkOnDraft(slot, form, path, diags);
747
+ const submitDisabled = checkSubmitDisabled(slot, form, path, diags);
748
+ const formOpts: KitFormOpts = {
749
+ ...fopts,
750
+ ...(groupTabs ? { groupTabs: true } : {}),
751
+ ...(Object.keys(fieldState).length > 0 ? { fieldState } : {}),
752
+ ...(onDraft !== undefined ? { onDraft } : {}),
753
+ ...(submitDisabled !== undefined ? { submitDisabled } : {}),
754
+ };
755
+ const hasFrom = slot !== 'filter' && hasBehaviorFrom(obj.behavior);
497
756
  return {
498
757
  layout, mode, ...(skeleton ? { skeleton } : {}), ...viewTexts(slot, form, path, diags),
758
+ ...(slotKnobs.emphasis !== undefined ? { emphasis: slotKnobs.emphasis } : {}),
759
+ ...(slotKnobs.surface !== undefined ? { surface: slotKnobs.surface } : {}),
760
+ ...(slotKnobs.highlight === true ? { highlight: true } : {}),
499
761
  ...(Object.keys(formOpts).length > 0 ? { formOpts } : {}),
500
- };
762
+ ...(hasFrom ? { readState: readStatePathsOf(ctx.object) } : {}),
763
+ } as KitViewIR;
501
764
  }
502
765
 
503
766
  /**
@@ -588,6 +851,7 @@ function groupsLayout(form: KitViewForm, env: KitCellEnv, fallbackArrange: KitAr
588
851
  refs.push({ ...item, name: `__divider_g${i}_${dividerSeq++}` });
589
852
  continue;
590
853
  }
854
+ if (slot === 'form' && env.schema[item.name]?.hidden === true) continue;
591
855
  if (seen.has(item.name)) {
592
856
  env.diagnostics.push({ code: 'KIT-OBJ-008', path: `${at}.fields`, message: `字段 ${item.name} 在多节里重复出现` });
593
857
  continue;
@@ -611,13 +875,28 @@ function groupsLayout(form: KitViewForm, env: KitCellEnv, fallbackArrange: KitAr
611
875
  else if (typeof g.divider === 'string') divider = g.divider;
612
876
  else if (g.divider !== false) env.diagnostics.push({ code: 'KIT-OBJ-008', path: `${at}.divider`, message: 'divider 必须是布尔或分隔线文字' });
613
877
  }
878
+ let grpEmphasis: 'primary' | 'normal' | 'subtle' | undefined;
879
+ if (g.emphasis !== undefined) {
880
+ if (g.emphasis === 'primary' || g.emphasis === 'normal' || g.emphasis === 'subtle') grpEmphasis = g.emphasis;
881
+ else env.diagnostics.push({ code: 'KIT-OBJ-008', path: `${at}.emphasis`, message: 'groups[i].emphasis 只许 primary / normal / subtle' });
882
+ }
883
+ let grpSurface: 'card' | 'flush' | 'plain' | undefined;
884
+ if (g.surface !== undefined) {
885
+ if (g.surface === 'card' || g.surface === 'flush' || g.surface === 'plain') grpSurface = g.surface;
886
+ else env.diagnostics.push({ code: 'KIT-OBJ-008', path: `${at}.surface`, message: 'groups[i].surface 只许 card / flush / plain' });
887
+ }
888
+ const grpLayout = arrange(form.arrange ?? fallbackArrange, refs, form, { ...env, path: at });
889
+ const grpExtra = [grpSurface ? resolveSurfaceRecipeClass(grpSurface) : '', grpEmphasis ? resolveContainerEmphasisClass(grpEmphasis) : ''].filter(Boolean).join(' ');
890
+ applyWrapKnobClass(grpLayout, grpExtra);
614
891
  out.push({
615
892
  title: g.title,
616
- layout: arrange(form.arrange ?? fallbackArrange, refs, form, { ...env, path: at }),
893
+ layout: grpLayout,
617
894
  id: `${objectName}__${slot}__g${i}`,
618
895
  collapsible,
619
896
  open,
620
897
  divider,
898
+ ...(grpEmphasis !== undefined ? { emphasis: grpEmphasis } : {}),
899
+ ...(grpSurface !== undefined ? { surface: grpSurface } : {}),
621
900
  });
622
901
  });
623
902
  if (out.length === 0) return null;
@@ -641,15 +920,29 @@ function groupsLayout(form: KitViewForm, env: KitCellEnv, fallbackArrange: KitAr
641
920
  function viewTexts(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[]): { title?: string; submitLabel?: string } {
642
921
  const out: { title?: string; submitLabel?: string } = {};
643
922
  if (form.title !== undefined) {
644
- if (typeof form.title === 'string') {
923
+ if (slot === 'filter') {
924
+ diags.push({ code: 'KIT-OBJ-007', path: `${path}.title`, message: 'filter 视图不支持 title' });
925
+ } else if (typeof form.title === 'string') {
645
926
  if (slot === 'list' || slot === 'summary') out.title = form.title;
646
927
  } else if (slot !== 'form') {
647
928
  diags.push({ code: 'KIT-OBJ-007', path: `${path}.title`, message: `${slot} 视图的 title 必须是字符串({ create, edit } 只用于 form)` });
929
+ } else if (form.title === null || typeof form.title !== 'object' || Array.isArray(form.title)) {
930
+ diags.push({ code: 'KIT-OBJ-007', path: `${path}.title`, message: 'form 视图的 title 必须是字符串或 { create?, edit? }' });
931
+ } else {
932
+ const tObj = form.title as Record<string, unknown>;
933
+ for (const [k, v] of Object.entries(tObj)) {
934
+ if (k !== 'create' && k !== 'edit') {
935
+ diags.push({ code: 'KIT-OBJ-007', path: `${path}.title.${k}`, message: `form.title 只许 create / edit,未知键 ${k}` });
936
+ } else if (v !== undefined && typeof v !== 'string') {
937
+ diags.push({ code: 'KIT-OBJ-007', path: `${path}.title.${k}`, message: `form.title.${k} 必须是字符串` });
938
+ }
939
+ }
648
940
  }
649
941
  }
650
942
  if (form.submitLabel !== undefined) {
651
943
  if (slot !== 'form') diags.push({ code: 'KIT-OBJ-007', path: `${path}.submitLabel`, message: 'submitLabel 只用于 form 视图' });
652
- else if (typeof form.submitLabel === 'string') out.submitLabel = form.submitLabel;
944
+ else if (typeof form.submitLabel !== 'string') diags.push({ code: 'KIT-OBJ-007', path: `${path}.submitLabel`, message: 'submitLabel 必须是字符串' });
945
+ else out.submitLabel = form.submitLabel;
653
946
  }
654
947
  return out;
655
948
  }
@@ -658,18 +951,46 @@ export function renderObject(obj: KitObject, ctx: KitRenderContext): KitObjectIR
658
951
  const diags: KitDiagnostic[] = [];
659
952
  const schema = resolveSchema(obj, ctx, diags);
660
953
 
954
+ for (const [name, field] of Object.entries(schema)) {
955
+ checkFieldRules(name, field.rules, `schema.${name}.rules`, diags);
956
+ }
957
+ checkEnumOptionsAndEditCompatibility(schema as unknown as Record<string, unknown>, (obj.view ?? {}) as Record<string, unknown>, '', diags);
958
+
959
+ const rawBehavior = obj.behavior as unknown as Record<string, unknown>;
960
+ if (rawBehavior.require_params !== undefined) {
961
+ diags.push({ code: 'KIT-PAGE-001', path: 'behavior.require_params', message: '未知键 require_params(请改写为 behavior.requireParams)' });
962
+ }
963
+ if (rawBehavior.requireParams !== undefined) {
964
+ if (!Array.isArray(rawBehavior.requireParams)) {
965
+ diags.push({ code: 'KIT-FORM-004', path: 'behavior.requireParams', message: 'behavior.requireParams 必须是非空字符串数组' });
966
+ } else {
967
+ const knownParams = new Set<string>(Object.keys(obj.behavior.params ?? {}));
968
+ for (const f of fieldNamesOf(obj.view?.filter?.fields)) knownParams.add(f);
969
+ if (obj.view?.list !== undefined) {
970
+ knownParams.add('page');
971
+ knownParams.add('size');
972
+ knownParams.add('sort');
973
+ knownParams.add('order');
974
+ }
975
+ rawBehavior.requireParams.forEach((k, i) => {
976
+ if (typeof k !== 'string' || k.trim() === '' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(k)) {
977
+ diags.push({ code: 'KIT-FORM-004', path: `behavior.requireParams[${i}]`, message: `behavior.requireParams[${i}] 必须是合法的参数名标识符` });
978
+ } else if (!knownParams.has(k)) {
979
+ diags.push({ code: 'KIT-FORM-004', path: `behavior.requireParams[${i}]`, message: `behavior.requireParams 的参数 "${k}" 不在该对象的请求参数(params / 筛选 / 分页 / 排序)中` });
980
+ }
981
+ });
982
+ }
983
+ }
984
+
661
985
  (obj.behavior.actions ?? []).forEach((a, i) => {
662
986
  if (Array.isArray(a.permission)) {
663
987
  diags.push({ code: 'KIT-OBJ-006', path: `behavior.actions[${i}].permission`, message: `动作 ${a.id} 的 permission 是数组,kit 层只允许一个权限码` });
664
988
  }
665
- // 后续链 then 与行操作条件 when(M 波 G3 D1 / D2):写法在这里统一核;emitEvents 只管展开
666
- if (a.then !== undefined) normalizeThen(a.then, `behavior.actions[${i}].then`, diags);
667
- if (a.when !== undefined) {
668
- if (a.on !== 'row') {
669
- diags.push({ code: 'KIT-FORM-001', path: `behavior.actions[${i}].when`, message: `动作 ${a.id} 的 when 只用于 on: row 的行操作` });
670
- } else {
671
- predicateToCore(a.when, `behavior.actions[${i}].when`, new Set(Object.keys(schema)), diags);
672
- }
989
+ if (a.tone !== undefined && (typeof a.tone !== 'string' || !KIT_ACTION_TONES.includes(a.tone))) {
990
+ diags.push({ code: 'KIT-ACT-010', path: `behavior.actions[${i}].tone`, message: `动作 ${a.id} 的 tone "${String(a.tone)}" 不在闭集(允许:${KIT_ACTION_TONES.join(' / ')})` });
991
+ }
992
+ if (a.request !== undefined || a.download !== undefined) {
993
+ validateRequestAction(a, `behavior.actions[${i}]`, diags);
673
994
  }
674
995
  });
675
996
 
@@ -681,17 +1002,15 @@ export function renderObject(obj: KitObject, ctx: KitRenderContext): KitObjectIR
681
1002
 
682
1003
  const views: KitObjectIR['views'] = {};
683
1004
  const declared = obj.view ?? {};
684
- // GB2 / GB3 / GB6:字段 default / hidden / derive 的写法在这里统一核(每个对象一次)
1005
+ // GB2 / GB3:字段 default / hidden 的写法在这里统一核(每个对象一次)
685
1006
  const formDecl = declared.form;
686
1007
  const rawGroups: unknown[] = Array.isArray(formDecl?.groups) ? (formDecl?.groups as unknown[]) : [];
687
1008
  const groupFieldNames = rawGroups.flatMap((g) => (
688
- g !== null && typeof g === 'object' && Array.isArray((g as { fields?: unknown }).fields)
689
- ? ((g as { fields: unknown[] }).fields).flatMap((f) => (typeof f === 'string' ? [f] : []))
690
- : []));
1009
+ g !== null && typeof g === 'object' ? fieldNamesOf((g as { fields?: unknown }).fields) : []));
691
1010
  const fieldValue = collectFieldValues(schema, formDecl?.fields, groupFieldNames, diags);
692
1011
  checkFlowFields(schema, diags);
693
- checkViewRowColumns(declared as Record<string, unknown>, diags, schema);
694
- checkViewFlowNodeOptions(declared as Record<string, unknown>, schema, diags);
1012
+ checkViewRowColumns(declared as Record<string, unknown>, diags);
1013
+ checkViewFlowNodeOptions(declared as Record<string, unknown>, diags);
695
1014
  for (const key of Object.keys(declared)) {
696
1015
  if (!(KIT_VIEW_SLOTS as readonly string[]).includes(key)) {
697
1016
  diags.push({