soma-kit 0.0.0-stage → 0.1.0

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 (353) hide show
  1. package/README.md +539 -2
  2. package/bin/soma-kit.mjs +27 -0
  3. package/package.json +66 -4
  4. package/packs/ai/agent-run-card.ts +64 -0
  5. package/packs/ai/evaluation-card.ts +51 -0
  6. package/packs/ai/guardrail-policy-card.ts +48 -0
  7. package/packs/ai/index.ts +31 -0
  8. package/packs/ai/model-card.ts +55 -0
  9. package/packs/ai/model-routing-card.ts +49 -0
  10. package/packs/ai/prompt-template-card.ts +49 -0
  11. package/packs/ai/texts.ts +19 -0
  12. package/packs/commerce/address-card.ts +58 -0
  13. package/packs/commerce/coupon-card.ts +64 -0
  14. package/packs/commerce/index.ts +25 -0
  15. package/packs/commerce/order-card.ts +60 -0
  16. package/packs/commerce/purchase-order-card.ts +74 -0
  17. package/packs/commerce/texts.ts +14 -0
  18. package/packs/finance/index.ts +30 -0
  19. package/packs/finance/invoice-summary-card.ts +48 -0
  20. package/packs/finance/reconcile-board.ts +450 -0
  21. package/packs/finance/reconcile-case-card.ts +70 -0
  22. package/packs/finance/reconcile-desk/compile.ts +208 -0
  23. package/packs/finance/reconcile-desk/index.ts +20 -0
  24. package/packs/finance/reconcile-desk/shell.ts +27 -0
  25. package/packs/finance/texts.ts +21 -0
  26. package/packs/ops/change-window-card.ts +54 -0
  27. package/packs/ops/dependency-status-card.ts +50 -0
  28. package/packs/ops/error-budget-card.ts +60 -0
  29. package/packs/ops/execution-task-runner.ts +61 -0
  30. package/packs/ops/index.ts +36 -0
  31. package/packs/ops/integration-status-card.ts +45 -0
  32. package/packs/ops/release-readiness-card.ts +63 -0
  33. package/packs/ops/runbook-execution-card.ts +81 -0
  34. package/packs/ops/texts.ts +21 -0
  35. package/packs/security/control-evidence-card.ts +54 -0
  36. package/packs/security/finding-card.ts +96 -0
  37. package/packs/security/index.ts +29 -0
  38. package/packs/security/texts.ts +31 -0
  39. package/packs/shared/card-util.ts +60 -0
  40. package/packs/shared/wrap.ts +13 -0
  41. package/spec/generated/kit-app.schema.json +84 -0
  42. package/spec/generated/kit-page.schema.json +2766 -0
  43. package/spec/kit-grammar.json +1358 -0
  44. package/spec/kit-grammar.schema.json +716 -0
  45. package/src/app/app-config.ts +108 -0
  46. package/src/app/compose-apps.ts +139 -0
  47. package/src/app/define-kit-actions.ts +89 -0
  48. package/src/app/define-kit-app.ts +362 -0
  49. package/src/app/define-kit-pack.ts +114 -0
  50. package/src/app/envelope.ts +117 -0
  51. package/src/app/index.ts +50 -0
  52. package/src/app/notify-renderer.ts +114 -0
  53. package/src/app/paged-list-adapter.ts +246 -0
  54. package/src/app/server-pages.ts +303 -0
  55. package/src/app/server.ts +244 -0
  56. package/src/app/submit.types.ts +87 -0
  57. package/src/base/action-busy.ts +159 -0
  58. package/src/base/action-gate.ts +267 -0
  59. package/src/base/action-status.ts +31 -0
  60. package/src/base/alert.ts +136 -0
  61. package/src/base/avatar.ts +271 -0
  62. package/src/base/button.ts +139 -0
  63. package/src/base/cascader.ts +523 -0
  64. package/src/base/check-core.ts +214 -0
  65. package/src/base/checkbox.ts +35 -0
  66. package/src/base/choice.ts +183 -0
  67. package/src/base/color-picker.ts +316 -0
  68. package/src/base/combobox.ts +61 -0
  69. package/src/base/command-palette.ts +371 -0
  70. package/src/base/context-menu.ts +103 -0
  71. package/src/base/countdown.ts +168 -0
  72. package/src/base/date-range.ts +444 -0
  73. package/src/base/date.ts +899 -0
  74. package/src/base/divider.ts +156 -0
  75. package/src/base/fab.ts +192 -0
  76. package/src/base/icons.ts +106 -0
  77. package/src/base/image.ts +177 -0
  78. package/src/base/index.ts +214 -0
  79. package/src/base/input.ts +316 -0
  80. package/src/base/kbd.ts +99 -0
  81. package/src/base/link.ts +167 -0
  82. package/src/base/listbox-core.ts +965 -0
  83. package/src/base/mentions.ts +323 -0
  84. package/src/base/menu-button.ts +240 -0
  85. package/src/base/menu-core.ts +341 -0
  86. package/src/base/month-grid.ts +171 -0
  87. package/src/base/motion/aura.ts +94 -0
  88. package/src/base/motion/hover-3d.ts +154 -0
  89. package/src/base/motion/hover-gallery.ts +185 -0
  90. package/src/base/motion/index.ts +27 -0
  91. package/src/base/motion/limits.ts +75 -0
  92. package/src/base/motion/marquee.ts +157 -0
  93. package/src/base/motion/text-rotate.ts +195 -0
  94. package/src/base/number.ts +121 -0
  95. package/src/base/otp.ts +259 -0
  96. package/src/base/permission-gate.ts +99 -0
  97. package/src/base/popover.ts +352 -0
  98. package/src/base/popup.ts +542 -0
  99. package/src/base/portal-core.ts +297 -0
  100. package/src/base/price-text.ts +126 -0
  101. package/src/base/progress.ts +216 -0
  102. package/src/base/qr-code.ts +446 -0
  103. package/src/base/qty-stepper.ts +241 -0
  104. package/src/base/radio.ts +33 -0
  105. package/src/base/range.ts +444 -0
  106. package/src/base/rating.ts +249 -0
  107. package/src/base/segmented.ts +286 -0
  108. package/src/base/select.ts +57 -0
  109. package/src/base/shared.ts +708 -0
  110. package/src/base/swap.ts +86 -0
  111. package/src/base/switch.ts +111 -0
  112. package/src/base/tag-input.ts +464 -0
  113. package/src/base/tag.ts +250 -0
  114. package/src/base/text.ts +126 -0
  115. package/src/base/textarea.ts +129 -0
  116. package/src/base/time-picker.ts +606 -0
  117. package/src/base/tree-select.ts +629 -0
  118. package/src/base/upload.ts +548 -0
  119. package/src/base/virtual-list.ts +286 -0
  120. package/src/biz/approval-desk/compile.ts +179 -0
  121. package/src/biz/approval-desk/index.ts +21 -0
  122. package/src/biz/approval-desk/shell.ts +50 -0
  123. package/src/biz/auth-panel/compile.ts +196 -0
  124. package/src/biz/auth-panel/index.ts +24 -0
  125. package/src/biz/auth-panel/shell.ts +46 -0
  126. package/src/biz/category-crud/compile.ts +173 -0
  127. package/src/biz/category-crud/index.ts +19 -0
  128. package/src/biz/category-crud/shell.ts +29 -0
  129. package/src/biz/checkout-page/compile.ts +111 -0
  130. package/src/biz/checkout-page/index.ts +20 -0
  131. package/src/biz/checkout-page/shell.ts +50 -0
  132. package/src/biz/compose.ts +313 -0
  133. package/src/biz/data-components.ts +26 -0
  134. package/src/biz/define.ts +23 -0
  135. package/src/biz/import-wizard/compile.ts +204 -0
  136. package/src/biz/import-wizard/hub.ts +540 -0
  137. package/src/biz/import-wizard/index.ts +24 -0
  138. package/src/biz/import-wizard/shell.ts +161 -0
  139. package/src/biz/index.ts +80 -0
  140. package/src/biz/landing-page/compile.ts +67 -0
  141. package/src/biz/landing-page/index.ts +20 -0
  142. package/src/biz/landing-page/shell.ts +48 -0
  143. package/src/biz/link/hub.ts +255 -0
  144. package/src/biz/link/shared.ts +493 -0
  145. package/src/biz/master-sub/compile.ts +232 -0
  146. package/src/biz/master-sub/index.ts +20 -0
  147. package/src/biz/master-sub/shell.ts +56 -0
  148. package/src/biz/multi-board/compile.ts +234 -0
  149. package/src/biz/multi-board/index.ts +19 -0
  150. package/src/biz/multi-board/shell.ts +70 -0
  151. package/src/biz/names.ts +30 -0
  152. package/src/biz/notification-center/compile.ts +138 -0
  153. package/src/biz/notification-center/index.ts +29 -0
  154. package/src/biz/notification-center/shell.ts +42 -0
  155. package/src/biz/page-templates/result-page/compile.ts +46 -0
  156. package/src/biz/page-templates/result-page/index.ts +19 -0
  157. package/src/biz/page-templates/result-page/shell.ts +31 -0
  158. package/src/biz/page-templates/shared.ts +121 -0
  159. package/src/biz/page-templates/sign-in-page/compile.ts +176 -0
  160. package/src/biz/page-templates/sign-in-page/index.ts +18 -0
  161. package/src/biz/page-templates/sign-in-page/shell.ts +116 -0
  162. package/src/biz/record-detail/compile.ts +290 -0
  163. package/src/biz/record-detail/index.ts +22 -0
  164. package/src/biz/record-detail/shell.ts +64 -0
  165. package/src/biz/settings-center/compile.ts +100 -0
  166. package/src/biz/settings-center/index.ts +18 -0
  167. package/src/biz/settings-center/shell.ts +51 -0
  168. package/src/biz/shared/action-host.ts +469 -0
  169. package/src/biz/shared/coordinator.ts +516 -0
  170. package/src/biz/shared/index.ts +9 -0
  171. package/src/biz/shared/pipes.ts +58 -0
  172. package/src/biz/shared/runtime-hub.ts +112 -0
  173. package/src/biz/shared/step-values.ts +25 -0
  174. package/src/biz/single-form/compile.ts +146 -0
  175. package/src/biz/single-form/index.ts +18 -0
  176. package/src/biz/single-form/shell.ts +38 -0
  177. package/src/biz/standard-crud/bridge.ts +11 -0
  178. package/src/biz/standard-crud/compile.ts +546 -0
  179. package/src/biz/standard-crud/index.ts +18 -0
  180. package/src/biz/standard-crud/shell.ts +157 -0
  181. package/src/biz/step-form/compile.ts +400 -0
  182. package/src/biz/step-form/hub.ts +412 -0
  183. package/src/biz/step-form/index.ts +23 -0
  184. package/src/biz/step-form/shell.ts +96 -0
  185. package/src/biz/step-form/steps-ref.ts +112 -0
  186. package/src/biz/types.ts +96 -0
  187. package/src/cli/kit-cli.ts +102 -0
  188. package/src/compile/action-host-attach.ts +76 -0
  189. package/src/compile/compile-page.ts +472 -0
  190. package/src/compile/component-candidates.ts +147 -0
  191. package/src/compile/fragment.ts +104 -0
  192. package/src/compile/hints.ts +255 -0
  193. package/src/compile/index.ts +16 -0
  194. package/src/compile/locate.ts +166 -0
  195. package/src/compile/page-params.ts +80 -0
  196. package/src/compile/parse.ts +355 -0
  197. package/src/compile/redirect.ts +90 -0
  198. package/src/compile/registry.ts +30 -0
  199. package/src/compile/remove-guard.ts +99 -0
  200. package/src/compile/styles.ts +244 -0
  201. package/src/compile/types.ts +106 -0
  202. package/src/data/amount-breakdown.ts +132 -0
  203. package/src/data/anchor-nav.ts +225 -0
  204. package/src/data/approval-flow.ts +269 -0
  205. package/src/data/assignment-picker.ts +652 -0
  206. package/src/data/async-result-panel.ts +308 -0
  207. package/src/data/breadcrumbs.ts +197 -0
  208. package/src/data/calendar.ts +363 -0
  209. package/src/data/carousel.ts +408 -0
  210. package/src/data/chart.ts +726 -0
  211. package/src/data/checklist.ts +215 -0
  212. package/src/data/code-view.ts +415 -0
  213. package/src/data/comment-thread.ts +342 -0
  214. package/src/data/confirm-dialog.ts +144 -0
  215. package/src/data/context-menu.ts +216 -0
  216. package/src/data/d9-limits.ts +42 -0
  217. package/src/data/d9-util.ts +81 -0
  218. package/src/data/diff.ts +239 -0
  219. package/src/data/display-util.ts +135 -0
  220. package/src/data/dock.ts +152 -0
  221. package/src/data/embed.ts +200 -0
  222. package/src/data/field-mapper.ts +544 -0
  223. package/src/data/flow-editor-contract.ts +41 -0
  224. package/src/data/flow-editor.ts +2622 -0
  225. package/src/data/flow-remote-options.ts +257 -0
  226. package/src/data/footer.ts +157 -0
  227. package/src/data/form-draft-registry.ts +76 -0
  228. package/src/data/gantt.ts +430 -0
  229. package/src/data/hero.ts +149 -0
  230. package/src/data/image-viewer.ts +333 -0
  231. package/src/data/index.ts +268 -0
  232. package/src/data/item-list.ts +335 -0
  233. package/src/data/kanban.ts +667 -0
  234. package/src/data/media-grid.ts +246 -0
  235. package/src/data/mega-menu.ts +257 -0
  236. package/src/data/menu-dom.ts +169 -0
  237. package/src/data/menu.ts +464 -0
  238. package/src/data/mockup.ts +176 -0
  239. package/src/data/modal-dialog.ts +182 -0
  240. package/src/data/navbar.ts +292 -0
  241. package/src/data/object-form.ts +1981 -0
  242. package/src/data/options-bus.ts +24 -0
  243. package/src/data/outcome-watch.ts +40 -0
  244. package/src/data/overlay-portal.ts +6 -0
  245. package/src/data/pager.ts +473 -0
  246. package/src/data/permission-matrix.ts +432 -0
  247. package/src/data/permission-tree.ts +916 -0
  248. package/src/data/pricing-table.ts +269 -0
  249. package/src/data/prompt-dialog.ts +235 -0
  250. package/src/data/reaction-bar.ts +236 -0
  251. package/src/data/record-card.ts +413 -0
  252. package/src/data/record-picker.ts +489 -0
  253. package/src/data/redirect.ts +109 -0
  254. package/src/data/remote-options.ts +54 -0
  255. package/src/data/request-console.ts +399 -0
  256. package/src/data/resident.ts +58 -0
  257. package/src/data/result-panel.ts +160 -0
  258. package/src/data/rich-text.ts +626 -0
  259. package/src/data/row-editor.ts +1066 -0
  260. package/src/data/rule-builder.ts +1137 -0
  261. package/src/data/shape-util.ts +221 -0
  262. package/src/data/staged-rows.ts +69 -0
  263. package/src/data/stat-group.ts +231 -0
  264. package/src/data/static-lazy.ts +63 -0
  265. package/src/data/static-registry.ts +227 -0
  266. package/src/data/steps.ts +195 -0
  267. package/src/data/survey.ts +455 -0
  268. package/src/data/system-switcher.ts +243 -0
  269. package/src/data/timeline.ts +204 -0
  270. package/src/data/tour-guide.ts +392 -0
  271. package/src/data/transfer.ts +597 -0
  272. package/src/data/tree-check.ts +30 -0
  273. package/src/data/tree-table.ts +674 -0
  274. package/src/data/tree.ts +656 -0
  275. package/src/data/trend-line.ts +147 -0
  276. package/src/data/virtual-rows.ts +556 -0
  277. package/src/data/watermark.ts +140 -0
  278. package/src/data/wrap.ts +267 -0
  279. package/src/data/wrapped-candidates.ts +96 -0
  280. package/src/frames/blank-frame.ts +19 -0
  281. package/src/frames/index.ts +44 -0
  282. package/src/frames/page-bar.ts +185 -0
  283. package/src/frames/page-header.ts +185 -0
  284. package/src/frames/page-status.ts +54 -0
  285. package/src/frames/resize-handle.ts +147 -0
  286. package/src/frames/shared.ts +242 -0
  287. package/src/frames/single-frame.ts +16 -0
  288. package/src/frames/split-frame/index.ts +4 -0
  289. package/src/frames/split-frame/shell.ts +219 -0
  290. package/src/frames/split-frame/span.ts +64 -0
  291. package/src/frames/split-frame/wiring.ts +164 -0
  292. package/src/frames/tabs-frame/index.ts +3 -0
  293. package/src/frames/tabs-frame/shell.ts +112 -0
  294. package/src/frames/tabs-frame/wiring.ts +69 -0
  295. package/src/frames/top-main-frame.ts +20 -0
  296. package/src/frames/types.ts +72 -0
  297. package/src/frames/workspace-frame/extras.ts +197 -0
  298. package/src/frames/workspace-frame/index.ts +13 -0
  299. package/src/frames/workspace-frame/shell.ts +282 -0
  300. package/src/frames/workspace-frame/state.ts +152 -0
  301. package/src/frames/workspace-frame/view.ts +1013 -0
  302. package/src/generated/kit-grammar-runtime.ts +2822 -0
  303. package/src/generated/page-origin.ts +57 -0
  304. package/src/i18n/index.ts +22 -0
  305. package/src/i18n/kit-text.ts +692 -0
  306. package/src/i18n/resolve-text-refs.ts +128 -0
  307. package/src/index.ts +6 -0
  308. package/src/object-renderer/action-gate.ts +216 -0
  309. package/src/object-renderer/adopt-gate.ts +333 -0
  310. package/src/object-renderer/arrange.ts +411 -0
  311. package/src/object-renderer/candidates.ts +68 -0
  312. package/src/object-renderer/collapse-wiring.ts +99 -0
  313. package/src/object-renderer/collection-expand.ts +185 -0
  314. package/src/object-renderer/collection-parts.ts +653 -0
  315. package/src/object-renderer/collection-table.ts +503 -0
  316. package/src/object-renderer/collection.ts +628 -0
  317. package/src/object-renderer/compile-data.ts +549 -0
  318. package/src/object-renderer/defaults.ts +252 -0
  319. package/src/object-renderer/display-checks.ts +153 -0
  320. package/src/object-renderer/emit-events.ts +498 -0
  321. package/src/object-renderer/emit-object.ts +98 -0
  322. package/src/object-renderer/emit-static.ts +1036 -0
  323. package/src/object-renderer/field-policy.ts +89 -0
  324. package/src/object-renderer/field-value.ts +581 -0
  325. package/src/object-renderer/form-detail.ts +116 -0
  326. package/src/object-renderer/index.ts +13 -0
  327. package/src/object-renderer/linkage.ts +371 -0
  328. package/src/object-renderer/merge-class.ts +126 -0
  329. package/src/object-renderer/mode.ts +25 -0
  330. package/src/object-renderer/outcome-draft.ts +61 -0
  331. package/src/object-renderer/parts.ts +136 -0
  332. package/src/object-renderer/pick-component.ts +36 -0
  333. package/src/object-renderer/render-object.ts +724 -0
  334. package/src/object-renderer/request-actions.ts +581 -0
  335. package/src/object-renderer/skeleton.ts +101 -0
  336. package/src/object-renderer/table-actions.ts +438 -0
  337. package/src/object-renderer/table-summary.ts +105 -0
  338. package/src/object-renderer/table-tools.ts +1072 -0
  339. package/src/object-renderer/types.ts +936 -0
  340. package/src/page-target/ai-surface.ts +154 -0
  341. package/src/page-target/compile.ts +354 -0
  342. package/src/page-target/drift.ts +186 -0
  343. package/src/page-target/index.ts +25 -0
  344. package/src/page-target/intent-map.ts +137 -0
  345. package/src/page-target/intent-schema.ts +711 -0
  346. package/src/page-target/origin.ts +17 -0
  347. package/src/page-target/target.ts +450 -0
  348. package/src/page-target/writer-policy.ts +315 -0
  349. package/src/theme/block-theme.ts +202 -0
  350. package/src/theme/kit-theme-text.ts +2 -0
  351. package/src/theme/kit-theme.css +275 -0
  352. package/src/theme/kit-theme.tpl +275 -0
  353. package/src/theme/theme-tokens.ts +135 -0
