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
@@ -1,34 +1,100 @@
1
1
  // 第 0 步:页面声明解析与闭集键检查(KIT-PAGE-001 / 003 / 004)。纯函数,不查注册表。
2
- // 键闭集全部读 spec/kit-grammar.json;对象内部的字段级语义(type、component、view 槽位名)归对象渲染内核校验,这里只拦未知键。
2
+ // 键闭集全部读 spec/kit-grammar.json;对象声明内部各层(schema / behavior / 动作 request·download·then / view 各槽 / fields[])
3
+ // 的闭集在 closed-set.ts 逐层查,写了闭集之外的键(含曾经的逻辑键)一律报错拒绝编译;字段级语义(type、component)归对象渲染内核校验。
3
4
 
5
+ import { isViewName } from '../object-renderer/view-binding';
4
6
  import { KIT_AI_WRITER_LIMITS, KIT_WORKSPACE_FRAME_LIMITS } from 'soma-foundation/kit-limits';
5
7
  import grammarJson from '../../spec/kit-grammar.json';
6
8
  import type { KitDiagnostic } from '../object-renderer/types';
7
9
  import type { KitPageDecl, KitProductDecl, KitTabDecl } from './types';
8
10
  import { parseRedirect } from './redirect';
11
+ import { checkNoRelativeOrSystemPath, checkObjectClosedSet } from './closed-set';
9
12
  import { blockThemeKitDiagnostics, checkBlockTheme } from '../theme/block-theme';
10
13
  import { parsePageHeader } from '../frames/page-header';
11
14
  import { parsePageParams } from './page-params';
12
- import { parseKitEnvelope } from '../app/envelope';
15
+ import { parseKitEnvelope } from '../shared/envelope';
13
16
 
14
17
  interface GrammarKeys {
15
18
  pageTopKeys: string[];
16
19
  pageKeys: string[];
17
20
  frameKeys: string[];
18
21
  productKeys: string[];
19
- actionKeys: string[];
20
- objectKeys: { schema: string[]; behavior: string[]; view: string[] };
22
+ objectLayer: {
23
+ topKeys: string[];
24
+ recordRoleExtraKeys: string[];
25
+ overlayExtraKeys: string[];
26
+ containerEmphasis: string[];
27
+ surface: string[];
28
+ };
29
+ bizComponents: {
30
+ MultiObjectBoard: {
31
+ roles?: Record<string, { required?: boolean; views?: string[]; many?: boolean; extraKeys?: string[] }>;
32
+ panelKeys: string[];
33
+ areas?: string[];
34
+ };
35
+ [kind: string]: {
36
+ roles?: Record<string, { required?: boolean; views?: string[]; many?: boolean; extraKeys?: string[] }>;
37
+ panelKeys?: string[];
38
+ areas?: string[];
39
+ } | undefined;
40
+ };
21
41
  }
22
- const G = grammarJson as unknown as GrammarKeys;
42
+ const KIT_GRAMMAR = grammarJson as unknown as GrammarKeys;
43
+ const G = KIT_GRAMMAR;
23
44
 
24
- /** 对象一级键:schema / behavior / view;title 给从属对象(subs.*)与浮层做标题 */
25
- const OBJECT_TOP_KEYS = ['schema', 'behavior', 'view', 'title'] as const;
26
- /** behavior 里编译器认、真源 objectKeys 没列全的键(types.ts 的 KitBehavior 有,规格 8.3 用到) */
27
- const BEHAVIOR_EXTRA_KEYS = ['params', 'list'] as const;
28
- /** 浮层声明键 */
29
- const OVERLAY_KEYS = ['kind', 'title', 'class', 'behavior', 'view', 'schema', 'events', 'editOverlay', 'rowClick'] as const;
30
- /** RecordDetail 的 record 角色多一个布局键:subsLayout(stack / tabs,E5) */
31
- const RECORD_ROLE_KEYS = [...OBJECT_TOP_KEYS, 'subsLayout'] as const;
45
+ const CONTAINER_EMPHASIS_VALUES: readonly string[] = KIT_GRAMMAR.objectLayer.containerEmphasis;
46
+ const SURFACE_RECIPE_VALUES: readonly string[] = KIT_GRAMMAR.objectLayer.surface;
47
+
48
+ /** 对象一级键:schema / behavior / view;title 给从属对象(subs.*)与浮层做标题(真源 KIT_GRAMMAR.objectLayer) */
49
+ const OBJECT_TOP_KEYS: readonly string[] = KIT_GRAMMAR.objectLayer.topKeys;
50
+ /** 浮层声明键(真源 KIT_GRAMMAR.objectLayer) */
51
+ const OVERLAY_KEYS: readonly string[] = [...KIT_GRAMMAR.objectLayer.topKeys, ...KIT_GRAMMAR.objectLayer.overlayExtraKeys];
52
+ /** RecordDetail 的 record 角色多一个布局键:subsLayout(stack / tabs,E5,真源 KIT_GRAMMAR.objectLayer) */
53
+ const RECORD_ROLE_KEYS: readonly string[] = [...KIT_GRAMMAR.objectLayer.topKeys, ...KIT_GRAMMAR.objectLayer.recordRoleExtraKeys];
54
+
55
+ /**
56
+ * 求解指定业务组件角色允许的对象顶层键(包含标准键与角色附加键 extraKeys)。
57
+ * 优先取应用装配/自定义组件(appRefs.bizComponents),未命中回退语法真源内置规则。
58
+ */
59
+ function resolveRoleAllowedKeys(
60
+ kind: string,
61
+ role: string,
62
+ _isMany: boolean,
63
+ appRefs?: KitAppRefsContext,
64
+ ): readonly string[] {
65
+ const customRole = appRefs?.bizComponents?.[kind]?.roles?.[role];
66
+ if (customRole !== undefined) {
67
+ return [...new Set([...OBJECT_TOP_KEYS, ...(customRole.extraKeys ?? [])])];
68
+ }
69
+ const builtinRole = KIT_GRAMMAR.bizComponents[kind]?.roles?.[role];
70
+ if (builtinRole?.extraKeys !== undefined) {
71
+ return [...new Set([...OBJECT_TOP_KEYS, ...builtinRole.extraKeys])];
72
+ }
73
+ return OBJECT_TOP_KEYS;
74
+ }
75
+
76
+ function resolveRoleAllowedKeysForRawObjects(
77
+ role: string,
78
+ appRefs?: KitAppRefsContext,
79
+ productKind?: string,
80
+ ): readonly string[] {
81
+ if (productKind) {
82
+ return resolveRoleAllowedKeys(productKind, role, false, appRefs);
83
+ }
84
+ const customExtra = Object.values(appRefs?.bizComponents ?? {})
85
+ .find((c) => c?.roles?.[role]?.extraKeys !== undefined)
86
+ ?.roles?.[role]?.extraKeys;
87
+ if (customExtra !== undefined) {
88
+ return [...new Set([...OBJECT_TOP_KEYS, ...customExtra])];
89
+ }
90
+ const builtinExtra = Object.values(KIT_GRAMMAR.bizComponents ?? {})
91
+ .find((c) => (c as { roles?: Record<string, { extraKeys?: string[] }> })?.roles?.[role]?.extraKeys !== undefined)
92
+ ?.roles?.[role]?.extraKeys;
93
+ if (builtinExtra !== undefined) {
94
+ return [...new Set([...OBJECT_TOP_KEYS, ...builtinExtra])];
95
+ }
96
+ return OBJECT_TOP_KEYS;
97
+ }
32
98
  const TITLE_MAX = KIT_AI_WRITER_LIMITS.limits.titleMax;
