soma-kit 0.1.11 → 0.1.12
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 +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -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 +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- 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 +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- 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 +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- 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 +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- 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 +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- 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/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -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 +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- 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/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- 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 +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -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 +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- 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 +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- 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 +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- 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 +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -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 +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -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 +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -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/data/prompt-dialog.ts +0 -235
- 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/frames/page-bar.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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';
|
|
@@ -13,6 +13,7 @@ import { safeHref } from '../base/link';
|
|
|
13
13
|
import { kitIcon } from '../base/icons';
|
|
14
14
|
import { kitDirAt, kitText } from '../i18n/kit-text';
|
|
15
15
|
import { queryWithDropdowns, releaseDropdownsIn } from '../base/popup';
|
|
16
|
+
import { KIT_ACTION_SLOT_BASE, actionSlotEmits, emitActionSlot } from '../base/action-slots';
|
|
16
17
|
import {
|
|
17
18
|
buildDropdownPanel, classSet, DROPDOWN_CLASSES, fitDropdownPanel, FOCUS, focusFirstItem, h, isRec, onOutsidePointer, recList, textOf,
|
|
18
19
|
type KitDropdownItem, type Rec,
|
|
@@ -48,7 +49,7 @@ interface NavHistoryLike {
|
|
|
48
49
|
back?: (fallback: string, options?: { exclude?: string[]; previousCount?: number }) => Promise<BackResult> | BackResult;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
const variantOf = (raw: unknown): string => (typeof raw === 'string' && raw
|
|
52
|
+
const variantOf = (raw: unknown): string => (typeof raw === 'string' && Object.hasOwn(BTN_CLASS, raw) ? raw : 'neutral');
|
|
52
53
|
|
|
53
54
|
export function createKitPageBar(): SomaComponentDefinition {
|
|
54
55
|
return {
|
|
@@ -63,19 +64,19 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
63
64
|
},
|
|
64
65
|
emits: {
|
|
65
66
|
back: { payload: { url: { type: 'string' }, viaFallback: { type: 'boolean' }, steps: { type: 'number' } }, desc: '点了返回;url 是实际去处(站内路径)' },
|
|
66
|
-
|
|
67
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.header, { id: { type: 'string' } }, '点了具名动作项(链接项直接导航,不抛);序号 = 动作在 actions 数组里的位置'),
|
|
67
68
|
},
|
|
68
69
|
},
|
|
69
70
|
services: ['navHistory'],
|
|
70
71
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
71
|
-
controllerFactory: (
|
|
72
|
+
controllerFactory: createKitController((api) => {
|
|
72
73
|
// 每个实例一份:下拉开合与点外面关
|
|
73
74
|
let open = false;
|
|
74
75
|
let offOutside: (() => void) | null = null;
|
|
75
76
|
let paint: () => void = () => undefined;
|
|
76
77
|
|
|
77
|
-
return
|
|
78
|
-
attach(root
|
|
78
|
+
return {
|
|
79
|
+
attach(root) {
|
|
79
80
|
const doc = root.ownerDocument;
|
|
80
81
|
const win = doc.defaultView;
|
|
81
82
|
const closeMenu = (restore: boolean): void => {
|
|
@@ -99,7 +100,7 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
99
100
|
const opts: { exclude?: string[]; previousCount?: number } = {};
|
|
100
101
|
if (Array.isArray(back.exclude)) opts.exclude = back.exclude.filter((e): e is string => typeof e === 'string');
|
|
101
102
|
if (typeof back.previous_count === 'number') opts.previousCount = back.previous_count;
|
|
102
|
-
const port = (
|
|
103
|
+
const port = (api.services as { navHistory?: NavHistoryLike } | undefined)?.navHistory;
|
|
103
104
|
const done = (r: BackResult): void => api.emit('back', { url: r.url, viaFallback: r.viaFallback, steps: r.steps });
|
|
104
105
|
const toFallback = (): void => {
|
|
105
106
|
win?.location.assign(fallback);
|
|
@@ -127,7 +128,7 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
127
128
|
inline.append(h('a', LINK_CLASS[variant]!, { href, 'data-kit-page-action': id }, ...content));
|
|
128
129
|
} else {
|
|
129
130
|
const b = h('button', BTN_CLASS[variant]!, { type: 'button', disabled, 'data-kit-page-action': id }, ...content);
|
|
130
|
-
if (!disabled) b.addEventListener('click', () => api.emit(
|
|
131
|
+
if (!disabled) b.addEventListener('click', () => emitActionSlot(api.emit, KIT_ACTION_SLOT_BASE.header, actions.findIndex((x) => textOf(x.id) === id), { id }));
|
|
131
132
|
inline.append(b);
|
|
132
133
|
}
|
|
133
134
|
}
|
|
@@ -156,7 +157,7 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
156
157
|
closeMenu(true);
|
|
157
158
|
const href = a !== undefined && textOf(a.href) !== '' ? safeHref(textOf(a.href)) : '';
|
|
158
159
|
if (href !== '') win?.location.assign(href);
|
|
159
|
-
else api.emit(
|
|
160
|
+
else emitActionSlot(api.emit, KIT_ACTION_SLOT_BASE.header, actions.findIndex((x) => textOf(x.id) === key), { id: key });
|
|
160
161
|
}, (restore) => closeMenu(restore), moreLabel));
|
|
161
162
|
}
|
|
162
163
|
kids.push(inline, more);
|
|
@@ -179,7 +180,7 @@ export function createKitPageBar(): SomaComponentDefinition {
|
|
|
179
180
|
render() {
|
|
180
181
|
paint();
|
|
181
182
|
},
|
|
182
|
-
}
|
|
183
|
-
},
|
|
183
|
+
};
|
|
184
|
+
}),
|
|
184
185
|
};
|
|
185
186
|
}
|
|
@@ -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) {
|
|
@@ -29,7 +29,7 @@ export function createKitPageStatus(): SomaComponentDefinition {
|
|
|
29
29
|
emits: {},
|
|
30
30
|
},
|
|
31
31
|
templateHtml: `<p data-soma-id="root" role="status" aria-live="polite" class="${ROOT_CLASS}"></p>`,
|
|
32
|
-
controllerFactory: createKitController({
|
|
32
|
+
controllerFactory: createKitController(() => ({
|
|
33
33
|
attach(root, api) {
|
|
34
34
|
const paint = (phase: KitActionStatusPhase | null, text: string): void => {
|
|
35
35
|
root.textContent = text;
|
|
@@ -49,6 +49,6 @@ export function createKitPageStatus(): SomaComponentDefinition {
|
|
|
49
49
|
},
|
|
50
50
|
// 状态来自事件;props 下行(follow / class)不改已显示的文案
|
|
51
51
|
render() { /* 空 */ },
|
|
52
|
-
}),
|
|
52
|
+
})),
|
|
53
53
|
};
|
|
54
54
|
}
|
package/src/frames/shared.ts
CHANGED
|
@@ -2,24 +2,24 @@
|
|
|
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
|
+
/** 第 1 层:页面框画布(默认 STANDARD_BALANCED 与 COMPACT_DENSE 为标准 p-4 + 14px 基准字号;theme.density 显式给 SPACIOUS_AIRY 切宽松 p-6) */
|
|
18
19
|
export const CANVAS_CLASS = 'bg-surface-sunken p-4 min-h-screen text-sm text-fg';
|
|
19
20
|
export const CANVAS_STANDARD_CLASS = 'bg-surface-sunken p-6 min-h-screen text-sm text-fg';
|
|
20
|
-
const TITLE_CLASS = '
|
|
21
|
-
const
|
|
22
|
-
const EYEBROW_CLASS = 'mb-1 text-xs font-medium text-primary';
|
|
21
|
+
const TITLE_CLASS = kitTypographyRecipe('pageTitle');
|
|
22
|
+
const EYEBROW_CLASS = 'mb-1 text-xs font-medium text-primary-on-soft';
|
|
23
23
|
const SUBTITLE_CLASS = 'mt-1 text-sm text-fg-muted';
|
|
24
24
|
|
|
25
25
|
export function classAttr(value: string): string {
|
|
@@ -45,14 +45,14 @@ const WIDTH_WRAP_CLASS = 'mx-auto w-full';
|
|
|
45
45
|
|
|
46
46
|
/** 页头用到的全部固定类(含页头部件 KitPageBar 自带类),并入候选 */
|
|
47
47
|
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,
|
|
48
|
+
...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
49
|
.flatMap((s) => s.split(/\s+/)).filter((c) => c !== '')),
|
|
50
50
|
];
|
|
51
51
|
|
|
52
52
|
/** max_width 档位 -> 包裹类(真源 pageHeader.maxWidths;full 与未写都不包) */
|
|
53
53
|
export function maxWidthClass(input: KitFrameInput): string {
|
|
54
54
|
const key = input.page.maxWidth;
|
|
55
|
-
const cls = key
|
|
55
|
+
const cls = key !== undefined && Object.prototype.hasOwnProperty.call(PAGE_HEADER.maxWidths, key) ? (PAGE_HEADER.maxWidths[key] ?? '') : '';
|
|
56
56
|
return cls === '' ? '' : `${WIDTH_WRAP_CLASS} ${cls}`;
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -89,12 +89,12 @@ export function checkNoMaxWidth(kind: string, input: KitFrameInput): KitDiagnost
|
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* 页头片段:标题 / 副标题 / 眼眉 / 面包屑(静态直出)+ F1 扩展(状态标签静态;返回与动作是 KitPageBar 实例)。
|
|
92
|
-
* 动作的 action 须在应用登记的具名动作里(input.registeredActions 给了才校验),点击事件 `<锚点>.
|
|
92
|
+
* 动作的 action 须在应用登记的具名动作里(input.registeredActions 给了才校验),点击事件 `<锚点>.action_<序号>`(序号 = 动作在 page.actions 里的位置)各绑一条 ACTION | 名字。
|
|
93
93
|
*/
|
|
94
94
|
export function headerFragment(input: KitFrameInput, prefix = ''): KitFragment {
|
|
95
95
|
const hid = `${prefix}frame__header`;
|
|
96
96
|
const out = emptyFragment();
|
|
97
|
-
const isStandard = input
|
|
97
|
+
const isStandard = roomyCanvas(input);
|
|
98
98
|
const { page } = input;
|
|
99
99
|
const { title, subtitle, eyebrow, breadcrumbs } = page;
|
|
100
100
|
const crumbs = breadcrumbs !== undefined && breadcrumbs.length > 0
|
|
@@ -132,21 +132,22 @@ export function headerFragment(input: KitFrameInput, prefix = ''): KitFragment {
|
|
|
132
132
|
if (page.actions !== undefined && page.actions.length > 0) {
|
|
133
133
|
const id = `${hid}__actions`;
|
|
134
134
|
show[id] = { props: { actions: page.actions.map((a) => ({ ...a })) } };
|
|
135
|
-
|
|
135
|
+
// 每个页头动作各抛 action_<序号>(序号 = 它在 actions 数组里的位置),各绑一条 ACTION | 名字
|
|
136
|
+
const overflow = actionSlotOverflow(page.actions.length, 'page.actions');
|
|
137
|
+
if (overflow !== null) out.diagnostics.push({ code: 'KIT-EVT-001', path: 'page.actions', message: overflow });
|
|
136
138
|
page.actions.forEach((a, i) => {
|
|
137
139
|
if (a.action === undefined) return;
|
|
138
140
|
if (input.registeredActions !== undefined && !input.registeredActions.has(a.action)) {
|
|
139
141
|
out.diagnostics.push({ code: 'KIT-EVT-001', path: `page.actions[${i}].action`, message: `页头动作 ${a.id} 的 action "${a.action}" 未在应用的具名动作中登记` });
|
|
140
142
|
return;
|
|
141
143
|
}
|
|
142
|
-
|
|
144
|
+
out.events[`${id}.${actionSlotEvent(KIT_ACTION_SLOT_BASE.header, i)}`] = `ACTION | ${a.action}`;
|
|
143
145
|
});
|
|
144
|
-
if (steps.length > 0) out.events[`${id}.action`] = { steps };
|
|
145
146
|
actionsHtml = `<div data-soma-component="KitPageBar" data-soma-id="${esc(id)}" class="shrink-0"></div>`;
|
|
146
147
|
}
|
|
147
|
-
const titleCls =
|
|
148
|
+
const titleCls = TITLE_CLASS;
|
|
148
149
|
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
|
+
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>`;
|
|
150
151
|
out.html = `<header data-soma-id="${esc(hid)}"${classAttr(barCls)}>${crumbs}${backHtml}${eye}<div${classAttr(TOP_ROW_CLASS)}>${titleBlock}${actionsHtml}</div></header>`;
|
|
151
152
|
if (Object.keys(show).length > 0) out.ui.show = show;
|
|
152
153
|
const used: string[] = [];
|
|
@@ -214,8 +215,13 @@ export function finishFrame(slotParts: KitFragment[], html: string, extraCandida
|
|
|
214
215
|
};
|
|
215
216
|
}
|
|
216
217
|
|
|
218
|
+
/** 宽松画布:仅当应用密度显式指定为 SPACIOUS_AIRY 时启用 p-6 宽松画布;未设与默认 STANDARD_BALANCED 及 COMPACT_DENSE 统一为 p-4 标准画布 */
|
|
219
|
+
function roomyCanvas(input: KitFrameInput): boolean {
|
|
220
|
+
return input.density === 'SPACIOUS_AIRY';
|
|
221
|
+
}
|
|
222
|
+
|
|
217
223
|
export function rootClass(input: KitFrameInput, base?: string): string {
|
|
218
|
-
const dflt = base ?? (input
|
|
224
|
+
const dflt = base ?? (roomyCanvas(input) ? CANVAS_STANDARD_CLASS : CANVAS_CLASS);
|
|
219
225
|
return mergeClass(dflt, input.class);
|
|
220
226
|
}
|
|
221
227
|
|
|
@@ -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);
|
|
@@ -108,7 +108,7 @@ export function checkSplitConfig(config: Rec | undefined): { value: SplitConfig;
|
|
|
108
108
|
else out.push(bad('ratio', `ratio(${value.ratio})必须落在 min(${value.min})与 max(${value.max})之间`));
|
|
109
109
|
}
|
|
110
110
|
if (config.height !== undefined) {
|
|
111
|
-
if (typeof config.height !== 'string' || !(config.height
|
|
111
|
+
if (typeof config.height !== 'string' || !Object.hasOwn(SPLIT_G.heightTiers, config.height)) out.push(bad('height', `height 只许 ${Object.keys(SPLIT_G.heightTiers).join(' / ')}`));
|
|
112
112
|
else value.height = config.height;
|
|
113
113
|
if (value.direction !== 'vertical') out.push(bad('height', 'height 只在 direction: vertical 时有意义'));
|
|
114
114
|
}
|
|
@@ -134,11 +134,10 @@ export function checkSplitConfig(config: Rec | undefined): { value: SplitConfig;
|
|
|
134
134
|
return { value, diagnostics: out };
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
function simpleFrame(input: KitFrameInput,
|
|
137
|
+
function simpleFrame(input: KitFrameInput, diagnostics: KitDiagnostic[]): ReturnType<KitFrameDefinition['compile']> {
|
|
138
138
|
const left = slotFragment(input.slots.left);
|
|
139
139
|
const right = slotFragment(input.slots.right);
|
|
140
140
|
const grid = `<div data-soma-id="frame__split"${classAttr(WRAP_CLASS)}><div data-soma-id="frame__grid"${classAttr(GRID_CLASS)}>${slotWrapper('left', CELL_CLASS, input, left.html)}${slotWrapper('right', CELL_CLASS, input, right.html)}</div></div>`;
|
|
141
|
-
void cfg;
|
|
142
141
|
const head = headerFragment(input);
|
|
143
142
|
const html = `<div data-soma-id="frame__root"${classAttr(rootClass(input))}>${head.html}${grid}</div>`;
|
|
144
143
|
return finishFrame([head, left, right], html, [], [...diagnostics, ...checkNoMaxWidth('split-frame', input)]);
|
|
@@ -147,11 +146,12 @@ function simpleFrame(input: KitFrameInput, cfg: SplitConfig, diagnostics: KitDia
|
|
|
147
146
|
export const splitFrame: KitFrameDefinition = {
|
|
148
147
|
kind: 'split-frame',
|
|
149
148
|
slots: ['left', 'right'],
|
|
149
|
+
capabilities: { readsConfig: true },
|
|
150
150
|
compile(input) {
|
|
151
151
|
const diagnostics = [...checkSlots('split-frame', ['left', 'right'], ['left', 'right'], input), ...checkFrameClasses(input)];
|
|
152
152
|
const { value: cfg, diagnostics: cfgDiag } = checkSplitConfig(input.config);
|
|
153
153
|
diagnostics.push(...cfgDiag);
|
|
154
|
-
if (input.config === undefined) return simpleFrame(input,
|
|
154
|
+
if (input.config === undefined) return simpleFrame(input, diagnostics);
|
|
155
155
|
|
|
156
156
|
const dir = cfg.direction;
|
|
157
157
|
const horizontal = dir === 'horizontal';
|
|
@@ -181,7 +181,7 @@ export const splitFrame: KitFrameDefinition = {
|
|
|
181
181
|
const cls = horizontal ? (side === 'right' ? H_TOGGLE_RIGHT : H_TOGGLE_LEFT) : (side === 'right' ? V_TOGGLE_BOTTOM : V_TOGGLE_TOP);
|
|
182
182
|
const isCollapsed = collapsedSide === side;
|
|
183
183
|
const label = isCollapsed ? cfg.expandLabel : cfg.collapseLabel;
|
|
184
|
-
return `<button type="button" data-kit-split-toggle="${side}" data-soma-id="frame__toggle" aria-expanded="${isCollapsed ? 'false' : 'true'}" aria-controls="${esc(`frame__${side}`)}" aria-label="${esc(label)}" data-icon-open="${glyph(side, false)}" data-icon-closed="${glyph(side, true)}"${classAttr(cls)}>${kitIconHtml(glyph(side, isCollapsed), 'sm', 'rtl:-scale-x-100')}</button>`;
|
|
184
|
+
return `<button type="button" data-kit-face="raised" data-kit-split-toggle="${side}" data-soma-id="frame__toggle" aria-expanded="${isCollapsed ? 'false' : 'true'}" aria-controls="${esc(`frame__${side}`)}" aria-label="${esc(label)}" data-icon-open="${glyph(side, false)}" data-icon-closed="${glyph(side, true)}"${classAttr(cls)}>${kitIconHtml(glyph(side, isCollapsed), 'sm', 'rtl:-scale-x-100')}</button>`;
|
|
185
185
|
};
|
|
186
186
|
// 按钮放在另一栏:left 可折叠 → right 栏里;right 可折叠 → left 栏里
|
|
187
187
|
const leftInner = `${body(left)}${handle}${toggleFor('right')}`;
|
|
@@ -61,7 +61,7 @@ export function createKitSplitWiring(): SomaComponentDefinition {
|
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
63
|
templateHtml: '<div data-soma-id="root" hidden></div>',
|
|
64
|
-
controllerFactory: createKitController({
|
|
64
|
+
controllerFactory: createKitController(() => ({
|
|
65
65
|
attach(root) {
|
|
66
66
|
const state: WiringState = { key: '', destroy: () => {} };
|
|
67
67
|
STATES.set(root, state);
|
|
@@ -159,6 +159,6 @@ export function createKitSplitWiring(): SomaComponentDefinition {
|
|
|
159
159
|
toggle?.removeEventListener('click', onToggle);
|
|
160
160
|
};
|
|
161
161
|
},
|
|
162
|
-
}),
|
|
162
|
+
})),
|
|
163
163
|
};
|
|
164
164
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// tabs-frame:顶部页签切换栏 + 下方各签独立产品承载框。
|
|
2
2
|
//
|
|
3
|
-
//
|
|
3
|
+
// 切换由 KitTabsWiring 在组件内完成(点页签 / 键盘 ←→Home/End 选中,面板显隐用 hidden 属性),不写事件声明、不引入页面状态;
|
|
4
4
|
// 隐藏接线件 KitTabsWiring 挂载后经 wireKitTablist 补 tablist/tab/tabpanel 的 ARIA、aria-selected、roving tabindex 与 ←/→/Home/End;
|
|
5
5
|
// 首签默认显示,其余面板初始 hidden。槽位按页签 id 取(slots[id]);没有同名槽位时,取 slots.tabs 数组里同序号的片段。
|
|
6
6
|
// 页签 id 限字母数字下划线,供锚点使用(锚点不含点号)。
|
|
@@ -63,7 +63,6 @@ export const tabsFrame: KitFrameDefinition = {
|
|
|
63
63
|
if (input.frameId !== undefined && input.frameId !== '' && !ID_RE.test(input.frameId)) {
|
|
64
64
|
diagnostics.push({ code: 'KIT-FRAME-001', path: 'frame.frameId', message: `帧实例前缀 ${input.frameId} 只许字母数字下划线且以字母开头` });
|
|
65
65
|
}
|
|
66
|
-
const events: Record<string, unknown> = {};
|
|
67
66
|
const buttons: string[] = [];
|
|
68
67
|
const panels: string[] = [];
|
|
69
68
|
const parts: KitFragment[] = [];
|
|
@@ -74,9 +73,6 @@ export const tabsFrame: KitFrameDefinition = {
|
|
|
74
73
|
}
|
|
75
74
|
parts.push(frag);
|
|
76
75
|
buttons.push(`<button type="button" data-soma-id="${esc(tabAnchor(t.id, input.frameId))}" data-key="${esc(t.id)}" role="tab" aria-selected="${i === 0 ? 'true' : 'false'}"${classAttr(TAB_CLASS)}>${esc(t.title)}</button>`);
|
|
77
|
-
events[`${tabAnchor(t.id, input.frameId)}.click`] = {
|
|
78
|
-
steps: tabs.map((o) => ({ do: `UI_INTERACT | ${panelAnchor(o.id, input.frameId)} | | ${o.id === t.id ? 'open' : 'close'}` })),
|
|
79
|
-
};
|
|
80
76
|
const cls = mergeClass('', input.slotClass?.[t.id]);
|
|
81
77
|
// 外层只放 hidden(无 preflight:与 grid / flex 同元素会让隐藏失效),slotClass 在内层
|
|
82
78
|
panels.push(`<div data-soma-id="${esc(panelAnchor(t.id, input.frameId))}"${i === 0 ? '' : ' hidden'}><div data-soma-id="${esc(`${fp}tabs__body__${t.id}`)}"${classAttr(cls)}>${frag.html}</div></div>`);
|
|
@@ -85,19 +81,12 @@ export const tabsFrame: KitFrameDefinition = {
|
|
|
85
81
|
const barId = `${fp}tabs__bar`;
|
|
86
82
|
const wiringId = `${fp}tabs__wiring`;
|
|
87
83
|
const bar = `<div data-soma-id="${esc(barId)}" role="tablist"${classAttr(BAR_CLASS)}>${buttons.join('')}</div>`;
|
|
88
|
-
// 隐藏接线件:给页签栏补 ARIA
|
|
84
|
+
// 隐藏接线件:给页签栏补 ARIA 与键盘,并切面板 hidden(见 wiring.ts)
|
|
89
85
|
const wiring = `<div data-soma-component="KitTabsWiring" data-soma-id="${esc(wiringId)}" hidden></div>`;
|
|
90
86
|
// data-kit-tabs-frame:接线件从自身往上找到它,只在本框内查锚点
|
|
91
87
|
const head = headerFragment(input, fp);
|
|
92
88
|
const html = `<div data-soma-id="${esc(`${fp}frame__root`)}" data-kit-tabs-frame=""${classAttr(rootClass(input))}>${head.html}${bar}${wiring}<div data-soma-id="${esc(`${fp}tabs__panels`)}">${panels.join('')}</div></div>`;
|
|
93
89
|
const out = finishFrame([head, ...parts], html, [], [...diagnostics, ...checkNoMaxWidth('tabs-frame', input)]);
|
|
94
|
-
for (const [k, v] of Object.entries(events)) {
|
|
95
|
-
if (k in out.events) {
|
|
96
|
-
out.diagnostics.push({ code: 'KIT-PAGE-002', path: `events.${k}`, message: `event 键重复:${k}` });
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
out.events[k] = v;
|
|
100
|
-
}
|
|
101
90
|
const show = (out.ui.show ??= {});
|
|
102
91
|
if (wiringId in show) {
|
|
103
92
|
out.diagnostics.push({ code: 'KIT-PAGE-002', path: `ui.show.${wiringId}`, message: `ui.show 键重复:${wiringId}` });
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// KitTabsWiring:tabs-frame 里的隐藏接线件(数据层小组件,不画任何东西)。
|
|
2
2
|
//
|
|
3
|
-
// 页签栏与面板是静态 HTML
|
|
3
|
+
// 页签栏与面板是静态 HTML,没有任何事件声明(core 的 `_event` 一个事件只能绑一条管道,切 N 个面板写不进去):
|
|
4
4
|
// 本组件挂载时对页签栏调 `wireKitTablist`(soma-core/keyboard 接线):补 role=tablist/tab/tabpanel、
|
|
5
|
-
// aria-selected、aria-controls、roving tabindex
|
|
6
|
-
// 键盘激活时合成一次 `tab.click()`,原有的 UI_INTERACT 事件照常生效(面板 hidden 仍由 core 管,这里不碰)。
|
|
5
|
+
// aria-selected、aria-controls、roving tabindex,让 ←/→/Home/End 生效,并由接线随选中切换各面板的 hidden(点击 / 键盘一致)。
|
|
7
6
|
|
|
8
7
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
8
|
import { createKitController, str, wireKitTablist, type KitProps } from '../../base/shared';
|
|
@@ -29,7 +28,7 @@ export function createKitTabsWiring(): SomaComponentDefinition {
|
|
|
29
28
|
},
|
|
30
29
|
},
|
|
31
30
|
templateHtml: '<div data-soma-id="root" hidden></div>',
|
|
32
|
-
controllerFactory: createKitController({
|
|
31
|
+
controllerFactory: createKitController(() => ({
|
|
33
32
|
attach(root) {
|
|
34
33
|
const state: WiringState = { key: '', destroy: () => {} };
|
|
35
34
|
STATES.set(root, state);
|
|
@@ -56,14 +55,11 @@ export function createKitTabsWiring(): SomaComponentDefinition {
|
|
|
56
55
|
tabs: () => ids.map(tabOf).filter((t): t is HTMLElement => t !== null),
|
|
57
56
|
idOf: (tab) => tab.dataset.key ?? '',
|
|
58
57
|
panelOf: (id) => doc.querySelector<HTMLElement>(`[data-soma-id="${panelPrefix}${id}"]`),
|
|
59
|
-
panelHidden: false,
|
|
60
58
|
selected: ids[0] ?? null,
|
|
61
59
|
activation,
|
|
62
|
-
// 键盘激活:合成点击,让 core 的 UI_INTERACT 事件切面板
|
|
63
|
-
onSelect: (_id, tab) => { tab.click(); },
|
|
64
60
|
});
|
|
65
61
|
state.destroy = () => handle.destroy();
|
|
66
62
|
},
|
|
67
|
-
}),
|
|
63
|
+
})),
|
|
68
64
|
};
|
|
69
65
|
}
|
|
@@ -8,6 +8,7 @@ const STACK_CLASS = 'space-y-5';
|
|
|
8
8
|
export const topMainFrame: KitFrameDefinition = {
|
|
9
9
|
kind: 'top-main-frame',
|
|
10
10
|
slots: ['top', 'main'],
|
|
11
|
+
capabilities: { supportsMaxWidth: true },
|
|
11
12
|
compile(input) {
|
|
12
13
|
const diagnostics = [...checkSlots('top-main-frame', ['top', 'main'], ['top', 'main'], input), ...checkFrameClasses(input)];
|
|
13
14
|
const head = headerFragment(input);
|
package/src/frames/types.ts
CHANGED
|
@@ -62,8 +62,8 @@ export interface KitFrameInput {
|
|
|
62
62
|
registeredActions?: ReadonlySet<string>;
|
|
63
63
|
/** 页面语言(同 KitBizContext.locale):页面框写进产物的内置文案按它取 */
|
|
64
64
|
locale?: string;
|
|
65
|
-
/**
|
|
66
|
-
density?: '
|
|
65
|
+
/** 应用级九维密度(kit.app.yaml#app.theme.density,由编译器从应用继承,页面框自己不单设):缺省与默认 STANDARD_BALANCED 及 COMPACT_DENSE 同为 p-4 标准画布,显式给 SPACIOUS_AIRY 用 p-6 宽松画布 */
|
|
66
|
+
density?: import('../app/app-config').KitThemeDensity;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export interface KitFrameDefinition {
|
|
@@ -71,4 +71,15 @@ export interface KitFrameDefinition {
|
|
|
71
71
|
/** 固定槽位名;tabs-frame 的 `tabs` 表示「页签槽位」 */
|
|
72
72
|
slots: string[];
|
|
73
73
|
compile(input: KitFrameInput): KitFragment;
|
|
74
|
+
/** 能力声明(缺省皆 false,即「普通页面框」):编译器按性质判断,不按页面框名字判断 */
|
|
75
|
+
capabilities?: KitFrameCapabilities;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface KitFrameCapabilities {
|
|
79
|
+
/** 读取 `frame.config`(未声明时给了 config 报 KIT-FRAME-003) */
|
|
80
|
+
readsConfig?: boolean;
|
|
81
|
+
/** 页面框自管整页布局(无页头外壳 / 自带整页壳):不继承应用级 `app.layout`(maxWidth / stickyHeader) */
|
|
82
|
+
ownsLayout?: boolean;
|
|
83
|
+
/** 页面框内容区支持 `page.maxWidth` 档位:应用级 `app.layout.maxWidth` 只继承给这类页面框 */
|
|
84
|
+
supportsMaxWidth?: boolean;
|
|
74
85
|
}
|
|
@@ -53,6 +53,15 @@ export interface WorkspaceExtras {
|
|
|
53
53
|
destroy(): void;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/** 从 hash 中提取查询段与路径前缀(支持 #/path?x=1、#/path 以及 #x=1) */
|
|
57
|
+
export function extractHashQuery(hashStr: string): { prefix: string; query: string } {
|
|
58
|
+
const raw = hashStr.startsWith('#') ? hashStr.slice(1) : hashStr;
|
|
59
|
+
const qIdx = raw.indexOf('?');
|
|
60
|
+
if (qIdx >= 0) return { prefix: raw.slice(0, qIdx), query: raw.slice(qIdx + 1) };
|
|
61
|
+
if (raw.startsWith('/')) return { prefix: raw, query: '' };
|
|
62
|
+
return { prefix: '', query: raw };
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
export function mountWorkspaceExtras(host: WorkspaceExtrasHost): WorkspaceExtras {
|
|
57
66
|
const doc = host.root.ownerDocument;
|
|
58
67
|
let cfg: Rec = {};
|
|
@@ -130,7 +139,9 @@ export function mountWorkspaceExtras(host: WorkspaceExtrasHost): WorkspaceExtras
|
|
|
130
139
|
// ── 分享 hash ──
|
|
131
140
|
const readHash = (): string => {
|
|
132
141
|
try {
|
|
133
|
-
const
|
|
142
|
+
const hash = globalThis.location?.hash ?? '';
|
|
143
|
+
const { query } = extractHashQuery(hash);
|
|
144
|
+
const v = new URLSearchParams(query).get(SHARE_PARAM) ?? '';
|
|
134
145
|
return v !== '' && safeHref(v) !== '' ? v : '';
|
|
135
146
|
} catch { return ''; }
|
|
136
147
|
};
|
|
@@ -144,13 +155,18 @@ export function mountWorkspaceExtras(host: WorkspaceExtrasHost): WorkspaceExtras
|
|
|
144
155
|
if (url !== '' && url !== host.activeUrl()) applyHash(url);
|
|
145
156
|
};
|
|
146
157
|
const writeHash = (url: string): void => {
|
|
147
|
-
const next = `#${SHARE_PARAM}=${encodeURIComponent(url)}`;
|
|
148
|
-
if (globalThis.location?.hash === next) { hashPushed = true; return; }
|
|
149
158
|
try {
|
|
159
|
+
const hash = globalThis.location?.hash ?? '';
|
|
160
|
+
const { prefix, query } = extractHashQuery(hash);
|
|
161
|
+
const params = new URLSearchParams(query);
|
|
162
|
+
params.set(SHARE_PARAM, url);
|
|
163
|
+
const q = params.toString();
|
|
164
|
+
const next = prefix !== '' ? `#${prefix}?${q}` : `#${q}`;
|
|
165
|
+
if (globalThis.location?.hash === next) { hashPushed = true; return; }
|
|
150
166
|
if (hashPushed) globalThis.history?.pushState(null, '', next);
|
|
151
167
|
else globalThis.history?.replaceState(null, '', next);
|
|
168
|
+
hashPushed = true;
|
|
152
169
|
} catch { /* 沙箱页等不许改地址栏:跳过 */ }
|
|
153
|
-
hashPushed = true;
|
|
154
170
|
};
|
|
155
171
|
|
|
156
172
|
return {
|
|
@@ -7,7 +7,7 @@ export {
|
|
|
7
7
|
export type { KitWorkspaceHandle, KitWorkspaceEmit } from './view';
|
|
8
8
|
export {
|
|
9
9
|
createWorkspaceState, openTab as openWorkspaceTab, switchTab as switchWorkspaceTab, closeTab as closeWorkspaceTab,
|
|
10
|
-
closeOtherTabs as closeOtherWorkspaceTabs, closeAllTabs as closeAllWorkspaceTabs, refreshTab as refreshWorkspaceTab,
|
|
10
|
+
closeOtherTabs as closeOtherWorkspaceTabs, closeAllTabs as closeAllWorkspaceTabs, closeTabsByKeys as closeWorkspaceTabsByKeys, refreshTab as refreshWorkspaceTab,
|
|
11
11
|
togglePinTab as togglePinWorkspaceTab, crumbsForTab, WORKSPACE_DEFAULT_MAX_TABS,
|
|
12
12
|
} from './state';
|
|
13
13
|
export type { WorkspaceState, WorkspaceTab, WorkspaceTabInput } from './state';
|
|
@@ -270,6 +270,7 @@ export function checkWorkspaceConfig(config: Rec | undefined): KitDiagnostic[] {
|
|
|
270
270
|
export const workspaceFrame: KitFrameDefinition = {
|
|
271
271
|
kind: 'workspace-frame',
|
|
272
272
|
slots: [],
|
|
273
|
+
capabilities: { readsConfig: true, ownsLayout: true },
|
|
273
274
|
compile(input) {
|
|
274
275
|
const diagnostics: KitDiagnostic[] = [...checkFrameClasses(input), ...checkNoHeaderExtras('workspace-frame', input), ...checkWorkspaceConfig(input.config)];
|
|
275
276
|
const id = 'workspace__view';
|
|
@@ -102,17 +102,24 @@ export function closeTab(state: WorkspaceState, key: string): WorkspaceState {
|
|
|
102
102
|
return { ...state, tabs, active };
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* 按给定的标签键集合关闭:不可关闭 / 固定的标签即便在集合里也保留,集合里不存在的键跳过。
|
|
107
|
+
* 激活标签被关时回落到基准标签 base(缺省无基准、该标签也已被关则取第一个保留的标签)。
|
|
108
|
+
*/
|
|
109
|
+
export function closeTabsByKeys(state: WorkspaceState, keys: Iterable<string>, base: string = ''): WorkspaceState {
|
|
110
|
+
const drop = new Set(keys);
|
|
111
|
+
const tabs = state.tabs.filter((t) => !drop.has(t.key) || !isTabClosable(t));
|
|
112
|
+
const active = tabs.some((t) => t.key === state.active) ? state.active : (tabs.find((t) => t.key === base)?.key ?? tabs[0]?.key ?? '');
|
|
113
|
+
return { ...state, tabs, active };
|
|
114
|
+
}
|
|
115
|
+
|
|
105
116
|
/** 关闭其他:保留 key(缺省当前)与所有不可关闭 / 固定的标签 */
|
|
106
117
|
export function closeOtherTabs(state: WorkspaceState, key: string = state.active): WorkspaceState {
|
|
107
|
-
|
|
108
|
-
const active = tabs.some((t) => t.key === state.active) ? state.active : (tabs.find((t) => t.key === key)?.key ?? tabs[0]?.key ?? '');
|
|
109
|
-
return { ...state, tabs, active };
|
|
118
|
+
return closeTabsByKeys(state, state.tabs.filter((t) => t.key !== key && isTabClosable(t)).map((t) => t.key), key);
|
|
110
119
|
}
|
|
111
120
|
|
|
112
121
|
export function closeAllTabs(state: WorkspaceState): WorkspaceState {
|
|
113
|
-
|
|
114
|
-
const active = tabs.some((t) => t.key === state.active) ? state.active : (tabs[0]?.key ?? '');
|
|
115
|
-
return { ...state, tabs, active };
|
|
122
|
+
return closeTabsByKeys(state, state.tabs.filter(isTabClosable).map((t) => t.key));
|
|
116
123
|
}
|
|
117
124
|
|
|
118
125
|
export function refreshTab(state: WorkspaceState, key: string = state.active): WorkspaceState {
|