soma-kit 0.1.11 → 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 +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -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 +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- 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 +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- 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/image.ts +1 -1
- package/src/base/index.ts +35 -11
- 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 +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- 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 +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- 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 +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- 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 +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- 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 +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- 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/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- 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 +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- 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/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 +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- 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/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/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- 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 +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -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 +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- 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 +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- 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 +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- 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 +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -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/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -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 +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- 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 +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -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 +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -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/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
package/src/base/virtual-list.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// (不是 HTML style 属性、不进模板,CSP 安全)。这是 kit 里唯一的运行期几何写入,集中在 `setSpacerHeight`。
|
|
15
15
|
|
|
16
16
|
import { KIT_COLLECTION_LIMITS } from 'soma-foundation/kit-limits';
|
|
17
|
+
import { KIT_NINE_DIM } from 'soma-foundation/kit-nine-dim';
|
|
17
18
|
import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
|
|
18
19
|
|
|
19
20
|
type Json = Record<string, any>;
|
|
@@ -22,6 +23,58 @@ const V = ((grammarJson as unknown as Json).collectionKeys as Json).virtual as J
|
|
|
22
23
|
export type KitRowTier = 'sm' | 'md' | 'lg';
|
|
23
24
|
export const KIT_ROW_TIERS: readonly KitRowTier[] = V.tiers as KitRowTier[];
|
|
24
25
|
export const KIT_VIRTUAL_ROW_PX: Readonly<Record<KitRowTier, number>> = KIT_COLLECTION_LIMITS.virtual.rowHeightPx;
|
|
26
|
+
|
|
27
|
+
// ── 初始行高估算跟随密度 ─────────────────────────────────────
|
|
28
|
+
// 档位行高类 h-8 / h-10 / h-12 是 Tailwind 的 N × --spacing,--spacing 即九维密度的间距单位(--soma-space-1,紧凑 3.5 / 标准 4 / 宽松 5 px);
|
|
29
|
+
// KIT_VIRTUAL_ROW_PX 按标准单位给 32 / 40 / 48。挂载时读宿主的间距单位,按「当前单位 / 标准单位」缩放,首帧估算就与实测一致。
|
|
30
|
+
// 标准单位取九维真源(density.default 那一档的 spaceUnitPx),不写字面量;读不到(jsdom、非九维主题、生成物未刷新)一律不缩放。
|
|
31
|
+
|
|
32
|
+
type StandardUnitSource = { default?: string; controlUnits?: number; levels?: ReadonlyArray<{ id?: string; spaceUnitPx?: number; controlHeightPx?: number }> };
|
|
33
|
+
|
|
34
|
+
/** 标准密度档的间距单位(px);真源读不到返回 null */
|
|
35
|
+
export function standardSpaceUnitPx(): number | null {
|
|
36
|
+
const d = (KIT_NINE_DIM.dimensions as unknown as { density?: StandardUnitSource }).density;
|
|
37
|
+
const level = d?.levels?.find((l) => l.id === d.default);
|
|
38
|
+
if (typeof level?.spaceUnitPx === 'number' && level.spaceUnitPx > 0) return level.spaceUnitPx;
|
|
39
|
+
// 兼容未刷新的生成物:控件高 = 单位 × controlUnits
|
|
40
|
+
if (typeof level?.controlHeightPx === 'number' && typeof d?.controlUnits === 'number' && d.controlUnits > 0) return level.controlHeightPx / d.controlUnits;
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 解析 `--soma-space-1` 的字面值(`3.5px`);非「正数 + px」一律 null */
|
|
45
|
+
export function parseSpaceUnitPx(raw: string | null | undefined): number | null {
|
|
46
|
+
const m = /^\s*(\d+(?:\.\d+)?)px\s*$/.exec(raw ?? '');
|
|
47
|
+
const n = m ? Number(m[1]) : NaN;
|
|
48
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 读宿主算出来的间距单位(px);取不到 null */
|
|
52
|
+
export function readSpaceUnitPx(host: Element | null): number | null {
|
|
53
|
+
const view = host?.ownerDocument?.defaultView;
|
|
54
|
+
if (!host || !view || typeof view.getComputedStyle !== 'function') return null;
|
|
55
|
+
try {
|
|
56
|
+
return parseSpaceUnitPx(view.getComputedStyle(host).getPropertyValue('--soma-space-1'));
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 纯缩放:任一单位缺失 / 非正数就原样返回 */
|
|
63
|
+
export function scaleRowPx(basePx: number, unitPx: number | null, standardPx: number | null): number {
|
|
64
|
+
if (unitPx === null || standardPx === null || !(unitPx > 0) || !(standardPx > 0)) return basePx;
|
|
65
|
+
return basePx * unitPx / standardPx;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 某档位的初始行高估算(px):标准估算值按宿主当前间距单位缩放;reader / standard 可注入(测试用) */
|
|
69
|
+
export function virtualRowPx(
|
|
70
|
+
tier: KitRowTier,
|
|
71
|
+
host: Element | null,
|
|
72
|
+
reader: (host: Element | null) => number | null = readSpaceUnitPx,
|
|
73
|
+
standard: () => number | null = standardSpaceUnitPx,
|
|
74
|
+
): number {
|
|
75
|
+
return scaleRowPx(KIT_VIRTUAL_ROW_PX[tier], reader(host), standard());
|
|
76
|
+
}
|
|
77
|
+
|
|
25
78
|
export const KIT_VIRTUAL_ROW_CLASS: Readonly<Record<KitRowTier, string>> = V.rowClass;
|
|
26
79
|
export const KIT_VIRTUAL_OPTION_ROW_CLASS: Readonly<Record<KitRowTier, string>> = V.componentProps.optionRowClass;
|
|
27
80
|
export const KIT_VIRTUAL_VIEWPORT_CLASS: Readonly<Record<KitRowTier, string>> = V.viewportClass;
|
|
@@ -175,18 +228,61 @@ export function createVirtualWindow(o: VirtualWindowOptions): VirtualWindow {
|
|
|
175
228
|
const port = portOf(o.services);
|
|
176
229
|
let count = Math.max(0, Math.min(Math.floor(o.count), KIT_VIRTUAL_MAX_COUNT));
|
|
177
230
|
let px = o.rowPx;
|
|
231
|
+
/** 当前档位的估算基准(容器宽度变化后复位用;换档时随 setRowPx 更新) */
|
|
232
|
+
let basePx = o.rowPx;
|
|
178
233
|
let virt: VirtualizerLike | null = null;
|
|
179
234
|
let off: (() => void) | null = null;
|
|
180
235
|
let failed = port === null;
|
|
181
236
|
let starting = false;
|
|
182
237
|
let disposed = false;
|
|
183
238
|
let calibrated = false;
|
|
239
|
+
let resizeObs: ResizeObserver | null = null;
|
|
240
|
+
let observedEl: HTMLElement | null = null;
|
|
241
|
+
let lastWidth = -1;
|
|
242
|
+
let pendingAnchorIndex = 0;
|
|
184
243
|
if (failed) warnOnce();
|
|
185
244
|
|
|
245
|
+
const bindResize = (sc: HTMLElement): void => {
|
|
246
|
+
if (typeof ResizeObserver === 'undefined' || disposed || observedEl === sc) return;
|
|
247
|
+
resizeObs?.disconnect();
|
|
248
|
+
observedEl = sc;
|
|
249
|
+
lastWidth = sc.clientWidth || sc.getBoundingClientRect?.().width || 0;
|
|
250
|
+
resizeObs = new ResizeObserver((entries) => {
|
|
251
|
+
if (disposed) return;
|
|
252
|
+
const entry = entries[0];
|
|
253
|
+
const newWidth = entry?.contentRect?.width ?? observedEl?.clientWidth ?? 0;
|
|
254
|
+
if (newWidth > 0 && lastWidth > 0 && Math.abs(newWidth - lastWidth) >= 0.5) {
|
|
255
|
+
lastWidth = newWidth;
|
|
256
|
+
// 容器宽度变化(如视口缩放、侧栏折叠折行变动):清高度缓存并重算,保持当前滚动锚点(首个可见项)不跳
|
|
257
|
+
calibrated = false;
|
|
258
|
+
px = basePx;
|
|
259
|
+
let anchorIndex = 0;
|
|
260
|
+
if (virt !== null) {
|
|
261
|
+
const items = virt.items();
|
|
262
|
+
if (items.length > 0) anchorIndex = items[0]!.index;
|
|
263
|
+
pendingAnchorIndex = anchorIndex;
|
|
264
|
+
off?.();
|
|
265
|
+
off = null;
|
|
266
|
+
virt.dispose();
|
|
267
|
+
virt = null;
|
|
268
|
+
}
|
|
269
|
+
start();
|
|
270
|
+
o.onChange();
|
|
271
|
+
} else if (lastWidth <= 0 && newWidth > 0) {
|
|
272
|
+
lastWidth = newWidth;
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
try {
|
|
276
|
+
resizeObs.observe(sc);
|
|
277
|
+
} catch { /* 忽略不支持的环境 */ }
|
|
278
|
+
};
|
|
279
|
+
|
|
186
280
|
const start = (): void => {
|
|
187
281
|
if (disposed || failed || starting || virt !== null || port === null) return;
|
|
188
282
|
// 滚动容器还没挂上:端口 create 会抛 CORE-VIRTUAL-SCROLLER,那不是引擎故障,等下一次 range() 再试
|
|
189
|
-
|
|
283
|
+
const sc = o.scroller();
|
|
284
|
+
if (sc === null) return;
|
|
285
|
+
bindResize(sc);
|
|
190
286
|
starting = true;
|
|
191
287
|
port.create({
|
|
192
288
|
count,
|
|
@@ -198,6 +294,10 @@ export function createVirtualWindow(o: VirtualWindowOptions): VirtualWindow {
|
|
|
198
294
|
starting = false;
|
|
199
295
|
if (disposed) { v.dispose(); return; }
|
|
200
296
|
virt = v;
|
|
297
|
+
if (pendingAnchorIndex > 0) {
|
|
298
|
+
try { v.scrollToIndex(pendingAnchorIndex, 'auto'); } catch {}
|
|
299
|
+
pendingAnchorIndex = 0;
|
|
300
|
+
}
|
|
201
301
|
off = v.subscribe(() => o.onChange());
|
|
202
302
|
o.onChange();
|
|
203
303
|
}).catch(() => {
|
|
@@ -216,6 +316,8 @@ export function createVirtualWindow(o: VirtualWindowOptions): VirtualWindow {
|
|
|
216
316
|
range() {
|
|
217
317
|
if (failed) return { start: 0, end: count };
|
|
218
318
|
if (virt === null) {
|
|
319
|
+
const sc = o.scroller();
|
|
320
|
+
if (sc !== null) bindResize(sc);
|
|
219
321
|
start();
|
|
220
322
|
return { start: 0, end: initialEnd() };
|
|
221
323
|
}
|
|
@@ -257,6 +359,7 @@ export function createVirtualWindow(o: VirtualWindowOptions): VirtualWindow {
|
|
|
257
359
|
setRowPx(next) {
|
|
258
360
|
if (!(next > 0) || next === px) return;
|
|
259
361
|
px = next;
|
|
362
|
+
basePx = next;
|
|
260
363
|
calibrated = false;
|
|
261
364
|
if (virt !== null) {
|
|
262
365
|
off?.();
|
|
@@ -277,6 +380,9 @@ export function createVirtualWindow(o: VirtualWindowOptions): VirtualWindow {
|
|
|
277
380
|
},
|
|
278
381
|
dispose() {
|
|
279
382
|
disposed = true;
|
|
383
|
+
resizeObs?.disconnect();
|
|
384
|
+
resizeObs = null;
|
|
385
|
+
observedEl = null;
|
|
280
386
|
off?.();
|
|
281
387
|
off = null;
|
|
282
388
|
virt?.dispose();
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 切换选中 队列行点击(pickOnRow)-> SCOPE semantic link_pick -> 枢纽写 selection;
|
|
6
6
|
// 审批单 / 历史的 from.params 带关联键(link_sel_key);枢纽抛 picked -> 页面对二者 `SCOPE | window-reload`
|
|
7
7
|
// 通过 / 驳回 做成审批单摘要里的「字段按钮」(schema 里声明虚拟字段,component: Button,action 指向 on: field 的动作):
|
|
8
|
-
// 按钮点击 -> 枢纽语义事件 ->
|
|
8
|
+
// 按钮点击 -> 枢纽语义事件 -> 枢纽补上当前选中行抛槽位事件 field_action_<序号> { row } -> 各槽位绑各自的具名动作,
|
|
9
9
|
// 动作之后追加 kit_reload(协调组件重取队列 + 审批单 + 历史)
|
|
10
10
|
// 工具栏按钮载荷里没有行,所以审批单不接受 on: toolbar 的具名动作(KIT-BIZ-003)
|
|
11
11
|
// 处理完选中下一条 枢纽 afterRemove: next:队列刷新后选中项消失,选它原位置的下一条(没有就选上一条)
|
|
@@ -17,30 +17,17 @@ import type { SomaScopeMirrorDecl } from 'soma-core';
|
|
|
17
17
|
import type { KitObject } from '../../object-renderer/types';
|
|
18
18
|
import type { KitFragment } from '../../compile/fragment';
|
|
19
19
|
import type { KitBizContext, KitBizInput } from '../types';
|
|
20
|
-
import { KIT_COORD_EVENTS } from '../shared/coordinator';
|
|
21
20
|
import { KIT_LINK_MIRRORS, KIT_SEL_PATH } from '../link/hub';
|
|
21
|
+
import { bizObjectName, finishBizCompile, validateBizAreaClass } from '../shared/compile-helpers';
|
|
22
22
|
import {
|
|
23
|
-
|
|
24
|
-
normalizeMember,
|
|
23
|
+
bindFieldSlots, bindPickedReloads, classesIn, emitMember, grantPageReset, isRec, keyFieldOf, linkRemoveProps, mirrorPath, newParts,
|
|
24
|
+
normalizeMember, sortMirrors, type FieldSlots, type Rec,
|
|
25
25
|
} from '../link/shared';
|
|
26
|
+
import { ApprovalDesk } from './index';
|
|
26
27
|
import { APPROVAL_DESK_AREAS, APPROVAL_DESK_CLASS, approvalDeskHtml, approvalDeskIds } from './shell';
|
|
27
28
|
|
|
28
|
-
const RESERVED = new Set(['page', 'p', 'ctrl', 'frame', 'tabs']);
|
|
29
|
-
|
|
30
29
|
export function approvalDeskObjectName(pageId: string, role: 'queue' | 'request' | 'history'): string {
|
|
31
|
-
|
|
32
|
-
return RESERVED.has(name) ? `${name}_obj` : name;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function finish(out: Parts, html: string): KitFragment {
|
|
36
|
-
return {
|
|
37
|
-
html,
|
|
38
|
-
ui: { data: out.data, scopes: out.scopes as unknown as Record<string, unknown>, show: out.show },
|
|
39
|
-
events: out.events,
|
|
40
|
-
components: [...out.components].sort(),
|
|
41
|
-
candidates: [...out.candidates].sort(),
|
|
42
|
-
diagnostics: dedupeDiagnostics(out.diagnostics),
|
|
43
|
-
};
|
|
30
|
+
return bizObjectName(pageId, role);
|
|
44
31
|
}
|
|
45
32
|
|
|
46
33
|
function isStaticView(s: unknown): boolean {
|
|
@@ -64,12 +51,8 @@ export function compileApprovalDesk(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
64
51
|
if (rawHistory !== undefined && (!isRec(rawHistory) || (!isStaticView(rawHistory) && !isRec(rawHistory.schema)) || !isRec(rawHistory.behavior))) {
|
|
65
52
|
fail('KIT-BIZ-001', 'ApprovalDesk 的 history 必须是对象声明(schema / behavior;写死形状组件可省 schema)', 'product.objects.history');
|
|
66
53
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
fail('KIT-PAGE-001', `areaClass 里的区域名 "${key}" 不在 ApprovalDesk 的区域闭集 ${APPROVAL_DESK_AREAS.join(' / ')} 内`, `product.areaClass.${key}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (out.diagnostics.length > 0) return finish(out, '');
|
|
54
|
+
validateBizAreaClass(input, 'ApprovalDesk', APPROVAL_DESK_AREAS, out.diagnostics);
|
|
55
|
+
if (out.diagnostics.length > 0) return finishBizCompile(out, '');
|
|
73
56
|
|
|
74
57
|
// 审批单的具名动作必须是字段按钮:工具栏载荷里没有行
|
|
75
58
|
const reqActions = isRec(rawRequest) && isRec(rawRequest.behavior) && Array.isArray((rawRequest.behavior as Rec).actions)
|
|
@@ -80,7 +63,7 @@ export function compileApprovalDesk(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
80
63
|
fail('KIT-BIZ-003', `request 的动作 ${String(a.id)}:审批单的通过 / 驳回要做成摘要里的字段按钮(on: field + 字段 action),工具栏按钮拿不到当前审批单`, `product.objects.request.behavior.actions[${i}].on`);
|
|
81
64
|
}
|
|
82
65
|
});
|
|
83
|
-
if (out.diagnostics.length > 0) return
|
|
66
|
+
if (out.diagnostics.length > 0) return finishBizCompile(out, '');
|
|
84
67
|
|
|
85
68
|
const ids = approvalDeskIds(ctx.pageId);
|
|
86
69
|
const areaClass = input.areaClass ?? {};
|
|
@@ -88,7 +71,8 @@ export function compileApprovalDesk(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
88
71
|
const queueName = approvalDeskObjectName(ctx.pageId, 'queue');
|
|
89
72
|
const queueNorm = normalizeMember(rawQueue, {
|
|
90
73
|
path: 'product.objects.queue',
|
|
91
|
-
|
|
74
|
+
roleName: 'queue',
|
|
75
|
+
roleDef: ApprovalDesk.roles.queue,
|
|
92
76
|
ensure: ['list'],
|
|
93
77
|
withForm: false,
|
|
94
78
|
});
|
|
@@ -97,7 +81,7 @@ export function compileApprovalDesk(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
97
81
|
const queueKey = keyFieldOf(queue);
|
|
98
82
|
if (queueKey === undefined) {
|
|
99
83
|
fail('KIT-BIZ-001', 'queue 的 schema 必须有 key 字段(或名为 id 的字段):审批单与历史靠它关联', 'product.objects.queue.schema');
|
|
100
|
-
return
|
|
84
|
+
return finishBizCompile(out, '');
|
|
101
85
|
}
|
|
102
86
|
const selKey = mirrorPath(link, KIT_LINK_MIRRORS.selKey);
|
|
103
87
|
|
|
@@ -109,7 +93,8 @@ export function compileApprovalDesk(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
109
93
|
const linkKey = typeof behavior.linkKey === 'string' && behavior.linkKey !== '' ? behavior.linkKey : queueKey;
|
|
110
94
|
const norm = normalizeMember(raw, {
|
|
111
95
|
path: `product.objects.${role}`,
|
|
112
|
-
|
|
96
|
+
roleName: role,
|
|
97
|
+
roleDef: ApprovalDesk.roles[role],
|
|
113
98
|
ensure: role === 'request' ? ['summary'] : 'any',
|
|
114
99
|
withForm: false,
|
|
115
100
|
params: { [linkKey]: `$${selKey}` },
|
|
@@ -119,17 +104,16 @@ export function compileApprovalDesk(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
119
104
|
const object = approvalDeskObjectName(ctx.pageId, role);
|
|
120
105
|
members.push({ role, object, scope: `${object}_scope`, obj: norm.obj, title: typeof raw.title === 'string' ? raw.title : '' });
|
|
121
106
|
}
|
|
122
|
-
if (out.diagnostics.length > 0) return
|
|
107
|
+
if (out.diagnostics.length > 0) return finishBizCompile(out, '');
|
|
123
108
|
|
|
124
|
-
const
|
|
125
|
-
const fieldSteps: Array<Rec> = [];
|
|
109
|
+
const fieldSteps: FieldSlots = [];
|
|
126
110
|
const q = emitMember(out, {
|
|
127
|
-
object: queueName, scope: `${queueName}_scope`, obj: queue, ctx, link, hubId: ids.hub,
|
|
111
|
+
object: queueName, scope: `${queueName}_scope`, obj: queue, ctx, link, hubId: ids.hub, pick: true, fieldSteps,
|
|
128
112
|
});
|
|
129
113
|
const pageScopes: string[] = [];
|
|
130
114
|
const blocks: Record<string, { title: string; html: string }> = {};
|
|
131
115
|
for (const m of members) {
|
|
132
|
-
const em = emitMember(out, { object: m.object, scope: m.scope, obj: m.obj, ctx, link, hubId: ids.hub,
|
|
116
|
+
const em = emitMember(out, { object: m.object, scope: m.scope, obj: m.obj, ctx, link, hubId: ids.hub, fieldSteps });
|
|
133
117
|
blocks[m.role] = {
|
|
134
118
|
title: m.title,
|
|
135
119
|
html: [em.r.parts.toolbar ?? '', em.r.parts.filter ?? '', em.listHtml, em.r.parts.summary ?? ''].filter((x) => x !== '').join('\n'),
|
|
@@ -154,13 +138,11 @@ export function compileApprovalDesk(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
154
138
|
props: { scope: link, keyField: queueKey, linkKey: '', autoSelect: true, afterRemove: 'next', rows: rowsPath, pageScopes },
|
|
155
139
|
};
|
|
156
140
|
out.show[ids.coord] = {
|
|
157
|
-
props: { scope: link, object: queueName, keyField: queueKey, reloads: members.map((m) => m.object), overlays: {} },
|
|
141
|
+
props: { scope: link, object: queueName, keyField: queueKey, reloads: members.map((m) => m.object), overlays: {}, ...linkRemoveProps(out) },
|
|
158
142
|
};
|
|
159
|
-
out
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
out.events[`${ids.hub}.field_action`] = { steps: [...fieldSteps, ...refresh.map((p) => ({ do: p }))] };
|
|
163
|
-
}
|
|
143
|
+
bindPickedReloads(out, ids.hub, members.map((m) => m.scope));
|
|
144
|
+
// 字段按钮的 confirm / permission 尾段带在 ACTION 管道上,由 core 在该管道上执行;动作做完的重取由 defineKitActions 固定执行
|
|
145
|
+
bindFieldSlots(out.events, ids.hub, fieldSteps, out.diagnostics);
|
|
164
146
|
|
|
165
147
|
const queueHtml = [q.r.parts.toolbar ?? '', q.r.parts.filter ?? '', q.listHtml].filter((x) => x !== '').join('\n');
|
|
166
148
|
const html = approvalDeskHtml(
|
|
@@ -175,5 +157,5 @@ export function compileApprovalDesk(input: KitBizInput, ctx: KitBizContext): Kit
|
|
|
175
157
|
);
|
|
176
158
|
for (const c of classesIn(html)) out.candidates.add(c);
|
|
177
159
|
for (const c of Object.values(APPROVAL_DESK_CLASS)) for (const t of c.split(/\s+/)) if (t !== '') out.candidates.add(t);
|
|
178
|
-
return
|
|
160
|
+
return finishBizCompile(out, html);
|
|
179
161
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// ApprovalDesk 的 HTML 代码壳:左待办队列 + 中审批单 + 右历史 / 比对三栏。只有结构与 Tailwind 类(语义色名 + utilityScales 里有的尺度),不写原生 CSS。
|
|
2
2
|
// 三栏靠容器查询变体 `@md:`:窄容器下上下堆叠;达到 md 档左 3 / 中 5 / 右 4(共 12 份)。
|
|
3
3
|
|
|
4
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../../base/hint-tips';
|
|
4
5
|
import { mergeClass } from '../../object-renderer/merge-class';
|
|
6
|
+
import { KIT_SHELL_FLAT_MARK, kitShellRecipe } from '../../recipes/container';
|
|
5
7
|
import { cls, esc, host } from '../link/shared';
|
|
6
8
|
|
|
7
9
|
/** 壳的内部区域名(`areaClass` 的合法键) */
|
|
@@ -11,9 +13,11 @@ export type ApprovalDeskArea = (typeof APPROVAL_DESK_AREAS)[number];
|
|
|
11
13
|
export const APPROVAL_DESK_CLASS = {
|
|
12
14
|
root: '@container flex flex-col gap-4',
|
|
13
15
|
grid: 'grid grid-cols-12 gap-4',
|
|
14
|
-
queue: 'col-span-12 @md:col-span-3 flex min-w-0 flex-col gap-3
|
|
15
|
-
request: 'col-span-12 @md:col-span-5 flex min-w-0 flex-col gap-3
|
|
16
|
-
history: 'col-span-12 @md:col-span-4 flex min-w-0 flex-col gap-3
|
|
16
|
+
queue: mergeClass('col-span-12 @md:col-span-3 flex min-w-0 flex-col gap-3 p-4', kitShellRecipe()),
|
|
17
|
+
request: mergeClass('col-span-12 @md:col-span-5 flex min-w-0 flex-col gap-3 p-4', kitShellRecipe()),
|
|
18
|
+
history: mergeClass('col-span-12 @md:col-span-4 flex min-w-0 flex-col gap-3 p-4', kitShellRecipe()),
|
|
19
|
+
/** 没有历史栏时审批单栏吃掉右侧 4 份(9/12) */
|
|
20
|
+
requestWide: mergeClass('col-span-12 @md:col-span-9 flex min-w-0 flex-col gap-3 p-4', kitShellRecipe()),
|
|
17
21
|
title: 'min-w-0 truncate text-base font-semibold text-fg',
|
|
18
22
|
} as const;
|
|
19
23
|
|
|
@@ -34,14 +38,13 @@ export function approvalDeskHtml(
|
|
|
34
38
|
extra: string | undefined,
|
|
35
39
|
): string {
|
|
36
40
|
const col = (area: 'queue' | 'request' | 'history', c: DeskColumn, wide?: string): string => {
|
|
37
|
-
|
|
41
|
+
// 截断的标题悬停 / 聚焦时由 hint-tips 按需挂全文气泡(作用范围标记就在标题元素自身)
|
|
42
|
+
const title = c.title === '' ? '' : `<h3${cls(APPROVAL_DESK_CLASS.title)} ${KIT_TIPS_SCOPE_ATTR}="">${esc(c.title)}</h3>`;
|
|
38
43
|
const base = wide === undefined ? APPROVAL_DESK_CLASS[area] : wide;
|
|
39
|
-
return `<section${cls(mergeClass(base, areaClass[area]))}>${title}${c.html}</section>`;
|
|
44
|
+
return `<section${cls(mergeClass(base, areaClass[area]))}${KIT_SHELL_FLAT_MARK}>${title}${c.html}</section>`;
|
|
40
45
|
};
|
|
41
46
|
// 没有历史栏时,审批单栏吃掉右侧 4 份
|
|
42
|
-
const requestBase = parts.history === null
|
|
43
|
-
? 'col-span-12 @md:col-span-9 flex min-w-0 flex-col gap-3 rounded-lg border border-border-strong bg-surface-raised p-4 shadow-xs'
|
|
44
|
-
: undefined;
|
|
47
|
+
const requestBase = parts.history === null ? APPROVAL_DESK_CLASS.requestWide : undefined;
|
|
45
48
|
const cols = [col('queue', parts.queue), col('request', parts.request, requestBase)];
|
|
46
49
|
if (parts.history !== null) cols.push(col('history', parts.history));
|
|
47
50
|
const root = mergeClass(mergeClass(APPROVAL_DESK_CLASS.root, areaClass.root), extra);
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// 矩阵的 from.params 带关联键(link_sel_key);枢纽抛 picked -> 页面对矩阵 `SCOPE | window-reload`
|
|
6
6
|
// 授权保存 matrix.behavior.actions 里 id 为 save 的具名动作(on: toolbar,submit: 应用动作):
|
|
7
7
|
// 编译器取走它(不渲染工具栏按钮),名字作矩阵底部保存钮文案(save_label);
|
|
8
|
-
// 矩阵抛 saved { value: grants } -> 枢纽补当前选中角色行(
|
|
9
|
-
// -> 执行具名动作(row = 当前角色,value = grants
|
|
8
|
+
// 矩阵抛 saved { value: grants } -> 枢纽补当前选中角色行(field_action_<序号> { value, row })
|
|
9
|
+
// -> 执行具名动作(row = 当前角色,value = grants;成功提示写在动作里,重取由 defineKitActions 固定执行)
|
|
10
10
|
// 约定:矩阵的 from 在页面刚加载、尚未选中角色时会不带关联键取一次——约定后端「缺关联键返回空」。
|
|
11
11
|
// user 是独立的当前用户摘要,不随角色选中变化。
|
|
12
12
|
|
|
@@ -15,32 +15,21 @@ import { viewAnchor } from '../../object-renderer/emit-static';
|
|
|
15
15
|
import type { KitObject } from '../../object-renderer/types';
|
|
16
16
|
import type { KitFragment } from '../../compile/fragment';
|
|
17
17
|
import type { KitBizContext, KitBizInput } from '../types';
|
|
18
|
-
import { KIT_COORD_EVENTS } from '../shared/coordinator';
|
|
19
|
-
import { KIT_LINK_EVENTS, KIT_LINK_MIRRORS, KIT_SEL_PATH } from '../link/hub';
|
|
20
18
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
bizObjectName, finishBizCompile, validateBizAreaClass,
|
|
20
|
+
} from '../shared/compile-helpers';
|
|
21
|
+
import { KIT_LINK_MIRRORS, KIT_SEL_PATH } from '../link/hub';
|
|
22
|
+
import {
|
|
23
|
+
addFieldSlot, bindFieldSlots, classesIn, emitMember, grantPageReset, isRec, keyFieldOf, linkRemoveProps, mirrorPath, newParts,
|
|
24
|
+
normalizeMember, sortMirrors, type FieldSlots, type Rec,
|
|
23
25
|
} from '../link/shared';
|
|
26
|
+
import { AuthPanel } from './index';
|
|
24
27
|
import { AUTH_PANEL_AREAS, AUTH_PANEL_CLASS, authPanelHtml, authPanelIds } from './shell';
|
|
25
|
-
import { kitText } from '../../i18n/kit-text';
|
|
26
28
|
|
|
27
|
-
const RESERVED = new Set(['page', 'p', 'ctrl', 'frame', 'tabs']);
|
|
28
29
|
const SAVE_ACTION = 'save';
|
|
29
30
|
|
|
30
31
|
export function authPanelObjectName(pageId: string, role: 'user' | 'roles' | 'matrix'): string {
|
|
31
|
-
|
|
32
|
-
return RESERVED.has(name) ? `${name}_obj` : name;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function finish(out: Parts, html: string): KitFragment {
|
|
36
|
-
return {
|
|
37
|
-
html,
|
|
38
|
-
ui: { data: out.data, scopes: out.scopes as unknown as Record<string, unknown>, show: out.show },
|
|
39
|
-
events: out.events,
|
|
40
|
-
components: [...out.components].sort(),
|
|
41
|
-
candidates: [...out.candidates].sort(),
|
|
42
|
-
diagnostics: dedupeDiagnostics(out.diagnostics),
|
|
43
|
-
};
|
|
32
|
+
return bizObjectName(pageId, role);
|
|
44
33
|
}
|
|
45
34
|
|
|
46
35
|
function isStaticView(s: unknown): boolean {
|
|
@@ -49,7 +38,6 @@ function isStaticView(s: unknown): boolean {
|
|
|
49
38
|
}
|
|
50
39
|
|
|
51
40
|
export function compileAuthPanel(input: KitBizInput, ctx: KitBizContext): KitFragment {
|
|
52
|
-
const SAVED_NOTICE = kitText('soma.kit.auth_saved', undefined, ctx.locale);
|
|
53
41
|
const out = newParts(['KitLinkHub', 'KitCrudBridge']);
|
|
54
42
|
const fail = (code: string, message: string, path: string): void => { out.diagnostics.push({ code, message, path }); };
|
|
55
43
|
|
|
@@ -69,12 +57,8 @@ export function compileAuthPanel(input: KitBizInput, ctx: KitBizContext): KitFra
|
|
|
69
57
|
if (rawUser !== undefined && (!isRec(rawUser) || !isRec(rawUser.schema) || !isRec(rawUser.behavior))) {
|
|
70
58
|
fail('KIT-BIZ-001', 'AuthPanel 的 user 必须是对象声明(需含 schema 与 behavior)', 'product.objects.user');
|
|
71
59
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
fail('KIT-PAGE-001', `areaClass 里的区域名 "${key}" 不在 AuthPanel 的区域闭集 ${AUTH_PANEL_AREAS.join(' / ')} 内`, `product.areaClass.${key}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (out.diagnostics.length > 0) return finish(out, '');
|
|
60
|
+
validateBizAreaClass(input, 'AuthPanel', AUTH_PANEL_AREAS, out.diagnostics);
|
|
61
|
+
if (out.diagnostics.length > 0) return finishBizCompile(out, '');
|
|
78
62
|
|
|
79
63
|
// matrix:取走 save 动作(名字作保存钮文案,submit 作保存时执行的具名动作)
|
|
80
64
|
const matrixSrc = JSON.parse(JSON.stringify(rawMatrix)) as Rec;
|
|
@@ -86,7 +70,7 @@ export function compileAuthPanel(input: KitBizInput, ctx: KitBizContext): KitFra
|
|
|
86
70
|
} else if (!ctx.registeredActions.has(saveAct.submit)) {
|
|
87
71
|
fail('KIT-EVT-001', `matrix 的保存动作 "${saveAct.submit}" 未在应用的具名动作中登记`, 'product.objects.matrix.behavior.actions');
|
|
88
72
|
}
|
|
89
|
-
if (out.diagnostics.length > 0 || saveAct === undefined) return
|
|
73
|
+
if (out.diagnostics.length > 0 || saveAct === undefined) return finishBizCompile(out, '');
|
|
90
74
|
mBehavior.actions = mActions.filter((a) => a.id !== SAVE_ACTION);
|
|
91
75
|
|
|
92
76
|
const ids = authPanelIds(ctx.pageId);
|
|
@@ -98,7 +82,8 @@ export function compileAuthPanel(input: KitBizInput, ctx: KitBizContext): KitFra
|
|
|
98
82
|
|
|
99
83
|
const rolesNorm = normalizeMember(rawRoles, {
|
|
100
84
|
path: 'product.objects.roles',
|
|
101
|
-
|
|
85
|
+
roleName: 'roles',
|
|
86
|
+
roleDef: AuthPanel.roles.roles,
|
|
102
87
|
ensure: ['list'],
|
|
103
88
|
withForm: false,
|
|
104
89
|
});
|
|
@@ -107,13 +92,14 @@ export function compileAuthPanel(input: KitBizInput, ctx: KitBizContext): KitFra
|
|
|
107
92
|
const roleKey = keyFieldOf(roles);
|
|
108
93
|
if (roleKey === undefined) {
|
|
109
94
|
fail('KIT-BIZ-001', 'roles 的 schema 必须有 key 字段(或名为 id 的字段):权限矩阵靠它关联', 'product.objects.roles.schema');
|
|
110
|
-
return
|
|
95
|
+
return finishBizCompile(out, '');
|
|
111
96
|
}
|
|
112
97
|
const selKey = mirrorPath(link, KIT_LINK_MIRRORS.selKey);
|
|
113
98
|
const linkKey = typeof mBehavior.linkKey === 'string' && mBehavior.linkKey !== '' ? mBehavior.linkKey : roleKey;
|
|
114
99
|
const matrixNorm = normalizeMember(matrixSrc, {
|
|
115
100
|
path: 'product.objects.matrix',
|
|
116
|
-
|
|
101
|
+
roleName: 'matrix',
|
|
102
|
+
roleDef: AuthPanel.roles.matrix,
|
|
117
103
|
ensure: ['summary'],
|
|
118
104
|
withForm: false,
|
|
119
105
|
params: { [linkKey]: `$${selKey}` },
|
|
@@ -127,38 +113,37 @@ export function compileAuthPanel(input: KitBizInput, ctx: KitBizContext): KitFra
|
|
|
127
113
|
}
|
|
128
114
|
let user: KitObject | undefined;
|
|
129
115
|
if (rawUser !== undefined) {
|
|
130
|
-
const un = normalizeMember(rawUser, {
|
|
116
|
+
const un = normalizeMember(rawUser, {
|
|
117
|
+
path: 'product.objects.user',
|
|
118
|
+
roleName: 'user',
|
|
119
|
+
roleDef: AuthPanel.roles.user,
|
|
120
|
+
ensure: ['summary'],
|
|
121
|
+
withForm: false,
|
|
122
|
+
});
|
|
131
123
|
out.diagnostics.push(...un.diagnostics);
|
|
132
124
|
user = un.obj;
|
|
133
125
|
}
|
|
134
|
-
if (out.diagnostics.length > 0) return
|
|
126
|
+
if (out.diagnostics.length > 0) return finishBizCompile(out, '');
|
|
135
127
|
|
|
136
|
-
const
|
|
137
|
-
const fieldSteps: Array<Rec> = [];
|
|
128
|
+
const fieldSteps: FieldSlots = [];
|
|
138
129
|
const r = emitMember(out, {
|
|
139
|
-
object: rolesName, scope: `${rolesName}_scope`, obj: roles, ctx, link, hubId: ids.hub,
|
|
130
|
+
object: rolesName, scope: `${rolesName}_scope`, obj: roles, ctx, link, hubId: ids.hub, pick: true, fieldSteps,
|
|
140
131
|
});
|
|
141
|
-
const mm = emitMember(out, { object: matrixName, scope: `${matrixName}_scope`, obj: matrix, ctx, link, hubId: ids.hub,
|
|
132
|
+
const mm = emitMember(out, { object: matrixName, scope: `${matrixName}_scope`, obj: matrix, ctx, link, hubId: ids.hub, fieldSteps });
|
|
142
133
|
const pageScopes: string[] = [];
|
|
143
134
|
if (grantPageReset(out, `${matrixName}_scope`, ids.hub)) pageScopes.push(`${matrixName}_scope`);
|
|
144
135
|
let userHtml: { title: string; html: string } | null = null;
|
|
145
136
|
if (user !== undefined) {
|
|
146
|
-
const um = emitMember(out, { object: userName, scope: `${userName}_scope`, obj: user, ctx, link, hubId: ids.hub,
|
|
137
|
+
const um = emitMember(out, { object: userName, scope: `${userName}_scope`, obj: user, ctx, link, hubId: ids.hub, fieldSteps });
|
|
147
138
|
userHtml = {
|
|
148
139
|
title: typeof (rawUser as Rec).title === 'string' ? ((rawUser as Rec).title as string) : '',
|
|
149
140
|
html: [um.r.parts.toolbar ?? '', um.listHtml, um.r.parts.summary ?? ''].filter((x) => x !== '').join('\n'),
|
|
150
141
|
};
|
|
151
142
|
}
|
|
152
143
|
|
|
153
|
-
// 授权保存:矩阵抛 saved ->
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
out.events[`${viewAnchor(matrixName, 'summary')}.saved`] = semanticPipe(link, `${KIT_LINK_EVENTS.fieldPrefix}${saveId}`);
|
|
157
|
-
const saveWhen = { field: 'id', op: 'eq', value: saveId };
|
|
158
|
-
fieldSteps.push(
|
|
159
|
-
{ when: saveWhen, do: `ACTION | ${saveAct.submit as string}` },
|
|
160
|
-
{ when: saveWhen, do: `NOTIFY | success | ${SAVED_NOTICE}` },
|
|
161
|
-
);
|
|
144
|
+
// 授权保存:矩阵抛 saved -> 枢纽补上当前选中的角色行(field_action_<序号> { value: grants, row: 当前角色 })-> 具名保存动作(单管道)。
|
|
145
|
+
// 保存后的提示写在具名动作里(ctx.notify),重取由 defineKitActions 在有协调组件的页面里固定执行
|
|
146
|
+
out.events[`${viewAnchor(matrixName, 'summary')}.saved`] = addFieldSlot(fieldSteps, link, `ACTION | ${saveAct.submit as string}`);
|
|
162
147
|
|
|
163
148
|
const mirrors: SomaScopeMirrorDecl[] = [
|
|
164
149
|
{ key: KIT_LINK_MIRRORS.selKey, slice: 'selection', path: `${KIT_SEL_PATH}.${roleKey}`, as: 'value' },
|
|
@@ -174,10 +159,10 @@ export function compileAuthPanel(input: KitBizInput, ctx: KitBizContext): KitFra
|
|
|
174
159
|
props: { scope: link, keyField: roleKey, linkKey: '', autoSelect: true, rows: `page.data.${rolesName}.${r.r.compiled.listShape.rows}`, pageScopes },
|
|
175
160
|
};
|
|
176
161
|
out.show[ids.coord] = {
|
|
177
|
-
props: { scope: link, object: rolesName, keyField: roleKey, reloads: [matrixName, ...(user !== undefined ? [userName] : [])], overlays: {} },
|
|
162
|
+
props: { scope: link, object: rolesName, keyField: roleKey, reloads: [matrixName, ...(user !== undefined ? [userName] : [])], overlays: {}, ...linkRemoveProps(out) },
|
|
178
163
|
};
|
|
179
|
-
out.events[`${ids.hub}.picked`] =
|
|
180
|
-
|
|
164
|
+
out.events[`${ids.hub}.picked`] = `SCOPE | window-reload | ${matrixName}_scope`;
|
|
165
|
+
bindFieldSlots(out.events, ids.hub, fieldSteps, out.diagnostics);
|
|
181
166
|
|
|
182
167
|
const title = (raw: unknown): string => (isRec(raw) && typeof raw.title === 'string' ? raw.title : '');
|
|
183
168
|
const html = authPanelHtml(
|
|
@@ -192,5 +177,5 @@ export function compileAuthPanel(input: KitBizInput, ctx: KitBizContext): KitFra
|
|
|
192
177
|
);
|
|
193
178
|
for (const c of classesIn(html)) out.candidates.add(c);
|
|
194
179
|
for (const c of Object.values(AUTH_PANEL_CLASS)) for (const t of c.split(/\s+/)) if (t !== '') out.candidates.add(t);
|
|
195
|
-
return
|
|
180
|
+
return finishBizCompile(out, html);
|
|
196
181
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// 对象角色槽:user(可选:当前用户摘要,summary 视图)、roles(必填:角色列表,list 视图,行可点选)、
|
|
3
3
|
// matrix(必填:写死形状件 PermissionMatrix,随选中角色重取;授权保存写成 behavior.actions 里 id 为 save 的具名动作)。
|
|
4
4
|
|
|
5
|
-
// 授权保存是写死的具名动作:矩阵的 `saved { value: grants }` 作为动作的 value,经 KitLinkHub 补上选中的角色行(
|
|
5
|
+
// 授权保存是写死的具名动作:矩阵的 `saved { value: grants }` 作为动作的 value,经 KitLinkHub 补上选中的角色行(field_action_<序号>),动作参数的 `row` 就是当前角色;
|
|
6
6
|
// 切换角色后矩阵由 KitLinkHub 的 `picked` 事件 `window-reload` 重取(同 MasterSub),不靠组件自己 watch。
|
|
7
7
|
|
|
8
8
|
import { defineKitBizComponent } from '../define';
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
// 分栏靠容器查询变体 `@md:`:窄容器下上下堆叠;达到 md 档角色 4 / 矩阵 8(共 12 份)。
|
|
3
3
|
|
|
4
4
|
import { mergeClass } from '../../object-renderer/merge-class';
|
|
5
|
+
import { KIT_SHELL_FLAT_MARK, kitShellRecipe } from '../../recipes/container';
|
|
5
6
|
import { cls, esc, host } from '../link/shared';
|
|
6
7
|
|
|
7
8
|
/** 壳的内部区域名(`areaClass` 的合法键) */
|
|
8
9
|
export const AUTH_PANEL_AREAS = ['root', 'user', 'roles', 'matrix'] as const;
|
|
9
10
|
export type AuthPanelArea = (typeof AUTH_PANEL_AREAS)[number];
|
|
10
11
|
|
|
11
|
-
const CARD = 'flex min-w-0 flex-col gap-3
|
|
12
|
+
const CARD = mergeClass('flex min-w-0 flex-col gap-3 p-4', kitShellRecipe());
|
|
12
13
|
|
|
13
14
|
export const AUTH_PANEL_CLASS = {
|
|
14
15
|
root: '@container flex flex-col gap-4',
|
|
15
16
|
user: CARD,
|
|
16
17
|
grid: 'grid grid-cols-12 gap-4',
|
|
17
|
-
roles:
|
|
18
|
-
matrix:
|
|
18
|
+
roles: mergeClass('col-span-12 @md:col-span-4', CARD),
|
|
19
|
+
matrix: mergeClass('col-span-12 @md:col-span-8', CARD),
|
|
19
20
|
title: 'text-base font-semibold text-fg',
|
|
20
21
|
} as const;
|
|
21
22
|
|
|
@@ -37,7 +38,7 @@ export function authPanelHtml(
|
|
|
37
38
|
): string {
|
|
38
39
|
const block = (area: 'user' | 'roles' | 'matrix', b: AuthBlock): string => {
|
|
39
40
|
const title = b.title === '' ? '' : `<h3${cls(AUTH_PANEL_CLASS.title)}>${esc(b.title)}</h3>`;
|
|
40
|
-
return `<section${cls(mergeClass(AUTH_PANEL_CLASS[area], areaClass[area]))}>${title}${b.html}</section>`;
|
|
41
|
+
return `<section${cls(mergeClass(AUTH_PANEL_CLASS[area], areaClass[area]))}${KIT_SHELL_FLAT_MARK}>${title}${b.html}</section>`;
|
|
41
42
|
};
|
|
42
43
|
const user = parts.user === null ? '' : `${block('user', parts.user)}\n`;
|
|
43
44
|
const root = mergeClass(mergeClass(AUTH_PANEL_CLASS.root, areaClass.root), extra);
|