33
99
  const SUBTITLE_MAX = KIT_AI_WRITER_LIMITS.limits.subtitleMax;
34
100
  /** page.breadcrumbs 项数上限(读真源 workspaceFrame.limits,缺省 8) */
@@ -75,6 +141,222 @@ function checkClassMap(v: unknown, path: string, out: KitDiagnostic[]): Record<s
75
141
  return res;
76
142
  }
77
143
 
144
+ export interface KitAppRefsContext {
145
+ dicts?: Record<string, Array<{ value: string | number | boolean; label: string; tone?: string }>>;
146
+ entities?: Record<string, Record<string, unknown>>;
147
+ bizComponents?: Readonly<Record<string, { readonly roles?: Readonly<Record<string, { readonly many?: boolean; readonly extraKeys?: readonly string[] }>> }>>;
148
+ }
149
+
150
+ /**
151
+ * 解析期特例:只给 frame.config、不写任何槽位也合法的页面框(自带整页内容,内容全由 config 驱动)。
152
+ * 解析发生在应用页面框登记表可得之前(parsePage 不接触 KitAppContext),无法读页面框能力字段,故保留框名比较、集中于此。
153
+ */
154
+ const CONFIG_ONLY_FRAME_KIND = 'workspace-frame';
155
+
156
+ const ENTITY_REF_RE = /^\$entity\.([A-Za-z_][A-Za-z0-9_]*)$/;
157
+ const DICT_REF_RE = /^\$dict\.([A-Za-z_][A-Za-z0-9_]*)$/;
158
+ const SCHEMA_REF_KEYS = ['$ref', 'pick', 'omit', 'override'] as const;
159
+
160
+ function cloneFieldMap(src: Record<string, unknown>): Record<string, Record<string, unknown>> {
161
+ const out: Record<string, Record<string, unknown>> = {};
162
+ for (const [k, v] of Object.entries(src)) {
163
+ if (isRecord(v)) {
164
+ const copy: Record<string, unknown> = { ...v };
165
+ if (Array.isArray(v.options)) copy.options = v.options.map((o) => (isRecord(o) ? { ...o } : o));
166
+ if (Array.isArray(v.rules)) copy.rules = v.rules.map((r) => (isRecord(r) ? { ...r } : r));
167
+ out[k] = copy;
168
+ }
169
+ }
170
+ return out;
171
+ }
172
+
173
+ function hasStaticComponentInView(view: unknown): boolean {
174
+ if (!isRecord(view)) return false;
175
+ if (typeof view.staticComponent === 'string' && view.staticComponent !== '') return true;
176
+ for (const slot of ['list', 'summary', 'filter', 'form'] as const) {
177
+ const s = view[slot];
178
+ if (isRecord(s) && typeof s.staticComponent === 'string' && s.staticComponent !== '') return true;
179
+ }
180
+ return false;
181
+ }
182
+
183
+ function expandFieldDictOptions(
184
+ schema: Record<string, unknown>,
185
+ path: string,
186
+ appRefs: KitAppRefsContext | undefined,
187
+ out: KitDiagnostic[],
188
+ ): void {
189
+ for (const [fieldName, fieldDef] of Object.entries(schema)) {
190
+ if (!isRecord(fieldDef) || typeof fieldDef.options !== 'string') continue;
191
+ const rawOpt = fieldDef.options.trim();
192
+ const m = DICT_REF_RE.exec(rawOpt);
193
+ if (!m) {
194
+ out.push({
195
+ code: 'KIT-FORM-003',
196
+ path: `${path}.schema.${fieldName}.options`,
197
+ message: `字段 ${fieldName} 的 options 字符串引用必须为 $dict.<字典名>(收到 "${fieldDef.options}")`,
198
+ });
199
+ continue;
200
+ }
201
+ const dictName = m[1]!;
202
+ const dictItems = appRefs?.dicts?.[dictName];
203
+ if (!Array.isArray(dictItems) || dictItems.length === 0) {
204
+ out.push({
205
+ code: 'KIT-FORM-003',
206
+ path: `${path}.schema.${fieldName}.options`,
207
+ message: `字段 ${fieldName} 引用了未在 kit.app.yaml#dicts 声明的字典 $dict.${dictName}`,
208
+ });
209
+ continue;
210
+ }
211
+ fieldDef.options = dictItems.map((it) => ({ ...it }));
212
+ }
213
+ }
214
+
215
+ export function expandObjectEntityAndDicts(
216
+ obj: Record<string, unknown>,
217
+ path: string,
218
+ appRefs: KitAppRefsContext | undefined,
219
+ out: KitDiagnostic[],
220
+ ): void {
221
+ const rawSchema = obj.schema;
222
+ if (typeof rawSchema === 'string') {
223
+ const m = ENTITY_REF_RE.exec(rawSchema.trim());
224
+ if (!m) {
225
+ out.push({
226
+ code: 'KIT-OBJ-001',
227
+ path: `${path}.schema`,
228
+ message: `schema 字符串引用必须为 $entity.<实体名>(收到 "${rawSchema}")`,
229
+ });
230
+ return;
231
+ }
232
+ const entityName = m[1]!;
233
+ const entityDef = appRefs?.entities?.[entityName];
234
+ if (!isRecord(entityDef)) {
235
+ out.push({
236
+ code: 'KIT-OBJ-001',
237
+ path: `${path}.schema`,
238
+ message: `对象引用了未在 kit.app.yaml#entities 声明的实体 $entity.${entityName}`,
239
+ });
240
+ return;
241
+ }
242
+ const resolved = cloneFieldMap(entityDef);
243
+ expandFieldDictOptions(resolved, path, appRefs, out);
244
+ obj.schema = resolved;
245
+ return;
246
+ }
247
+
248
+ if (isRecord(rawSchema) && '$ref' in rawSchema) {
249
+ unknownKeys(rawSchema, SCHEMA_REF_KEYS, `${path}.schema`, out);
250
+ const refStr = typeof rawSchema.$ref === 'string' ? rawSchema.$ref.trim() : '';
251
+ const m = ENTITY_REF_RE.exec(refStr);
252
+ if (!m) {
253
+ out.push({
254
+ code: 'KIT-OBJ-001',
255
+ path: `${path}.schema.$ref`,
256
+ message: `schema.$ref 必须为 $entity.<实体名>(收到 "${String(rawSchema.$ref)}")`,
257
+ });
258
+ return;
259
+ }
260
+ const entityName = m[1]!;
261
+ const entityDef = appRefs?.entities?.[entityName];
262
+ if (!isRecord(entityDef)) {
263
+ out.push({
264
+ code: 'KIT-OBJ-001',
265
+ path: `${path}.schema.$ref`,
266
+ message: `对象引用了未在 kit.app.yaml#entities 声明的实体 $entity.${entityName}`,
267
+ });
268
+ return;
269
+ }
270
+ const baseFields = cloneFieldMap(entityDef);
271
+ let selectedNames = Object.keys(baseFields);
272
+ if (rawSchema.pick !== undefined) {
273
+ if (!Array.isArray(rawSchema.pick) || rawSchema.pick.some((x) => typeof x !== 'string' || x === '')) {
274
+ shape(`${path}.schema.pick`, 'schema.pick 必须是非空字段名字符串数组', out);
275
+ } else {
276
+ const pickList = rawSchema.pick as string[];
277
+ for (const f of pickList) {
278
+ if (!(f in baseFields)) {
279
+ out.push({
280
+ code: 'KIT-OBJ-001',
281
+ path: `${path}.schema.pick`,
282
+ message: `schema.pick 引用了实体 $entity.${entityName} 中不存在的字段 ${f}`,
283
+ });
284
+ }
285
+ }
286
+ selectedNames = pickList.filter((f) => f in baseFields);
287
+ }
288
+ }
289
+ if (rawSchema.omit !== undefined) {
290
+ if (!Array.isArray(rawSchema.omit) || rawSchema.omit.some((x) => typeof x !== 'string' || x === '')) {
291
+ shape(`${path}.schema.omit`, 'schema.omit 必须是非空字段名字符串数组', out);
292
+ } else {
293
+ const omitSet = new Set(rawSchema.omit as string[]);
294
+ selectedNames = selectedNames.filter((f) => !omitSet.has(f));
295
+ }
296
+ }
297
+ const resolved: Record<string, Record<string, unknown>> = {};
298
+ for (const f of selectedNames) {
299
+ if (baseFields[f] !== undefined) resolved[f] = { ...baseFields[f]! };
300
+ }
301
+ if (rawSchema.override !== undefined) {
302
+ if (!isRecord(rawSchema.override)) {
303
+ shape(`${path}.schema.override`, 'schema.override 必须是 { 字段名: 覆写属性 } 对象', out);
304
+ } else {
305
+ for (const [fName, overDef] of Object.entries(rawSchema.override)) {
306
+ if (!isRecord(overDef)) {
307
+ shape(`${path}.schema.override.${fName}`, `schema.override.${fName} 必须是对象`, out);
308
+ continue;
309
+ }
310
+ resolved[fName] = { ...(resolved[fName] ?? baseFields[fName] ?? {}), ...overDef };
311
+ }
312
+ }
313
+ }
314
+ expandFieldDictOptions(resolved, path, appRefs, out);
315
+ obj.schema = resolved;
316
+ return;
317
+ }
318
+
319
+ if (isRecord(rawSchema)) {
320
+ expandFieldDictOptions(rawSchema, path, appRefs, out);
321
+ }
322
+ }
323
+
324
+ function expandProductObjects(
325
+ objects: Record<string, unknown>,
326
+ path: string,
327
+ appRefs: KitAppRefsContext | undefined,
328
+ out: KitDiagnostic[],
329
+ ): void {
330
+ // 1) 先展开所有非浮层角色对象的 $entity / $dict
331
+ for (const [role, val] of Object.entries(objects)) {
332
+ if (role === 'overlays') continue;
333
+ const rp = `${path}.objects.${role}`;
334
+ if (isRecord(val) && !('schema' in val) && !('behavior' in val) && !('view' in val) && Object.keys(val).length > 0 && Object.values(val).every(isRecord)) {
335
+ for (const [subName, subObj] of Object.entries(val)) {
336
+ if (isRecord(subObj)) expandObjectEntityAndDicts(subObj, `${rp}.${subName}`, appRefs, out);
337
+ }
338
+ } else if (isRecord(val)) {
339
+ expandObjectEntityAndDicts(val, rp, appRefs, out);
340
+ }
341
+ }
342
+ // 2) 确定主对象 schema,供未显式声明 schema 的关联浮层(overlays)继承
343
+ const mainCandidate = objects.entity ?? objects.master ?? objects.record ?? objects.target ?? objects.item
344
+ ?? Object.entries(objects).find(([k, v]) => k !== 'overlays' && k !== 'subs' && isRecord(v) && isRecord(v.schema))?.[1];
345
+ const mainSchema = isRecord(mainCandidate) && isRecord(mainCandidate.schema) ? mainCandidate.schema : undefined;
346
+
347
+ if (isRecord(objects.overlays)) {
348
+ for (const [ovName, ovDecl] of Object.entries(objects.overlays)) {
349
+ if (!isRecord(ovDecl)) continue;
350
+ const ovPath = `${path}.objects.overlays.${ovName}`;
351
+ if (ovDecl.schema !== undefined) {
352
+ expandObjectEntityAndDicts(ovDecl, ovPath, appRefs, out);
353
+ } else if (mainSchema !== undefined && !hasStaticComponentInView(ovDecl.view)) {
354
+ ovDecl.schema = cloneFieldMap(mainSchema);
355
+ }
356
+ }
357
+ }
358
+ }
359
+
78
360
  function checkObjectDecl(obj: unknown, path: string, out: KitDiagnostic[], allowTop: readonly string[]): void {
79
361
  if (!isRecord(obj)) {
80
362
  shape(path, `${path} 必须是对象声明(schema / behavior / view)`, out);
@@ -86,22 +368,14 @@ function checkObjectDecl(obj: unknown, path: string, out: KitDiagnostic[], allow
86
368
  if (f.includes('.')) {
87
369
  out.push({ code: 'KIT-PAGE-005', path: `${path}.schema.${f}`, message: `字段名 ${f} 含点号(会与 _event 选择器分段冲突)` });
88
370
  }
89
- if (isRecord(def)) unknownKeys(def, G.objectKeys.schema, `${path}.schema.${f}`, out);
90
- else shape(`${path}.schema.${f}`, '字段声明必须是对象', out);
91
- }
92
- }
93
- if (isRecord(obj.behavior)) {
94
- unknownKeys(obj.behavior, [...G.objectKeys.behavior, ...BEHAVIOR_EXTRA_KEYS], `${path}.behavior`, out);
95
- const actions = obj.behavior.actions;
96
- if (Array.isArray(actions)) {
97
- actions.forEach((a, i) => {
98
- if (isRecord(a)) unknownKeys(a, G.actionKeys, `${path}.behavior.actions[${i}]`, out);
99
- });
371
+ if (!isRecord(def)) shape(`${path}.schema.${f}`, '字段声明必须是对象', out);
100
372
  }
101
373
  }
374
+ // 各层闭集(schema 字段 / options / rules / default、behavior 与动作的 request / download / then、view 各槽与 fields[])
375
+ checkObjectClosedSet(obj, path, out);
102
376
  }
