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/data/wrap.ts
CHANGED
|
@@ -7,11 +7,12 @@ import type {
|
|
|
7
7
|
SomaComponentDefinition,
|
|
8
8
|
SomaComponentServiceName,
|
|
9
9
|
} from 'soma-core';
|
|
10
|
-
import { findRoot } from '../base/shared';
|
|
10
|
+
import { createKitController, findRoot } from '../base/shared';
|
|
11
11
|
import { kitLocaleAt } from '../i18n/kit-text';
|
|
12
12
|
import { checkClasses, mergeClass } from '../object-renderer/merge-class';
|
|
13
13
|
import { mountKitComponent, type KitMount } from './embed';
|
|
14
14
|
import { attachWrappedCandidates, splitClassTokens } from './wrapped-candidates';
|
|
15
|
+
import { kitFail } from '../compile/kit-error';
|
|
15
16
|
|
|
16
17
|
export type PackProps = Record<string, unknown>;
|
|
17
18
|
|
|
@@ -39,11 +40,11 @@ export type WrapOptions = WrapDataOptions;
|
|
|
39
40
|
*/
|
|
40
41
|
export function wrapKitDataComponent(inner: SomaComponentDefinition, options: WrapDataOptions): SomaComponentDefinition {
|
|
41
42
|
const innerFactory = inner.controllerFactory;
|
|
42
|
-
if (innerFactory === undefined)
|
|
43
|
+
if (innerFactory === undefined) kitFail('KIT-COMP-004', `${options.name}.inner`, `被包装的组件 ${inner.contract.name} 没有控制器`, '只能包装带 controllerFactory 的组件;纯模板组件请直接登记');
|
|
43
44
|
const ownTokens = splitClassTokens(options.candidates);
|
|
44
45
|
for (const tok of ownTokens) {
|
|
45
46
|
const bad = checkClasses(tok, `${options.name}.candidates`);
|
|
46
|
-
if (bad.length > 0)
|
|
47
|
+
if (bad.length > 0) kitFail('KIT-COMP-003', `${options.name}.candidates`, `${options.name} 的 candidates 含非法类 "${tok}":${bad[0]!.message}`, '候选类只能用刻度内的 Tailwind 类,不写方括号任意值');
|
|
47
48
|
}
|
|
48
49
|
return attachWrappedCandidates({
|
|
49
50
|
...inner,
|
|
@@ -53,20 +54,44 @@ export function wrapKitDataComponent(inner: SomaComponentDefinition, options: Wr
|
|
|
53
54
|
...(options.desc !== undefined ? { desc: options.desc } : {}),
|
|
54
55
|
props: { ...(inner.contract.props ?? {}), ...options.props },
|
|
55
56
|
} as SomaComponentDefinition['contract'],
|
|
56
|
-
controllerFactory: (
|
|
57
|
-
const read = (): PackProps => (
|
|
57
|
+
controllerFactory: createKitController((api) => {
|
|
58
|
+
const read = (): PackProps => (api.props() ?? {}) as PackProps;
|
|
58
59
|
// 页面没给 locale prop 时,用宿主元素最近的 [lang](页面语言)补上:领域包默认文案(packLabel)按它选语言
|
|
59
60
|
const withLocale = (props: PackProps): PackProps => {
|
|
60
61
|
if (typeof props.locale === 'string' && props.locale !== '') return props;
|
|
61
|
-
const page = kitLocaleAt(
|
|
62
|
+
const page = kitLocaleAt(api.host);
|
|
62
63
|
return page === '' ? props : { ...props, locale: page };
|
|
63
64
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
const innerProps = (): PackProps => options.adapt(withLocale(read()));
|
|
66
|
+
const innerCtx: SomaComponentControllerContext = {
|
|
67
|
+
host: api.host,
|
|
68
|
+
props: innerProps(),
|
|
69
|
+
readProps: innerProps,
|
|
70
|
+
emit: (name, payload) => api.emit(name, payload),
|
|
71
|
+
services: api.services,
|
|
72
|
+
refresh: () => api.refresh(),
|
|
73
|
+
};
|
|
74
|
+
const innerCtrl = innerFactory(innerCtx) as Record<string, any>;
|
|
75
|
+
let firstRender = true;
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
attach() {
|
|
79
|
+
innerCtrl.onMount?.();
|
|
80
|
+
return () => {
|
|
81
|
+
firstRender = true;
|
|
82
|
+
innerCtrl.onUnmount?.();
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
render() {
|
|
86
|
+
if (firstRender) {
|
|
87
|
+
firstRender = false;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
innerCtrl.onPropsChange?.();
|
|
91
|
+
},
|
|
92
|
+
...(innerCtrl.handle ? { handle: innerCtrl.handle } : {}),
|
|
93
|
+
};
|
|
94
|
+
}),
|
|
70
95
|
}, [inner], ownTokens);
|
|
71
96
|
}
|
|
72
97
|
|
|
@@ -118,16 +143,16 @@ function resolveDef(input: SomaComponentDefinition | (() => SomaComponentDefinit
|
|
|
118
143
|
*/
|
|
119
144
|
export function composeKitDataComponents(options: ComposeDataOptions): SomaComponentDefinition {
|
|
120
145
|
const entries = Object.entries(options.parts);
|
|
121
|
-
if (entries.length === 0)
|
|
146
|
+
if (entries.length === 0) kitFail('KIT-COMP-004', `${options.name}.parts`, `composeKitDataComponents(${options.name}) 至少需要 1 个子部件`, 'parts 里至少登记一个子部件');
|
|
122
147
|
|
|
123
148
|
const baseRootClass = options.rootClass ?? '@container grid grid-cols-12 gap-4';
|
|
124
149
|
const rootBad = checkClasses(baseRootClass, `${options.name}.rootClass`);
|
|
125
|
-
if (rootBad.length > 0)
|
|
150
|
+
if (rootBad.length > 0) kitFail('KIT-COMP-003', `${options.name}.rootClass`, `${options.name} 的 rootClass 非法:${rootBad[0]!.message}`, 'rootClass 只能用刻度内的 Tailwind 类');
|
|
126
151
|
|
|
127
152
|
const resolvedParts = entries.map(([key, spec]) => {
|
|
128
153
|
if (spec.slotClass !== undefined) {
|
|
129
154
|
const bad = checkClasses(spec.slotClass, `${options.name}.parts.${key}.slotClass`);
|
|
130
|
-
if (bad.length > 0)
|
|
155
|
+
if (bad.length > 0) kitFail('KIT-COMP-003', `${options.name}.parts.${key}.slotClass`, `${options.name}.parts.${key}.slotClass 非法:${bad[0]!.message}`, 'slotClass 只能用刻度内的 Tailwind 类');
|
|
131
156
|
}
|
|
132
157
|
return { key, spec, def: resolveDef(spec.component) };
|
|
133
158
|
});
|
|
@@ -135,7 +160,7 @@ export function composeKitDataComponents(options: ComposeDataOptions): SomaCompo
|
|
|
135
160
|
const ownTokens = splitClassTokens([baseRootClass, ...(options.candidates ?? []), ...resolvedParts.map((r) => r.spec.slotClass ?? '')]);
|
|
136
161
|
for (const tok of splitClassTokens(options.candidates)) {
|
|
137
162
|
const bad = checkClasses(tok, `${options.name}.candidates`);
|
|
138
|
-
if (bad.length > 0)
|
|
163
|
+
if (bad.length > 0) kitFail('KIT-COMP-003', `${options.name}.candidates`, `${options.name} 的 candidates 含非法类 "${tok}":${bad[0]!.message}`, '候选类只能用刻度内的 Tailwind 类,不写方括号任意值');
|
|
139
164
|
}
|
|
140
165
|
|
|
141
166
|
const serviceSet = new Set<SomaComponentServiceName>(options.services ?? []);
|
|
@@ -158,15 +183,15 @@ export function composeKitDataComponents(options: ComposeDataOptions): SomaCompo
|
|
|
158
183
|
} as SomaComponentDefinition['contract'],
|
|
159
184
|
...(services.length > 0 ? { services } : {}),
|
|
160
185
|
templateHtml: `<div data-soma-id="root" class="${baseRootClass}"></div>`,
|
|
161
|
-
controllerFactory: (
|
|
162
|
-
const read = (): PackProps => (
|
|
163
|
-
let
|
|
186
|
+
controllerFactory: createKitController((api) => {
|
|
187
|
+
const read = (): PackProps => (api.props() ?? {}) as PackProps;
|
|
188
|
+
let rootEl: HTMLElement | null = null;
|
|
164
189
|
let mounts: Array<{ key: string; spec: ComposeDataPart; mount: KitMount }> = [];
|
|
165
190
|
|
|
166
191
|
const applyRootClass = (p: PackProps): void => {
|
|
167
|
-
if (!
|
|
192
|
+
if (!rootEl) return;
|
|
168
193
|
const extra = typeof p.class === 'string' ? p.class : '';
|
|
169
|
-
|
|
194
|
+
rootEl.className = extra !== '' ? mergeClass(baseRootClass, extra) : baseRootClass;
|
|
170
195
|
};
|
|
171
196
|
|
|
172
197
|
const buildSlots = (target: HTMLElement, p: PackProps): Record<string, HTMLElement> => {
|
|
@@ -184,12 +209,12 @@ export function composeKitDataComponents(options: ComposeDataOptions): SomaCompo
|
|
|
184
209
|
};
|
|
185
210
|
|
|
186
211
|
return {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
212
|
+
attach(root) {
|
|
213
|
+
rootEl = root;
|
|
214
|
+
rootEl.textContent = '';
|
|
190
215
|
const p = read();
|
|
191
216
|
applyRootClass(p);
|
|
192
|
-
const slots = buildSlots(
|
|
217
|
+
const slots = buildSlots(rootEl, p);
|
|
193
218
|
mounts = [];
|
|
194
219
|
for (const { key, spec, def } of resolvedParts) {
|
|
195
220
|
const container = slots[key];
|
|
@@ -198,10 +223,10 @@ export function composeKitDataComponents(options: ComposeDataOptions): SomaCompo
|
|
|
198
223
|
for (const [childEvt, rule] of Object.entries(spec.forwardEvents ?? {})) {
|
|
199
224
|
handlers[childEvt] = (payload: unknown) => {
|
|
200
225
|
if (typeof rule === 'string') {
|
|
201
|
-
|
|
226
|
+
api.emit(rule, payload as Record<string, unknown>);
|
|
202
227
|
} else {
|
|
203
228
|
const mapped = rule(payload);
|
|
204
|
-
if (mapped !== null)
|
|
229
|
+
if (mapped !== null) api.emit(mapped.event, mapped.payload as Record<string, unknown>);
|
|
205
230
|
}
|
|
206
231
|
};
|
|
207
232
|
}
|
|
@@ -210,25 +235,25 @@ export function composeKitDataComponents(options: ComposeDataOptions): SomaCompo
|
|
|
210
235
|
container,
|
|
211
236
|
spec.adaptProps(p),
|
|
212
237
|
handlers,
|
|
213
|
-
|
|
238
|
+
api.services as Record<string, unknown> | undefined,
|
|
214
239
|
);
|
|
215
240
|
mounts.push({ key, spec, mount: m });
|
|
216
241
|
}
|
|
242
|
+
return () => {
|
|
243
|
+
for (const item of mounts) item.mount.destroy();
|
|
244
|
+
mounts = [];
|
|
245
|
+
rootEl = null;
|
|
246
|
+
};
|
|
217
247
|
},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
applyRootClass(p);
|
|
248
|
+
render(root, p) {
|
|
249
|
+
rootEl = root;
|
|
250
|
+
applyRootClass(p as PackProps);
|
|
221
251
|
for (const item of mounts) {
|
|
222
|
-
item.mount.setProps(item.spec.adaptProps(p));
|
|
252
|
+
item.mount.setProps(item.spec.adaptProps(p as PackProps));
|
|
223
253
|
}
|
|
224
254
|
},
|
|
225
|
-
onUnmount(): void {
|
|
226
|
-
for (const item of mounts) item.mount.destroy();
|
|
227
|
-
mounts = [];
|
|
228
|
-
root = null;
|
|
229
|
-
},
|
|
230
255
|
};
|
|
231
|
-
},
|
|
256
|
+
}),
|
|
232
257
|
}, resolvedParts.map((r) => r.def), ownTokens);
|
|
233
258
|
}
|
|
234
259
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// 键用 Symbol.for:应用组件与编译器在 CJS / ESM 双载或打包器分块成两份模块实例时,键仍相等;元数据随定义走,不进进程级表。
|
|
6
6
|
|
|
7
7
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
8
|
+
import { KIT_STATE_PANEL_CLASS_CANDIDATES } from '../base/state-panel';
|
|
8
9
|
|
|
9
10
|
export interface WrappedCandidateSource {
|
|
10
11
|
/** 被包装 / 被嵌入的底层组件定义(编译器按它们的契约名查内置候选类,并递归读它们自己的元数据) */
|
|
@@ -45,6 +46,15 @@ export function declareKitUses<T extends SomaComponentDefinition>(def: T, uses:
|
|
|
45
46
|
return def;
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* 应用组件里用了 `kitStatePanel` / `paintKitStatePanel`(含 not_ready / upstream_broken / denied)时调一次:
|
|
51
|
+
* 把三态面板的类(盒、插画、重试钮)并入该组件的候选类,并满足 KIT-STYLE-003 的「声明过用到哪些内置件」。
|
|
52
|
+
* 与 `declareKitUses` 同一条元数据(可叠加;已声明的 uses 与候选类保留),返回同一个定义。
|
|
53
|
+
*/
|
|
54
|
+
export function declareKitStatePanel<T extends SomaComponentDefinition>(def: T): T {
|
|
55
|
+
return declareKitUses(def, [], KIT_STATE_PANEL_CLASS_CANDIDATES);
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
/** 给组件定义追加本层写死类(领域包按组件登记候选类用;与已有元数据合并) */
|
|
49
59
|
export function addWrappedOwnCandidates<T extends SomaComponentDefinition>(def: T, own: readonly string[]): T {
|
|
50
60
|
const prev = wrappedCandidateSource(def);
|
|
@@ -10,6 +10,7 @@ const BLANK_CANVAS_CLASS = 'bg-surface-sunken min-h-screen text-sm text-fg';
|
|
|
10
10
|
export const blankFrame: KitFrameDefinition = {
|
|
11
11
|
kind: 'blank-frame',
|
|
12
12
|
slots: ['main'],
|
|
13
|
+
capabilities: { ownsLayout: true },
|
|
13
14
|
compile(input) {
|
|
14
15
|
const diagnostics = [...checkSlots('blank-frame', ['main'], ['main'], input), ...checkFrameClasses(input), ...checkNoHeaderExtras('blank-frame', input)];
|
|
15
16
|
const main = slotFragment(input.slots.main);
|
package/src/frames/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { splitFrame } from './split-frame';
|
|
|
7
7
|
import { tabsFrame } from './tabs-frame';
|
|
8
8
|
import { topMainFrame } from './top-main-frame';
|
|
9
9
|
|
|
10
|
-
export type { KitFrameDefinition, KitFrameInput, KitPageMeta } from './types';
|
|
10
|
+
export type { KitFrameCapabilities, KitFrameDefinition, KitFrameInput, KitPageMeta } from './types';
|
|
11
11
|
import { workspaceFrame } from './workspace-frame';
|
|
12
12
|
|
|
13
13
|
export { blankFrame, singleFrame, splitFrame, tabsFrame, topMainFrame, workspaceFrame };
|
|
@@ -20,7 +20,7 @@ export { createKitWorkspace, mountKitWorkspace, workspaceLabels, withFrameQuery,
|
|
|
20
20
|
export type { KitWorkspaceHandle, KitWorkspaceEmit } from './workspace-frame/view';
|
|
21
21
|
export {
|
|
22
22
|
createWorkspaceState, openTab as openWorkspaceTab, switchTab as switchWorkspaceTab, closeTab as closeWorkspaceTab,
|
|
23
|
-
closeOtherTabs as closeOtherWorkspaceTabs, closeAllTabs as closeAllWorkspaceTabs, refreshTab as refreshWorkspaceTab,
|
|
23
|
+
closeOtherTabs as closeOtherWorkspaceTabs, closeAllTabs as closeAllWorkspaceTabs, closeTabsByKeys as closeWorkspaceTabsByKeys, refreshTab as refreshWorkspaceTab,
|
|
24
24
|
togglePinTab as togglePinWorkspaceTab, crumbsForTab, WORKSPACE_DEFAULT_MAX_TABS,
|
|
25
25
|
} from './workspace-frame/state';
|
|
26
26
|
export type { WorkspaceState, WorkspaceTab, WorkspaceTabInput } from './workspace-frame/state';
|
package/src/frames/page-bar.ts
CHANGED
|
@@ -4,15 +4,17 @@
|
|
|
4
4
|
// · back(返回):「← 返回」钮,点击走 services.navHistory.back(fallback, { exclude, previousCount })(core 选址并跳转),
|
|
5
5
|
// 端口缺席或抛错退到 fallback(location.assign);永远抛 back { url, viaFallback, steps }。
|
|
6
6
|
// · actions(动作):宽于 @lg 的页头容器内联成按钮(链接项是 <a>),窄于 @lg 收进「更多」下拉(role=menu,↑↓/Home/End/Esc,回焦触发钮)。
|
|
7
|
-
//
|
|
7
|
+
// 具名动作项点击抛槽位事件 action_<序号> { id },页面事件 `<锚点>.action_<序号>` 给每个动作各绑一条 ACTION | 名字;链接项直接导航,不抛事件。
|
|
8
8
|
// 容器查询以页头 <header> 的 @container 为准,所以动作区的折叠随页面框宽度走,而不是视口。
|
|
9
9
|
|
|
10
10
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
11
11
|
import { CLASS_PROP, createKitController, str } from '../base/shared';
|
|
12
12
|
import { safeHref } from '../base/link';
|
|
13
|
+
import { kitButtonNoWrapMap } from '../recipes/nowrap';
|
|
13
14
|
import { kitIcon } from '../base/icons';
|
|
14
15
|
import { kitDirAt, kitText } from '../i18n/kit-text';
|
|
15
16
|
import { queryWithDropdowns, releaseDropdownsIn } from '../base/popup';
|
|
17
|
+
import { KIT_ACTION_SLOT_BASE, actionSlotEmits, emitActionSlot } from '../base/action-slots';
|
|
16
18
|
import {
|
|
17
19
|
buildDropdownPanel, classSet, DROPDOWN_CLASSES, fitDropdownPanel, FOCUS, focusFirstItem, h, isRec, onOutsidePointer, recList, textOf,
|
|
18
20
|
type KitDropdownItem, type Rec,
|
|
@@ -20,23 +22,23 @@ import {
|
|
|
20
22
|
|
|
21
23
|
const ROOT_CLASS = 'flex min-w-0 items-center gap-2';
|
|
22
24
|
|
|
23
|
-
const BACK_CLASS = `inline-flex h-8 cursor-pointer items-center gap-1 rounded-md px-2 text-sm text-fg-muted transition-colors hover:bg-
|
|
25
|
+
const BACK_CLASS = `inline-flex h-8 cursor-pointer items-center gap-1 rounded-md px-2 text-sm text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg ${FOCUS}`;
|
|
24
26
|
const INLINE_CLASS = 'hidden @lg:flex items-center gap-2';
|
|
25
27
|
const MORE_WRAP_CLASS = 'relative @lg:hidden';
|
|
26
28
|
|
|
27
|
-
const BTN_CLASS: Record<string, string> = {
|
|
28
|
-
primary: 'inline-flex h-
|
|
29
|
-
neutral: 'inline-flex h-
|
|
30
|
-
danger: 'inline-flex h-
|
|
31
|
-
ghost: 'inline-flex h-
|
|
32
|
-
};
|
|
29
|
+
const BTN_CLASS: Record<string, string> = kitButtonNoWrapMap({
|
|
30
|
+
primary: 'inline-flex h-8 cursor-pointer items-center justify-center gap-2 rounded-md bg-primary px-4 text-sm font-medium text-primary-fg transition-colors enabled:hover:bg-primary-hover enabled:active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
31
|
+
neutral: 'inline-flex h-8 cursor-pointer items-center justify-center gap-2 rounded-md border border-button-edge bg-surface px-4 text-sm font-medium text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
32
|
+
danger: 'inline-flex h-8 cursor-pointer items-center justify-center gap-2 rounded-md bg-danger px-4 text-sm font-medium text-danger-fg transition-colors enabled:hover:bg-danger-hover enabled:active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
33
|
+
ghost: 'inline-flex h-8 cursor-pointer items-center justify-center gap-2 rounded-md px-4 text-sm font-medium text-fg transition-colors enabled:hover:bg-state-layer-hover enabled:active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
34
|
+
});
|
|
33
35
|
/** 链接项(<a>):没有 enabled 伪类,用 hover */
|
|
34
|
-
const LINK_CLASS: Record<string, string> = {
|
|
35
|
-
primary: 'inline-flex h-
|
|
36
|
-
neutral: 'inline-flex h-
|
|
37
|
-
danger: 'inline-flex h-
|
|
38
|
-
ghost: 'inline-flex h-
|
|
39
|
-
};
|
|
36
|
+
const LINK_CLASS: Record<string, string> = kitButtonNoWrapMap({
|
|
37
|
+
primary: 'inline-flex h-8 cursor-pointer items-center justify-center gap-2 rounded-md bg-primary px-4 text-sm font-medium text-primary-fg no-underline transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
38
|
+
neutral: 'inline-flex h-8 cursor-pointer items-center justify-center gap-2 rounded-md border border-button-edge bg-surface px-4 text-sm font-medium text-fg no-underline transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
39
|
+
danger: 'inline-flex h-8 cursor-pointer items-center justify-center gap-2 rounded-md bg-danger px-4 text-sm font-medium text-danger-fg no-underline transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
40
|
+
ghost: 'inline-flex h-8 cursor-pointer items-center justify-center gap-2 rounded-md px-4 text-sm font-medium text-fg no-underline transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
41
|
+
});
|
|
40
42
|
|
|
41
43
|
/** 本部件自带的全部类(供页头并入候选类) */
|
|
42
44
|
export const KIT_PAGE_BAR_CLASS_CANDIDATES: readonly string[] = classSet(
|
|
@@ -48,7 +50,7 @@ interface NavHistoryLike {
|
|
|
48
50
|
back?: (fallback: string, options?: { exclude?: string[]; previousCount?: number }) => Promise<BackResult> | BackResult;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
const variantOf = (raw: unknown): string => (typeof raw === 'string' && raw
|
|
53
|
+
const variantOf = (raw: unknown): string => (typeof raw === 'string' && Object.hasOwn(BTN_CLASS, raw) ? raw : 'neutral');
|
|
52
54
|
|
|
53
55
|
export function createKitPageBar(): SomaComponentDefinition {
|
|
54
56
|
return {
|
|
@@ -63,19 +65,19 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
63
65
|
},
|
|
64
66
|
emits: {
|
|
65
67
|
back: { payload: { url: { type: 'string' }, viaFallback: { type: 'boolean' }, steps: { type: 'number' } }, desc: '点了返回;url 是实际去处(站内路径)' },
|
|
66
|
-
|
|
68
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.header, { id: { type: 'string' } }, '点了具名动作项(链接项直接导航,不抛);序号 = 动作在 actions 数组里的位置'),
|
|
67
69
|
},
|
|
68
70
|
},
|
|
69
71
|
services: ['navHistory'],
|
|
70
72
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
71
|
-
controllerFactory: (
|
|
73
|
+
controllerFactory: createKitController((api) => {
|
|
72
74
|
// 每个实例一份:下拉开合与点外面关
|
|
73
75
|
let open = false;
|
|
74
76
|
let offOutside: (() => void) | null = null;
|
|
75
77
|
let paint: () => void = () => undefined;
|
|
76
78
|
|
|
77
|
-
return
|
|
78
|
-
attach(root
|
|
79
|
+
return {
|
|
80
|
+
attach(root) {
|
|
79
81
|
const doc = root.ownerDocument;
|
|
80
82
|
const win = doc.defaultView;
|
|
81
83
|
const closeMenu = (restore: boolean): void => {
|
|
@@ -99,7 +101,7 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
99
101
|
const opts: { exclude?: string[]; previousCount?: number } = {};
|
|
100
102
|
if (Array.isArray(back.exclude)) opts.exclude = back.exclude.filter((e): e is string => typeof e === 'string');
|
|
101
103
|
if (typeof back.previous_count === 'number') opts.previousCount = back.previous_count;
|
|
102
|
-
const port = (
|
|
104
|
+
const port = (api.services as { navHistory?: NavHistoryLike } | undefined)?.navHistory;
|
|
103
105
|
const done = (r: BackResult): void => api.emit('back', { url: r.url, viaFallback: r.viaFallback, steps: r.steps });
|
|
104
106
|
const toFallback = (): void => {
|
|
105
107
|
win?.location.assign(fallback);
|
|
@@ -127,7 +129,7 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
127
129
|
inline.append(h('a', LINK_CLASS[variant]!, { href, 'data-kit-page-action': id }, ...content));
|
|
128
130
|
} else {
|
|
129
131
|
const b = h('button', BTN_CLASS[variant]!, { type: 'button', disabled, 'data-kit-page-action': id }, ...content);
|
|
130
|
-
if (!disabled) b.addEventListener('click', () => api.emit(
|
|
132
|
+
if (!disabled) b.addEventListener('click', () => emitActionSlot(api.emit, KIT_ACTION_SLOT_BASE.header, actions.findIndex((x) => textOf(x.id) === id), { id }));
|
|
131
133
|
inline.append(b);
|
|
132
134
|
}
|
|
133
135
|
}
|
|
@@ -156,7 +158,7 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
156
158
|
closeMenu(true);
|
|
157
159
|
const href = a !== undefined && textOf(a.href) !== '' ? safeHref(textOf(a.href)) : '';
|
|
158
160
|
if (href !== '') win?.location.assign(href);
|
|
159
|
-
else api.emit(
|
|
161
|
+
else emitActionSlot(api.emit, KIT_ACTION_SLOT_BASE.header, actions.findIndex((x) => textOf(x.id) === key), { id: key });
|
|
160
162
|
}, (restore) => closeMenu(restore), moreLabel));
|
|
161
163
|
}
|
|
162
164
|
kids.push(inline, more);
|
|
@@ -179,7 +181,7 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
179
181
|
render() {
|
|
180
182
|
paint();
|
|
181
183
|
},
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
+
};
|
|
185
|
+
}),
|
|
184
186
|
};
|
|
185
187
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { KIT_WORKSPACE_FRAME_LIMITS } from 'soma-foundation/kit-limits';
|
|
5
5
|
import grammarJson from '../../spec/kit-grammar.json';
|
|
6
6
|
import { safeHref } from '../base/link';
|
|
7
|
+
import { checkNoRelativeOrSystemPath } from '../shared/path-guard';
|
|
7
8
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
8
9
|
import type { KitPageAction, KitPageBack, KitPageMeta } from './types';
|
|
9
10
|
|
|
@@ -68,7 +69,13 @@ function parseActions(raw: unknown, out: KitDiagnostic[]): KitPageAction[] | und
|
|
|
68
69
|
else if ([...label].length > L.actionLabel) tooLong(`${at}.label`, `${at}.label 不得超过 ${L.actionLabel} 字`, out);
|
|
69
70
|
if ((action === undefined) === (href === undefined)) shape(at, `${at} 必须在 action(应用登记的具名动作)与 href(链接)中二选一`, out);
|
|
70
71
|
if (action !== undefined && (typeof action !== 'string' || !ACTION_RE.test(action))) shape(`${at}.action`, `${at}.action 必须是具名动作名`, out);
|
|
71
|
-
if (href !== undefined
|
|
72
|
+
if (href !== undefined) {
|
|
73
|
+
if (typeof href !== 'string' || safeHref(href) === '') {
|
|
74
|
+
shape(`${at}.href`, `${at}.href 必须是安全地址(站内 / 路径、http(s)、mailto、tel)`, out);
|
|
75
|
+
} else {
|
|
76
|
+
checkNoRelativeOrSystemPath(href, `${at}.href`, out, 'KIT-PAGE-004', { allowExternalHref: true });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
72
79
|
if (variant !== undefined && (typeof variant !== 'string' || !PAGE_HEADER.actionVariants.includes(variant))) {
|
|
73
80
|
shape(`${at}.variant`, `${at}.variant 必须是 ${PAGE_HEADER.actionVariants.join(' / ')}`, out);
|
|
74
81
|
}
|
|
@@ -95,8 +102,10 @@ function parseBack(raw: unknown, out: KitDiagnostic[]): KitPageBack | undefined
|
|
|
95
102
|
}
|
|
96
103
|
unknownKeys(raw, PAGE_HEADER.backKeys, 'page.back', out);
|
|
97
104
|
const { fallback, exclude, previous_count: previous, label } = raw;
|
|
98
|
-
if (!isInternalPath(fallback)) {
|
|
99
|
-
|
|
105
|
+
if (!isInternalPath(fallback) || !checkNoRelativeOrSystemPath(fallback, 'page.back.fallback', out, 'KIT-PAGE-004')) {
|
|
106
|
+
if (!out.some((d) => d.path === 'page.back.fallback')) {
|
|
107
|
+
shape('page.back.fallback', 'page.back.fallback 必须是站内绝对路径(返回栈为空时的去处)', out);
|
|
108
|
+
}
|
|
100
109
|
return undefined;
|
|
101
110
|
}
|
|
102
111
|
const back: KitPageBack = { fallback };
|
|
@@ -173,8 +182,8 @@ export function parsePageHeader(page: Rec, out: KitDiagnostic[]): Partial<KitPag
|
|
|
173
182
|
}
|
|
174
183
|
}
|
|
175
184
|
if (page.max_width !== undefined) {
|
|
176
|
-
if (typeof page.max_width !== 'string' || !(page.max_width
|
|
177
|
-
|
|
185
|
+
if (typeof page.max_width !== 'string' || !Object.prototype.hasOwnProperty.call(PAGE_HEADER.maxWidths, page.max_width)) {
|
|
186
|
+
out.push({ code: 'KIT-PAGE-001', path: 'page.max_width', message: `page.max_width 必须是 ${Object.keys(PAGE_HEADER.maxWidths).join(' / ')}` });
|
|
178
187
|
} else meta.maxWidth = page.max_width;
|
|
179
188
|
}
|
|
180
189
|
if (page.sticky !== undefined) {
|
|
@@ -11,11 +11,13 @@ import { CLASS_PROP, createKitController } from '../base/shared';
|
|
|
11
11
|
import { onKitActionStatus, type KitActionStatusPhase } from '../base/action-status';
|
|
12
12
|
import { classSet } from '../data/menu-dom';
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
const
|
|
14
|
+
// 与标题的间距(mt-1)跟着文案走:没有文案时整行不占位(hidden),页头节奏与不写 status 的页一致
|
|
15
|
+
const ROOT_CLASS = 'mt-1 min-h-5 text-sm text-fg-muted';
|
|
16
|
+
const FAILED_CLASS = 'mt-1 min-h-5 text-sm text-danger-on-soft';
|
|
17
|
+
const EMPTY_CLASS = 'hidden';
|
|
16
18
|
|
|
17
19
|
/** 本部件自带的全部类(供页头并入候选类) */
|
|
18
|
-
export const KIT_PAGE_STATUS_CLASS_CANDIDATES: readonly string[] = classSet(ROOT_CLASS, FAILED_CLASS);
|
|
20
|
+
export const KIT_PAGE_STATUS_CLASS_CANDIDATES: readonly string[] = classSet(ROOT_CLASS, FAILED_CLASS, EMPTY_CLASS);
|
|
19
21
|
|
|
20
22
|
export function createKitPageStatus(): SomaComponentDefinition {
|
|
21
23
|
return {
|
|
@@ -28,12 +30,12 @@ export function createKitPageStatus(): SomaComponentDefinition {
|
|
|
28
30
|
},
|
|
29
31
|
emits: {},
|
|
30
32
|
},
|
|
31
|
-
templateHtml: `<p data-soma-id="root" role="status" aria-live="polite" class="${
|
|
32
|
-
controllerFactory: createKitController({
|
|
33
|
+
templateHtml: `<p data-soma-id="root" role="status" aria-live="polite" class="${EMPTY_CLASS}"></p>`,
|
|
34
|
+
controllerFactory: createKitController(() => ({
|
|
33
35
|
attach(root, api) {
|
|
34
36
|
const paint = (phase: KitActionStatusPhase | null, text: string): void => {
|
|
35
37
|
root.textContent = text;
|
|
36
|
-
root.className = phase === 'failed' ? FAILED_CLASS : ROOT_CLASS;
|
|
38
|
+
root.className = text === '' ? EMPTY_CLASS : phase === 'failed' ? FAILED_CLASS : ROOT_CLASS;
|
|
37
39
|
if (phase === null) root.removeAttribute('data-kit-status');
|
|
38
40
|
else root.setAttribute('data-kit-status', phase);
|
|
39
41
|
if (phase === 'busy') root.setAttribute('aria-busy', 'true');
|
|
@@ -49,6 +51,6 @@ export function createKitPageStatus(): SomaComponentDefinition {
|
|
|
49
51
|
},
|
|
50
52
|
// 状态来自事件;props 下行(follow / class)不改已显示的文案
|
|
51
53
|
render() { /* 空 */ },
|
|
52
|
-
}),
|
|
54
|
+
})),
|
|
53
55
|
};
|
|
54
56
|
}
|
package/src/frames/shared.ts
CHANGED
|
@@ -2,24 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
import { emptyFragment, mergeFragments, type KitFragment } from '../compile/fragment';
|
|
4
4
|
import { classesInHtml } from '../object-renderer/candidates';
|
|
5
|
+
import { KIT_ACTION_SLOT_BASE, actionSlotEvent, actionSlotOverflow } from '../base/action-slots';
|
|
5
6
|
import { checkClasses, mergeClass } from '../object-renderer/merge-class';
|
|
6
7
|
import type { KitDiagnostic } from '../object-renderer/types';
|
|
7
8
|
import { breadcrumbsHtml } from '../data/breadcrumbs';
|
|
9
|
+
import { KIT_PART_TITLE_PAGE, kitTypographyRecipe } from '../recipes/typography';
|
|
8
10
|
import type { KitFrameInput } from './types';
|
|
9
11
|
import { PAGE_HEADER } from './page-header';
|
|
10
12
|
import { KIT_PAGE_BAR_CLASS_CANDIDATES } from './page-bar';
|
|
11
13
|
import { KIT_PAGE_STATUS_CLASS_CANDIDATES } from './page-status';
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
15
|
+
import { esc } from '../shared/escape';
|
|
16
|
+
export { esc };
|
|
16
17
|
|
|
17
|
-
/** 第 1
|
|
18
|
-
export const CANVAS_CLASS = 'bg-surface-sunken p-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const TITLE_STANDARD_CLASS = 'text-xl font-semibold text-fg';
|
|
22
|
-
const EYEBROW_CLASS = 'mb-1 text-xs font-medium text-primary';
|
|
18
|
+
/** 第 1 层:页面框画布;页边距读真源 density.pageMarginPx(--soma-page-margin,标准 24 / 紧凑 16 / 宽松 32,随 theme.density),不再按档位换类 */
|
|
19
|
+
export const CANVAS_CLASS = 'bg-surface-sunken p-page min-h-screen text-sm text-fg';
|
|
20
|
+
const TITLE_CLASS = kitTypographyRecipe('pageTitle');
|
|
21
|
+
const EYEBROW_CLASS = 'mb-1 text-xs font-medium text-primary-on-soft';
|
|
23
22
|
const SUBTITLE_CLASS = 'mt-1 text-sm text-fg-muted';
|
|
24
23
|
|
|
25
24
|
export function classAttr(value: string): string {
|
|
@@ -27,10 +26,12 @@ export function classAttr(value: string): string {
|
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
// 页头扩展(F1):页头成为容器查询的容器(动作区随它折叠);吸顶时盖住滚上来的内容
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
29
|
+
// 页面标题到首块统一 16(间距阶 4 / 8 / 12 / 16 / 24 的 16 = mb-4);吸顶时用 pb-4 代替 mb-4,保证滚上来的内容不露在页头与首块之间
|
|
30
|
+
// 间距读真源 structure.titleToBlockGapUnits(--soma-title-block-gap,标准 4 × 4 = 16,随密度同比):mb-title-block / pb-title-block
|
|
31
|
+
const HEADER_BAR_CLASS = 'mb-title-block @container';
|
|
32
|
+
const HEADER_BAR_STANDARD_CLASS = 'mb-title-block @container';
|
|
33
|
+
const HEADER_STICKY_CLASS = 'sticky top-0 z-10 bg-surface-sunken pb-title-block @container';
|
|
34
|
+
const HEADER_STICKY_STANDARD_CLASS = 'sticky top-0 z-10 bg-surface-sunken pb-title-block @container';
|
|
34
35
|
const TITLE_ROW_CLASS = 'flex flex-wrap items-center gap-2';
|
|
35
36
|
const TOP_ROW_CLASS = 'flex flex-wrap items-start justify-between gap-3';
|
|
36
37
|
const BACK_WRAP_CLASS = 'mb-2';
|
|
@@ -45,14 +46,14 @@ const WIDTH_WRAP_CLASS = 'mx-auto w-full';
|
|
|
45
46
|
|
|
46
47
|
/** 页头用到的全部固定类(含页头部件 KitPageBar 自带类),并入候选 */
|
|
47
48
|
const HEADER_EXTRA_CANDIDATES: readonly string[] = [
|
|
48
|
-
...new Set([HEADER_BAR_CLASS, HEADER_BAR_STANDARD_CLASS, HEADER_STICKY_CLASS, HEADER_STICKY_STANDARD_CLASS, TITLE_CLASS,
|
|
49
|
+
...new Set([HEADER_BAR_CLASS, HEADER_BAR_STANDARD_CLASS, HEADER_STICKY_CLASS, HEADER_STICKY_STANDARD_CLASS, TITLE_CLASS, TITLE_ROW_CLASS, TOP_ROW_CLASS, BACK_WRAP_CLASS, ...Object.values(STATUS_CLASS), ...KIT_PAGE_BAR_CLASS_CANDIDATES, ...KIT_PAGE_STATUS_CLASS_CANDIDATES]
|
|
49
50
|
.flatMap((s) => s.split(/\s+/)).filter((c) => c !== '')),
|
|
50
51
|
];
|
|
51
52
|
|
|
52
53
|
/** max_width 档位 -> 包裹类(真源 pageHeader.maxWidths;full 与未写都不包) */
|
|
53
54
|
export function maxWidthClass(input: KitFrameInput): string {
|
|
54
55
|
const key = input.page.maxWidth;
|
|
55
|
-
const cls = key
|
|
56
|
+
const cls = key !== undefined && Object.prototype.hasOwnProperty.call(PAGE_HEADER.maxWidths, key) ? (PAGE_HEADER.maxWidths[key] ?? '') : '';
|
|
56
57
|
return cls === '' ? '' : `${WIDTH_WRAP_CLASS} ${cls}`;
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -89,12 +90,12 @@ export function checkNoMaxWidth(kind: string, input: KitFrameInput): KitDiagnost
|
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
92
|
* 页头片段:标题 / 副标题 / 眼眉 / 面包屑(静态直出)+ F1 扩展(状态标签静态;返回与动作是 KitPageBar 实例)。
|
|
92
|
-
* 动作的 action 须在应用登记的具名动作里(input.registeredActions 给了才校验),点击事件 `<锚点>.
|
|
93
|
+
* 动作的 action 须在应用登记的具名动作里(input.registeredActions 给了才校验),点击事件 `<锚点>.action_<序号>`(序号 = 动作在 page.actions 里的位置)各绑一条 ACTION | 名字。
|
|
93
94
|
*/
|
|
94
95
|
export function headerFragment(input: KitFrameInput, prefix = ''): KitFragment {
|
|
95
96
|
const hid = `${prefix}frame__header`;
|
|
96
97
|
const out = emptyFragment();
|
|
97
|
-
const isStandard = input
|
|
98
|
+
const isStandard = roomyCanvas(input);
|
|
98
99
|
const { page } = input;
|
|
99
100
|
const { title, subtitle, eyebrow, breadcrumbs } = page;
|
|
100
101
|
const crumbs = breadcrumbs !== undefined && breadcrumbs.length > 0
|
|
@@ -126,28 +127,33 @@ export function headerFragment(input: KitFrameInput, prefix = ''): KitFragment {
|
|
|
126
127
|
if (page.statusFollow !== undefined) {
|
|
127
128
|
const id = `${hid}__live`;
|
|
128
129
|
show[id] = { props: { follow: [...page.statusFollow] } };
|
|
129
|
-
liveHtml = `<div data-soma-component="KitPageStatus" data-soma-id="${esc(id)}"
|
|
130
|
+
liveHtml = `<div data-soma-component="KitPageStatus" data-soma-id="${esc(id)}"></div>`;
|
|
130
131
|
}
|
|
131
132
|
let actionsHtml = '';
|
|
132
133
|
if (page.actions !== undefined && page.actions.length > 0) {
|
|
133
134
|
const id = `${hid}__actions`;
|
|
134
135
|
show[id] = { props: { actions: page.actions.map((a) => ({ ...a })) } };
|
|
135
|
-
|
|
136
|
+
// 每个页头动作各抛 action_<序号>(序号 = 它在 actions 数组里的位置),各绑一条 ACTION | 名字
|
|
137
|
+
const overflow = actionSlotOverflow(page.actions.length, 'page.actions');
|
|
138
|
+
if (overflow !== null) out.diagnostics.push({ code: 'KIT-EVT-001', path: 'page.actions', message: overflow });
|
|
136
139
|
page.actions.forEach((a, i) => {
|
|
137
140
|
if (a.action === undefined) return;
|
|
138
141
|
if (input.registeredActions !== undefined && !input.registeredActions.has(a.action)) {
|
|
139
142
|
out.diagnostics.push({ code: 'KIT-EVT-001', path: `page.actions[${i}].action`, message: `页头动作 ${a.id} 的 action "${a.action}" 未在应用的具名动作中登记` });
|
|
140
143
|
return;
|
|
141
144
|
}
|
|
142
|
-
|
|
145
|
+
out.events[`${id}.${actionSlotEvent(KIT_ACTION_SLOT_BASE.header, i)}`] = `ACTION | ${a.action}`;
|
|
143
146
|
});
|
|
144
|
-
if (steps.length > 0) out.events[`${id}.action`] = { steps };
|
|
145
147
|
actionsHtml = `<div data-soma-component="KitPageBar" data-soma-id="${esc(id)}" class="shrink-0"></div>`;
|
|
146
148
|
}
|
|
147
|
-
const titleCls =
|
|
149
|
+
const titleCls = TITLE_CLASS;
|
|
148
150
|
const barCls = page.sticky === true ? (isStandard ? HEADER_STICKY_STANDARD_CLASS : HEADER_STICKY_CLASS) : (isStandard ? HEADER_BAR_STANDARD_CLASS : HEADER_BAR_CLASS);
|
|
149
|
-
const titleBlock = `<div class="min-w-0"><div${classAttr(TITLE_ROW_CLASS)}><h1 data-soma-id="${esc(`${hid}__title`)}"${classAttr(titleCls)}>${esc(title)}</h1>${status}</div>${sub}${liveHtml}</div>`;
|
|
150
|
-
|
|
151
|
+
const titleBlock = `<div class="min-w-0"><div${classAttr(TITLE_ROW_CLASS)}><h1 data-soma-id="${esc(`${hid}__title`)}" data-kit-part="${KIT_PART_TITLE_PAGE}"${classAttr(titleCls)}>${esc(title)}</h1>${status}</div>${sub}${liveHtml}</div>`;
|
|
152
|
+
// 吸顶页头与画布同层(层 0):它只是盖住滚动内容的画布色条,不是新的一层表面;不写则编译期标注把它标成层 1(白底),在蓝灰画布上长出一条白带
|
|
153
|
+
const stickyLayer = page.sticky === true ? ' data-kit-layer="0"' : '';
|
|
154
|
+
// 吸顶页头吸住后才出现下缘分隔:标记 data-kit-sticky-edge(滚动驱动 CSS 路径,零脚本;样式与数字在结构 CSS / 真源 structure.stickyEdge)
|
|
155
|
+
const stickyEdge = page.sticky === true ? ' data-kit-sticky-edge=""' : '';
|
|
156
|
+
out.html = `<header data-soma-id="${esc(hid)}"${stickyLayer}${stickyEdge}${classAttr(barCls)}>${crumbs}${backHtml}${eye}<div${classAttr(TOP_ROW_CLASS)}>${titleBlock}${actionsHtml}</div></header>`;
|
|
151
157
|
if (Object.keys(show).length > 0) out.ui.show = show;
|
|
152
158
|
const used: string[] = [];
|
|
153
159
|
if (backHtml !== '' || actionsHtml !== '') used.push('KitPageBar');
|
|
@@ -214,8 +220,13 @@ export function finishFrame(slotParts: KitFragment[], html: string, extraCandida
|
|
|
214
220
|
};
|
|
215
221
|
}
|
|
216
222
|
|
|
223
|
+
/** 宽松画布:仅当应用密度显式指定为 SPACIOUS_AIRY 时启用 p-6 宽松画布;未设与默认 STANDARD_BALANCED 及 COMPACT_DENSE 统一为 p-4 标准画布 */
|
|
224
|
+
function roomyCanvas(input: KitFrameInput): boolean {
|
|
225
|
+
return input.density === 'SPACIOUS_AIRY';
|
|
226
|
+
}
|
|
227
|
+
|
|
217
228
|
export function rootClass(input: KitFrameInput, base?: string): string {
|
|
218
|
-
const dflt = base ??
|
|
229
|
+
const dflt = base ?? CANVAS_CLASS;
|
|
219
230
|
return mergeClass(dflt, input.class);
|
|
220
231
|
}
|
|
221
232
|
|
|
@@ -6,6 +6,7 @@ import { checkFrameClasses, checkSlots, classAttr, finishFrame, headerFragment,
|
|
|
6
6
|
export const singleFrame: KitFrameDefinition = {
|
|
7
7
|
kind: 'single-frame',
|
|
8
8
|
slots: ['main'],
|
|
9
|
+
capabilities: { supportsMaxWidth: true },
|
|
9
10
|
compile(input) {
|
|
10
11
|
const diagnostics = [...checkSlots('single-frame', ['main'], ['main'], input), ...checkFrameClasses(input)];
|
|
11
12
|
const head = headerFragment(input);
|