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,140 @@
|
|
|
1
|
+
// Watermark:文本水印层(layer: data,写死形状,accept: single)。
|
|
2
|
+
//
|
|
3
|
+
// 数据:`data` 是 { text?, sub_text?, lines?, user?, template?, rotate?, opacity?, font_size?, gap_x?, gap_y? }:
|
|
4
|
+
// - 文案三选一:text(+ sub_text 第二行)、lines(多行数组)、或 template + user(模板里的 {name} {email} {id} {date} {time}
|
|
5
|
+
// 用 user 与当前时间替换,缺的占位替成空),用于「账号 + 时间」事后追溯;
|
|
6
|
+
// - rotate 倾斜角度(缺省 -22,限 -90..90);opacity 0..1(缺省 0.12);font_size 字号(缺省 14,限 8..48);
|
|
7
|
+
// gap_x / gap_y 格间距(缺省 48 / 40,限 0..400)。
|
|
8
|
+
// 实现:一张 SVG <pattern> 平铺,文字用 currentColor(令牌 text-fg-subtle),不透明度写在 SVG 属性上;
|
|
9
|
+
// 根节点 absolute inset-0 + pointer-events-none,宿主容器需 relative;aria-hidden,不拦截任何点击。
|
|
10
|
+
|
|
11
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
12
|
+
import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
13
|
+
import { createKitController, joinClass, nextUid, num } from '../base/shared';
|
|
14
|
+
import { classSet, isRec, textOf, type Rec } from './menu-dom';
|
|
15
|
+
|
|
16
|
+
const ROOT_CLASS = 'pointer-events-none absolute inset-0 select-none overflow-hidden text-fg-subtle';
|
|
17
|
+
const SVG_CLASS = 'h-full w-full';
|
|
18
|
+
|
|
19
|
+
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
20
|
+
export const KIT_WATERMARK_CLASS_CANDIDATES: readonly string[] = classSet(ROOT_CLASS, SVG_CLASS);
|
|
21
|
+
|
|
22
|
+
export interface KitWatermarkConfig {
|
|
23
|
+
lines: string[];
|
|
24
|
+
rotate: number;
|
|
25
|
+
opacity: number;
|
|
26
|
+
fontSize: number;
|
|
27
|
+
gapX: number;
|
|
28
|
+
gapY: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const clamp = (n: number, lo: number, hi: number): number => Math.min(hi, Math.max(lo, n));
|
|
32
|
+
const pad2 = (n: number): string => String(n).padStart(2, '0');
|
|
33
|
+
|
|
34
|
+
/** 模板占位替换:{name} {email} {id} {date} {time};缺的替成空串 */
|
|
35
|
+
export function fillWatermarkTemplate(template: string, user: Rec, now: Date): string {
|
|
36
|
+
const date = `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())}`;
|
|
37
|
+
const time = `${pad2(now.getHours())}:${pad2(now.getMinutes())}`;
|
|
38
|
+
const vars: Record<string, string> = {
|
|
39
|
+
name: textOf(user.name), email: textOf(user.email), id: textOf(user.id), date, time,
|
|
40
|
+
};
|
|
41
|
+
return template.replace(/\{(name|email|id|date|time)\}/g, (_m, k: string) => vars[k] ?? '');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 数据 -> 配置(纯函数,限值夹紧;没有可画的文字时 lines 为空) */
|
|
45
|
+
export function watermarkConfig(data: unknown, now: Date = new Date()): KitWatermarkConfig {
|
|
46
|
+
const d: Rec = isRec(data) ? data : {};
|
|
47
|
+
let lines: string[] = [];
|
|
48
|
+
if (Array.isArray(d.lines)) lines = d.lines.map((l) => textOf(l)).filter((l) => l.trim() !== '');
|
|
49
|
+
else if (textOf(d.template) !== '') lines = fillWatermarkTemplate(textOf(d.template), isRec(d.user) ? d.user : {}, now).split('\n');
|
|
50
|
+
else {
|
|
51
|
+
if (textOf(d.text) !== '') lines.push(textOf(d.text));
|
|
52
|
+
if (textOf(d.sub_text) !== '') lines.push(textOf(d.sub_text));
|
|
53
|
+
}
|
|
54
|
+
const WL = KIT_STATIC_COMPONENT_LIMITS.navigation.watermark.limits;
|
|
55
|
+
lines = lines.map((l) => l.trim()).filter((l) => l !== '').slice(0, WL.lines);
|
|
56
|
+
return {
|
|
57
|
+
lines,
|
|
58
|
+
rotate: clamp(num(d.rotate) ?? -22, WL.rotate[0], WL.rotate[1]),
|
|
59
|
+
opacity: clamp(num(d.opacity) ?? 0.12, WL.opacity[0], WL.opacity[1]),
|
|
60
|
+
fontSize: clamp(num(d.font_size) ?? 14, WL.fontSize[0], WL.fontSize[1]),
|
|
61
|
+
gapX: clamp(num(d.gap_x) ?? 48, WL.gap[0], WL.gap[1]),
|
|
62
|
+
gapY: clamp(num(d.gap_y) ?? 40, WL.gap[0], WL.gap[1]),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 估算文字宽度:CJK 全角算 1em,其余约 0.6em */
|
|
67
|
+
function estimateWidth(text: string, fontSize: number): number {
|
|
68
|
+
let em = 0;
|
|
69
|
+
for (const ch of text) em += /[⺀-鿿-]/.test(ch) ? 1 : 0.6;
|
|
70
|
+
return Math.ceil(em * fontSize);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface KitWatermarkTile { width: number; height: number; lineHeight: number }
|
|
74
|
+
|
|
75
|
+
export function watermarkTile(cfg: KitWatermarkConfig): KitWatermarkTile {
|
|
76
|
+
const lineHeight = Math.ceil(cfg.fontSize * 1.5);
|
|
77
|
+
const textW = Math.max(0, ...cfg.lines.map((l) => estimateWidth(l, cfg.fontSize)));
|
|
78
|
+
return { width: textW + cfg.gapX, height: lineHeight * cfg.lines.length + cfg.gapY, lineHeight };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
82
|
+
|
|
83
|
+
function svgEl(tag: string, attrs: Record<string, string>): SVGElement {
|
|
84
|
+
const el = document.createElementNS(SVG_NS, tag);
|
|
85
|
+
for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, v);
|
|
86
|
+
return el;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 把水印画进 root(组件本体与 workspace-frame 共用);没有文字时清空 */
|
|
90
|
+
export function paintKitWatermark(root: HTMLElement, data: unknown, className: unknown, patternId: string, now: Date = new Date()): void {
|
|
91
|
+
root.className = joinClass(ROOT_CLASS, className);
|
|
92
|
+
root.setAttribute('aria-hidden', 'true');
|
|
93
|
+
const cfg = watermarkConfig(data, now);
|
|
94
|
+
if (cfg.lines.length === 0) {
|
|
95
|
+
root.replaceChildren();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const tile = watermarkTile(cfg);
|
|
99
|
+
const svg = svgEl('svg', { class: SVG_CLASS, 'aria-hidden': 'true', focusable: 'false' });
|
|
100
|
+
const pattern = svgEl('pattern', {
|
|
101
|
+
id: patternId, patternUnits: 'userSpaceOnUse', width: String(tile.width), height: String(tile.height),
|
|
102
|
+
patternTransform: `rotate(${cfg.rotate})`,
|
|
103
|
+
});
|
|
104
|
+
const top = (tile.height - tile.lineHeight * cfg.lines.length) / 2 + cfg.fontSize;
|
|
105
|
+
cfg.lines.forEach((line, i) => {
|
|
106
|
+
const text = svgEl('text', {
|
|
107
|
+
x: String(tile.width / 2), y: String(top + i * tile.lineHeight), 'text-anchor': 'middle',
|
|
108
|
+
'font-size': String(cfg.fontSize), fill: 'currentColor', 'fill-opacity': String(cfg.opacity),
|
|
109
|
+
});
|
|
110
|
+
text.textContent = line;
|
|
111
|
+
pattern.append(text);
|
|
112
|
+
});
|
|
113
|
+
const defs = svgEl('defs', {});
|
|
114
|
+
defs.append(pattern);
|
|
115
|
+
svg.append(defs, svgEl('rect', { width: '100%', height: '100%', fill: `url(#${patternId})` }));
|
|
116
|
+
root.replaceChildren(svg);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function createWatermark(): SomaComponentDefinition {
|
|
120
|
+
const ids = new WeakMap<HTMLElement, string>();
|
|
121
|
+
return {
|
|
122
|
+
contract: {
|
|
123
|
+
name: 'Watermark',
|
|
124
|
+
layer: 'data',
|
|
125
|
+
props: {
|
|
126
|
+
data: { type: 'object', default: {}, desc: '{ text?, sub_text?, lines?, user?, template?, rotate?, opacity?, font_size?, gap_x?, gap_y? };template 的 {name} {email} {id} {date} {time} 由 user 与当前时间替换' },
|
|
127
|
+
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
128
|
+
},
|
|
129
|
+
emits: {},
|
|
130
|
+
},
|
|
131
|
+
templateHtml: `<div data-soma-id="root" aria-hidden="true" class="${ROOT_CLASS}"></div>`,
|
|
132
|
+
controllerFactory: createKitController({
|
|
133
|
+
render(root, p) {
|
|
134
|
+
let id = ids.get(root);
|
|
135
|
+
if (id === undefined) { id = nextUid('kit-wm'); ids.set(root, id); }
|
|
136
|
+
paintKitWatermark(root, p.data, p.class, id);
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
};
|
|
140
|
+
}
|
package/src/data/wrap.ts
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// 数据组件的包装与组合原语(应用层与领域包共用,纯函数 + 标准 SomaComponentDefinition 输出):
|
|
2
|
+
// 1. wrapKitDataComponent(别名 wrapBuiltin):把单个内置数据组件「包一层」,通过纯函数 adapt 将专属简写 props / 固定样式翻译成底层组件 props;
|
|
3
|
+
// 2. composeKitDataComponents:把多个数据组件(或基础组件)拼装在同一个自定义布局壳内,对外暴露为一个写死形状数据组件(accept: single | list)。
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
SomaComponentControllerContext,
|
|
7
|
+
SomaComponentDefinition,
|
|
8
|
+
SomaComponentServiceName,
|
|
9
|
+
} from 'soma-core';
|
|
10
|
+
import { findRoot } from '../base/shared';
|
|
11
|
+
import { kitLocaleAt } from '../i18n/kit-text';
|
|
12
|
+
import { checkClasses, mergeClass } from '../object-renderer/merge-class';
|
|
13
|
+
import { mountKitComponent, type KitMount } from './embed';
|
|
14
|
+
import { attachWrappedCandidates, splitClassTokens } from './wrapped-candidates';
|
|
15
|
+
|
|
16
|
+
export type PackProps = Record<string, unknown>;
|
|
17
|
+
|
|
18
|
+
export interface WrapDataOptions {
|
|
19
|
+
/** 新数据组件契约名(应用组件以 App 开头,领域包以包名前缀开头) */
|
|
20
|
+
name: string;
|
|
21
|
+
/** 组件契约说明 */
|
|
22
|
+
desc?: string;
|
|
23
|
+
/** 覆盖或追加的 props 契约(同名覆盖底层契约) */
|
|
24
|
+
props: Record<string, unknown>;
|
|
25
|
+
/** 专属 props -> 底层组件完整 props(纯函数) */
|
|
26
|
+
adapt(props: PackProps): PackProps;
|
|
27
|
+
/**
|
|
28
|
+
* 本层 adapt 里写死的 Tailwind 类(类串或类名列表)。编译器按页自动并入候选类,
|
|
29
|
+
* 底层组件自带的候选类也由编译器按组件名自动并入,不必再手抄进 appCandidates。
|
|
30
|
+
*/
|
|
31
|
+
candidates?: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type WrapOptions = WrapDataOptions;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 包装单个内置或已有数据组件:复用底层模板与控制器,仅在属性进入前做一次纯函数翻译。
|
|
38
|
+
* 适合固化固定边框/配色、收窄专属业务入参或写死字段映射。
|
|
39
|
+
*/
|
|
40
|
+
export function wrapKitDataComponent(inner: SomaComponentDefinition, options: WrapDataOptions): SomaComponentDefinition {
|
|
41
|
+
const innerFactory = inner.controllerFactory;
|
|
42
|
+
if (innerFactory === undefined) throw new Error(`[soma-kit] 被包装的组件 ${inner.contract.name} 没有控制器`);
|
|
43
|
+
const ownTokens = splitClassTokens(options.candidates);
|
|
44
|
+
for (const tok of ownTokens) {
|
|
45
|
+
const bad = checkClasses(tok, `${options.name}.candidates`);
|
|
46
|
+
if (bad.length > 0) throw new Error(`[soma-kit] ${options.name} 的 candidates 含非法类 "${tok}":${bad[0]!.message}`);
|
|
47
|
+
}
|
|
48
|
+
return attachWrappedCandidates({
|
|
49
|
+
...inner,
|
|
50
|
+
contract: {
|
|
51
|
+
...inner.contract,
|
|
52
|
+
name: options.name,
|
|
53
|
+
...(options.desc !== undefined ? { desc: options.desc } : {}),
|
|
54
|
+
props: { ...(inner.contract.props ?? {}), ...options.props },
|
|
55
|
+
} as SomaComponentDefinition['contract'],
|
|
56
|
+
controllerFactory: (ctx: SomaComponentControllerContext) => {
|
|
57
|
+
const read = (): PackProps => (ctx.readProps ? ctx.readProps() : ctx.props) as PackProps;
|
|
58
|
+
// 页面没给 locale prop 时,用宿主元素最近的 [lang](页面语言)补上:领域包默认文案(packLabel)按它选语言
|
|
59
|
+
const withLocale = (props: PackProps): PackProps => {
|
|
60
|
+
if (typeof props.locale === 'string' && props.locale !== '') return props;
|
|
61
|
+
const page = kitLocaleAt(ctx.host);
|
|
62
|
+
return page === '' ? props : { ...props, locale: page };
|
|
63
|
+
};
|
|
64
|
+
return innerFactory({
|
|
65
|
+
...ctx,
|
|
66
|
+
props: options.adapt(withLocale(ctx.props as PackProps)),
|
|
67
|
+
readProps: () => options.adapt(withLocale(read())),
|
|
68
|
+
} as SomaComponentControllerContext);
|
|
69
|
+
},
|
|
70
|
+
}, [inner], ownTokens);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 领域包历史命名兼容别名 */
|
|
74
|
+
export const wrapBuiltin = wrapKitDataComponent;
|
|
75
|
+
|
|
76
|
+
export type ComposeEventForward =
|
|
77
|
+
| string
|
|
78
|
+
| ((payload: unknown) => { event: string; payload: unknown } | null);
|
|
79
|
+
|
|
80
|
+
export interface ComposeDataPart {
|
|
81
|
+
/** 子组件定义(如 createStatGroup() / createRecordCard() / createTimeline()) */
|
|
82
|
+
component: SomaComponentDefinition | (() => SomaComponentDefinition);
|
|
83
|
+
/** 默认布局下该子槽位容器的 Tailwind 类(如 'col-span-12 @md:col-span-6 rounded-xl border border-border p-4') */
|
|
84
|
+
slotClass?: string;
|
|
85
|
+
/** 父组件 props -> 该子组件 props(纯函数) */
|
|
86
|
+
adaptProps(parentProps: PackProps): PackProps;
|
|
87
|
+
/** 子组件事件转发:{ 子事件名: 父事件名 | 转换函数 } */
|
|
88
|
+
forwardEvents?: Record<string, ComposeEventForward>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ComposeDataOptions {
|
|
92
|
+
/** 组合后的数据组件名(应用组件以 App 开头) */
|
|
93
|
+
name: string;
|
|
94
|
+
desc?: string;
|
|
95
|
+
/** 额外声明的契约 props(自动补齐 data 与 class) */
|
|
96
|
+
props?: Record<string, unknown>;
|
|
97
|
+
/** 对外抛出的契约 emits */
|
|
98
|
+
emits?: Record<string, unknown>;
|
|
99
|
+
/** 额外需要的运行时服务名(自动并入所有子组件声明的 services) */
|
|
100
|
+
services?: readonly SomaComponentServiceName[];
|
|
101
|
+
/** 根容器默认 Tailwind 类(缺省 '@container grid grid-cols-12 gap-4'),可被外部传入的 props.class 按同族规则覆盖 */
|
|
102
|
+
rootClass?: string;
|
|
103
|
+
/** 额外的写死类(adaptProps / renderLayout 里用到的);rootClass 与各 slotClass 已自动登记 */
|
|
104
|
+
candidates?: readonly string[];
|
|
105
|
+
/** 子组件部件表(按书写顺序挂载) */
|
|
106
|
+
parts: Record<string, ComposeDataPart>;
|
|
107
|
+
/**
|
|
108
|
+
* 可选:自定义异形 DOM 外壳构建函数,在 root 内创建任意装饰边框与布局结构,
|
|
109
|
+
* 并返回 `{ [partKey]: 子组件挂载容器元素 }`。缺省在 root 下按 parts 顺序生成带 slotClass 的槽位。
|
|
110
|
+
*/
|
|
111
|
+
renderLayout?: (root: HTMLElement, props: PackProps) => Record<string, HTMLElement>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function resolveDef(input: SomaComponentDefinition | (() => SomaComponentDefinition)): SomaComponentDefinition {
|
|
115
|
+
return typeof input === 'function' ? input() : input;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 将多个数据组件(或基础组件)组合成一个写死形状数据组件(layer: 'data')。
|
|
120
|
+
* 组件内部写死的 Tailwind 类与被嵌入子组件的候选类,需并入 defineKitApp({ appCandidates })。
|
|
121
|
+
*/
|
|
122
|
+
export function composeKitDataComponents(options: ComposeDataOptions): SomaComponentDefinition {
|
|
123
|
+
const entries = Object.entries(options.parts);
|
|
124
|
+
if (entries.length === 0) throw new Error(`[soma-kit] composeKitDataComponents(${options.name}) 至少需要 1 个子部件`);
|
|
125
|
+
|
|
126
|
+
const baseRootClass = options.rootClass ?? '@container grid grid-cols-12 gap-4';
|
|
127
|
+
const rootBad = checkClasses(baseRootClass, `${options.name}.rootClass`);
|
|
128
|
+
if (rootBad.length > 0) throw new Error(`[soma-kit] ${options.name} 的 rootClass 非法:${rootBad[0]!.message}`);
|
|
129
|
+
|
|
130
|
+
const resolvedParts = entries.map(([key, spec]) => {
|
|
131
|
+
if (spec.slotClass !== undefined) {
|
|
132
|
+
const bad = checkClasses(spec.slotClass, `${options.name}.parts.${key}.slotClass`);
|
|
133
|
+
if (bad.length > 0) throw new Error(`[soma-kit] ${options.name}.parts.${key}.slotClass 非法:${bad[0]!.message}`);
|
|
134
|
+
}
|
|
135
|
+
return { key, spec, def: resolveDef(spec.component) };
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const ownTokens = splitClassTokens([baseRootClass, ...(options.candidates ?? []), ...resolvedParts.map((r) => r.spec.slotClass ?? '')]);
|
|
139
|
+
for (const tok of splitClassTokens(options.candidates)) {
|
|
140
|
+
const bad = checkClasses(tok, `${options.name}.candidates`);
|
|
141
|
+
if (bad.length > 0) throw new Error(`[soma-kit] ${options.name} 的 candidates 含非法类 "${tok}":${bad[0]!.message}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const serviceSet = new Set<SomaComponentServiceName>(options.services ?? []);
|
|
145
|
+
for (const { def } of resolvedParts) {
|
|
146
|
+
for (const s of def.services ?? []) serviceSet.add(s);
|
|
147
|
+
}
|
|
148
|
+
const services = [...serviceSet];
|
|
149
|
+
|
|
150
|
+
return attachWrappedCandidates({
|
|
151
|
+
contract: {
|
|
152
|
+
name: options.name,
|
|
153
|
+
layer: 'data',
|
|
154
|
+
...(options.desc !== undefined ? { desc: options.desc } : {}),
|
|
155
|
+
props: {
|
|
156
|
+
data: { type: 'object', default: {}, desc: '组合数据载荷(单对象或数组)' },
|
|
157
|
+
class: { type: 'string', default: '', desc: '外层容器 Tailwind 覆写类' },
|
|
158
|
+
...(options.props ?? {}),
|
|
159
|
+
},
|
|
160
|
+
emits: (options.emits ?? {}) as NonNullable<SomaComponentDefinition['contract']['emits']>,
|
|
161
|
+
} as SomaComponentDefinition['contract'],
|
|
162
|
+
...(services.length > 0 ? { services } : {}),
|
|
163
|
+
templateHtml: `<div data-soma-id="root" class="${baseRootClass}"></div>`,
|
|
164
|
+
controllerFactory: (ctx: SomaComponentControllerContext) => {
|
|
165
|
+
const read = (): PackProps => ((ctx.readProps ? ctx.readProps() : ctx.props) ?? {}) as PackProps;
|
|
166
|
+
let root: HTMLElement | null = null;
|
|
167
|
+
let mounts: Array<{ key: string; spec: ComposeDataPart; mount: KitMount }> = [];
|
|
168
|
+
|
|
169
|
+
const applyRootClass = (p: PackProps): void => {
|
|
170
|
+
if (!root) return;
|
|
171
|
+
const extra = typeof p.class === 'string' ? p.class : '';
|
|
172
|
+
root.className = extra !== '' ? mergeClass(baseRootClass, extra) : baseRootClass;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const buildSlots = (target: HTMLElement, p: PackProps): Record<string, HTMLElement> => {
|
|
176
|
+
if (options.renderLayout) return options.renderLayout(target, p);
|
|
177
|
+
const doc = target.ownerDocument;
|
|
178
|
+
const map: Record<string, HTMLElement> = {};
|
|
179
|
+
for (const { key, spec } of resolvedParts) {
|
|
180
|
+
const slot = doc.createElement('div');
|
|
181
|
+
slot.setAttribute('data-kit-compose-slot', key);
|
|
182
|
+
if (spec.slotClass) slot.className = spec.slotClass;
|
|
183
|
+
target.appendChild(slot);
|
|
184
|
+
map[key] = slot;
|
|
185
|
+
}
|
|
186
|
+
return map;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
onMount(): void {
|
|
191
|
+
root = findRoot(ctx.host);
|
|
192
|
+
root.textContent = '';
|
|
193
|
+
const p = read();
|
|
194
|
+
applyRootClass(p);
|
|
195
|
+
const slots = buildSlots(root, p);
|
|
196
|
+
mounts = [];
|
|
197
|
+
for (const { key, spec, def } of resolvedParts) {
|
|
198
|
+
const container = slots[key];
|
|
199
|
+
if (!container) continue;
|
|
200
|
+
const handlers: Record<string, (payload: unknown) => void> = {};
|
|
201
|
+
for (const [childEvt, rule] of Object.entries(spec.forwardEvents ?? {})) {
|
|
202
|
+
handlers[childEvt] = (payload: unknown) => {
|
|
203
|
+
if (typeof rule === 'string') {
|
|
204
|
+
ctx.emit(rule, payload as Record<string, unknown>);
|
|
205
|
+
} else {
|
|
206
|
+
const mapped = rule(payload);
|
|
207
|
+
if (mapped !== null) ctx.emit(mapped.event, mapped.payload as Record<string, unknown>);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const m = mountKitComponent(
|
|
212
|
+
def,
|
|
213
|
+
container,
|
|
214
|
+
spec.adaptProps(p),
|
|
215
|
+
handlers,
|
|
216
|
+
ctx.services as Record<string, unknown> | undefined,
|
|
217
|
+
);
|
|
218
|
+
mounts.push({ key, spec, mount: m });
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
onPropsChange(): void {
|
|
222
|
+
const p = read();
|
|
223
|
+
applyRootClass(p);
|
|
224
|
+
for (const item of mounts) {
|
|
225
|
+
item.mount.setProps(item.spec.adaptProps(p));
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
onUnmount(): void {
|
|
229
|
+
for (const item of mounts) item.mount.destroy();
|
|
230
|
+
mounts = [];
|
|
231
|
+
root = null;
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
},
|
|
235
|
+
}, resolvedParts.map((r) => r.def), ownTokens);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ── 适配函数的通用取值小工具 ───────────────────────────────────
|
|
239
|
+
|
|
240
|
+
export function rec(raw: unknown): PackProps {
|
|
241
|
+
return raw !== null && typeof raw === 'object' && !Array.isArray(raw) ? raw as PackProps : {};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function txt(raw: unknown): string {
|
|
245
|
+
if (raw === null || raw === undefined) return '';
|
|
246
|
+
return typeof raw === 'string' ? raw : String(raw);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** 键名对照:defaults 的每个键,被 map 里同名的非空字符串改写 */
|
|
250
|
+
export function mapKeys<K extends string>(defaults: Readonly<Record<K, string>>, raw: unknown): Record<K, string> {
|
|
251
|
+
const out = { ...defaults } as Record<K, string>;
|
|
252
|
+
const m = rec(raw);
|
|
253
|
+
for (const k of Object.keys(defaults) as K[]) {
|
|
254
|
+
const v = m[k];
|
|
255
|
+
if (typeof v === 'string' && v !== '') out[k] = v;
|
|
256
|
+
}
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function list(raw: unknown): PackProps[] {
|
|
261
|
+
return Array.isArray(raw) ? raw.filter((r) => r !== null && typeof r === 'object' && !Array.isArray(r)) as PackProps[] : [];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** 语气六档归一化 */
|
|
265
|
+
export function tone(raw: unknown, fallback = 'neutral'): string {
|
|
266
|
+
return raw === 'neutral' || raw === 'primary' || raw === 'info' || raw === 'success' || raw === 'warning' || raw === 'danger' ? raw : fallback;
|
|
267
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// 包装 / 组合数据组件的候选类元数据(纯数据,无全局状态)。
|
|
2
|
+
// wrapKitDataComponent / composeKitDataComponents 把「底层组件定义 + 本层写死类」挂在返回的组件定义对象上
|
|
3
|
+
// (Symbol.for 键的不可枚举属性);编译器按本应用登记的组件定义读回,自动并入底层组件候选类与本层类,
|
|
4
|
+
// 应用不必再手抄底层的 KIT_*_CLASS_CANDIDATES(仍可经 appCandidates 追加)。
|
|
5
|
+
// 键用 Symbol.for:应用组件与编译器在 CJS / ESM 双载或打包器分块成两份模块实例时,键仍相等;元数据随定义走,不进进程级表。
|
|
6
|
+
|
|
7
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
8
|
+
|
|
9
|
+
export interface WrappedCandidateSource {
|
|
10
|
+
/** 被包装 / 被嵌入的底层组件定义(编译器按它们的契约名查内置候选类,并递归读它们自己的元数据) */
|
|
11
|
+
inner: readonly SomaComponentDefinition[];
|
|
12
|
+
/** 本层写死的类(已拆成单类) */
|
|
13
|
+
own: readonly string[];
|
|
14
|
+
/** 声明会在运行期(mountKitComponent / mountKitModal 等命令式嵌入)用到的内置组件名;编译器据此只并入这些组件的类 */
|
|
15
|
+
uses?: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const KEY = Symbol.for('soma-kit.wrappedCandidates');
|
|
19
|
+
|
|
20
|
+
/** 运行期常驻组件名(与 compile/component-candidates 的 KIT_RESIDENT_RUNTIME_CLASS_CANDIDATES 对应):每页都带类,不必声明 */
|
|
21
|
+
export const KIT_RESIDENT_COMPONENT_NAMES: readonly string[] = Object.freeze([
|
|
22
|
+
'Button', 'Input', 'Textarea', 'Link', 'Text', 'Tag', 'Badge', 'Tooltip', 'Select',
|
|
23
|
+
'Dropdown', 'Popup', 'PopupPlace', 'Modal', 'Segmented', 'QtyStepper', 'ContextMenu',
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
/** 进程内已声明过的组件名并集(只给开发态运行期提示用,不参与编译) */
|
|
27
|
+
const declaredUnion = new Set<string>();
|
|
28
|
+
const hinted = new Set<string>();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 声明一个应用组件在运行期会命令式嵌入哪些内置组件(契约名,如 'Button' / 'CodeView' / 'RowEditor')。
|
|
32
|
+
* 编译器读到后,只并入这些组件的候选类;没声明的 `App*` 组件仍退到「全部基础件类」兜底并给出提示。
|
|
33
|
+
* 第三参数 `own` 是该组件自己写死的类:只在页面用到它时并入(不必再放进全局 appCandidates)。
|
|
34
|
+
* 与 wrapKitDataComponent / composeKitDataComponents 的元数据同一处,可叠加;返回同一个定义。
|
|
35
|
+
*/
|
|
36
|
+
export function declareKitUses<T extends SomaComponentDefinition>(def: T, uses: readonly string[], own: readonly string[] = []): T {
|
|
37
|
+
const prev = wrappedCandidateSource(def);
|
|
38
|
+
const names = [...new Set([...(prev?.uses ?? []), ...uses.filter((n) => typeof n === 'string' && n !== '')])];
|
|
39
|
+
for (const n of names) declaredUnion.add(n);
|
|
40
|
+
Object.defineProperty(def, KEY, {
|
|
41
|
+
value: { inner: prev?.inner ?? [], own: splitClassTokens([...(prev?.own ?? []), ...own]), uses: names } satisfies WrappedCandidateSource,
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: true,
|
|
44
|
+
});
|
|
45
|
+
return def;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 给组件定义追加本层写死类(领域包按组件登记候选类用;与已有元数据合并) */
|
|
49
|
+
export function addWrappedOwnCandidates<T extends SomaComponentDefinition>(def: T, own: readonly string[]): T {
|
|
50
|
+
const prev = wrappedCandidateSource(def);
|
|
51
|
+
Object.defineProperty(def, KEY, {
|
|
52
|
+
value: {
|
|
53
|
+
inner: prev?.inner ?? [],
|
|
54
|
+
own: splitClassTokens([...(prev?.own ?? []), ...own]),
|
|
55
|
+
...(prev?.uses !== undefined ? { uses: prev.uses } : {}),
|
|
56
|
+
} satisfies WrappedCandidateSource,
|
|
57
|
+
enumerable: false,
|
|
58
|
+
configurable: true,
|
|
59
|
+
});
|
|
60
|
+
return def;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 开发态安全网:mountKitComponent 挂了一个既不常驻、也没被任何 declareKitUses 声明过的内置组件时,console 提示一次(不抛错)。
|
|
65
|
+
* 进程里一次 declareKitUses 都没调过(应用还没迁移)时不提示。
|
|
66
|
+
*/
|
|
67
|
+
export function hintUndeclaredKitUse(def: SomaComponentDefinition): void {
|
|
68
|
+
if (declaredUnion.size === 0) return;
|
|
69
|
+
const name = def.contract?.name;
|
|
70
|
+
if (typeof name !== 'string' || hinted.has(name)) return;
|
|
71
|
+
if (KIT_RESIDENT_COMPONENT_NAMES.includes(name) || declaredUnion.has(name) || wrappedCandidateSource(def) !== undefined) return;
|
|
72
|
+
const prod = typeof process !== 'undefined' && process.env?.['NODE_ENV'] === 'production';
|
|
73
|
+
if (prod) return;
|
|
74
|
+
hinted.add(name);
|
|
75
|
+
console.warn(`[soma-kit] 运行期嵌入了组件 ${name},但没有任何应用组件用 declareKitUses 声明它;按页裁剪样式时它的类可能缺失`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function splitClassTokens(list: readonly string[] | undefined): string[] {
|
|
79
|
+
if (list === undefined) return [];
|
|
80
|
+
return [...new Set(list.flatMap((s) => s.split(/\s+/)).filter((t) => t !== ''))];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 把候选类元数据挂到组件定义上(不可枚举,展开 `{ ...def }` 不会带走,包装时由新一层重新挂) */
|
|
84
|
+
export function attachWrappedCandidates<T extends SomaComponentDefinition>(def: T, inner: readonly SomaComponentDefinition[], own: readonly string[]): T {
|
|
85
|
+
Object.defineProperty(def, KEY, {
|
|
86
|
+
value: { inner: [...inner], own: splitClassTokens(own) } satisfies WrappedCandidateSource,
|
|
87
|
+
enumerable: false,
|
|
88
|
+
configurable: true,
|
|
89
|
+
});
|
|
90
|
+
return def;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function wrappedCandidateSource(def: SomaComponentDefinition | undefined): WrappedCandidateSource | undefined {
|
|
94
|
+
if (def === undefined || def === null) return undefined;
|
|
95
|
+
return (def as unknown as Record<symbol, WrappedCandidateSource | undefined>)[KEY];
|
|
96
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// blank-frame(K1-5):空白页面框——只有画布和一个 main 槽,不带标题头(title / subtitle / eyebrow 不渲染,
|
|
2
|
+
// 页面标题仍进信封)。画布无内边距(N-2),给自带页头的整页产品用。
|
|
3
|
+
|
|
4
|
+
import type { KitFrameDefinition } from './types';
|
|
5
|
+
import { checkFrameClasses, checkNoHeaderExtras, checkSlots, classAttr, finishFrame, rootClass, slotFragment, slotWrapper } from './shared';
|
|
6
|
+
|
|
7
|
+
/** 画布无内边距(N-2):只有底色与满屏高度;要内边距由 frame.class 自加 */
|
|
8
|
+
const BLANK_CANVAS_CLASS = 'bg-surface-sunken min-h-screen';
|
|
9
|
+
|
|
10
|
+
export const blankFrame: KitFrameDefinition = {
|
|
11
|
+
kind: 'blank-frame',
|
|
12
|
+
slots: ['main'],
|
|
13
|
+
compile(input) {
|
|
14
|
+
const diagnostics = [...checkSlots('blank-frame', ['main'], ['main'], input), ...checkFrameClasses(input), ...checkNoHeaderExtras('blank-frame', input)];
|
|
15
|
+
const main = slotFragment(input.slots.main);
|
|
16
|
+
const html = `<div data-soma-id="frame__root"${classAttr(rootClass(input, BLANK_CANVAS_CLASS))}>${slotWrapper('main', '', input, main.html)}</div>`;
|
|
17
|
+
return finishFrame([main], html, [], diagnostics);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// 页面框闭集:single-frame(缺省)/ top-main-frame / tabs-frame / split-frame。
|
|
2
|
+
|
|
3
|
+
import type { KitFrameDefinition } from './types';
|
|
4
|
+
import { blankFrame } from './blank-frame';
|
|
5
|
+
import { singleFrame } from './single-frame';
|
|
6
|
+
import { splitFrame } from './split-frame';
|
|
7
|
+
import { tabsFrame } from './tabs-frame';
|
|
8
|
+
import { topMainFrame } from './top-main-frame';
|
|
9
|
+
|
|
10
|
+
export type { KitFrameDefinition, KitFrameInput, KitPageMeta } from './types';
|
|
11
|
+
import { workspaceFrame } from './workspace-frame';
|
|
12
|
+
|
|
13
|
+
export { blankFrame, singleFrame, splitFrame, tabsFrame, topMainFrame, workspaceFrame };
|
|
14
|
+
export { checkWorkspaceConfig } from './workspace-frame';
|
|
15
|
+
export { createKitPageBar, KIT_PAGE_BAR_CLASS_CANDIDATES } from './page-bar';
|
|
16
|
+
export { createKitPageStatus, KIT_PAGE_STATUS_CLASS_CANDIDATES } from './page-status';
|
|
17
|
+
export { parsePageHeader } from './page-header';
|
|
18
|
+
export { headerFragment } from './shared';
|
|
19
|
+
export { createKitWorkspace, mountKitWorkspace, workspaceLabels, withFrameQuery, KIT_WORKSPACE_CLASS_CANDIDATES } from './workspace-frame/view';
|
|
20
|
+
export type { KitWorkspaceHandle, KitWorkspaceEmit } from './workspace-frame/view';
|
|
21
|
+
export {
|
|
22
|
+
createWorkspaceState, openTab as openWorkspaceTab, switchTab as switchWorkspaceTab, closeTab as closeWorkspaceTab,
|
|
23
|
+
closeOtherTabs as closeOtherWorkspaceTabs, closeAllTabs as closeAllWorkspaceTabs, refreshTab as refreshWorkspaceTab,
|
|
24
|
+
togglePinTab as togglePinWorkspaceTab, crumbsForTab, WORKSPACE_DEFAULT_MAX_TABS,
|
|
25
|
+
} from './workspace-frame/state';
|
|
26
|
+
export type { WorkspaceState, WorkspaceTab, WorkspaceTabInput } from './workspace-frame/state';
|
|
27
|
+
|
|
28
|
+
export { createKitTabsWiring } from './tabs-frame/wiring';
|
|
29
|
+
export { createKitSplitWiring } from './split-frame/wiring';
|
|
30
|
+
export { attachResizeHandle, clampStep } from './resize-handle';
|
|
31
|
+
export type { ResizeHandle, ResizeHandleOptions, ResizeAxis, ResizeSource } from './resize-handle';
|
|
32
|
+
export { checkSplitConfig, splitSpanClass, splitSpanClasses, KIT_SPLIT_CLASS_CANDIDATES } from './split-frame';
|
|
33
|
+
export type { SplitConfig, SplitDirection, SplitSide } from './split-frame';
|
|
34
|
+
|
|
35
|
+
export const DEFAULT_FRAME_KIND = 'single-frame';
|
|
36
|
+
|
|
37
|
+
export const KIT_FRAMES: Record<string, KitFrameDefinition> = {
|
|
38
|
+
'single-frame': singleFrame,
|
|
39
|
+
'blank-frame': blankFrame,
|
|
40
|
+
'top-main-frame': topMainFrame,
|
|
41
|
+
'tabs-frame': tabsFrame,
|
|
42
|
+
'split-frame': splitFrame,
|
|
43
|
+
'workspace-frame': workspaceFrame,
|
|
44
|
+
};
|