103
377
 
104
- function parseProduct(raw: unknown, path: string, out: KitDiagnostic[]): KitProductDecl | undefined {
378
+ function parseProduct(raw: unknown, path: string, out: KitDiagnostic[], appRefs?: KitAppRefsContext): KitProductDecl | undefined {
105
379
  if (!isRecord(raw)) {
106
380
  shape(path, `${path} 必须是产品声明 { kind, objects, class?, areaClass? }`, out);
107
381
  return undefined;
@@ -116,6 +390,7 @@ function parseProduct(raw: unknown, path: string, out: KitDiagnostic[]): KitProd
116
390
  shape(`${path}.objects`, `${path}.objects 必须是对象角色表`, out);
117
391
  return undefined;
118
392
  }
393
+ expandProductObjects(objects, path, appRefs, out);
119
394
  for (const [role, val] of Object.entries(objects)) {
120
395
  const rp = `${path}.objects.${role}`;
121
396
  checkObjectName(role, rp, out);
@@ -132,11 +407,10 @@ function parseProduct(raw: unknown, path: string, out: KitDiagnostic[]): KitProd
132
407
  && Object.values(val).every(isRecord)) {
133
408
  // 对象表(如 subs.*):每项是一个对象
134
409
  for (const [name, sub] of Object.entries(val)) checkObjectName(name, `${rp}.${name}`, out);
135
- // MultiObjectBoard 的 panels.*:面板宽度 span(1~12)与面板外框 class 由业务组件解释
136
- const keys = role === 'panels' ? [...OBJECT_TOP_KEYS, 'span', 'class'] as const : role === 'steps' ? [...OBJECT_TOP_KEYS, 'gate'] as const : OBJECT_TOP_KEYS;
410
+ const keys = resolveRoleAllowedKeys(raw.kind, role, true, appRefs);
137
411
  for (const [name, sub] of Object.entries(val)) checkObjectDecl(sub, `${rp}.${name}`, out, keys);
138
412
  } else {
139
- checkObjectDecl(val, rp, out, role === 'record' ? RECORD_ROLE_KEYS : OBJECT_TOP_KEYS);
413
+ checkObjectDecl(val, rp, out, resolveRoleAllowedKeys(raw.kind, role, false, appRefs));
140
414
  }
141
415
  }
142
416
  const decl: KitProductDecl = { kind: raw.kind, objects };
@@ -153,10 +427,18 @@ function parseProduct(raw: unknown, path: string, out: KitDiagnostic[]): KitProd
153
427
  if (!isRecord(raw.config)) shape(`${path}.config`, `${path}.config 必须是对象(业务组件专属配置)`, out);
154
428
  else decl.config = raw.config;
155
429
  }
