soma-kit 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/data/prompt-dialog.ts +0 -235
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// 展示对象的纯路径绑定(三层分工:页面只做视觉翻译与纯绑定,交互逻辑在展示对象)。
|
|
2
|
+
// 页面里字段项的 hidden / disabled / required 与动作的 disabled 只许写 `view.<成员>`;本文件是这条规则的唯一实现:
|
|
3
|
+
// · 判纯路径(语法真源 viewObject.pathPattern,不是谓词 / 表达式 / 取反 / 字面量);
|
|
4
|
+
// · 把 `view.` 换成 core 的页面变量(page.),编成 core 的路径绑定;
|
|
5
|
+
// · 收集字段项绑定成表单的 fieldState prop 的形态,收集 view.form.onDraft。
|
|
6
|
+
// 纯函数,不碰 DOM;成员 / 方法是否在展示对象上声明过,由 compile/view-check.ts 对着登记表核(这里不认登记表)。
|
|
7
|
+
|
|
8
|
+
import { KIT_GRAMMAR } from './defaults';
|
|
9
|
+
import type { KitDiagnostic, KitFieldRef, KitSchema, KitViewForm, KitViewSlot } from './types';
|
|
10
|
+
import { normalizeRef } from './arrange';
|
|
11
|
+
|
|
12
|
+
type Json = Record<string, any>;
|
|
13
|
+
const VO = (KIT_GRAMMAR as Json).viewObject as {
|
|
14
|
+
pathPattern: string; pathRoot: string; pathCoreVar: string; namePattern: string;
|
|
15
|
+
rowState: { pathPattern: string; pathRoot: string; actionKeys: string[]; toneTiers: Record<string, string> };
|
|
16
|
+
};
|
|
17
|
+
const RS = VO.rowState;
|
|
18
|
+
const ROW_RE = new RegExp(RS.pathPattern);
|
|
19
|
+
|
|
20
|
+
const PATH_RE = new RegExp(VO.pathPattern);
|
|
21
|
+
const NAME_RE = new RegExp(VO.namePattern);
|
|
22
|
+
const METHOD_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
23
|
+
|
|
24
|
+
/** 字段项上的状态键(hidden / disabled / required 要标量,options 要数组成员,nodeOptions 要对象成员,只用于画布字段) */
|
|
25
|
+
export const KIT_FIELD_STATE_KEYS = ['hidden', 'disabled', 'required', 'options', 'nodeOptions'] as const;
|
|
26
|
+
export type KitFieldStateKey = (typeof KIT_FIELD_STATE_KEYS)[number];
|
|
27
|
+
|
|
28
|
+
/** 页面上写的 view 路径(view.<成员>[.<子成员>])? */
|
|
29
|
+
export function isViewPath(value: unknown): value is string {
|
|
30
|
+
return typeof value === 'string' && PATH_RE.test(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 展示对象类名(页面 page.view 的值)合法? */
|
|
34
|
+
export function isViewName(value: unknown): value is string {
|
|
35
|
+
return typeof value === 'string' && NAME_RE.test(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 展示对象方法名合法(标识符)? */
|
|
39
|
+
export function isViewMethodName(value: unknown): value is string {
|
|
40
|
+
return typeof value === 'string' && METHOD_RE.test(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** view.<成员> -> core 路径 page.<成员>(调用前须先过 isViewPath) */
|
|
44
|
+
export function viewPathToCore(path: string): string {
|
|
45
|
+
return `${VO.pathCoreVar}.${path.slice(VO.pathRoot.length + 1)}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 路径的第一段成员名(view.remark.x -> remark) */
|
|
49
|
+
export function viewPathMember(path: string): string {
|
|
50
|
+
return path.slice(VO.pathRoot.length + 1).split('.')[0]!;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 校验一个视图绑定值;不是纯 view 路径记 KIT-VIEW-001 并返回 undefined,是则返回 core 路径 */
|
|
54
|
+
export function checkViewPath(value: unknown, at: string, what: string, diags: KitDiagnostic[]): string | undefined {
|
|
55
|
+
if (isViewPath(value)) return viewPathToCore(value);
|
|
56
|
+
diags.push({
|
|
57
|
+
code: 'KIT-VIEW-001',
|
|
58
|
+
path: at,
|
|
59
|
+
message: `${what} 只许写展示对象成员路径 ${VO.pathRoot}.<成员>,收到 ${JSON.stringify(value)}(不许字面量真假、谓词、表达式、取反、非 ${VO.pathRoot}. 前缀)`,
|
|
60
|
+
});
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ---------------------------------------------------------------- 行级状态的纯绑定(取值来自业务对象逐行给出的字段)
|
|
65
|
+
|
|
66
|
+
/** 行动作上的两个状态键(hidden / disabled) */
|
|
67
|
+
export const KIT_ROW_ACTION_KEYS = RS.actionKeys as readonly ('hidden' | 'disabled')[];
|
|
68
|
+
/** 行样式档位 -> 类串(闭集,真源 viewObject.rowState.toneTiers) */
|
|
69
|
+
export const KIT_ROW_TONE_CLASS: Readonly<Record<string, string>> = RS.toneTiers;
|
|
70
|
+
export const KIT_ROW_TONE_TIERS: readonly string[] = Object.keys(RS.toneTiers);
|
|
71
|
+
|
|
72
|
+
/** 页面上写的行路径(row.<字段>,单段字段名)? */
|
|
73
|
+
export function isRowPath(value: unknown): value is string {
|
|
74
|
+
return typeof value === 'string' && ROW_RE.test(value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** row.<字段> -> 字段名(调用前须先过 isRowPath) */
|
|
78
|
+
export function rowPathField(path: string): string {
|
|
79
|
+
return path.slice(RS.pathRoot.length + 1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** row.<字段> -> core 路径 <行变量>.<字段>(行变量由发射层给,是行模板里的 bind.var) */
|
|
83
|
+
export function rowPathToCore(path: string, rowVar: string): string {
|
|
84
|
+
return `${rowVar}.${rowPathField(path)}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 校验一个行级绑定值;不是纯 row 路径记 KIT-ROW-001 并返回 undefined;
|
|
89
|
+
* 给了 schema 时字段还必须在该对象 schema 里声明过,否则记 KIT-ROW-003(拼错字段名在编译期暴露,不等到运行期当假值)。
|
|
90
|
+
* 通过则返回字段名。
|
|
91
|
+
*/
|
|
92
|
+
export function checkRowPath(value: unknown, at: string, what: string, diags: KitDiagnostic[], schema?: Readonly<Record<string, unknown>>): string | undefined {
|
|
93
|
+
if (!isRowPath(value)) {
|
|
94
|
+
diags.push({
|
|
95
|
+
code: 'KIT-ROW-001',
|
|
96
|
+
path: at,
|
|
97
|
+
message: `${what} 只许写行字段路径 ${RS.pathRoot}.<字段>(由业务对象逐行给出),收到 ${JSON.stringify(value)}(不许字面量真假、谓词、表达式、取反、类名、非 ${RS.pathRoot}. 前缀)`,
|
|
98
|
+
});
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
const field = rowPathField(value);
|
|
102
|
+
if (schema !== undefined && !Object.prototype.hasOwnProperty.call(schema, field)) {
|
|
103
|
+
diags.push({
|
|
104
|
+
code: 'KIT-ROW-003',
|
|
105
|
+
path: at,
|
|
106
|
+
message: `${what} 引用的行字段 ${field} 没有在该对象 schema 里声明(已声明:${Object.keys(schema).join(' / ') || '无'});状态字段在 schema 里声明、但不放进 view.list.fields 即不显示成列`,
|
|
107
|
+
});
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
return field;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 运行期:从 actionState prop({ 动作id: { hidden?, disabled? } },叶子已被 core 逐行求成值)取一个动作此刻的状态;只认真值 true / 'true' */
|
|
114
|
+
export function rowActionState(all: unknown, id: string): { hidden: boolean; disabled: boolean } {
|
|
115
|
+
const one = all !== null && typeof all === 'object' ? (all as Record<string, unknown>)[id] : undefined;
|
|
116
|
+
const rec = one !== null && typeof one === 'object' ? (one as Record<string, unknown>) : {};
|
|
117
|
+
const on = (v: unknown): boolean => v === true || v === 'true';
|
|
118
|
+
return { hidden: on(rec.hidden), disabled: on(rec.disabled) };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** 运行期:行样式档位名 -> 类串;不在闭集(含空、未知)返回 ''(不加任何类) */
|
|
122
|
+
export function rowToneClass(tier: unknown): string {
|
|
123
|
+
return typeof tier === 'string' && Object.prototype.hasOwnProperty.call(KIT_ROW_TONE_CLASS, tier) ? KIT_ROW_TONE_CLASS[tier]! : '';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** nodeOptions 的宿主:只有这个编辑组件的字段项可写 nodeOptions */
|
|
127
|
+
const NODE_OPTIONS_EDITOR = 'FlowEditor';
|
|
128
|
+
|
|
129
|
+
export type KitFieldStateIR = Record<string, Partial<Record<KitFieldStateKey, string>>>;
|
|
130
|
+
|
|
131
|
+
/** 一个视图 fields / groups[].fields 里全部字段项(已规范化,带它们的路径) */
|
|
132
|
+
function refsOf(form: KitViewForm, path: string): Array<{ ref: KitFieldRef; at: string }> {
|
|
133
|
+
const out: Array<{ ref: KitFieldRef; at: string }> = [];
|
|
134
|
+
const push = (items: unknown, base: string): void => {
|
|
135
|
+
if (!Array.isArray(items)) return;
|
|
136
|
+
items.forEach((item, i) => {
|
|
137
|
+
if (item === null || (typeof item !== 'string' && typeof item !== 'object')) return;
|
|
138
|
+
out.push({ ref: normalizeRef(item as never), at: `${base}[${i}]` });
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
push(form.fields, `${path}.fields`);
|
|
142
|
+
if (Array.isArray(form.groups)) form.groups.forEach((g, gi) => push((g as { fields?: unknown }).fields, `${path}.groups[${gi}].fields`));
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 收集一个视图字段项上的状态绑定。只有可编辑 form 视图的字段项有意义,其它视图写了记 KIT-VIEW-006;
|
|
148
|
+
* 值不是纯 view 路径记 KIT-VIEW-001。返回 { 字段: { hidden?, disabled?, required? } }(路径已换成 core 的 page.<成员>)。
|
|
149
|
+
*/
|
|
150
|
+
export function collectFieldState(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[], schema?: KitSchema): KitFieldStateIR {
|
|
151
|
+
const out: KitFieldStateIR = {};
|
|
152
|
+
for (const { ref, at } of refsOf(form, path)) {
|
|
153
|
+
for (const key of KIT_FIELD_STATE_KEYS) {
|
|
154
|
+
const raw = (ref as unknown as Record<string, unknown>)[key];
|
|
155
|
+
if (raw === undefined) continue;
|
|
156
|
+
const where = `${at}.${key}`;
|
|
157
|
+
if (slot !== 'form') {
|
|
158
|
+
diags.push({ code: 'KIT-VIEW-006', path: where, message: `字段项的 ${key} 只对可编辑 form 视图生效,${slot} 视图不能写` });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
// nodeOptions 是画布字段(编辑组件 FlowEditor)的节点候选项,写在别的字段上没有落点
|
|
162
|
+
if (key === 'nodeOptions' && (ref.component ?? schema?.[ref.name]?.edit) !== NODE_OPTIONS_EDITOR) {
|
|
163
|
+
diags.push({ code: 'KIT-VIEW-006', path: where, message: `字段 ${ref.name} 的 nodeOptions 只对编辑组件是 ${NODE_OPTIONS_EDITOR} 的字段生效(schema 里 edit: ${NODE_OPTIONS_EDITOR},或字段项 component: ${NODE_OPTIONS_EDITOR})` });
|
|
164
|
+
}
|
|
165
|
+
const core = checkViewPath(raw, where, `字段 ${ref.name} 的 ${key}`, diags);
|
|
166
|
+
if (core !== undefined) (out[ref.name] ??= {})[key] = core;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** view.form.submitDisabled:纯 view 路径,返回 core 路径;只许可编辑 form 视图 */
|
|
173
|
+
export function checkSubmitDisabled(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[]): string | undefined {
|
|
174
|
+
const raw = (form as unknown as Record<string, unknown>).submitDisabled;
|
|
175
|
+
if (raw === undefined) return undefined;
|
|
176
|
+
if (slot !== 'form') {
|
|
177
|
+
diags.push({ code: 'KIT-VIEW-006', path: `${path}.submitDisabled`, message: 'submitDisabled 只用于 form 视图' });
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
return checkViewPath(raw, `${path}.submitDisabled`, 'submitDisabled', diags);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** view.form.onDraft:展示对象方法名;只许 form 视图 */
|
|
184
|
+
export function checkOnDraft(slot: KitViewSlot, form: KitViewForm, path: string, diags: KitDiagnostic[]): string | undefined {
|
|
185
|
+
const raw = (form as unknown as Record<string, unknown>).onDraft;
|
|
186
|
+
if (raw === undefined) return undefined;
|
|
187
|
+
if (slot !== 'form') {
|
|
188
|
+
diags.push({ code: 'KIT-VIEW-006', path: `${path}.onDraft`, message: 'onDraft 只用于 form 视图' });
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
if (!isViewMethodName(raw)) {
|
|
192
|
+
diags.push({ code: 'KIT-VIEW-001', path: `${path}.onDraft`, message: `onDraft 只许写展示对象方法名(标识符),收到 ${JSON.stringify(raw)}` });
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
return raw;
|
|
196
|
+
}
|
|
@@ -119,6 +119,37 @@ export function knownNonAiKeys(): ReadonlySet<string> {
|
|
|
119
119
|
return out;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* 视图字段引用里编译器代写的提示键:aiWriter.fieldRef 的 ai 级键去掉 label
|
|
124
|
+
* (label 编成 schema 的显示名,不另写在视图引用上)。蓝图字段用同名键承载,只落在 form / filter 视图。
|
|
125
|
+
*/
|
|
126
|
+
export const fieldHintKeys = (): readonly string[] => aiKeysOf(kitAiWriter().fieldRef).filter((k) => k === 'placeholder' || k === 'help');
|
|
127
|
+
|
|
128
|
+
/** 提示文字落在哪些视图槽位:展示词不作用的槽位(aiDisplayMap.slots 之外);list / summary 里的字段引用只承载展示词 */
|
|
129
|
+
export const hintSlots = (): readonly string[] => kitViewSlots().filter((s) => !KIT_AI_DISPLAY_MAP.slots.includes(s));
|
|
130
|
+
|
|
131
|
+
/** 对象角色的形状要求(真源 aiWriter.roleShape;未列出的角色取缺省 any、不禁任何键) */
|
|
132
|
+
export interface KitRoleShape {
|
|
133
|
+
readonly channel: 'any' | 'read' | 'write' | 'free';
|
|
134
|
+
readonly omit: readonly ('schema' | 'behavior' | 'view')[];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function roleShapeOf(kind: string, role: string): KitRoleShape {
|
|
138
|
+
const table = kitAiWriter().roleShape;
|
|
139
|
+
const hit = Object.hasOwn(table, kind) && Object.hasOwn(table[kind]!, role) ? table[kind]![role] : undefined;
|
|
140
|
+
return { channel: hit?.channel ?? 'any', omit: hit?.omit ?? [] };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** 授权接口的用途 */
|
|
144
|
+
export type ApiPurpose = 'api' | 'write_api' | 'delete_api';
|
|
145
|
+
|
|
146
|
+
/** 某用途允许的 HTTP 方法集(真源 aiWriter 的 readMethods / writeMethods / deleteMethods,大写) */
|
|
147
|
+
export function methodsFor(purpose: ApiPurpose): readonly string[] {
|
|
148
|
+
const w = kitAiWriter();
|
|
149
|
+
const list = purpose === 'api' ? w.readMethods : purpose === 'write_api' ? w.writeMethods : w.deleteMethods;
|
|
150
|
+
return list.map((m) => m.toUpperCase());
|
|
151
|
+
}
|
|
152
|
+
|
|
122
153
|
/** 字段类型闭集:真源 types 表的键 */
|
|
123
154
|
export const kitFieldTypes = (): readonly string[] => Object.keys(G.types);
|
|
124
155
|
|
|
@@ -152,3 +183,9 @@ export function kitDiagnosticText(code: string): string | undefined {
|
|
|
152
183
|
export function kitAiProductSummary(): Readonly<Record<string, string>> {
|
|
153
184
|
return KIT_AI_INTENT_MAP.summary;
|
|
154
185
|
}
|
|
186
|
+
|
|
187
|
+
/** 字段视觉强调级别(真源 objectLayer.fieldEmphasis) */
|
|
188
|
+
export const aiFieldEmphasis = (): readonly string[] => (grammarJson as unknown as { objectLayer: { fieldEmphasis: string[] } }).objectLayer.fieldEmphasis;
|
|
189
|
+
|
|
190
|
+
/** 字段访问权限(真源 objectLayer.fieldAccess) */
|
|
191
|
+
export const aiFieldAccess = (): readonly string[] => (grammarJson as unknown as { objectLayer: { fieldAccess: string[] } }).objectLayer.fieldAccess;
|
|
@@ -17,7 +17,7 @@ import type { PageDiagnostic } from 'soma-core/page-target';
|
|
|
17
17
|
import { KIT_PLACEHOLDER_URL } from '../app/submit.types';
|
|
18
18
|
import { resolveBiz } from '../compile/registry';
|
|
19
19
|
import type { KitAppContext } from '../compile/types';
|
|
20
|
-
import { KIT_REMOVE_CONFIRM_REF as REMOVE_CONFIRM_REF, kitAiDisplayMap, kitAiWriter, kitViewSlots } from './ai-surface';
|
|
20
|
+
import { fieldHintKeys, hintSlots, KIT_REMOVE_CONFIRM_REF as REMOVE_CONFIRM_REF, kitAiDisplayMap, kitAiWriter, kitViewSlots, roleShapeOf, type KitRoleShape } from './ai-surface';
|
|
21
21
|
import {
|
|
22
22
|
KIT_INTENT_MAP,
|
|
23
23
|
frameKindOfIntent,
|
|
@@ -73,6 +73,9 @@ function compileSchema(
|
|
|
73
73
|
if (f.key === true || (!hasKey && i === 0)) entry.key = true;
|
|
74
74
|
const permission = f.permission ?? (formFields.has(f.name) ? 'w' : undefined);
|
|
75
75
|
if (permission !== undefined) entry.permission = permission;
|
|
76
|
+
if (f.access !== undefined) entry.access = f.access;
|
|
77
|
+
if (f.emphasis !== undefined) entry.emphasis = f.emphasis;
|
|
78
|
+
if (f.highlight !== undefined) entry.highlight = f.highlight;
|
|
76
79
|
if ((f.type === 'enum' || f.type === 'enums') && (f.options === undefined || f.options.length === 0)) {
|
|
77
80
|
issues.push(issue(`${at}.fields[${i}].options`, `字段 ${f.name}(${f.type})需要候选项`, '给该字段补 options(value / label / 可选 tone)'));
|
|
78
81
|
}
|
|
@@ -101,12 +104,25 @@ function displayRef(object: KitIntentObject, id: string): unknown {
|
|
|
101
104
|
return { name: id, component: entry.component, ...props };
|
|
102
105
|
}
|
|
103
106
|
|
|
107
|
+
/**
|
|
108
|
+
* form / filter 视图里的一个字段引用:字段带了 placeholder / help(aiWriter.fieldRef 的 ai 键)就写成 { name, placeholder?, help? },
|
|
109
|
+
* 否则仍是字段 id 字符串。list / summary 的引用只承载展示词,不承载提示(蓝图解析已拒绝落不到视图上的提示)。
|
|
110
|
+
*/
|
|
111
|
+
function hintRef(object: KitIntentObject, id: string): unknown {
|
|
112
|
+
const field = object.fields.find((f) => f.name === id);
|
|
113
|
+
if (field === undefined) return id;
|
|
114
|
+
const hints = fieldHintKeys().filter((k) => (field as unknown as Rec)[k] !== undefined);
|
|
115
|
+
if (hints.length === 0) return id;
|
|
116
|
+
return { name: id, ...Object.fromEntries(hints.map((k) => [k, (field as unknown as Rec)[k]])) };
|
|
117
|
+
}
|
|
118
|
+
|
|
104
119
|
function compileObject(
|
|
105
120
|
name: string,
|
|
106
121
|
object: KitIntentObject,
|
|
107
122
|
slots: KitIntentSlots | undefined,
|
|
108
123
|
actions: readonly KitIntentAction[],
|
|
109
124
|
locale: string | undefined,
|
|
125
|
+
shape: KitRoleShape,
|
|
110
126
|
at: string,
|
|
111
127
|
issues: PageDiagnostic[],
|
|
112
128
|
): Rec {
|
|
@@ -116,14 +132,18 @@ function compileObject(
|
|
|
116
132
|
for (const slot of kitViewSlots()) {
|
|
117
133
|
const fields = slots?.[slot];
|
|
118
134
|
if (fields === undefined) continue;
|
|
119
|
-
const body: Rec = {
|
|
135
|
+
const body: Rec = {
|
|
136
|
+
fields: displayMap.slots.includes(slot)
|
|
137
|
+
? fields.map((id) => displayRef(object, id))
|
|
138
|
+
: hintSlots().includes(slot) ? fields.map((id) => hintRef(object, id)) : [...fields],
|
|
139
|
+
};
|
|
120
140
|
if (slot === 'list') {
|
|
121
141
|
const rows = actions.filter((a) => a.on === 'row').map((a) => `@${a.id}`);
|
|
122
142
|
if (rows.length > 0) body.rowActions = rows;
|
|
123
143
|
}
|
|
124
144
|
view[slot] = body;
|
|
125
145
|
}
|
|
126
|
-
if (slots?.form !== undefined && (object.write_api === undefined || object.write_api === '')) {
|
|
146
|
+
if (shape.channel !== 'free' && slots?.form !== undefined && (object.write_api === undefined || object.write_api === '')) {
|
|
127
147
|
issues.push(issue(`${at}.write_api`, `对象 ${name} 有 form 视图,但没有写接口(write_api),表单没有保存通道`, '在授权接口里选一个写入接口填到 write_api,或去掉 form 视图'));
|
|
128
148
|
}
|
|
129
149
|
if (actions.some((a) => a.on === 'row') && slots?.list === undefined) {
|
|
@@ -132,13 +152,24 @@ function compileObject(
|
|
|
132
152
|
const hasApi = typeof object.api === 'string' && object.api !== '';
|
|
133
153
|
const hasWrite = typeof object.write_api === 'string' && object.write_api !== '';
|
|
134
154
|
const hasDelete = typeof object.delete_api === 'string' && object.delete_api !== '';
|
|
135
|
-
|
|
155
|
+
// 接口通道按角色形状(真源 aiWriter.roleShape):缺省要有 api 或 write_api;只读展示角色不收写入口;只提交角色须有 write_api 且不收 api;free 不要求
|
|
156
|
+
if (shape.channel === 'any' && !hasApi && !hasWrite) {
|
|
136
157
|
issues.push(issue(`${at}`, `对象 ${name} 既没有 api 也没有 write_api:对象描述不足以编译(kit 没有样本数据通道)`, '在授权接口里选一个读接口填到 api'));
|
|
137
158
|
}
|
|
159
|
+
if (shape.omit.includes('behavior') && (hasApi || hasWrite || hasDelete)) {
|
|
160
|
+
issues.push(issue(`${at}`, `对象 ${name} 所在角色的取数 / 写入由模板继承别的角色,不收 api / write_api / delete_api`, '删去 api / write_api / delete_api;字段值读自主记录'));
|
|
161
|
+
}
|
|
162
|
+
if (shape.channel === 'read' && (hasWrite || hasDelete)) {
|
|
163
|
+
issues.push(issue(`${at}`, `对象 ${name} 所在角色是只读展示,不收 write_api / delete_api`, '删去 write_api / delete_api;要写入换用别的页面模式'));
|
|
164
|
+
}
|
|
165
|
+
if (shape.channel === 'write') {
|
|
166
|
+
if (!hasWrite) issues.push(issue(`${at}.write_api`, `对象 ${name} 所在角色只负责提交,须有写接口(write_api)`, '在授权接口里选一个写入接口填到 write_api'));
|
|
167
|
+
if (hasApi) issues.push(issue(`${at}.api`, `对象 ${name} 所在角色只负责提交,不收读接口 api`, '删去 api'));
|
|
168
|
+
}
|
|
138
169
|
// 写通道:只有 write_api 时保持字符串写法(创建与更新共用);带 delete_api 改成通道表,删除通道独立
|
|
139
170
|
// core 的删除端点要带身份占位符(DELETE 不带请求体):编译器把主键拼进查询串 `?<主键>={<主键>}`,授权核对仍只看路径本身
|
|
140
171
|
const keyField = object.fields.find((f) => f.key === true)?.name ?? object.fields[0]?.name;
|
|
141
|
-
const deleteEndpoint = !hasDelete || keyField === undefined ? undefined : `${object.delete_api}
|
|
172
|
+
const deleteEndpoint = !hasDelete || keyField === undefined ? undefined : `${object.delete_api}${object.delete_api!.includes('?') ? '&' : '?'}${keyField}={${keyField}}`;
|
|
142
173
|
const write = deleteEndpoint !== undefined
|
|
143
174
|
? { ...(hasWrite ? { create: object.write_api, update: object.write_api } : {}), delete: deleteEndpoint }
|
|
144
175
|
: hasWrite ? object.write_api : undefined;
|
|
@@ -155,7 +186,12 @@ function compileObject(
|
|
|
155
186
|
}
|
|
156
187
|
: {}),
|
|
157
188
|
};
|
|
158
|
-
|
|
189
|
+
// 模板写死的角色(roleShape.omit)不收 schema / behavior / view:目标不写(字段字典、取数由模板自己合并或继承)
|
|
190
|
+
return {
|
|
191
|
+
...(shape.omit.includes('schema') ? {} : { schema: compileSchema(object, formFields, locale, at, issues) }),
|
|
192
|
+
...(shape.omit.includes('behavior') ? {} : { behavior }),
|
|
193
|
+
...(shape.omit.includes('view') ? {} : { view }),
|
|
194
|
+
};
|
|
159
195
|
}
|
|
160
196
|
|
|
161
197
|
function compileSection(
|
|
@@ -188,6 +224,10 @@ function compileSection(
|
|
|
188
224
|
issues.push(issue(`${aat}.role`, `动作 ${a.id} 没有可挂的角色(${role === undefined ? '该页面模式没有主角色,请写 role' : `角色 ${role} 未绑定对象`})`, '给动作写 role,取 roles 里已绑定的角色'));
|
|
189
225
|
return;
|
|
190
226
|
}
|
|
227
|
+
if (roleShapeOf(kind, role).channel === 'read') {
|
|
228
|
+
issues.push(issue(`${aat}.role`, `动作 ${a.id} 挂在只读展示的角色 ${role} 上,该角色不收动作`, '删去该动作'));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
191
231
|
if ((a.builtin === 'openEdit') && a.on !== 'row') issues.push(issue(`${aat}.on`, `openEdit 只能是行动作(要带当前行)`, '把 on 改成 row'));
|
|
192
232
|
if ((a.builtin === 'openCreate' || a.builtin === 'reload') && a.on !== 'toolbar') issues.push(issue(`${aat}.on`, `${a.builtin} 只能放工具栏`, '把 on 改成 toolbar'));
|
|
193
233
|
if (a.builtin === 'remove') {
|
|
@@ -225,13 +265,13 @@ function compileSection(
|
|
|
225
265
|
if (typeof ref === 'string') {
|
|
226
266
|
const object = section.objects[ref];
|
|
227
267
|
if (object === undefined) continue;
|
|
228
|
-
objects[role] = compileObject(ref, object, roleViews as KitIntentSlots | undefined, roleActions, locale, `${at}objects.${ref}`, issues);
|
|
268
|
+
objects[role] = compileObject(ref, object, roleViews as KitIntentSlots | undefined, roleActions, locale, roleShapeOf(kind, role), `${at}objects.${ref}`, issues);
|
|
229
269
|
} else {
|
|
230
270
|
const table: Rec = {};
|
|
231
271
|
for (const n of ref) {
|
|
232
272
|
const object = section.objects[n];
|
|
233
273
|
if (object === undefined) continue;
|
|
234
|
-
table[n] = compileObject(n, object, (roleViews as Record<string, KitIntentSlots> | undefined)?.[n], roleActions, locale, `${at}objects.${n}`, issues);
|
|
274
|
+
table[n] = compileObject(n, object, (roleViews as Record<string, KitIntentSlots> | undefined)?.[n], roleActions, locale, roleShapeOf(kind, role), `${at}objects.${n}`, issues);
|
|
235
275
|
}
|
|
236
276
|
objects[role] = table;
|
|
237
277
|
}
|
package/src/page-target/index.ts
CHANGED
|
@@ -6,7 +6,14 @@ export {
|
|
|
6
6
|
KitTargetInputError,
|
|
7
7
|
SOMA_KIT_TARGET_SOURCE_PATH,
|
|
8
8
|
} from './target';
|
|
9
|
-
export type {
|
|
9
|
+
export type {
|
|
10
|
+
KitCurrentApiAuthorizationRequest,
|
|
11
|
+
KitCurrentApiAuthorizationProvider,
|
|
12
|
+
KitPageTargetApp,
|
|
13
|
+
KitPageTargetOptions,
|
|
14
|
+
} from './target';
|
|
15
|
+
// 宿主装配 soma-ai-page 时标注目标类型用,应用不必 import soma-core/page-target
|
|
16
|
+
export type { PageTarget } from 'soma-core/page-target';
|
|
10
17
|
export { kitIntentSchema, parseKitIntentBlueprint } from './intent-schema';
|
|
11
18
|
export type {
|
|
12
19
|
KitIntentBlueprint,
|