soma-kit 0.0.0-stage → 0.1.0
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 +539 -2
- package/bin/soma-kit.mjs +27 -0
- package/package.json +66 -4
- package/packs/ai/agent-run-card.ts +64 -0
- package/packs/ai/evaluation-card.ts +51 -0
- package/packs/ai/guardrail-policy-card.ts +48 -0
- package/packs/ai/index.ts +31 -0
- package/packs/ai/model-card.ts +55 -0
- package/packs/ai/model-routing-card.ts +49 -0
- package/packs/ai/prompt-template-card.ts +49 -0
- package/packs/ai/texts.ts +19 -0
- package/packs/commerce/address-card.ts +58 -0
- package/packs/commerce/coupon-card.ts +64 -0
- package/packs/commerce/index.ts +25 -0
- package/packs/commerce/order-card.ts +60 -0
- package/packs/commerce/purchase-order-card.ts +74 -0
- package/packs/commerce/texts.ts +14 -0
- package/packs/finance/index.ts +30 -0
- package/packs/finance/invoice-summary-card.ts +48 -0
- package/packs/finance/reconcile-board.ts +450 -0
- package/packs/finance/reconcile-case-card.ts +70 -0
- package/packs/finance/reconcile-desk/compile.ts +208 -0
- package/packs/finance/reconcile-desk/index.ts +20 -0
- package/packs/finance/reconcile-desk/shell.ts +27 -0
- package/packs/finance/texts.ts +21 -0
- package/packs/ops/change-window-card.ts +54 -0
- package/packs/ops/dependency-status-card.ts +50 -0
- package/packs/ops/error-budget-card.ts +60 -0
- package/packs/ops/execution-task-runner.ts +61 -0
- package/packs/ops/index.ts +36 -0
- package/packs/ops/integration-status-card.ts +45 -0
- package/packs/ops/release-readiness-card.ts +63 -0
- package/packs/ops/runbook-execution-card.ts +81 -0
- package/packs/ops/texts.ts +21 -0
- package/packs/security/control-evidence-card.ts +54 -0
- package/packs/security/finding-card.ts +96 -0
- package/packs/security/index.ts +29 -0
- package/packs/security/texts.ts +31 -0
- package/packs/shared/card-util.ts +60 -0
- package/packs/shared/wrap.ts +13 -0
- package/spec/generated/kit-app.schema.json +84 -0
- package/spec/generated/kit-page.schema.json +2766 -0
- package/spec/kit-grammar.json +1358 -0
- package/spec/kit-grammar.schema.json +716 -0
- package/src/app/app-config.ts +108 -0
- package/src/app/compose-apps.ts +139 -0
- package/src/app/define-kit-actions.ts +89 -0
- package/src/app/define-kit-app.ts +362 -0
- package/src/app/define-kit-pack.ts +114 -0
- package/src/app/envelope.ts +117 -0
- package/src/app/index.ts +50 -0
- package/src/app/notify-renderer.ts +114 -0
- package/src/app/paged-list-adapter.ts +246 -0
- package/src/app/server-pages.ts +303 -0
- package/src/app/server.ts +244 -0
- package/src/app/submit.types.ts +87 -0
- package/src/base/action-busy.ts +159 -0
- package/src/base/action-gate.ts +267 -0
- package/src/base/action-status.ts +31 -0
- package/src/base/alert.ts +136 -0
- package/src/base/avatar.ts +271 -0
- package/src/base/button.ts +139 -0
- package/src/base/cascader.ts +523 -0
- package/src/base/check-core.ts +214 -0
- package/src/base/checkbox.ts +35 -0
- package/src/base/choice.ts +183 -0
- package/src/base/color-picker.ts +316 -0
- package/src/base/combobox.ts +61 -0
- package/src/base/command-palette.ts +371 -0
- package/src/base/context-menu.ts +103 -0
- package/src/base/countdown.ts +168 -0
- package/src/base/date-range.ts +444 -0
- package/src/base/date.ts +899 -0
- package/src/base/divider.ts +156 -0
- package/src/base/fab.ts +192 -0
- package/src/base/icons.ts +106 -0
- package/src/base/image.ts +177 -0
- package/src/base/index.ts +214 -0
- package/src/base/input.ts +316 -0
- package/src/base/kbd.ts +99 -0
- package/src/base/link.ts +167 -0
- package/src/base/listbox-core.ts +965 -0
- package/src/base/mentions.ts +323 -0
- package/src/base/menu-button.ts +240 -0
- package/src/base/menu-core.ts +341 -0
- package/src/base/month-grid.ts +171 -0
- package/src/base/motion/aura.ts +94 -0
- package/src/base/motion/hover-3d.ts +154 -0
- package/src/base/motion/hover-gallery.ts +185 -0
- package/src/base/motion/index.ts +27 -0
- package/src/base/motion/limits.ts +75 -0
- package/src/base/motion/marquee.ts +157 -0
- package/src/base/motion/text-rotate.ts +195 -0
- package/src/base/number.ts +121 -0
- package/src/base/otp.ts +259 -0
- package/src/base/permission-gate.ts +99 -0
- package/src/base/popover.ts +352 -0
- package/src/base/popup.ts +542 -0
- package/src/base/portal-core.ts +297 -0
- package/src/base/price-text.ts +126 -0
- package/src/base/progress.ts +216 -0
- package/src/base/qr-code.ts +446 -0
- package/src/base/qty-stepper.ts +241 -0
- package/src/base/radio.ts +33 -0
- package/src/base/range.ts +444 -0
- package/src/base/rating.ts +249 -0
- package/src/base/segmented.ts +286 -0
- package/src/base/select.ts +57 -0
- package/src/base/shared.ts +708 -0
- package/src/base/swap.ts +86 -0
- package/src/base/switch.ts +111 -0
- package/src/base/tag-input.ts +464 -0
- package/src/base/tag.ts +250 -0
- package/src/base/text.ts +126 -0
- package/src/base/textarea.ts +129 -0
- package/src/base/time-picker.ts +606 -0
- package/src/base/tree-select.ts +629 -0
- package/src/base/upload.ts +548 -0
- package/src/base/virtual-list.ts +286 -0
- package/src/biz/approval-desk/compile.ts +179 -0
- package/src/biz/approval-desk/index.ts +21 -0
- package/src/biz/approval-desk/shell.ts +50 -0
- package/src/biz/auth-panel/compile.ts +196 -0
- package/src/biz/auth-panel/index.ts +24 -0
- package/src/biz/auth-panel/shell.ts +46 -0
- package/src/biz/category-crud/compile.ts +173 -0
- package/src/biz/category-crud/index.ts +19 -0
- package/src/biz/category-crud/shell.ts +29 -0
- package/src/biz/checkout-page/compile.ts +111 -0
- package/src/biz/checkout-page/index.ts +20 -0
- package/src/biz/checkout-page/shell.ts +50 -0
- package/src/biz/compose.ts +313 -0
- package/src/biz/data-components.ts +26 -0
- package/src/biz/define.ts +23 -0
- package/src/biz/import-wizard/compile.ts +204 -0
- package/src/biz/import-wizard/hub.ts +540 -0
- package/src/biz/import-wizard/index.ts +24 -0
- package/src/biz/import-wizard/shell.ts +161 -0
- package/src/biz/index.ts +80 -0
- package/src/biz/landing-page/compile.ts +67 -0
- package/src/biz/landing-page/index.ts +20 -0
- package/src/biz/landing-page/shell.ts +48 -0
- package/src/biz/link/hub.ts +255 -0
- package/src/biz/link/shared.ts +493 -0
- package/src/biz/master-sub/compile.ts +232 -0
- package/src/biz/master-sub/index.ts +20 -0
- package/src/biz/master-sub/shell.ts +56 -0
- package/src/biz/multi-board/compile.ts +234 -0
- package/src/biz/multi-board/index.ts +19 -0
- package/src/biz/multi-board/shell.ts +70 -0
- package/src/biz/names.ts +30 -0
- package/src/biz/notification-center/compile.ts +138 -0
- package/src/biz/notification-center/index.ts +29 -0
- package/src/biz/notification-center/shell.ts +42 -0
- package/src/biz/page-templates/result-page/compile.ts +46 -0
- package/src/biz/page-templates/result-page/index.ts +19 -0
- package/src/biz/page-templates/result-page/shell.ts +31 -0
- package/src/biz/page-templates/shared.ts +121 -0
- package/src/biz/page-templates/sign-in-page/compile.ts +176 -0
- package/src/biz/page-templates/sign-in-page/index.ts +18 -0
- package/src/biz/page-templates/sign-in-page/shell.ts +116 -0
- package/src/biz/record-detail/compile.ts +290 -0
- package/src/biz/record-detail/index.ts +22 -0
- package/src/biz/record-detail/shell.ts +64 -0
- package/src/biz/settings-center/compile.ts +100 -0
- package/src/biz/settings-center/index.ts +18 -0
- package/src/biz/settings-center/shell.ts +51 -0
- package/src/biz/shared/action-host.ts +469 -0
- package/src/biz/shared/coordinator.ts +516 -0
- package/src/biz/shared/index.ts +9 -0
- package/src/biz/shared/pipes.ts +58 -0
- package/src/biz/shared/runtime-hub.ts +112 -0
- package/src/biz/shared/step-values.ts +25 -0
- package/src/biz/single-form/compile.ts +146 -0
- package/src/biz/single-form/index.ts +18 -0
- package/src/biz/single-form/shell.ts +38 -0
- package/src/biz/standard-crud/bridge.ts +11 -0
- package/src/biz/standard-crud/compile.ts +546 -0
- package/src/biz/standard-crud/index.ts +18 -0
- package/src/biz/standard-crud/shell.ts +157 -0
- package/src/biz/step-form/compile.ts +400 -0
- package/src/biz/step-form/hub.ts +412 -0
- package/src/biz/step-form/index.ts +23 -0
- package/src/biz/step-form/shell.ts +96 -0
- package/src/biz/step-form/steps-ref.ts +112 -0
- package/src/biz/types.ts +96 -0
- package/src/cli/kit-cli.ts +102 -0
- package/src/compile/action-host-attach.ts +76 -0
- package/src/compile/compile-page.ts +472 -0
- package/src/compile/component-candidates.ts +147 -0
- package/src/compile/fragment.ts +104 -0
- package/src/compile/hints.ts +255 -0
- package/src/compile/index.ts +16 -0
- package/src/compile/locate.ts +166 -0
- package/src/compile/page-params.ts +80 -0
- package/src/compile/parse.ts +355 -0
- package/src/compile/redirect.ts +90 -0
- package/src/compile/registry.ts +30 -0
- package/src/compile/remove-guard.ts +99 -0
- package/src/compile/styles.ts +244 -0
- package/src/compile/types.ts +106 -0
- package/src/data/amount-breakdown.ts +132 -0
- package/src/data/anchor-nav.ts +225 -0
- package/src/data/approval-flow.ts +269 -0
- package/src/data/assignment-picker.ts +652 -0
- package/src/data/async-result-panel.ts +308 -0
- package/src/data/breadcrumbs.ts +197 -0
- package/src/data/calendar.ts +363 -0
- package/src/data/carousel.ts +408 -0
- package/src/data/chart.ts +726 -0
- package/src/data/checklist.ts +215 -0
- package/src/data/code-view.ts +415 -0
- package/src/data/comment-thread.ts +342 -0
- package/src/data/confirm-dialog.ts +144 -0
- package/src/data/context-menu.ts +216 -0
- package/src/data/d9-limits.ts +42 -0
- package/src/data/d9-util.ts +81 -0
- package/src/data/diff.ts +239 -0
- package/src/data/display-util.ts +135 -0
- package/src/data/dock.ts +152 -0
- package/src/data/embed.ts +200 -0
- package/src/data/field-mapper.ts +544 -0
- package/src/data/flow-editor-contract.ts +41 -0
- package/src/data/flow-editor.ts +2622 -0
- package/src/data/flow-remote-options.ts +257 -0
- package/src/data/footer.ts +157 -0
- package/src/data/form-draft-registry.ts +76 -0
- package/src/data/gantt.ts +430 -0
- package/src/data/hero.ts +149 -0
- package/src/data/image-viewer.ts +333 -0
- package/src/data/index.ts +268 -0
- package/src/data/item-list.ts +335 -0
- package/src/data/kanban.ts +667 -0
- package/src/data/media-grid.ts +246 -0
- package/src/data/mega-menu.ts +257 -0
- package/src/data/menu-dom.ts +169 -0
- package/src/data/menu.ts +464 -0
- package/src/data/mockup.ts +176 -0
- package/src/data/modal-dialog.ts +182 -0
- package/src/data/navbar.ts +292 -0
- package/src/data/object-form.ts +1981 -0
- package/src/data/options-bus.ts +24 -0
- package/src/data/outcome-watch.ts +40 -0
- package/src/data/overlay-portal.ts +6 -0
- package/src/data/pager.ts +473 -0
- package/src/data/permission-matrix.ts +432 -0
- package/src/data/permission-tree.ts +916 -0
- package/src/data/pricing-table.ts +269 -0
- package/src/data/prompt-dialog.ts +235 -0
- package/src/data/reaction-bar.ts +236 -0
- package/src/data/record-card.ts +413 -0
- package/src/data/record-picker.ts +489 -0
- package/src/data/redirect.ts +109 -0
- package/src/data/remote-options.ts +54 -0
- package/src/data/request-console.ts +399 -0
- package/src/data/resident.ts +58 -0
- package/src/data/result-panel.ts +160 -0
- package/src/data/rich-text.ts +626 -0
- package/src/data/row-editor.ts +1066 -0
- package/src/data/rule-builder.ts +1137 -0
- package/src/data/shape-util.ts +221 -0
- package/src/data/staged-rows.ts +69 -0
- package/src/data/stat-group.ts +231 -0
- package/src/data/static-lazy.ts +63 -0
- package/src/data/static-registry.ts +227 -0
- package/src/data/steps.ts +195 -0
- package/src/data/survey.ts +455 -0
- package/src/data/system-switcher.ts +243 -0
- package/src/data/timeline.ts +204 -0
- package/src/data/tour-guide.ts +392 -0
- package/src/data/transfer.ts +597 -0
- package/src/data/tree-check.ts +30 -0
- package/src/data/tree-table.ts +674 -0
- package/src/data/tree.ts +656 -0
- package/src/data/trend-line.ts +147 -0
- package/src/data/virtual-rows.ts +556 -0
- package/src/data/watermark.ts +140 -0
- package/src/data/wrap.ts +267 -0
- package/src/data/wrapped-candidates.ts +96 -0
- package/src/frames/blank-frame.ts +19 -0
- package/src/frames/index.ts +44 -0
- package/src/frames/page-bar.ts +185 -0
- package/src/frames/page-header.ts +185 -0
- package/src/frames/page-status.ts +54 -0
- package/src/frames/resize-handle.ts +147 -0
- package/src/frames/shared.ts +242 -0
- package/src/frames/single-frame.ts +16 -0
- package/src/frames/split-frame/index.ts +4 -0
- package/src/frames/split-frame/shell.ts +219 -0
- package/src/frames/split-frame/span.ts +64 -0
- package/src/frames/split-frame/wiring.ts +164 -0
- package/src/frames/tabs-frame/index.ts +3 -0
- package/src/frames/tabs-frame/shell.ts +112 -0
- package/src/frames/tabs-frame/wiring.ts +69 -0
- package/src/frames/top-main-frame.ts +20 -0
- package/src/frames/types.ts +72 -0
- package/src/frames/workspace-frame/extras.ts +197 -0
- package/src/frames/workspace-frame/index.ts +13 -0
- package/src/frames/workspace-frame/shell.ts +282 -0
- package/src/frames/workspace-frame/state.ts +152 -0
- package/src/frames/workspace-frame/view.ts +1013 -0
- package/src/generated/kit-grammar-runtime.ts +2822 -0
- package/src/generated/page-origin.ts +57 -0
- package/src/i18n/index.ts +22 -0
- package/src/i18n/kit-text.ts +692 -0
- package/src/i18n/resolve-text-refs.ts +128 -0
- package/src/index.ts +6 -0
- package/src/object-renderer/action-gate.ts +216 -0
- package/src/object-renderer/adopt-gate.ts +333 -0
- package/src/object-renderer/arrange.ts +411 -0
- package/src/object-renderer/candidates.ts +68 -0
- package/src/object-renderer/collapse-wiring.ts +99 -0
- package/src/object-renderer/collection-expand.ts +185 -0
- package/src/object-renderer/collection-parts.ts +653 -0
- package/src/object-renderer/collection-table.ts +503 -0
- package/src/object-renderer/collection.ts +628 -0
- package/src/object-renderer/compile-data.ts +549 -0
- package/src/object-renderer/defaults.ts +252 -0
- package/src/object-renderer/display-checks.ts +153 -0
- package/src/object-renderer/emit-events.ts +498 -0
- package/src/object-renderer/emit-object.ts +98 -0
- package/src/object-renderer/emit-static.ts +1036 -0
- package/src/object-renderer/field-policy.ts +89 -0
- package/src/object-renderer/field-value.ts +581 -0
- package/src/object-renderer/form-detail.ts +116 -0
- package/src/object-renderer/index.ts +13 -0
- package/src/object-renderer/linkage.ts +371 -0
- package/src/object-renderer/merge-class.ts +126 -0
- package/src/object-renderer/mode.ts +25 -0
- package/src/object-renderer/outcome-draft.ts +61 -0
- package/src/object-renderer/parts.ts +136 -0
- package/src/object-renderer/pick-component.ts +36 -0
- package/src/object-renderer/render-object.ts +724 -0
- package/src/object-renderer/request-actions.ts +581 -0
- package/src/object-renderer/skeleton.ts +101 -0
- package/src/object-renderer/table-actions.ts +438 -0
- package/src/object-renderer/table-summary.ts +105 -0
- package/src/object-renderer/table-tools.ts +1072 -0
- package/src/object-renderer/types.ts +936 -0
- package/src/page-target/ai-surface.ts +154 -0
- package/src/page-target/compile.ts +354 -0
- package/src/page-target/drift.ts +186 -0
- package/src/page-target/index.ts +25 -0
- package/src/page-target/intent-map.ts +137 -0
- package/src/page-target/intent-schema.ts +711 -0
- package/src/page-target/origin.ts +17 -0
- package/src/page-target/target.ts +450 -0
- package/src/page-target/writer-policy.ts +315 -0
- package/src/theme/block-theme.ts +202 -0
- package/src/theme/kit-theme-text.ts +2 -0
- package/src/theme/kit-theme.css +275 -0
- package/src/theme/kit-theme.tpl +275 -0
- package/src/theme/theme-tokens.ts +135 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// 服务端面:装配 + 扫描 + 编译 + 按 URL 注册进 core(owner 'soma-kit')。
|
|
2
|
+
// 只在服务端 / build 面可达;node 内置模块与 core 服务端子路径全部动态 import,并带 webpackIgnore,
|
|
3
|
+
// 即便 defineKitApp 的惰性 import 被打进浏览器包图,也不会在解析期报错。
|
|
4
|
+
|
|
5
|
+
import { KIT_BASE_COMPONENTS } from '../base/index';
|
|
6
|
+
import { KIT_STATIC_BUILTIN_SPECS } from '../data/static-registry';
|
|
7
|
+
import { compileKitPage } from '../compile/compile-page';
|
|
8
|
+
import { createYamlLocator } from '../compile/locate';
|
|
9
|
+
import { formatKitDiagnostic } from '../compile/hints';
|
|
10
|
+
import type { KitAppContext, KitPageArtifact } from '../compile/types';
|
|
11
|
+
import { KIT_FORM_FIELD_DATA_COMPONENTS } from '../object-renderer/defaults';
|
|
12
|
+
import type { KitDiagnostic } from '../object-renderer/types';
|
|
13
|
+
import { KIT_DEFAULT_THEME_CSS } from '../theme/kit-theme-text';
|
|
14
|
+
import { resolveKitThemeTokens, type KitThemeConfig } from '../theme/theme-tokens';
|
|
15
|
+
import { parseAppConfig } from './app-config';
|
|
16
|
+
import { setKitAppEnvelope } from './envelope';
|
|
17
|
+
import type { DefineKitAppOptions, KitAppRegistry } from './define-kit-app';
|
|
18
|
+
import { KIT_PAGE_OWNER, createKitServerPages } from './server-pages';
|
|
19
|
+
import type { KitServerPages } from './submit.types';
|
|
20
|
+
|
|
21
|
+
export const KIT_OWNER = KIT_PAGE_OWNER;
|
|
22
|
+
|
|
23
|
+
export class KitAppAssemblyError extends Error {
|
|
24
|
+
readonly diagnostics: KitDiagnostic[];
|
|
25
|
+
constructor(message: string, diagnostics: KitDiagnostic[]) {
|
|
26
|
+
super(`${message}\n${diagnostics.map((d) => ` ${formatKitDiagnostic(d)}`).join('\n')}`);
|
|
27
|
+
this.name = 'KitAppAssemblyError';
|
|
28
|
+
this.diagnostics = diagnostics;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface KitServerFace {
|
|
33
|
+
readonly appContext: KitAppContext;
|
|
34
|
+
/** URL -> 产物 */
|
|
35
|
+
readonly artifacts: ReadonlyMap<string, KitPageArtifact>;
|
|
36
|
+
/** 构建期预热:按 persist 重新登记全部页面 */
|
|
37
|
+
prewarm(): Promise<void>;
|
|
38
|
+
/** 按 URL 提交 / 撤下 / 列出动态页面(owner `soma-kit`;授权取 `defineKitApp({ pageGrants })`) */
|
|
39
|
+
readonly pages: KitServerPages;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const nodeFs = (): Promise<typeof import('node:fs/promises')> => import(/* webpackIgnore: true */ 'node:fs/promises');
|
|
43
|
+
const nodePath = (): Promise<typeof import('node:path')> => import(/* webpackIgnore: true */ 'node:path');
|
|
44
|
+
|
|
45
|
+
async function readIfExists(file: string): Promise<string | undefined> {
|
|
46
|
+
const fs = await nodeFs();
|
|
47
|
+
try {
|
|
48
|
+
return await fs.readFile(file, 'utf8');
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if ((error as { code?: string }).code === 'ENOENT') return undefined;
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function parseYaml(text: string, label: string): Promise<unknown> {
|
|
56
|
+
const { parseSomaDsl } = await import('soma-core/server/runtime');
|
|
57
|
+
const r = parseSomaDsl(text, 'ui');
|
|
58
|
+
if (!r.ok) throw new KitAppAssemblyError(`${label} 解析失败`, [{ code: 'KIT-APP-001', path: label, message: r.diagnostics.map((d) => d.message).join(';') }]);
|
|
59
|
+
return r.value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 装配 server 面:读配置 → 对账登记 → 建上下文 → 编译全部页面 → 注册。失败抛 KitAppAssemblyError */
|
|
63
|
+
export async function assembleKitServer(options: DefineKitAppOptions, registry: KitAppRegistry): Promise<KitServerFace> {
|
|
64
|
+
const path = await nodePath();
|
|
65
|
+
const fs = await nodeFs();
|
|
66
|
+
const root = path.resolve(options.root ?? process.env.SOMA_HOST_DIR ?? process.cwd());
|
|
67
|
+
|
|
68
|
+
// 1 kit.app.yaml
|
|
69
|
+
const appFile = path.join(root, options.app ?? 'kit.app.yaml');
|
|
70
|
+
const appText = await readIfExists(appFile);
|
|
71
|
+
const diagnostics: KitDiagnostic[] = [];
|
|
72
|
+
const config = parseAppConfig(appText === undefined ? undefined : await parseYaml(appText, 'kit.app.yaml'), diagnostics);
|
|
73
|
+
|
|
74
|
+
// 2 与代码登记对账(两边都要有)
|
|
75
|
+
for (const name of Object.keys(config.baseComponents)) {
|
|
76
|
+
if (!(name in registry.baseComponents)) diagnostics.push({ code: 'KIT-APP-001', path: `baseComponents.${name}`, message: `kit.app.yaml 登记了基础组件 ${name},soma.app.ts 没有提供实现` });
|
|
77
|
+
}
|
|
78
|
+
for (const name of Object.keys(registry.baseComponents)) {
|
|
79
|
+
if (!(name in config.baseComponents) && appText !== undefined) diagnostics.push({ code: 'KIT-APP-001', path: `baseComponents.${name}`, message: `soma.app.ts 提供了基础组件 ${name},kit.app.yaml 没有登记` });
|
|
80
|
+
}
|
|
81
|
+
const staticContracts: Record<string, { accept: 'single' | 'list'; emits: readonly string[]; props: readonly string[] }> = {};
|
|
82
|
+
for (const spec of KIT_STATIC_BUILTIN_SPECS) {
|
|
83
|
+
const def = spec.define();
|
|
84
|
+
staticContracts[spec.name] = { accept: spec.accept, emits: Object.keys(def.contract.emits ?? {}), props: Object.keys(def.contract.props ?? {}) };
|
|
85
|
+
}
|
|
86
|
+
for (const name of Object.keys(config.staticObjectComponents)) {
|
|
87
|
+
if (!(name in registry.staticComponents)) diagnostics.push({ code: 'KIT-APP-001', path: `staticObjectComponents.${name}`, message: `kit.app.yaml 登记了数据组件 ${name},soma.app.ts 没有提供实现` });
|
|
88
|
+
}
|
|
89
|
+
for (const [name, entry] of Object.entries(registry.staticComponents)) {
|
|
90
|
+
const yamlAccept = config.staticObjectComponents[name]?.accept;
|
|
91
|
+
if (yamlAccept !== undefined && entry.accept !== undefined && yamlAccept !== entry.accept) {
|
|
92
|
+
diagnostics.push({ code: 'KIT-APP-001', path: `staticObjectComponents.${name}.accept`, message: `accept 在 kit.app.yaml(${yamlAccept})与 soma.app.ts(${entry.accept})里不一致` });
|
|
93
|
+
}
|
|
94
|
+
const accept = yamlAccept ?? entry.accept;
|
|
95
|
+
if (accept === undefined) {
|
|
96
|
+
diagnostics.push({ code: 'KIT-APP-001', path: `staticObjectComponents.${name}`, message: `数据组件 ${name} 没有 accept:请在 kit.app.yaml 的 staticObjectComponents 登记` });
|
|
97
|
+
} else {
|
|
98
|
+
staticContracts[name] = { accept, emits: Object.keys(entry.definition.contract.emits ?? {}), props: Object.keys(entry.definition.contract.props ?? {}) };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (diagnostics.length > 0) throw new KitAppAssemblyError('kit.app.yaml 与应用登记不符,拒绝启动', diagnostics);
|
|
102
|
+
|
|
103
|
+
// 3 主题头
|
|
104
|
+
let themeCss: string;
|
|
105
|
+
if (config.style !== undefined) {
|
|
106
|
+
const text = await readIfExists(path.resolve(root, config.style));
|
|
107
|
+
if (text === undefined) throw new KitAppAssemblyError('主题头不存在', [{ code: 'KIT-APP-001', path: 'style', message: `找不到 ${config.style}` }]);
|
|
108
|
+
themeCss = text;
|
|
109
|
+
} else {
|
|
110
|
+
themeCss = KIT_DEFAULT_THEME_CSS;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 令牌 CSS:theme 声明交 soma-foundation 求解(亮 / 暗两套),拼在主题头前面;没写 theme 用 foundation 默认方案
|
|
114
|
+
// kit.app.yaml 写了 theme 则以 yaml 为准;没写才用 defineKitApp 的 defaultTheme(外壳继承用)
|
|
115
|
+
const themeInput: KitThemeConfig | undefined = config.theme === undefined ? options.defaultTheme : {
|
|
116
|
+
...(config.theme.paletteScheme !== undefined ? { paletteScheme: config.theme.paletteScheme } : {}),
|
|
117
|
+
...(config.theme.fontScheme !== undefined ? { fontScheme: config.theme.fontScheme } : {}),
|
|
118
|
+
...(config.theme.color !== undefined ? { color: config.theme.color } : {}),
|
|
119
|
+
...(config.theme.mode !== undefined ? { mode: config.theme.mode as KitThemeConfig['mode'] } : {}),
|
|
120
|
+
};
|
|
121
|
+
const tokens = resolveKitThemeTokens(themeInput, options.defaultLocale);
|
|
122
|
+
if (tokens.diagnostics.length > 0) throw new KitAppAssemblyError('主题令牌求解失败,拒绝启动', tokens.diagnostics);
|
|
123
|
+
|
|
124
|
+
// 应用词条表:`locales/<语言>.yaml`(平铺 `键: 文案`)读成 { 语言: { 键: 文案 } };没有该目录就没有应用词条表
|
|
125
|
+
const localeTables: Record<string, Record<string, string>> = {};
|
|
126
|
+
{
|
|
127
|
+
const fs = await nodeFs();
|
|
128
|
+
let names: string[] = [];
|
|
129
|
+
try {
|
|
130
|
+
names = (await fs.readdir(path.join(root, 'locales'))).filter((n) => /\.ya?ml$/.test(n)).sort();
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if ((error as { code?: string }).code !== 'ENOENT') throw error;
|
|
133
|
+
}
|
|
134
|
+
for (const n of names) {
|
|
135
|
+
const doc = await parseYaml((await readIfExists(path.join(root, 'locales', n))) ?? '', `locales/${n}`);
|
|
136
|
+
if (doc === null || typeof doc !== 'object' || Array.isArray(doc)) {
|
|
137
|
+
throw new KitAppAssemblyError('应用词条表不合法,拒绝启动', [{ code: 'KIT-APP-001', path: `locales/${n}`, message: '词条表必须是平铺的「键: 文案」映射' }]);
|
|
138
|
+
}
|
|
139
|
+
const table: Record<string, string> = {};
|
|
140
|
+
for (const [k, v] of Object.entries(doc as Record<string, unknown>)) if (typeof v === 'string') table[k] = v;
|
|
141
|
+
localeTables[n.replace(/\.ya?ml$/, '')] = table;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// 业务信封约定:编译期编进 core 数据声明,服务端薄壳(分页适配等)缺省读同一份
|
|
146
|
+
setKitAppEnvelope(config.envelope);
|
|
147
|
+
const appContext: KitAppContext = {
|
|
148
|
+
...(config.envelope !== undefined ? { envelope: config.envelope } : {}),
|
|
149
|
+
...(options.defaultLocale !== undefined ? { defaultLocale: options.defaultLocale } : {}),
|
|
150
|
+
...(Object.keys(localeTables).length > 0 ? { locales: localeTables } : {}),
|
|
151
|
+
themeTokensCss: tokens.css,
|
|
152
|
+
...(themeInput !== undefined ? { themeConfig: themeInput } : {}),
|
|
153
|
+
registeredActions: new Set(Object.keys(registry.actions)),
|
|
154
|
+
registeredComponents: new Set([...Object.keys(KIT_BASE_COMPONENTS), ...KIT_FORM_FIELD_DATA_COMPONENTS, ...Object.keys(registry.baseComponents)]),
|
|
155
|
+
staticComponents: staticContracts,
|
|
156
|
+
themeCss,
|
|
157
|
+
bizComponents: registry.bizComponents,
|
|
158
|
+
frames: registry.frames,
|
|
159
|
+
appCandidates: registry.appCandidates,
|
|
160
|
+
componentDefinitions: {
|
|
161
|
+
...registry.baseComponents,
|
|
162
|
+
...Object.fromEntries(Object.entries(registry.staticComponents).map(([n, e]) => [n, e.definition])),
|
|
163
|
+
...registry.packDataComponents,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// 4 扫描并编译页面
|
|
168
|
+
// 主页面目录 + extraPagesDirs(绝对路径或相对应用根);同一目录只扫一次
|
|
169
|
+
const pageDirs = [...new Set([path.join(root, options.pagesDir ?? 'pages'), ...(options.extraPagesDirs ?? []).map((d) => path.resolve(root, d))])];
|
|
170
|
+
const pageFiles: Array<{ dir: string; file: string }> = [];
|
|
171
|
+
for (const dir of pageDirs) {
|
|
172
|
+
try {
|
|
173
|
+
for (const f of (await fs.readdir(dir)).filter((n) => n.endsWith('.kit.yaml')).sort()) pageFiles.push({ dir, file: f });
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if ((error as { code?: string }).code !== 'ENOENT') throw error;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const artifacts = new Map<string, KitPageArtifact>();
|
|
179
|
+
const failures: KitDiagnostic[] = [];
|
|
180
|
+
for (const { dir, file: name } of pageFiles) {
|
|
181
|
+
const file = dir === pageDirs[0] ? name : `${path.relative(root, path.join(dir, name)) || name}`;
|
|
182
|
+
const text = await fs.readFile(path.join(dir, name), 'utf8');
|
|
183
|
+
const res = await compileKitPage(text, appContext);
|
|
184
|
+
if (res.artifact === undefined || res.diagnostics.length > 0) {
|
|
185
|
+
const locate = createYamlLocator(text);
|
|
186
|
+
failures.push(...res.diagnostics.map((d) => {
|
|
187
|
+
const pos = locate(d.path);
|
|
188
|
+
return { ...d, path: `${file}:${d.path}`, file, ...(pos ? { line: pos.line, column: pos.column } : {}) };
|
|
189
|
+
}));
|
|
190
|
+
// 没产物又没诊断也是失败:不许静默吞掉一页
|
|
191
|
+
if (res.diagnostics.length === 0) failures.push({ code: 'KIT-PAGE-004', path: file, message: '页面没有产出产物,也没有给出诊断' });
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (artifacts.has(res.artifact.url)) {
|
|
195
|
+
failures.push({ code: 'KIT-PAGE-004', path: file, message: `页面地址 ${res.artifact.url} 重复` });
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
artifacts.set(res.artifact.url, res.artifact);
|
|
199
|
+
}
|
|
200
|
+
if (failures.length > 0) throw new KitAppAssemblyError('页面编译失败,拒绝启动', failures);
|
|
201
|
+
|
|
202
|
+
// 5 注册(若同一 URL 已由 soma-kit 预热落盘,再次装配时保持 persist: true,避免抹除持久绑定文件)
|
|
203
|
+
const register = async (persist: boolean): Promise<void> => {
|
|
204
|
+
const { listBindings, registerSomaPages } = await import('soma-core/server/runtime');
|
|
205
|
+
const persistedUrls = persist
|
|
206
|
+
? null
|
|
207
|
+
: new Set(
|
|
208
|
+
listBindings()
|
|
209
|
+
.filter((b) => b.owner === KIT_OWNER && b.persisted)
|
|
210
|
+
.map((b) => b.address),
|
|
211
|
+
);
|
|
212
|
+
const entries = [...artifacts.values()].map((a) => {
|
|
213
|
+
const keepPersist = persist || (persistedUrls?.has(a.url) ?? false);
|
|
214
|
+
return {
|
|
215
|
+
url: a.url,
|
|
216
|
+
page: { html: a.html, uiYaml: a.uiYaml, eventYaml: a.eventYaml, styles: a.styles, version: a.version },
|
|
217
|
+
options: { owner: KIT_OWNER, version: a.version, ...(keepPersist ? { persist: true } : {}) },
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
const outcomes = registerSomaPages(entries);
|
|
221
|
+
const bad = outcomes.filter((o) => !o.registered);
|
|
222
|
+
if (bad.length > 0) {
|
|
223
|
+
throw new KitAppAssemblyError('页面注册未生效', bad.map((o) => ({ code: o.code ?? 'KIT-APP-001', path: o.url, message: o.message ?? '地址已被其它来源占用' })));
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
await register(false);
|
|
227
|
+
|
|
228
|
+
// 6 提交面:缺省授权只有 host 一条(core 的缺省);授权表读时取
|
|
229
|
+
const runtime = await import('soma-core/server/runtime');
|
|
230
|
+
const pages = createKitServerPages({
|
|
231
|
+
runtime,
|
|
232
|
+
appContext,
|
|
233
|
+
...(options.locales !== undefined ? { locales: options.locales } : {}),
|
|
234
|
+
grants: () => {
|
|
235
|
+
const given = options.pageGrants?.();
|
|
236
|
+
return (given === undefined || given.length === 0 ? runtime.SOMA_DEFAULT_PAGE_GRANTS : given) as never;
|
|
237
|
+
},
|
|
238
|
+
tableAddresses: () => [...artifacts.keys()],
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
return { appContext, artifacts, prewarm: () => register(true), pages };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
(globalThis as Record<symbol, unknown>)[Symbol.for('soma-kit.serverModule')] = { assembleKitServer };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// 按 URL 注册的应用可见类型(《soma-kit AI 页目标施工规格》§4.3)。只有类型与一个错误类,浏览器与服务端入口共用,不 import node 内置模块。
|
|
2
|
+
//
|
|
3
|
+
// 提交选项、授权条目与溯源摘要的真源在 `soma-core/page-target`(页面目标接口),本文件只做再导出并保留本线习惯的名字;
|
|
4
|
+
// 字段与语义以 core 为准,结构与 `PageSubmitOptions / PageSubmitResult` 兼容(可直接赋给 `PageTarget.submit` 的入参 / 返回)。
|
|
5
|
+
// `KitSubmitOptions.provenance` 必填:动态提交一律带溯源摘要,缺失即拒收(判据是 core 的 `provenanceProblem`)。
|
|
6
|
+
// 与 soma-lite 的 `submit.types.ts` 对称(D5:本规格不把提交管线抽到 core);诊断直接用 core 的 `PageDiagnostic`(坐标字段叫 `at`)。
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
PageGrant,
|
|
10
|
+
PageGrantAccess,
|
|
11
|
+
PageDiagnostic,
|
|
12
|
+
PageProvenance,
|
|
13
|
+
PageSubmitOptions,
|
|
14
|
+
PageSubmitResult,
|
|
15
|
+
} from 'soma-core/page-target';
|
|
16
|
+
|
|
17
|
+
export type { PageDiagnostic, PageProvenance } from 'soma-core/page-target';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 提交时源里 `page.url` 的占位值:AI 目标的 accept / dryRun 不知道最终地址,编译时用它占位。
|
|
21
|
+
* `pages.submit` 把等于它的源 `page.url` 视为「没写」,地址只取 submit 的第一个参数;其余值与参数不等即 CORE-RUNTIME-ADDRESS-MISMATCH。
|
|
22
|
+
*/
|
|
23
|
+
export const KIT_PLACEHOLDER_URL = '/ai-page-placeholder';
|
|
24
|
+
|
|
25
|
+
/** 持久度,由弱到强:memory < runtime < registry(kit 的生成页不接收 registry,见 KIT-AIT-006) */
|
|
26
|
+
export type KitSubmitPersist = NonNullable<PageSubmitOptions['persist']>;
|
|
27
|
+
|
|
28
|
+
/** 提交选项(真源 `soma-core/page-target` 的 `PageSubmitOptions`;`provenance` 必填) */
|
|
29
|
+
export type KitSubmitOptions = PageSubmitOptions;
|
|
30
|
+
|
|
31
|
+
/** 提交结果(真源 `PageSubmitResult`:`digest` = 方言源摘要,与 dryRun 的 digest 同口径) */
|
|
32
|
+
export type KitSubmitResult = PageSubmitResult;
|
|
33
|
+
|
|
34
|
+
/** kit 的方言源:`page.kit.yaml` 全文 */
|
|
35
|
+
export interface KitPageSource {
|
|
36
|
+
readonly source: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** runtime 空间里一条绑定的只读视图(`pages.list`) */
|
|
40
|
+
export interface KitPageBindingView {
|
|
41
|
+
readonly address: string;
|
|
42
|
+
readonly kind: 'exact' | 'pattern' | 'prefix';
|
|
43
|
+
readonly origin: 'static' | 'inject' | 'registry';
|
|
44
|
+
/** 标准载荷摘要(与 `KitSubmitResult.digest` 的方言源摘要是两个口径) */
|
|
45
|
+
readonly digest: string | null;
|
|
46
|
+
readonly generation: number;
|
|
47
|
+
readonly persisted: boolean;
|
|
48
|
+
readonly fixed: boolean;
|
|
49
|
+
readonly caller: string | null;
|
|
50
|
+
readonly purpose: 'access' | 'preview';
|
|
51
|
+
readonly expiresAt: number | null;
|
|
52
|
+
readonly title?: string;
|
|
53
|
+
/** 动态提交的溯源摘要(深拷贝并冻结);只在代次与当前绑定一致时出现,表内页与进程重启后的绑定没有 */
|
|
54
|
+
readonly provenance?: PageProvenance;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 装配服务端面的 `pages.*` */
|
|
58
|
+
export interface KitServerPages {
|
|
59
|
+
/** 按 URL 提交一页:定址 → 授权 → 信封 → 编译 → 注册(同一 URL 覆盖);`dryRun` 只跑到编译,不注册 */
|
|
60
|
+
submit(url: string | undefined, source: KitPageSource, options: KitSubmitOptions): Promise<KitSubmitResult>;
|
|
61
|
+
/** 撤下 soma-kit 自己注册的 URL;`expectGeneration` 不等则拒收。返回是否真的撤下了 */
|
|
62
|
+
unbind(url: string, options?: { readonly expectGeneration?: number }): Promise<boolean>;
|
|
63
|
+
/** 当前绑定(含溯源摘要) */
|
|
64
|
+
list(filter?: { readonly prefix?: string }): readonly KitPageBindingView[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ───────────────────────── 授权 ─────────────────────────
|
|
68
|
+
|
|
69
|
+
export type KitPageGrantAccess = PageGrantAccess;
|
|
70
|
+
|
|
71
|
+
/** 页面授权条目(真源 `soma-core/page-target` 的 `PageGrant`),Host 在 `defineKitApp({ pageGrants })` 声明 */
|
|
72
|
+
export type KitPageGrant = PageGrant;
|
|
73
|
+
|
|
74
|
+
// ───────────────────────── 错误 ─────────────────────────
|
|
75
|
+
|
|
76
|
+
/** 提交被拒:`code` 是 CORE-* / KIT-* 码,`diagnostics` 带三段式(可直接给作者 / 回喂用) */
|
|
77
|
+
export class KitSubmitError extends Error {
|
|
78
|
+
readonly code: string;
|
|
79
|
+
readonly diagnostics: readonly PageDiagnostic[];
|
|
80
|
+
|
|
81
|
+
constructor(code: string, message: string, diagnostics: readonly PageDiagnostic[] = []) {
|
|
82
|
+
super(`${code} ${message}`);
|
|
83
|
+
this.name = 'KitSubmitError';
|
|
84
|
+
this.code = code;
|
|
85
|
+
this.diagnostics = diagnostics;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// 具名动作的「进行中」通道(通用,不属于某个组件)。
|
|
2
|
+
//
|
|
3
|
+
// core 的事件是发了就走,组件不知道它抛出的 saved / submit 对应的具名动作什么时候结束。
|
|
4
|
+
// defineKitActions 把每个处理函数包进 beginKitAction:动作开始时计数 +1,结束(成功、失败、返回 false)时 -1,
|
|
5
|
+
// 并通知订阅者。带保存钮的组件声明 `busy_action: 动作名`(可写多个,逗号分隔)后订阅这里:
|
|
6
|
+
// 进行中时禁用触发钮、挂 aria-busy、忽略重复点击;动作结束自动恢复。宿主也可以直接给 `busy: true`。
|
|
7
|
+
// 计数而不是布尔:同名动作并发时,全部结束才算闲。无动作在跑时所有查询都是 false,没有订阅者也无副作用。
|
|
8
|
+
|
|
9
|
+
const counts = new Map<string, number>();
|
|
10
|
+
const subs = new Set<() => void>();
|
|
11
|
+
|
|
12
|
+
function notify(): void {
|
|
13
|
+
for (const fn of [...subs]) {
|
|
14
|
+
try { fn(); } catch { /* 订阅者自己的错误不影响动作 */ }
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 标记动作开始;返回结束函数(幂等) */
|
|
19
|
+
export function beginKitAction(name: string): () => void {
|
|
20
|
+
counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
21
|
+
notify();
|
|
22
|
+
let ended = false;
|
|
23
|
+
return () => {
|
|
24
|
+
if (ended) return;
|
|
25
|
+
ended = true;
|
|
26
|
+
const n = (counts.get(name) ?? 1) - 1;
|
|
27
|
+
if (n <= 0) counts.delete(name);
|
|
28
|
+
else counts.set(name, n);
|
|
29
|
+
notify();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 名字列表(逗号 / 空白分隔)里任一动作正在进行;空串恒为 false */
|
|
34
|
+
export function isKitActionBusy(names: string): boolean {
|
|
35
|
+
if (names === '' || counts.size === 0) return false;
|
|
36
|
+
return names.split(/[\s,]+/).some((n) => n !== '' && counts.has(n));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ---------------------------------------------------------------- 可取消(request.cancelable)
|
|
40
|
+
// 声明了 cancelable 的 request 动作在途期间由页面级宿主登记一个取消函数(登记早于 beginKitAction,忙闲通知时已可查);
|
|
41
|
+
// 触发钮 / 采纳条 / 结果槽据此在处理中显示「取消」,点了调 cancelKitAction 真正中止网络请求。结束时宿主摘掉。
|
|
42
|
+
const cancelers = new Map<string, Set<() => void>>();
|
|
43
|
+
|
|
44
|
+
/** 登记某动作在途请求的取消函数;返回摘除函数(幂等) */
|
|
45
|
+
export function registerKitCancel(name: string, cancel: () => void): () => void {
|
|
46
|
+
let set = cancelers.get(name);
|
|
47
|
+
if (set === undefined) { set = new Set(); cancelers.set(name, set); }
|
|
48
|
+
set.add(cancel);
|
|
49
|
+
return () => {
|
|
50
|
+
const s = cancelers.get(name);
|
|
51
|
+
if (s === undefined) return;
|
|
52
|
+
s.delete(cancel);
|
|
53
|
+
if (s.size === 0) cancelers.delete(name);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 名字列表(逗号 / 空白分隔)里任一动作有可取消的在途请求 */
|
|
58
|
+
export function isKitActionCancelable(names: string): boolean {
|
|
59
|
+
if (names === '' || cancelers.size === 0) return false;
|
|
60
|
+
return names.split(/[\s,]+/).some((n) => n !== '' && cancelers.has(n));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 中止名字列表里各动作的在途请求;返回是否真有可取消的 */
|
|
64
|
+
export function cancelKitAction(names: string): boolean {
|
|
65
|
+
let any = false;
|
|
66
|
+
for (const n of names.split(/[\s,]+/)) {
|
|
67
|
+
const set = n === '' ? undefined : cancelers.get(n);
|
|
68
|
+
if (set === undefined) continue;
|
|
69
|
+
for (const fn of [...set]) { any = true; fn(); }
|
|
70
|
+
}
|
|
71
|
+
return any;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 订阅忙闲变化;返回取消订阅函数 */
|
|
75
|
+
export function onKitActionBusy(fn: () => void): () => void {
|
|
76
|
+
subs.add(fn);
|
|
77
|
+
return () => { subs.delete(fn); };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 组件取忙闲:宿主给的 busy 为真,或 busy_action 列出的动作在跑 */
|
|
81
|
+
export function kitBusyOf(props: Record<string, unknown>): boolean {
|
|
82
|
+
if (props.busy === true) return true;
|
|
83
|
+
return typeof props.busy_action === 'string' && isKitActionBusy(props.busy_action);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------- 通用辅助(组件与编译器共用)
|
|
87
|
+
|
|
88
|
+
/** 带忙闲通道的组件与它们「写入 / 提交」类事件名:编译器按 view.on 里这些事件接的具名动作自动注入 busy_action */
|
|
89
|
+
export const KIT_BUSY_EVENTS: Readonly<Record<string, readonly string[]>> = Object.freeze({
|
|
90
|
+
PermissionTree: ['saved'],
|
|
91
|
+
AssignmentPicker: ['saved'],
|
|
92
|
+
Transfer: ['saved'],
|
|
93
|
+
FieldMapper: ['saved'],
|
|
94
|
+
RuleBuilder: ['saved'],
|
|
95
|
+
PermissionMatrix: ['saved'],
|
|
96
|
+
RowEditor: ['add', 'remove', 'change'],
|
|
97
|
+
AsyncResultPanel: ['run'],
|
|
98
|
+
RequestConsole: ['run'],
|
|
99
|
+
Questionnaire: ['submit'],
|
|
100
|
+
KitObjectForm: ['submit'],
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
/** 契约 props 里统一的两条 busy 声明(各组件展开使用,不各写一份) */
|
|
104
|
+
export const KIT_BUSY_PROP_DEFS = Object.freeze({
|
|
105
|
+
busy: { type: 'boolean', default: false, desc: '宿主给的提交中:触发钮禁用并挂 aria-busy,忽略重复触发' },
|
|
106
|
+
busy_action: { type: 'string', default: '', desc: '所接具名动作的名字(逗号分隔可多个);其中任一在进行中即视为提交中;view.on 接了具名动作时由编译器自动填,手写优先(忙闲通道见 base/action-busy)' },
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export interface KitBusyBinding {
|
|
110
|
+
/** 当前是否忙 */
|
|
111
|
+
busy(): boolean;
|
|
112
|
+
/** 订阅忙闲变化(onMount 调;重复调用先摘旧的) */
|
|
113
|
+
subscribe(repaint: () => void): void;
|
|
114
|
+
/** 取消订阅(onUnmount 调) */
|
|
115
|
+
dispose(): void;
|
|
116
|
+
/** 把忙闲落到触发钮:disabled = 其它禁用条件 || 忙;忙时挂 aria-busy */
|
|
117
|
+
paint(btn: HTMLElement | null, otherDisabled?: boolean): void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** 组件的忙闲绑定:getProps 取最新 props(含宿主给的 busy / busy_action) */
|
|
121
|
+
export function createKitBusy(getProps: () => Record<string, unknown>): KitBusyBinding {
|
|
122
|
+
let off: (() => void) | null = null;
|
|
123
|
+
const busy = (): boolean => kitBusyOf(getProps());
|
|
124
|
+
return {
|
|
125
|
+
busy,
|
|
126
|
+
subscribe(repaint) {
|
|
127
|
+
off?.();
|
|
128
|
+
off = onKitActionBusy(repaint);
|
|
129
|
+
},
|
|
130
|
+
dispose() {
|
|
131
|
+
off?.();
|
|
132
|
+
off = null;
|
|
133
|
+
},
|
|
134
|
+
paint(btn, otherDisabled = false) {
|
|
135
|
+
if (btn === null) return;
|
|
136
|
+
const b = busy();
|
|
137
|
+
(btn as HTMLButtonElement).disabled = otherDisabled || b;
|
|
138
|
+
if (b) btn.setAttribute('aria-busy', 'true'); else btn.removeAttribute('aria-busy');
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 编译期:view.on 里该组件的写入 / 提交类事件接的具名动作 -> busy_action 字符串(逗号分隔、去重)。
|
|
145
|
+
* 内置角色(saved / cancel / close / reload)与 data.orderMove 不是具名动作,不计;没有则返回 null。
|
|
146
|
+
*/
|
|
147
|
+
export function busyActionOf(component: string, on: Readonly<Record<string, string | { readonly action: string; readonly then?: string }>> | undefined): string | null {
|
|
148
|
+
const events = KIT_BUSY_EVENTS[component];
|
|
149
|
+
if (events === undefined || on === undefined) return null;
|
|
150
|
+
const builtin = new Set(['saved', 'cancel', 'close', 'reload', 'data.orderMove']);
|
|
151
|
+
const names: string[] = [];
|
|
152
|
+
for (const ev of events) {
|
|
153
|
+
if (!Object.prototype.hasOwnProperty.call(on, ev)) continue;
|
|
154
|
+
const v = on[ev]!;
|
|
155
|
+
const name = typeof v === 'string' ? v : v.action;
|
|
156
|
+
if (!builtin.has(name) && !names.includes(name)) names.push(name);
|
|
157
|
+
}
|
|
158
|
+
return names.length > 0 ? names.join(',') : null;
|
|
159
|
+
}
|