soma-kit 0.1.10 → 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 -1278
|
@@ -8,13 +8,15 @@
|
|
|
8
8
|
// import_files Upload 变化:取第一个文件,在浏览器内读成文本、按 CSV 解析(首行是表头);超过体积 / 行数上限给出错误提示
|
|
9
9
|
// import_next 0 -> 1:按表头与目标字段自动建议映射;1 -> 2:按映射逐行用目标对象字典校验(services.data.validate)
|
|
10
10
|
// import_commit 2 -> 3:把校验通过的行逐行 services.data.submit(目标, 行, 'create')(有限并发),收集失败行;写入全经 core 的 data 端口
|
|
11
|
+
// import_cancel 写入中取消:不再发起后续行(已发出的等落定),未处理行与失败行并入同一个「仅重试失败行」入口
|
|
11
12
|
// import_download 下载问题行报告(CSV,单元格防公式注入)
|
|
12
13
|
// import_prev 回上一步;import_restart 回第 1 步清空
|
|
13
14
|
// 错误行不会被导入,也不阻断其余行:预览里标出,结果里汇总,随时可下载报告。
|
|
14
15
|
//
|
|
15
16
|
// 本组件不读 / 不存任何凭据;文件内容只在浏览器内存里,不写本地存储。
|
|
16
17
|
|
|
17
|
-
import type {
|
|
18
|
+
import type { SomaComponentDefinition, SomaDataPort, SomaRegionPort } from 'soma-core';
|
|
19
|
+
import { createKitController } from '../../base/shared';
|
|
18
20
|
import { KIT_BIZ_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
19
21
|
import { kitText } from '../../i18n/kit-text';
|
|
20
22
|
|
|
@@ -27,6 +29,7 @@ export const KIT_IMPORT_EVENTS = {
|
|
|
27
29
|
commit: 'import_commit',
|
|
28
30
|
download: 'import_download',
|
|
29
31
|
restart: 'import_restart',
|
|
32
|
+
cancel: 'import_cancel',
|
|
30
33
|
result: 'import_result',
|
|
31
34
|
} as const;
|
|
32
35
|
|
|
@@ -53,6 +56,8 @@ export const KIT_IMPORT_MIRRORS = {
|
|
|
53
56
|
hasErrors: { key: 'imp_has_errors', path: 'has_errors', as: 'truthy' } as const,
|
|
54
57
|
commitReady: { key: 'imp_commit_ready', path: 'commit_ready', as: 'truthy' } as const,
|
|
55
58
|
commitBlocked: { key: 'imp_commit_blocked', path: 'commit_blocked', as: 'truthy' } as const,
|
|
59
|
+
cancelReady: { key: 'imp_cancel_ready', path: 'cancel_ready', as: 'truthy' } as const,
|
|
60
|
+
cancelBlocked: { key: 'imp_cancel_blocked', path: 'cancel_blocked', as: 'truthy' } as const,
|
|
56
61
|
busy: { key: 'imp_busy', path: 'busy', as: 'truthy' } as const,
|
|
57
62
|
notBusy: { key: 'imp_not_busy', path: 'not_busy', as: 'truthy' } as const,
|
|
58
63
|
result: { key: 'imp_result', path: 'result', as: 'value' } as const,
|
|
@@ -66,6 +71,22 @@ function isRec(raw: unknown): raw is Rec {
|
|
|
66
71
|
|
|
67
72
|
// ───────── CSV:解析、映射建议、行转换、报告(均为纯函数) ─────────
|
|
68
73
|
|
|
74
|
+
/** CSV 字节解码:先严格 UTF-8,失败(如 Excel 另存的 GBK)回退 GBK,环境不支持 GBK 再回退非严格 UTF-8;去掉开头 BOM */
|
|
75
|
+
export function decodeCsvBytes(buf: ArrayBuffer): string {
|
|
76
|
+
let text: string;
|
|
77
|
+
try {
|
|
78
|
+
text = new TextDecoder('utf-8', { fatal: true }).decode(buf);
|
|
79
|
+
} catch {
|
|
80
|
+
try {
|
|
81
|
+
text = new TextDecoder('gbk').decode(buf);
|
|
82
|
+
} catch {
|
|
83
|
+
// 运行环境不支持 gbk(RangeError):退回非严格 UTF-8,个别字符显示为替换符,也让用户看到内容自行判断
|
|
84
|
+
text = new TextDecoder('utf-8').decode(buf);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
88
|
+
}
|
|
89
|
+
|
|
69
90
|
/** RFC 4180 的 CSV 解析:引号包裹、双引号转义、CRLF / LF;去掉 BOM 与全空行。返回行数组(每行是单元格数组) */
|
|
70
91
|
export function parseCsv(text: string): string[][] {
|
|
71
92
|
const src = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
@@ -147,12 +168,8 @@ export function mapRow(
|
|
|
147
168
|
return out;
|
|
148
169
|
}
|
|
149
170
|
|
|
150
|
-
|
|
151
|
-
export
|
|
152
|
-
let s = value === undefined || value === null ? '' : String(value);
|
|
153
|
-
if (/^[=+\-@]/.test(s)) s = `'${s}`;
|
|
154
|
-
return /[",\r\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
|
155
|
-
}
|
|
171
|
+
import { csvCell } from '../../shared/escape';
|
|
172
|
+
export { csvCell };
|
|
156
173
|
|
|
157
174
|
export interface KitImportIssue { row: number; field: string; message: string }
|
|
158
175
|
|
|
@@ -188,11 +205,20 @@ export interface KitImportMem {
|
|
|
188
205
|
progress: { done: number; total: number } | null;
|
|
189
206
|
result: { status: string; title: string; subtitle: string; extra: Array<{ key: string; label: string }> } | null;
|
|
190
207
|
seq: number;
|
|
208
|
+
runId: number;
|
|
209
|
+
/** 累计写入成功的行号(含重试) */
|
|
210
|
+
written: number[];
|
|
211
|
+
/** 最近一轮写入失败的行号(可重试) */
|
|
212
|
+
failedRows: number[];
|
|
213
|
+
/** 取消后未处理的行号(与失败行同一个重试入口) */
|
|
214
|
+
pendingRows: number[];
|
|
215
|
+
/** 已请求取消、在途行尚未落定(取消按钮禁用的依据);下一轮开始 / 重开 / 一轮结束时复位 */
|
|
216
|
+
cancelling: boolean;
|
|
191
217
|
}
|
|
192
218
|
|
|
193
|
-
export function initialImportMem(seq = 0): KitImportMem {
|
|
219
|
+
export function initialImportMem(seq = 0, runId = 0): KitImportMem {
|
|
194
220
|
return {
|
|
195
|
-
step: 0, files: [], parseError: '', columns: [], rows: [], mapping: {}, checked: null, busy: false, progress: null, result: null, seq,
|
|
221
|
+
step: 0, files: [], parseError: '', columns: [], rows: [], mapping: {}, checked: null, busy: false, progress: null, result: null, seq, runId, written: [], failedRows: [], pendingRows: [], cancelling: false,
|
|
196
222
|
};
|
|
197
223
|
}
|
|
198
224
|
|
|
@@ -214,8 +240,11 @@ export interface KitImportFocus {
|
|
|
214
240
|
has_errors: boolean;
|
|
215
241
|
commit_ready: boolean;
|
|
216
242
|
commit_blocked: boolean;
|
|
243
|
+
cancel_ready: boolean;
|
|
244
|
+
cancel_blocked: boolean;
|
|
217
245
|
busy: boolean;
|
|
218
246
|
not_busy: boolean;
|
|
247
|
+
progress: { done: number; total: number } | null;
|
|
219
248
|
result: Rec;
|
|
220
249
|
seq: number;
|
|
221
250
|
}
|
|
@@ -283,8 +312,11 @@ export function viewOfImport(mem: KitImportMem, targets: readonly KitImportTarge
|
|
|
283
312
|
has_errors: errorRows > 0 || (mem.result !== null && (checked?.issues.length ?? 0) > 0),
|
|
284
313
|
commit_ready: checked !== null && okCount > 0 && !mem.busy,
|
|
285
314
|
commit_blocked: !(checked !== null && okCount > 0 && !mem.busy),
|
|
315
|
+
cancel_ready: !mem.cancelling,
|
|
316
|
+
cancel_blocked: mem.cancelling,
|
|
286
317
|
busy: mem.busy,
|
|
287
318
|
not_busy: !mem.busy,
|
|
319
|
+
progress: mem.progress,
|
|
288
320
|
result: mem.result ?? {},
|
|
289
321
|
seq: mem.seq,
|
|
290
322
|
};
|
|
@@ -314,51 +346,55 @@ export function createKitImportHub(): SomaComponentDefinition {
|
|
|
314
346
|
},
|
|
315
347
|
emits: {
|
|
316
348
|
step_change: { payload: { step: { type: 'number' } }, desc: '当前步变化' },
|
|
317
|
-
imported: { payload: { ok: { type: 'number' }, failed: { type: 'number' } }, desc: '
|
|
349
|
+
imported: { payload: { ok: { type: 'number' }, failed: { type: 'number' }, added: { type: 'number' } }, desc: '导入结束:ok 为累计成功行数(含此前各轮重试),failed 为当前未成功行数(失败 + 校验跳过 + 未处理),added 为本轮新增成功行数;宿主要累加请用 added,不要把各次的 ok 相加' },
|
|
318
350
|
},
|
|
319
351
|
scope: { slices: ['focus'] },
|
|
320
352
|
},
|
|
321
353
|
services: ['region', 'data', 'notify'],
|
|
322
354
|
templateHtml: '<div data-soma-id="root" class="hidden"></div>',
|
|
323
|
-
controllerFactory: (
|
|
355
|
+
controllerFactory: createKitController((api) => {
|
|
324
356
|
let off: (() => void) | undefined;
|
|
325
357
|
let alive = false;
|
|
326
358
|
let mem = initialImportMem();
|
|
359
|
+
/** 独立的提交轮次标识(取消或重开时更换) */
|
|
360
|
+
let activeRunId = 0;
|
|
361
|
+
/** 已请求取消的轮次(0 = 无):不再发起后续行,已发出的一行等它落定 */
|
|
362
|
+
let cancelRun = 0;
|
|
327
363
|
/** 当前选中的文件对象(不进切片,只在浏览器内存里) */
|
|
328
364
|
let pickedFile: File | null = null;
|
|
329
|
-
const props = (): Rec =>
|
|
365
|
+
const props = (): Rec => api.props() as Rec;
|
|
330
366
|
const targets = (): KitImportTarget[] => targetsOf(props().targets);
|
|
331
367
|
const types = (): Record<string, string | undefined> => {
|
|
332
368
|
const t = props().types;
|
|
333
369
|
return isRec(t) ? (t as Record<string, string | undefined>) : {};
|
|
334
370
|
};
|
|
335
371
|
const dataPort = (): SomaDataPort | undefined => {
|
|
336
|
-
const port = (
|
|
372
|
+
const port = (api.services as { data?: SomaDataPort } | undefined)?.data;
|
|
337
373
|
return port && typeof port === 'object' ? port : undefined;
|
|
338
374
|
};
|
|
339
375
|
const toast = (level: string, message: string): void => {
|
|
340
|
-
const svc = (
|
|
376
|
+
const svc = (api.services as { notify?: { toast?: (o: { level: string; message: string }) => void } } | undefined)?.notify;
|
|
341
377
|
if (svc && typeof svc.toast === 'function') svc.toast({ level, message });
|
|
342
378
|
};
|
|
343
379
|
|
|
344
380
|
const run = (port: SomaRegionPort, next: KitImportMem): void => {
|
|
345
381
|
const prevStep = mem.step;
|
|
346
382
|
mem = { ...next, seq: mem.seq + 1 };
|
|
347
|
-
port.slice('focus')?.set(viewOfImport(mem, targets(),
|
|
348
|
-
if (mem.step !== prevStep)
|
|
383
|
+
port.slice('focus')?.set(viewOfImport(mem, targets(), api.host) as unknown as Rec);
|
|
384
|
+
if (mem.step !== prevStep) api.emit('step_change', { step: mem.step });
|
|
349
385
|
};
|
|
350
386
|
|
|
351
387
|
const readFile = async (port: SomaRegionPort, file: File): Promise<void> => {
|
|
352
388
|
const files: KitImportFile[] = [{ name: file.name, size: file.size, status: 'done' }];
|
|
353
389
|
if (file.size > LIMITS.maxFileKb * 1024) {
|
|
354
|
-
run(port, { ...mem, files: [{ ...files[0]!, status: 'error' }], parseError: kitText('soma.kit.iw_too_big', { n: LIMITS.maxFileKb },
|
|
390
|
+
run(port, { ...mem, files: [{ ...files[0]!, status: 'error' }], parseError: kitText('soma.kit.iw_too_big', { n: LIMITS.maxFileKb }, api.host), columns: [], rows: [], mapping: {}, checked: null });
|
|
355
391
|
return;
|
|
356
392
|
}
|
|
357
393
|
let text = '';
|
|
358
394
|
try {
|
|
359
|
-
text = await file.
|
|
395
|
+
text = decodeCsvBytes(await file.arrayBuffer());
|
|
360
396
|
} catch {
|
|
361
|
-
if (alive) run(port, { ...mem, files: [{ ...files[0]!, status: 'error' }], parseError: kitText('soma.kit.iw_read_failed', undefined,
|
|
397
|
+
if (alive) run(port, { ...mem, files: [{ ...files[0]!, status: 'error' }], parseError: kitText('soma.kit.iw_read_failed', undefined, api.host), columns: [], rows: [], mapping: {}, checked: null });
|
|
362
398
|
return;
|
|
363
399
|
}
|
|
364
400
|
if (!alive || pickedFile !== file) return;
|
|
@@ -366,10 +402,10 @@ export function createKitImportHub(): SomaComponentDefinition {
|
|
|
366
402
|
const header = (table[0] ?? []).map((h) => h.trim());
|
|
367
403
|
const body = table.slice(1);
|
|
368
404
|
let error = '';
|
|
369
|
-
if (header.length === 0 || header.every((h) => h === '')) error = kitText('soma.kit.iw_no_header', undefined,
|
|
370
|
-
else if (new Set(header).size !== header.length) error = kitText('soma.kit.iw_dup_header', undefined,
|
|
371
|
-
else if (body.length === 0) error = kitText('soma.kit.iw_no_rows', undefined,
|
|
372
|
-
else if (body.length > LIMITS.maxRows) error = kitText('soma.kit.iw_too_many', { n: LIMITS.maxRows },
|
|
405
|
+
if (header.length === 0 || header.every((h) => h === '')) error = kitText('soma.kit.iw_no_header', undefined, api.host);
|
|
406
|
+
else if (new Set(header).size !== header.length) error = kitText('soma.kit.iw_dup_header', undefined, api.host);
|
|
407
|
+
else if (body.length === 0) error = kitText('soma.kit.iw_no_rows', undefined, api.host);
|
|
408
|
+
else if (body.length > LIMITS.maxRows) error = kitText('soma.kit.iw_too_many', { n: LIMITS.maxRows }, api.host);
|
|
373
409
|
if (error !== '') {
|
|
374
410
|
run(port, { ...mem, files: [{ ...files[0]!, status: 'error' }], parseError: error, columns: [], rows: [], mapping: {}, checked: null });
|
|
375
411
|
return;
|
|
@@ -398,56 +434,76 @@ export function createKitImportHub(): SomaComponentDefinition {
|
|
|
398
434
|
return { okRows, issues };
|
|
399
435
|
};
|
|
400
436
|
|
|
401
|
-
|
|
437
|
+
/** 写入:首次 = 全部校验通过的行;重试 = 上次失败行 + 未处理行(同一条写入路径) */
|
|
438
|
+
const commit = async (port: SomaRegionPort, retry = false): Promise<void> => {
|
|
402
439
|
const data = dataPort();
|
|
403
440
|
const object = typeof props().object === 'string' ? (props().object as string) : '';
|
|
404
441
|
const checked = mem.checked;
|
|
405
|
-
if (!data || object === '' || checked === null
|
|
406
|
-
const
|
|
407
|
-
const queue = [...checked.okRows];
|
|
442
|
+
if (!data || object === '' || checked === null) return;
|
|
443
|
+
const retryRows = [...mem.failedRows, ...mem.pendingRows].sort((x, y) => x - y);
|
|
444
|
+
const queue = retry ? retryRows : [...checked.okRows];
|
|
445
|
+
if (queue.length === 0) return;
|
|
446
|
+
activeRunId += 1;
|
|
447
|
+
const thisRun = activeRunId;
|
|
448
|
+
cancelRun = 0;
|
|
408
449
|
const total = queue.length;
|
|
450
|
+
const priorWritten = retry ? mem.written : [];
|
|
409
451
|
const failed: KitImportIssue[] = [];
|
|
452
|
+
const okNow: number[] = [];
|
|
410
453
|
let done = 0;
|
|
411
|
-
|
|
454
|
+
// 重试的行先清掉旧的失败原因,仍失败的会带最新原因写回
|
|
455
|
+
const baseIssues = retry ? checked.issues.filter((x) => !queue.includes(x.row)) : checked.issues;
|
|
456
|
+
run(port, { ...mem, step: 3, busy: true, cancelling: false, progress: { done: 0, total }, result: null, runId: thisRun, ...(retry ? {} : { written: [], failedRows: [], pendingRows: [] }) });
|
|
412
457
|
const worker = async (): Promise<void> => {
|
|
413
458
|
for (;;) {
|
|
459
|
+
if (!alive || activeRunId !== thisRun || cancelRun === thisRun) return;
|
|
414
460
|
const n = queue.shift();
|
|
415
|
-
if (n === undefined
|
|
461
|
+
if (n === undefined) return;
|
|
416
462
|
const r = await data.submit(object, mapRow(mem.rows[n - 1] ?? {}, mem.mapping, types()), 'create');
|
|
463
|
+
if (!alive || activeRunId !== thisRun) return;
|
|
417
464
|
if (!r.ok) {
|
|
418
465
|
const fe = Object.entries(r.fieldErrors ?? {});
|
|
419
466
|
if (fe.length > 0) for (const [field, message] of fe) failed.push({ row: n, field, message });
|
|
420
|
-
else failed.push({ row: n, field: '', message: r.message !== '' ? r.message : '
|
|
421
|
-
}
|
|
467
|
+
else failed.push({ row: n, field: '', message: r.message !== '' ? r.message : kitText('soma.kit.iw_write_failed', undefined, api.host) });
|
|
468
|
+
} else okNow.push(n);
|
|
422
469
|
done += 1;
|
|
423
|
-
//
|
|
424
|
-
if (alive &&
|
|
470
|
+
// 重新开始(轮次变了)后,过期的进度不再写回
|
|
471
|
+
if (alive && activeRunId === thisRun) run(port, { ...mem, progress: { done, total } });
|
|
425
472
|
}
|
|
426
473
|
};
|
|
427
474
|
await Promise.all(Array.from({ length: Math.min(LIMITS.concurrency, total) }, () => worker()));
|
|
428
|
-
if (!alive || mem.step !== 3) return;
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
const
|
|
432
|
-
const
|
|
433
|
-
const
|
|
434
|
-
const
|
|
475
|
+
if (!alive || activeRunId !== thisRun || mem.step !== 3) return;
|
|
476
|
+
// 取消后没来得及发出的行:queue 里剩下的
|
|
477
|
+
const pendingRows = [...queue];
|
|
478
|
+
const failedRows = [...new Set(failed.map((f) => f.row))];
|
|
479
|
+
const written = [...priorWritten, ...okNow];
|
|
480
|
+
const okCount = written.length;
|
|
481
|
+
const failCount = failedRows.length;
|
|
482
|
+
const issues = [...baseIssues, ...failed];
|
|
483
|
+
const skipped = new Set(baseIssues.map((x) => x.row)).size;
|
|
484
|
+
const clean = failCount === 0 && skipped === 0 && pendingRows.length === 0;
|
|
485
|
+
// 用户取消(确有未处理行)且一行都没写成功:不算错误态,用「已取消」标题
|
|
486
|
+
const cancelled = cancelRun === thisRun && pendingRows.length > 0;
|
|
487
|
+
const status = clean ? 'success' : okCount === 0 && !cancelled ? 'error' : 'warning';
|
|
488
|
+
let subtitle = kitText('soma.kit.iw_sub', { ok: okCount, fail: failCount, skipped }, api.host);
|
|
489
|
+
if (pendingRows.length > 0) subtitle += `${kitText('soma.kit.semicolon', undefined, api.host)}${kitText('soma.kit.iw_unprocessed', { n: pendingRows.length }, api.host)}`;
|
|
435
490
|
const extra: Array<{ key: string; label: string }> = [];
|
|
436
|
-
if (
|
|
437
|
-
extra.push({ key: '
|
|
491
|
+
if (failCount + pendingRows.length > 0) extra.push({ key: 'retry', label: kitText('soma.kit.iw_retry_failed', { n: failCount + pendingRows.length }, api.host) });
|
|
492
|
+
if (issues.length > 0) extra.push({ key: 'download', label: kitText('soma.kit.iw_download_issues', undefined, api.host) });
|
|
493
|
+
extra.push({ key: 'restart', label: kitText('soma.kit.iw_restart', undefined, api.host) });
|
|
438
494
|
run(port, {
|
|
439
|
-
...mem, busy: false, progress: null,
|
|
440
|
-
checked: { okRows: checked.okRows.filter((n) => !
|
|
441
|
-
result: { status, title: kitText(status === 'success' ? 'soma.kit.iw_done' : status === 'error' ? 'soma.kit.iw_failed' : 'soma.kit.iw_partial', undefined,
|
|
495
|
+
...mem, busy: false, cancelling: false, progress: null, written, failedRows, pendingRows,
|
|
496
|
+
checked: { okRows: [...new Set([...checked.okRows, ...okNow])].filter((n) => !failedRows.includes(n)).sort((x, y) => x - y), issues },
|
|
497
|
+
result: { status, title: kitText(status === 'success' ? 'soma.kit.iw_done' : status === 'error' ? 'soma.kit.iw_failed' : cancelled && okCount === 0 ? 'soma.kit.request_cancelled' : 'soma.kit.iw_partial', undefined, api.host), subtitle, extra },
|
|
442
498
|
});
|
|
443
|
-
|
|
444
|
-
if (
|
|
499
|
+
api.emit('imported', { ok: okCount, failed: failCount + skipped + pendingRows.length, added: okNow.length });
|
|
500
|
+
if (clean) toast('success', kitText('soma.kit.iw_imported', { n: okCount }, api.host));
|
|
445
501
|
};
|
|
446
502
|
|
|
447
503
|
const download = (): void => {
|
|
448
504
|
const checked = mem.checked;
|
|
449
505
|
if (!checked || checked.issues.length === 0 || typeof document === 'undefined' || typeof Blob === 'undefined') return;
|
|
450
|
-
const csv = buildIssueReport(mem.columns, mem.rows, checked.issues,
|
|
506
|
+
const csv = buildIssueReport(mem.columns, mem.rows, checked.issues, api.host);
|
|
451
507
|
const url = URL.createObjectURL(new Blob([`${csv}`], { type: 'text/csv;charset=utf-8' }));
|
|
452
508
|
const a = document.createElement('a');
|
|
453
509
|
a.href = url;
|
|
@@ -459,15 +515,16 @@ export function createKitImportHub(): SomaComponentDefinition {
|
|
|
459
515
|
};
|
|
460
516
|
|
|
461
517
|
return {
|
|
462
|
-
|
|
518
|
+
attach() {
|
|
463
519
|
alive = true;
|
|
464
520
|
const scope = typeof props().scope === 'string' ? (props().scope as string) : '';
|
|
465
|
-
const svc = (
|
|
521
|
+
const svc = (api.services as { region?: (id: string) => SomaRegionPort | null } | undefined)?.region;
|
|
466
522
|
const port = scope !== '' && typeof svc === 'function' ? svc(scope) : null;
|
|
467
523
|
const focus = port?.slice('focus');
|
|
468
524
|
if (!port || !focus) return;
|
|
469
|
-
|
|
470
|
-
|
|
525
|
+
activeRunId += 1;
|
|
526
|
+
mem = initialImportMem(0, activeRunId);
|
|
527
|
+
focus.set(viewOfImport(mem, targets(), api.host) as unknown as Rec);
|
|
471
528
|
off = port.onSemantic((name, payload) => {
|
|
472
529
|
const p = isRec(payload) ? payload : {};
|
|
473
530
|
switch (name) {
|
|
@@ -514,25 +571,33 @@ export function createKitImportHub(): SomaComponentDefinition {
|
|
|
514
571
|
case KIT_IMPORT_EVENTS.result: {
|
|
515
572
|
const key = typeof p.key === 'string' ? p.key : '';
|
|
516
573
|
if (key === 'download') download();
|
|
517
|
-
else if (key === '
|
|
574
|
+
else if (key === 'retry') { if (!mem.busy && mem.step === 3) void commit(port, true); }
|
|
575
|
+
else if (key === 'restart') { activeRunId += 1; pickedFile = null; run(port, initialImportMem(mem.seq, activeRunId)); }
|
|
518
576
|
return;
|
|
519
577
|
}
|
|
578
|
+
case KIT_IMPORT_EVENTS.cancel:
|
|
579
|
+
if (mem.busy && mem.step === 3) { cancelRun = activeRunId; if (!mem.cancelling) run(port, { ...mem, cancelling: true }); }
|
|
580
|
+
return;
|
|
520
581
|
case KIT_IMPORT_EVENTS.restart:
|
|
521
|
-
|
|
582
|
+
activeRunId += 1;
|
|
583
|
+
pickedFile = null;
|
|
584
|
+
run(port, initialImportMem(mem.seq, activeRunId));
|
|
522
585
|
return;
|
|
523
586
|
default:
|
|
524
587
|
return;
|
|
525
588
|
}
|
|
526
589
|
});
|
|
590
|
+
return () => {
|
|
591
|
+
alive = false;
|
|
592
|
+
activeRunId += 1;
|
|
593
|
+
pickedFile = null;
|
|
594
|
+
if (off) off();
|
|
595
|
+
off = undefined;
|
|
596
|
+
};
|
|
527
597
|
},
|
|
528
|
-
|
|
529
|
-
alive = false;
|
|
530
|
-
pickedFile = null;
|
|
531
|
-
if (off) off();
|
|
532
|
-
off = undefined;
|
|
533
|
-
},
|
|
598
|
+
render() {},
|
|
534
599
|
};
|
|
535
|
-
},
|
|
600
|
+
}),
|
|
536
601
|
};
|
|
537
602
|
}
|
|
538
603
|
|
|
@@ -55,9 +55,9 @@ export interface ImportWizardIds {
|
|
|
55
55
|
resultWrap: string;
|
|
56
56
|
result: string;
|
|
57
57
|
/** 带显隐门的按钮:`<名>` 可用态与 `<名>_off` 禁用态成对 */
|
|
58
|
-
btn(name: 'up_next' | 'map_prev' | 'map_next' | 'pre_prev' | 'pre_download' | 'pre_commit', off?: boolean): string;
|
|
58
|
+
btn(name: 'up_next' | 'map_prev' | 'map_next' | 'pre_prev' | 'pre_download' | 'pre_commit' | 'cancel', off?: boolean): string;
|
|
59
59
|
/** 带显隐门的按钮外层(只放 core 写的 hidden);门与按钮 id 不同,避免重复 */
|
|
60
|
-
btnGate(name: 'up_next' | 'map_prev' | 'map_next' | 'pre_prev' | 'pre_download' | 'pre_commit', off?: boolean): string;
|
|
60
|
+
btnGate(name: 'up_next' | 'map_prev' | 'map_next' | 'pre_prev' | 'pre_download' | 'pre_commit' | 'cancel', off?: boolean): string;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export function importWizardIds(pageId: string): ImportWizardIds {
|
|
@@ -149,7 +149,7 @@ export function importWizardHtml(
|
|
|
149
149
|
].join(''));
|
|
150
150
|
const p3 = gate(ids.panel(3), `<div${cls(mergeClass(C.done, areaClass.done))}>`
|
|
151
151
|
+ `<h3${cls(C.panelTitle)}>${esc(T(3))}</h3>`
|
|
152
|
-
+ gate(ids.progress, text(`${ids.progress}_text`, C.hint))
|
|
152
|
+
+ gate(ids.progress, text(`${ids.progress}_text`, C.hint) + buttons(gatedBtn('cancel'), gatedBtn('cancel', true)))
|
|
153
153
|
+ gate(ids.resultWrap, host('ResultPanel', ids.result))
|
|
154
154
|
+ parts.job
|
|
155
155
|
+ '</div>');
|
package/src/biz/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 业务组件登记表:内置闭集。编译器按 `product.kind` 查 KIT_BIZ_COMPONENTS。
|
|
2
|
-
//
|
|
2
|
+
// 15 个内置业务组件闭集(StandardCrud / MasterSubWorkstation / CategoryCrud / MultiObjectBoard / SingleObjectForm / ApprovalDesk / RecordDetail / StepForm / NotificationCenter / AuthPanel / SettingsCenter / CheckoutPage / LandingPage / ResultPage / ImportWizard)+ KIT_PAGE_TEMPLATES 10 个可选页面模板。
|
|
3
3
|
// 业务组件壳依赖两个无界面协作数据组件:KitCrudBridge(focus 切片 owner:浮层开合、预填、保存后重取、删除)
|
|
4
4
|
// 与 KitLinkHub(selection 切片 owner:主子 / 分类联动选中、默认首条、字段动作带当前行),登记在 KIT_BIZ_DATA_COMPONENTS,
|
|
5
5
|
// 由应用装配并入数据组件表(与 createKitDataComponents 的产物合并,重名要显式 overrides)。
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
CapacityScheduleDesk,
|
|
30
30
|
TraceDiagnosticDesk,
|
|
31
31
|
TicketServiceDesk,
|
|
32
|
-
} from
|
|
32
|
+
} from './page-templates/domain-templates';
|
|
33
33
|
|
|
34
34
|
import type { KitBizDefinition } from './types';
|
|
35
35
|
|
|
@@ -66,7 +66,7 @@ export {
|
|
|
66
66
|
CapacityScheduleDesk,
|
|
67
67
|
TraceDiagnosticDesk,
|
|
68
68
|
TicketServiceDesk,
|
|
69
|
-
} from
|
|
69
|
+
} from './page-templates/domain-templates';
|
|
70
70
|
|
|
71
71
|
export {
|
|
72
72
|
ImportWizard, compileImportWizard, importWizardObjectName, createKitImportHub, KIT_IMPORT_EVENTS, KIT_IMPORT_MIRRORS,
|
|
@@ -13,6 +13,7 @@ import { IDENT, classesIn, isRec, newParts, type Rec } from '../link/shared';
|
|
|
13
13
|
import {
|
|
14
14
|
addClassTokens, checkAreas, emitReadOnlyMember, finishTemplate, templateObjectName,
|
|
15
15
|
} from '../page-templates/shared';
|
|
16
|
+
import { LandingPage } from './index';
|
|
16
17
|
import {
|
|
17
18
|
LANDING_PAGE_AREAS, LANDING_PAGE_CLASS, landingPageHtml, landingPageIds, type LandingSectionBlock,
|
|
18
19
|
} from './shell';
|
|
@@ -33,6 +34,9 @@ export function compileLandingPage(input: KitBizInput, ctx: KitBizContext): KitF
|
|
|
33
34
|
checkAreas(input, 'LandingPage', LANDING_PAGE_AREAS, out);
|
|
34
35
|
const names = isRec(rawSections) ? Object.keys(rawSections) : [];
|
|
35
36
|
for (const n of names) {
|
|
37
|
+
if (n === 'hero' || n === 'footer') {
|
|
38
|
+
fail('KIT-BIZ-001', `内容段名 "${n}" 与保留角色名撞名,禁止静默覆盖主视觉或页脚对象`, `product.objects.sections.${n}`);
|
|
39
|
+
}
|
|
36
40
|
if (!IDENT.test(n)) fail('KIT-PAGE-001', `内容段名 "${n}" 必须是标识符(字母数字下划线)`, `product.objects.sections.${n}`);
|
|
37
41
|
}
|
|
38
42
|
if (out.diagnostics.length > 0) return finishTemplate(out, '');
|
|
@@ -41,20 +45,32 @@ export function compileLandingPage(input: KitBizInput, ctx: KitBizContext): KitF
|
|
|
41
45
|
const areaClass = input.areaClass ?? {};
|
|
42
46
|
|
|
43
47
|
const hero = emitReadOnlyMember(out, rawHero, {
|
|
44
|
-
object: landingPageObjectName(ctx.pageId, 'hero'),
|
|
48
|
+
object: landingPageObjectName(ctx.pageId, 'hero'),
|
|
49
|
+
path: 'product.objects.hero',
|
|
50
|
+
roleName: 'hero',
|
|
51
|
+
roleDef: LandingPage.roles.hero,
|
|
52
|
+
ctx,
|
|
45
53
|
});
|
|
46
54
|
const blocks: LandingSectionBlock[] = [];
|
|
47
55
|
for (const n of names) {
|
|
48
56
|
const raw = (rawSections as Rec)[n];
|
|
49
57
|
const m = emitReadOnlyMember(out, raw, {
|
|
50
|
-
object: landingPageObjectName(ctx.pageId, n),
|
|
58
|
+
object: landingPageObjectName(ctx.pageId, n),
|
|
59
|
+
path: `product.objects.sections.${n}`,
|
|
60
|
+
roleName: 'sections',
|
|
61
|
+
roleDef: LandingPage.roles.sections,
|
|
62
|
+
ctx,
|
|
51
63
|
});
|
|
52
64
|
if (m !== undefined) blocks.push({ title: isRec(raw) && typeof raw.title === 'string' ? raw.title : '', html: m.html });
|
|
53
65
|
}
|
|
54
66
|
let footer = '';
|
|
55
67
|
if (rawFooter !== undefined) {
|
|
56
68
|
const m = emitReadOnlyMember(out, rawFooter, {
|
|
57
|
-
object: landingPageObjectName(ctx.pageId, 'footer'),
|
|
69
|
+
object: landingPageObjectName(ctx.pageId, 'footer'),
|
|
70
|
+
path: 'product.objects.footer',
|
|
71
|
+
roleName: 'footer',
|
|
72
|
+
roleDef: LandingPage.roles.footer,
|
|
73
|
+
ctx,
|
|
58
74
|
});
|
|
59
75
|
footer = m?.html ?? '';
|
|
60
76
|
}
|
package/src/biz/link/hub.ts
CHANGED
|
@@ -6,14 +6,17 @@
|
|
|
6
6
|
// · 行选中(语义事件 link_pick,载荷带整行)→ 写 selection;行数据到达时默认选首行(autoSelect);
|
|
7
7
|
// · 选中项一变(不论谁写的):把依赖对象的 view 切片回第 1 页(经路径写者 `page`),等镜像落地后上抛 picked { id, item, prefill },
|
|
8
8
|
// 页面再接 `SCOPE | window-reload`(MasterSub)或 `SCOPE | semantic kit_pick`(CategoryCrud,交给协调组件写预填并重取);
|
|
9
|
-
// · 摘要字段动作(语义事件 link_field_
|
|
9
|
+
// · 摘要字段动作(语义事件 link_field_<序号>):字段事件自己的载荷只有 { value },由本组件补上当前选中行后抛槽位事件 field_action_<序号> { value, row },
|
|
10
|
+
// 页面给每个槽位各绑一条管道。
|
|
10
11
|
// 为什么走 SCOPE | semantic:行内组件写切片会被拒收(切片写者必须是页面直接声明的实例),这是唯一没有写者核对的通路。
|
|
11
12
|
|
|
12
|
-
import type {
|
|
13
|
+
import type { SomaComponentDefinition, SomaRegionPort } from 'soma-core';
|
|
14
|
+
import { createKitController } from '../../base/shared';
|
|
15
|
+
import { KIT_ACTION_SLOT_BASE, KIT_ACTION_SLOT_MAX, actionSlotEmits, actionSlotEvent, emitActionSlot } from '../../base/action-slots';
|
|
13
16
|
|
|
14
17
|
export const KIT_LINK_EVENTS = {
|
|
15
18
|
pick: 'link_pick',
|
|
16
|
-
/** 摘要字段动作:`link_field_
|
|
19
|
+
/** 摘要字段动作:`link_field_<序号>`(序号 = 动作槽位) */
|
|
17
20
|
fieldPrefix: 'link_field_',
|
|
18
21
|
} as const;
|
|
19
22
|
|
|
@@ -103,24 +106,34 @@ export function createKitLinkHub(): SomaComponentDefinition {
|
|
|
103
106
|
rows: { type: 'array', default: [], desc: '主列表的行数据(autoSelect 用)' },
|
|
104
107
|
afterRemove: { type: 'string', default: '', desc: "选中项从行里消失后的去向:'next' = 原位置的下一条(没有就上一条);空 = 首行" },
|
|
105
108
|
pageScopes: { type: 'array', default: [], desc: '选中项变化时要回第 1 页的作用域 id(它们 view 切片的 page 路径写者是本组件)' },
|
|
109
|
+
pickSlots: { type: 'number', default: 0, desc: '选中项变化时依次抛 picked_0 … picked_<n-1> 的个数(每个依赖对象的重取各绑一个槽位;0 = 只抛 picked)' },
|
|
110
|
+
watchFilters: { type: 'array', default: [], desc: '筛选条的作用域 id:它们的 filter 切片一变(每次提交 / 重置都算,值没变也算)就回第 1 页并上抛 picked,页面据此重取(MultiObjectBoard 的全局筛选)' },
|
|
106
111
|
},
|
|
107
112
|
emits: {
|
|
108
113
|
picked: { payload: { id: { type: 'string' }, item: { type: 'object' }, prefill: { type: 'object' } }, desc: '选中项变化(页面据此重取依赖对象)' },
|
|
109
|
-
|
|
114
|
+
...actionSlotEmits('picked', { id: { type: 'string' }, item: { type: 'object' }, prefill: { type: 'object' } }, '选中项变化的分发槽位(pickSlots 个):依赖多个对象要各自重取时,每个对象的重取各绑一个槽位'),
|
|
115
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.field, { value: { type: 'string' }, row: { type: 'object' } }, '摘要字段动作 / 工具栏具名动作:载荷带当前选中行(字段事件自己只有 { value })'),
|
|
110
116
|
},
|
|
111
117
|
scope: { slices: ['selection', 'view'] },
|
|
112
118
|
},
|
|
113
119
|
services: ['region'],
|
|
114
120
|
templateHtml: '<div data-soma-id="root" class="hidden"></div>',
|
|
115
|
-
controllerFactory: (
|
|
116
|
-
const props = (): Rec =>
|
|
121
|
+
controllerFactory: createKitController((api) => {
|
|
122
|
+
const props = (): Rec => api.props() as Rec;
|
|
117
123
|
let offs: Array<() => void> = [];
|
|
118
124
|
let lastKey: string | null | undefined;
|
|
119
125
|
let alive = false;
|
|
120
126
|
let lastRows: readonly unknown[] = [];
|
|
121
127
|
|
|
128
|
+
/** 选中项变化:抛 picked,并按 pickSlots 依次抛 picked_0 … picked_<n-1>(页面给每个依赖对象的重取各绑一条管道,不共用一个事件) */
|
|
129
|
+
const emitPicked = (payload: Rec): void => {
|
|
130
|
+
api.emit('picked', payload);
|
|
131
|
+
const n = Math.min(Math.max(0, Math.floor(Number(props().pickSlots) || 0)), KIT_ACTION_SLOT_MAX);
|
|
132
|
+
for (let i = 0; i < n; i += 1) api.emit(actionSlotEvent('picked', i), payload);
|
|
133
|
+
};
|
|
134
|
+
|
|
122
135
|
const regionOf = (id: string): SomaRegionPort | null => {
|
|
123
|
-
const svc = (
|
|
136
|
+
const svc = (api.services as { region?: (scopeId: string) => SomaRegionPort | null } | undefined)?.region;
|
|
124
137
|
return id !== '' && typeof svc === 'function' ? svc(id) : null;
|
|
125
138
|
};
|
|
126
139
|
const port = (): SomaRegionPort | null => regionOf(strOf(props().scope));
|
|
@@ -188,13 +201,28 @@ export function createKitLinkHub(): SomaComponentDefinition {
|
|
|
188
201
|
await tick();
|
|
189
202
|
// 卸载了,或等待期间选中项又变了(后一次调用会自己通知):不再上抛过期的选中
|
|
190
203
|
if (!alive || lastKey !== key) return;
|
|
191
|
-
|
|
204
|
+
emitPicked({
|
|
192
205
|
id: key ?? '',
|
|
193
206
|
item: isRec(row) ? row : {},
|
|
194
207
|
prefill: createPrefill(row, keyField(), strOf(props().linkKey)),
|
|
195
208
|
});
|
|
196
209
|
};
|
|
197
210
|
|
|
211
|
+
// 筛选条提交 / 重置:filter 切片每写一次就通知一次(值没变也通知),按“选中项变了”同一条路回第 1 页、等镜像落地后上抛 picked
|
|
212
|
+
const watchFilters = (): void => {
|
|
213
|
+
for (const id of listOf(props().watchFilters)) {
|
|
214
|
+
const slice = regionOf(id)?.slice('filter');
|
|
215
|
+
if (!slice) continue;
|
|
216
|
+
offs.push(slice.subscribe(() => {
|
|
217
|
+
if (!alive) return;
|
|
218
|
+
resetPages();
|
|
219
|
+
void tick().then(() => {
|
|
220
|
+
if (alive) emitPicked({ id: '', item: {}, prefill: {} });
|
|
221
|
+
});
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
198
226
|
const syncDefault = (): void => {
|
|
199
227
|
const p = props();
|
|
200
228
|
if (p.autoSelect !== true && p.autoSelect !== 'true') return;
|
|
@@ -215,8 +243,8 @@ export function createKitLinkHub(): SomaComponentDefinition {
|
|
|
215
243
|
if (name.startsWith(KIT_LINK_EVENTS.fieldPrefix)) {
|
|
216
244
|
// 字段动作的载荷只有 { value }:补上当前选中行,不依赖 core 补 row
|
|
217
245
|
const row = selectedOf(port()?.slice('selection')?.get());
|
|
218
|
-
|
|
219
|
-
|
|
246
|
+
const slot = Number(name.slice(KIT_LINK_EVENTS.fieldPrefix.length));
|
|
247
|
+
if (Number.isInteger(slot)) emitActionSlot((n, p) => api.emit(n, p), KIT_ACTION_SLOT_BASE.field, slot, {
|
|
220
248
|
value: payload.value,
|
|
221
249
|
row: isRec(row) ? row : {},
|
|
222
250
|
});
|
|
@@ -224,7 +252,7 @@ export function createKitLinkHub(): SomaComponentDefinition {
|
|
|
224
252
|
};
|
|
225
253
|
|
|
226
254
|
return {
|
|
227
|
-
|
|
255
|
+
attach() {
|
|
228
256
|
alive = true;
|
|
229
257
|
const p = port();
|
|
230
258
|
if (!p) return;
|
|
@@ -233,21 +261,22 @@ export function createKitLinkHub(): SomaComponentDefinition {
|
|
|
233
261
|
const sel = p.slice('selection');
|
|
234
262
|
if (sel) offs.push(sel.subscribe(() => { void onSelection(); }));
|
|
235
263
|
watchSort();
|
|
264
|
+
watchFilters();
|
|
236
265
|
syncDefault();
|
|
266
|
+
return () => {
|
|
267
|
+
alive = false;
|
|
268
|
+
for (const off of offs) off();
|
|
269
|
+
offs = [];
|
|
270
|
+
sortWatching.clear();
|
|
271
|
+
sortSeen.clear();
|
|
272
|
+
};
|
|
237
273
|
},
|
|
238
|
-
|
|
274
|
+
render() {
|
|
239
275
|
watchSort();
|
|
240
276
|
syncDefault();
|
|
241
277
|
},
|
|
242
|
-
onUnmount(): void {
|
|
243
|
-
alive = false;
|
|
244
|
-
for (const off of offs) off();
|
|
245
|
-
offs = [];
|
|
246
|
-
sortWatching.clear();
|
|
247
|
-
sortSeen.clear();
|
|
248
|
-
},
|
|
249
278
|
};
|
|
250
|
-
},
|
|
279
|
+
}),
|
|
251
280
|
};
|
|
252
281
|
}
|
|
253
282
|
|