430
+ if (raw.emphasis !== undefined) {
431
+ if (typeof raw.emphasis === 'string' && CONTAINER_EMPHASIS_VALUES.includes(raw.emphasis)) decl.emphasis = raw.emphasis as KitProductDecl['emphasis'];
432
+ else out.push({ code: 'KIT-OBJ-009', path: `${path}.emphasis`, message: `product.emphasis 只许 ${CONTAINER_EMPHASIS_VALUES.join(' / ')},收到 "${String(raw.emphasis)}"` });
433
+ }
434
+ if (raw.surface !== undefined) {
435
+ if (typeof raw.surface === 'string' && SURFACE_RECIPE_VALUES.includes(raw.surface)) decl.surface = raw.surface as KitProductDecl['surface'];
436
+ else out.push({ code: 'KIT-OBJ-009', path: `${path}.surface`, message: `product.surface 只许 ${SURFACE_RECIPE_VALUES.join(' / ')},收到 "${String(raw.surface)}"` });
437
+ }
156
438
  return decl;
157
439
  }
158
440
 
159
- function parseTabs(raw: unknown[], path: string, out: KitDiagnostic[]): KitTabDecl[] {
441
+ function parseTabs(raw: unknown[], path: string, out: KitDiagnostic[], appRefs?: KitAppRefsContext): KitTabDecl[] {
160
442
  const tabs: KitTabDecl[] = [];
161
443
  const seen = new Set<string>();
162
444
  raw.forEach((t, i) => {
@@ -185,7 +467,7 @@ function parseTabs(raw: unknown[], path: string, out: KitDiagnostic[]): KitTabDe
185
467
  shape(`${tp}.title`, '页签 title 必须是非空字符串', out);
186
468
  return;
187
469
  }
188
- const product = parseProduct(t.product, `${tp}.product`, out);
470
+ const product = parseProduct(t.product, `${tp}.product`, out, appRefs);
189
471
  if (product) tabs.push({ id, title: t.title, product });
190
472
  });
191
473
  return tabs;
@@ -195,13 +477,30 @@ function parseTabs(raw: unknown[], path: string, out: KitDiagnostic[]): KitTabDe
195
477
  * 解析并检查一份页面声明。有任何诊断就不要继续编译。
196
478
  * 顶层键 page / frame / product;product 等价于 frame.slots.main;frame 缺省为 single-frame。
197
479
  */
198
- export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPageDecl | undefined {
480
+ /** 根据页面相对 pages/ 目录的文件路径推导默认路由(如 orders/detail.kit.yaml -> /orders/detail) */
481
+ export function inferPageUrlFromPath(relPath: string): string {
482
+ const normalized = relPath.replace(/\\/g, '/').replace(/^\/+/, '');
483
+ const stem = normalized.replace(/\.(?:kit\.ya?ml|ya?ml)$/i, '');
484
+ if (stem === '' || stem === 'index') return '/';
485
+ if (stem.endsWith('/index')) return `/${stem.slice(0, -'/index'.length)}`;
486
+ return `/${stem}`;
487
+ }
488
+
489
+ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[], defaultUrl?: string, appRefs?: KitAppRefsContext): KitPageDecl | undefined {
199
490
  const before = diagnostics.length;
200
491
  if (!isRecord(raw)) {
201
492
  shape('$', '页面声明必须是对象(page / frame / product)', diagnostics);
202
493
  return undefined;
203
494
  }
204
- unknownKeys(raw, G.pageTopKeys, '$', diagnostics);
495
+ for (const k of Object.keys(raw)) {
496
+ if (!G.pageTopKeys.includes(k)) {
497
+ if (k === 'layout' && isRecord(raw.layout) && raw.layout.frame !== undefined) {
498
+ diagnostics.push({ code: 'KIT-PAGE-001', path: '$.layout', message: '未知键 layout(页面级请改写为 frame.kind,或将 layout.frame 写在 kit.app.yaml)' });
499
+ } else {
500
+ diagnostics.push({ code: 'KIT-PAGE-001', path: `$.${k}`, message: `未知键 ${k}($ 允许:${G.pageTopKeys.join(' / ')})` });
501
+ }
502
+ }
503
+ }
205
504
 
206
505
  const page = raw.page;
207
506
  let meta: KitPageDecl['page'] | undefined;
@@ -210,7 +509,12 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
210
509
  shape('page', 'page 必须是对象 { url, title, subtitle?, roles? }', diagnostics);
211
510
  } else {
212
511
  unknownKeys(page, G.pageKeys, 'page', diagnostics);
213
- const { url, title, subtitle, roles, eyebrow, breadcrumbs, redirect } = page;
512
+ const { url: rawUrl, title, subtitle, roles, eyebrow, breadcrumbs, redirect } = page;
513
+ if (page.path !== undefined) {
514
+ if (typeof page.path !== 'string') shape('page.path', 'page.path 必须是以 / 开头的路径', diagnostics);
515
+ else checkNoRelativeOrSystemPath(page.path, 'page.path', diagnostics, 'KIT-PAGE-004');
516
+ }
517
+ const url = rawUrl !== undefined ? rawUrl : defaultUrl;
214
518
  // 内置页面类型:跳转页(page.redirect);不写 product / frame.slots
215
519
  const redirectDecl = redirect === undefined ? undefined : parseRedirect(redirect, diagnostics);
216
520
  if (redirect !== undefined && (raw.product !== undefined || (isRecord(raw.frame) && raw.frame.slots !== undefined))) {
@@ -232,6 +536,9 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
232
536
  }
233
537
  const keys = Object.keys(b).filter((k) => k !== 'label' && k !== 'href');
234
538
  if (keys.length > 0) shape(`page.breadcrumbs[${i}]`, `page.breadcrumbs 的项只许 label / href,多余:${keys.join(' / ')}`, diagnostics);
539
+ if (typeof b.href === 'string') {
540
+ checkNoRelativeOrSystemPath(b.href, `page.breadcrumbs[${i}].href`, diagnostics, 'KIT-PAGE-004', { allowExternalHref: true });
541
+ }
235
542
  crumbs!.push(typeof b.href === 'string' ? { label: b.label, href: b.href } : { label: b.label });
236
543
  });
