soma-kit 0.1.12 → 0.1.14
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 +5 -4
- package/bin/soma-kit.mjs +31 -1
- package/bin/soma.mjs +0 -0
- package/package.json +5 -4
- package/spec/generated/kit-app.schema.json +172 -4
- package/spec/generated/kit-page.schema.json +164 -5
- package/spec/kit-grammar.json +598 -96
- package/spec/kit-grammar.schema.json +12 -6
- package/src/app/app-config.ts +92 -8
- package/src/app/component-gate.ts +271 -13
- package/src/app/define-kit-app.ts +2 -2
- package/src/app/define-kit-view.ts +9 -5
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/index.ts +29 -5
- package/src/app/kit-view-context.ts +181 -15
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +55 -8
- package/src/app/theme-runtime.ts +4 -0
- package/src/base/action-busy.ts +101 -4
- package/src/base/action-slots.ts +13 -2
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/button.ts +62 -15
- package/src/base/check-core.ts +8 -0
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +21 -2
- package/src/base/color-picker.ts +10 -5
- package/src/base/command-palette.ts +1 -1
- package/src/base/context-menu.ts +10 -7
- package/src/base/date-range.ts +7 -7
- package/src/base/date.ts +55 -16
- package/src/base/delta.ts +72 -0
- package/src/base/end-edge.ts +61 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +168 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +95 -0
- package/src/base/index.ts +32 -9
- package/src/base/listbox-core.ts +6 -5
- package/src/base/loading-gate.ts +140 -87
- package/src/base/mentions.ts +2 -1
- package/src/base/menu-button.ts +16 -18
- package/src/base/menu-core.ts +37 -8
- package/src/base/motion/hover-3d.ts +1 -1
- package/src/base/motion/marquee.ts +1 -1
- package/src/base/otp.ts +5 -4
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/popover.ts +10 -9
- package/src/base/popup.ts +67 -8
- package/src/base/portal-core.ts +4 -0
- package/src/base/qty-stepper.ts +5 -5
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +19 -2
- package/src/base/rating.ts +11 -6
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +36 -24
- package/src/base/shared.ts +180 -36
- package/src/base/state-panel.ts +367 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +6 -6
- package/src/base/switch.ts +10 -5
- package/src/base/tag-input.ts +6 -6
- package/src/base/tag.ts +76 -41
- package/src/base/text.ts +43 -14
- package/src/base/time-picker.ts +7 -5
- package/src/base/tree-select.ts +6 -4
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +15 -9
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +15 -11
- package/src/biz/auth-panel/shell.ts +9 -7
- package/src/biz/category-crud/compile.ts +5 -4
- package/src/biz/category-crud/shell.ts +5 -3
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +10 -8
- package/src/biz/compose.ts +2 -2
- package/src/biz/data-components.ts +4 -0
- package/src/biz/import-wizard/shell.ts +13 -10
- package/src/biz/landing-page/shell.ts +2 -2
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +207 -16
- package/src/biz/master-sub/detail-head.ts +61 -0
- package/src/biz/master-sub/index.ts +7 -3
- package/src/biz/master-sub/shell.ts +133 -24
- package/src/biz/multi-board/compile.ts +167 -9
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +1 -1
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +94 -23
- package/src/biz/notification-center/shell.ts +10 -7
- package/src/biz/page-templates/domain-templates.ts +2 -2
- package/src/biz/page-templates/result-page/shell.ts +4 -3
- package/src/biz/page-templates/sign-in-page/shell.ts +16 -16
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +13 -10
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +12 -9
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +97 -0
- package/src/biz/shared/coordinator.ts +7 -30
- package/src/biz/shared/index.ts +5 -0
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +281 -0
- package/src/biz/shared/overlay-shell.ts +142 -11
- package/src/biz/shared/pipes.ts +11 -5
- package/src/biz/shared/remove-wire.ts +4 -19
- package/src/biz/shared/runtime-hub.ts +10 -0
- package/src/biz/single-form/compile.ts +3 -2
- package/src/biz/single-form/shell.ts +9 -6
- package/src/biz/standard-crud/compile.ts +36 -161
- package/src/biz/standard-crud/shell.ts +23 -60
- package/src/biz/standard-crud/summary.ts +40 -0
- package/src/biz/step-form/shell.ts +15 -13
- package/src/biz/types.ts +6 -1
- package/src/cli/kit-cli.ts +138 -13
- package/src/cli/kit-init.ts +6 -1
- 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/view-writes.ts +69 -60
- package/src/compile/access-gate-attach.ts +27 -0
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +66 -11
- package/src/compile/component-candidates.ts +14 -1
- package/src/compile/fragment.ts +11 -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 +267 -0
- package/src/compile/layout-lint/rules-form.ts +191 -0
- package/src/compile/layout-lint/rules-table.ts +278 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/page-composition.ts +189 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +46 -8
- package/src/compile/types.ts +16 -2
- package/src/compile/view-check.ts +149 -16
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +9 -2
- package/src/data/approval-flow.ts +5 -2
- package/src/data/assignment-picker.ts +59 -28
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +8 -3
- package/src/data/carousel.ts +10 -6
- package/src/data/chart.ts +744 -46
- package/src/data/checklist.ts +22 -6
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +3 -2
- package/src/data/confirm-dialog.ts +72 -25
- package/src/data/context-menu.ts +3 -3
- package/src/data/dock.ts +1 -1
- package/src/data/embed.ts +231 -29
- package/src/data/field-mapper.ts +7 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +26 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/footer.ts +2 -0
- package/src/data/gantt.ts +192 -27
- package/src/data/hero.ts +4 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +16 -4
- package/src/data/item-list.ts +27 -12
- package/src/data/kanban.ts +41 -10
- package/src/data/matrix.ts +391 -0
- package/src/data/media-grid.ts +6 -1
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +60 -16
- package/src/data/mockup.ts +5 -1
- package/src/data/modal-dialog.ts +146 -26
- package/src/data/navbar.ts +8 -6
- package/src/data/notice-list.ts +301 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +409 -87
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +19 -8
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +36 -11
- package/src/data/permission-tree.ts +52 -23
- package/src/data/pricing-table.ts +22 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +40 -7
- package/src/data/record-picker.ts +13 -7
- package/src/data/resident.ts +8 -0
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +77 -24
- package/src/data/rule-builder.ts +14 -9
- package/src/data/shape-util.ts +27 -12
- package/src/data/stat-group.ts +459 -74
- package/src/data/static-lazy.ts +5 -0
- package/src/data/static-registry.ts +8 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +7 -4
- package/src/data/system-switcher.ts +3 -2
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +3 -2
- package/src/data/transfer.ts +40 -16
- package/src/data/tree-table.ts +65 -37
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +21 -11
- package/src/data/wrapped-candidates.ts +32 -1
- package/src/frames/index.ts +1 -0
- package/src/frames/list-summary.ts +100 -0
- package/src/frames/page-bar.ts +7 -14
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +34 -13
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +9 -6
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +3 -3
- package/src/frames/types.ts +3 -1
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +4 -4
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +168 -44
- package/src/generated/kit-grammar-runtime.ts +390 -59
- package/src/i18n/kit-text.ts +90 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/action-group.ts +139 -0
- package/src/object-renderer/action-more.ts +144 -0
- package/src/object-renderer/arrange.ts +71 -7
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +264 -62
- package/src/object-renderer/collection-table.ts +177 -5
- package/src/object-renderer/collection.ts +188 -37
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +27 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-object.ts +4 -0
- package/src/object-renderer/emit-static.ts +434 -41
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +5 -0
- package/src/object-renderer/layout-facts.ts +394 -0
- package/src/object-renderer/layout-plan.ts +225 -0
- package/src/object-renderer/layout-plan.types.ts +59 -0
- package/src/object-renderer/parts.ts +6 -7
- package/src/object-renderer/render-object.ts +107 -46
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +172 -32
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +62 -30
- package/src/object-renderer/types.ts +84 -13
- package/src/object-renderer/view-binding.ts +205 -8
- package/src/page-target/intent-schema.ts +11 -0
- package/src/page-target/target.ts +5 -1
- package/src/recipes/container.ts +77 -1
- package/src/recipes/control.ts +76 -116
- package/src/recipes/emphasis.ts +56 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +72 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +120 -17
- package/src/recipes/placeholder.ts +95 -0
- package/src/recipes/rail-grid.ts +48 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +40 -21
- package/src/recipes/status.ts +147 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +146 -3
- package/src/recipes/tabs.ts +49 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +30 -37
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +2 -2
- package/src/shared/paged-list-adapter.ts +15 -240
- package/src/shared/theme-runtime-shared.ts +6 -1
- package/src/theme/index.ts +1 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +384 -13
- package/src/theme/kit-theme.tpl +384 -13
- package/src/theme/nine-dim-structure.ts +244 -7
- package/src/theme/surface-layers.ts +10 -1
- package/src/theme/theme-tokens.ts +63 -16
- package/src/theme/theme-types.ts +32 -0
- package/src/theme/typography.ts +21 -17
- package/src/biz/shared/remove-key.ts +0 -6
package/src/base/shared.ts
CHANGED
|
@@ -19,6 +19,9 @@ import {
|
|
|
19
19
|
popupTipClass, showPopupFitted,
|
|
20
20
|
} from './popup';
|
|
21
21
|
import { classCandidates } from './class-candidates';
|
|
22
|
+
import { leaveAnchored, unmarkAnchored } from './anchored-layer';
|
|
23
|
+
import type { KitLeaveHandle } from './overlay-runtime';
|
|
24
|
+
import { withKitViewTransition } from './view-transition';
|
|
22
25
|
import { kitBusyOf, onKitActionBusy } from './action-busy';
|
|
23
26
|
import { deniedBy, registerLivePermissionGate } from './permission-gate';
|
|
24
27
|
import { kitText } from '../i18n/kit-text';
|
|
@@ -30,7 +33,6 @@ import {
|
|
|
30
33
|
kitFocusRingRecipe,
|
|
31
34
|
kitInvalidRecipe,
|
|
32
35
|
KIT_TYPOGRAPHY_RECIPE_MAP,
|
|
33
|
-
kitTypographyRecipe,
|
|
34
36
|
type KitTypographyRecipeRole,
|
|
35
37
|
} from '../recipes';
|
|
36
38
|
|
|
@@ -46,18 +48,7 @@ export function sizeOf(raw: unknown): KitSize {
|
|
|
46
48
|
// ── 文本类控件的统一类串(Input / Textarea 的单行部分 / Number / Date / DateRange / Select)─────
|
|
47
49
|
// 直接由 kitControlRecipe 与 kitInvalidRecipe 生成,不再维护平行字面量或拆单 token。
|
|
48
50
|
|
|
49
|
-
export const KIT_TYPOGRAPHY: Readonly<Record<KitTypographyRecipeRole, string>> =
|
|
50
|
-
pageTitle: kitTypographyRecipe('pageTitle'),
|
|
51
|
-
dialogTitle: kitTypographyRecipe('dialogTitle'),
|
|
52
|
-
sectionTitle: kitTypographyRecipe('sectionTitle'),
|
|
53
|
-
statValue: kitTypographyRecipe('statValue'),
|
|
54
|
-
body: kitTypographyRecipe('body'),
|
|
55
|
-
bodyStrong: kitTypographyRecipe('bodyStrong'),
|
|
56
|
-
caption: kitTypographyRecipe('caption'),
|
|
57
|
-
muted: kitTypographyRecipe('muted'),
|
|
58
|
-
code: kitTypographyRecipe('code'),
|
|
59
|
-
label: kitTypographyRecipe('label'),
|
|
60
|
-
});
|
|
51
|
+
export const KIT_TYPOGRAPHY: Readonly<Record<KitTypographyRecipeRole, string>> = KIT_TYPOGRAPHY_RECIPE_MAP;
|
|
61
52
|
|
|
62
53
|
export { KIT_TYPOGRAPHY_RECIPE_MAP };
|
|
63
54
|
|
|
@@ -75,7 +66,7 @@ export function withInvalid(base: string, invalid: boolean): string {
|
|
|
75
66
|
return invalid ? `${base} ${FIELD_INVALID_CLASS}` : base;
|
|
76
67
|
}
|
|
77
68
|
|
|
78
|
-
export const KIT_SPINNER_CLASS = 'inline-block h-4 w-4 animate-spin rounded-full border-2 border-border border-t-primary';
|
|
69
|
+
export const KIT_SPINNER_CLASS = 'inline-block h-4 w-4 motion-safe:animate-spin rounded-full border-2 border-border border-t-primary';
|
|
79
70
|
|
|
80
71
|
// ── props 读取 ────────────────────────────────────────────────
|
|
81
72
|
|
|
@@ -115,6 +106,8 @@ export interface KitOption {
|
|
|
115
106
|
label: string;
|
|
116
107
|
/** 仅 Tag 读:命中该选项时优先于 tone prop */
|
|
117
108
|
tone?: KitTone;
|
|
109
|
+
/** 选项写了 `tone: unknown`(未知 / 无法判断):tone 按 neutral 归一(不认识 unknown 的组件照 neutral 画),Tag 读此标记画虚线未知外观 */
|
|
110
|
+
unknown?: boolean;
|
|
118
111
|
disabled?: boolean;
|
|
119
112
|
/** Radio / Checkbox 读:选项图标(短字符,emoji 或符号);label 为空时是纯图标选项 */
|
|
120
113
|
icon?: string;
|
|
@@ -163,13 +156,15 @@ export function optionsOf(raw: unknown): KitOption[] {
|
|
|
163
156
|
const icon = typeof rec.icon === 'string' ? rec.icon : '';
|
|
164
157
|
// 带 icon 又没写 label = 纯图标选项(label 为空,可访问名取 aria_label,缺省取 value)
|
|
165
158
|
const label = rec.label !== undefined && rec.label !== null ? String(rec.label) : icon !== '' ? '' : String(rec.value ?? '');
|
|
166
|
-
const
|
|
159
|
+
const unknownTone = rec.tone === 'unknown';
|
|
160
|
+
const tone = unknownTone ? 'neutral' : toneOf(rec.tone, null);
|
|
167
161
|
push({
|
|
168
162
|
value: rec.value,
|
|
169
163
|
label,
|
|
170
164
|
...(icon !== '' ? { icon } : {}),
|
|
171
165
|
...(typeof rec.aria_label === 'string' && rec.aria_label !== '' ? { aria_label: rec.aria_label } : {}),
|
|
172
166
|
...(tone ? { tone } : {}),
|
|
167
|
+
...(unknownTone ? { unknown: true } : {}),
|
|
173
168
|
...(rec.disabled === true ? { disabled: true } : {}),
|
|
174
169
|
});
|
|
175
170
|
}
|
|
@@ -246,6 +241,11 @@ export interface DisplayResult {
|
|
|
246
241
|
* 铁律:只产出文字。有 options 时按选项取 label(命中不到则显示原值);
|
|
247
242
|
* 没有 options 时 bool、0/1 一律显示原值文字,不变成开关或色块。
|
|
248
243
|
*/
|
|
244
|
+
/** 空值判定(displayOf 与 Tag 共用唯一一份):null / undefined / '' / 空数组 */
|
|
245
|
+
export function valueIsEmpty(value: unknown): boolean {
|
|
246
|
+
return value === null || value === undefined || value === '' || (Array.isArray(value) && value.length === 0);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
249
|
export function displayOf(
|
|
250
250
|
value: unknown,
|
|
251
251
|
options: readonly KitOption[],
|
|
@@ -253,7 +253,9 @@ export function displayOf(
|
|
|
253
253
|
locale: string,
|
|
254
254
|
placeholder: string,
|
|
255
255
|
): DisplayResult {
|
|
256
|
-
|
|
256
|
+
// 显式空串 '' 是「有意留白」:渲染为空白;null / undefined / 空数组仍按占位(缺省「-」)
|
|
257
|
+
if (value === '') return { text: '', option: null };
|
|
258
|
+
if (valueIsEmpty(value)) {
|
|
257
259
|
return { text: placeholder, option: null };
|
|
258
260
|
}
|
|
259
261
|
if (options.length > 0) {
|
|
@@ -276,6 +278,16 @@ export function findRoot(host: HTMLElement): HTMLElement {
|
|
|
276
278
|
?? host;
|
|
277
279
|
}
|
|
278
280
|
|
|
281
|
+
/**
|
|
282
|
+
* 整块不渲染:收起组件根;根在没有标题的看板面板里(`data-kit-board-panel="bare"`)时,面板壳一并收起 / 恢复,不留空白圆角条。
|
|
283
|
+
* 带标题的面板壳不动(标题行仍在,空态由组件自己画)。
|
|
284
|
+
*/
|
|
285
|
+
export function kitCollapseBlock(root: HTMLElement, collapsed: boolean): void {
|
|
286
|
+
root.hidden = collapsed;
|
|
287
|
+
const panel = root.closest<HTMLElement>('[data-kit-board-panel="bare"]');
|
|
288
|
+
if (panel !== null) panel.hidden = collapsed;
|
|
289
|
+
}
|
|
290
|
+
|
|
279
291
|
export function setBoolAttr(el: Element, name: string, on: boolean): void {
|
|
280
292
|
if (on) el.setAttribute(name, '');
|
|
281
293
|
else el.removeAttribute(name);
|
|
@@ -286,19 +298,111 @@ export function setAttr(el: Element, name: string, value: string): void {
|
|
|
286
298
|
else el.setAttribute(name, value);
|
|
287
299
|
}
|
|
288
300
|
|
|
289
|
-
/**
|
|
301
|
+
/** 上一次由 applyCommon 写进 aria-describedby 的 id 串(合并时只替换自己写的那部分,不抹掉控件自带的说明 id) */
|
|
302
|
+
const APPLIED_DESCRIBEDBY = new WeakMap<Element, string[]>();
|
|
303
|
+
|
|
304
|
+
/** 空白分隔的 id 串拆成去重的令牌表 */
|
|
305
|
+
function idRefTokens(raw: string): string[] {
|
|
306
|
+
return Array.from(new Set(raw.split(/\s+/).filter((t) => t !== '')));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** 在空白分隔的 id 引用属性里加入一个令牌(已在则不动) */
|
|
310
|
+
export function addIdToken(el: Element, attr: string, id: string): void {
|
|
311
|
+
const tokens = idRefTokens(el.getAttribute(attr) ?? '');
|
|
312
|
+
if (id === '' || tokens.includes(id)) return;
|
|
313
|
+
el.setAttribute(attr, [...tokens, id].join(' '));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** 从空白分隔的 id 引用属性里摘掉一个令牌;摘空则移除属性 */
|
|
317
|
+
export function removeIdToken(el: Element, attr: string, id: string): void {
|
|
318
|
+
const tokens = idRefTokens(el.getAttribute(attr) ?? '');
|
|
319
|
+
if (!tokens.includes(id)) return;
|
|
320
|
+
const rest = tokens.filter((t) => t !== id);
|
|
321
|
+
if (rest.length > 0) el.setAttribute(attr, rest.join(' '));
|
|
322
|
+
else el.removeAttribute(attr);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* 合并写 aria-describedby:保留元素上已有、但不是上次 applyCommon 写入的令牌(控件自带的说明节点),
|
|
327
|
+
* 再并入这次的令牌;重复调用不累积。
|
|
328
|
+
*/
|
|
329
|
+
function mergeDescribedby(el: Element, next: string): void {
|
|
330
|
+
const prevOwn = new Set(APPLIED_DESCRIBEDBY.get(el) ?? []);
|
|
331
|
+
const keep = idRefTokens(el.getAttribute('aria-describedby') ?? '').filter((t) => !prevOwn.has(t));
|
|
332
|
+
const own = idRefTokens(next);
|
|
333
|
+
APPLIED_DESCRIBEDBY.set(el, own);
|
|
334
|
+
const merged = [...keep, ...own.filter((t) => !keep.includes(t))];
|
|
335
|
+
if (merged.length > 0) el.setAttribute('aria-describedby', merged.join(' '));
|
|
336
|
+
else el.removeAttribute('aria-describedby');
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* 标签关联、可访问名与程序化无障碍校验关联:`id` / `aria-label` / `aria-labelledby` / `name` / `aria-required` / `aria-invalid` / `aria-describedby`(合并)/ `aria-errormessage`。
|
|
341
|
+
* `labelledby` 只在 props 里带了该键(契约声明过)时才写 / 清,避免只传部分键的调用方误清外部写好的名字。
|
|
342
|
+
*/
|
|
290
343
|
export function applyCommon(el: Element, p: KitProps): void {
|
|
291
344
|
setAttr(el, 'id', str(p.id));
|
|
292
|
-
setAttr(el, 'aria-label', str(p.aria_label));
|
|
293
345
|
setAttr(el, 'name', str(p.name));
|
|
346
|
+
applyAria(el, p);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** applyCommon 去掉 id / name 的部分:名字、标签关联、校验态与说明关联 */
|
|
350
|
+
function applyAria(el: Element, p: KitProps): void {
|
|
351
|
+
setAttr(el, 'aria-label', str(p.aria_label));
|
|
352
|
+
if ('labelledby' in p || 'aria_labelledby' in p) setAttr(el, 'aria-labelledby', str(p.aria_labelledby, str(p.labelledby)));
|
|
353
|
+
// WAI-ARIA 1.2:aria-required / aria-invalid / aria-errormessage 不属于 role=group,写了是无效 ARIA;
|
|
354
|
+
// group 根只留名字与说明关联(+ 一个 data-kit-invalid 标记供表单滚动聚焦),校验态落到组内真正承载值的控件上(见 applyGroupA11y)
|
|
355
|
+
if (el.getAttribute('role') === 'group') {
|
|
356
|
+
el.removeAttribute('aria-required');
|
|
357
|
+
el.removeAttribute('aria-invalid');
|
|
358
|
+
el.removeAttribute('aria-errormessage');
|
|
359
|
+
setAttr(el, KIT_INVALID_MARK, bool(p.invalid) ? 'true' : '');
|
|
360
|
+
} else {
|
|
361
|
+
applyValidity(el, p);
|
|
362
|
+
el.removeAttribute(KIT_INVALID_MARK);
|
|
363
|
+
}
|
|
364
|
+
mergeDescribedby(el, str(p.aria_describedby, str(p.describedby)));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** group 根上的无效标记(ARIA 不允许 group 带 aria-invalid;表单据此找首个出错字段) */
|
|
368
|
+
export const KIT_INVALID_MARK = 'data-kit-invalid';
|
|
369
|
+
|
|
370
|
+
/** 必填 / 无效 / 错误消息关联三个校验属性(只给支持它们的角色:原生输入、radiogroup、combobox、textbox 等) */
|
|
371
|
+
function applyValidity(el: Element, p: KitProps): void {
|
|
294
372
|
if (bool(p.required)) el.setAttribute('aria-required', 'true');
|
|
295
373
|
else el.removeAttribute('aria-required');
|
|
296
374
|
if (bool(p.invalid)) el.setAttribute('aria-invalid', 'true');
|
|
297
375
|
else el.removeAttribute('aria-invalid');
|
|
298
|
-
setAttr(el, 'aria-describedby', str(p.aria_describedby, str(p.describedby)));
|
|
299
376
|
setAttr(el, 'aria-errormessage', str(p.aria_errormessage, str(p.errormessage)));
|
|
300
377
|
}
|
|
301
378
|
|
|
379
|
+
/**
|
|
380
|
+
* 组类控件(无单一可标注原生元素:radiogroup / group / 自绘组合)的校验与名字写面:
|
|
381
|
+
* 与 applyCommon 同一套 aria 属性,但不碰 id / name(组根不占 id,id 给第一个可聚焦控件)。
|
|
382
|
+
* 组根是 role=group 时(多选组、验证码格组等),必填 / 无效 / 错误消息写到 `targets`(组内承载值的输入),
|
|
383
|
+
* 说明 / 错误节点仍经 aria-describedby 挂在组根上;radiogroup 根支持这些属性,直接写根。
|
|
384
|
+
*/
|
|
385
|
+
export function applyGroupA11y(el: Element, p: KitProps, targets: Iterable<Element> = []): void {
|
|
386
|
+
applyAria(el, p);
|
|
387
|
+
if (el.getAttribute('role') !== 'group') return;
|
|
388
|
+
for (const target of targets) applyValidity(target, p);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** 表单传给字段控件的无障碍 props 键:任一有值就说明该控件被当作表单字段用 */
|
|
392
|
+
const FIELD_A11Y_KEYS = ['labelledby', 'aria_labelledby', 'describedby', 'aria_describedby', 'required', 'invalid'] as const;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* 复合字段控件(上传、取色、选记录、穿梭等:根不是原生可标注元素)的字段无障碍写面:
|
|
396
|
+
* 被当作表单字段用(props 里带了标签 / 说明 / 必填 / 无效)时根写 role=group + 名字 + 说明关联,必填 / 无效落到 `targets`;
|
|
397
|
+
* 没有这些 props 时不加角色(与单独使用时的原有输出一致),并清掉上一轮写的。
|
|
398
|
+
*/
|
|
399
|
+
export function applyCompositeField(el: Element, p: KitProps, targets: Iterable<Element> = []): void {
|
|
400
|
+
const used = FIELD_A11Y_KEYS.some((k) => { const v = p[k]; return v !== undefined && v !== null && v !== '' && v !== false; });
|
|
401
|
+
if (used) el.setAttribute('role', 'group');
|
|
402
|
+
else if (el.getAttribute('role') === 'group') el.removeAttribute('role');
|
|
403
|
+
applyGroupA11y(el, { ...p, aria_label: '' }, targets);
|
|
404
|
+
}
|
|
405
|
+
|
|
302
406
|
/** 禁用态:原生 disabled + aria-disabled 同写 */
|
|
303
407
|
export function applyDisabled(el: Element, disabled: boolean): void {
|
|
304
408
|
setBoolAttr(el, 'disabled', disabled);
|
|
@@ -354,6 +458,12 @@ export interface KitView {
|
|
|
354
458
|
* (render 里用 `kitBusyOf(p)` 取状态落到触发钮)。
|
|
355
459
|
*/
|
|
356
460
|
busyAware?: boolean;
|
|
461
|
+
/**
|
|
462
|
+
* 组件声明的数据对象取数完成(外部触发的重算,如 behavior.from 读取回来)后,core 在重渲之后调用一次;
|
|
463
|
+
* 骨架原样挂到控制器上(不包装)。需要在取数后「补画 / 回填」副作用时写在这里(重渲只让派生值重算,不会替你回填);
|
|
464
|
+
* 不要在里面改 props,需要重绘调 `api.refresh()`。抛错由 core 记录,不影响其它组件。
|
|
465
|
+
*/
|
|
466
|
+
onDataObjectsChange?(): void;
|
|
357
467
|
}
|
|
358
468
|
|
|
359
469
|
export type KitViewSetup = (api: KitApi) => KitView;
|
|
@@ -398,6 +508,15 @@ function guardAsyncServices(
|
|
|
398
508
|
return { ...services, engines: wrappedEngines };
|
|
399
509
|
}
|
|
400
510
|
|
|
511
|
+
/**
|
|
512
|
+
* 控制器挂载钩子:每个 kit 组件实例挂载时按宿主元素各调一次(钩子自己保证幂等)。
|
|
513
|
+
* 给「每页只需装一次」的文档级装置用(按需提示的事件委托,见 hint-tips.ts);这里不 import 它们,避免 shared ↔ reason-tip 循环依赖。
|
|
514
|
+
*/
|
|
515
|
+
const MOUNT_HOOKS = new Set<(host: HTMLElement) => void>();
|
|
516
|
+
export function onKitControllerMount(hook: (host: HTMLElement) => void): void {
|
|
517
|
+
MOUNT_HOOKS.add(hook);
|
|
518
|
+
}
|
|
519
|
+
|
|
401
520
|
/**
|
|
402
521
|
* 控制器骨架:每个实例调用一次 setup(api),闭包即实例状态;
|
|
403
522
|
* onMount 取根、挂事件并首绘,onPropsChange 全量重绘,onUnmount 统一执行清理函数。
|
|
@@ -465,6 +584,7 @@ export function createKitController(setup: KitViewSetup | KitView): SomaComponen
|
|
|
465
584
|
onMount(): void {
|
|
466
585
|
alive = true;
|
|
467
586
|
root = findRoot(ctx.host);
|
|
587
|
+
for (const hook of MOUNT_HOOKS) hook(ctx.host);
|
|
468
588
|
offPerm = registerLivePermissionGate(applyPerm);
|
|
469
589
|
cleanup = view.attach?.(root, api);
|
|
470
590
|
paint();
|
|
@@ -588,6 +708,7 @@ export const CLASS_PROP = {
|
|
|
588
708
|
export const ID_PROPS = {
|
|
589
709
|
id: { type: 'string', default: '', desc: '根控件 id,供 label for 关联' },
|
|
590
710
|
aria_label: { type: 'string', default: '', desc: '无可见标签时的可访问名' },
|
|
711
|
+
labelledby: { type: 'string', default: '', desc: '可见标签元素 id(写 aria-labelledby;非原生可标注控件靠它得到可访问名,表单自动传入)' },
|
|
591
712
|
name: { type: 'string', default: '', desc: '表单字段名' },
|
|
592
713
|
} as const;
|
|
593
714
|
|
|
@@ -629,6 +750,8 @@ export interface KitTablistOptions {
|
|
|
629
750
|
orientation?: 'horizontal' | 'vertical';
|
|
630
751
|
/** 选中变化(点击 / 键盘 / select())后回调;silent 的 select 不回调 */
|
|
631
752
|
onSelect?: (id: string, tab: HTMLElement) => void;
|
|
753
|
+
/** 面板切换时用页面过渡(View Transitions,仅内容区参与;不支持 / 减弱动效时直切)。缺省 false;只对真正换了选中项的 select 生效 */
|
|
754
|
+
viewTransition?: boolean;
|
|
632
755
|
}
|
|
633
756
|
|
|
634
757
|
export interface KitTablistHandle {
|
|
@@ -720,15 +843,20 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
|
|
|
720
843
|
const tab = byId(id);
|
|
721
844
|
if (!tab || isDisabled(tab)) return;
|
|
722
845
|
const changed = current !== id;
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
846
|
+
const run = (): void => {
|
|
847
|
+
const sLeft = root.scrollLeft;
|
|
848
|
+
const sTop = root.scrollTop;
|
|
849
|
+
current = id;
|
|
850
|
+
cursor = id;
|
|
851
|
+
paint();
|
|
852
|
+
if (o.focus === true) tab.focus({ preventScroll: true });
|
|
853
|
+
root.scrollLeft = sLeft;
|
|
854
|
+
root.scrollTop = sTop;
|
|
855
|
+
if (changed && o.silent !== true) opts.onSelect?.(id, tab);
|
|
856
|
+
};
|
|
857
|
+
// 过渡路径下 run 由浏览器在下一帧调用;选中状态与回调都在 run 里一起落,顺序与直切一致
|
|
858
|
+
if (changed && opts.viewTransition === true) withKitViewTransition(run);
|
|
859
|
+
else run();
|
|
732
860
|
};
|
|
733
861
|
|
|
734
862
|
const reset = (): void => {
|
|
@@ -838,21 +966,34 @@ export function withTooltip(viewOrSetup: KitView | KitViewSetup, targetOf: (root
|
|
|
838
966
|
function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLElement = (r) => r): KitView {
|
|
839
967
|
// 视图对象在同一组件定义的所有实例间共享,逐实例状态按根元素存
|
|
840
968
|
// bound / rebind:目标可随渲染变化(如 MenuButton split 时目标由箭头钮换成主钮),监听跟着目标走
|
|
841
|
-
interface TipState { tip: HTMLElement | null; shown: boolean; bound: HTMLElement | null; rebind: ((t: HTMLElement) => void) | null }
|
|
969
|
+
interface TipState { tip: HTMLElement | null; shown: boolean; bound: HTMLElement | null; rebind: ((t: HTMLElement) => void) | null; leave: KitLeaveHandle | null }
|
|
842
970
|
const states = new WeakMap<HTMLElement, TipState>();
|
|
843
971
|
const stateOf = (root: HTMLElement): TipState => {
|
|
844
972
|
let s = states.get(root);
|
|
845
973
|
if (!s) {
|
|
846
|
-
s = { tip: null, shown: false, bound: null, rebind: null };
|
|
974
|
+
s = { tip: null, shown: false, bound: null, rebind: null, leave: null };
|
|
847
975
|
states.set(root, s);
|
|
848
976
|
}
|
|
849
977
|
return s;
|
|
850
978
|
};
|
|
851
979
|
const paintTip = (s: TipState): void => {
|
|
852
|
-
|
|
980
|
+
const tip = s.tip;
|
|
981
|
+
if (tip === null) return;
|
|
853
982
|
// 显示时量一次可用空间,贴边则在闭集位置类间翻转(popup.ts);隐藏只换整串类
|
|
854
|
-
if (s.shown)
|
|
855
|
-
|
|
983
|
+
if (s.shown) {
|
|
984
|
+
// 退场中被重新唤起:撤销退场再落位
|
|
985
|
+
s.leave?.cancel();
|
|
986
|
+
s.leave = null;
|
|
987
|
+
showPopupFitted(tip, tip.parentElement ?? tip, POPUP_TIP_PREF, popupTipClass);
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
if (tip.className === TOOLTIP_HIDDEN_CLASS || s.leave !== null) return;
|
|
991
|
+
// 出场:与其他锚定浮层同一机制(隐藏前过渡,anchored-layer 的 leaveAnchored);没有退场动画则立即收尾
|
|
992
|
+
s.leave = leaveAnchored(tip, () => {
|
|
993
|
+
s.leave = null;
|
|
994
|
+
tip.className = TOOLTIP_HIDDEN_CLASS;
|
|
995
|
+
unmarkAnchored(tip);
|
|
996
|
+
});
|
|
856
997
|
};
|
|
857
998
|
|
|
858
999
|
return {
|
|
@@ -884,7 +1025,7 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
|
|
|
884
1025
|
};
|
|
885
1026
|
const bind = (t: HTMLElement): void => {
|
|
886
1027
|
if (s.bound === t) return;
|
|
887
|
-
if (s.bound !== null && s.tip !== null
|
|
1028
|
+
if (s.bound !== null && s.tip !== null) removeIdToken(s.bound, 'aria-describedby', s.tip.id);
|
|
888
1029
|
unbind();
|
|
889
1030
|
t.addEventListener('mouseenter', show);
|
|
890
1031
|
t.addEventListener('mouseleave', hide);
|
|
@@ -899,6 +1040,8 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
|
|
|
899
1040
|
return () => {
|
|
900
1041
|
unbind();
|
|
901
1042
|
s.rebind = null;
|
|
1043
|
+
s.leave?.cancel();
|
|
1044
|
+
s.leave = null;
|
|
902
1045
|
if (s.tip) s.tip.remove();
|
|
903
1046
|
s.tip = null;
|
|
904
1047
|
s.shown = false;
|
|
@@ -913,7 +1056,7 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
|
|
|
913
1056
|
const text = str(p.tooltip);
|
|
914
1057
|
if (text === '') {
|
|
915
1058
|
if (s.tip) {
|
|
916
|
-
|
|
1059
|
+
removeIdToken(target, 'aria-describedby', s.tip.id);
|
|
917
1060
|
s.tip.remove();
|
|
918
1061
|
s.tip = null;
|
|
919
1062
|
}
|
|
@@ -927,7 +1070,7 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
|
|
|
927
1070
|
}
|
|
928
1071
|
s.tip.textContent = text;
|
|
929
1072
|
if (s.tip.parentNode !== target) target.appendChild(s.tip);
|
|
930
|
-
target
|
|
1073
|
+
addIdToken(target, 'aria-describedby', s.tip.id);
|
|
931
1074
|
const cls = target.className;
|
|
932
1075
|
if (!/(^|\s)(relative|absolute|fixed|sticky)(\s|$)/.test(cls)) {
|
|
933
1076
|
target.className = cls === '' ? TOOLTIP_ANCHOR_CLASS : `${cls} ${TOOLTIP_ANCHOR_CLASS}`;
|
|
@@ -941,3 +1084,4 @@ function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLEle
|
|
|
941
1084
|
|
|
942
1085
|
export * from '../recipes';
|
|
943
1086
|
export * from './loading-gate';
|
|
1087
|
+
export { withKitViewTransition, canKitViewTransition } from './view-transition';
|