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
|
@@ -16,37 +16,23 @@ import type { SomaScopeMirrorDecl } from 'soma-core';
|
|
|
16
16
|
import { KIT_VIEW_FORM_KEYS, KIT_VIEW_SLOTS } from '../../object-renderer/defaults';
|
|
17
17
|
import { emitObject } from '../../object-renderer/emit-object';
|
|
18
18
|
import { viewAnchor } from '../../object-renderer/emit-static';
|
|
19
|
-
import type {
|
|
19
|
+
import type { KitDiagnostic, KitFieldSchema, KitObject, KitViewForm } from '../../object-renderer/types';
|
|
20
20
|
import type { KitFragment } from '../../compile/fragment';
|
|
21
21
|
import type { KitBizContext, KitBizInput } from '../types';
|
|
22
22
|
import { kitText } from '../../i18n/kit-text';
|
|
23
|
-
import {
|
|
24
|
-
|
|
23
|
+
import {
|
|
24
|
+
bizObjectName, checkRoleAllowedViews, finishBizCompile, validateBizAreaClass,
|
|
25
|
+
} from '../shared/compile-helpers';
|
|
25
26
|
import { KIT_STEP_EVENTS, KIT_STEP_MIRRORS } from './hub';
|
|
27
|
+
import { StepForm } from './index';
|
|
26
28
|
import {
|
|
27
|
-
IDENT, addEmit, classesIn,
|
|
28
|
-
type
|
|
29
|
+
IDENT, addEmit, classesIn, isRec, mirrorPath, newParts, patchProps, semanticPipe, sortMirrors,
|
|
30
|
+
type Rec,
|
|
29
31
|
} from '../link/shared';
|
|
30
32
|
import { STEP_FORM_AREAS, STEP_FORM_CLASS, stepFormHtml, stepFormIds } from './shell';
|
|
31
|
-
import { rewriteStepRefs } from './steps-ref';
|
|
32
|
-
import { runInKitStepScope } from '../../object-renderer/field-value';
|
|
33
|
-
|
|
34
|
-
const RESERVED = new Set(['page', 'p', 'ctrl', 'frame', 'tabs']);
|
|
35
33
|
|
|
36
34
|
export function stepFormObjectName(pageId: string, role: string): string {
|
|
37
|
-
|
|
38
|
-
return RESERVED.has(name) ? `${name}_obj` : name;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function finish(out: Parts, html: string): KitFragment {
|
|
42
|
-
return {
|
|
43
|
-
html,
|
|
44
|
-
ui: { data: out.data, scopes: out.scopes as unknown as Record<string, unknown>, show: out.show },
|
|
45
|
-
events: out.events,
|
|
46
|
-
components: [...out.components].sort(),
|
|
47
|
-
candidates: [...out.candidates].sort(),
|
|
48
|
-
diagnostics: dedupeDiagnostics(out.diagnostics),
|
|
49
|
-
};
|
|
35
|
+
return bizObjectName(pageId, role);
|
|
50
36
|
}
|
|
51
37
|
|
|
52
38
|
/** 一步规整:view 顶层的表单键归到 form 槽;只许 form 槽;不许读写 */
|
|
@@ -62,35 +48,20 @@ function normalizeStep(raw: Rec, path: string, diagnostics: KitDiagnostic[], per
|
|
|
62
48
|
view.form = form;
|
|
63
49
|
}
|
|
64
50
|
}
|
|
65
|
-
|
|
66
|
-
if (slot !== 'form' && view[slot] !== undefined) {
|
|
67
|
-
fail(`StepForm 的每一步只有 form 视图,不允许 ${slot}`, `${path}.view.${slot}`);
|
|
68
|
-
delete view[slot];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
51
|
+
checkRoleAllowedViews('steps', { view }, StepForm.roles.steps, diagnostics, path);
|
|
71
52
|
if (view.form === undefined) view.form = {};
|
|
72
53
|
const behavior: Rec = isRec(raw.behavior) ? { ...raw.behavior } : {};
|
|
73
54
|
if (behavior.from !== undefined) fail('StepForm 每一步不声明 behavior.from:分步表单只新建', `${path}.behavior.from`);
|
|
74
55
|
if (behavior.write !== undefined && !perStep) {
|
|
75
56
|
diagnostics.push({ code: 'KIT-STEP-001', message: 'saveMode 为 final 时步骤对象不写 behavior.write(读写由 target 承担;要每步保存请设 config.saveMode: perStep)', path: `${path}.behavior.write` });
|
|
76
57
|
}
|
|
77
|
-
// 步骤动作只许 request 动作且不写 on:上一步 / 下一步 / 提交由写死的按钮承担,request 动作只被 gate.run(「去验证」钮)引用
|
|
78
|
-
const stepActions: unknown[] = [];
|
|
79
|
-
if (Array.isArray(behavior.actions)) {
|
|
80
|
-
behavior.actions.forEach((a, i) => {
|
|
81
|
-
const ok = isRec(a) && isRec(a.request) && a.on === undefined && a.submit === undefined && a.builtin === undefined;
|
|
82
|
-
if (ok) stepActions.push(a);
|
|
83
|
-
else fail('StepForm 每一步的 behavior.actions 只许不写 on 的 request 动作(它只被 gate.run 引用;上一步 / 下一步 / 提交由写死的按钮承担)', `${path}.behavior.actions[${i}]`);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
58
|
// perStep 下步骤对象自带写口(首步 create + update,其余步 update);final 下没有读写
|
|
87
|
-
const { gate: _gate, ...rest } = raw;
|
|
88
59
|
return {
|
|
89
|
-
...
|
|
60
|
+
...raw,
|
|
90
61
|
schema: isRec(raw.schema) ? raw.schema : {},
|
|
91
62
|
behavior: {
|
|
92
63
|
...(perStep && behavior.write !== undefined ? { write: behavior.write } : {}),
|
|
93
|
-
...(
|
|
64
|
+
...(Array.isArray(behavior.actions) ? { actions: behavior.actions } : {}),
|
|
94
65
|
},
|
|
95
66
|
view,
|
|
96
67
|
} as unknown as KitObject;
|
|
@@ -175,7 +146,7 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
175
146
|
const rawTarget = input.objects.target;
|
|
176
147
|
if (!isRec(rawSteps) || Object.keys(rawSteps).length === 0) {
|
|
177
148
|
fail('KIT-BIZ-001', 'StepForm 缺少必填对象角色槽 steps(至少 1 步)', 'product.objects.steps');
|
|
178
|
-
return
|
|
149
|
+
return finishBizCompile(out, '');
|
|
179
150
|
}
|
|
180
151
|
const cfg = readStepConfig(isRec(input.config) ? input.config : undefined, out.diagnostics);
|
|
181
152
|
const perStep = cfg.perStep;
|
|
@@ -189,22 +160,16 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
189
160
|
} else {
|
|
190
161
|
if (!isRec(rawTarget) || !isRec(rawTarget.behavior) || (rawTarget.behavior as Rec).write === undefined) {
|
|
191
162
|
fail('KIT-BIZ-001', 'StepForm 缺少必填对象角色槽 target(需含 behavior.write:最终提交的写接口)', 'product.objects.target');
|
|
192
|
-
return
|
|
163
|
+
return finishBizCompile(out, '');
|
|
193
164
|
}
|
|
194
165
|
if (rawTarget.schema !== undefined) fail('KIT-BIZ-003', 'StepForm 的 target 不写 schema:字段字典由各步 schema 合并而来', 'product.objects.target.schema');
|
|
195
166
|
if (rawTarget.view !== undefined) fail('KIT-BIZ-003', 'StepForm 的 target 不写 view', 'product.objects.target.view');
|
|
196
167
|
if ((rawTarget.behavior as Rec).from !== undefined) fail('KIT-BIZ-003', 'StepForm 的 target 不支持 behavior.from(分步表单只新建)', 'product.objects.target.behavior.from');
|
|
197
168
|
}
|
|
198
|
-
|
|
199
|
-
if (!(STEP_FORM_AREAS as readonly string[]).includes(key)) {
|
|
200
|
-
fail('KIT-PAGE-001', `areaClass 里的区域名 "${key}" 不在 StepForm 的区域闭集 ${STEP_FORM_AREAS.join(' / ')} 内`, `product.areaClass.${key}`);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
169
|
+
validateBizAreaClass(input, 'StepForm', STEP_FORM_AREAS, out.diagnostics);
|
|
203
170
|
const stepNames = Object.keys(rawSteps);
|
|
204
|
-
const steps: Array<{ name: string; object: string; obj: KitObject; title: string; fields: string[]
|
|
171
|
+
const steps: Array<{ name: string; object: string; obj: KitObject; title: string; fields: string[] }> = [];
|
|
205
172
|
const union: Record<string, KitFieldSchema> = {};
|
|
206
|
-
/** 已处理的更早步骤:闸门的 steps.<名>.<字段> 只能指向它们 */
|
|
207
|
-
const earlier = new Map<string, { index: number; fields: ReadonlySet<string> }>();
|
|
208
173
|
for (const n of stepNames) {
|
|
209
174
|
const at = `product.objects.steps.${n}`;
|
|
210
175
|
const raw = rawSteps[n];
|
|
@@ -213,9 +178,7 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
213
178
|
fail('KIT-BIZ-001', `steps.${n} 必须是对象声明且含非空 schema`, at);
|
|
214
179
|
continue;
|
|
215
180
|
}
|
|
216
|
-
|
|
217
|
-
const refd = rewriteStepRefs(raw as Rec, at, earlier, out.diagnostics);
|
|
218
|
-
const obj = normalizeStep(refd.step, at, out.diagnostics, perStep);
|
|
181
|
+
const obj = normalizeStep(raw as Rec, at, out.diagnostics, perStep);
|
|
219
182
|
if (perStep) {
|
|
220
183
|
checkPerStepWrite(isRec(raw.behavior) ? (raw.behavior as Rec).write : undefined, stepNames[0] === n, stepKey, abandonDelete, at, out.diagnostics);
|
|
221
184
|
if (stepKey in obj.schema) fail('KIT-STEP-001', `stepKey "${stepKey}" 是主键位,不能同时是步骤字段`, `${at}.schema.${stepKey}`);
|
|
@@ -224,27 +187,20 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
224
187
|
for (const f of fields) {
|
|
225
188
|
if (f in union) fail('KIT-BIZ-003', `字段 ${f} 在多个步骤里重复声明(字段名在各步之间不得重名)`, `${at}.schema.${f}`);
|
|
226
189
|
else {
|
|
227
|
-
// 提交目标只取字典(rules / 类型):初值 /
|
|
228
|
-
const { default: _default, hidden: _hidden,
|
|
190
|
+
// 提交目标只取字典(rules / 类型):初值 / 隐藏是各步表单自己的事,不带进目标(目标不发射界面)
|
|
191
|
+
const { default: _default, hidden: _hidden, ...plain } = obj.schema[f]!;
|
|
229
192
|
union[f] = plain;
|
|
230
193
|
}
|
|
231
194
|
}
|
|
232
|
-
// 阶段闸门:{ when, message },不满足时本步「下一步」禁用并显示 message
|
|
233
|
-
const gate = raw.gate === undefined
|
|
234
|
-
? null
|
|
235
|
-
: gateOf(raw.gate, `${at}.gate`, new Set(fields), new Map(earlier), out.diagnostics);
|
|
236
195
|
steps.push({
|
|
237
196
|
name: n,
|
|
238
197
|
object: stepFormObjectName(ctx.pageId, `step_${n}`),
|
|
239
198
|
obj,
|
|
240
199
|
title: typeof raw.title === 'string' && raw.title !== '' ? raw.title : n,
|
|
241
200
|
fields,
|
|
242
|
-
usesSteps: refd.used,
|
|
243
|
-
...(gate !== null ? { gate } : {}),
|
|
244
201
|
});
|
|
245
|
-
earlier.set(n, { index: steps.length - 1, fields: new Set(fields) });
|
|
246
202
|
}
|
|
247
|
-
if (out.diagnostics.length > 0) return
|
|
203
|
+
if (out.diagnostics.length > 0) return finishBizCompile(out, '');
|
|
248
204
|
|
|
249
205
|
const ids = stepFormIds(ctx.pageId);
|
|
250
206
|
const link = ids.link;
|
|
@@ -256,8 +212,7 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
256
212
|
// ---- 每步一个表单(只含本步字段的数据对象 + KitObjectForm)
|
|
257
213
|
const formHtml: Record<string, string> = {};
|
|
258
214
|
steps.forEach((s, i) => {
|
|
259
|
-
|
|
260
|
-
const r = runInKitStepScope(() => emitObject(
|
|
215
|
+
const r = emitObject(
|
|
261
216
|
s.obj,
|
|
262
217
|
{ object: s.object, scope: `${s.object}_scope`, registered: ctx.registeredComponents, staticComponents: ctx.staticComponents },
|
|
263
218
|
{
|
|
@@ -265,7 +220,7 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
265
220
|
formMode: 'create',
|
|
266
221
|
formInitialPath: mirrorPath(link, KIT_STEP_MIRRORS.values(i).key),
|
|
267
222
|
},
|
|
268
|
-
)
|
|
223
|
+
);
|
|
269
224
|
r.diagnostics = r.diagnostics.map((d) => ({ ...d, path: `${s.object}:${d.path}` }));
|
|
270
225
|
addEmit(out, r);
|
|
271
226
|
// abandon: delete:首步 write.delete 的 {stepKey} 占位取自目标记录,core 要求它是本对象字典里的字段;
|
|
@@ -290,28 +245,6 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
290
245
|
resetLabel: '',
|
|
291
246
|
...(i > 0 ? { cancelLabel: kitText('soma.kit.prev_step', undefined, ctx.locale) } : {}),
|
|
292
247
|
});
|
|
293
|
-
// 阶段闸门:声明与各步已确认值(镜像)一并交给表单,由表单实时求值、禁用提交并显示原因
|
|
294
|
-
if (s.gate !== undefined) {
|
|
295
|
-
let gate: KitGateDecl = s.gate;
|
|
296
|
-
const gateAt = `product.objects.steps.${s.name}.gate`;
|
|
297
|
-
if (gate.run !== undefined) {
|
|
298
|
-
// 「去验证」钮:指向本步一个不写 on 的 request 动作,其 into 必须写明(闸门用 outcome.<into>.status 读它)
|
|
299
|
-
const acts = (s.obj.behavior.actions ?? []) as KitAction[];
|
|
300
|
-
const hit = acts.find((a) => a.id === gate.run);
|
|
301
|
-
const into = hit?.request?.into;
|
|
302
|
-
if (hit === undefined || hit.request === undefined) fail('KIT-STEP-004', `gate.run "${gate.run}" 不是本步 behavior.actions 里的 request 动作`, `${gateAt}.run`);
|
|
303
|
-
else if (typeof into !== 'string' || into === '') fail('KIT-STEP-004', `gate.run 指向的动作 ${hit.id} 必须写 request.into(闸门读它的结果)`, `${gateAt}.run`);
|
|
304
|
-
else {
|
|
305
|
-
const pipe = runInKitStepScope(() => actionPipeline(hit, `${gateAt}.run`, { actions: acts, hasWrite: false, object: s.object, ...(ctx.registeredActions !== undefined ? { registeredActions: ctx.registeredActions } : {}) }, out.diagnostics));
|
|
306
|
-
if (pipe !== null) out.events[`${formId}.gate_run`] = actionEvent(pipe, hit, `${s.object}_scope`);
|
|
307
|
-
gate = { ...gate, runOutcome: into };
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
patchProps(out.show, formId, { gate, gateSteps: mirrorPath(link, KIT_STEP_MIRRORS.allValues.key) });
|
|
311
|
-
} else if (s.usesSteps) {
|
|
312
|
-
// GB1:没有闸门但字段 default / options.params / derive 用到 $steps:只交各步已确认值的镜像
|
|
313
|
-
patchProps(out.show, formId, { gateSteps: mirrorPath(link, KIT_STEP_MIRRORS.allValues.key) });
|
|
314
|
-
}
|
|
315
248
|
out.events[`${formId}.submit`] = semanticPipe(link, KIT_STEP_EVENTS.next);
|
|
316
249
|
if (i > 0) out.events[`${formId}.cancel`] = semanticPipe(link, KIT_STEP_EVENTS.prev);
|
|
317
250
|
// abandon: delete:每步多一个「取消」,放弃并(已保存过时)二次确认后删掉半成品
|
|
@@ -320,7 +253,7 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
320
253
|
out.events[`${ids.abort(i)}.click`] = semanticPipe(link, KIT_STEP_EVENTS.abort);
|
|
321
254
|
}
|
|
322
255
|
});
|
|
323
|
-
if (out.diagnostics.length > 0) return
|
|
256
|
+
if (out.diagnostics.length > 0) return finishBizCompile(out, '');
|
|
324
257
|
|
|
325
258
|
// ---- 提交目标的数据对象:字段字典 = 并集,带 write;只取它的 data 声明,不发射界面
|
|
326
259
|
// perStep 不要提交目标:写口在各步对象上
|
|
@@ -330,21 +263,17 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
330
263
|
behavior: { write: (targetRec.behavior as Rec).write },
|
|
331
264
|
view: { form: { fields: Object.keys(union) } },
|
|
332
265
|
} as unknown as KitObject;
|
|
333
|
-
|
|
334
|
-
const tr = runInKitStepScope(() => emitObject(
|
|
266
|
+
const tr = emitObject(
|
|
335
267
|
targetObj,
|
|
336
268
|
{ object: targetName, scope: `${targetName}_scope`, registered: ctx.registeredComponents, staticComponents: ctx.staticComponents },
|
|
337
269
|
{ registeredActions: ctx.registeredActions, formMode: 'create' },
|
|
338
|
-
)
|
|
270
|
+
);
|
|
339
271
|
out.diagnostics.push(...tr.diagnostics.map((d) => ({ ...d, path: `${targetName}:${d.path}` })));
|
|
340
272
|
Object.assign(out.data, tr.ui.data);
|
|
341
273
|
}
|
|
342
274
|
|
|
343
275
|
// ---- 链接作用域:focus 归 KitStepHub
|
|
344
276
|
const mirrors: SomaScopeMirrorDecl[] = [{ key: KIT_STEP_MIRRORS.done.key, slice: 'focus', path: KIT_STEP_MIRRORS.done.path, as: 'truthy' }];
|
|
345
|
-
if (steps.some((s) => s.gate !== undefined || s.usesSteps)) {
|
|
346
|
-
mirrors.push({ key: KIT_STEP_MIRRORS.allValues.key, slice: 'focus', path: KIT_STEP_MIRRORS.allValues.path, as: KIT_STEP_MIRRORS.allValues.as });
|
|
347
|
-
}
|
|
348
277
|
for (let i = 0; i < total; i += 1) {
|
|
349
278
|
for (const x of [KIT_STEP_MIRRORS.at(i), KIT_STEP_MIRRORS.past(i), KIT_STEP_MIRRORS.fut(i)]) {
|
|
350
279
|
mirrors.push({ key: x.key, slice: 'focus', path: x.path, as: x.as });
|
|
@@ -379,7 +308,7 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
379
308
|
...(abandonDelete ? { abandon: 'delete' } : {}),
|
|
380
309
|
},
|
|
381
310
|
};
|
|
382
|
-
out.events[`${ids.hub}.saved`] =
|
|
311
|
+
out.events[`${ids.hub}.saved`] = `NOTIFY | success | ${kitText('soma.kit.sf_done', undefined, ctx.locale)}`;
|
|
383
312
|
|
|
384
313
|
const doneTitle = typeof targetRec.title === 'string' && targetRec.title !== '' ? targetRec.title : kitText('soma.kit.sf_done', undefined, ctx.locale);
|
|
385
314
|
const html = stepFormHtml(
|
|
@@ -396,5 +325,5 @@ export function compileStepForm(input: KitBizInput, ctx: KitBizContext): KitFrag
|
|
|
396
325
|
);
|
|
397
326
|
for (const c of classesIn(html)) out.candidates.add(c);
|
|
398
327
|
for (const c of Object.values(STEP_FORM_CLASS)) for (const t of c.split(/\s+/)) if (t !== '') out.candidates.add(t);
|
|
399
|
-
return
|
|
328
|
+
return finishBizCompile(out, html);
|
|
400
329
|
}
|
package/src/biz/step-form/hub.ts
CHANGED
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
//
|
|
26
26
|
// focus 切片值:{ step, total, done, busy, at: {s<i>}, past: {s<i>}, fut: {s<i>}, values: {s<i>: model}, seq, rid? }
|
|
27
27
|
|
|
28
|
-
import type {
|
|
28
|
+
import type { SomaComponentDefinition, SomaDataPort, SomaRegionPort } from 'soma-core';
|
|
29
|
+
import { createKitController } from '../../base/shared';
|
|
29
30
|
import { kitText } from '../../i18n/kit-text';
|
|
30
31
|
import { askKitConfirm } from '../../data/confirm-dialog';
|
|
31
|
-
import { registerKitStepValues } from '../shared/step-values';
|
|
32
32
|
|
|
33
33
|
/** 语义事件名(SCOPE | semantic 要求小写 snake_case) */
|
|
34
34
|
export const KIT_STEP_EVENTS = {
|
|
@@ -60,8 +60,6 @@ export const KIT_STEP_MIRRORS = {
|
|
|
60
60
|
fut: (i: number): { key: string; path: string; as: 'truthy' } => ({ key: `step_fut_${i}`, path: `fut.s${i}`, as: 'truthy' }),
|
|
61
61
|
values: (i: number): { key: string; path: string; as: 'value' } => ({ key: `step_vals_${i}`, path: `values.s${i}`, as: 'value' }),
|
|
62
62
|
done: { key: 'step_done', path: 'done', as: 'truthy' } as const,
|
|
63
|
-
/** 全部步骤已确认的 model(阶段闸门 steps.s<i>.字段 的取值来源;只有声明了 gate 才编入) */
|
|
64
|
-
allValues: { key: 'step_vals_all', path: 'values', as: 'value' } as const,
|
|
65
63
|
} as const;
|
|
66
64
|
|
|
67
65
|
type Rec = Record<string, unknown>;
|
|
@@ -208,17 +206,17 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
208
206
|
},
|
|
209
207
|
services: ['region', 'data', 'notify'],
|
|
210
208
|
templateHtml: '<div data-soma-id="root" class="hidden"></div>',
|
|
211
|
-
controllerFactory: (
|
|
209
|
+
controllerFactory: createKitController((api) => {
|
|
212
210
|
let off: (() => void) | undefined;
|
|
213
211
|
let alive = false;
|
|
214
|
-
const props = (): Rec =>
|
|
212
|
+
const props = (): Rec => api.props() as Rec;
|
|
215
213
|
const steps = (): string[] => strings(props().steps);
|
|
216
214
|
const dataPort = (): SomaDataPort | undefined => {
|
|
217
|
-
const port = (
|
|
215
|
+
const port = (api.services as { data?: SomaDataPort } | undefined)?.data;
|
|
218
216
|
return port && typeof port === 'object' ? port : undefined;
|
|
219
217
|
};
|
|
220
218
|
const toast = (level: string, message: string): void => {
|
|
221
|
-
const svc = (
|
|
219
|
+
const svc = (api.services as { notify?: { toast?: (o: { level: string; message: string }) => void } } | undefined)?.notify;
|
|
222
220
|
if (svc && typeof svc.toast === 'function') svc.toast({ level, message });
|
|
223
221
|
};
|
|
224
222
|
|
|
@@ -235,7 +233,7 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
235
233
|
if (cur.seq !== focus.seq) return;
|
|
236
234
|
if (result.ok) {
|
|
237
235
|
slice.set({ ...stepFocus(cur.step, cur.total, true, cur.values, cur.seq + 1) });
|
|
238
|
-
|
|
236
|
+
api.emit('saved', { result: result.data ?? {} });
|
|
239
237
|
return;
|
|
240
238
|
}
|
|
241
239
|
const errors = result.fieldErrors ?? {};
|
|
@@ -243,11 +241,11 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
243
241
|
const fields = rawFields.map((f) => strings(f));
|
|
244
242
|
const at = stepOfFirstError(errors, fields);
|
|
245
243
|
const first = Object.values(errors).find((m) => typeof m === 'string' && m !== '');
|
|
246
|
-
const message = first ?? (result.message !== '' ? result.message : kitText('soma.kit.step_failed', undefined,
|
|
244
|
+
const message = first ?? (result.message !== '' ? result.message : kitText('soma.kit.step_failed', undefined, api.host));
|
|
247
245
|
const back = at >= 0 ? at : cur.step;
|
|
248
246
|
slice.set(stepFocus(back, cur.total, false, cur.values, cur.seq + 1));
|
|
249
|
-
toast('danger', at >= 0 ? kitText('soma.kit.step_n_message', { n: at + 1, message },
|
|
250
|
-
if (back !== cur.step)
|
|
247
|
+
toast('danger', at >= 0 ? kitText('soma.kit.step_n_message', { n: at + 1, message }, api.host) : message);
|
|
248
|
+
if (back !== cur.step) api.emit('step_change', { step: back, total: cur.total });
|
|
251
249
|
};
|
|
252
250
|
|
|
253
251
|
/** perStep:保存一步;成功才前进(末步即完成态),失败停在本步(fieldErrors 指向更早的步则退回那一步),rid 不清 */
|
|
@@ -268,15 +266,15 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
268
266
|
const rawFields = Array.isArray(props().fields) ? (props().fields as unknown[]) : [];
|
|
269
267
|
const at = stepOfFirstError(fieldErrors, rawFields.map((f) => strings(f)));
|
|
270
268
|
const first = Object.values(fieldErrors).find((m) => typeof m === 'string' && m !== '');
|
|
271
|
-
const text = first ?? (message !== '' ? message : kitText('soma.kit.step_failed', undefined,
|
|
269
|
+
const text = first ?? (message !== '' ? message : kitText('soma.kit.step_failed', undefined, api.host));
|
|
272
270
|
const back = at >= 0 ? at : cur.step;
|
|
273
271
|
slice.set(stepFocus(back, cur.total, false, cur.values, cur.seq + 1, false, cur.rid));
|
|
274
|
-
toast('danger', at >= 0 ? kitText('soma.kit.step_n_message', { n: at + 1, message: text },
|
|
275
|
-
if (back !== cur.step)
|
|
272
|
+
toast('danger', at >= 0 ? kitText('soma.kit.step_n_message', { n: at + 1, message: text }, api.host) : text);
|
|
273
|
+
if (back !== cur.step) api.emit('step_change', { step: back, total: cur.total });
|
|
276
274
|
};
|
|
277
275
|
// 首步没有 rid 用 create,其余(含回到首步改后再下一步)用 update;update 必须带 rid
|
|
278
276
|
const creating = rid === undefined;
|
|
279
|
-
if (creating && job.idx !== 0) { fail(kitText('soma.kit.step_no_id', undefined,
|
|
277
|
+
if (creating && job.idx !== 0) { fail(kitText('soma.kit.step_no_id', undefined, api.host)); return; }
|
|
280
278
|
const result = creating
|
|
281
279
|
? await data.submit(object, job.model, 'create')
|
|
282
280
|
: await data.submit(object, { ...job.model, [stepKey]: rid }, 'update', { identityField: stepKey });
|
|
@@ -285,14 +283,14 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
285
283
|
if (cur.seq !== focus.seq) return; // 保存期间点了「重新开始」:过期回执不写回
|
|
286
284
|
if (!result.ok) { fail(result.message, result.fieldErrors ?? {}); return; }
|
|
287
285
|
const got = creating ? pickStepRid(result.data, stepKey) : rid;
|
|
288
|
-
if (got === undefined) { fail(kitText('soma.kit.step_no_id', undefined,
|
|
286
|
+
if (got === undefined) { fail(kitText('soma.kit.step_no_id', undefined, api.host)); return; }
|
|
289
287
|
if (job.last) {
|
|
290
288
|
slice.set(stepFocus(cur.step, cur.total, true, cur.values, cur.seq + 1, false, got));
|
|
291
|
-
|
|
289
|
+
api.emit('saved', { result: result.data ?? {}, id: String(got) });
|
|
292
290
|
return;
|
|
293
291
|
}
|
|
294
292
|
slice.set(stepFocus(job.idx + 1, cur.total, false, cur.values, cur.seq + 1, false, got));
|
|
295
|
-
|
|
293
|
+
api.emit('step_change', { step: job.idx + 1, total: cur.total });
|
|
296
294
|
};
|
|
297
295
|
|
|
298
296
|
/** abandon: delete:调首步对象已声明的 write.delete,主键取 focus.rid;失败照实 toast,返回是否删成 */
|
|
@@ -301,18 +299,18 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
301
299
|
const stepKey = typeof props().stepKey === 'string' ? (props().stepKey as string) : '';
|
|
302
300
|
const first = steps()[0] ?? '';
|
|
303
301
|
if (!data || focus.rid === undefined || first === '' || stepKey === '') {
|
|
304
|
-
toast('danger', kitText('soma.kit.step_abandon_failed', { message: kitText('soma.kit.step_failed', undefined,
|
|
302
|
+
toast('danger', kitText('soma.kit.step_abandon_failed', { message: kitText('soma.kit.step_failed', undefined, api.host) }, api.host));
|
|
305
303
|
return false;
|
|
306
304
|
}
|
|
307
305
|
slice.set({ ...focus, busy: true });
|
|
308
306
|
const result = await data.remove(first, { [stepKey]: focus.rid });
|
|
309
307
|
if (result.ok) return true;
|
|
310
|
-
toast('danger', kitText('soma.kit.step_abandon_failed', { message: result.message !== '' ? result.message : kitText('soma.kit.step_failed', undefined,
|
|
308
|
+
toast('danger', kitText('soma.kit.step_abandon_failed', { message: result.message !== '' ? result.message : kitText('soma.kit.step_failed', undefined, api.host) }, api.host));
|
|
311
309
|
return false;
|
|
312
310
|
};
|
|
313
311
|
// 放弃半成品的确认:自绘对话框(异步,danger 色调);无 DOM 时视为同意
|
|
314
312
|
const askAbandon = (): Promise<boolean> => askKitConfirm({
|
|
315
|
-
message: kitText('soma.kit.step_abandon_confirm', undefined,
|
|
313
|
+
message: kitText('soma.kit.step_abandon_confirm', undefined, api.host), tone: 'danger', at: api.host ?? null, whenNoDom: true,
|
|
316
314
|
});
|
|
317
315
|
|
|
318
316
|
/** 中途点「取消」且已保存过:二次确认 -> 删半成品 -> 成功回到初始;失败停在原地(保留状态,可重试或继续填) */
|
|
@@ -325,13 +323,12 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
325
323
|
if (cur.seq !== focus.seq) return; // 期间点了「重新开始」:过期回执不写回
|
|
326
324
|
if (!ok) { slice.set({ ...cur, busy: false }); return; }
|
|
327
325
|
slice.set(initialStepFocus(cur.total, cur.seq + 1));
|
|
328
|
-
toast('success', kitText('soma.kit.step_abandoned', undefined,
|
|
329
|
-
if (cur.step !== 0)
|
|
326
|
+
toast('success', kitText('soma.kit.step_abandoned', undefined, api.host));
|
|
327
|
+
if (cur.step !== 0) api.emit('step_change', { step: 0, total: cur.total });
|
|
330
328
|
};
|
|
331
329
|
|
|
332
330
|
/** 离开页面守卫(abandon: delete 且已有半成品、未完成时生效):站内链接二次确认后删半成品再走(删除失败照实报错,不拦离开);刷新 / 关闭只能走浏览器自带提示,来不及异步删除 */
|
|
333
331
|
let offGuard: (() => void) | undefined;
|
|
334
|
-
let offStepValues: (() => void) | undefined;
|
|
335
332
|
const installLeaveGuard = (slice: NonNullable<ReturnType<SomaRegionPort['slice']>>): void => {
|
|
336
333
|
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
|
337
334
|
const active = (): KitStepFocus | undefined => {
|
|
@@ -367,17 +364,14 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
367
364
|
};
|
|
368
365
|
|
|
369
366
|
return {
|
|
370
|
-
|
|
367
|
+
attach() {
|
|
371
368
|
alive = true;
|
|
372
369
|
const scope = typeof props().scope === 'string' ? (props().scope as string) : '';
|
|
373
|
-
const svc = (
|
|
370
|
+
const svc = (api.services as { region?: (id: string) => SomaRegionPort | null } | undefined)?.region;
|
|
374
371
|
const port = scope !== '' && typeof svc === 'function' ? svc(scope) : null;
|
|
375
372
|
const focus = port?.slice('focus');
|
|
376
373
|
if (!port || !focus) return;
|
|
377
374
|
focus.set(initialStepFocus(steps().length));
|
|
378
|
-
// GB1:登记各步已确认值的读口,request 动作的 $steps.s<i>.<字段> 经它取值
|
|
379
|
-
offStepValues?.();
|
|
380
|
-
offStepValues = registerKitStepValues(() => focusOf(focus.get(), steps().length).values);
|
|
381
375
|
offGuard?.();
|
|
382
376
|
offGuard = undefined;
|
|
383
377
|
if (props().saveMode === 'perStep' && props().abandon === 'delete') installLeaveGuard(focus);
|
|
@@ -387,24 +381,23 @@ export function createKitStepHub(): SomaComponentDefinition {
|
|
|
387
381
|
const r = reduceStepHub(now, name, payload, steps(), perStep);
|
|
388
382
|
if (r.focus !== now) {
|
|
389
383
|
focus.set(r.focus);
|
|
390
|
-
if (r.focus.step !== now.step)
|
|
384
|
+
if (r.focus.step !== now.step) api.emit('step_change', { step: r.focus.step, total: r.focus.total });
|
|
391
385
|
}
|
|
392
386
|
if (r.submit !== null) void submit(r.focus, port, r.submit);
|
|
393
387
|
if (r.save !== null) void saveStep(r.focus, port, r.save);
|
|
394
388
|
if (r.abort === 'delete' && props().abandon === 'delete') void abandon(focus, r.focus);
|
|
395
389
|
});
|
|
390
|
+
return () => {
|
|
391
|
+
alive = false;
|
|
392
|
+
offGuard?.();
|
|
393
|
+
offGuard = undefined;
|
|
394
|
+
if (off) off();
|
|
395
|
+
off = undefined;
|
|
396
|
+
};
|
|
396
397
|
},
|
|
397
|
-
|
|
398
|
-
alive = false;
|
|
399
|
-
offGuard?.();
|
|
400
|
-
offGuard = undefined;
|
|
401
|
-
offStepValues?.();
|
|
402
|
-
offStepValues = undefined;
|
|
403
|
-
if (off) off();
|
|
404
|
-
off = undefined;
|
|
405
|
-
},
|
|
398
|
+
render() {},
|
|
406
399
|
};
|
|
407
|
-
},
|
|
400
|
+
}),
|
|
408
401
|
};
|
|
409
402
|
}
|
|
410
403
|
|
package/src/biz/types.ts
CHANGED
|
@@ -37,10 +37,9 @@ export interface KitOverlayDecl {
|
|
|
37
37
|
schema?: KitObject['schema'];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/**
|
|
40
|
+
/** 浮层事件绑具名动作:`{ action: 具名动作 }`(单管道;动作之后的提示 / 重取 / 关窗写在具名动作处理函数里) */
|
|
41
41
|
export interface KitOverlayEventAction {
|
|
42
42
|
action: string;
|
|
43
|
-
then?: 'saved' | 'close' | 'reload';
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
export interface KitBizInput {
|
|
@@ -66,7 +65,7 @@ export interface KitBizContext {
|
|
|
66
65
|
/** 已登记的基础组件名(内置 13 个 + App*) */
|
|
67
66
|
registeredComponents: ReadonlySet<string>;
|
|
68
67
|
/** 已登记的写死形状数据组件 */
|
|
69
|
-
staticComponents: Record<string, { accept: 'single' | 'list'; emits?: readonly string[]; props?: readonly string[] }>;
|
|
68
|
+
staticComponents: Record<string, { accept: 'single' | 'list'; emits?: readonly string[]; props?: readonly string[]; propTypes?: Readonly<Record<string, string>> }>;
|
|
70
69
|
/** 页面语言(`page.locale`,缺省应用 defaultLocale;未声明为空串):业务组件写进产物的内置文案按它取(`kitText(key, params, ctx.locale)`) */
|
|
71
70
|
locale?: string;
|
|
72
71
|
}
|
|
@@ -77,6 +76,8 @@ export interface KitBizRole {
|
|
|
77
76
|
views: Array<'list' | 'summary' | 'filter' | 'form'>;
|
|
78
77
|
/** 对象表(如 `subs.*`):值是「名字 -> 对象」 */
|
|
79
78
|
many?: boolean;
|
|
79
|
+
/** 该角色下对象声明允许的额外顶层键(如看板面板的 title / span / class、详情主记录的 subsLayout) */
|
|
80
|
+
extraKeys?: readonly string[];
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
export interface KitBizDefinition {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// AP-1(应用代码不直接 import soma-core*)在 kit 线的检查:`soma kit check` 递归扫描应用根下的 js/ts 源码,
|
|
2
|
+
// 命中即报 KIT-APP-013(诊断带文件、行号与改用 soma-kit/app 的建议)。规则册闸门 G84。
|
|
3
|
+
// 跳过:node_modules、.soma、tests/、test/(测试允许 import core 内部名校验产物)与其他点目录、构建产物目录。
|
|
4
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
5
|
+
|
|
6
|
+
const SKIP_DIRS = new Set(['node_modules', 'tests', 'test', 'dist', 'build', 'coverage']);
|
|
7
|
+
/** import / import type / export … from / 动态 import() / require() 里的 soma-core 或 soma-core/* 说明符 */
|
|
8
|
+
const IMPORT_CORE = /(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)['"](soma-core(?:\/[^'"]*)?)['"]/g;
|
|
9
|
+
|
|
10
|
+
/** 扫描应用根目录;返回 KIT-APP-013 诊断(按文件名、行号有序);目录读不到当作空 */
|
|
11
|
+
export async function scanKitCoreImports(appDir: string): Promise<KitDiagnostic[]> {
|
|
12
|
+
const path = await import(/* webpackIgnore: true */ 'node:path');
|
|
13
|
+
const fs = await import(/* webpackIgnore: true */ 'node:fs');
|
|
14
|
+
const root = path.resolve(appDir);
|
|
15
|
+
const out: KitDiagnostic[] = [];
|
|
16
|
+
const walk = (dir: string): void => {
|
|
17
|
+
let entries: import('node:fs').Dirent[];
|
|
18
|
+
try {
|
|
19
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
24
|
+
const full = path.join(dir, e.name);
|
|
25
|
+
if (e.isDirectory()) {
|
|
26
|
+
if (!SKIP_DIRS.has(e.name) && !e.name.startsWith('.')) walk(full);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (!/\.[cm]?[jt]sx?$/.test(e.name) || /\.d\.[cm]?ts$/.test(e.name)) continue;
|
|
30
|
+
let text: string;
|
|
31
|
+
try {
|
|
32
|
+
text = fs.readFileSync(full, 'utf8');
|
|
33
|
+
} catch {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const file = path.relative(root, full).split(path.sep).join('/');
|
|
37
|
+
text.split('\n').forEach((lineText, i) => {
|
|
38
|
+
for (const m of lineText.matchAll(IMPORT_CORE)) {
|
|
39
|
+
out.push({
|
|
40
|
+
code: 'KIT-APP-013',
|
|
41
|
+
path: `${file}:${i + 1}`,
|
|
42
|
+
file,
|
|
43
|
+
line: i + 1,
|
|
44
|
+
column: (m.index ?? 0) + 1,
|
|
45
|
+
message: `应用代码直接 import '${m[1]}'(AP-1:应用不直接依赖 soma-core*)`,
|
|
46
|
+
hint: `改为从 'soma-kit/app' 取用(装配名字在 soma-kit/app,服务端名字在 soma-kit/app/server)`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
walk(root);
|
|
53
|
+
return out;
|
|
54
|
+
}
|