237
544
  }
@@ -242,7 +549,11 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
242
549
  diagnostics.push({ code: 'KIT-PAGE-003', path: 'page.eyebrow', message: `page.eyebrow 不得超过 ${TITLE_MAX} 字` });
243
550
  }
244
551
  }
245
- if (typeof url !== 'string' || !url.startsWith('/')) shape('page.url', 'page.url 必须是以 / 开头的路径', diagnostics);
552
+ if (typeof url !== 'string' || url.trim() === '') {
553
+ shape('page.url', 'page.url 必须是以 / 开头的路径', diagnostics);
554
+ } else {
555
+ checkNoRelativeOrSystemPath(url, 'page.url', diagnostics, 'KIT-PAGE-004');
556
+ }
246
557
  if (typeof title !== 'string' || title.trim() === '') {
247
558
  diagnostics.push({ code: 'KIT-PAGE-003', path: 'page.title', message: 'page.title 必填' });
248
559
  } else if ([...title].length > TITLE_MAX) {
@@ -267,6 +578,9 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
267
578
  if (page.inherit_layout !== undefined && typeof page.inherit_layout !== 'boolean') {
268
579
  shape('page.inherit_layout', 'page.inherit_layout 必须是布尔值', diagnostics);
269
580
  }
581
+ if (page.view !== undefined && !isViewName(page.view)) {
582
+ diagnostics.push({ code: 'KIT-VIEW-001', path: 'page.view', message: `page.view 须是展示对象类名(大写字母开头、以 View 结尾,如 RefG3View),收到 ${JSON.stringify(page.view)}` });
583
+ }
270
584
  if (raw.locales !== undefined) {
271
585
  const lc = raw.locales;
272
586
  const ok = isRecord(lc) && Object.values(lc).every((t) => isRecord(t) && Object.values(t).every((s) => typeof s === 'string'));
@@ -281,6 +595,7 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
281
595
  if (Array.isArray(roles)) meta.roles = roles.filter((r): r is string => typeof r === 'string');
282
596
  if (crumbs !== undefined && crumbs.length > 0) meta.breadcrumbs = crumbs;
283
597
  if (typeof page.inherit_layout === 'boolean') meta.inheritLayout = page.inherit_layout;
598
+ if (isViewName(page.view)) meta.view = page.view;
284
599
  if (redirectDecl !== undefined) meta.redirect = redirectDecl;
285
600
  Object.assign(meta, header);
286
601
  Object.assign(meta, parsePageParams(page, url, diagnostics));
@@ -298,6 +613,7 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
298
613
 
299
614
  // frame
300
615
  let frameKind = 'single-frame';
616
+ let explicitKind = false;
301
617
  let frameClass: string | undefined;
302
618
  let slotClass: Record<string, string> | undefined;
303
619
  let frameConfig: Record<string, unknown> | undefined;
@@ -309,8 +625,10 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
309
625
  const f = raw.frame;
310
626
  unknownKeys(f, G.frameKeys, 'frame', diagnostics);
311
627
  if (f.kind !== undefined) {
312
- if (typeof f.kind === 'string' && f.kind !== '') frameKind = f.kind;
313
- else shape('frame.kind', 'frame.kind 必须是页面框名', diagnostics);
628
+ if (typeof f.kind === 'string' && f.kind !== '') {
629
+ frameKind = f.kind;
630
+ explicitKind = true;
631
+ } else shape('frame.kind', 'frame.kind 必须是页面框名', diagnostics);
314
632
  }
315
633
  if (typeof f.class === 'string') frameClass = f.class;
316
634
  else if (f.class !== undefined) shape('frame.class', 'frame.class 必须是类串', diagnostics);
@@ -327,9 +645,9 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
327
645
  diagnostics.push({ code: 'KIT-PAGE-005', path: `frame.slots.${slot}`, message: `槽名 ${slot} 只能是字母开头的字母数字下划线` });
328
646
  continue;
329
647
  }
330
- if (Array.isArray(val)) slots[slot] = parseTabs(val, `frame.slots.${slot}`, diagnostics);
648
+ if (Array.isArray(val)) slots[slot] = parseTabs(val, `frame.slots.${slot}`, diagnostics, appRefs);
331
649
  else {
332
- const p = parseProduct(val, `frame.slots.${slot}`, diagnostics);
650
+ const p = parseProduct(val, `frame.slots.${slot}`, diagnostics, appRefs);
333
651
  if (p) slots[slot] = p;
334
652
  }
335
653
  }
