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.
- package/README.md +539 -2
- package/bin/soma-kit.mjs +27 -0
- package/package.json +66 -4
- package/packs/ai/agent-run-card.ts +64 -0
- package/packs/ai/evaluation-card.ts +51 -0
- package/packs/ai/guardrail-policy-card.ts +48 -0
- package/packs/ai/index.ts +31 -0
- package/packs/ai/model-card.ts +55 -0
- package/packs/ai/model-routing-card.ts +49 -0
- package/packs/ai/prompt-template-card.ts +49 -0
- package/packs/ai/texts.ts +19 -0
- package/packs/commerce/address-card.ts +58 -0
- package/packs/commerce/coupon-card.ts +64 -0
- package/packs/commerce/index.ts +25 -0
- package/packs/commerce/order-card.ts +60 -0
- package/packs/commerce/purchase-order-card.ts +74 -0
- package/packs/commerce/texts.ts +14 -0
- package/packs/finance/index.ts +30 -0
- package/packs/finance/invoice-summary-card.ts +48 -0
- package/packs/finance/reconcile-board.ts +450 -0
- package/packs/finance/reconcile-case-card.ts +70 -0
- package/packs/finance/reconcile-desk/compile.ts +208 -0
- package/packs/finance/reconcile-desk/index.ts +20 -0
- package/packs/finance/reconcile-desk/shell.ts +27 -0
- package/packs/finance/texts.ts +21 -0
- package/packs/ops/change-window-card.ts +54 -0
- package/packs/ops/dependency-status-card.ts +50 -0
- package/packs/ops/error-budget-card.ts +60 -0
- package/packs/ops/execution-task-runner.ts +61 -0
- package/packs/ops/index.ts +36 -0
- package/packs/ops/integration-status-card.ts +45 -0
- package/packs/ops/release-readiness-card.ts +63 -0
- package/packs/ops/runbook-execution-card.ts +81 -0
- package/packs/ops/texts.ts +21 -0
- package/packs/security/control-evidence-card.ts +54 -0
- package/packs/security/finding-card.ts +96 -0
- package/packs/security/index.ts +29 -0
- package/packs/security/texts.ts +31 -0
- package/packs/shared/card-util.ts +60 -0
- package/packs/shared/wrap.ts +13 -0
- package/spec/generated/kit-app.schema.json +84 -0
- package/spec/generated/kit-page.schema.json +2766 -0
- package/spec/kit-grammar.json +1358 -0
- package/spec/kit-grammar.schema.json +716 -0
- package/src/app/app-config.ts +108 -0
- package/src/app/compose-apps.ts +139 -0
- package/src/app/define-kit-actions.ts +89 -0
- package/src/app/define-kit-app.ts +362 -0
- package/src/app/define-kit-pack.ts +114 -0
- package/src/app/envelope.ts +117 -0
- package/src/app/index.ts +50 -0
- package/src/app/notify-renderer.ts +114 -0
- package/src/app/paged-list-adapter.ts +246 -0
- package/src/app/server-pages.ts +303 -0
- package/src/app/server.ts +244 -0
- package/src/app/submit.types.ts +87 -0
- package/src/base/action-busy.ts +159 -0
- package/src/base/action-gate.ts +267 -0
- package/src/base/action-status.ts +31 -0
- package/src/base/alert.ts +136 -0
- package/src/base/avatar.ts +271 -0
- package/src/base/button.ts +139 -0
- package/src/base/cascader.ts +523 -0
- package/src/base/check-core.ts +214 -0
- package/src/base/checkbox.ts +35 -0
- package/src/base/choice.ts +183 -0
- package/src/base/color-picker.ts +316 -0
- package/src/base/combobox.ts +61 -0
- package/src/base/command-palette.ts +371 -0
- package/src/base/context-menu.ts +103 -0
- package/src/base/countdown.ts +168 -0
- package/src/base/date-range.ts +444 -0
- package/src/base/date.ts +899 -0
- package/src/base/divider.ts +156 -0
- package/src/base/fab.ts +192 -0
- package/src/base/icons.ts +106 -0
- package/src/base/image.ts +177 -0
- package/src/base/index.ts +214 -0
- package/src/base/input.ts +316 -0
- package/src/base/kbd.ts +99 -0
- package/src/base/link.ts +167 -0
- package/src/base/listbox-core.ts +965 -0
- package/src/base/mentions.ts +323 -0
- package/src/base/menu-button.ts +240 -0
- package/src/base/menu-core.ts +341 -0
- package/src/base/month-grid.ts +171 -0
- package/src/base/motion/aura.ts +94 -0
- package/src/base/motion/hover-3d.ts +154 -0
- package/src/base/motion/hover-gallery.ts +185 -0
- package/src/base/motion/index.ts +27 -0
- package/src/base/motion/limits.ts +75 -0
- package/src/base/motion/marquee.ts +157 -0
- package/src/base/motion/text-rotate.ts +195 -0
- package/src/base/number.ts +121 -0
- package/src/base/otp.ts +259 -0
- package/src/base/permission-gate.ts +99 -0
- package/src/base/popover.ts +352 -0
- package/src/base/popup.ts +542 -0
- package/src/base/portal-core.ts +297 -0
- package/src/base/price-text.ts +126 -0
- package/src/base/progress.ts +216 -0
- package/src/base/qr-code.ts +446 -0
- package/src/base/qty-stepper.ts +241 -0
- package/src/base/radio.ts +33 -0
- package/src/base/range.ts +444 -0
- package/src/base/rating.ts +249 -0
- package/src/base/segmented.ts +286 -0
- package/src/base/select.ts +57 -0
- package/src/base/shared.ts +708 -0
- package/src/base/swap.ts +86 -0
- package/src/base/switch.ts +111 -0
- package/src/base/tag-input.ts +464 -0
- package/src/base/tag.ts +250 -0
- package/src/base/text.ts +126 -0
- package/src/base/textarea.ts +129 -0
- package/src/base/time-picker.ts +606 -0
- package/src/base/tree-select.ts +629 -0
- package/src/base/upload.ts +548 -0
- package/src/base/virtual-list.ts +286 -0
- package/src/biz/approval-desk/compile.ts +179 -0
- package/src/biz/approval-desk/index.ts +21 -0
- package/src/biz/approval-desk/shell.ts +50 -0
- package/src/biz/auth-panel/compile.ts +196 -0
- package/src/biz/auth-panel/index.ts +24 -0
- package/src/biz/auth-panel/shell.ts +46 -0
- package/src/biz/category-crud/compile.ts +173 -0
- package/src/biz/category-crud/index.ts +19 -0
- package/src/biz/category-crud/shell.ts +29 -0
- package/src/biz/checkout-page/compile.ts +111 -0
- package/src/biz/checkout-page/index.ts +20 -0
- package/src/biz/checkout-page/shell.ts +50 -0
- package/src/biz/compose.ts +313 -0
- package/src/biz/data-components.ts +26 -0
- package/src/biz/define.ts +23 -0
- package/src/biz/import-wizard/compile.ts +204 -0
- package/src/biz/import-wizard/hub.ts +540 -0
- package/src/biz/import-wizard/index.ts +24 -0
- package/src/biz/import-wizard/shell.ts +161 -0
- package/src/biz/index.ts +80 -0
- package/src/biz/landing-page/compile.ts +67 -0
- package/src/biz/landing-page/index.ts +20 -0
- package/src/biz/landing-page/shell.ts +48 -0
- package/src/biz/link/hub.ts +255 -0
- package/src/biz/link/shared.ts +493 -0
- package/src/biz/master-sub/compile.ts +232 -0
- package/src/biz/master-sub/index.ts +20 -0
- package/src/biz/master-sub/shell.ts +56 -0
- package/src/biz/multi-board/compile.ts +234 -0
- package/src/biz/multi-board/index.ts +19 -0
- package/src/biz/multi-board/shell.ts +70 -0
- package/src/biz/names.ts +30 -0
- package/src/biz/notification-center/compile.ts +138 -0
- package/src/biz/notification-center/index.ts +29 -0
- package/src/biz/notification-center/shell.ts +42 -0
- package/src/biz/page-templates/result-page/compile.ts +46 -0
- package/src/biz/page-templates/result-page/index.ts +19 -0
- package/src/biz/page-templates/result-page/shell.ts +31 -0
- package/src/biz/page-templates/shared.ts +121 -0
- package/src/biz/page-templates/sign-in-page/compile.ts +176 -0
- package/src/biz/page-templates/sign-in-page/index.ts +18 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +116 -0
- package/src/biz/record-detail/compile.ts +290 -0
- package/src/biz/record-detail/index.ts +22 -0
- package/src/biz/record-detail/shell.ts +64 -0
- package/src/biz/settings-center/compile.ts +100 -0
- package/src/biz/settings-center/index.ts +18 -0
- package/src/biz/settings-center/shell.ts +51 -0
- package/src/biz/shared/action-host.ts +469 -0
- package/src/biz/shared/coordinator.ts +516 -0
- package/src/biz/shared/index.ts +9 -0
- package/src/biz/shared/pipes.ts +58 -0
- package/src/biz/shared/runtime-hub.ts +112 -0
- package/src/biz/shared/step-values.ts +25 -0
- package/src/biz/single-form/compile.ts +146 -0
- package/src/biz/single-form/index.ts +18 -0
- package/src/biz/single-form/shell.ts +38 -0
- package/src/biz/standard-crud/bridge.ts +11 -0
- package/src/biz/standard-crud/compile.ts +546 -0
- package/src/biz/standard-crud/index.ts +18 -0
- package/src/biz/standard-crud/shell.ts +157 -0
- package/src/biz/step-form/compile.ts +400 -0
- package/src/biz/step-form/hub.ts +412 -0
- package/src/biz/step-form/index.ts +23 -0
- package/src/biz/step-form/shell.ts +96 -0
- package/src/biz/step-form/steps-ref.ts +112 -0
- package/src/biz/types.ts +96 -0
- package/src/cli/kit-cli.ts +102 -0
- package/src/compile/action-host-attach.ts +76 -0
- package/src/compile/compile-page.ts +472 -0
- package/src/compile/component-candidates.ts +147 -0
- package/src/compile/fragment.ts +104 -0
- package/src/compile/hints.ts +255 -0
- package/src/compile/index.ts +16 -0
- package/src/compile/locate.ts +166 -0
- package/src/compile/page-params.ts +80 -0
- package/src/compile/parse.ts +355 -0
- package/src/compile/redirect.ts +90 -0
- package/src/compile/registry.ts +30 -0
- package/src/compile/remove-guard.ts +99 -0
- package/src/compile/styles.ts +244 -0
- package/src/compile/types.ts +106 -0
- package/src/data/amount-breakdown.ts +132 -0
- package/src/data/anchor-nav.ts +225 -0
- package/src/data/approval-flow.ts +269 -0
- package/src/data/assignment-picker.ts +652 -0
- package/src/data/async-result-panel.ts +308 -0
- package/src/data/breadcrumbs.ts +197 -0
- package/src/data/calendar.ts +363 -0
- package/src/data/carousel.ts +408 -0
- package/src/data/chart.ts +726 -0
- package/src/data/checklist.ts +215 -0
- package/src/data/code-view.ts +415 -0
- package/src/data/comment-thread.ts +342 -0
- package/src/data/confirm-dialog.ts +144 -0
- package/src/data/context-menu.ts +216 -0
- package/src/data/d9-limits.ts +42 -0
- package/src/data/d9-util.ts +81 -0
- package/src/data/diff.ts +239 -0
- package/src/data/display-util.ts +135 -0
- package/src/data/dock.ts +152 -0
- package/src/data/embed.ts +200 -0
- package/src/data/field-mapper.ts +544 -0
- package/src/data/flow-editor-contract.ts +41 -0
- package/src/data/flow-editor.ts +2622 -0
- package/src/data/flow-remote-options.ts +257 -0
- package/src/data/footer.ts +157 -0
- package/src/data/form-draft-registry.ts +76 -0
- package/src/data/gantt.ts +430 -0
- package/src/data/hero.ts +149 -0
- package/src/data/image-viewer.ts +333 -0
- package/src/data/index.ts +268 -0
- package/src/data/item-list.ts +335 -0
- package/src/data/kanban.ts +667 -0
- package/src/data/media-grid.ts +246 -0
- package/src/data/mega-menu.ts +257 -0
- package/src/data/menu-dom.ts +169 -0
- package/src/data/menu.ts +464 -0
- package/src/data/mockup.ts +176 -0
- package/src/data/modal-dialog.ts +182 -0
- package/src/data/navbar.ts +292 -0
- package/src/data/object-form.ts +1981 -0
- package/src/data/options-bus.ts +24 -0
- package/src/data/outcome-watch.ts +40 -0
- package/src/data/overlay-portal.ts +6 -0
- package/src/data/pager.ts +473 -0
- package/src/data/permission-matrix.ts +432 -0
- package/src/data/permission-tree.ts +916 -0
- package/src/data/pricing-table.ts +269 -0
- package/src/data/prompt-dialog.ts +235 -0
- package/src/data/reaction-bar.ts +236 -0
- package/src/data/record-card.ts +413 -0
- package/src/data/record-picker.ts +489 -0
- package/src/data/redirect.ts +109 -0
- package/src/data/remote-options.ts +54 -0
- package/src/data/request-console.ts +399 -0
- package/src/data/resident.ts +58 -0
- package/src/data/result-panel.ts +160 -0
- package/src/data/rich-text.ts +626 -0
- package/src/data/row-editor.ts +1066 -0
- package/src/data/rule-builder.ts +1137 -0
- package/src/data/shape-util.ts +221 -0
- package/src/data/staged-rows.ts +69 -0
- package/src/data/stat-group.ts +231 -0
- package/src/data/static-lazy.ts +63 -0
- package/src/data/static-registry.ts +227 -0
- package/src/data/steps.ts +195 -0
- package/src/data/survey.ts +455 -0
- package/src/data/system-switcher.ts +243 -0
- package/src/data/timeline.ts +204 -0
- package/src/data/tour-guide.ts +392 -0
- package/src/data/transfer.ts +597 -0
- package/src/data/tree-check.ts +30 -0
- package/src/data/tree-table.ts +674 -0
- package/src/data/tree.ts +656 -0
- package/src/data/trend-line.ts +147 -0
- package/src/data/virtual-rows.ts +556 -0
- package/src/data/watermark.ts +140 -0
- package/src/data/wrap.ts +267 -0
- package/src/data/wrapped-candidates.ts +96 -0
- package/src/frames/blank-frame.ts +19 -0
- package/src/frames/index.ts +44 -0
- package/src/frames/page-bar.ts +185 -0
- package/src/frames/page-header.ts +185 -0
- package/src/frames/page-status.ts +54 -0
- package/src/frames/resize-handle.ts +147 -0
- package/src/frames/shared.ts +242 -0
- package/src/frames/single-frame.ts +16 -0
- package/src/frames/split-frame/index.ts +4 -0
- package/src/frames/split-frame/shell.ts +219 -0
- package/src/frames/split-frame/span.ts +64 -0
- package/src/frames/split-frame/wiring.ts +164 -0
- package/src/frames/tabs-frame/index.ts +3 -0
- package/src/frames/tabs-frame/shell.ts +112 -0
- package/src/frames/tabs-frame/wiring.ts +69 -0
- package/src/frames/top-main-frame.ts +20 -0
- package/src/frames/types.ts +72 -0
- package/src/frames/workspace-frame/extras.ts +197 -0
- package/src/frames/workspace-frame/index.ts +13 -0
- package/src/frames/workspace-frame/shell.ts +282 -0
- package/src/frames/workspace-frame/state.ts +152 -0
- package/src/frames/workspace-frame/view.ts +1013 -0
- package/src/generated/kit-grammar-runtime.ts +2822 -0
- package/src/generated/page-origin.ts +57 -0
- package/src/i18n/index.ts +22 -0
- package/src/i18n/kit-text.ts +692 -0
- package/src/i18n/resolve-text-refs.ts +128 -0
- package/src/index.ts +6 -0
- package/src/object-renderer/action-gate.ts +216 -0
- package/src/object-renderer/adopt-gate.ts +333 -0
- package/src/object-renderer/arrange.ts +411 -0
- package/src/object-renderer/candidates.ts +68 -0
- package/src/object-renderer/collapse-wiring.ts +99 -0
- package/src/object-renderer/collection-expand.ts +185 -0
- package/src/object-renderer/collection-parts.ts +653 -0
- package/src/object-renderer/collection-table.ts +503 -0
- package/src/object-renderer/collection.ts +628 -0
- package/src/object-renderer/compile-data.ts +549 -0
- package/src/object-renderer/defaults.ts +252 -0
- package/src/object-renderer/display-checks.ts +153 -0
- package/src/object-renderer/emit-events.ts +498 -0
- package/src/object-renderer/emit-object.ts +98 -0
- package/src/object-renderer/emit-static.ts +1036 -0
- package/src/object-renderer/field-policy.ts +89 -0
- package/src/object-renderer/field-value.ts +581 -0
- package/src/object-renderer/form-detail.ts +116 -0
- package/src/object-renderer/index.ts +13 -0
- package/src/object-renderer/linkage.ts +371 -0
- package/src/object-renderer/merge-class.ts +126 -0
- package/src/object-renderer/mode.ts +25 -0
- package/src/object-renderer/outcome-draft.ts +61 -0
- package/src/object-renderer/parts.ts +136 -0
- package/src/object-renderer/pick-component.ts +36 -0
- package/src/object-renderer/render-object.ts +724 -0
- package/src/object-renderer/request-actions.ts +581 -0
- package/src/object-renderer/skeleton.ts +101 -0
- package/src/object-renderer/table-actions.ts +438 -0
- package/src/object-renderer/table-summary.ts +105 -0
- package/src/object-renderer/table-tools.ts +1072 -0
- package/src/object-renderer/types.ts +936 -0
- package/src/page-target/ai-surface.ts +154 -0
- package/src/page-target/compile.ts +354 -0
- package/src/page-target/drift.ts +186 -0
- package/src/page-target/index.ts +25 -0
- package/src/page-target/intent-map.ts +137 -0
- package/src/page-target/intent-schema.ts +711 -0
- package/src/page-target/origin.ts +17 -0
- package/src/page-target/target.ts +450 -0
- package/src/page-target/writer-policy.ts +315 -0
- package/src/theme/block-theme.ts +202 -0
- package/src/theme/kit-theme-text.ts +2 -0
- package/src/theme/kit-theme.css +275 -0
- package/src/theme/kit-theme.tpl +275 -0
- package/src/theme/theme-tokens.ts +135 -0
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
// StandardCrud 编译:筛选栏 + 主表(工具栏、分页、行操作)+ 新增 / 编辑弹窗 + 行级附加浮层。
|
|
2
|
+
// 对象渲染全部交 emitObject(同一对象只调一次,用 r.parts 摆进壳);本文件只做壳和写死的协作链(规格 5.3):
|
|
3
|
+
//
|
|
4
|
+
// 提交筛选或重置 筛选条 submit / reset -> 写 filter 切片 + window-reload(emitObject 已发);Pager 订阅 filter 切片回第 1 页
|
|
5
|
+
// 点新增 工具栏 -> SCOPE semantic crud_open_create -> KitCoordinator 写 focus -> 弹窗显隐 + 表单 mode / initial(镜像)
|
|
6
|
+
// 点行编辑 row_action -> semantic crud_open_edit(载荷带整行)-> 同上,initial = 当前行
|
|
7
|
+
// 点行附加动作 row_action -> semantic crud_open_overlay -> 浮层显隐;协调组件重取附加对象,from.params 带当前行主键(镜像)
|
|
8
|
+
// 写入成功 表单 saved -> semantic kit_saved -> 协调组件关窗 + services.data.reload
|
|
9
|
+
// 删除 builtin remove -> semantic kit_remove -> 协调组件调 services.data.remove(对象需声明 write.delete)后重取
|
|
10
|
+
//
|
|
11
|
+
// 行操作按「有无尾段」分实例(见 shared/pipes.ts):带 confirm / permission 的每个单独一个 KitTableActions,走单管道才会执行尾段。
|
|
12
|
+
|
|
13
|
+
import { regionMirrorStatePath } from 'soma-core';
|
|
14
|
+
import { kitText } from '../../i18n/kit-text';
|
|
15
|
+
import type { SomaScopeDecl, SomaScopeMirrorDecl, SomaScopeSliceDecl } from 'soma-core';
|
|
16
|
+
import { KIT_GRAMMAR, KIT_VIEW_FORM_KEYS, KIT_VIEW_SLOTS } from '../../object-renderer/defaults';
|
|
17
|
+
import { emitObject, type KitEmitResult } from '../../object-renderer/emit-object';
|
|
18
|
+
import { actionPipeline, actionThenPipes, rowActionGate } from '../../object-renderer/emit-events';
|
|
19
|
+
import { isRequestLikeAction, registerRequestAction } from '../../object-renderer/request-actions';
|
|
20
|
+
import { checkExpandChild, expandHolderHtml, expandHostId } from '../../object-renderer/collection-expand';
|
|
21
|
+
import { ctxMenuAnchor, opsAnchor, rowsAnchor, staticCtxAnchor, toolbarAnchor, treeAnchor, viewAnchor, virtualAnchor } from '../../object-renderer/emit-static';
|
|
22
|
+
import type { KitAction, KitDiagnostic, KitObject, KitView, KitViewForm } from '../../object-renderer/types';
|
|
23
|
+
import type { KitFragment } from '../../compile/fragment';
|
|
24
|
+
import type { KitBizContext, KitBizInput, KitOverlayEventAction } from '../types';
|
|
25
|
+
import { KIT_COORD_EVENTS, KIT_COORD_MIRRORS, overlayMirrorKey, rewritePageLevelRowActions } from '../shared/coordinator';
|
|
26
|
+
import { labelDiagnostics, normalizeList } from '../link/shared';
|
|
27
|
+
import { busyActionOf } from '../../base/action-busy';
|
|
28
|
+
import { removeConfirmPlaceholders } from '../../compile/remove-guard';
|
|
29
|
+
import { actionSteps, createEventName, pipeTails, semanticPipe, wireDialogForm } from '../shared/pipes';
|
|
30
|
+
import { prefillOf } from '../../object-renderer/action-gate';
|
|
31
|
+
import {
|
|
32
|
+
CRUD_CLASS, STANDARD_CRUD_AREAS, classesIn, coordinatorHtml, coordinatorId, dialogHtml, dialogIds, dialogTitles, mainHtml, overlayHtml, overlayIds, rootHtml,
|
|
33
|
+
} from './shell';
|
|
34
|
+
|
|
35
|
+
type Rec = Record<string, unknown>;
|
|
36
|
+
|
|
37
|
+
const IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
38
|
+
|
|
39
|
+
/** 浮层里数据组件的约定事件 -> 角色(K-1) */
|
|
40
|
+
const OVERLAY_EVENT_ROLES: Record<string, string> = KIT_GRAMMAR.overlayEventRoles.conventional as Record<string, string>;
|
|
41
|
+
const OVERLAY_ROLE_SEMANTIC: Record<string, string> = {
|
|
42
|
+
saved: KIT_COORD_EVENTS.saved,
|
|
43
|
+
close: KIT_COORD_EVENTS.close,
|
|
44
|
+
reload: KIT_COORD_EVENTS.reload,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** 关联键镜像:当前行主键(附加对象的 from.params 引用) */
|
|
48
|
+
export const KIT_CRUD_LINK_KEY = 'crud_link';
|
|
49
|
+
|
|
50
|
+
function isRec(v: unknown): v is Rec {
|
|
51
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 主对象名:`${槽名}_entity`,槽名即 pageId(保留名由编译器前置校验) */
|
|
55
|
+
export function crudObjectName(pageId: string): string {
|
|
56
|
+
return `${pageId}_entity`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function mirrorPath(scope: string, key: string): string {
|
|
60
|
+
return regionMirrorStatePath(scope, key);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function keyFieldOf(obj: KitObject): string | undefined {
|
|
64
|
+
return Object.entries(obj.schema).find(([, f]) => f.key === true)?.[0];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------- 动作
|
|
68
|
+
|
|
69
|
+
// 共用实例的 steps 判别键是 row_action 载荷里的 kit_action(= 动作 id;core 会把行字段盖到载荷上,id 不可靠)。
|
|
70
|
+
|
|
71
|
+
/** 一个行动作的单管道(尾段由 pipeTails 给);返回 null 表示该动作不是本壳解释的、交 actionPipeline */
|
|
72
|
+
function ownPipe(a: KitAction, scope: string, at: string, diagnostics: KitDiagnostic[]): string | null {
|
|
73
|
+
const tails = (): string[] => pipeTails(a, at, diagnostics);
|
|
74
|
+
switch (a.builtin) {
|
|
75
|
+
case 'openEdit': return semanticPipe(scope, KIT_COORD_EVENTS.openEdit, tails());
|
|
76
|
+
case 'openOverlay': return semanticPipe(scope, KIT_COORD_EVENTS.openOverlay, tails());
|
|
77
|
+
// 带行占位的确认({字段})由 KitCrudBridge 按被删行插值后再问,core 的静态 confirm 尾段不能带行数据,故不写
|
|
78
|
+
case 'remove': return semanticPipe(scope, KIT_COORD_EVENTS.remove, removeConfirmPlaceholders(a.confirm).length > 0 ? pipeTails({ ...a, confirm: undefined }, at, diagnostics) : tails());
|
|
79
|
+
// K-2:刷新内置动作,经协调组件重取
|
|
80
|
+
case 'reload': return semanticPipe(scope, KIT_COORD_EVENTS.reload, tails());
|
|
81
|
+
default: return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ---------------------------------------------------------------- 浮层视图规整
|
|
86
|
+
|
|
87
|
+
/** 浮层的 view 允许直接写成一个视图(如 `staticComponent` 写在 view 下):list 型放 list 槽,single 型放 summary 槽 */
|
|
88
|
+
function normalizeOverlayView(view: unknown): KitView | undefined {
|
|
89
|
+
if (!isRec(view)) return undefined;
|
|
90
|
+
if (KIT_VIEW_SLOTS.some((s) => s in view)) return view as KitView;
|
|
91
|
+
if (Object.keys(view).some((k) => KIT_VIEW_FORM_KEYS.has(k))) {
|
|
92
|
+
const form = view as unknown as KitViewForm;
|
|
93
|
+
return form.accept === 'single' ? { summary: form } : { list: form };
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ---------------------------------------------------------------- 累积
|
|
99
|
+
|
|
100
|
+
interface Parts {
|
|
101
|
+
show: Rec;
|
|
102
|
+
data: Rec;
|
|
103
|
+
scopes: Record<string, SomaScopeDecl>;
|
|
104
|
+
events: Rec;
|
|
105
|
+
components: Set<string>;
|
|
106
|
+
candidates: Set<string>;
|
|
107
|
+
diagnostics: KitDiagnostic[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function addEmit(into: Parts, r: KitEmitResult): void {
|
|
111
|
+
Object.assign(into.show, r.ui.show);
|
|
112
|
+
Object.assign(into.data, r.ui.data);
|
|
113
|
+
for (const decl of r.ui.scopes) into.scopes[decl.id] = decl;
|
|
114
|
+
Object.assign(into.events, r.events);
|
|
115
|
+
for (const c of r.components) into.components.add(c);
|
|
116
|
+
for (const c of r.candidates) into.candidates.add(c);
|
|
117
|
+
into.diagnostics.push(...r.diagnostics);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function withScopeParts(decl: SomaScopeDecl | undefined, base: { id: string; object: string }, slices: SomaScopeSliceDecl[], mirrors: SomaScopeMirrorDecl[]): SomaScopeDecl {
|
|
121
|
+
const allMirrors = [...(decl?.mirrors ?? []), ...mirrors].sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
122
|
+
return {
|
|
123
|
+
id: base.id,
|
|
124
|
+
object: base.object,
|
|
125
|
+
slices: [...(decl?.slices ?? []), ...slices],
|
|
126
|
+
...(allMirrors.length > 0 ? { mirrors: allMirrors } : {}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function patchProps(show: Rec, id: string, props: Rec): boolean {
|
|
131
|
+
const entry = show[id];
|
|
132
|
+
if (!isRec(entry) || !isRec(entry.props)) return false;
|
|
133
|
+
show[id] = { ...entry, props: { ...entry.props, ...props } };
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function finish(out: Parts, html: string): KitFragment {
|
|
138
|
+
return {
|
|
139
|
+
html,
|
|
140
|
+
ui: {
|
|
141
|
+
data: out.data,
|
|
142
|
+
// 键 = 作用域 id;core 的 `scopes:` 是数组,编译器输出 `_ui.yaml` 时取 Object.values
|
|
143
|
+
scopes: out.scopes as unknown as Record<string, unknown>,
|
|
144
|
+
show: out.show,
|
|
145
|
+
},
|
|
146
|
+
events: out.events,
|
|
147
|
+
components: [...out.components].sort(),
|
|
148
|
+
candidates: [...out.candidates].sort(),
|
|
149
|
+
diagnostics: out.diagnostics,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ---------------------------------------------------------------- 主函数
|
|
154
|
+
|
|
155
|
+
export function compileStandardCrud(input: KitBizInput, ctx: KitBizContext): KitFragment {
|
|
156
|
+
const CREATE_COPY = kitText('soma.kit.create', undefined, ctx.locale);
|
|
157
|
+
const EDIT_COPY = kitText('soma.kit.edit', undefined, ctx.locale);
|
|
158
|
+
const CLOSE_LABEL = kitText('soma.kit.close', undefined, ctx.locale);
|
|
159
|
+
const CANCEL_LABEL = kitText('soma.kit.cancel', undefined, ctx.locale);
|
|
160
|
+
const out: Parts = {
|
|
161
|
+
show: {}, data: {}, scopes: {}, events: {},
|
|
162
|
+
components: new Set<string>(['Button', 'KitCrudBridge']),
|
|
163
|
+
candidates: new Set<string>(),
|
|
164
|
+
diagnostics: [],
|
|
165
|
+
};
|
|
166
|
+
const fail = (code: string, message: string, path: string): void => { out.diagnostics.push({ code, message, path }); };
|
|
167
|
+
|
|
168
|
+
const rawEntity = input.objects.entity;
|
|
169
|
+
if (!isRec(rawEntity) || !isRec(rawEntity.schema) || !isRec(rawEntity.behavior)) {
|
|
170
|
+
fail('KIT-BIZ-001', 'StandardCrud 缺少必填对象角色槽 entity(需含 schema 与 behavior)', 'product.objects.entity');
|
|
171
|
+
return finish(out, '');
|
|
172
|
+
}
|
|
173
|
+
const entityRaw = rawEntity as unknown as KitObject;
|
|
174
|
+
const entity: KitObject = isRec(entityRaw.view) && isRec((entityRaw.view as Rec).list)
|
|
175
|
+
? { ...entityRaw, view: { ...entityRaw.view, list: normalizeList((entityRaw.view as Rec).list as KitViewForm & Rec) } }
|
|
176
|
+
: entityRaw;
|
|
177
|
+
for (const key of Object.keys(input.areaClass ?? {})) {
|
|
178
|
+
if (!(STANDARD_CRUD_AREAS as readonly string[]).includes(key)) {
|
|
179
|
+
fail('KIT-PAGE-001', `areaClass 里的区域名 "${key}" 不在 StandardCrud 的区域闭集 ${STANDARD_CRUD_AREAS.join(' / ')} 内`, `product.areaClass.${key}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const areaClass = input.areaClass ?? {};
|
|
183
|
+
|
|
184
|
+
const object = crudObjectName(ctx.pageId);
|
|
185
|
+
const scope = `${object}_scope`;
|
|
186
|
+
const keyField = keyFieldOf(entity);
|
|
187
|
+
const actions = entity.behavior.actions ?? [];
|
|
188
|
+
|
|
189
|
+
const hasList = entity.view?.list !== undefined;
|
|
190
|
+
const hasForm = entity.view?.form !== undefined;
|
|
191
|
+
if (!hasList) fail('KIT-BIZ-001', 'StandardCrud 的 entity 必须有 list 视图(主列表)', 'product.objects.entity.view.list');
|
|
192
|
+
if (actions.some((a) => a.builtin === 'openCreate' || a.builtin === 'openEdit') && !hasForm) {
|
|
193
|
+
fail('KIT-BIZ-001', 'entity 声明了 openCreate / openEdit 动作,但没有 form 视图', 'product.objects.entity.view.form');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const overlays = input.overlays ?? {};
|
|
197
|
+
for (const name of Object.keys(overlays)) {
|
|
198
|
+
if (!IDENT.test(name)) fail('KIT-PAGE-001', `附加浮层名 "${name}" 必须是标识符(字母数字下划线)`, `product.overlays.${name}`);
|
|
199
|
+
else if (name === 'entity') fail('KIT-PAGE-001', '附加浮层名不能叫 entity(与主对象角色槽同名)', `product.overlays.${name}`);
|
|
200
|
+
}
|
|
201
|
+
// E3:只读浮层的 editOverlay 必须指向另一个存在的浮层(点「编辑」切过去,当前行保留)
|
|
202
|
+
const showEdit: Record<string, string> = {};
|
|
203
|
+
for (const [name, decl] of Object.entries(overlays)) {
|
|
204
|
+
if (decl.editOverlay === undefined) continue;
|
|
205
|
+
const at = `product.overlays.${name}.editOverlay`;
|
|
206
|
+
if (typeof decl.editOverlay !== 'string' || !(decl.editOverlay in overlays) || decl.editOverlay === name) {
|
|
207
|
+
fail('KIT-BIZ-003', `浮层 ${name} 的 editOverlay "${String(decl.editOverlay)}" 必须是另一个已声明的浮层名`, at);
|
|
208
|
+
} else {
|
|
209
|
+
showEdit[name] = decl.editOverlay;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// 整行点击:至多一个浮层写 rowClick: true;点行 / 行聚焦按 Enter 以当前行打开它
|
|
213
|
+
const rowClickNames = Object.entries(overlays).filter(([, d]) => d.rowClick !== undefined && d.rowClick !== false).map(([n]) => n);
|
|
214
|
+
for (const [name, decl] of Object.entries(overlays)) {
|
|
215
|
+
if (decl.rowClick !== undefined && typeof decl.rowClick !== 'boolean') fail('KIT-BIZ-003', `浮层 ${name} 的 rowClick 必须是布尔`, `product.overlays.${name}.rowClick`);
|
|
216
|
+
}
|
|
217
|
+
if (rowClickNames.length > 1) {
|
|
218
|
+
fail('KIT-BIZ-003', `rowClick 只能有一个浮层(现有:${rowClickNames.join(' / ')})`, `product.overlays.${rowClickNames[1]}.rowClick`);
|
|
219
|
+
}
|
|
220
|
+
const rowClickName = rowClickNames.length === 1 && hasList ? rowClickNames[0] : undefined;
|
|
221
|
+
if (rowClickNames.length === 1 && !hasList) fail('KIT-BIZ-003', 'rowClick 需要 entity 有 list 视图', `product.overlays.${rowClickNames[0]}.rowClick`);
|
|
222
|
+
actions.forEach((a, i) => {
|
|
223
|
+
const at = `product.objects.entity.behavior.actions[${i}]`;
|
|
224
|
+
if (a.builtin === 'openOverlay') {
|
|
225
|
+
if (a.on !== 'row') fail('KIT-EVT-001', `动作 ${a.id}:openOverlay 只能是行操作(要带当前行主键)`, at);
|
|
226
|
+
if (a.targetOverlay === undefined || !(a.targetOverlay in overlays)) {
|
|
227
|
+
fail('KIT-EVT-001', `动作 ${a.id} 的 targetOverlay "${a.targetOverlay ?? ''}" 不在 overlays 里`, `${at}.targetOverlay`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if ((a.builtin === 'openEdit' || a.builtin === 'remove') && a.on !== 'row') {
|
|
231
|
+
fail('KIT-EVT-001', `动作 ${a.id}:${a.builtin} 只能是行操作(要带当前行)`, at);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
if (out.diagnostics.length > 0) return finish(out, '');
|
|
235
|
+
|
|
236
|
+
// ---- 展开行子表(Q 波 G5):kind: expand 的附加对象不画浮层,由 entity 的 collection.expand.list 引用
|
|
237
|
+
const expandNames = new Set(Object.entries(overlays).filter(([, d]) => d.kind === 'expand').map(([n]) => n));
|
|
238
|
+
const listColl = isRec(entity.view) && isRec((entity.view as Rec).list) ? ((entity.view as Rec).list as Rec).collection : undefined;
|
|
239
|
+
const expandDecl = isRec(listColl) && isRec(listColl.expand) ? listColl.expand : undefined;
|
|
240
|
+
const expandRef = expandDecl !== undefined && typeof expandDecl.list === 'string' && typeof expandDecl.link === 'string' && expandNames.has(expandDecl.list)
|
|
241
|
+
? { list: expandDecl.list, link: expandDecl.link }
|
|
242
|
+
: undefined;
|
|
243
|
+
const expandMirrorPath = mirrorPath(scope, KIT_COORD_MIRRORS.expand.key);
|
|
244
|
+
let expandObject = '';
|
|
245
|
+
let expandHolder = '';
|
|
246
|
+
|
|
247
|
+
// ---- 主对象(只 emit 一次)
|
|
248
|
+
const entityEmit = labelDiagnostics(emitObject(
|
|
249
|
+
entity,
|
|
250
|
+
{ object, scope, registered: ctx.registeredComponents, staticComponents: ctx.staticComponents, expandHosts: expandNames, ...(ctx.locale !== undefined ? { locale: ctx.locale } : {}) },
|
|
251
|
+
{
|
|
252
|
+
registeredActions: ctx.registeredActions,
|
|
253
|
+
expandPath: expandMirrorPath,
|
|
254
|
+
formMode: 'create',
|
|
255
|
+
...(rowClickName !== undefined ? { pickOnRow: true } : {}),
|
|
256
|
+
// 弹窗表单的 mode / initial 绑 focus 镜像
|
|
257
|
+
formModePath: mirrorPath(scope, KIT_COORD_MIRRORS.mode.key),
|
|
258
|
+
formInitialPath: mirrorPath(scope, KIT_COORD_MIRRORS.row.key),
|
|
259
|
+
selectedPath: mirrorPath(scope, KIT_COORD_MIRRORS.sel.key),
|
|
260
|
+
},
|
|
261
|
+
), object);
|
|
262
|
+
addEmit(out, entityEmit);
|
|
263
|
+
|
|
264
|
+
// 弹窗表单的写入结果范围独立(不与筛选条串)
|
|
265
|
+
const formId = viewAnchor(object, 'form');
|
|
266
|
+
const m = KIT_COORD_MIRRORS;
|
|
267
|
+
const mirrors: SomaScopeMirrorDecl[] = (hasForm ? [m.openForm, m.creating, m.editing, m.mode, m.row, m.id, m.sel] : [m.row, m.id, m.sel])
|
|
268
|
+
.map((x) => ({ key: x.key, slice: 'focus', path: x.path, as: x.as }));
|
|
269
|
+
if (hasForm) {
|
|
270
|
+
patchProps(out.show, formId, {
|
|
271
|
+
scope: `${object}__form`,
|
|
272
|
+
cancelLabel: CANCEL_LABEL,
|
|
273
|
+
});
|
|
274
|
+
wireDialogForm(out.events, formId, scope);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// 工具栏:openCreate 改走语义事件
|
|
278
|
+
let createCopy = CREATE_COPY;
|
|
279
|
+
// GA5:带 prefill 的「新建」钮各占一个语义事件,协调组件按事件名查预填表(事件名 -> { 字段: $filter.x | 字面量 })
|
|
280
|
+
const createPrefills: Record<string, Record<string, unknown>> = {};
|
|
281
|
+
actions.forEach((a, i) => {
|
|
282
|
+
if (a.on !== 'toolbar') return;
|
|
283
|
+
const at = `behavior.actions[${i}]`;
|
|
284
|
+
const click = `${toolbarAnchor(object, a.id)}.click`;
|
|
285
|
+
if (a.builtin === 'openCreate') {
|
|
286
|
+
createCopy = a.name;
|
|
287
|
+
const prefill = prefillOf(a, new Set(Object.keys(entity.schema)), entity.view?.filter !== undefined, at, out.diagnostics);
|
|
288
|
+
if (prefill !== undefined && prefill !== null) createPrefills[createEventName(a)] = prefill;
|
|
289
|
+
out.events[click] = semanticPipe(scope, prefill === undefined || prefill === null ? KIT_COORD_EVENTS.openCreate : createEventName(a), pipeTails(a, at, out.diagnostics));
|
|
290
|
+
} else if (a.builtin === 'reload') {
|
|
291
|
+
out.events[click] = semanticPipe(scope, KIT_COORD_EVENTS.reload, pipeTails(a, at, out.diagnostics));
|
|
292
|
+
} else if (a.after === 'reload') {
|
|
293
|
+
// K-5:声明 after: reload 的工具栏动作,执行后经协调组件重取
|
|
294
|
+
const pipe = actionPipeline(a, at, { hasWrite: entity.behavior.write !== undefined, object, registeredActions: ctx.registeredActions }, []);
|
|
295
|
+
if (pipe !== null) out.events[click] ={ steps: actionSteps(pipe, [semanticPipe(scope, KIT_COORD_EVENTS.reload)]) };
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// 行操作:同一个实例,steps 按 kit_action 分流,尾段写在对应步骤上;事件整段重写
|
|
300
|
+
const listHtml = entityEmit.parts.list ?? '';
|
|
301
|
+
let editCopy = EDIT_COPY;
|
|
302
|
+
const rowActions = actions.filter((a) => a.on === 'row');
|
|
303
|
+
if (rowActions.length > 0 || rowClickName !== undefined) {
|
|
304
|
+
const rowsKey = rowsAnchor(object);
|
|
305
|
+
const ops = opsAnchor(object);
|
|
306
|
+
|
|
307
|
+
const nested: Rec = isRec(out.events[rowsKey]) ? { ...(out.events[rowsKey] as Rec) } : {};
|
|
308
|
+
// 只有行模板真的产出了操作列锚点(原事件表里有它)才写回;虚拟表 / 树表 / 看板 / 只配右键菜单的表没有这个节点,写了会在挂载期缺事件源
|
|
309
|
+
// 仅整行点击无行操作时事件表没有这一项,但 html 里补了无按钮的操作列实例,也要写(否则行点击接线丢失)
|
|
310
|
+
const hadRowOps = nested[`${ops}.row_action`] !== undefined || listHtml.includes(`data-soma-id="${ops}"`);
|
|
311
|
+
delete nested[`${ops}.row_action`];
|
|
312
|
+
for (const a of rowActions) if (a.builtin === 'openEdit') editCopy = a.name;
|
|
313
|
+
|
|
314
|
+
const steps: Array<Record<string, unknown>> = [];
|
|
315
|
+
for (const a of rowActions) {
|
|
316
|
+
const at = `behavior.actions.${a.id}`;
|
|
317
|
+
const when = rowActionGate(a);
|
|
318
|
+
const own = ownPipe(a, scope, at, out.diagnostics);
|
|
319
|
+
if (own !== null) {
|
|
320
|
+
steps.push({ when, do: own });
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
// 具名动作 / 其它内置:D 的管道串;诊断 emitObject 已报过一次,用一次性数组吞掉重复
|
|
324
|
+
const pipe = actionPipeline(a, at, { hasWrite: entity.behavior.write !== undefined, object, registeredActions: ctx.registeredActions }, []);
|
|
325
|
+
if (pipe !== null) {
|
|
326
|
+
steps.push({ when, do: pipe });
|
|
327
|
+
for (const p of actionThenPipes(a, scope)) steps.push({ when, do: p });
|
|
328
|
+
steps.push({ when, do: semanticPipe(scope, KIT_COORD_EVENTS.reload) });
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
// 整行点击:KitTableActions 的行点击抛 row_action(kit_action: select),这里接到打开浮层(协调组件按 overlayActions.select 反查目标)
|
|
332
|
+
if (rowClickName !== undefined) {
|
|
333
|
+
steps.push({ when: { field: 'kit_action', op: 'eq', value: 'select' }, do: semanticPipe(scope, KIT_COORD_EVENTS.openOverlay) });
|
|
334
|
+
}
|
|
335
|
+
if (hadRowOps && steps.length > 0) nested[`${ops}.row_action`] = { steps };
|
|
336
|
+
// 右键菜单(Q 波 G6)的 KitContextMenu 与行操作同载荷,沿用同一串改写后的步骤
|
|
337
|
+
if (steps.length > 0 && nested[`${ctxMenuAnchor(object)}.row_action`] !== undefined) nested[`${ctxMenuAnchor(object)}.row_action`] = { steps };
|
|
338
|
+
// 页面级表体(虚拟滚动 / 树表)与各右键菜单实例的事件不在 rowsKey 之下,同样改写(否则 openEdit 等内置动作在这些视图里不生效)
|
|
339
|
+
if (steps.length > 0) {
|
|
340
|
+
rewritePageLevelRowActions(out.events, [virtualAnchor(object), treeAnchor(object), ctxMenuAnchor(object), staticCtxAnchor(object, 'list'), staticCtxAnchor(object, 'summary')], steps);
|
|
341
|
+
}
|
|
342
|
+
if (Object.keys(nested).length > 0) out.events[rowsKey] = nested;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ---- 附加浮层
|
|
346
|
+
const overlayHtmls: string[] = [];
|
|
347
|
+
const overlayMirrors: SomaScopeMirrorDecl[] = [];
|
|
348
|
+
const overlayObjects: Record<string, string> = {};
|
|
349
|
+
for (const [name, decl] of Object.entries(overlays)) {
|
|
350
|
+
const at = `product.overlays.${name}`;
|
|
351
|
+
if (!IDENT.test(name)) continue;
|
|
352
|
+
if (decl.kind === 'expand') {
|
|
353
|
+
// 展开行子表的子对象:只读、平铺的 table / stack,关联参数 = 展开行主键的镜像(缺参 core 不取数)
|
|
354
|
+
if (expandRef === undefined || expandRef.list !== name) {
|
|
355
|
+
fail('KIT-TBL-003', `kind: expand 的对象 ${name} 没有被 entity 的 collection.expand 引用(须写 { list: ${name}, link: <读接口参数名> })`, at);
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const childView = normalizeOverlayView(decl.view);
|
|
359
|
+
if (childView === undefined) {
|
|
360
|
+
fail('KIT-BIZ-001', `展开子对象 ${name} 缺少 view`, `${at}.view`);
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
const childObject = `${ctx.pageId}_${name}`;
|
|
364
|
+
const childScope = `${childObject}_scope`;
|
|
365
|
+
const childObj: KitObject = {
|
|
366
|
+
schema: decl.schema ?? {},
|
|
367
|
+
behavior: {
|
|
368
|
+
...(decl.behavior ?? {}),
|
|
369
|
+
params: { ...(decl.behavior?.params ?? {}), [expandRef.link]: `$${expandMirrorPath}` },
|
|
370
|
+
requireParams: [...new Set([...(decl.behavior?.requireParams ?? []), expandRef.link])],
|
|
371
|
+
},
|
|
372
|
+
view: childView,
|
|
373
|
+
};
|
|
374
|
+
const childIssues = checkExpandChild(childObj, at);
|
|
375
|
+
if (childIssues.length > 0) {
|
|
376
|
+
out.diagnostics.push(...childIssues);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const childEmit = labelDiagnostics(emitObject(
|
|
380
|
+
childObj,
|
|
381
|
+
{ object: childObject, scope: childScope, registered: ctx.registeredComponents, staticComponents: ctx.staticComponents, ...(ctx.locale !== undefined ? { locale: ctx.locale } : {}) },
|
|
382
|
+
{ registeredActions: ctx.registeredActions },
|
|
383
|
+
), childObject);
|
|
384
|
+
addEmit(out, childEmit);
|
|
385
|
+
out.scopes[childScope] = withScopeParts(out.scopes[childScope], { id: childScope, object: childObject }, [], []);
|
|
386
|
+
expandObject = childObject;
|
|
387
|
+
expandHolder = expandHolderHtml(expandHostId(object, name), childEmit.html, '');
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const view = normalizeOverlayView(decl.view);
|
|
391
|
+
if (view === undefined) {
|
|
392
|
+
fail('KIT-BIZ-001', `附加浮层 ${name} 缺少 view`, `${at}.view`);
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
// 编辑详情(behavior.detail)与读通道(behavior.from)二选一:from 已是「按关联键取浮层对象」的读口
|
|
396
|
+
if (decl.behavior?.from !== undefined && decl.behavior?.detail !== undefined) {
|
|
397
|
+
fail('KIT-DET-001', `附加浮层 ${name} 同时写了 behavior.from 与 behavior.detail:二选一(from 已按关联键取浮层对象,detail 用于以当前行为初值的编辑表单)`, `${at}.behavior.detail`);
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
const ovObject = `${ctx.pageId}_${name}`;
|
|
401
|
+
const ovScope = `${ovObject}_scope`;
|
|
402
|
+
overlayObjects[name] = ovObject;
|
|
403
|
+
const linkKey = decl.behavior?.linkKey ?? keyField;
|
|
404
|
+
const params: Record<string, string> = { ...(decl.behavior?.params ?? {}) };
|
|
405
|
+
if (linkKey !== undefined && keyField !== undefined) params[linkKey] = `$${mirrorPath(scope, KIT_CRUD_LINK_KEY)}`;
|
|
406
|
+
const ovObj: KitObject = {
|
|
407
|
+
schema: decl.schema ?? {},
|
|
408
|
+
behavior: { ...(decl.behavior ?? {}), params },
|
|
409
|
+
view,
|
|
410
|
+
};
|
|
411
|
+
// K-9:浮层没有自己的读接口(无 behavior.from)时,当前行(协调组件 focus.row 的镜像)就是它的数据:
|
|
412
|
+
// 写死形状组件的 data、表单的 initial 都注入这一行,不必按主键回查
|
|
413
|
+
const rowPath = mirrorPath(scope, m.row.key);
|
|
414
|
+
const injectRow = decl.behavior?.from === undefined;
|
|
415
|
+
const ovEmit = labelDiagnostics(emitObject(
|
|
416
|
+
ovObj,
|
|
417
|
+
{ object: ovObject, scope: ovScope, registered: ctx.registeredComponents, staticComponents: ctx.staticComponents },
|
|
418
|
+
{ registeredActions: ctx.registeredActions, formMode: 'edit', ...(injectRow ? { summaryPath: rowPath } : {}) },
|
|
419
|
+
), ovObject);
|
|
420
|
+
addEmit(out, ovEmit);
|
|
421
|
+
if (decl.behavior?.from !== undefined) {
|
|
422
|
+
out.scopes[ovScope] = withScopeParts(out.scopes[ovScope], { id: ovScope, object: ovObject }, [], []);
|
|
423
|
+
}
|
|
424
|
+
// 浮层里的可编辑表单:编辑取回的单对象(或注入的当前行),保存后关窗并刷新
|
|
425
|
+
const ovFormId = viewAnchor(ovObject, 'form');
|
|
426
|
+
if (view.form !== undefined) {
|
|
427
|
+
patchProps(out.show, ovFormId, { mode: 'edit', initial: injectRow ? rowPath : `page.data.${ovObject}`, scope: `${ovObject}__form`, cancelLabel: CANCEL_LABEL });
|
|
428
|
+
wireDialogForm(out.events, ovFormId, scope);
|
|
429
|
+
}
|
|
430
|
+
// K-1 / M1-3:浮层里的写死形状数据组件(应用组件)按约定抛 saved / cancel / close / reload,由协调组件接;
|
|
431
|
+
// overlays.<名>.events 可再把自定义事件名映射到这四种之一。组件没抛的事件不会触发(core 对未声明的 emit 选择器惰性)
|
|
432
|
+
for (const slot of ['list', 'summary'] as const) {
|
|
433
|
+
const staticComp = view[slot]?.staticComponent;
|
|
434
|
+
if (staticComp === undefined) continue;
|
|
435
|
+
const knownEmits = ctx.staticComponents[staticComp]?.emits;
|
|
436
|
+
const explicitEvents = decl.events ?? {};
|
|
437
|
+
const anchor = viewAnchor(ovObject, slot);
|
|
438
|
+
// 接了具名动作的事件:编完后自动带上该动作的 busy 绑定(手写 busy_action 优先)
|
|
439
|
+
const namedOn: Record<string, string> = {};
|
|
440
|
+
for (const [emitName, role] of Object.entries<string | KitOverlayEventAction>({ ...OVERLAY_EVENT_ROLES, ...explicitEvents })) {
|
|
441
|
+
if (!(emitName in explicitEvents) && knownEmits !== undefined && !knownEmits.includes(emitName)) continue;
|
|
442
|
+
if (typeof role !== 'string') {
|
|
443
|
+
// M1-5:{ action, then }——先执行具名动作,成功后再走 then(缺省不追加)
|
|
444
|
+
const epath = `${at}.events.${emitName}`;
|
|
445
|
+
if (!isRec(role) || typeof role.action !== 'string' || role.action === '') {
|
|
446
|
+
fail('KIT-EVT-001', `附加浮层 ${name} 的 events.${emitName} 必须是角色名或 { action, then }`, epath);
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
// action 可以是主对象 behavior.actions 里的 request / download 动作 id(声明式请求,交页面级 KitActionHost),否则必须是登记的具名动作
|
|
450
|
+
const declared = actions.find((a) => a.id === role.action && isRequestLikeAction(a));
|
|
451
|
+
let actionPipe = `ACTION | ${role.action}`;
|
|
452
|
+
if (declared !== undefined) {
|
|
453
|
+
// 请求由宿主异步执行:then(关窗)必须等请求成功才做,由宿主在成功后关窗,这里不再追加 then 步骤(失败时窗口保留,编辑不丢)
|
|
454
|
+
const registered = registerRequestAction(declared, object, `${epath}.action`, out.diagnostics, { closeOnSuccess: role.then !== undefined });
|
|
455
|
+
if (registered === null) continue;
|
|
456
|
+
actionPipe = registered;
|
|
457
|
+
} else if (!ctx.registeredActions.has(role.action)) {
|
|
458
|
+
fail('KIT-EVT-001', `附加浮层 ${name} 的 events.${emitName}.action "${role.action}" 未在应用的具名动作中登记`, `${epath}.action`);
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
const thenSem = role.then === undefined ? undefined : OVERLAY_ROLE_SEMANTIC[role.then];
|
|
462
|
+
if (role.then !== undefined && thenSem === undefined) {
|
|
463
|
+
fail('KIT-EVT-001', `附加浮层 ${name} 的 events.${emitName}.then = "${String(role.then)}" 不在 ${Object.keys(OVERLAY_ROLE_SEMANTIC).join(' / ')} 内`, `${epath}.then`);
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
const steps: Array<{ do: string }> = [{ do: actionPipe }];
|
|
467
|
+
if (thenSem !== undefined && declared === undefined) steps.push({ do: semanticPipe(scope, thenSem) });
|
|
468
|
+
out.events[`${anchor}.${emitName}`] = { steps };
|
|
469
|
+
namedOn[emitName] = role.action;
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
const sem = OVERLAY_ROLE_SEMANTIC[role];
|
|
473
|
+
if (sem === undefined) {
|
|
474
|
+
fail('KIT-EVT-001', `附加浮层 ${name} 的 events.${emitName} = "${role}" 不在 ${Object.keys(OVERLAY_ROLE_SEMANTIC).join(' / ')} 内`, `${at}.events.${emitName}`);
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
out.events[`${anchor}.${emitName}`] = semanticPipe(scope, sem);
|
|
478
|
+
}
|
|
479
|
+
const busyNames = busyActionOf(view[slot]!.staticComponent!, namedOn);
|
|
480
|
+
const shown = out.show[anchor];
|
|
481
|
+
if (busyNames !== null && isRec(shown) && isRec(shown.props) && shown.props.busy_action === undefined) {
|
|
482
|
+
patchProps(out.show, anchor, { busy_action: busyNames });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
const ids = overlayIds(object, name);
|
|
486
|
+
overlayMirrors.push({ key: overlayMirrorKey(name), slice: 'focus', path: `ov.${name}`, as: 'truthy' });
|
|
487
|
+
out.show[ids.layer] = { when: mirrorPath(scope, overlayMirrorKey(name)) };
|
|
488
|
+
out.events[`${ids.close}.click`] = semanticPipe(scope, KIT_COORD_EVENTS.close);
|
|
489
|
+
const withEdit = name in showEdit;
|
|
490
|
+
if (withEdit) {
|
|
491
|
+
out.show[ids.edit] = { props: { label: EDIT_COPY, variant: 'neutral', size: 'sm' } };
|
|
492
|
+
out.events[`${ids.edit}.click`] = semanticPipe(scope, KIT_COORD_EVENTS.showEdit);
|
|
493
|
+
}
|
|
494
|
+
overlayHtmls.push(overlayHtml(ids, decl.kind, decl.title ?? name, ovEmit.html, decl.class, areaClass, withEdit, CLOSE_LABEL));
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// 主对象作用域:补 focus 切片(owner 是协调组件)与镜像
|
|
498
|
+
const linkMirror: SomaScopeMirrorDecl[] = keyField !== undefined && Object.keys(overlayObjects).length > 0
|
|
499
|
+
? [{ key: KIT_CRUD_LINK_KEY, slice: 'focus', path: `row.${keyField}`, as: 'value' }]
|
|
500
|
+
: [];
|
|
501
|
+
out.scopes[scope] = withScopeParts(
|
|
502
|
+
out.scopes[scope],
|
|
503
|
+
{ id: scope, object },
|
|
504
|
+
[{ name: 'focus', owner: coordinatorId(object) }],
|
|
505
|
+
[...mirrors, ...overlayMirrors, ...linkMirror, ...(expandObject !== '' ? [{ key: KIT_COORD_MIRRORS.expand.key, slice: 'focus' as const, path: KIT_COORD_MIRRORS.expand.path, as: KIT_COORD_MIRRORS.expand.as }] : [])],
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
// ---- 壳
|
|
509
|
+
const removeConfirms: Record<string, string> = Object.fromEntries(
|
|
510
|
+
actions
|
|
511
|
+
.filter((a) => a.builtin === 'remove' && a.confirm !== undefined && removeConfirmPlaceholders(a.confirm).length > 0)
|
|
512
|
+
.map((a) => [a.id, a.confirm as string]),
|
|
513
|
+
);
|
|
514
|
+
out.show[coordinatorId(object)] = {
|
|
515
|
+
props: {
|
|
516
|
+
scope, object, keyField: keyField ?? '', reloads: [], overlays: overlayObjects, showEdit, ...(expandObject !== '' ? { expandObject } : {}),
|
|
517
|
+
// 带行占位的删除确认:动作 id -> 确认文案模板(运行期按被删行插值)
|
|
518
|
+
...(Object.keys(removeConfirms).length > 0 ? { removeConfirms } : {}),
|
|
519
|
+
...(Object.keys(createPrefills).length > 0 ? { createPrefills } : {}),
|
|
520
|
+
overlayActions: {
|
|
521
|
+
...Object.fromEntries(actions.filter((a) => a.builtin === 'openOverlay' && a.targetOverlay !== undefined).map((a) => [a.id, a.targetOverlay as string])),
|
|
522
|
+
...(rowClickName !== undefined ? { select: rowClickName } : {}),
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
// W1-1:没有 form 视图就没有新增 / 编辑弹窗——不发射弹窗节点与它的显隐 / 关闭事件
|
|
527
|
+
const ids = dialogIds(object);
|
|
528
|
+
let dialog = '';
|
|
529
|
+
if (hasForm) {
|
|
530
|
+
out.show[ids.dialogLayer] = { when: mirrorPath(scope, m.openForm.key) };
|
|
531
|
+
out.show[ids.dialogTitleCreate] = { when: mirrorPath(scope, m.creating.key) };
|
|
532
|
+
out.show[ids.dialogTitleEdit] = { when: mirrorPath(scope, m.editing.key) };
|
|
533
|
+
out.events[`${ids.dialogClose}.click`] = semanticPipe(scope, KIT_COORD_EVENTS.close);
|
|
534
|
+
// K-7:form 视图的 title(字符串两态通用,或 { create, edit })覆写弹窗标题;缺省取动作名
|
|
535
|
+
const titles = dialogTitles((entity.view?.form as KitViewForm | undefined)?.title, { create: createCopy, edit: editCopy });
|
|
536
|
+
dialog = dialogHtml(ids, titles, entityEmit.parts.form ?? '', areaClass, CLOSE_LABEL);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const main = mainHtml({ filter: entityEmit.parts.filter ?? '', toolbar: entityEmit.parts.toolbar ?? '', list: listHtml }, areaClass);
|
|
540
|
+
const html = rootHtml(object, [main, coordinatorHtml(object), dialog, ...overlayHtmls, expandHolder], areaClass, input.class);
|
|
541
|
+
|
|
542
|
+
for (const c of classesIn(html)) out.candidates.add(c);
|
|
543
|
+
for (const c of Object.values(CRUD_CLASS)) for (const t of c.split(/\s+/)) if (t !== '') out.candidates.add(t);
|
|
544
|
+
|
|
545
|
+
return finish(out, html);
|
|
546
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// StandardCrud:标准单实体增删改查业务组件(规格 5.3)。
|
|
2
|
+
// 对象角色槽:entity(必填:filter / list / form 三态);overlays.*(可选:行级触发的附加关联对象,由 product.overlays 传入)。
|
|
3
|
+
|
|
4
|
+
import { defineKitBizComponent } from '../define';
|
|
5
|
+
import { compileStandardCrud } from './compile';
|
|
6
|
+
import { STANDARD_CRUD_AREAS } from './shell';
|
|
7
|
+
|
|
8
|
+
export const StandardCrud = defineKitBizComponent({
|
|
9
|
+
kind: 'StandardCrud',
|
|
10
|
+
roles: {
|
|
11
|
+
entity: { required: true, views: ['filter', 'list', 'form'] },
|
|
12
|
+
},
|
|
13
|
+
areas: [...STANDARD_CRUD_AREAS],
|
|
14
|
+
compile: compileStandardCrud,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export { compileStandardCrud, crudObjectName, KIT_CRUD_LINK_KEY } from './compile';
|
|
18
|
+
export { STANDARD_CRUD_AREAS, CRUD_CLASS } from './shell';
|