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.
- package/README.md +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/data/prompt-dialog.ts +0 -235
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
|
@@ -3,32 +3,31 @@
|
|
|
3
3
|
// 一页一个,由 compile-page 在页面里存在 request / download 动作时补进来,持有语义作用域 kit_act。
|
|
4
4
|
// 动作按钮 / 行操作 / 右键菜单的事件是 `SCOPE | semantic | kit_act | rq_<对象>_<动作>`(confirm / permission 尾段由 core 先裁决),
|
|
5
5
|
// 本组件按事件名查 props.requests 里的配置:
|
|
6
|
-
// · request
|
|
6
|
+
// · request:经 `services.data.dispatch('data.submit', …)` 走 core 内置动作发请求(页面声明不带请求体,载荷由业务对象 / 具名动作 / 接口一侧提供)
|
|
7
7
|
// (合成的只写对象在页面 data 段声明,接口与方法写在它的 write 里)。写入结果(pending / saved / failed、响应体、失败文案)
|
|
8
8
|
// 落 core 的 write-outcome-store,范围名 = into(缺省合成对象名);组件用 outcome prop 订阅(见 outcome-watch.ts)。
|
|
9
9
|
// 本组件自己不 fetch、不直调写接口。失败弹 danger 提示,成功按配置弹提示并刷新。
|
|
10
10
|
// · download:浏览器原生下载——GET 用 `<a href download>`,POST 用提交到隐藏窗体的表单;不走 fetch。
|
|
11
11
|
// 同一动作进行中再次触发被忽略(防重复提交),并登记到 base/action-busy(带 busy_action 的组件可禁用触发钮)。
|
|
12
12
|
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
// 页面不留编排:这里没有「计划」「路由」「步骤」。请求完成后要做的事(自定义提示、跳转、只重取某个对象)归展示对象:
|
|
14
|
+
// ctx.onRequestDone(into, fn) / ctx.onOutcome 里用 async/await 与 ctx 写。本组件只保留写死的固定协作——
|
|
15
|
+
// 写操作请求成功后重取主对象与附带对象(read: true 的只读请求不重取)、overlay 事件绑的请求成功后关掉该浮层;
|
|
16
|
+
// 另外订阅筛选条的 filter 切片,变更后等一拍重取(watches,见 object-renderer/filter-reload.ts)。
|
|
17
|
+
//
|
|
18
|
+
import type { SomaComponentDefinition, SomaDataPort, SomaRegionPort } from 'soma-core';
|
|
18
19
|
import { interpolate } from 'soma-core/i18n';
|
|
20
|
+
import { createKitController } from '../../base/shared';
|
|
19
21
|
import { beginKitAction, registerKitCancel } from '../../base/action-busy';
|
|
20
22
|
import { publishKitActionStatus, type KitActionStatusPhase } from '../../base/action-status';
|
|
21
23
|
import { OUTCOME_KEY_SEP, outcomeScopeOf } from '../../base/action-gate';
|
|
22
24
|
import { safeHref } from '../../base/link';
|
|
23
25
|
import { closeKitHub, hasKitHub, kitActionExtras } from './runtime-hub';
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import { setKitAppEnvelope, getKitAppEnvelope, resolveEnvelopeSubPath, type KitEnvelope } from '../../app/envelope';
|
|
27
|
-
import { draftFieldsOfBody, recordKitOutcomeDraft } from '../../object-renderer/outcome-draft';
|
|
26
|
+
import type { KitSliceReload } from '../../object-renderer/filter-reload';
|
|
27
|
+
import { getKitAppEnvelope, registerKitHostEnvelope, resolveEnvelopeSubPath, type KitEnvelope } from '../../shared/envelope';
|
|
28
28
|
import { kitText } from '../../i18n/kit-text';
|
|
29
29
|
import { KIT_GRAMMAR } from '../../object-renderer/defaults';
|
|
30
|
-
import type
|
|
31
|
-
import { invalidateKitOptions } from '../../data/options-bus';
|
|
30
|
+
import { buildRequestPayload, type KitRequestSpec } from '../../object-renderer/request-actions';
|
|
32
31
|
|
|
33
32
|
/** 自动触发(挂载 / 字段变化)的事件载荷标记键:带它的触发遇上一次还在途时只保留最新一次,上一次的结果丢弃 */
|
|
34
33
|
const AUTO_KEY: string = (KIT_GRAMMAR.requestAction as { autoPayloadKey: string }).autoPayloadKey;
|
|
@@ -37,35 +36,11 @@ const rec = (v: unknown): Record<string, unknown> => (v !== null && typeof v ===
|
|
|
37
36
|
const ACT_SCOPE: string = (KIT_GRAMMAR.requestAction as { scopeId: string }).scopeId;
|
|
38
37
|
const HOST_NAME: string = (KIT_GRAMMAR.requestAction as { hostComponent: string }).hostComponent;
|
|
39
38
|
|
|
39
|
+
/** 状态行插值与按行分槽取行键用的语境:触发这次动作的行、协调组件当前行、当前可见表单的草稿 */
|
|
40
40
|
interface ResolveContext {
|
|
41
41
|
row: Record<string, unknown>;
|
|
42
42
|
focus: Record<string, unknown>;
|
|
43
|
-
filter: Record<string, unknown>;
|
|
44
|
-
page: Record<string, unknown>;
|
|
45
|
-
value: unknown;
|
|
46
|
-
selected: Array<Record<string, unknown>>;
|
|
47
|
-
/** 当前可见表单里尚未提交的草稿值($draft.*;data/form-draft-registry) */
|
|
48
43
|
draft?: Record<string, unknown>;
|
|
49
|
-
/** 数据对象的读态($loaded.<对象>.<路径>;版本锁用:取页面加载 / 最近一次重取时读到的值,不是点击时再去服务端读) */
|
|
50
|
-
loaded?: (object: string) => unknown;
|
|
51
|
-
/** StepForm 各步已确认的值 { s<i>: { 字段: 值 } }($steps.s<i>.<字段>;GB1,编译器把步骤名改写成序号) */
|
|
52
|
-
steps?: Record<string, unknown>;
|
|
53
|
-
/** 触发这次动作的组件事件的整个载荷($event.*;GA1:view.on 把组件事件接到 request / download 动作) */
|
|
54
|
-
event?: Record<string, unknown>;
|
|
55
|
-
/** 请求前输入表单里用户填的值($prompt.<name>;GA4) */
|
|
56
|
-
prompt?: Record<string, unknown>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** body / query 里引用了 `$loaded.*` 却取不到值的引用(版本锁缺值时必须拒绝发出,不能静默省略) */
|
|
60
|
-
export function unresolvedLoaded(map: Record<string, unknown> | undefined, ctx: ResolveContext): string[] {
|
|
61
|
-
const out: string[] = [];
|
|
62
|
-
if (map === undefined) return out;
|
|
63
|
-
for (const raw of Object.values(map)) {
|
|
64
|
-
if (typeof raw !== 'string' || !raw.startsWith('$loaded.')) continue;
|
|
65
|
-
const v = resolveBinding(raw, ctx);
|
|
66
|
-
if (v === undefined || v === null || v === '') out.push(raw);
|
|
67
|
-
}
|
|
68
|
-
return out;
|
|
69
44
|
}
|
|
70
45
|
|
|
71
46
|
/** 页头状态行的插值参数:行 -> 草稿 -> 协调组件当前行 的顺序取标量字段(先到先得,不引表达式) */
|
|
@@ -103,54 +78,15 @@ function walk(root: unknown, path: string[]): unknown {
|
|
|
103
78
|
return cur;
|
|
104
79
|
}
|
|
105
80
|
|
|
106
|
-
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const root = parts[0]!;
|
|
110
|
-
const rest = parts.slice(1);
|
|
111
|
-
switch (root) {
|
|
112
|
-
case 'row': return walk(ctx.row, rest);
|
|
113
|
-
case 'focus': return walk(ctx.focus, rest);
|
|
114
|
-
case 'filter': return walk(ctx.filter, rest);
|
|
115
|
-
case 'page': return walk(ctx.page, rest);
|
|
116
|
-
case 'value': return walk(ctx.value, rest);
|
|
117
|
-
case 'selected': return rest.length === 0 ? ctx.selected : ctx.selected.map((r) => walk(r, rest));
|
|
118
|
-
case 'draft': return walk(ctx.draft ?? {}, rest);
|
|
119
|
-
case 'steps': return walk(ctx.steps ?? {}, rest);
|
|
120
|
-
case 'event': return walk(ctx.event ?? {}, rest);
|
|
121
|
-
case 'prompt': return walk(ctx.prompt ?? {}, rest);
|
|
122
|
-
case 'loaded': return rest.length < 2 || ctx.loaded === undefined ? undefined : walk(ctx.loaded(rest[0]!), rest.slice(1));
|
|
123
|
-
default: return undefined;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** body / query 的映射表 -> 具体对象:$ 开头取值,其余字面量;取不到值(undefined)的键不进对象 */
|
|
128
|
-
export function resolveBindingMap(map: Record<string, unknown> | undefined, ctx: ResolveContext): Record<string, unknown> {
|
|
129
|
-
const out: Record<string, unknown> = {};
|
|
130
|
-
if (map === undefined) return out;
|
|
131
|
-
for (const [key, raw] of Object.entries(map)) {
|
|
132
|
-
const v = typeof raw === 'string' && raw.startsWith('$') ? resolveBinding(raw, ctx) : raw;
|
|
133
|
-
if (v !== undefined) out[key] = v;
|
|
134
|
-
}
|
|
135
|
-
return out;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** GET 下载的地址:api + query(空值不带) */
|
|
139
|
-
export function downloadUrl(api: string, query: Record<string, unknown>): string {
|
|
140
|
-
const params = new URLSearchParams();
|
|
141
|
-
for (const [k, v] of Object.entries(query)) {
|
|
142
|
-
if (v === undefined || v === null || v === '') continue;
|
|
143
|
-
params.set(k, typeof v === 'object' ? JSON.stringify(v) : String(v));
|
|
144
|
-
}
|
|
145
|
-
const qs = params.toString();
|
|
146
|
-
if (qs === '') return api;
|
|
147
|
-
return `${api}${api.includes('?') ? '&' : '?'}${qs}`;
|
|
81
|
+
/** 按行分槽的行键值:into.key 是 `$row.<主键字段>`,取触发行的该字段 */
|
|
82
|
+
function rowKeyOf(key: string, ctx: ResolveContext): unknown {
|
|
83
|
+
return ctx.row[key.slice('$row.'.length)];
|
|
148
84
|
}
|
|
149
85
|
|
|
150
86
|
/** 浏览器原生下载:GET 点一个临时链接;POST 提交临时表单到隐藏窗体。无 DOM 返回 false */
|
|
151
|
-
function startDownload(spec: KitRequestSpec
|
|
87
|
+
function startDownload(spec: KitRequestSpec): boolean {
|
|
152
88
|
if (typeof document === 'undefined') return false;
|
|
153
|
-
const href = safeHref(spec.
|
|
89
|
+
const href = safeHref(spec.api);
|
|
154
90
|
if (href === '') return false;
|
|
155
91
|
if (spec.method === 'POST') {
|
|
156
92
|
const frame = document.createElement('iframe');
|
|
@@ -161,13 +97,6 @@ function startDownload(spec: KitRequestSpec, ctx: ResolveContext): boolean {
|
|
|
161
97
|
form.action = href;
|
|
162
98
|
form.target = frame.name;
|
|
163
99
|
form.hidden = true;
|
|
164
|
-
for (const [k, v] of Object.entries(resolveBindingMap(spec.body, ctx))) {
|
|
165
|
-
const input = document.createElement('input');
|
|
166
|
-
input.type = 'hidden';
|
|
167
|
-
input.name = k;
|
|
168
|
-
input.value = typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v);
|
|
169
|
-
form.appendChild(input);
|
|
170
|
-
}
|
|
171
100
|
document.body.appendChild(frame);
|
|
172
101
|
document.body.appendChild(form);
|
|
173
102
|
form.submit();
|
|
@@ -191,24 +120,28 @@ export function createKitActionHost(): SomaComponentDefinition {
|
|
|
191
120
|
layer: 'data',
|
|
192
121
|
props: {
|
|
193
122
|
scope: { type: 'string', default: ACT_SCOPE, desc: '语义作用域 id(恒为 kit_act)' },
|
|
194
|
-
envelope: { type: 'object', default: {}, desc: '业务信封约定 { failWhen?, messagePath?, dataPath? }(kit.app.yaml#envelope / page.envelope
|
|
123
|
+
envelope: { type: 'object', default: {}, desc: '业务信封约定 { failWhen?, messagePath?, dataPath? }(kit.app.yaml#envelope / page.envelope,编译器带入);挂载时登记在本宿主名下(卸载注销),本页面触发的具名动作的 http 同源读它' },
|
|
195
124
|
requests: { type: 'object', default: {}, desc: '语义事件名 -> request / download 配置(编译器生成,见 object-renderer/request-actions.ts)' },
|
|
125
|
+
watches: { type: 'array', default: [], desc: '筛选条提交后重取的登记 [{ scope, slice, reload: [{ scope, object? }] }](编译器生成,见 object-renderer/filter-reload.ts)' },
|
|
196
126
|
},
|
|
197
127
|
emits: {},
|
|
198
128
|
scope: { slices: ['results'] },
|
|
199
129
|
},
|
|
200
130
|
services: ['region', 'data', 'notify'],
|
|
201
131
|
templateHtml: '<div data-soma-id="root" class="hidden"></div>',
|
|
202
|
-
controllerFactory: (
|
|
132
|
+
controllerFactory: createKitController((api) => {
|
|
203
133
|
let off: (() => void) | undefined;
|
|
134
|
+
/** 本宿主登记的信封的注销函数(卸载时调用) */
|
|
135
|
+
let offEnvelope: (() => void) | undefined;
|
|
204
136
|
let alive = false;
|
|
137
|
+
const watchOffs: Array<() => void> = [];
|
|
205
138
|
const inflight = new Set<string>();
|
|
206
139
|
/** 自动触发排队:在途期间到来的最新一次(每个动作 / 行只留一条) */
|
|
207
140
|
const queued = new Map<string, { name: string; payload: Readonly<Record<string, unknown>> }>();
|
|
208
141
|
/** 在途请求的取消控制器(按动作 + 行):被更新的自动触发顶替时真正中止网络请求 */
|
|
209
142
|
const aborts = new Map<string, AbortController>();
|
|
210
|
-
const props = (): Record<string, unknown> =>
|
|
211
|
-
const svc =
|
|
143
|
+
const props = (): Record<string, unknown> => api.props();
|
|
144
|
+
const svc = api.services as {
|
|
212
145
|
region?: (id: string) => SomaRegionPort | null;
|
|
213
146
|
data?: SomaDataPort;
|
|
214
147
|
notify?: { toast?: (o: { level: string; message: string }) => void };
|
|
@@ -217,82 +150,38 @@ export function createKitActionHost(): SomaComponentDefinition {
|
|
|
217
150
|
if (message !== '') svc?.notify?.toast?.({ level, message });
|
|
218
151
|
};
|
|
219
152
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (!data) return undefined;
|
|
224
|
-
const direct = data.getObject(name);
|
|
225
|
-
if (direct !== undefined) return direct;
|
|
226
|
-
const cut = hint.lastIndexOf('_');
|
|
227
|
-
return cut > 0 ? data.getObject(`${hint.slice(0, cut)}_${name}`) : undefined;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
const contextOf = (payload: Readonly<Record<string, unknown>>, prompt?: Record<string, unknown>): ResolveContext => {
|
|
231
|
-
const extras = kitActionExtras();
|
|
232
|
-
return {
|
|
233
|
-
event: { ...payload },
|
|
234
|
-
...(prompt !== undefined ? { prompt } : {}),
|
|
235
|
-
row: rec(payload.row),
|
|
236
|
-
focus: extras.focusRow(),
|
|
237
|
-
filter: extras.filter(),
|
|
238
|
-
page: { ...extras.page() },
|
|
239
|
-
value: payload.value,
|
|
240
|
-
selected: extras.selected,
|
|
241
|
-
draft: extras.draft(),
|
|
242
|
-
steps: readKitStepValues(),
|
|
243
|
-
loaded: loadedReader(''),
|
|
244
|
-
};
|
|
153
|
+
const contextOf = (spec: KitRequestSpec, payload: Readonly<Record<string, unknown>>): ResolveContext => {
|
|
154
|
+
const extras = kitActionExtras(spec.object);
|
|
155
|
+
return { row: rec(payload.row), focus: extras.focusRow(), draft: extras.draft() };
|
|
245
156
|
};
|
|
246
157
|
|
|
247
158
|
const reload = async (object: string): Promise<void> => {
|
|
248
|
-
if (hasKitHub()) await kitActionExtras().reload();
|
|
159
|
+
if (hasKitHub(object)) await kitActionExtras(object).reload(object);
|
|
249
160
|
else if (object !== '') await svc?.data?.reload([object]);
|
|
250
161
|
};
|
|
251
162
|
|
|
252
|
-
/** H1b / H1c:request.then 数组项——按成败筛选后依次重取(true = 主对象与附带对象 / 数据对象名 / /接口路径的选项候选) */
|
|
253
|
-
const runThenItems = async (spec: KitRequestSpec, succeeded: boolean): Promise<void> => {
|
|
254
|
-
for (const it of spec.thenItems ?? []) {
|
|
255
|
-
if (it.on === 'success' && !succeeded) continue;
|
|
256
|
-
if (it.on === 'failed' && succeeded) continue;
|
|
257
|
-
try {
|
|
258
|
-
if (it.reload === true) await reload(spec.object);
|
|
259
|
-
else if (it.reload.startsWith('/')) invalidateKitOptions(it.reload);
|
|
260
|
-
else await svc?.data?.reload([it.reload]);
|
|
261
|
-
} catch (error) {
|
|
262
|
-
console.error('[soma-kit] 请求后续重取失败', error);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
163
|
/** 页头状态行:把一次请求的阶段发给 base/action-status(订阅者是 KitPageStatus;没人听无副作用) */
|
|
268
164
|
type StatusReport = (phase: KitActionStatusPhase, message?: string, params?: Record<string, string | number>) => void;
|
|
269
165
|
|
|
270
166
|
const runRequest = async (
|
|
271
|
-
spec: KitRequestSpec, payload: Readonly<Record<string, unknown>>,
|
|
167
|
+
spec: KitRequestSpec, payload: Readonly<Record<string, unknown>>, stale: () => boolean = () => false, signal?: AbortSignal,
|
|
272
168
|
report: StatusReport = () => undefined,
|
|
273
169
|
): Promise<void> => {
|
|
274
170
|
const data = svc?.data;
|
|
275
171
|
if (!data || spec.writeObject === undefined || spec.outcome === undefined) {
|
|
276
|
-
toast('danger', kitText('soma.kit.request_failed', undefined,
|
|
277
|
-
report('failed', kitText('soma.kit.request_failed', undefined,
|
|
172
|
+
toast('danger', kitText('soma.kit.request_failed', undefined, api.host));
|
|
173
|
+
report('failed', kitText('soma.kit.request_failed', undefined, api.host));
|
|
278
174
|
return;
|
|
279
175
|
}
|
|
280
|
-
const resolved = contextOf(
|
|
281
|
-
resolved.loaded = loadedReader(spec.object);
|
|
176
|
+
const resolved = contextOf(spec, payload);
|
|
282
177
|
const params = statusParamsOf(resolved);
|
|
283
|
-
// 版本锁:body 引用了 $loaded.* 却取不到值(对象还没读到 / 接口没带版本)-> 不发请求,如实提示,绝不悄悄去掉锁
|
|
284
|
-
if (unresolvedLoaded(spec.body, resolved).length > 0) {
|
|
285
|
-
toast('danger', kitText('soma.kit.version_missing', undefined, ctx.host));
|
|
286
|
-
report('failed', kitText('soma.kit.version_missing', undefined, ctx.host), params);
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
178
|
// 按行分槽(into: { name, key }):结果范围名 = 名字 + 本行主键值;取不到行键就不发(发了也没有槽可落,行内条件会读不到)
|
|
290
179
|
let outcomeScope: string = spec.outcome;
|
|
291
180
|
if (spec.outcomeKey !== undefined) {
|
|
292
|
-
const rowKey =
|
|
181
|
+
const rowKey = rowKeyOf(spec.outcomeKey, resolved);
|
|
293
182
|
if (rowKey === undefined || rowKey === null || rowKey === '') {
|
|
294
|
-
toast('danger', kitText('soma.kit.request_failed', undefined,
|
|
295
|
-
report('failed', kitText('soma.kit.request_failed', undefined,
|
|
183
|
+
toast('danger', kitText('soma.kit.request_failed', undefined, api.host));
|
|
184
|
+
report('failed', kitText('soma.kit.request_failed', undefined, api.host), params);
|
|
296
185
|
return;
|
|
297
186
|
}
|
|
298
187
|
outcomeScope = outcomeScopeOf(spec.outcome, String(rowKey));
|
|
@@ -303,7 +192,7 @@ export function createKitActionHost(): SomaComponentDefinition {
|
|
|
303
192
|
if (spec.splitBy !== undefined) {
|
|
304
193
|
outcomeScope = spec.writeObject;
|
|
305
194
|
const env = rec(props().envelope);
|
|
306
|
-
const dataPath = typeof env.dataPath === 'string' ? env.dataPath : getKitAppEnvelope()?.dataPath;
|
|
195
|
+
const dataPath = typeof env.dataPath === 'string' ? env.dataPath : getKitAppEnvelope(api.host)?.dataPath;
|
|
307
196
|
splitPath = resolveEnvelopeSubPath(spec.splitBy.path, dataPath);
|
|
308
197
|
split = {
|
|
309
198
|
path: splitPath, key: spec.splitBy.key, prefix: spec.outcome, separator: OUTCOME_KEY_SEP,
|
|
@@ -311,22 +200,19 @@ export function createKitActionHost(): SomaComponentDefinition {
|
|
|
311
200
|
...(typeof env.messagePath === 'string' ? { messagePath: env.messagePath } : {}),
|
|
312
201
|
};
|
|
313
202
|
}
|
|
314
|
-
const model = resolveBindingMap(spec.body, resolved);
|
|
315
|
-
// 请求读了 $draft:记下用到的草稿字段与当时的值,之后这些字段被改则该结果对闸门过期(object-form 对账)
|
|
316
|
-
recordKitOutcomeDraft(spec.outcome, draftFieldsOfBody(spec.body, rec(resolved.draft)));
|
|
317
203
|
try {
|
|
204
|
+
const model = buildRequestPayload(spec, [resolved.row, resolved.draft, resolved.focus, payload]);
|
|
318
205
|
await data.dispatch('data.submit', { object: spec.writeObject, scope: outcomeScope, model, mode: spec.mode ?? 'create', ...(split !== undefined ? { split } : {}), ...(signal !== undefined ? { options: { signal } } : {}) });
|
|
319
206
|
} catch (error) {
|
|
320
|
-
//
|
|
321
|
-
if (alive && !stale()) await runThenItems(spec, false);
|
|
207
|
+
// 抛错也算失败:错误继续上抛由 handle 提示
|
|
322
208
|
throw error;
|
|
323
209
|
}
|
|
324
210
|
// 自动触发被更新的一次顶替:网络请求已经中止(AbortController -> core 写通道 signal),这次的结果丢弃(不提示、不刷新)
|
|
325
211
|
if (!alive || stale()) return;
|
|
326
212
|
const view = data.writeOutcome(outcomeScope);
|
|
327
|
-
// 用户取消:不是失败也不是成功——只如实提示,不执行任何后续(
|
|
213
|
+
// 用户取消:不是失败也不是成功——只如实提示,不执行任何后续(notify / 刷新);写类请求说明服务端可能已处理
|
|
328
214
|
if (view.status === 'cancelled') {
|
|
329
|
-
toast('info', kitText(spec.read === true ? 'soma.kit.request_cancelled' : 'soma.kit.request_cancelled_write', undefined,
|
|
215
|
+
toast('info', kitText(spec.read === true ? 'soma.kit.request_cancelled' : 'soma.kit.request_cancelled_write', undefined, api.host));
|
|
330
216
|
report('cancelled', '', params);
|
|
331
217
|
return;
|
|
332
218
|
}
|
|
@@ -335,42 +221,28 @@ export function createKitActionHost(): SomaComponentDefinition {
|
|
|
335
221
|
// 拆分:响应体里取不到列表(接口形状不对)按请求失败,不假装拆出了结果
|
|
336
222
|
if (ok && spec.splitBy !== undefined && !Array.isArray(walk(rec(view.result).data, splitPath.split('.')))) {
|
|
337
223
|
ok = false;
|
|
338
|
-
message = kitText('soma.kit.request_failed', undefined,
|
|
224
|
+
message = kitText('soma.kit.request_failed', undefined, api.host);
|
|
339
225
|
}
|
|
340
226
|
// 版本冲突(409 / 412 / VERSION_CONFLICT):如实报「已被他人修改」,不当成普通失败,也不自动重取覆盖
|
|
341
|
-
if (view.status === 'conflict') message = kitText('soma.kit.form_conflict', undefined,
|
|
342
|
-
// 业务信封判定:HTTP 成功但信封说失败(如 success: false / ret != 0)按失败提示,不刷新
|
|
343
|
-
if (ok && spec.ok?.path !== undefined) {
|
|
344
|
-
const result = rec(view.result);
|
|
345
|
-
const path = spec.ok.path.split('.');
|
|
346
|
-
const got = walk(result.data, path);
|
|
347
|
-
const expected = 'equals' in spec.ok ? spec.ok.equals : true;
|
|
348
|
-
// 取不到值(响应不是信封形状)不判:HTTP 层的失败已由 core 写通道判过
|
|
349
|
-
if (got !== undefined && got !== expected) {
|
|
350
|
-
ok = false;
|
|
351
|
-
const m = spec.ok.message === undefined ? undefined : walk(result.data, spec.ok.message.split('.'));
|
|
352
|
-
message = typeof m === 'string' && m !== '' ? m : message;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
227
|
+
if (view.status === 'conflict') message = kitText('soma.kit.form_conflict', undefined, api.host);
|
|
355
228
|
if (!ok) {
|
|
356
|
-
toast('danger', message !== '' ? message : kitText('soma.kit.request_failed', undefined,
|
|
229
|
+
toast('danger', message !== '' ? message : kitText('soma.kit.request_failed', undefined, api.host));
|
|
357
230
|
report('failed', message, params);
|
|
358
|
-
await runThenItems(spec, false);
|
|
359
231
|
return;
|
|
360
232
|
}
|
|
361
233
|
// 请求已真实成功(信封也判过)才写成功状态,不乐观
|
|
362
234
|
report('ok', '', params);
|
|
363
235
|
if (spec.notify !== undefined) toast('success', spec.notify);
|
|
364
|
-
if (spec.closeOnSuccess === true) closeKitHub();
|
|
365
|
-
|
|
366
|
-
|
|
236
|
+
if (spec.closeOnSuccess === true) closeKitHub(spec.object);
|
|
237
|
+
// 固定协作:写操作成功后重取(只读请求不重取);别的后续事归展示对象(ctx.onRequestDone)
|
|
238
|
+
if (spec.read !== true) await reload(spec.object);
|
|
367
239
|
};
|
|
368
240
|
|
|
369
241
|
const handle = (name: string, payload: Readonly<Record<string, unknown>>): void => {
|
|
370
242
|
const spec = rec(props().requests)[name] as KitRequestSpec | undefined;
|
|
371
243
|
if (spec === undefined) return;
|
|
372
244
|
// 按行分槽的请求:防重复按「动作 + 行」算,一行在途不挡别的行
|
|
373
|
-
const rowPart = spec.kind === 'request' && spec.outcomeKey !== undefined ?
|
|
245
|
+
const rowPart = spec.kind === 'request' && spec.outcomeKey !== undefined ? rowKeyOf(spec.outcomeKey, contextOf(spec, payload)) : undefined;
|
|
374
246
|
const flight = rowPart === undefined || rowPart === null ? name : `${name}|${String(rowPart)}`;
|
|
375
247
|
if (inflight.has(flight)) {
|
|
376
248
|
// 自动触发(挂载 / 字段变化):上一次还在途,只留最新一次,在途的结束后再发它(在途那次的结果已被标为过期)
|
|
@@ -381,7 +253,7 @@ export function createKitActionHost(): SomaComponentDefinition {
|
|
|
381
253
|
return;
|
|
382
254
|
}
|
|
383
255
|
inflight.add(flight);
|
|
384
|
-
const start = (
|
|
256
|
+
const start = (): void => {
|
|
385
257
|
const controller = new AbortController();
|
|
386
258
|
// request.cancelable:在途期间登记取消函数(早于忙标记,忙闲通知时按钮已能查到「可取消」)
|
|
387
259
|
// 行级动作另按 `动作#行键` 登记一份(与 into 分槽键一致):行内按钮可只取消 / 只看自己这一行;动作名那份仍是「任一行在途」
|
|
@@ -403,7 +275,7 @@ export function createKitActionHost(): SomaComponentDefinition {
|
|
|
403
275
|
}
|
|
404
276
|
};
|
|
405
277
|
if (spec.kind === 'download') {
|
|
406
|
-
if (!startDownload(spec
|
|
278
|
+
if (!startDownload(spec)) toast('danger', kitText('soma.kit.download_failed', undefined, api.host));
|
|
407
279
|
done();
|
|
408
280
|
return;
|
|
409
281
|
}
|
|
@@ -414,59 +286,67 @@ export function createKitActionHost(): SomaComponentDefinition {
|
|
|
414
286
|
const report: StatusReport = (phase, message = '', params = {}) => {
|
|
415
287
|
if (quiet || !alive) return;
|
|
416
288
|
reported = true;
|
|
417
|
-
publishKitActionStatus({ actionId: spec.actionId, phase, text: actionStatusText(spec, phase, params, message,
|
|
289
|
+
publishKitActionStatus({ actionId: spec.actionId, phase, text: actionStatusText(spec, phase, params, message, api.host) });
|
|
418
290
|
};
|
|
419
|
-
if (!quiet) publishKitActionStatus({ actionId: spec.actionId, phase: 'busy', text: actionStatusText(spec, 'busy', {}, '',
|
|
420
|
-
void runRequest(spec, payload,
|
|
291
|
+
if (!quiet) publishKitActionStatus({ actionId: spec.actionId, phase: 'busy', text: actionStatusText(spec, 'busy', {}, '', api.host) });
|
|
292
|
+
void runRequest(spec, payload, () => queued.has(flight), controller.signal, report).catch((error: unknown) => {
|
|
421
293
|
console.error('[soma-kit] 声明式请求失败', error);
|
|
422
294
|
if (queued.has(flight)) return;
|
|
423
|
-
const text = error instanceof Error && error.message !== '' ? error.message : kitText('soma.kit.request_failed', undefined,
|
|
295
|
+
const text = error instanceof Error && error.message !== '' ? error.message : kitText('soma.kit.request_failed', undefined, api.host);
|
|
424
296
|
if (!reported) report('failed', text);
|
|
425
297
|
toast('danger', text);
|
|
426
298
|
}).finally(done);
|
|
427
299
|
};
|
|
428
|
-
// GA4 请求前输入:先弹自绘输入表单(取消 / Esc = 不发请求);进行中标记从确认后才开始,弹窗期间只防重复弹
|
|
429
|
-
if (spec.kind === 'request' && spec.prompt !== undefined) {
|
|
430
|
-
const base = contextOf(payload);
|
|
431
|
-
const defaults: Record<string, unknown> = {};
|
|
432
|
-
for (const f of spec.prompt.fields) {
|
|
433
|
-
const d = f.default;
|
|
434
|
-
defaults[f.name] = typeof d === 'string' && d.startsWith('$') ? resolveBinding(d, base) : d;
|
|
435
|
-
}
|
|
436
|
-
void askKitPrompt({ ...spec.prompt, defaults, at: ctx.host ?? null }).then((values) => {
|
|
437
|
-
if (!alive || values === null) { inflight.delete(flight); return; }
|
|
438
|
-
start(values);
|
|
439
|
-
});
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
300
|
start();
|
|
443
301
|
};
|
|
444
302
|
|
|
445
303
|
return {
|
|
446
|
-
|
|
304
|
+
attach() {
|
|
447
305
|
alive = true;
|
|
448
|
-
// 浏览器里应用具名动作的 http
|
|
306
|
+
// 浏览器里应用具名动作的 http 与此同源读信封约定:页面级宿主把编译期的有效信封登记在「本宿主」名下(不写全局),
|
|
307
|
+
// 动作按触发元素所属页面找到它;空对象(页面与应用都没声明信封)不登记,免得遮住应用级缺省。卸载即注销
|
|
449
308
|
const envelope = props().envelope;
|
|
450
|
-
if (envelope !== undefined && typeof envelope === 'object' && envelope !== null
|
|
309
|
+
if (envelope !== undefined && typeof envelope === 'object' && envelope !== null && Object.keys(envelope).length > 0 && api.host) {
|
|
310
|
+
offEnvelope = registerKitHostEnvelope(api.host, envelope as KitEnvelope);
|
|
311
|
+
}
|
|
451
312
|
const scope = typeof props().scope === 'string' && props().scope !== '' ? (props().scope as string) : ACT_SCOPE;
|
|
452
313
|
const port = typeof svc?.region === 'function' ? svc.region(scope) : null;
|
|
453
|
-
if (!port) return;
|
|
314
|
+
if (!port) return () => { alive = false; offEnvelope?.(); offEnvelope = undefined; };
|
|
454
315
|
off = port.onSemantic((name, payload) => handle(name, payload));
|
|
455
|
-
//
|
|
316
|
+
// 切片变更即重取:筛选条提交只写 filter 切片,重取归这里(等一拍,让分页器回第 1 页等镜像先落地)
|
|
317
|
+
const watches = (Array.isArray(props().watches) ? props().watches : []) as KitSliceReload[];
|
|
318
|
+
for (const w of watches) {
|
|
319
|
+
const slice = typeof svc?.region === 'function' ? svc.region(w.scope)?.slice(w.slice) : null;
|
|
320
|
+
if (!slice) continue;
|
|
321
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
322
|
+
const offSlice = slice.subscribe(() => {
|
|
323
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
324
|
+
timer = setTimeout(() => {
|
|
325
|
+
if (!alive) return;
|
|
326
|
+
for (const r of w.reload) void svc?.data?.reload(r.object === undefined ? undefined : [r.object]);
|
|
327
|
+
}, 0);
|
|
328
|
+
});
|
|
329
|
+
watchOffs.push(() => { offSlice(); if (timer !== undefined) clearTimeout(timer); });
|
|
330
|
+
}
|
|
331
|
+
// H1d:request.on: mount 的只读请求,宿主挂载时各发一次(载荷只带自动触发标记:挂载时没有行)
|
|
456
332
|
for (const [name, raw] of Object.entries(rec(props().requests))) {
|
|
457
333
|
if ((raw as KitRequestSpec).auto === 'mount') handle(name, { [AUTO_KEY]: true });
|
|
458
334
|
}
|
|
335
|
+
return () => {
|
|
336
|
+
alive = false;
|
|
337
|
+
offEnvelope?.();
|
|
338
|
+
offEnvelope = undefined;
|
|
339
|
+
off?.();
|
|
340
|
+
off = undefined;
|
|
341
|
+
for (const o of watchOffs.splice(0)) o();
|
|
342
|
+
for (const c of aborts.values()) c.abort();
|
|
343
|
+
aborts.clear();
|
|
344
|
+
inflight.clear();
|
|
345
|
+
queued.clear();
|
|
346
|
+
};
|
|
459
347
|
},
|
|
460
|
-
|
|
461
|
-
alive = false;
|
|
462
|
-
off?.();
|
|
463
|
-
off = undefined;
|
|
464
|
-
for (const c of aborts.values()) c.abort();
|
|
465
|
-
aborts.clear();
|
|
466
|
-
inflight.clear();
|
|
467
|
-
queued.clear();
|
|
468
|
-
},
|
|
348
|
+
render() {},
|
|
469
349
|
};
|
|
470
|
-
},
|
|
350
|
+
}),
|
|
471
351
|
};
|
|
472
352
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// 业务组件编译期公共辅助函数:角色视图槽白名单校验、区域类闭集校验、对象命名与编译片段收敛。纯函数。
|
|
2
|
+
|
|
3
|
+
import { KIT_VIEW_SLOTS } from '../../object-renderer/defaults';
|
|
4
|
+
import type { KitDiagnostic } from '../../object-renderer/types';
|
|
5
|
+
import type { KitFragment } from '../../compile/fragment';
|
|
6
|
+
import type { KitBizInput, KitBizRole } from '../types';
|
|
7
|
+
import { dedupeDiagnostics, isRec, type Parts } from '../link/shared';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 业务组件内部对象命名:`<页面槽>_<角色或子名>`。
|
|
11
|
+
* 页面槽(pageId)的保留名已在编译入口前置拒收,无需附加 `_obj` 死分支。
|
|
12
|
+
*/
|
|
13
|
+
export function bizObjectName(pageId: string, role: string): string {
|
|
14
|
+
return `${pageId}_${role}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 按业务组件契约定义 `roles[roleName].views` 校验角色对象的 view 槽闭集;
|
|
19
|
+
* 出现不在允许闭集内的视图槽时记录 KIT-BIZ-003 诊断并从 view 中移除。
|
|
20
|
+
*/
|
|
21
|
+
export function checkRoleAllowedViews(
|
|
22
|
+
roleName: string,
|
|
23
|
+
obj: unknown,
|
|
24
|
+
roleDef: Pick<KitBizRole, 'views'> | undefined,
|
|
25
|
+
diagnostics: KitDiagnostic[],
|
|
26
|
+
path = `product.objects.${roleName}`,
|
|
27
|
+
): void {
|
|
28
|
+
if (!isRec(obj) || roleDef === undefined) return;
|
|
29
|
+
const view = isRec(obj.view) ? obj.view : undefined;
|
|
30
|
+
if (view === undefined) return;
|
|
31
|
+
const allowed = roleDef.views;
|
|
32
|
+
for (const slot of KIT_VIEW_SLOTS) {
|
|
33
|
+
if (view[slot] !== undefined && !allowed.includes(slot)) {
|
|
34
|
+
diagnostics.push({
|
|
35
|
+
code: 'KIT-BIZ-003',
|
|
36
|
+
message: `该对象角色 ${roleName} 不允许 ${slot} 视图(允许:${allowed.join(' / ')})`,
|
|
37
|
+
path: `${path}.view.${slot}`,
|
|
38
|
+
});
|
|
39
|
+
delete view[slot];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 校验 input.areaClass 的键是否在业务组件声明的 areas 闭集内;越界记 KIT-PAGE-001。
|
|
46
|
+
*/
|
|
47
|
+
export function validateBizAreaClass(
|
|
48
|
+
input: KitBizInput,
|
|
49
|
+
kind: string,
|
|
50
|
+
areas: readonly string[],
|
|
51
|
+
diagnostics: KitDiagnostic[],
|
|
52
|
+
): void {
|
|
53
|
+
for (const key of Object.keys(input.areaClass ?? {})) {
|
|
54
|
+
if (!areas.includes(key)) {
|
|
55
|
+
diagnostics.push({
|
|
56
|
+
code: 'KIT-PAGE-001',
|
|
57
|
+
message: `areaClass 里的区域名 "${key}" 不在 ${kind} 的区域闭集 ${areas.join(' / ')} 内`,
|
|
58
|
+
path: `product.areaClass.${key}`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 收敛业务组件编译产物(去重诊断、排序 components 与 candidates)。
|
|
66
|
+
*/
|
|
67
|
+
export function finishBizCompile(out: Parts, html: string): KitFragment {
|
|
68
|
+
return {
|
|
69
|
+
html,
|
|
70
|
+
ui: {
|
|
71
|
+
data: out.data,
|
|
72
|
+
scopes: out.scopes as unknown as Record<string, unknown>,
|
|
73
|
+
show: out.show,
|
|
74
|
+
},
|
|
75
|
+
events: out.events,
|
|
76
|
+
components: [...out.components].sort(),
|
|
77
|
+
candidates: [...out.candidates].sort(),
|
|
78
|
+
diagnostics: dedupeDiagnostics(out.diagnostics),
|
|
79
|
+
};
|
|
80
|
+
}
|