@@ -340,18 +658,29 @@ export function parsePageDecl(raw: unknown, diagnostics: KitDiagnostic[]): KitPa
340
658
 
341
659
  // product -> main 槽
342
660
  if (raw.product !== undefined) {
343
- const p = parseProduct(raw.product, 'product', diagnostics);
661
+ const p = parseProduct(raw.product, 'product', diagnostics, appRefs);
344
662
  if (p) {
345
663
  if ('main' in slots) shape('product', 'product 与 frame.slots.main 不能同时写', diagnostics);
346
664
  else slots.main = p;
347
665
  }
348
666
  }
349
- if (Object.keys(slots).length === 0 && diagnostics.length === before && !isRedirect && !(frameConfig !== undefined && frameKind === 'workspace-frame')) {
667
+ if (isRecord(raw.objects)) {
668
+ const rawProductKind = isRecord(raw.product) && typeof raw.product.kind === 'string'
669
+ ? raw.product.kind
670
+ : (isRecord(raw.page) && typeof raw.page.kind === 'string' ? raw.page.kind : undefined);
671
+ for (const [role, val] of Object.entries(raw.objects)) {
672
+ const rp = `objects.${role}`;
673
+ checkObjectName(role, rp, diagnostics);
674
+ if (isRecord(val)) expandObjectEntityAndDicts(val, rp, appRefs, diagnostics);
675
+ checkObjectDecl(val, rp, diagnostics, resolveRoleAllowedKeysForRawObjects(role, appRefs, rawProductKind));
676
+ }
677
+ }
678
+ if (Object.keys(slots).length === 0 && diagnostics.length === before && !isRedirect && !(frameConfig !== undefined && frameKind === CONFIG_ONLY_FRAME_KIND)) {
350
679
  shape('product', '页面至少要有一个产品(product 或 frame.slots.*)', diagnostics);
351
680
  }
352
681
 
353
682
  if (diagnostics.length > before || meta === undefined) return undefined;
354
- const frame: KitPageDecl['frame'] = { kind: frameKind, slots };
683
+ const frame: KitPageDecl['frame'] = { kind: frameKind, explicitKind, slots };
355
684
  if (frameClass !== undefined) frame.class = frameClass;
356
685
  if (slotClass !== undefined) frame.slotClass = slotClass;
357
686
  if (frameConfig !== undefined) frame.config = frameConfig;
@@ -11,6 +11,7 @@
11
11
  import { KIT_REDIRECT } from '../object-renderer/defaults';
12
12
  import type { KitDiagnostic } from '../object-renderer/types';
13
13
  import { safeRedirectTarget } from '../data/redirect';
14
+ import { checkNoRelativeOrSystemPath } from '../shared/path-guard';
14
15
  import type { KitFragment } from './fragment';
15
16
 
16
17
  export interface KitRedirectDecl {
@@ -40,8 +41,11 @@ export function parseRedirect(raw: unknown, diagnostics: KitDiagnostic[]): KitRe
40
41
  diagnostics.push({ code: 'KIT-PAGE-001', path: `${path}.${k}`, message: `未知键 ${k}(${path} 允许:${KIT_REDIRECT.keys.join(' / ')})` });
41
42
  }
42
43
  }
