soma-kit 0.1.12 → 0.1.14
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 +172 -4
- package/spec/generated/kit-page.schema.json +164 -5
- package/spec/kit-grammar.json +598 -96
- package/spec/kit-grammar.schema.json +12 -6
- package/src/app/app-config.ts +92 -8
- 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 +29 -5
- package/src/app/kit-view-context.ts +181 -15
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +55 -8
- 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 +62 -15
- 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 +61 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +168 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +95 -0
- package/src/base/index.ts +32 -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 +16 -18
- 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 +10 -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 +36 -24
- package/src/base/shared.ts +180 -36
- package/src/base/state-panel.ts +367 -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 +76 -41
- package/src/base/text.ts +43 -14
- 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 -9
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +15 -11
- package/src/biz/auth-panel/shell.ts +9 -7
- package/src/biz/category-crud/compile.ts +5 -4
- package/src/biz/category-crud/shell.ts +5 -3
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +10 -8
- package/src/biz/compose.ts +2 -2
- package/src/biz/data-components.ts +4 -0
- package/src/biz/import-wizard/shell.ts +13 -10
- package/src/biz/landing-page/shell.ts +2 -2
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +207 -16
- package/src/biz/master-sub/detail-head.ts +61 -0
- package/src/biz/master-sub/index.ts +7 -3
- package/src/biz/master-sub/shell.ts +133 -24
- package/src/biz/multi-board/compile.ts +167 -9
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +1 -1
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +94 -23
- package/src/biz/notification-center/shell.ts +10 -7
- package/src/biz/page-templates/domain-templates.ts +2 -2
- package/src/biz/page-templates/result-page/shell.ts +4 -3
- package/src/biz/page-templates/sign-in-page/shell.ts +16 -16
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +13 -10
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +12 -9
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +97 -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 +281 -0
- package/src/biz/shared/overlay-shell.ts +142 -11
- 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 +9 -6
- package/src/biz/standard-crud/compile.ts +36 -161
- package/src/biz/standard-crud/shell.ts +23 -60
- package/src/biz/standard-crud/summary.ts +40 -0
- package/src/biz/step-form/shell.ts +15 -13
- package/src/biz/types.ts +6 -1
- 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/access-gate-attach.ts +27 -0
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +66 -11
- package/src/compile/component-candidates.ts +14 -1
- package/src/compile/fragment.ts +11 -0
- 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 +267 -0
- package/src/compile/layout-lint/rules-form.ts +191 -0
- package/src/compile/layout-lint/rules-table.ts +278 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/page-composition.ts +189 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +46 -8
- package/src/compile/types.ts +16 -2
- package/src/compile/view-check.ts +149 -16
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +9 -2
- package/src/data/approval-flow.ts +5 -2
- package/src/data/assignment-picker.ts +59 -28
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +8 -3
- package/src/data/carousel.ts +10 -6
- package/src/data/chart.ts +744 -46
- package/src/data/checklist.ts +22 -6
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +3 -2
- package/src/data/confirm-dialog.ts +72 -25
- 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 +7 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +26 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/footer.ts +2 -0
- package/src/data/gantt.ts +192 -27
- package/src/data/hero.ts +4 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +16 -4
- package/src/data/item-list.ts +27 -12
- package/src/data/kanban.ts +41 -10
- package/src/data/matrix.ts +391 -0
- 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 +60 -16
- package/src/data/mockup.ts +5 -1
- package/src/data/modal-dialog.ts +146 -26
- package/src/data/navbar.ts +8 -6
- package/src/data/notice-list.ts +301 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +409 -87
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +19 -8
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +36 -11
- package/src/data/permission-tree.ts +52 -23
- package/src/data/pricing-table.ts +22 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +40 -7
- package/src/data/record-picker.ts +13 -7
- package/src/data/resident.ts +8 -0
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +77 -24
- package/src/data/rule-builder.ts +14 -9
- package/src/data/shape-util.ts +27 -12
- package/src/data/stat-group.ts +459 -74
- package/src/data/static-lazy.ts +5 -0
- package/src/data/static-registry.ts +8 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +7 -4
- package/src/data/system-switcher.ts +3 -2
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +3 -2
- package/src/data/transfer.ts +40 -16
- package/src/data/tree-table.ts +65 -37
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +21 -11
- package/src/data/wrapped-candidates.ts +32 -1
- package/src/frames/index.ts +1 -0
- package/src/frames/list-summary.ts +100 -0
- package/src/frames/page-bar.ts +7 -14
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +34 -13
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +9 -6
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +3 -3
- package/src/frames/types.ts +3 -1
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +4 -4
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +168 -44
- package/src/generated/kit-grammar-runtime.ts +390 -59
- package/src/i18n/kit-text.ts +90 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/action-group.ts +139 -0
- package/src/object-renderer/action-more.ts +144 -0
- package/src/object-renderer/arrange.ts +71 -7
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +264 -62
- package/src/object-renderer/collection-table.ts +177 -5
- package/src/object-renderer/collection.ts +188 -37
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +27 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-object.ts +4 -0
- package/src/object-renderer/emit-static.ts +434 -41
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +5 -0
- package/src/object-renderer/layout-facts.ts +394 -0
- package/src/object-renderer/layout-plan.ts +225 -0
- package/src/object-renderer/layout-plan.types.ts +59 -0
- package/src/object-renderer/parts.ts +6 -7
- package/src/object-renderer/render-object.ts +107 -46
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +172 -32
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +62 -30
- package/src/object-renderer/types.ts +84 -13
- 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 +77 -1
- package/src/recipes/control.ts +76 -116
- package/src/recipes/emphasis.ts +56 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +72 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +120 -17
- package/src/recipes/placeholder.ts +95 -0
- package/src/recipes/rail-grid.ts +48 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +40 -21
- package/src/recipes/status.ts +147 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +146 -3
- package/src/recipes/tabs.ts +49 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +30 -37
- 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 +384 -13
- package/src/theme/kit-theme.tpl +384 -13
- package/src/theme/nine-dim-structure.ts +244 -7
- package/src/theme/surface-layers.ts +10 -1
- package/src/theme/theme-tokens.ts +63 -16
- package/src/theme/theme-types.ts +32 -0
- package/src/theme/typography.ts +21 -17
- package/src/biz/shared/remove-key.ts +0 -6
package/src/biz/shared/pipes.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import type { KitAction, KitDiagnostic } from '../../object-renderer/types';
|
|
7
7
|
import { isValidPermissionCode, formatPermissionInvalidMessage } from '../../shared/action-field-guard';
|
|
8
|
+
import { checkKitConfirmObject, checkKitConfirmText, confirmScopeOfAction, confirmSegmentOfText, confirmToneOfAction, isConfirmObject } from '../../shared/confirm-decl';
|
|
8
9
|
import { KIT_COORD_EVENTS } from './coordinator';
|
|
9
10
|
|
|
10
11
|
export function semanticPipe(scope: string, name: string, extra: string[] = []): string {
|
|
@@ -19,12 +20,17 @@ export function reloadPipe(scope: string): string {
|
|
|
19
20
|
export function pipeTails(a: KitAction, at: string, diagnostics: KitDiagnostic[]): string[] {
|
|
20
21
|
const out: string[] = [];
|
|
21
22
|
if (a.confirm !== undefined) {
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (isConfirmObject(a.confirm)) {
|
|
24
|
+
// 对象形(字面量版):编成 core 的结构化确认段 confirm:{…JSON},与字符串形同一个尾段位置
|
|
25
|
+
const checked = checkKitConfirmObject(a.confirm, confirmScopeOfAction(a.on), confirmToneOfAction(a));
|
|
26
|
+
if (checked.ok) out.push(checked.segment);
|
|
27
|
+
else diagnostics.push({ code: 'KIT-ACT-010', path: `${at}.confirm`, message: `动作 ${a.id ?? ''} 的 confirm:${checked.error}` });
|
|
28
|
+
} else if (typeof a.confirm !== 'string') {
|
|
29
|
+
diagnostics.push({ code: 'KIT-ACT-010', path: `${at}.confirm`, message: `动作 ${a.id ?? ''} 的 confirm 必须是字符串或 { level, text, phrase?, impact? } 对象(收到 ${Array.isArray(a.confirm) ? 'array' : typeof a.confirm})` });
|
|
26
30
|
} else if (a.confirm !== '') {
|
|
27
|
-
|
|
31
|
+
const problem = checkKitConfirmText(a.confirm, confirmScopeOfAction(a.on));
|
|
32
|
+
if (problem !== null) diagnostics.push({ code: 'KIT-ACT-010', message: `动作 ${a.id} 的 confirm ${problem}`, path: `${at}.confirm` });
|
|
33
|
+
else out.push(confirmSegmentOfText(a.confirm, confirmToneOfAction(a)));
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
if (a.permission !== undefined) {
|
|
@@ -1,29 +1,14 @@
|
|
|
1
1
|
// 内置删除(builtin: remove)经协调组件 KitCrudBridge 的接线规则:StandardCrud 与 link 系业务组件共用,每条规则只此一份。
|
|
2
2
|
//
|
|
3
|
-
// · 管道:`SCOPE | semantic | <作用域> | kit_remove`,尾段(confirm / permission)由 pipeTails
|
|
4
|
-
// 带行占位 {字段}
|
|
5
|
-
//
|
|
6
|
-
// link 系多对象,键 = `${对象}:${动作id}`,协调组件先查带对象名的键、再查动作 id)。
|
|
3
|
+
// · 管道:`SCOPE | semantic | <作用域> | kit_remove`,尾段(confirm / permission)由 pipeTails 给,一律由 core 执行;
|
|
4
|
+
// 带行占位 {字段} 的确认文案原样写进 core 的 confirm 尾段,触发时由 core 按载荷 row 代入(J3:确认文案一条规则一份实现,
|
|
5
|
+
// 协调组件不再自弹确认框)。因此 permission / roles 判定、确认级别、取消即中止与其他动作完全一致。
|
|
7
6
|
|
|
8
|
-
import { removeConfirmPlaceholders } from '../../compile/remove-guard';
|
|
9
7
|
import type { KitAction, KitDiagnostic } from '../../object-renderer/types';
|
|
10
8
|
import { KIT_COORD_EVENTS } from './coordinator';
|
|
11
9
|
import { pipeTails, semanticPipe } from './pipes';
|
|
12
|
-
import { removeConfirmKey } from './remove-key';
|
|
13
10
|
|
|
14
11
|
/** 一个 builtin remove 行动作的单管道 */
|
|
15
12
|
export function removePipe(scope: string, a: KitAction, at: string, diagnostics: KitDiagnostic[]): string {
|
|
16
|
-
|
|
17
|
-
? pipeTails({ ...a, confirm: undefined }, at, diagnostics)
|
|
18
|
-
: pipeTails(a, at, diagnostics);
|
|
19
|
-
return semanticPipe(scope, KIT_COORD_EVENTS.remove, tails);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** 动作表里带行占位确认的 builtin remove -> 键到确认文案模板(object 缺省则键 = 动作 id);rowOnly 时只取行动作 */
|
|
23
|
-
export function removeConfirmTemplates(actions: readonly KitAction[], object?: string, rowOnly = false): Record<string, string> {
|
|
24
|
-
return Object.fromEntries(
|
|
25
|
-
actions
|
|
26
|
-
.filter((a) => a.builtin === 'remove' && (!rowOnly || a.on === 'row') && a.confirm !== undefined && removeConfirmPlaceholders(a.confirm).length > 0)
|
|
27
|
-
.map((a) => [removeConfirmKey(object, a.id), a.confirm as string]),
|
|
28
|
-
);
|
|
13
|
+
return semanticPipe(scope, KIT_COORD_EVENTS.remove, pipeTails(a, at, diagnostics));
|
|
29
14
|
}
|
|
@@ -32,6 +32,8 @@ export interface KitHubEntry {
|
|
|
32
32
|
focusRow(): Record<string, unknown>;
|
|
33
33
|
/** 关掉当前打开的浮层(不问未保存修改:调用方是保存成功后的收尾) */
|
|
34
34
|
close?(): void;
|
|
35
|
+
/** 打开新建表单并带初值(展示对象 ctx.openCreate 用;初值盖在组件级预填之上,用户随后可改) */
|
|
36
|
+
openCreate?(prefill?: Record<string, unknown>): void;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
/** 按 scopeId / instanceId 索引的协调组件映射表(同 scope 多实例挂载时按栈保存,卸载时精确移除自身) */
|
|
@@ -227,6 +229,14 @@ export function closeKitHub(target?: string | HTMLElement): void {
|
|
|
227
229
|
resolveHub(target)?.close?.();
|
|
228
230
|
}
|
|
229
231
|
|
|
232
|
+
/** 在指定对象(或 scope)所属的协调组件上打开新建表单并带初值;没有协调组件 / 它不支持新建返回 false */
|
|
233
|
+
export function openKitHubCreate(target: string, prefill?: Record<string, unknown>): boolean {
|
|
234
|
+
const hub = resolveHub(target);
|
|
235
|
+
if (hub?.openCreate === undefined) return false;
|
|
236
|
+
hub.openCreate(prefill);
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
|
|
230
240
|
/** 页面上有没有协调组件登记(支持按 scope / 宿主查询;KitActionHost 据此决定刷新走协调组件还是直接重取动作所属对象) */
|
|
231
241
|
export function hasKitHub(target?: string | HTMLElement): boolean {
|
|
232
242
|
if (target !== undefined) return resolveHub(target) !== undefined;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import { kitText } from '../../i18n/kit-text';
|
|
15
15
|
import { KIT_VIEW_FORM_KEYS, KIT_VIEW_SLOTS } from '../../object-renderer/defaults';
|
|
16
16
|
import { emitObject } from '../../object-renderer/emit-object';
|
|
17
|
+
import { savedNoticePipe } from '../../object-renderer/form-notify';
|
|
17
18
|
import { viewAnchor } from '../../object-renderer/emit-static';
|
|
18
19
|
import type { KitDiagnostic, KitObject, KitViewForm } from '../../object-renderer/types';
|
|
19
20
|
import type { KitFragment } from '../../compile/fragment';
|
|
@@ -110,8 +111,8 @@ export function compileSingleForm(input: KitBizInput, ctx: KitBizContext): KitFr
|
|
|
110
111
|
return finishBizCompile(out, '');
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
//
|
|
114
|
-
out.events[`${formId}.saved`] =
|
|
114
|
+
// 写入成功:通知(单管道,文案可由 view.form.notify 字面量覆盖)。重取由 write.reload: self 完成;保存后的跳转等别的事归展示对象(ctx.onOutcome 订阅表单的写入结果)
|
|
115
|
+
out.events[`${formId}.saved`] = savedNoticePipe(formView, SAVED_NOTICE);
|
|
115
116
|
|
|
116
117
|
// 标题:string 两态通用;{ create, edit } 按有无读接口取
|
|
117
118
|
const t = formView.title;
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// 底部固定的保存 / 重置栏是 KitObjectForm 的按钮行(actions 区),这里只给它一组 sticky 底栏类(经 classes.actions 传入)。
|
|
3
3
|
|
|
4
4
|
import { mergeClass } from '../../object-renderer/merge-class';
|
|
5
|
+
import { kitShellRecipe } from '../../recipes/container';
|
|
6
|
+
import { kitTypographyRecipe } from '../../recipes/typography';
|
|
5
7
|
import { cls, esc } from '../link/shared';
|
|
6
8
|
|
|
7
9
|
/** 壳的内部区域名(`areaClass` 的合法键) */
|
|
@@ -10,12 +12,12 @@ export type SingleFormArea = (typeof SINGLE_FORM_AREAS)[number];
|
|
|
10
12
|
|
|
11
13
|
export const SINGLE_FORM_CLASS = {
|
|
12
14
|
root: '@container flex justify-center',
|
|
13
|
-
card: 'flex w-full max-w-2xl flex-col
|
|
15
|
+
card: mergeClass('flex w-full max-w-2xl flex-col', kitShellRecipe({ shadow: false })),
|
|
14
16
|
header: 'border-b border-border-subtle px-6 py-4',
|
|
15
|
-
title: '
|
|
16
|
-
body: 'p-
|
|
17
|
-
/**
|
|
18
|
-
footer: 'sticky bottom-0 mt-4 flex flex-wrap items-end gap-
|
|
17
|
+
title: kitTypographyRecipe('sectionTitle'),
|
|
18
|
+
body: 'p-inset-roomy',
|
|
19
|
+
/** 底栏:贴着可滚动祖先的底边,带分隔线与卡面底色(页面里的卡面 = bg-surface;写 raised 在暗色里比卡面亮一档,底栏成了一条亮带;浮层里的底栏另有 group 变体取浮层面) */
|
|
20
|
+
footer: 'sticky bottom-0 mt-4 flex flex-wrap items-end gap-cluster border-t border-border-subtle bg-surface py-3',
|
|
19
21
|
} as const;
|
|
20
22
|
|
|
21
23
|
export function singleFormIds(pageId: string): { root: string } {
|
|
@@ -32,7 +34,8 @@ export function singleFormHtml(
|
|
|
32
34
|
? ''
|
|
33
35
|
: `<div${cls(SINGLE_FORM_CLASS.header)}><h2${cls(SINGLE_FORM_CLASS.title)}>${esc(parts.title)}</h2></div>`;
|
|
34
36
|
const body = `<div${cls(mergeClass(SINGLE_FORM_CLASS.body, areaClass.body))}>${parts.form}</div>`;
|
|
35
|
-
|
|
37
|
+
// 唯一主体 = 页面(C2):表单卡是 E1 主体
|
|
38
|
+
const card = `<section data-kit-emphasis="primary" data-kit-role="subject" data-kit-container="card"${cls(mergeClass(SINGLE_FORM_CLASS.card, areaClass.card))}>${header}${body}</section>`;
|
|
36
39
|
const root = mergeClass(mergeClass(SINGLE_FORM_CLASS.root, areaClass.root), extra);
|
|
37
40
|
return `<div data-soma-id="${esc(ids.root)}"${cls(root)}>\n${card}\n</div>`;
|
|
38
41
|
}
|
|
@@ -13,44 +13,34 @@
|
|
|
13
13
|
import { regionMirrorStatePath } from 'soma-core';
|
|
14
14
|
import { kitText } from '../../i18n/kit-text';
|
|
15
15
|
import type { SomaScopeDecl, SomaScopeMirrorDecl, SomaScopeSliceDecl } from 'soma-core';
|
|
16
|
-
import { KIT_GRAMMAR, KIT_VIEW_FORM_KEYS, KIT_VIEW_SLOTS } from '../../object-renderer/defaults';
|
|
17
16
|
import { emitObject, type KitEmitResult } from '../../object-renderer/emit-object';
|
|
18
17
|
import { primaryKeyFieldOf } from '../../object-renderer/key-field';
|
|
19
18
|
import { actionPipeline, rowActionSlotsOf } from '../../object-renderer/emit-events';
|
|
20
|
-
import { isRequestLikeAction, registerRequestAction } from '../../object-renderer/request-actions';
|
|
21
19
|
import { checkExpandChild, expandHolderHtml, expandHostId } from '../../object-renderer/collection-expand';
|
|
22
20
|
import { ctxMenuAnchor, opsAnchor, rowsAnchor, staticCtxAnchor, toolbarAnchor, treeAnchor, viewAnchor, virtualAnchor } from '../../object-renderer/emit-static';
|
|
23
|
-
import type { KitAction, KitDiagnostic, KitObject,
|
|
21
|
+
import type { KitAction, KitDiagnostic, KitObject, KitViewForm } from '../../object-renderer/types';
|
|
24
22
|
import type { KitFragment } from '../../compile/fragment';
|
|
25
|
-
import type { KitBizContext, KitBizInput
|
|
26
|
-
import { KIT_COORD_EVENTS, KIT_COORD_MIRRORS,
|
|
23
|
+
import type { KitBizContext, KitBizInput } from '../types';
|
|
24
|
+
import { KIT_COORD_EVENTS, KIT_COORD_MIRRORS, rewriteRowActions, type KitRowActionRoute } from '../shared/coordinator';
|
|
25
|
+
import { KIT_CRUD_LINK_KEY, compileOverlay, normalizeOverlayView, validateOverlayNames } from '../shared/overlay-compile';
|
|
27
26
|
import {
|
|
28
27
|
bizObjectName, checkRoleAllowedViews, finishBizCompile, validateBizAreaClass,
|
|
29
28
|
} from '../shared/compile-helpers';
|
|
30
|
-
import { labelDiagnostics, newParts, normalizeList, type Parts } from '../link/shared';
|
|
31
|
-
import { busyActionOf } from '../../base/action-busy';
|
|
29
|
+
import { IDENT, labelDiagnostics, newParts, normalizeList, type Parts } from '../link/shared';
|
|
32
30
|
import { pipeTails, semanticPipe, wireDialogForm } from '../shared/pipes';
|
|
33
|
-
import {
|
|
31
|
+
import { removePipe } from '../shared/remove-wire';
|
|
34
32
|
import { KIT_ACTION_SLOT_BASE } from '../../base/action-slots';
|
|
35
33
|
import { StandardCrud } from './index';
|
|
34
|
+
import { esc } from '../../shared/escape';
|
|
35
|
+
import { facetsPathOf, listSummaryFields, listSummaryHoist } from './summary';
|
|
36
36
|
import {
|
|
37
|
-
CRUD_CLASS, STANDARD_CRUD_AREAS, classesIn, coordinatorHtml, coordinatorId, dialogHtml, dialogIds, dialogTitles, mainHtml, overlayHtml, overlayIds, rootHtml,
|
|
37
|
+
CRUD_CLASS, STANDARD_CRUD_AREAS, classesIn, coordinatorHtml, coordinatorId, dialogHtml, dialogIds, dialogTitles, dialogWidthOf, mainHtml, overlayHtml, overlayIds, rootHtml,
|
|
38
38
|
} from './shell';
|
|
39
39
|
|
|
40
40
|
type Rec = Record<string, unknown>;
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/** 浮层里数据组件的约定事件 -> 角色(K-1) */
|
|
45
|
-
const OVERLAY_EVENT_ROLES: Record<string, string> = KIT_GRAMMAR.overlayEventRoles.conventional as Record<string, string>;
|
|
46
|
-
const OVERLAY_ROLE_SEMANTIC: Record<string, string> = {
|
|
47
|
-
saved: KIT_COORD_EVENTS.saved,
|
|
48
|
-
close: KIT_COORD_EVENTS.close,
|
|
49
|
-
reload: KIT_COORD_EVENTS.reload,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/** 关联键镜像:当前行主键(附加对象的 from.params 引用) */
|
|
53
|
-
export const KIT_CRUD_LINK_KEY = 'crud_link';
|
|
42
|
+
/** 关联键镜像:当前行主键(附加对象的 from.params 引用);附加浮层的共用编译在 shared/overlay-compile.ts,这里原样 re-export */
|
|
43
|
+
export { KIT_CRUD_LINK_KEY };
|
|
54
44
|
|
|
55
45
|
function isRec(v: unknown): v is Rec {
|
|
56
46
|
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -85,17 +75,6 @@ function ownPipe(a: KitAction, scope: string, at: string, diagnostics: KitDiagno
|
|
|
85
75
|
|
|
86
76
|
// ---------------------------------------------------------------- 浮层视图规整
|
|
87
77
|
|
|
88
|
-
/** 浮层的 view 允许直接写成一个视图(如 `staticComponent` 写在 view 下):list 型放 list 槽,single 型放 summary 槽 */
|
|
89
|
-
function normalizeOverlayView(view: unknown): KitView | undefined {
|
|
90
|
-
if (!isRec(view)) return undefined;
|
|
91
|
-
if (KIT_VIEW_SLOTS.some((s) => s in view)) return view as KitView;
|
|
92
|
-
if (Object.keys(view).some((k) => KIT_VIEW_FORM_KEYS.has(k))) {
|
|
93
|
-
const form = view as unknown as KitViewForm;
|
|
94
|
-
return form.accept === 'single' ? { summary: form } : { list: form };
|
|
95
|
-
}
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
78
|
// ---------------------------------------------------------------- 累积
|
|
100
79
|
|
|
101
80
|
function addEmit(into: Parts, r: KitEmitResult): void {
|
|
@@ -166,21 +145,8 @@ export function compileStandardCrud(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
166
145
|
}
|
|
167
146
|
|
|
168
147
|
const overlays = input.overlays ?? {};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
else if (name === 'entity') fail('KIT-PAGE-001', '附加浮层名不能叫 entity(与主对象角色槽同名)', `product.overlays.${name}`);
|
|
172
|
-
}
|
|
173
|
-
// E3:只读浮层的 editOverlay 必须指向另一个存在的浮层(点「编辑」切过去,当前行保留)
|
|
174
|
-
const showEdit: Record<string, string> = {};
|
|
175
|
-
for (const [name, decl] of Object.entries(overlays)) {
|
|
176
|
-
if (decl.editOverlay === undefined) continue;
|
|
177
|
-
const at = `product.overlays.${name}.editOverlay`;
|
|
178
|
-
if (typeof decl.editOverlay !== 'string' || !(decl.editOverlay in overlays) || decl.editOverlay === name) {
|
|
179
|
-
fail('KIT-BIZ-003', `浮层 ${name} 的 editOverlay "${String(decl.editOverlay)}" 必须是另一个已声明的浮层名`, at);
|
|
180
|
-
} else {
|
|
181
|
-
showEdit[name] = decl.editOverlay;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
148
|
+
// 浮层名 / editOverlay 校验与 MasterSub 同一份(shared/overlay-compile.ts)
|
|
149
|
+
const showEdit = validateOverlayNames(overlays, ['entity'], fail);
|
|
184
150
|
// 整行点击:至多一个浮层写 rowClick: true;点行 / 行聚焦按 Enter 以当前行打开它
|
|
185
151
|
const rowClickNames = Object.entries(overlays).filter(([, d]) => d.rowClick !== undefined && d.rowClick !== false).map(([n]) => n);
|
|
186
152
|
for (const [name, decl] of Object.entries(overlays)) {
|
|
@@ -222,6 +188,7 @@ export function compileStandardCrud(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
222
188
|
registeredActions: ctx.registeredActions,
|
|
223
189
|
expandPath: expandMirrorPath,
|
|
224
190
|
formMode: 'create',
|
|
191
|
+
pagerClass: CRUD_CLASS.pager,
|
|
225
192
|
...(rowClickName !== undefined ? { pickOnRow: true } : {}),
|
|
226
193
|
// 弹窗表单的 mode / initial 绑 focus 镜像
|
|
227
194
|
formModePath: mirrorPath(scope, KIT_COORD_MIRRORS.mode.key),
|
|
@@ -351,115 +318,16 @@ export function compileStandardCrud(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
351
318
|
expandHolder = expandHolderHtml(expandHostId(object, name), childEmit.html, '');
|
|
352
319
|
continue;
|
|
353
320
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const ovObject = `${ctx.pageId}_${name}`;
|
|
365
|
-
const ovScope = `${ovObject}_scope`;
|
|
366
|
-
overlayObjects[name] = ovObject;
|
|
367
|
-
const linkKey = decl.behavior?.linkKey ?? keyField;
|
|
368
|
-
const params: Record<string, string> = { ...(decl.behavior?.params ?? {}) };
|
|
369
|
-
if (linkKey !== undefined && keyField !== undefined) params[linkKey] = `$${mirrorPath(scope, KIT_CRUD_LINK_KEY)}`;
|
|
370
|
-
const dynParams = Object.entries(params).filter(([, v]) => typeof v === 'string' && v.startsWith('$')).map(([k]) => k);
|
|
371
|
-
const reqParams = [...new Set([...(decl.behavior?.requireParams ?? []), ...(linkKey !== undefined && keyField !== undefined ? [linkKey] : []), ...dynParams])];
|
|
372
|
-
const ovObj: KitObject = {
|
|
373
|
-
schema: decl.schema ?? {},
|
|
374
|
-
behavior: {
|
|
375
|
-
...(decl.behavior ?? {}),
|
|
376
|
-
params,
|
|
377
|
-
...(reqParams.length > 0 ? { requireParams: reqParams } : {}),
|
|
378
|
-
},
|
|
379
|
-
view,
|
|
380
|
-
};
|
|
381
|
-
// K-9:浮层没有自己的读接口(无 behavior.from)时,当前行(协调组件 focus.row 的镜像)就是它的数据:
|
|
382
|
-
// 写死形状组件的 data、表单的 initial 都注入这一行,不必按主键回查
|
|
383
|
-
const rowPath = mirrorPath(scope, m.row.key);
|
|
384
|
-
const injectRow = decl.behavior?.from === undefined;
|
|
385
|
-
const ovEmit = labelDiagnostics(emitObject(
|
|
386
|
-
ovObj,
|
|
387
|
-
{ object: ovObject, scope: ovScope, registered: ctx.registeredComponents, staticComponents: ctx.staticComponents },
|
|
388
|
-
{ registeredActions: ctx.registeredActions, formMode: 'edit', ...(injectRow ? { summaryPath: rowPath } : {}) },
|
|
389
|
-
), ovObject);
|
|
390
|
-
addEmit(out, ovEmit);
|
|
391
|
-
if (decl.behavior?.from !== undefined) {
|
|
392
|
-
out.scopes[ovScope] = withScopeParts(out.scopes[ovScope], { id: ovScope, object: ovObject }, [], []);
|
|
393
|
-
}
|
|
394
|
-
// 浮层里的可编辑表单:编辑取回的单对象(或注入的当前行),保存后关窗并刷新
|
|
395
|
-
const ovFormId = viewAnchor(ovObject, 'form');
|
|
396
|
-
if (view.form !== undefined) {
|
|
397
|
-
patchProps(out.show, ovFormId, { mode: 'edit', initial: injectRow ? rowPath : `page.data.${ovObject}`, scope: `${ovObject}__form`, cancelLabel: CANCEL_LABEL });
|
|
398
|
-
wireDialogForm(out.events, ovFormId, scope);
|
|
399
|
-
}
|
|
400
|
-
// K-1 / M1-3:浮层里的写死形状数据组件(应用组件)按约定抛 saved / cancel / close / reload,由协调组件接;
|
|
401
|
-
// overlays.<名>.events 可再把自定义事件名映射到这四种之一。组件没抛的事件不会触发(core 对未声明的 emit 选择器惰性)
|
|
402
|
-
for (const slot of ['list', 'summary'] as const) {
|
|
403
|
-
const staticComp = view[slot]?.staticComponent;
|
|
404
|
-
if (staticComp === undefined) continue;
|
|
405
|
-
const knownEmits = ctx.staticComponents[staticComp]?.emits;
|
|
406
|
-
const explicitEvents = decl.events ?? {};
|
|
407
|
-
const anchor = viewAnchor(ovObject, slot);
|
|
408
|
-
// 接了具名动作的事件:编完后自动带上该动作的 busy 绑定(手写 busy_action 优先)
|
|
409
|
-
const namedOn: Record<string, string> = {};
|
|
410
|
-
for (const [emitName, role] of Object.entries<string | KitOverlayEventAction>({ ...OVERLAY_EVENT_ROLES, ...explicitEvents })) {
|
|
411
|
-
if (!(emitName in explicitEvents) && knownEmits !== undefined && !knownEmits.includes(emitName)) continue;
|
|
412
|
-
if (typeof role !== 'string') {
|
|
413
|
-
// { action }:绑一条具名动作 / request / download 管道;动作之后的提示 / 重取 / 关窗写在具名动作处理函数里
|
|
414
|
-
const epath = `${at}.events.${emitName}`;
|
|
415
|
-
if (!isRec(role) || typeof role.action !== 'string' || role.action === '') {
|
|
416
|
-
fail('KIT-EVT-001', `附加浮层 ${name} 的 events.${emitName} 必须是角色名或 { action }`, epath);
|
|
417
|
-
continue;
|
|
418
|
-
}
|
|
419
|
-
// action 可以是主对象 behavior.actions 里的 request / download 动作 id(声明式请求,交页面级 KitActionHost),否则必须是登记的具名动作
|
|
420
|
-
const declared = actions.find((a) => a.id === role.action && isRequestLikeAction(a));
|
|
421
|
-
let actionPipe = `ACTION | ${role.action}`;
|
|
422
|
-
if (declared !== undefined) {
|
|
423
|
-
// 请求由宿主异步执行:浮层事件绑的请求是这个浮层的「提交」,成功后由宿主固定关窗并重取(失败时窗口保留,编辑不丢)
|
|
424
|
-
const registered = registerRequestAction(declared, object, `${epath}.action`, out.diagnostics, { closeOnSuccess: true });
|
|
425
|
-
if (registered === null) continue;
|
|
426
|
-
actionPipe = registered;
|
|
427
|
-
} else if (!ctx.registeredActions.has(role.action)) {
|
|
428
|
-
fail('KIT-EVT-001', `附加浮层 ${name} 的 events.${emitName}.action "${role.action}" 未在应用的具名动作中登记`, `${epath}.action`);
|
|
429
|
-
continue;
|
|
430
|
-
}
|
|
431
|
-
const extra = Object.keys(role).filter((k) => k !== 'action');
|
|
432
|
-
if (extra.length > 0) {
|
|
433
|
-
fail('KIT-EVT-001', `附加浮层 ${name} 的 events.${emitName} 只许 action 键(多余:${extra.join(' / ')};动作之后的事写在具名动作处理函数里)`, epath);
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
out.events[`${anchor}.${emitName}`] = actionPipe;
|
|
437
|
-
namedOn[emitName] = role.action;
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
|
-
const sem = OVERLAY_ROLE_SEMANTIC[role];
|
|
441
|
-
if (sem === undefined) {
|
|
442
|
-
fail('KIT-EVT-001', `附加浮层 ${name} 的 events.${emitName} = "${role}" 不在 ${Object.keys(OVERLAY_ROLE_SEMANTIC).join(' / ')} 内`, `${at}.events.${emitName}`);
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
out.events[`${anchor}.${emitName}`] = semanticPipe(scope, sem);
|
|
446
|
-
}
|
|
447
|
-
const busyNames = busyActionOf(view[slot]!.staticComponent!, namedOn);
|
|
448
|
-
const shown = out.show[anchor];
|
|
449
|
-
if (busyNames !== null && isRec(shown) && isRec(shown.props) && shown.props.busy_action === undefined) {
|
|
450
|
-
patchProps(out.show, anchor, { busy_action: busyNames });
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
const ids = overlayIds(object, name);
|
|
454
|
-
overlayMirrors.push({ key: overlayMirrorKey(name), slice: 'focus', path: `ov.${name}`, as: 'truthy' });
|
|
455
|
-
out.show[ids.layer] = { when: mirrorPath(scope, overlayMirrorKey(name)) };
|
|
456
|
-
out.events[`${ids.close}.click`] = semanticPipe(scope, KIT_COORD_EVENTS.close);
|
|
457
|
-
const withEdit = name in showEdit;
|
|
458
|
-
if (withEdit) {
|
|
459
|
-
out.show[ids.edit] = { props: { label: EDIT_COPY, variant: 'neutral', size: 'sm' } };
|
|
460
|
-
out.events[`${ids.edit}.click`] = semanticPipe(scope, KIT_COORD_EVENTS.showEdit);
|
|
461
|
-
}
|
|
462
|
-
overlayHtmls.push(overlayHtml(ids, decl.kind, decl.title ?? name, ovEmit.html, decl.class, areaClass, withEdit, CLOSE_LABEL));
|
|
321
|
+
// dialog / drawer 浮层的共用编译(shared/overlay-compile.ts,与 MasterSub 同一份)
|
|
322
|
+
const compiled = compileOverlay(
|
|
323
|
+
{ out, ctx, scope, object, keyField, actions, areaClass, closeLabel: CLOSE_LABEL, cancelLabel: CANCEL_LABEL, editLabel: EDIT_COPY, showEdit },
|
|
324
|
+
name,
|
|
325
|
+
decl,
|
|
326
|
+
);
|
|
327
|
+
if (compiled === undefined) continue;
|
|
328
|
+
overlayObjects[name] = compiled.object;
|
|
329
|
+
overlayMirrors.push(compiled.mirror);
|
|
330
|
+
overlayHtmls.push(compiled.html);
|
|
463
331
|
}
|
|
464
332
|
|
|
465
333
|
// 主对象作用域:补 focus 切片(owner 是协调组件)与镜像
|
|
@@ -474,12 +342,9 @@ export function compileStandardCrud(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
474
342
|
);
|
|
475
343
|
|
|
476
344
|
// ---- 壳
|
|
477
|
-
const removeConfirms = removeConfirmTemplates(actions);
|
|
478
345
|
out.show[coordinatorId(object)] = {
|
|
479
346
|
props: {
|
|
480
347
|
scope, object, keyField: keyField ?? '', reloads: [], overlays: overlayObjects, showEdit, rowsPath: entityEmit.compiled.listShape.rows, ...(expandObject !== '' ? { expandObject } : {}),
|
|
481
|
-
// 带行占位的删除确认:动作 id -> 确认文案模板(运行期按被删行插值)
|
|
482
|
-
...(Object.keys(removeConfirms).length > 0 ? { removeConfirms } : {}),
|
|
483
348
|
overlayActions: {
|
|
484
349
|
...Object.fromEntries(actions.filter((a) => a.builtin === 'openOverlay' && a.targetOverlay !== undefined).map((a) => [a.id, a.targetOverlay as string])),
|
|
485
350
|
...(rowClickName !== undefined ? { select: rowClickName } : {}),
|
|
@@ -496,10 +361,20 @@ export function compileStandardCrud(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
496
361
|
out.events[`${ids.dialogClose}.click`] = semanticPipe(scope, KIT_COORD_EVENTS.close);
|
|
497
362
|
// K-7:form 视图的 title(字符串两态通用,或 { create, edit })覆写弹窗标题;缺省取动作名
|
|
498
363
|
const titles = dialogTitles((entity.view?.form as KitViewForm | undefined)?.title, { create: createCopy, edit: editCopy });
|
|
499
|
-
dialog = dialogHtml(ids, titles, entityEmit.parts.form ?? '', areaClass, CLOSE_LABEL);
|
|
364
|
+
dialog = dialogHtml(ids, titles, entityEmit.parts.form ?? '', areaClass, CLOSE_LABEL, '', dialogWidthOf({ form: entity.view?.form, schema: entity.schema }));
|
|
500
365
|
}
|
|
501
366
|
|
|
502
|
-
|
|
367
|
+
// 页头概况行:筛选区有枚举字段才给;总数 / facets 取列表响应(facets 是总数的同级兄弟字段,接口不给就整行不渲染)
|
|
368
|
+
const summaryFields = hasList ? listSummaryFields(entity) : [];
|
|
369
|
+
let summary = '';
|
|
370
|
+
if (summaryFields.length > 0) {
|
|
371
|
+
const sid = `${object}__list_summary`;
|
|
372
|
+
const totalPath = `page.data.${object}.${entityEmit.compiled.listShape.total}`;
|
|
373
|
+
out.components.add('KitListSummary');
|
|
374
|
+
out.show[sid] = { props: { total: totalPath, facets: facetsPathOf(totalPath), fields: summaryFields } };
|
|
375
|
+
summary = listSummaryHoist(`<div data-soma-component="KitListSummary" data-soma-id="${esc(sid)}"></div>`);
|
|
376
|
+
}
|
|
377
|
+
const main = mainHtml({ filter: entityEmit.parts.filter ?? '', toolbar: entityEmit.parts.toolbar ?? '', list: listHtml, summary }, areaClass);
|
|
503
378
|
const html = rootHtml(object, [main, coordinatorHtml(object), dialog, ...overlayHtmls, expandHolder], areaClass, input.class);
|
|
504
379
|
|
|
505
380
|
for (const c of classesIn(html)) out.candidates.add(c);
|
|
@@ -4,28 +4,34 @@ import { esc } from '../../shared/escape';
|
|
|
4
4
|
// 显隐层统一用 `fixed inset-0` 的遮罩 + 内层 flex 容器:显隐只靠 core 写 `hidden` 属性,不在遮罩自身叠 display 类。
|
|
5
5
|
|
|
6
6
|
import { mergeClass } from '../../object-renderer/merge-class';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { KIT_LIST_BAR_FLAT_CLASS } from '../../recipes/container';
|
|
8
|
+
import { KIT_LIST_PANEL_CLASS, flatListPanelHtml, listPanelParts } from '../shared/compile-helpers';
|
|
9
|
+
import { OVERLAY_SHELL_CLASS, classAttr, closeButtonHtml, dialogHtml, dialogIds, dialogIsWide, dialogTitles, dialogWidthOf, overlayHtml, overlayIds } from '../shared/overlay-shell';
|
|
9
10
|
|
|
10
|
-
//
|
|
11
|
-
export { closeButtonHtml, dialogHtml, dialogIds, dialogTitles };
|
|
11
|
+
// 弹窗外壳与附加浮层壳的公共部分已下沉到 biz/shared/overlay-shell(主从工作台同用);这里原样 re-export,保持原导出名可用
|
|
12
|
+
export { closeButtonHtml, dialogHtml, dialogIds, dialogIsWide, dialogTitles, dialogWidthOf, overlayHtml, overlayIds };
|
|
12
13
|
|
|
13
14
|
/** 壳的内部区域名(`areaClass` 的合法键) */
|
|
14
15
|
export const STANDARD_CRUD_AREAS = ['root', 'filter', 'list', 'dialog', 'drawer'] as const;
|
|
15
16
|
export type StandardCrudArea = (typeof STANDARD_CRUD_AREAS)[number];
|
|
16
17
|
|
|
17
18
|
export const CRUD_CLASS = {
|
|
18
|
-
root: 'flex flex-col gap-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
root: 'flex flex-col gap-region',
|
|
20
|
+
/** 筛选带(列表为空 / 无集合时单独出现):自带圆角的下沉带,与列表工作面里的筛选带同一份类(不再是独立卡) */
|
|
21
|
+
filter: KIT_LIST_BAR_FLAT_CLASS,
|
|
22
|
+
/** 列表工作面:无容器(唯一主体 = 页面本身),表头 / 数据行 / 计数分页直接铺在页面上 */
|
|
23
|
+
list: 'flex flex-col gap-region',
|
|
24
|
+
listHeadRow: KIT_LIST_PANEL_CLASS.listHeadRow,
|
|
25
|
+
/** 分页条:贴工作面底(内容不足一屏时在表后自然位置,超出一屏时粘在底)、底色同工作面、文字落在对齐轴上(轴内边距同 p-card 角色) */
|
|
26
|
+
pager: 'sticky bottom-0 z-10 bg-surface px-card py-2',
|
|
22
27
|
...OVERLAY_SHELL_CLASS,
|
|
23
28
|
} as const;
|
|
24
29
|
|
|
25
30
|
const cls = classAttr;
|
|
26
31
|
|
|
32
|
+
// 协作宿主(KitCrudBridge)没有界面:class=hidden 让它不占 flex 子项的位(否则根的 flex gap 为它多量出一份间距)
|
|
27
33
|
function host(component: string, id: string): string {
|
|
28
|
-
return `<div data-soma-component="${component}" data-soma-id="${esc(id)}"></div>`;
|
|
34
|
+
return `<div data-soma-component="${component}" data-soma-id="${esc(id)}" class="hidden"></div>`;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
export interface CrudShellIds {
|
|
@@ -38,13 +44,6 @@ export interface CrudShellIds {
|
|
|
38
44
|
dialogClose: string;
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
export function overlayIds(object: string, name: string): { layer: string; title: string; close: string; edit: string } {
|
|
42
|
-
return {
|
|
43
|
-
layer: `${object}__ov_${name}_layer`, title: `${object}__ov_${name}_title`, close: `${object}__ov_${name}_close`,
|
|
44
|
-
edit: `${object}__ov_${name}_edit`,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
47
|
export function rootId(object: string): string {
|
|
49
48
|
return `${object}__crud_root`;
|
|
50
49
|
}
|
|
@@ -53,50 +52,14 @@ export function coordinatorId(object: string): string {
|
|
|
53
52
|
return `${object}__link`;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
/** 主区:筛选卡 + 列表卡(工具栏在列表卡里,排在列表之前)。区域类按 7.3
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (m !== null) {
|
|
65
|
-
const titleH3 = m[1]!.replace(/\bmb-\d+(?:\.\d+)?\s*/g, '');
|
|
66
|
-
const restList = m[2]!;
|
|
67
|
-
listInner = [`<div${cls(CRUD_CLASS.listHeadRow)}>${titleH3}${parts.toolbar}</div>`, restList].filter((p) => p !== '').join('\n');
|
|
68
|
-
} else {
|
|
69
|
-
listInner = [parts.toolbar, parts.list].filter((p) => p !== '').join('\n');
|
|
70
|
-
}
|
|
71
|
-
if (listInner !== '') blocks.push(`<section${cls(mergeClass(CRUD_CLASS.list, areaClass.list))}>${listInner}</section>`);
|
|
72
|
-
return blocks.join('\n');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** 附加浮层(dialog / drawer):`panelClass` 是声明里的 `class`,按同族规则覆写基准 */
|
|
76
|
-
export function overlayHtml(
|
|
77
|
-
ids: ReturnType<typeof overlayIds>,
|
|
78
|
-
kind: 'dialog' | 'drawer',
|
|
79
|
-
title: string,
|
|
80
|
-
body: string,
|
|
81
|
-
panelClass: string | undefined,
|
|
82
|
-
areaClass: Record<string, string>,
|
|
83
|
-
withEdit = false,
|
|
84
|
-
closeLabel = 'Close',
|
|
85
|
-
footer = '',
|
|
86
|
-
): string {
|
|
87
|
-
const isDrawer = kind === 'drawer';
|
|
88
|
-
const base = isDrawer ? CRUD_CLASS.drawer : CRUD_CLASS.dialog;
|
|
89
|
-
const panel = mergeClass(mergeClass(base, areaClass[kind]), panelClass);
|
|
90
|
-
return `<div data-soma-id="${esc(ids.layer)}">`
|
|
91
|
-
+ `<div data-kit-scrim="" ${KIT_FIXED_ATTRIBUTE}=""${cls(isDrawer ? CRUD_CLASS.drawerRow : CRUD_CLASS.dialogRow)}>`
|
|
92
|
-
+ `<div role="dialog" aria-modal="true"${cls(panel)} data-kit-part="${isDrawer ? KIT_PART_DRAWER : KIT_PART_DIALOG}" aria-labelledby="${esc(ids.title)}">`
|
|
93
|
-
+ `<div data-kit-overlay-header=""${cls(CRUD_CLASS.header)}>`
|
|
94
|
-
+ `<h2 id="${esc(ids.title)}" data-soma-id="${esc(ids.title)}"${cls(CRUD_CLASS.title)} data-kit-part="${KIT_PART_TITLE_DIALOG}">${esc(title)}</h2>`
|
|
95
|
-
+ (withEdit ? `<div${cls(CRUD_CLASS.headerActions)}>${host('Button', ids.edit)}${closeButtonHtml(ids.close, closeLabel)}</div>` : closeButtonHtml(ids.close, closeLabel))
|
|
96
|
-
+ '</div>'
|
|
97
|
-
+ `<div data-kit-overlay-body=""${cls(CRUD_CLASS.body)}>${body}</div>`
|
|
98
|
-
+ (footer !== '' ? `<div data-kit-overlay-footer=""${cls(CRUD_CLASS.footer)}>${footer}</div>` : '')
|
|
99
|
-
+ '</div></div></div>';
|
|
55
|
+
/** 主区:筛选卡 + 列表卡(工具栏在列表卡里,排在列表之前)。区域类按 7.3 同族规则覆写。拆分规则与主从 / 分类壳共用 shared/compile-helpers#listPanelParts */
|
|
56
|
+
export function mainHtml(parts: { filter: string; toolbar: string; list: string; summary?: string }, areaClass: Record<string, string>): string {
|
|
57
|
+
const { filterInner, listInner } = listPanelParts(parts);
|
|
58
|
+
if (listInner === '') return parts.filter === '' ? '' : `<div${cls(mergeClass(CRUD_CLASS.filter, areaClass.filter))}>${filterInner}</div>`;
|
|
59
|
+
// 页面构成(C2 唯一主体 = 页面本身):列表就是页面——不再包一张卡(container: plain、强调 primary),页面底取面板面(data-kit-canvas-hint,页面编译写 data-kit-canvas);
|
|
60
|
+
// 筛选带是自带圆角的下沉带,区域主动作打搬运标记由页面编译搬进页头尾端(页头一行 = 标题 + 主动作)
|
|
61
|
+
// 用 div 而不是 section:section 会被主题当容器画外框(描边 / 圆角 / 阴影),而本工作面是无容器的页面本体
|
|
62
|
+
return `<div data-kit-emphasis="primary" data-kit-role="subject" data-kit-container="plain" data-kit-canvas-hint="surface" data-kit-axis=""${cls(mergeClass(CRUD_CLASS.list, areaClass.list))}>${parts.summary ?? ''}${flatListPanelHtml(parts, areaClass.filter ?? '')}</div>`;
|
|
100
63
|
}
|
|
101
64
|
|
|
102
65
|
export function rootHtml(object: string, children: string[], areaClass: Record<string, string>, extra: string | undefined): string {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// StandardCrud 页头概况行的编译期部分:从筛选区的枚举字段取分面字段(名 + 枚举值 → 标签),给 KitListSummary 的静态 props。
|
|
2
|
+
// 总数 / facets 的取值路径由列表响应的总数路径推出(facets 与总数同级的兄弟字段);响应没给 facets 时组件整行不渲染。
|
|
3
|
+
|
|
4
|
+
import { esc } from '../../shared/escape';
|
|
5
|
+
import type { KitListSummaryField } from '../../frames/list-summary';
|
|
6
|
+
import { KIT_HOIST_ATTR, KIT_HOIST_HEADER_SUMMARY } from '../shared/compile-helpers';
|
|
7
|
+
|
|
8
|
+
type Rec = Record<string, unknown>;
|
|
9
|
+
|
|
10
|
+
function isRec(v: unknown): v is Rec {
|
|
11
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** 筛选区里的枚举字段(按筛选字段序):字段声明了 options({ value, label })才算;没有枚举字段 → 空数组(页头不给概况)。 */
|
|
15
|
+
export function listSummaryFields(entity: { schema: unknown; view?: unknown }): KitListSummaryField[] {
|
|
16
|
+
const view = isRec(entity.view) ? entity.view : undefined;
|
|
17
|
+
const filter = view !== undefined && isRec(view.filter) ? view.filter : undefined;
|
|
18
|
+
const names = Array.isArray(filter?.fields)
|
|
19
|
+
? (filter.fields as unknown[]).map((f) => (typeof f === 'string' ? f : isRec(f) ? Object.keys(f)[0] : undefined)).filter((n): n is string => n !== undefined)
|
|
20
|
+
: [];
|
|
21
|
+
const schema = isRec(entity.schema) ? entity.schema : {};
|
|
22
|
+
const out: KitListSummaryField[] = [];
|
|
23
|
+
for (const field of names) {
|
|
24
|
+
const decl = schema[field];
|
|
25
|
+
if (!isRec(decl) || decl.type !== 'enum' || !Array.isArray(decl.options)) continue;
|
|
26
|
+
const options = (decl.options as unknown[]).flatMap((o) => (isRec(o) && typeof o.value === 'string' ? [{ value: o.value, label: typeof o.label === 'string' ? o.label : o.value }] : []));
|
|
27
|
+
if (options.length > 0) out.push({ field, options });
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 列表响应总数路径的同级 facets 路径(`a.b.total` → `a.b.facets`)。 */
|
|
33
|
+
export function facetsPathOf(totalPath: string): string {
|
|
34
|
+
return totalPath.includes('.') ? totalPath.replace(/\.[^.]+$/, '.facets') : 'facets';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 概况行的搬运块(标记 + 宿主);调用方保证宿主 id 与 show 条目已登记。 */
|
|
38
|
+
export function listSummaryHoist(hostHtml: string): string {
|
|
39
|
+
return `<div ${KIT_HOIST_ATTR}="${esc(KIT_HOIST_HEADER_SUMMARY)}" class="contents">${hostHtml}</div>`;
|
|
40
|
+
}
|