soma-kit 0.1.12 → 0.1.13
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 +5 -4
- package/bin/soma-kit.mjs +31 -1
- package/bin/soma.mjs +0 -0
- package/package.json +5 -4
- package/spec/generated/kit-app.schema.json +158 -4
- package/spec/generated/kit-page.schema.json +139 -5
- package/spec/kit-grammar.json +438 -87
- package/spec/kit-grammar.schema.json +11 -3
- package/src/app/app-config.ts +83 -5
- package/src/app/component-gate.ts +271 -13
- package/src/app/define-kit-app.ts +2 -2
- package/src/app/define-kit-view.ts +9 -5
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/index.ts +17 -5
- package/src/app/kit-view-context.ts +163 -14
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +3 -1
- package/src/app/server.ts +40 -3
- package/src/app/theme-runtime.ts +4 -0
- package/src/base/action-busy.ts +101 -4
- package/src/base/action-slots.ts +13 -2
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/button.ts +57 -12
- package/src/base/check-core.ts +8 -0
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +21 -2
- package/src/base/color-picker.ts +10 -5
- package/src/base/command-palette.ts +1 -1
- package/src/base/context-menu.ts +10 -7
- package/src/base/date-range.ts +7 -7
- package/src/base/date.ts +55 -16
- package/src/base/delta.ts +72 -0
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/index.ts +27 -9
- package/src/base/listbox-core.ts +6 -5
- package/src/base/loading-gate.ts +140 -87
- package/src/base/mentions.ts +2 -1
- package/src/base/menu-button.ts +23 -12
- package/src/base/menu-core.ts +37 -8
- package/src/base/motion/hover-3d.ts +1 -1
- package/src/base/motion/marquee.ts +1 -1
- package/src/base/otp.ts +5 -4
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/popover.ts +9 -9
- package/src/base/popup.ts +67 -8
- package/src/base/portal-core.ts +4 -0
- package/src/base/qty-stepper.ts +5 -5
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +19 -2
- package/src/base/rating.ts +11 -6
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +24 -22
- package/src/base/shared.ts +169 -23
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +6 -6
- package/src/base/switch.ts +10 -5
- package/src/base/tag-input.ts +6 -6
- package/src/base/tag.ts +63 -33
- package/src/base/text.ts +42 -13
- package/src/base/time-picker.ts +7 -5
- package/src/base/tree-select.ts +6 -4
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +15 -10
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +2 -2
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/import-wizard/shell.ts +2 -1
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +102 -10
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +4 -1
- package/src/biz/multi-board/shell.ts +8 -5
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +18 -0
- package/src/biz/shared/coordinator.ts +7 -30
- package/src/biz/shared/index.ts +5 -0
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +139 -10
- package/src/biz/shared/pipes.ts +11 -5
- package/src/biz/shared/remove-wire.ts +4 -19
- package/src/biz/shared/runtime-hub.ts +10 -0
- package/src/biz/single-form/compile.ts +3 -2
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +22 -160
- package/src/biz/standard-crud/shell.ts +16 -44
- package/src/biz/step-form/shell.ts +5 -5
- package/src/cli/kit-cli.ts +138 -13
- package/src/cli/kit-init.ts +6 -1
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/view-writes.ts +69 -60
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +51 -7
- package/src/compile/component-candidates.ts +12 -1
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +36 -8
- package/src/compile/types.ts +13 -1
- package/src/compile/view-check.ts +149 -16
- package/src/data/amount-breakdown.ts +6 -1
- package/src/data/approval-flow.ts +1 -1
- package/src/data/assignment-picker.ts +53 -27
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +2 -2
- package/src/data/carousel.ts +8 -6
- package/src/data/chart.ts +141 -10
- package/src/data/checklist.ts +18 -5
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +2 -2
- package/src/data/confirm-dialog.ts +71 -18
- package/src/data/context-menu.ts +3 -3
- package/src/data/dock.ts +1 -1
- package/src/data/embed.ts +231 -29
- package/src/data/field-mapper.ts +4 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +25 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/gantt.ts +5 -2
- package/src/data/hero.ts +2 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +6 -1
- package/src/data/item-list.ts +18 -10
- package/src/data/kanban.ts +39 -10
- package/src/data/media-grid.ts +6 -1
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +45 -13
- package/src/data/mockup.ts +8 -4
- package/src/data/modal-dialog.ts +29 -9
- package/src/data/navbar.ts +5 -5
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +354 -48
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +17 -7
- package/src/data/permission-matrix.ts +33 -11
- package/src/data/permission-tree.ts +47 -22
- package/src/data/pricing-table.ts +21 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +23 -2
- package/src/data/record-picker.ts +13 -7
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +79 -26
- package/src/data/rule-builder.ts +8 -8
- package/src/data/shape-util.ts +23 -9
- package/src/data/stat-group.ts +170 -29
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +2 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +3 -3
- package/src/data/system-switcher.ts +1 -1
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +1 -1
- package/src/data/transfer.ts +36 -16
- package/src/data/tree-table.ts +62 -36
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +19 -10
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/page-bar.ts +14 -13
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +15 -10
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +2 -1
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +2 -2
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +2 -2
- package/src/frames/workspace-frame/view.ts +141 -33
- package/src/generated/kit-grammar-runtime.ts +239 -55
- package/src/i18n/kit-text.ts +63 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/arrange.ts +42 -8
- package/src/object-renderer/collection-parts.ts +241 -60
- package/src/object-renderer/collection-table.ts +109 -5
- package/src/object-renderer/collection.ts +174 -36
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +30 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-static.ts +370 -30
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/render-object.ts +54 -6
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +135 -27
- package/src/object-renderer/table-tools.ts +12 -11
- package/src/object-renderer/types.ts +78 -7
- package/src/object-renderer/view-binding.ts +205 -8
- package/src/page-target/intent-schema.ts +11 -0
- package/src/page-target/target.ts +5 -1
- package/src/recipes/container.ts +46 -1
- package/src/recipes/control.ts +70 -12
- package/src/recipes/index.ts +49 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +75 -17
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +34 -5
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +40 -3
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +13 -1
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +2 -2
- package/src/shared/paged-list-adapter.ts +15 -240
- package/src/shared/theme-runtime-shared.ts +6 -1
- package/src/theme/index.ts +1 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +372 -12
- package/src/theme/kit-theme.tpl +372 -12
- package/src/theme/nine-dim-structure.ts +177 -7
- package/src/theme/surface-layers.ts +4 -0
- package/src/theme/theme-tokens.ts +53 -13
- package/src/theme/theme-types.ts +32 -0
- package/src/biz/shared/remove-key.ts +0 -6
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
// · unwrap:详情在响应里的点路径;缺省按应用声明的信封约定(kit.app.yaml#envelope:failWhen 判失败、dataPath 拆数据)。
|
|
6
6
|
// 取数成功用「行 + 详情(详情盖行)」作表单初值;取数中只显示处理中状态;失败照实报错并给重试,不渲染表单。
|
|
7
7
|
|
|
8
|
-
import { isBizFailure, unwrapBizEnvelope } from '../shared/
|
|
9
|
-
import { envelopeMessage, getCompileEnvelope, type KitEnvelope } from '../shared/envelope';
|
|
8
|
+
import { envelopeMessage, getCompileEnvelope, isEnvelopeFailure as isBizFailure, unwrapEnvelope as unwrapBizEnvelope, type KitEnvelope } from '../shared/envelope';
|
|
10
9
|
import { checkNoRelativeOrSystemPath } from '../shared/path-guard';
|
|
11
10
|
import { KIT_GRAMMAR } from './defaults';
|
|
12
11
|
import type { KitDiagnostic } from './types';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// 表单保存成功提示(view.form.notify):页面只写一段字面量文案,替换默认「已保存」类提示。
|
|
2
|
+
//
|
|
3
|
+
// 唯一实现:业务组件(SingleObjectForm / CheckoutPage / SettingsCenter)发 `<表单>.saved` 事件管道 `NOTIFY | success | <文案>` 时都经 `savedNoticePipe` 取文案;
|
|
4
|
+
// 对象渲染(render-object 的视图文本校验)经 `formNotifyProblem` 判写法。含义与请求动作 `request.notify` 相同(成功提示的文案),
|
|
5
|
+
// 但这里只许字面量:不是 view. / row. 路径、不是 {…} 占位、不含管道符,也不与 core 事件管道的可选段前缀撞车。
|
|
6
|
+
// 空串 / 空白 / 未写 = 没写:默认文案与输出与没有该键时逐字节相同。
|
|
7
|
+
|
|
8
|
+
/** core 事件管道的可选段(出现在第三段之外的位置会被当成选项吞掉,文案不能与它们相撞) */
|
|
9
|
+
const RESERVED_SEGMENT = /^(force$|confirm:|permission:|roles:)/;
|
|
10
|
+
|
|
11
|
+
/** 文案写法有问题时返回原因;写法合法(含空串 / 未写)返回 null */
|
|
12
|
+
export function formNotifyProblem(raw: unknown): string | null {
|
|
13
|
+
if (raw === undefined) return null;
|
|
14
|
+
if (typeof raw !== 'string') return 'notify 必须是字符串字面量(保存成功的提示文案)';
|
|
15
|
+
const text = raw.trim();
|
|
16
|
+
if (text === '') return null;
|
|
17
|
+
if (text.includes('|')) return 'notify 不许含管道符 |';
|
|
18
|
+
if (text.includes('{') || text.includes('}')) return 'notify 只许字面量,不许 {…} 占位(要拼值请由接口 / 展示对象给成品文案)';
|
|
19
|
+
if (/^(view|row|page)\./.test(text) || text.startsWith('$')) return 'notify 只许字面量,不许 view. / row. / page. / $ 路径';
|
|
20
|
+
if (RESERVED_SEGMENT.test(text)) return 'notify 不能以 force / confirm: / permission: / roles: 开头(与事件管道的可选段冲突)';
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 展示对象 `ctx.notify` 的成品文案(运行期值,不是页面字面量):去首尾空白,剔除管道符 |(与上面 `notify` 不许含 | 同一条规则,
|
|
26
|
+
* 避免文案被事件管道切段);不是字符串或处理后为空返回 null(调用方当「没有可提示的」处理)。
|
|
27
|
+
*/
|
|
28
|
+
export function runtimeNoticeText(raw: unknown): string | null {
|
|
29
|
+
if (typeof raw !== 'string') return null;
|
|
30
|
+
const text = raw.replace(/\|/g, '').trim();
|
|
31
|
+
return text === '' ? null : text;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 取这个表单的保存成功文案:写了合法字面量用它(去首尾空白),否则用默认文案 */
|
|
35
|
+
export function savedNoticeText(formView: unknown, fallback: string): string {
|
|
36
|
+
const raw = typeof formView === 'object' && formView !== null ? (formView as { notify?: unknown }).notify : undefined;
|
|
37
|
+
if (typeof raw !== 'string' || formNotifyProblem(raw) !== null) return fallback;
|
|
38
|
+
const text = raw.trim();
|
|
39
|
+
return text === '' ? fallback : text;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 表单 `saved` 事件的管道:`NOTIFY | success | <文案>`(业务组件发射保存成功提示的唯一出口) */
|
|
43
|
+
export function savedNoticePipe(formView: unknown, fallback: string): string {
|
|
44
|
+
return `NOTIFY | success | ${savedNoticeText(formView, fallback)}`;
|
|
45
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
// 布局事实适配(RV-1117 T04):kit 页面声明(解析后的 KitPageDecl)→ 与方言无关的「内容事实」(类型、标签、选项、max_len、角色、显式覆写)。
|
|
2
|
+
// 纯函数、只读:不改声明、不产类名、不碰发射。下游:layout-plan.ts(求解)与 compile/layout-lint(体检)。
|
|
3
|
+
// 角色推断读 foundation 生成的 field-roles 真源(SOMA_PIPELINE_FIELD_ROLES.inference:键名别名 × 类型),不另写一份表。
|
|
4
|
+
|
|
5
|
+
import { SOMA_PIPELINE_FIELD_ROLES } from 'soma-foundation/data/generated';
|
|
6
|
+
import type { KitPanelKind } from 'soma-foundation/kit-layout';
|
|
7
|
+
import type { KitPageDecl, KitProductDecl, KitTabDecl } from '../compile/types';
|
|
8
|
+
import { normalizeRef } from './arrange';
|
|
9
|
+
import type { KitFieldRef, KitType, KitViewSlot } from './types';
|
|
10
|
+
|
|
11
|
+
type Rec = Record<string, unknown>;
|
|
12
|
+
const isRec = (v: unknown): v is Rec => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
13
|
+
const str = (v: unknown): string | undefined => (typeof v === 'string' ? v : undefined);
|
|
14
|
+
const num = (v: unknown): number | undefined => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
|
|
15
|
+
|
|
16
|
+
const KIT_TYPE_NAMES: readonly string[] = ['text', 'longtext', 'int', 'decimal', 'money', 'percent', 'bool', 'enum', 'enums', 'date', 'datetime', 'daterange'];
|
|
17
|
+
|
|
18
|
+
// ─── 事实类型 ───
|
|
19
|
+
|
|
20
|
+
export interface KitFactField {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly label: string;
|
|
23
|
+
readonly type: KitType;
|
|
24
|
+
readonly maxLen: number | null;
|
|
25
|
+
/** 静态枚举候选的文案;远程候选 / 无候选为 undefined */
|
|
26
|
+
readonly options?: readonly string[];
|
|
27
|
+
/** 静态候选里是否有任何一项带 tone */
|
|
28
|
+
readonly optionTones: boolean;
|
|
29
|
+
/** 候选文案是否以符号开头(038) */
|
|
30
|
+
readonly optionLabelsWithSymbol: readonly string[];
|
|
31
|
+
/** 作者写的组件名(component,或 schema 的 show / edit) */
|
|
32
|
+
readonly component?: string;
|
|
33
|
+
readonly sortable: boolean;
|
|
34
|
+
readonly columnFilter: boolean;
|
|
35
|
+
readonly width: number | null;
|
|
36
|
+
readonly align: 'start' | 'center' | 'end' | null;
|
|
37
|
+
readonly fixed: boolean;
|
|
38
|
+
readonly span: number | null;
|
|
39
|
+
readonly emphasis: 'strong' | 'muted' | null;
|
|
40
|
+
readonly highlight: boolean;
|
|
41
|
+
readonly roles: readonly string[];
|
|
42
|
+
readonly path: string;
|
|
43
|
+
/** 作者在该字段项上写的类(class / labelClass / valueClass) */
|
|
44
|
+
readonly classes: ReadonlyArray<{ readonly key: string; readonly value: string; readonly path: string }>;
|
|
45
|
+
readonly isDivider: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface KitFactAction {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly on: 'row' | 'toolbar' | 'field' | string;
|
|
52
|
+
readonly tone: string | null;
|
|
53
|
+
readonly more: boolean;
|
|
54
|
+
readonly danger: boolean;
|
|
55
|
+
readonly primary: boolean;
|
|
56
|
+
readonly path: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface KitFactGroup {
|
|
60
|
+
readonly title: string;
|
|
61
|
+
readonly fields: readonly KitFactField[];
|
|
62
|
+
readonly surface: string | null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface KitFactView {
|
|
66
|
+
readonly slot: KitViewSlot;
|
|
67
|
+
readonly path: string;
|
|
68
|
+
readonly fields: readonly KitFactField[];
|
|
69
|
+
readonly groups: readonly KitFactGroup[];
|
|
70
|
+
readonly explicitCols: number | null;
|
|
71
|
+
readonly collapsible: boolean | null;
|
|
72
|
+
readonly collapsedRows: number | null;
|
|
73
|
+
readonly defaultCollapsedCount: number | null;
|
|
74
|
+
readonly labelPosition: string | null;
|
|
75
|
+
readonly labelWidth: number | null;
|
|
76
|
+
/** list 槽:集合形态;其余槽为 null */
|
|
77
|
+
readonly collection: 'table' | 'treeTable' | 'cards' | 'stack' | 'compact-list' | null;
|
|
78
|
+
readonly rowActionIds: readonly string[];
|
|
79
|
+
readonly select: boolean;
|
|
80
|
+
readonly hasFixedColumn: boolean;
|
|
81
|
+
readonly hasColumnsTool: boolean;
|
|
82
|
+
readonly hasExpand: boolean;
|
|
83
|
+
readonly staticComponent: string | null;
|
|
84
|
+
readonly staticItems: ReadonlyArray<{ readonly hasTrend: boolean }> | null;
|
|
85
|
+
readonly emphasis: string | null;
|
|
86
|
+
readonly surface: string | null;
|
|
87
|
+
readonly classes: ReadonlyArray<{ readonly key: string; readonly value: string; readonly path: string }>;
|
|
88
|
+
readonly hasOn: boolean;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface KitFactObject {
|
|
92
|
+
/** 例 `main.entity` / `main.panels.stat` */
|
|
93
|
+
readonly path: string;
|
|
94
|
+
readonly role: string;
|
|
95
|
+
readonly name: string | null;
|
|
96
|
+
readonly isPanel: boolean;
|
|
97
|
+
readonly title: string | null;
|
|
98
|
+
readonly panelSpan: number | null;
|
|
99
|
+
readonly panelKind: KitPanelKind;
|
|
100
|
+
readonly views: readonly KitFactView[];
|
|
101
|
+
readonly actions: readonly KitFactAction[];
|
|
102
|
+
readonly schemaFieldNames: readonly string[];
|
|
103
|
+
readonly emphasis: string | null;
|
|
104
|
+
readonly surface: string | null;
|
|
105
|
+
readonly classes: ReadonlyArray<{ readonly key: string; readonly value: string; readonly path: string }>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface KitFactProduct {
|
|
109
|
+
readonly path: string;
|
|
110
|
+
readonly slot: string;
|
|
111
|
+
readonly kind: string;
|
|
112
|
+
readonly objects: readonly KitFactObject[];
|
|
113
|
+
readonly surface: string | null;
|
|
114
|
+
readonly classes: ReadonlyArray<{ readonly key: string; readonly value: string; readonly path: string }>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface KitPageFacts {
|
|
118
|
+
readonly title: string;
|
|
119
|
+
readonly subtitle: string | null;
|
|
120
|
+
readonly url: string;
|
|
121
|
+
readonly frameKind: string;
|
|
122
|
+
readonly maxWidth: string | null;
|
|
123
|
+
readonly products: readonly KitFactProduct[];
|
|
124
|
+
readonly tabsDepth: number;
|
|
125
|
+
readonly frameClasses: ReadonlyArray<{ readonly key: string; readonly value: string; readonly path: string }>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ─── 抽取 ───
|
|
129
|
+
|
|
130
|
+
const SYMBOL_START = /^[\s]*[■-➿⭐⭕]/u;
|
|
131
|
+
|
|
132
|
+
/** 字段角色推断(field-roles#inference):键名(小写、去下划线连字符)命中别名且类型在允许集里。 */
|
|
133
|
+
export function inferFieldRoles(key: string, type: string): string[] {
|
|
134
|
+
const normalized = key.toLowerCase().replace(/[_-]/g, '');
|
|
135
|
+
const out: string[] = [];
|
|
136
|
+
const inference = SOMA_PIPELINE_FIELD_ROLES.inference as unknown as Record<string, { aliases: readonly string[]; types: readonly string[] }>;
|
|
137
|
+
const typeKey = type === 'decimal' ? 'float' : type;
|
|
138
|
+
for (const [role, rule] of Object.entries(inference)) {
|
|
139
|
+
if (rule.aliases.includes(normalized) && (rule.types.includes(typeKey) || rule.types.includes(type))) out.push(role);
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function classSites(raw: Rec | undefined, at: string, keys: readonly string[]): Array<{ key: string; value: string; path: string }> {
|
|
145
|
+
const out: Array<{ key: string; value: string; path: string }> = [];
|
|
146
|
+
if (raw === undefined) return out;
|
|
147
|
+
for (const key of keys) {
|
|
148
|
+
const value = str(raw[key]);
|
|
149
|
+
if (value !== undefined && value.trim() !== '') out.push({ key, value, path: `${at}.${key}` });
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function fieldFact(ref: KitFieldRef, schema: Rec, at: string): KitFactField {
|
|
155
|
+
const raw = ref as unknown as Rec;
|
|
156
|
+
if (raw.divider !== undefined) {
|
|
157
|
+
return { name: '', label: '', type: 'text', maxLen: null, optionTones: false, optionLabelsWithSymbol: [], sortable: false, columnFilter: false, width: null, align: null, fixed: false, span: null, emphasis: null, highlight: false, roles: [], path: at, classes: [], isDivider: true };
|
|
158
|
+
}
|
|
159
|
+
const def = isRec(schema[ref.name]) ? (schema[ref.name] as Rec) : {};
|
|
160
|
+
const typeRaw = str(def.type) ?? 'text';
|
|
161
|
+
const type = (KIT_TYPE_NAMES.includes(typeRaw) ? typeRaw : 'text') as KitType;
|
|
162
|
+
let maxLen: number | null = null;
|
|
163
|
+
if (Array.isArray(def.rules)) {
|
|
164
|
+
for (const r of def.rules) {
|
|
165
|
+
if (!isRec(r)) continue;
|
|
166
|
+
const v = num(r.max_len) ?? num(r.maxLength);
|
|
167
|
+
if (v !== undefined) maxLen = maxLen === null ? v : Math.min(maxLen, v);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let options: string[] | undefined;
|
|
171
|
+
let optionTones = false;
|
|
172
|
+
const optionLabelsWithSymbol: string[] = [];
|
|
173
|
+
if (Array.isArray(def.options)) {
|
|
174
|
+
options = [];
|
|
175
|
+
for (const o of def.options) {
|
|
176
|
+
if (!isRec(o)) continue;
|
|
177
|
+
const label = str(o.label) ?? String(o.value ?? '');
|
|
178
|
+
options.push(label);
|
|
179
|
+
if (o.tone !== undefined) optionTones = true;
|
|
180
|
+
if (SYMBOL_START.test(label)) optionLabelsWithSymbol.push(label);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const component = str(raw.component) ?? str(def.show) ?? str(def.edit);
|
|
184
|
+
const align = raw.align === 'start' || raw.align === 'center' || raw.align === 'end' ? raw.align : null;
|
|
185
|
+
const emphasis = raw.emphasis === 'strong' || raw.emphasis === 'muted' ? raw.emphasis : def.emphasis === 'strong' || def.emphasis === 'muted' ? (def.emphasis as 'strong' | 'muted') : null;
|
|
186
|
+
return {
|
|
187
|
+
name: ref.name,
|
|
188
|
+
label: str(raw.label) ?? str(def.name) ?? ref.name,
|
|
189
|
+
type,
|
|
190
|
+
maxLen,
|
|
191
|
+
...(options !== undefined ? { options } : {}),
|
|
192
|
+
optionTones,
|
|
193
|
+
optionLabelsWithSymbol,
|
|
194
|
+
...(component !== undefined ? { component } : {}),
|
|
195
|
+
sortable: raw.sortable === true,
|
|
196
|
+
columnFilter: raw.columnFilter === true || raw.columnFilter === 'enum' || raw.columnFilter === 'text',
|
|
197
|
+
width: num(raw.width) ?? null,
|
|
198
|
+
align,
|
|
199
|
+
fixed: raw.fixed === 'left' || raw.fixed === 'right',
|
|
200
|
+
span: num(raw.span) ?? null,
|
|
201
|
+
emphasis,
|
|
202
|
+
highlight: raw.highlight === true || def.highlight === true,
|
|
203
|
+
roles: inferFieldRoles(ref.name, type),
|
|
204
|
+
path: at,
|
|
205
|
+
classes: classSites(raw, at, ['class', 'labelClass', 'valueClass']),
|
|
206
|
+
isDivider: false,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function fieldsOf(items: unknown, schema: Rec, at: string): KitFactField[] {
|
|
210
|
+
if (!Array.isArray(items)) return [];
|
|
211
|
+
const out: KitFactField[] = [];
|
|
212
|
+
items.forEach((item, i) => {
|
|
213
|
+
if (item === null || (typeof item !== 'string' && typeof item !== 'object')) return;
|
|
214
|
+
const f = fieldFact(normalizeRef(item as never), schema, `${at}[${i}]`);
|
|
215
|
+
if (!f.isDivider) out.push(f);
|
|
216
|
+
});
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** 缺省字段集合(视图没写 fields 时,按 kit 缺省:list = 非主键、summary = 全部、form = 可写)。 */
|
|
221
|
+
function defaultFieldNames(slot: KitViewSlot, schema: Rec): string[] {
|
|
222
|
+
const entries = Object.entries(schema).filter(([, d]) => isRec(d));
|
|
223
|
+
if (slot === 'list') return entries.filter(([, d]) => (d as Rec).key !== true).map(([k]) => k);
|
|
224
|
+
if (slot === 'summary') return entries.map(([k]) => k);
|
|
225
|
+
if (slot === 'form') return entries.filter(([, d]) => { const p = (d as Rec).permission ?? (d as Rec).access; return p === 'w' || p === 'write' || p === 'create'; }).map(([k]) => k);
|
|
226
|
+
return [];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function viewFact(slot: KitViewSlot, raw: Rec, schema: Rec, at: string): KitFactView {
|
|
230
|
+
const groups: KitFactGroup[] = [];
|
|
231
|
+
if (Array.isArray(raw.groups)) {
|
|
232
|
+
raw.groups.forEach((g, gi) => {
|
|
233
|
+
if (!isRec(g)) return;
|
|
234
|
+
groups.push({ title: str(g.title) ?? '', fields: fieldsOf(g.fields, schema, `${at}.groups[${gi}].fields`), surface: str(g.surface) ?? null });
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
let fields = fieldsOf(raw.fields, schema, `${at}.fields`);
|
|
238
|
+
if (raw.fields === undefined && groups.length === 0 && raw.staticComponent === undefined) {
|
|
239
|
+
fields = fieldsOf(defaultFieldNames(slot, schema), schema, `${at}.fields`);
|
|
240
|
+
}
|
|
241
|
+
const collection = isRec(raw.collection) ? raw.collection : undefined;
|
|
242
|
+
const collectionType = slot === 'list' && raw.staticComponent === undefined ? (str(collection?.type) as KitFactView['collection'] | undefined) ?? 'table' : null;
|
|
243
|
+
const arrange = isRec(raw.arrange) ? raw.arrange : undefined;
|
|
244
|
+
const rowActionsRaw = Array.isArray(raw.rowActions) ? raw.rowActions : Array.isArray(collection?.rowActions) ? (collection?.rowActions as unknown[]) : [];
|
|
245
|
+
const toolbar = Array.isArray(collection?.toolbar) ? (collection?.toolbar as unknown[]) : [];
|
|
246
|
+
const select = collection?.select;
|
|
247
|
+
const items = isRec(raw.props) && Array.isArray(raw.props.items) ? raw.props.items : undefined;
|
|
248
|
+
const allFields = [...fields, ...groups.flatMap((g) => g.fields)];
|
|
249
|
+
return {
|
|
250
|
+
slot,
|
|
251
|
+
path: at,
|
|
252
|
+
fields,
|
|
253
|
+
groups,
|
|
254
|
+
explicitCols: num(arrange?.cols) ?? null,
|
|
255
|
+
collapsible: typeof raw.collapsible === 'boolean' ? raw.collapsible : null,
|
|
256
|
+
collapsedRows: num(raw.collapsedRows) ?? null,
|
|
257
|
+
defaultCollapsedCount: num(raw.defaultCollapsedCount) ?? null,
|
|
258
|
+
labelPosition: str(raw.labelPosition) ?? null,
|
|
259
|
+
labelWidth: num(raw.labelWidth) ?? null,
|
|
260
|
+
collection: collectionType === undefined ? null : collectionType,
|
|
261
|
+
rowActionIds: rowActionsRaw.filter((x): x is string => typeof x === 'string').map((x) => (x.startsWith('@') ? x.slice(1) : x)),
|
|
262
|
+
select: select === 'single' || select === 'multi' || (isRec(select) && (select.mode === 'single' || select.mode === 'multi')),
|
|
263
|
+
hasFixedColumn: allFields.some((f) => f.fixed),
|
|
264
|
+
hasColumnsTool: toolbar.includes('columns'),
|
|
265
|
+
hasExpand: collection?.expand !== undefined,
|
|
266
|
+
staticComponent: str(raw.staticComponent) ?? null,
|
|
267
|
+
staticItems: items === undefined ? null : items.map((it) => ({ hasTrend: isRec(it) && it.trend !== undefined })),
|
|
268
|
+
emphasis: str(raw.emphasis) ?? null,
|
|
269
|
+
surface: str(raw.surface) ?? null,
|
|
270
|
+
classes: classSites(raw, at, ['class', 'cellClass', 'rowClass', 'replaceClass']),
|
|
271
|
+
hasOn: isRec(raw.on) && Object.keys(raw.on).length > 0,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function actionFacts(behavior: unknown, at: string): KitFactAction[] {
|
|
276
|
+
if (!isRec(behavior) || !Array.isArray(behavior.actions)) return [];
|
|
277
|
+
const out: KitFactAction[] = [];
|
|
278
|
+
behavior.actions.forEach((a, i) => {
|
|
279
|
+
if (!isRec(a) || typeof a.id !== 'string') return;
|
|
280
|
+
const tone = str(a.tone) ?? null;
|
|
281
|
+
out.push({
|
|
282
|
+
id: a.id,
|
|
283
|
+
name: str(a.name) ?? a.id,
|
|
284
|
+
on: str(a.on) ?? '',
|
|
285
|
+
tone,
|
|
286
|
+
more: a.more === true,
|
|
287
|
+
danger: tone === 'danger' || a.builtin === 'remove',
|
|
288
|
+
primary: tone === 'primary',
|
|
289
|
+
path: `${at}.behavior.actions[${i}]`,
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
return out;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const PANEL_KIND_BY_STATIC: Readonly<Record<string, KitPanelKind>> = { StatGroup: 'metric', Chart: 'chart' };
|
|
296
|
+
|
|
297
|
+
function panelKindOf(views: readonly KitFactView[]): KitPanelKind {
|
|
298
|
+
const first = views[0];
|
|
299
|
+
if (first === undefined) return 'unknown';
|
|
300
|
+
if (first.staticComponent !== null) {
|
|
301
|
+
const direct = PANEL_KIND_BY_STATIC[first.staticComponent];
|
|
302
|
+
if (direct !== undefined) return direct;
|
|
303
|
+
return /^App(Stat|Metric)/.test(first.staticComponent) ? 'metric' : 'unknown';
|
|
304
|
+
}
|
|
305
|
+
if (first.slot === 'list') return first.collection === 'table' || first.collection === 'treeTable' ? 'table' : 'unknown';
|
|
306
|
+
if (first.slot === 'summary') return 'summary';
|
|
307
|
+
if (first.slot === 'form') return 'form';
|
|
308
|
+
return 'unknown';
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function objectFact(raw: Rec, role: string, name: string | null, isPanel: boolean, at: string): KitFactObject {
|
|
312
|
+
const schema = isRec(raw.schema) ? raw.schema : {};
|
|
313
|
+
const views: KitFactView[] = [];
|
|
314
|
+
if (isRec(raw.view)) {
|
|
315
|
+
for (const slot of ['list', 'summary', 'filter', 'form'] as const) {
|
|
316
|
+
const v = raw.view[slot];
|
|
317
|
+
if (isRec(v)) views.push(viewFact(slot, v, schema, `${at}.view.${slot}`));
|
|
318
|
+
}
|
|
319
|
+
// 视图级散键写成 staticComponent / props / on:并入一个合成的 list 槽事实(写死形状数据组件没有槽)
|
|
320
|
+
if (raw.view.staticComponent !== undefined) views.push(viewFact('list', raw.view, schema, `${at}.view`));
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
path: at,
|
|
324
|
+
role,
|
|
325
|
+
name,
|
|
326
|
+
isPanel,
|
|
327
|
+
title: str(raw.title) ?? null,
|
|
328
|
+
panelSpan: num(raw.span) ?? null,
|
|
329
|
+
panelKind: panelKindOf(views),
|
|
330
|
+
views,
|
|
331
|
+
actions: actionFacts(raw.behavior, at),
|
|
332
|
+
schemaFieldNames: Object.keys(schema),
|
|
333
|
+
emphasis: str(raw.emphasis) ?? null,
|
|
334
|
+
surface: str(raw.surface) ?? null,
|
|
335
|
+
classes: classSites(raw, at, ['class']),
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function productFact(product: KitProductDecl, at: string, slot: string): KitFactProduct {
|
|
340
|
+
const objects: KitFactObject[] = [];
|
|
341
|
+
for (const [role, value] of Object.entries(product.objects ?? {})) {
|
|
342
|
+
if (!isRec(value)) continue;
|
|
343
|
+
if (value.schema !== undefined || value.behavior !== undefined || value.view !== undefined) {
|
|
344
|
+
objects.push(objectFact(value, role, null, false, `${at}.objects.${role}`));
|
|
345
|
+
} else {
|
|
346
|
+
// 对象表(many 角色:panels / subs / steps …):名字 → 对象;MultiObjectBoard 的 panels 是面板
|
|
347
|
+
for (const [name, sub] of Object.entries(value)) {
|
|
348
|
+
if (isRec(sub)) objects.push(objectFact(sub, role, name, role === 'panels', `${at}.objects.${role}.${name}`));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const classes = [...classSites(product as unknown as Rec, at, ['class'])];
|
|
353
|
+
if (isRec(product.areaClass)) {
|
|
354
|
+
for (const [area, value] of Object.entries(product.areaClass)) if (typeof value === 'string' && value.trim() !== '') classes.push({ key: `areaClass.${area}`, value, path: `${at}.areaClass.${area}` });
|
|
355
|
+
}
|
|
356
|
+
return { path: at, slot, kind: product.kind, objects, surface: product.surface ?? null, classes };
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** 页面声明 → 布局事实。声明形状不对的部分跳过,不抛。 */
|
|
360
|
+
export function extractKitPageFacts(decl: KitPageDecl): KitPageFacts {
|
|
361
|
+
const products: KitFactProduct[] = [];
|
|
362
|
+
let tabsDepth = 0;
|
|
363
|
+
for (const [slot, val] of Object.entries(decl.frame.slots)) {
|
|
364
|
+
if (Array.isArray(val)) {
|
|
365
|
+
tabsDepth = Math.max(tabsDepth, 1);
|
|
366
|
+
(val as KitTabDecl[]).forEach((tab, i) => products.push(productFact(tab.product, `frame.slots.${slot}[${i}].product`, slot)));
|
|
367
|
+
} else {
|
|
368
|
+
// 路径与 view-check 的 viewUsageOf 同口径(main 槽的产品在 YAML 里是顶层 product:),compile/locate 才定位得到行列
|
|
369
|
+
products.push(productFact(val as KitProductDecl, slot === 'main' ? 'product' : `frame.slots.${slot}`, slot));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const frameClasses: Array<{ key: string; value: string; path: string }> = classSites(decl.frame as unknown as Rec, 'frame', ['class']);
|
|
373
|
+
if (isRec(decl.frame.slotClass)) {
|
|
374
|
+
for (const [slot, value] of Object.entries(decl.frame.slotClass)) if (typeof value === 'string' && value.trim() !== '') frameClasses.push({ key: `slotClass.${slot}`, value, path: `frame.slotClass.${slot}` });
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
title: decl.page.title,
|
|
378
|
+
subtitle: decl.page.subtitle ?? null,
|
|
379
|
+
url: decl.page.url,
|
|
380
|
+
frameKind: decl.frame.kind,
|
|
381
|
+
maxWidth: decl.page.maxWidth ?? null,
|
|
382
|
+
products,
|
|
383
|
+
tabsDepth,
|
|
384
|
+
frameClasses,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// 布局规划(RV-1117 T04):页面布局事实 → KitLayoutPlan(影子规划)。
|
|
2
|
+
// 只调 soma-foundation/kit-layout 的门面,不写任何布局公式(单实现门 S1-i 看守);
|
|
3
|
+
// 规则版本 0(缺省,现状)下只产 plan、不改发射;发射端按版本 ≥ 1 才用 plan(第二期,T10–T13)。
|
|
4
|
+
// 规划失败(事实形状异常、字段重复等)按视图跳过,不抛:规划是旁路,绝不能让一页编译失败。
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
KIT_LAYOUT_CURRENT_VERSION,
|
|
8
|
+
KIT_LAYOUT_RULES,
|
|
9
|
+
kitLayoutDigestOf,
|
|
10
|
+
kitReferenceContainerRem,
|
|
11
|
+
kitSolveVersionOf,
|
|
12
|
+
solveKitFilterBar,
|
|
13
|
+
solveKitFormGrid,
|
|
14
|
+
solveKitPanels,
|
|
15
|
+
solveKitRowActions,
|
|
16
|
+
solveKitSummary,
|
|
17
|
+
solveKitTableColumns,
|
|
18
|
+
type KitActionFact,
|
|
19
|
+
type KitFormFieldFact,
|
|
20
|
+
type KitLayoutFieldFact,
|
|
21
|
+
type KitPanelFact,
|
|
22
|
+
type KitPanelPlan,
|
|
23
|
+
type KitTableColumnFact,
|
|
24
|
+
} from 'soma-foundation/kit-layout';
|
|
25
|
+
import type { KitFactField, KitFactObject, KitFactView, KitPageFacts } from './layout-facts';
|
|
26
|
+
import type { KitLayoutPlan, KitViewPlan } from './layout-plan.types';
|
|
27
|
+
|
|
28
|
+
export interface KitLayoutPlanOptions {
|
|
29
|
+
/** 应用钉的规则版本(`kit.app.yaml#app.layout.rules`),缺省 0 */
|
|
30
|
+
readonly rules?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 当前存在的规则版本号(0..current)。 */
|
|
34
|
+
export const KIT_LAYOUT_VERSIONS: readonly number[] = Object.keys(KIT_LAYOUT_RULES).map(Number).sort((a, b) => a - b);
|
|
35
|
+
|
|
36
|
+
/** 规整规则版本钉:缺省 0;非整数或不存在的版本不接受(返回 undefined 由调用方报配置错误)。 */
|
|
37
|
+
export function normalizeLayoutPin(raw: unknown): number | undefined {
|
|
38
|
+
if (raw === undefined) return 0;
|
|
39
|
+
return typeof raw === 'number' && Number.isInteger(raw) && KIT_LAYOUT_VERSIONS.includes(raw) ? raw : undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** AI 目标与新应用钉的版本:恒为当前最新版。 */
|
|
43
|
+
export const KIT_LAYOUT_LATEST_PIN: number = KIT_LAYOUT_CURRENT_VERSION;
|
|
44
|
+
|
|
45
|
+
const fieldFactOf = (f: KitFactField): KitLayoutFieldFact => ({
|
|
46
|
+
key: f.name,
|
|
47
|
+
type: f.type,
|
|
48
|
+
label: f.label,
|
|
49
|
+
...(f.maxLen !== null ? { maxLen: f.maxLen } : {}),
|
|
50
|
+
...(f.options !== undefined ? { options: f.options } : {}),
|
|
51
|
+
roles: f.roles,
|
|
52
|
+
...(f.component !== undefined ? { display: f.component } : {}),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const dedupe = (fields: readonly KitFactField[]): KitFactField[] => {
|
|
56
|
+
const seen = new Set<string>();
|
|
57
|
+
return fields.filter((f) => (seen.has(f.name) ? false : (seen.add(f.name), true)));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function actionFactsOf(object: KitFactObject, view: KitFactView): KitActionFact[] {
|
|
61
|
+
const byId = new Map(object.actions.filter((a) => a.on === 'row').map((a) => [a.id, a]));
|
|
62
|
+
return view.rowActionIds.flatMap((id) => {
|
|
63
|
+
const a = byId.get(id);
|
|
64
|
+
return a === undefined ? [] : [{ id: a.id, label: a.name, primary: a.primary, danger: a.danger, more: a.more }];
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 一个视图槽的规划;不适用(cards / stack / 写死形状组件 / 空字段)返回 undefined。 */
|
|
69
|
+
function planView(object: KitFactObject, view: KitFactView, pin: number): KitViewPlan | undefined {
|
|
70
|
+
const ctx = { version: pin };
|
|
71
|
+
const fields = dedupe([...view.fields, ...view.groups.flatMap((g) => g.fields)]);
|
|
72
|
+
if (view.staticComponent !== null) return undefined;
|
|
73
|
+
if (view.slot === 'list') {
|
|
74
|
+
if (view.collection !== 'table' && view.collection !== 'treeTable') return undefined;
|
|
75
|
+
const actions = solveKitRowActions({ actions: actionFactsOf(object, view), narrow: false, ctx });
|
|
76
|
+
const columns: KitTableColumnFact[] = fields.map((f) => ({
|
|
77
|
+
...fieldFactOf(f),
|
|
78
|
+
sortable: f.sortable,
|
|
79
|
+
columnFilter: f.columnFilter,
|
|
80
|
+
explicitWidth: f.width,
|
|
81
|
+
explicitAlign: f.align,
|
|
82
|
+
}));
|
|
83
|
+
const table = solveKitTableColumns({ columns, containerRem: kitReferenceContainerRem(), select: view.select, actionsRem: actions.widthRem, ctx });
|
|
84
|
+
return { kind: 'table', ...table, actions };
|
|
85
|
+
}
|
|
86
|
+
if (view.slot === 'form') {
|
|
87
|
+
const facts: KitFormFieldFact[] = fields.map((f) => ({
|
|
88
|
+
...fieldFactOf(f),
|
|
89
|
+
...(f.component !== undefined ? { component: f.component } : {}),
|
|
90
|
+
...(f.options !== undefined ? { optionCount: f.options.length } : {}),
|
|
91
|
+
explicitSpan: f.span,
|
|
92
|
+
}));
|
|
93
|
+
return { kind: 'form', ...solveKitFormGrid({ fields: facts, explicitCols: view.explicitCols, ctx }) };
|
|
94
|
+
}
|
|
95
|
+
if (view.slot === 'summary') {
|
|
96
|
+
return { kind: 'summary', ...solveKitSummary({ fields: fields.map(fieldFactOf), explicitCols: view.explicitCols, ctx }) };
|
|
97
|
+
}
|
|
98
|
+
return { kind: 'filter', ...solveKitFilterBar({ fields: fields.map(fieldFactOf), ctx }) };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 页面布局规划。pin = 应用钉的规则版本(缺省 0)。
|
|
103
|
+
* 影子规划:pin 为 0 时取当前最新版的表求解(solvedWith),发射仍走现状;pin ≥ 1 时 solvedWith = pin。
|
|
104
|
+
*/
|
|
105
|
+
export function planKitPageLayout(facts: KitPageFacts, options?: KitLayoutPlanOptions): KitLayoutPlan {
|
|
106
|
+
const pin = options?.rules ?? 0;
|
|
107
|
+
const solvedWith = kitSolveVersionOf(pin);
|
|
108
|
+
const views: Record<string, KitViewPlan> = {};
|
|
109
|
+
const panels: Record<string, KitPanelPlan> = {};
|
|
110
|
+
for (const product of facts.products) {
|
|
111
|
+
const panelFacts: KitPanelFact[] = [];
|
|
112
|
+
for (const object of product.objects) {
|
|
113
|
+
for (const view of object.views) {
|
|
114
|
+
try {
|
|
115
|
+
const planned = planView(object, view, solvedWith);
|
|
116
|
+
if (planned !== undefined) views[`${object.path}.${view.slot}`] = planned;
|
|
117
|
+
} catch {
|
|
118
|
+
// 规划是旁路:事实形状异常(重复字段、未知类型…)的视图不出 plan,诊断仍由编译主体负责
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (object.isPanel) panelFacts.push({ id: object.name ?? object.path, kind: object.panelKind, explicitSpan: object.panelSpan });
|
|
122
|
+
}
|
|
123
|
+
if (panelFacts.length > 0) {
|
|
124
|
+
try {
|
|
125
|
+
panels[product.path] = solveKitPanels(panelFacts, { version: solvedWith });
|
|
126
|
+
} catch {
|
|
127
|
+
// 同上:显式 span 越界等由编译主体的闭集检查报
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { rules: pin, solvedWith, designDigest: kitLayoutDigestOf(solvedWith), views, panels };
|
|
132
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// 布局规划(RV-1117 T04)的产物类型:KitLayoutPlan 是 KitCompileResult 的旁路产物,不进四件套、不改发射。
|
|
2
|
+
// 求解形状取自 soma-foundation/kit-layout 的门面类型,这里只加「视图键」与版本信息。
|
|
3
|
+
|
|
4
|
+
import type { KitFilterPlan, KitGridPlan, KitPanelPlan, KitRowActionsPlan, KitTablePlan } from 'soma-foundation/kit-layout';
|
|
5
|
+
|
|
6
|
+
/** 一个视图槽的规划:键是 `<对象路径>.<槽>`(如 `main.entity.list`)。 */
|
|
7
|
+
export type KitViewPlan =
|
|
8
|
+
| ({ readonly kind: 'table' } & KitTablePlan & { readonly actions: KitRowActionsPlan })
|
|
9
|
+
| ({ readonly kind: 'form' | 'summary' } & KitGridPlan)
|
|
10
|
+
| ({ readonly kind: 'filter' } & KitFilterPlan);
|
|
11
|
+
|
|
12
|
+
export interface KitLayoutPlan {
|
|
13
|
+
/** 应用钉的规则版本(`kit.app.yaml#app.layout.rules`,缺省 0 = 现状,输出逐字节不变) */
|
|
14
|
+
readonly rules: number;
|
|
15
|
+
/** 求解所用的规则表版本:规则版本 0(legacy)下影子规划取当前最新版的表,只供体检与 explain,不影响发射 */
|
|
16
|
+
readonly solvedWith: number;
|
|
17
|
+
/** 所用规则表的内容摘要(fnv1a),回滚重提交可据此核对同一布局 */
|
|
18
|
+
readonly designDigest: string;
|
|
19
|
+
readonly views: Readonly<Record<string, KitViewPlan>>;
|
|
20
|
+
/** 每个产品的面板装箱(只有 MultiObjectBoard 一类的面板产品才有) */
|
|
21
|
+
readonly panels: Readonly<Record<string, KitPanelPlan>>;
|
|
22
|
+
}
|