43
- const to = typeof raw.to === 'string' ? safeRedirectTarget(raw.to) : '';
44
- if (to === '') shape(`${path}.to`, 'redirect.to 必须是站内绝对路径(单个 / 开头,不是 //,不含反斜杠)');
44
+ const validPath = typeof raw.to === 'string' && raw.to.trim() !== '' && checkNoRelativeOrSystemPath(raw.to, `${path}.to`, diagnostics, 'KIT-PAGE-004');
45
+ const to = validPath && typeof raw.to === 'string' ? safeRedirectTarget(raw.to) : '';
46
+ if (to === '' && !diagnostics.some((d) => d.path === `${path}.to`)) {
47
+ shape(`${path}.to`, 'redirect.to 必须是站内绝对路径(单个 / 开头,不是 //,不含反斜杠)');
48
+ }
45
49
  let replace = KIT_REDIRECT.defaults.replace;
46
50
  if (raw.replace !== undefined) {
47
51
  if (typeof raw.replace === 'boolean') replace = raw.replace;
@@ -64,6 +64,7 @@ import type { SomaComponentDefinition } from 'soma-core';
64
64
  import type { SomaStyleEngine } from 'soma-core/server/style-engine';
65
65
  import type { KitFragment } from './fragment';
66
66
  import type { KitAppContext } from './types';
67
+ import { KIT_WORKSPACE_FRAME_LIMITS } from 'soma-foundation/kit-limits';
67
68
 
68
69
  /** 内置数据组件名 -> 自带候选类(用到才并入) */
69
70
  const DATA_COMPONENT_CANDIDATES: Readonly<Record<string, readonly string[]>> = {
@@ -219,6 +220,28 @@ export interface KitStyleResult {
219
220
  const MARKER_CLASS = /^(group|peer)(\/[A-Za-z0-9_-]+)?$/;
220
221
  /** 块级主题的作用域类(theme/block-theme.ts 写在块根上):它是令牌变量块的选择器,不是工具类,不交样式引擎 */
221
222
  const SCOPE_CLASS = /^soma-scope-[a-z0-9]+(?:-[a-z0-9]+)*$/;
223
+ /**
224
+ * 侧栏固定 px 宽度类(如 w-[224px]、w-[64px]):侧栏宽度与密度无关,真源定精确 px 档位;
225
+ * core 样式引擎按平台规范拦截所有方括号任意值,此类由 kit 自行生成精确规则,不交 core 引擎。
226
+ * 只放行真源里的闭集宽度(档位、收起、抽屉,外加继承侧栏的最窄归档 176),其余 w-[Npx] 照旧交引擎拒收,
227
+ * 不给「任意值禁用」开口子。
228
+ */
229
+ const SIDEBAR_PX_CLASS = /^w-\[(\d+)px\]$/;
230
+ const SIDEBAR_LEGACY_MIN_PX = 176;
231
+ const SIDEBAR_PX_ALLOWED: ReadonlySet<number> = new Set<number>([
232
+ ...Object.values(KIT_WORKSPACE_FRAME_LIMITS.sidebarTiers.widthPx as Record<string, number>),
233
+ KIT_WORKSPACE_FRAME_LIMITS.sidebarTiers.collapsedPx,
234
+ KIT_WORKSPACE_FRAME_LIMITS.sidebarTiers.drawerPx,
235
+ SIDEBAR_LEGACY_MIN_PX,
236
+ ]);
237
+
238
+ /** 是侧栏闭集宽度类则回 px,否则 null */
239
+ function sidebarPxOf(candidate: string): number | null {
240
+ const m = SIDEBAR_PX_CLASS.exec(candidate);
241
+ if (m === null) return null;
242
+ const px = Number(m[1]);
243
+ return SIDEBAR_PX_ALLOWED.has(px) ? px : null;
244
+ }
222
245
 
223
246
  let defaultStyleEngine: SomaStyleEngine | undefined;
224
247
 
@@ -244,11 +267,21 @@ export async function compileStyles(candidates: readonly string[], app: KitAppCo
244
267
  }
245
268
  // group / peer(含具名 group/x、peer/x)只是变体锚点标记,本身不产生任何样式规则;
246
269
  // 它们留在 HTML 上给 group-hover: / peer-checked: 等变体用,不交样式引擎(否则按 no-rule 拒收)。
247
- const styled = candidates.filter((c) => !MARKER_CLASS.test(c) && !SCOPE_CLASS.test(c));
270
+ // 侧栏闭集 px 宽度类(w-[Npx])不交样式引擎(core 禁任意值),由 kit 自行注入;闭集外的任意值仍交引擎拒收。
271
+ const sidebarPx = [...new Set(candidates.map(sidebarPxOf).filter((px): px is number => px !== null))].sort((x, y) => x - y);
272
+ const styled = candidates.filter((c) => !MARKER_CLASS.test(c) && !SCOPE_CLASS.test(c) && sidebarPxOf(c) === null);
248
273
  try {
249
274
  // 块级主题的作用域变量块紧跟整站令牌块(同为令牌层),在主题头之前
250
275
  const res = await engine.compile({ themeCss: `${app.themeTokensCss ?? ''}${blockThemeCss}${app.themeCss}`, candidates: styled, allow: allowCandidate });
251
- return { css: res.css, digest: res.digest, diagnostics: [] };
276
+ if (sidebarPx.length === 0) return { css: res.css, digest: res.digest, diagnostics: [] };
277
+ const sidebarCss = sidebarPx.map((px) => `.w-\\[${px}px\\] { width: ${px}px; }`).join('\n');
278
+ // 摘要是样式表的注入键(同键只落一张 <style>)与页面版本的一部分:自注入的规则必须算进去,
279
+ // 否则两张页引擎候选类相同、侧栏宽度不同时会共用一个键,后到的那张拿不到自己的宽度规则。
280
+ return {
281
+ css: res.css ? `${res.css}\n${sidebarCss}` : sidebarCss,
282
+ digest: `${res.digest}-w${sidebarPx.join('-')}`,
283
+ diagnostics: [],
284
+ };
252
285
  } catch (error) {
253
286
  const message = error instanceof Error ? error.message : String(error);
254
287
  return { css: '', digest: '', diagnostics: [{ code: 'KIT-STYLE-001', path: 'styles', message: `样式引擎拒收:${message}` }] };