@@ -0,0 +1,493 @@
1
+ // MasterSub / CategoryCrud 共用的编译小件:对象规整、事件路由、片段累积。纯函数。
2
+ //
3
+ // 规整(normalizeMember)解决三件规格里写了、渲染内核没接的事:
4
+ // 1) `view` 下直接写 staticComponent / accept / map / class(示例二、三的写法)→ 归到一个视图槽(写死形状件一律放 summary 槽:
5
+ // summary 槽不触发列表信封 `into: result`,数据路径就是对象本身);
6
+ // 2) 视图层的 `page` / `rowActions`(语法真源 viewFormKeys 列了)→ 并入 collection;
7
+ // 3) 有 write 就补缺省 form 视图,并合成「新增」工具栏动作与「编辑」行动作(规格 5.3 写死的协作入口)。
8
+
9
+ import { regionMirrorStatePath } from 'soma-core';
10
+ import { kitText } from '../../i18n/kit-text';
11
+ import type { SomaScopeDecl, SomaScopeMirrorDecl, SomaScopeSliceDecl } from 'soma-core';
12
+ import { KIT_VIEW_FORM_KEYS, KIT_VIEW_SLOTS } from '../../object-renderer/defaults';
13
+ import { actionPipeline } from '../../object-renderer/emit-events';
14
+ import { emitObject, type KitEmitInput, type KitEmitResult } from '../../object-renderer/emit-object';
15
+ import { ctxMenuAnchor, opsAnchor, rowsAnchor, selAnchor, staticCtxAnchor, toolbarAnchor, treeAnchor, virtualAnchor } from '../../object-renderer/emit-static';
16
+ import type {
17
+ KitAction, KitCollection, KitDiagnostic, KitObject, KitType, KitViewForm, KitViewSlot,
18
+ } from '../../object-renderer/types';
19
+ import { KIT_COORD_EVENTS, rewritePageLevelRowActions } from '../shared/coordinator';
20
+ import { actionSteps, createEventName, pipeTails, reloadPipe, semanticPipe } from '../shared/pipes';
21
+ import { prefillOf } from '../../object-renderer/action-gate';
22
+ import type { KitBizContext } from '../types';
23
+ import { KIT_LINK_EVENTS } from './hub';
24
+
25
+ export type Rec = Record<string, unknown>;
26
+
27
+ export function isRec(v: unknown): v is Rec {
28
+ return v !== null && typeof v === 'object' && !Array.isArray(v);
29
+ }
30
+
31
+ export const IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/;
32
+
33
+ /** 本文件合成 / 解释的内置动作名(openCreate / openEdit 与 StandardCrud 同名) */
34
+ export const LINK_BUILTIN = {
35
+ create: 'openCreate',
36
+ edit: 'openEdit',
37
+ } as const;
38
+
39
+ export function mirrorPath(scope: string, key: string): string {
40
+ return regionMirrorStatePath(scope, key);
41
+ }
42
+
43
+ export function keyFieldOf(obj: KitObject): string | undefined {
44
+ const hit = Object.entries(obj.schema).find(([, f]) => f.key === true)?.[0];
45
+ if (hit !== undefined) return hit;
46
+ return 'id' in obj.schema ? 'id' : undefined;
47
+ }
48
+
49
+ export function patchProps(show: Rec, id: string, props: Rec): boolean {
50
+ const entry = show[id];
51
+ if (!isRec(entry) || !isRec(entry.props)) return false;
52
+ show[id] = { ...entry, props: { ...entry.props, ...props } };
53
+ return true;
54
+ }
55
+
56
+ function clone<T>(v: T): T {
57
+ return JSON.parse(JSON.stringify(v)) as T;
58
+ }
59
+
60
+ // ---------------------------------------------------------------- 对象规整
61
+
62
+ export interface NormalizeOptions {
63
+ /** 诊断路径前缀,如 `product.objects.master` */
64
+ path: string;
65
+ /** 该角色允许出现的视图槽位 */
66
+ allowedViews: readonly KitViewSlot[];
67
+ /** 缺失时补缺省 {} 的视图;'any' = list / summary 都没有时补 list */
68
+ ensure: ReadonlyArray<'list' | 'summary'> | 'any';
69
+ /** true:有 write 则补 form、合成新增 / 编辑;false:写了 form 视图报 KIT-BIZ-003 */
70
+ withForm: boolean;
71
+ /** 页面语言(KitBizContext.locale):合成的「新增 / 编辑」动作名按它取 */
72
+ locale?: string;
73
+ /** 并入 behavior.params(关联键 -> 镜像引用) */
74
+ params?: Record<string, string>;
75
+ /** true:params 里的关联键编成 from[].require(没选中主行 / 分类时 core 不发请求);全局筛选类的可选参数不要开 */
76
+ requireLink?: boolean;
77
+ /** 缺失时合成的关联字段(permission: create,新建时预填、编辑时只读) */
78
+ link?: { field: string; type: KitType };
79
+ }
80
+
81
+ const SLOT_SET = new Set<string>(KIT_VIEW_SLOTS);
82
+
83
+ function toCollection(raw: unknown): KitCollection {
84
+ if (isRec(raw)) return { ...(raw as unknown as KitCollection) };
85
+ if (raw === 'cards') return { type: 'cards', cols: 1 };
86
+ if (raw === 'stack') return { type: 'stack' };
87
+ return { type: 'table' };
88
+ }
89
+
90
+ /** list 槽里的 `page` / `rowActions` 并入 collection(规格书写面)。 */
91
+ export function normalizeList(list: KitViewForm & Rec): KitViewForm {
92
+ const { page, rowActions, contextMenu, ...rest } = list as KitViewForm & Rec;
93
+ const out: KitViewForm & Rec = { ...rest };
94
+ // 写死形状组件(ItemList / Tree / Kanban)的 contextMenu 留在视图上(渲染时核对适用组件,KIT-MENU-001)
95
+ if (list.staticComponent !== undefined) {
96
+ if (contextMenu !== undefined) (out as Rec).contextMenu = contextMenu;
97
+ return out;
98
+ }
99
+ if (page === undefined && rowActions === undefined && contextMenu === undefined && list.collection === undefined) return out;
100
+ const c = toCollection(list.collection);
101
+ if (page !== undefined && c.type === 'table') (c as unknown as Rec).page = page;
102
+ if (Array.isArray(rowActions)) c.rowActions = [...(rowActions as string[])];
103
+ // 右键菜单(Q 波 G6):list 槽里的 contextMenu 并入 collection;类型 / 个数 / 动作校验在 collection()(KIT-MENU-001)
104
+ if (contextMenu !== undefined) (c as unknown as Rec).contextMenu = contextMenu;
105
+ out.collection = c;
106
+ return out;
107
+ }
108
+
109
+ function withRowAction(list: KitViewForm, id: string): KitViewForm {
110
+ if (list.staticComponent !== undefined) return list;
111
+ const c = toCollection(list.collection);
112
+ const ids = c.rowActions ?? [];
113
+ if (!ids.includes(id) && !ids.includes(`@${id}`)) c.rowActions = [...ids, id];
114
+ return { ...list, collection: c };
115
+ }
116
+
117
+ export function normalizeMember(raw: unknown, opts: NormalizeOptions): { obj: KitObject; diagnostics: KitDiagnostic[] } {
118
+ const diagnostics: KitDiagnostic[] = [];
119
+ const fail = (message: string, at: string): void => { diagnostics.push({ code: 'KIT-BIZ-003', message, path: at }); };
120
+ const src = clone(raw) as Rec;
121
+ const schema: Rec = isRec(src.schema) ? src.schema : {};
122
+ const behavior: Rec = isRec(src.behavior) ? src.behavior : {};
123
+ const originalNames = Object.keys(schema);
124
+ const nonKeyNames = Object.entries(schema).filter(([, f]) => !(isRec(f) && f.key === true)).map(([k]) => k);
125
+
126
+ // view:先把顶层的视图键归到一个槽
127
+ const view: Rec = isRec(src.view) ? { ...src.view } : {};
128
+ const loose = Object.keys(view).filter((k) => !SLOT_SET.has(k) && KIT_VIEW_FORM_KEYS.has(k));
129
+ if (loose.length > 0) {
130
+ const form: Rec = {};
131
+ for (const k of loose) { form[k] = view[k]; delete view[k]; }
132
+ const slot = form.staticComponent !== undefined ? 'summary' : 'list';
133
+ if (view[slot] === undefined) view[slot] = form;
134
+ else fail(`view 顶层的 ${loose.join(' / ')} 与 view.${slot} 冲突,请只写一处`, `${opts.path}.view`);
135
+ }
136
+ // 写死形状件统一放 summary 槽
137
+ const listView = view.list;
138
+ if (isRec(listView) && listView.staticComponent !== undefined) {
139
+ if (view.summary === undefined) { view.summary = listView; delete view.list; }
140
+ else fail('list 与 summary 不能同时是写死形状件', `${opts.path}.view.list`);
141
+ }
142
+ // 槽位白名单
143
+ for (const slot of KIT_VIEW_SLOTS) {
144
+ if (view[slot] !== undefined && !opts.allowedViews.includes(slot)) {
145
+ fail(`该对象角色不允许 ${slot} 视图(允许:${opts.allowedViews.join(' / ')})`, `${opts.path}.view.${slot}`);
146
+ delete view[slot];
147
+ }
148
+ }
149
+ if (isRec(view.list)) view.list = normalizeList(view.list as KitViewForm & Rec);
150
+
151
+ // 缺省视图
152
+ const ensure = opts.ensure === 'any'
153
+ ? (view.list === undefined && view.summary === undefined ? (['list'] as const) : [])
154
+ : opts.ensure;
155
+ for (const slot of ensure) if (view[slot] === undefined) view[slot] = {};
156
+
157
+ // 表单与动作
158
+ const actions: KitAction[] = Array.isArray(behavior.actions) ? [...(behavior.actions as KitAction[])] : [];
159
+ const hasWrite = behavior.write !== undefined;
160
+ if (opts.withForm) {
161
+ if (hasWrite && view.form === undefined) view.form = {};
162
+ if (!hasWrite && view.form !== undefined) fail('声明了 form 视图但没有 behavior.write', `${opts.path}.view.form`);
163
+ if (hasWrite && view.form !== undefined) {
164
+ if (!actions.some((a) => a.builtin === LINK_BUILTIN.create)) {
165
+ actions.unshift({ id: 'create', name: kitText('soma.kit.create', undefined, opts.locale), on: 'toolbar', builtin: LINK_BUILTIN.create, tone: 'primary' });
166
+ }
167
+ if (!actions.some((a) => a.builtin === LINK_BUILTIN.edit)) {
168
+ actions.push({ id: 'edit', name: kitText('soma.kit.edit', undefined, opts.locale), on: 'row', builtin: LINK_BUILTIN.edit });
169
+ }
170
+ }
171
+ } else if (view.form !== undefined) {
172
+ fail('该对象角色不支持 form 视图(写入由具名动作承担)', `${opts.path}.view.form`);
173
+ delete view.form;
174
+ }
175
+
176
+ // 关联字段
177
+ if (opts.link !== undefined && !(opts.link.field in schema)) {
178
+ schema[opts.link.field] = { name: opts.link.field, type: opts.link.type, permission: 'create' };
179
+ for (const slot of ['list', 'summary'] as const) {
180
+ const v = view[slot];
181
+ if (isRec(v) && v.staticComponent === undefined && v.fields === undefined) {
182
+ v.fields = slot === 'list' ? nonKeyNames : originalNames;
183
+ }
184
+ }
185
+ const form = view.form;
186
+ if (isRec(form) && Array.isArray(form.fields) && !(form.fields as unknown[]).some((f) => f === opts.link!.field || (isRec(f) && opts.link!.field in f))) {
187
+ form.fields = [...(form.fields as unknown[]), opts.link.field];
188
+ }
189
+ }
190
+
191
+ // 合成的「编辑」行动作入列
192
+ if (isRec(view.list)) {
193
+ let list = view.list as KitViewForm;
194
+ const synthEdit = actions.find((a) => a.builtin === LINK_BUILTIN.edit && a.id === 'edit');
195
+ if (synthEdit !== undefined && isRec(view.form)) list = withRowAction(list, synthEdit.id);
196
+ view.list = list;
197
+ }
198
+
199
+ const params = { ...(isRec(behavior.params) ? behavior.params as Record<string, string> : {}), ...(opts.params ?? {}) };
200
+ const nextBehavior: Rec = { ...behavior, actions };
201
+ if (Object.keys(params).length > 0) nextBehavior.params = params;
202
+ // 联动子对象:带了关联键就必填,没选中主行 / 分类时 core 不发请求(from[].require)
203
+ const requireKeys = Object.keys(opts.params ?? {});
204
+ if (opts.requireLink === true && requireKeys.length > 0) nextBehavior.requireParams = requireKeys;
205
+ const obj = { ...src, schema, behavior: nextBehavior, view } as unknown as KitObject;
206
+ return { obj, diagnostics };
207
+ }
208
+
209
+ // ---------------------------------------------------------------- 动作路由
210
+
211
+ const PLAIN_ACTION = /^ACTION \| (?!kit\.)(?!data\.)/;
212
+
213
+ /** 具名应用动作(非 kit 内置、非 data.submit)之后追加刷新步骤:规格 5.3「写入成功后协同刷新」 */
214
+ function wrapActions(node: Rec, refresh: readonly string[], link: string): void {
215
+ for (const [k, v] of Object.entries(node)) {
216
+ if (typeof v === 'string' && PLAIN_ACTION.test(v)) {
217
+ // 尾段(confirm / permission)直接带在 ACTION 步骤上,被拒则刷新不执行
218
+ node[k] = { steps: actionSteps(v, refresh) };
219
+ } else if (isRec(v) && !Array.isArray(v.steps)) {
220
+ wrapActions(v, refresh, link);
221
+ }
222
+ }
223
+ }
224
+
225
+ /** 字段动作的语义事件回传 id:由字段与动作名拼出,小写 snake_case */
226
+ export function fieldActionId(field: string, action: string): string {
227
+ return `${field}_${action}`.toLowerCase().replace(/[^a-z0-9_]/g, '_');
228
+ }
229
+
230
+ /**
231
+ * 摘要里的字段动作(Switch 等 change 事件)载荷只有 `{ value }`,不知道是哪一行(core 不替字段事件补 row)。
232
+ * 改成:字段事件 -> `SCOPE | semantic`(枢纽持有当前选中行)-> 枢纽抛 `field_action { id, value, row }` -> 页面按 id 分流到应用动作。
233
+ * 返回要挂到枢纽 `field_action` 事件上的步骤。
234
+ */
235
+ export function liftFieldActions(object: string, link: string, events: Rec): Array<Rec> {
236
+ const steps: Array<Rec> = [];
237
+ const prefix = `${object}__summary__`;
238
+ for (const [k, v] of Object.entries(events)) {
239
+ if (!k.startsWith(prefix) || typeof v !== 'string' || !PLAIN_ACTION.test(v)) continue;
240
+ const anchor = k.slice(0, k.lastIndexOf('.'));
241
+ const act = v.split(' | ')[1] ?? '';
242
+ const sid = fieldActionId(anchor.slice(prefix.length), act);
243
+ events[k] = semanticPipe(link, `${KIT_LINK_EVENTS.fieldPrefix}${sid}`);
244
+ steps.push({ when: { field: 'id', op: 'eq', value: sid }, do: v });
245
+ }
246
+ return steps;
247
+ }
248
+
249
+ export interface MemberArgs {
250
+ object: string;
251
+ scope: string;
252
+ obj: KitObject;
253
+ ctx: KitBizContext;
254
+ /** 链接作用域:所有语义事件发往这里 */
255
+ link: string;
256
+ hubId: string;
257
+ /** 应用动作之后要追加的刷新管道(如协调组件的 kit_reload) */
258
+ refresh: readonly string[];
259
+ /** 列表行可点选(行点击抛 row_action,kit_action: select) */
260
+ pick?: boolean;
261
+ emitInput?: KitEmitInput;
262
+ /** 累积摘要字段动作的分流步骤(挂到枢纽的 field_action 事件上) */
263
+ fieldSteps?: Array<Rec>;
264
+ /** 累积带预填的「新建」钮(H1a):语义事件名 -> { 字段: 字面量 },调用方整表交给协调组件的 createPrefills */
265
+ createPrefills?: Record<string, Record<string, unknown>>;
266
+ }
267
+
268
+ export interface MemberResult {
269
+ r: KitEmitResult;
270
+ /** 行操作拆实例之后的列表 HTML */
271
+ listHtml: string;
272
+ }
273
+
274
+ /**
275
+ * 诊断路径带上对象名(`<对象>:<路径>`)。多个对象的同形诊断(如两个对象都引用了不存在的行动作)
276
+ * 路径与文案相同,去重会把后一个吞掉;带上对象名后各自独立。
277
+ */
278
+ export function labelDiagnostics(r: KitEmitResult, label: string): KitEmitResult {
279
+ r.diagnostics = r.diagnostics.map((d) => ({ ...d, path: `${label}:${d.path}` }));
280
+ return r;
281
+ }
282
+
283
+ /** 发射一个对象,并把事件改写成本组件的协作链 */
284
+ export function emitMember(out: Parts, a: MemberArgs): MemberResult {
285
+ const { object, scope, obj, ctx, link } = a;
286
+ const actions = obj.behavior.actions ?? [];
287
+ const r = labelDiagnostics(emitObject(
288
+ obj,
289
+ { object, scope, registered: ctx.registeredComponents, staticComponents: ctx.staticComponents },
290
+ {
291
+ registeredActions: ctx.registeredActions,
292
+ formMode: 'create',
293
+ ...(a.pick === true ? { pickOnRow: true } : {}),
294
+ ...(a.emitInput ?? {}),
295
+ },
296
+ ), object);
297
+ addEmit(out, r);
298
+ ensureScope(out, scope, object, a.hubId);
299
+
300
+ const events = out.events;
301
+ // 勾选列的 row_select 语义事件发往链接作用域的协调组件(emitObject 发的是对象自己的作用域)
302
+ const rowsEv = events[rowsAnchor(object)];
303
+ const selKey = `${selAnchor(object)}.row_select`;
304
+ if (isRec(rowsEv) && selKey in rowsEv) rowsEv[selKey] = semanticPipe(link, KIT_COORD_EVENTS.select);
305
+ const lifted = liftFieldActions(object, link, events);
306
+ if (a.fieldSteps !== undefined) a.fieldSteps.push(...lifted);
307
+ // 具名工具栏动作的原管道(wrapActions 之前取):枢纽带当前选中行转发(③),见下方改写
308
+ const toolbarNamed = new Map<string, { id: string; pipe: string }>();
309
+ if (a.fieldSteps !== undefined) {
310
+ for (const act of actions) {
311
+ if (act.on !== 'toolbar') continue;
312
+ const click = `${toolbarAnchor(object, act.id)}.click`;
313
+ const cur = events[click];
314
+ if (typeof cur === 'string' && PLAIN_ACTION.test(cur)) toolbarNamed.set(click, { id: act.id, pipe: cur });
315
+ }
316
+ }
317
+ wrapActions(events, a.refresh, link);
318
+ // ③:工具栏点击没有载荷、拿不到选中的主单。改成「点击 -> 枢纽语义事件 -> 枢纽抛 field_action { id, row: 当前选中行 } ->
319
+ // 页面按 id 分流到原动作」,动作回调的 row 就是当前选中主单;动作之后的刷新由枢纽事件末尾统一追加
320
+ if (a.fieldSteps !== undefined) {
321
+ for (const [click, { id, pipe }] of toolbarNamed) {
322
+ const sid = fieldActionId('toolbar', id);
323
+ events[click] = semanticPipe(link, `${KIT_LINK_EVENTS.fieldPrefix}${sid}`);
324
+ a.fieldSteps.push({ when: { field: 'id', op: 'eq', value: sid }, do: pipe });
325
+ }
326
+ }
327
+
328
+ actions.forEach((act, i) => {
329
+ if (act.prefill !== undefined && act.builtin !== LINK_BUILTIN.create) {
330
+ out.diagnostics.push({ code: 'KIT-ACT-007', path: `behavior.actions[${i}].prefill`, message: `动作 ${act.id} 的 prefill 只用于 builtin: openCreate` });
331
+ }
332
+ if (act.on !== 'toolbar') return;
333
+ const click = `${toolbarAnchor(object, act.id)}.click`;
334
+ if (act.builtin === LINK_BUILTIN.create) {
335
+ // H1a:联动型业务组件的「新建」钮也可带预填(多个预设类型的新建钮各写各的 prefill);联动对象没有筛选来源,只许字面量
336
+ const at = `behavior.actions[${i}]`;
337
+ let eventName: string = KIT_COORD_EVENTS.openCreate;
338
+ if (act.prefill !== undefined) {
339
+ const dollar = Object.entries(act.prefill as Rec).filter(([, v]) => typeof v === 'string' && v.startsWith('$'));
340
+ if (a.createPrefills === undefined) {
341
+ out.diagnostics.push({ code: 'KIT-ACT-007', path: `${at}.prefill`, message: `动作 ${act.id} 写了 prefill,但这个位置的新建不带预填(预填只在 StandardCrud、MasterSub 的主对象、CategoryCrud 的明细对象的新建钮上生效)` });
342
+ } else if (dollar.length > 0) {
343
+ out.diagnostics.push({
344
+ code: 'KIT-ACT-007', path: `${at}.prefill.${dollar[0]![0]}`,
345
+ message: `动作 ${act.id} 的 prefill.${dollar[0]![0]} 写了取值路径 ${String(dollar[0]![1])}:联动型业务组件(主从 / 分类 / 多对象)的新建没有筛选来源,预填只许字面量;需要按筛选预填请用 StandardCrud`,
346
+ });
347
+ } else {
348
+ const prefill = prefillOf(act, new Set(Object.keys(obj.schema)), false, at, out.diagnostics);
349
+ if (prefill !== undefined && prefill !== null) {
350
+ eventName = createEventName(act);
351
+ const table = a.createPrefills;
352
+ if (table !== undefined) {
353
+ if (eventName in table && JSON.stringify(table[eventName]) !== JSON.stringify(prefill)) {
354
+ out.diagnostics.push({ code: 'KIT-ACT-007', path: `${at}.id`, message: `动作 ${act.id} 的 id 归一化后与同组件里另一个新建钮重名(${eventName})而预填不同,请换一个动作 id` });
355
+ }
356
+ table[eventName] = prefill;
357
+ }
358
+ }
359
+ }
360
+ }
361
+ events[click] = semanticPipe(link, eventName, pipeTails(act, at, out.diagnostics));
362
+ } else if (act.builtin === 'reload') {
363
+ // K-2:刷新内置动作
364
+ events[click] = semanticPipe(link, KIT_COORD_EVENTS.reload, pipeTails(act, `behavior.actions[${i}]`, out.diagnostics));
365
+ }
366
+ });
367
+
368
+ // ---- 行操作:同一个实例,steps 按 kit_action 分流,尾段写在对应步骤上
369
+ const listHtml = r.parts.list ?? '';
370
+ const rowActs = actions.filter((x) => x.on === 'row');
371
+ const pick = a.pick === true;
372
+ if (rowActs.length > 0 || pick) {
373
+ const rowsKey = rowsAnchor(object);
374
+ const ops = opsAnchor(object);
375
+
376
+ const nested: Rec = isRec(events[rowsKey]) ? { ...(events[rowsKey] as Rec) } : {};
377
+ // 只有行模板真的产出了操作列锚点(原事件表里有它)才写回;虚拟表 / 树表 / 看板 / 只配右键菜单的表没有这个节点,写了会在挂载期缺事件源
378
+ // 仅行点击(pickOnRow)无行操作时事件表没有这一项,但 html 里补了无按钮的操作列实例,也要写(否则行点击接线丢失)
379
+ const hadRowOps = nested[`${ops}.row_action`] !== undefined || listHtml.includes(`data-soma-id="${ops}"`);
380
+ delete nested[`${ops}.row_action`];
381
+ const steps: Array<Rec> = [];
382
+ if (pick) steps.push({ when: { field: 'kit_action', op: 'eq', value: 'select' }, do: semanticPipe(link, KIT_LINK_EVENTS.pick) });
383
+ const route = (act: KitAction, withRefresh: boolean): Array<{ do: string }> | null => {
384
+ const at = `behavior.actions.${act.id}`;
385
+ if (act.builtin === LINK_BUILTIN.edit) return [{ do: semanticPipe(link, KIT_COORD_EVENTS.openEdit, pipeTails(act, at, out.diagnostics)) }];
386
+ if (act.builtin === 'reload') return [{ do: semanticPipe(link, KIT_COORD_EVENTS.reload, pipeTails(act, at, out.diagnostics)) }];
387
+ const pipe = actionPipeline(act, at, { hasWrite: true, object, registeredActions: ctx.registeredActions }, []);
388
+ if (pipe === null) return null;
389
+ return [{ do: pipe }, ...(withRefresh ? a.refresh.map((p) => ({ do: p })) : [])];
390
+ };
391
+ for (const act of rowActs) {
392
+ const list = route(act, true);
393
+ if (list === null) continue;
394
+ for (const s of list) steps.push({ when: { field: 'kit_action', op: 'eq', value: act.id }, ...s });
395
+ }
396
+ if (hadRowOps && steps.length > 0) nested[`${ops}.row_action`] = { steps };
397
+ // 右键菜单(Q 波 G6)的 KitContextMenu 与行操作同载荷,沿用同一串改写后的步骤
398
+ if (steps.length > 0 && nested[`${ctxMenuAnchor(object)}.row_action`] !== undefined) nested[`${ctxMenuAnchor(object)}.row_action`] = { steps };
399
+ // 页面级表体(虚拟滚动 / 树表)与各右键菜单实例的事件不在 rowsKey 之下,同样改写
400
+ if (steps.length > 0) {
401
+ rewritePageLevelRowActions(events, [virtualAnchor(object), treeAnchor(object), ctxMenuAnchor(object), staticCtxAnchor(object, 'list'), staticCtxAnchor(object, 'summary')], steps);
402
+ }
403
+ if (Object.keys(nested).length > 0) events[rowsKey] = nested;
404
+ }
405
+ return { r, listHtml };
406
+ }
407
+
408
+ // ---------------------------------------------------------------- 片段累积
409
+
410
+ export interface Parts {
411
+ show: Rec;
412
+ data: Rec;
413
+ scopes: Record<string, SomaScopeDecl>;
414
+ events: Rec;
415
+ components: Set<string>;
416
+ candidates: Set<string>;
417
+ diagnostics: KitDiagnostic[];
418
+ }
419
+
420
+ export function newParts(components: readonly string[]): Parts {
421
+ return {
422
+ show: {}, data: {}, scopes: {}, events: {},
423
+ components: new Set(components), candidates: new Set<string>(), diagnostics: [],
424
+ };
425
+ }
426
+
427
+ export function addEmit(into: Parts, r: KitEmitResult): void {
428
+ Object.assign(into.show, r.ui.show);
429
+ Object.assign(into.data, r.ui.data);
430
+ for (const decl of r.ui.scopes) into.scopes[decl.id] = decl;
431
+ Object.assign(into.events, r.events);
432
+ for (const c of r.components) into.components.add(c);
433
+ for (const c of r.candidates) into.candidates.add(c);
434
+ into.diagnostics.push(...r.diagnostics);
435
+ }
436
+
437
+ /** 保证对象有作用域声明(window-reload 按它取对象名);没有就补一个只带 results 切片、owner 是枢纽的最小声明 */
438
+ export function ensureScope(parts: Parts, id: string, object: string, ownerId: string): SomaScopeDecl {
439
+ const have = parts.scopes[id];
440
+ if (have !== undefined) return have;
441
+ const decl: SomaScopeDecl = { id, object, slices: [{ name: 'results', owner: ownerId }] };
442
+ parts.scopes[id] = decl;
443
+ return decl;
444
+ }
445
+
446
+ /** 给作用域的 view 切片登记 `page` 路径写者(枢纽选中项变化时回第 1 页);没有 view 切片返回 false */
447
+ export function grantPageReset(parts: Parts, id: string, hubId: string): boolean {
448
+ const decl = parts.scopes[id];
449
+ const slice = decl?.slices.find((s) => s.name === 'view');
450
+ if (decl === undefined || slice === undefined) return false;
451
+ const patched: SomaScopeSliceDecl = { ...slice, writers: { ...(slice.writers ?? {}), page: hubId } };
452
+ parts.scopes[id] = { ...decl, slices: decl.slices.map((s) => (s === slice ? patched : s)) };
453
+ return true;
454
+ }
455
+
456
+ export function sortMirrors(list: SomaScopeMirrorDecl[]): SomaScopeMirrorDecl[] {
457
+ return [...list].sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
458
+ }
459
+
460
+ /** 去掉重复诊断 */
461
+ export function dedupeDiagnostics(list: readonly KitDiagnostic[]): KitDiagnostic[] {
462
+ const seen = new Set<string>();
463
+ const out: KitDiagnostic[] = [];
464
+ for (const d of list) {
465
+ const key = `${d.code}\u0000${d.path}\u0000${d.message}`;
466
+ if (seen.has(key)) continue;
467
+ seen.add(key);
468
+ out.push(d);
469
+ }
470
+ return out;
471
+ }
472
+
473
+ export function classesIn(html: string): string[] {
474
+ const out = new Set<string>();
475
+ for (const m of html.matchAll(/class="([^"]*)"/g)) {
476
+ for (const c of (m[1] ?? '').split(/\s+/)) if (c !== '') out.add(c);
477
+ }
478
+ return [...out];
479
+ }
480
+
481
+ export function esc(text: string): string {
482
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
483
+ }
484
+
485
+ export function cls(value: string): string {
486
+ return value === '' ? '' : ` class="${esc(value)}"`;
487
+ }
488
+
489
+ export function host(component: string, id: string): string {
490
+ return `<div data-soma-component="${component}" data-soma-id="${esc(id)}"></div>`;
491
+ }
492
+
493
+ export { reloadPipe, semanticPipe };