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/action-busy.ts
CHANGED
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
// 进行中时禁用触发钮、挂 aria-busy、忽略重复点击;动作结束自动恢复。宿主也可以直接给 `busy: true`。
|
|
7
7
|
// 计数而不是布尔:同名动作并发时,全部结束才算闲。无动作在跑时所有查询都是 false,没有订阅者也无副作用。
|
|
8
8
|
|
|
9
|
+
import {
|
|
10
|
+
KIT_LOADING_GATE_DEFAULTS, LOADING_FEEDBACK_IDLE, stepLoadingFeedback,
|
|
11
|
+
type LoadingFeedbackConfig, type LoadingFeedbackState,
|
|
12
|
+
} from './loading-gate';
|
|
13
|
+
import { KIT_LOADING_HELD_ATTR } from '../recipes/placeholder';
|
|
14
|
+
|
|
9
15
|
const counts = new Map<string, number>();
|
|
10
16
|
const subs = new Set<() => void>();
|
|
11
17
|
|
|
@@ -117,25 +123,115 @@ export interface KitBusyBinding {
|
|
|
117
123
|
paint(btn: HTMLElement | null, otherDisabled?: boolean): void;
|
|
118
124
|
}
|
|
119
125
|
|
|
126
|
+
// ---------------------------------------------------------------- 按钮忙碌态的视觉指示
|
|
127
|
+
// 忙时按钮内叠一个居中的转圈(绝对定位盖在按钮上、原内容 visibility:hidden 占位,所以按钮宽高不跳动);
|
|
128
|
+
// 时序与三态面板同一台状态机(loading-gate 的 stepLoadingFeedback,真源 structure.loadingFeedback):
|
|
129
|
+
// 延迟出现(delayMs 内完成则全程不出转圈,语义上的 disabled / aria-busy 仍即时)、出现后至少显示 minVisibleMs(期满前保持忙碌外观)。
|
|
130
|
+
// 位置与隐藏原内容的规则在主题结构(kit-theme.tpl 的「按钮忙碌态」块,认 [data-kit-busy-spin])。
|
|
131
|
+
|
|
132
|
+
/** 转圈的属性标记(样式只认它) */
|
|
133
|
+
export const KIT_BUSY_SPIN_ATTR = 'data-kit-busy-spin';
|
|
134
|
+
const BUSY_SPIN_CLASS = 'absolute inset-0 flex items-center justify-center';
|
|
135
|
+
const BUSY_SPIN_DOT_CLASS = 'inline-block h-4 w-4 motion-safe:animate-spin rounded-full border-2 border-border border-t-primary';
|
|
136
|
+
|
|
137
|
+
/** 转圈用到的类(供候选类清单) */
|
|
138
|
+
export const KIT_BUSY_SPIN_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
139
|
+
[...new Set(`${BUSY_SPIN_CLASS} ${BUSY_SPIN_DOT_CLASS}`.split(/\s+/))],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const BUSY_CFG: LoadingFeedbackConfig = Object.freeze({
|
|
143
|
+
delayMs: KIT_LOADING_GATE_DEFAULTS.delayMs,
|
|
144
|
+
minVisibleMs: KIT_LOADING_GATE_DEFAULTS.minDurationMs,
|
|
145
|
+
doneHoldMs: KIT_LOADING_GATE_DEFAULTS.doneHoldMs,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 在按钮上放 / 摘转圈(幂等);held = 已过首次延迟(状态机不在 pending-delay),转圈与被遮内容立即切换(只在新建时标,已存在的不重置延迟)。
|
|
150
|
+
* 忙碌开始时刻存在组件控制器的门状态里(createKitBusy 的 gate,跨全量 render 存活):按钮被重建时,已过 delayMs 则直接标 held;
|
|
151
|
+
* 延迟期内重建只得到「满延迟」一档(不按剩余毫秒算),但门状态不重置,所以越过 delayMs 后的第一次重画即 held,不会被连续刷新无限推迟。
|
|
152
|
+
* 延迟值 --kit-loading-delay 由结构 CSS 写出(读真源 structure.loadingFeedback.delayMs;标记 data-kit-loading-held 取 heldDelayMs,真源值 0),这里不写运行期样式。
|
|
153
|
+
*/
|
|
154
|
+
function setBusySpin(btn: HTMLElement, on: boolean, held: boolean): void {
|
|
155
|
+
let spin: HTMLElement | null = null;
|
|
156
|
+
for (const c of Array.from(btn.children)) {
|
|
157
|
+
if (c.hasAttribute(KIT_BUSY_SPIN_ATTR)) { spin = c as HTMLElement; break; }
|
|
158
|
+
}
|
|
159
|
+
if (!on) {
|
|
160
|
+
spin?.remove();
|
|
161
|
+
btn.removeAttribute(KIT_LOADING_HELD_ATTR);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (spin !== null) return;
|
|
165
|
+
const doc = btn.ownerDocument;
|
|
166
|
+
spin = doc.createElement('span');
|
|
167
|
+
spin.setAttribute(KIT_BUSY_SPIN_ATTR, '');
|
|
168
|
+
spin.setAttribute('aria-hidden', 'true');
|
|
169
|
+
spin.className = BUSY_SPIN_CLASS;
|
|
170
|
+
// 延迟变量在按钮上(转圈与被遮住的原内容共用同一个延迟:转圈出现的同一刻原内容才让位);已过首次延迟则打标记取 0ms
|
|
171
|
+
if (held) btn.setAttribute(KIT_LOADING_HELD_ATTR, '');
|
|
172
|
+
else btn.removeAttribute(KIT_LOADING_HELD_ATTR);
|
|
173
|
+
const dot = doc.createElement('span');
|
|
174
|
+
dot.className = BUSY_SPIN_DOT_CLASS;
|
|
175
|
+
spin.appendChild(dot);
|
|
176
|
+
btn.appendChild(spin);
|
|
177
|
+
}
|
|
178
|
+
|
|
120
179
|
/** 组件的忙闲绑定:getProps 取最新 props(含宿主给的 busy / busy_action) */
|
|
121
180
|
export function createKitBusy(getProps: () => Record<string, unknown>): KitBusyBinding {
|
|
122
181
|
let off: (() => void) | null = null;
|
|
182
|
+
let repaintFn: (() => void) | null = null;
|
|
183
|
+
let gate: LoadingFeedbackState = LOADING_FEEDBACK_IDLE;
|
|
184
|
+
let holdTimer: ReturnType<typeof setTimeout> | undefined;
|
|
185
|
+
const clearHold = (): void => {
|
|
186
|
+
if (holdTimer !== undefined) {
|
|
187
|
+
clearTimeout(holdTimer);
|
|
188
|
+
holdTimer = undefined;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
123
191
|
const busy = (): boolean => kitBusyOf(getProps());
|
|
124
192
|
return {
|
|
125
193
|
busy,
|
|
126
194
|
subscribe(repaint) {
|
|
127
195
|
off?.();
|
|
196
|
+
repaintFn = repaint;
|
|
128
197
|
off = onKitActionBusy(repaint);
|
|
129
198
|
},
|
|
130
199
|
dispose() {
|
|
131
200
|
off?.();
|
|
132
201
|
off = null;
|
|
202
|
+
repaintFn = null;
|
|
203
|
+
clearHold();
|
|
204
|
+
gate = LOADING_FEEDBACK_IDLE;
|
|
133
205
|
},
|
|
134
206
|
paint(btn, otherDisabled = false) {
|
|
135
207
|
if (btn === null) return;
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
208
|
+
const raw = busy();
|
|
209
|
+
const now = Date.now();
|
|
210
|
+
let wakeAt: number | null = null;
|
|
211
|
+
if (raw) {
|
|
212
|
+
// 一轮忙只起一次计时(重复重绘不重置延迟起点);上一轮已收尾才重新开始
|
|
213
|
+
const startNew = gate.phase === 'idle' || gate.phase === 'done' || gate.finishing;
|
|
214
|
+
const step = stepLoadingFeedback(gate, { type: startNew ? 'start' : 'tick' }, now, BUSY_CFG);
|
|
215
|
+
gate = step.state;
|
|
216
|
+
} else if (gate.phase !== 'idle') {
|
|
217
|
+
const step = stepLoadingFeedback(gate, { type: 'finish' }, now, BUSY_CFG);
|
|
218
|
+
gate = step.state;
|
|
219
|
+
wakeAt = step.wakeAt;
|
|
220
|
+
}
|
|
221
|
+
// 最短显示:转圈已出现但不足最短时长就结束了 -> 继续保持忙碌外观,期满后重绘
|
|
222
|
+
const holding = !raw && gate.phase === 'visible';
|
|
223
|
+
const showBusy = raw || holding;
|
|
224
|
+
clearHold();
|
|
225
|
+
if (holding && wakeAt !== null && repaintFn !== null) {
|
|
226
|
+
const fn = repaintFn;
|
|
227
|
+
holdTimer = setTimeout(() => {
|
|
228
|
+
holdTimer = undefined;
|
|
229
|
+
fn();
|
|
230
|
+
}, Math.max(0, wakeAt - now));
|
|
231
|
+
}
|
|
232
|
+
(btn as HTMLButtonElement).disabled = otherDisabled || showBusy;
|
|
233
|
+
if (showBusy) btn.setAttribute('aria-busy', 'true'); else btn.removeAttribute('aria-busy');
|
|
234
|
+
setBusySpin(btn, showBusy, gate.phase !== 'pending-delay');
|
|
139
235
|
},
|
|
140
236
|
};
|
|
141
237
|
}
|
|
@@ -153,7 +249,8 @@ export function busyActionOf(component: string, on: Readonly<Record<string, stri
|
|
|
153
249
|
if (!Object.prototype.hasOwnProperty.call(on, ev)) continue;
|
|
154
250
|
const v = on[ev]!;
|
|
155
251
|
const name = typeof v === 'string' ? v : v.action;
|
|
156
|
-
|
|
252
|
+
// view.<方法> 是展示对象方法(忙闲由展示对象自己的成员给,如 props: { busy: view.busy }),不是具名动作
|
|
253
|
+
if (!builtin.has(name) && !name.startsWith('view.') && !names.includes(name)) names.push(name);
|
|
157
254
|
}
|
|
158
255
|
return names.length > 0 ? names.join(',') : null;
|
|
159
256
|
}
|
package/src/base/action-slots.ts
CHANGED
|
@@ -13,6 +13,12 @@ const G = (KIT_GRAMMAR_RUNTIME as unknown as { actionSlots: { events: Record<'ro
|
|
|
13
13
|
/** 一个组件最多可绑的动作数(数字真源:design 的 kit-limits#formLinkage.actionSlots.max) */
|
|
14
14
|
export const KIT_ACTION_SLOT_MAX: number = (KIT_FORM_LINKAGE_LIMITS as unknown as { actionSlots: { max: number } }).actionSlots.max;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* 选中项变化后可各自重取的依赖对象数上限(联动枢纽的 picked_<序号> 分发槽位;数字真源:kit-limits#formLinkage.pickSlots.max)。
|
|
18
|
+
* 与动作槽位分开计:它数的是「主从工作台挂了多少个依赖面板」,不是按钮数,面板多的工作台不该被按钮上限卡住。
|
|
19
|
+
*/
|
|
20
|
+
export const KIT_PICK_SLOT_MAX: number = (KIT_FORM_LINKAGE_LIMITS as unknown as { pickSlots: { max: number } }).pickSlots.max;
|
|
21
|
+
|
|
16
22
|
/** 各类多动作事件的基名(语法真源 actionSlots.events) */
|
|
17
23
|
export const KIT_ACTION_SLOT_BASE = G.events;
|
|
18
24
|
|
|
@@ -23,10 +29,10 @@ export function actionSlotEvent(base: string, index: number): string {
|
|
|
23
29
|
|
|
24
30
|
/** 契约 emits 里的槽位事件表(max 个),调用方展开进自己的 emits */
|
|
25
31
|
export function actionSlotEmits(
|
|
26
|
-
base: string, payload: Record<string, { type: string; desc?: string }>, desc: string,
|
|
32
|
+
base: string, payload: Record<string, { type: string; desc?: string }>, desc: string, max: number = KIT_ACTION_SLOT_MAX,
|
|
27
33
|
): Record<string, { payload: Record<string, { type: string; desc?: string }>; desc: string }> {
|
|
28
34
|
const out: Record<string, { payload: Record<string, { type: string; desc?: string }>; desc: string }> = {};
|
|
29
|
-
for (let i = 0; i <
|
|
35
|
+
for (let i = 0; i < max; i += 1) out[actionSlotEvent(base, i)] = { payload, desc: `${desc}(第 ${i + 1} 个动作的槽位事件)` };
|
|
30
36
|
return out;
|
|
31
37
|
}
|
|
32
38
|
|
|
@@ -40,6 +46,11 @@ export function actionSlotOverflow(count: number, what: string): string | null {
|
|
|
40
46
|
return count > KIT_ACTION_SLOT_MAX ? `${what}有 ${count} 个动作,超过单个组件可绑的上限 ${KIT_ACTION_SLOT_MAX}` : null;
|
|
41
47
|
}
|
|
42
48
|
|
|
49
|
+
/** 编译期:选中项要重取的依赖对象数超过上限时返回提示文案,否则 null */
|
|
50
|
+
export function pickSlotOverflow(count: number): string | null {
|
|
51
|
+
return count > KIT_PICK_SLOT_MAX ? `选中项变化后要重取的依赖对象有 ${count} 个,超过一个联动枢纽可分发的上限 ${KIT_PICK_SLOT_MAX}(把面板拆到多个页面,或合并只读面板的数据来源)` : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
/** 动作 id 在组件 actions 数组(元素带 id)里的槽位序号;找不到 -1 */
|
|
44
55
|
export function actionSlotIndex(items: unknown, id: string): number {
|
|
45
56
|
if (!Array.isArray(items)) return -1;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// 锚定浮层的统一构件(美化方案 G):无遮罩、锚定触发点、空间不足自动翻转的小浮层——提示、菜单、表头筛选面板、选择器下拉、日期面板、气泡。
|
|
2
|
+
//
|
|
3
|
+
// 一份实现,分三处:
|
|
4
|
+
// - 定位与翻转:popup.ts 的 resolvePopPlace / resolveDropdown(纯函数,贴边翻转与对齐翻转)+ portal-core 的 createPanelPortalWith(挂浮层根、
|
|
5
|
+
// 锚盒跟随触发点、随滚动与尺寸变化重定位);
|
|
6
|
+
// - 标记(本文件):面板根标 data-kit-anchored 与 data-kit-placement="top|bottom|start|end"(落位后的实际方向,翻转 / 重定位后随之更新)。
|
|
7
|
+
// 样式只认这两个属性(nine-dim-structure 的「载体与布局构件」规则(carrierRules)):进场 120ms / 出场 80ms(motion.json 的 popover 意图令牌),从锚点方向小位移 + 缩放 + 淡入,
|
|
8
|
+
// 减弱动效只淡入淡出;表面(浮起面 + 高光边 + 双层阴影)读 --soma-surface-raised / --soma-edge-highlight / --soma-elevation-raised;
|
|
9
|
+
// - 出场(本文件的 leaveAnchored):复用 overlay-runtime 的隐藏前过渡机制(beginKitLeave:标 data-kit-leaving + inert,等退场动画结束再收尾,
|
|
10
|
+
// 带超时兜底,没有退场动画则立即收尾)。
|
|
11
|
+
// 层栈与焦点域仍各有唯一裁决者:Esc 只关栈顶由 core 浮层挂载点登记的层栈裁决,焦点隔离 / 回焦归各组件的 focus-scope;本文件不另立。
|
|
12
|
+
// 不引入浏览器内置 Popover API。
|
|
13
|
+
|
|
14
|
+
import { beginKitLeave, type KitLeaveHandle } from './overlay-runtime';
|
|
15
|
+
|
|
16
|
+
/** 锚定浮层根标记(无遮罩的锚定面板) */
|
|
17
|
+
export const KIT_ANCHORED_ATTR = 'data-kit-anchored';
|
|
18
|
+
/** 落位后的实际方向:面板在锚点的哪一侧 */
|
|
19
|
+
export const KIT_PLACEMENT_ATTR = 'data-kit-placement';
|
|
20
|
+
|
|
21
|
+
export type KitPlacement = 'top' | 'bottom' | 'start' | 'end';
|
|
22
|
+
const PLACEMENTS: readonly KitPlacement[] = ['top', 'bottom', 'start', 'end'];
|
|
23
|
+
|
|
24
|
+
/** 纯函数:任意值 -> 合法方向(非法回落 bottom) */
|
|
25
|
+
export function placementSideOf(raw: unknown): KitPlacement {
|
|
26
|
+
return PLACEMENTS.includes(raw as KitPlacement) ? (raw as KitPlacement) : 'bottom';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 给面板打锚定浮层标记(幂等;每次落位 / 翻转后重复调用即更新方向) */
|
|
30
|
+
export function markAnchored(panel: HTMLElement, place: { side: string }): void {
|
|
31
|
+
const side = placementSideOf(place.side);
|
|
32
|
+
if (!panel.hasAttribute(KIT_ANCHORED_ATTR)) panel.setAttribute(KIT_ANCHORED_ATTR, '');
|
|
33
|
+
if (panel.getAttribute(KIT_PLACEMENT_ATTR) !== side) panel.setAttribute(KIT_PLACEMENT_ATTR, side);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 摘掉标记(面板收起后不再是锚定浮层) */
|
|
37
|
+
export function unmarkAnchored(panel: HTMLElement): void {
|
|
38
|
+
panel.removeAttribute(KIT_ANCHORED_ATTR);
|
|
39
|
+
panel.removeAttribute(KIT_PLACEMENT_ATTR);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 出场:有退场动画就先播完再调 done,没有(无关键帧 / jsdom / 无窗口)立即调 done。
|
|
44
|
+
* 返回句柄:退场中被重新打开时调 cancel(撤销退场状态,不调 done);立即收尾时返回 null。
|
|
45
|
+
*/
|
|
46
|
+
export function leaveAnchored(panel: HTMLElement, done: () => void): KitLeaveHandle | null {
|
|
47
|
+
const handle = beginKitLeave(panel, done);
|
|
48
|
+
if (handle === null) done();
|
|
49
|
+
return handle;
|
|
50
|
+
}
|
package/src/base/button.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
5
5
|
import {
|
|
6
6
|
CLASS_PROP, ID_PROPS, SIZE_PROP, TOOLTIP_PROP, BADGE_PROPS, KIT_BADGE_CLASS_CANDIDATES, KIT_SPINNER_CLASS,
|
|
7
|
-
applyCommon, bool, classCandidates, createKitController, joinClass, paintBadge, setAttr, sizeOf, str, withBadgeAnchor, withTooltip, type KitSize,
|
|
7
|
+
applyCommon, bool, classCandidates, createKitController, joinClass, paintBadge, setAttr, sizeOf, str, withBadgeAnchor, withTooltip, type KitSize, type KitView,
|
|
8
8
|
} from './shared';
|
|
9
9
|
import {
|
|
10
10
|
KIT_PART_ATTRIBUTE,
|
|
@@ -14,8 +14,12 @@ import {
|
|
|
14
14
|
kitControlPartOf,
|
|
15
15
|
kitControlRecipe,
|
|
16
16
|
kitSelectedRecipe,
|
|
17
|
+
kitDisabledRecipe,
|
|
17
18
|
setKitFace,
|
|
18
19
|
} from '../recipes';
|
|
20
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
21
|
+
import { KIT_REASON_TIP_CLASS_CANDIDATES, releaseReasonTip, syncReasonTip } from './reason-tip';
|
|
22
|
+
import { KIT_BUSY_SPIN_ATTR, KIT_BUSY_SPIN_CLASS_CANDIDATES } from './action-busy';
|
|
19
23
|
|
|
20
24
|
export {
|
|
21
25
|
KIT_PART_BUTTON,
|
|
@@ -40,10 +44,11 @@ export const BUTTON_CLASS: Record<ButtonVariant, Record<KitSize, string>> = {
|
|
|
40
44
|
md: kitControlRecipe({ variant: 'primary', size: 'md' }),
|
|
41
45
|
lg: kitControlRecipe({ variant: 'primary', size: 'lg' }),
|
|
42
46
|
},
|
|
47
|
+
// neutral = 次级动作:按强调等级取色调按钮(品牌浅色填充,无描边线框;R01),不再是灰描边
|
|
43
48
|
neutral: {
|
|
44
|
-
sm:
|
|
45
|
-
md:
|
|
46
|
-
lg:
|
|
49
|
+
sm: kitEmphasisButtonRecipe('button.toolbar', { size: 'sm' }),
|
|
50
|
+
md: kitEmphasisButtonRecipe('button.toolbar', { size: 'md' }),
|
|
51
|
+
lg: kitEmphasisButtonRecipe('button.toolbar', { size: 'lg' }),
|
|
47
52
|
},
|
|
48
53
|
danger: {
|
|
49
54
|
sm: kitControlRecipe({ variant: 'danger', size: 'sm' }),
|
|
@@ -57,16 +62,23 @@ export const BUTTON_CLASS: Record<ButtonVariant, Record<KitSize, string>> = {
|
|
|
57
62
|
},
|
|
58
63
|
};
|
|
59
64
|
|
|
65
|
+
const SPINNER_WRAP_CLASS = 'absolute inset-0 flex items-center justify-center';
|
|
60
66
|
const SPINNER_CLASS = KIT_SPINNER_CLASS;
|
|
61
67
|
|
|
62
68
|
// icon_only:宽度等于高度,文字藏起来只留符号(横向内边距被 border-box 的定宽吃掉,符号居中溢出)
|
|
63
69
|
const ICON_ONLY_WIDTH: Record<KitSize, string> = { sm: 'w-8', md: 'w-9', lg: 'w-10' };
|
|
64
70
|
|
|
65
71
|
export const KIT_BUTTON_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
66
|
-
Object.values(BUTTON_CLASS).flatMap((m) => Object.values(m)), Object.values(ICON_ONLY_WIDTH),
|
|
67
|
-
|
|
72
|
+
Object.values(BUTTON_CLASS).flatMap((m) => Object.values(m)), Object.values(ICON_ONLY_WIDTH), SPINNER_WRAP_CLASS, SPINNER_CLASS,
|
|
73
|
+
KIT_BUSY_SPIN_CLASS_CANDIDATES, 'hidden', 'inline-block', 'relative',
|
|
74
|
+
KIT_BADGE_CLASS_CANDIDATES, KIT_REASON_TIP_CLASS_CANDIDATES, kitDisabledRecipe('aria'),
|
|
68
75
|
);
|
|
69
76
|
|
|
77
|
+
/** 带原因的置灰:disabled 为真、不在加载中、原因非空——此时只留 aria-disabled(可聚焦),原因走气泡 */
|
|
78
|
+
function reasonOf(p: Record<string, unknown>): string {
|
|
79
|
+
return bool(p.disabled) && !bool(p.loading) ? str(p.disabled_reason).trim() : '';
|
|
80
|
+
}
|
|
81
|
+
|
|
70
82
|
function variantOf(raw: unknown): ButtonVariant {
|
|
71
83
|
return raw === 'neutral' || raw === 'danger' || raw === 'ghost' || raw === 'tonal' ? raw : 'primary';
|
|
72
84
|
}
|
|
@@ -84,6 +96,7 @@ export function createButton(): SomaComponentDefinition {
|
|
|
84
96
|
...BADGE_PROPS,
|
|
85
97
|
loading: { type: 'boolean', default: false, desc: '加载中:显示转圈,不响应点击' },
|
|
86
98
|
disabled: { type: 'boolean', default: false },
|
|
99
|
+
disabled_reason: { type: 'string', default: '', desc: '置灰原因文案:disabled 为真且非空时,按钮不用原生 disabled(只留 aria-disabled,保持可聚焦),原因经气泡在悬停 / 聚焦时显示(aria-describedby,Esc 隐藏);点击 / Enter / Space 仍不抛 click;disabled 为假或为空串时与没写一样' },
|
|
87
100
|
type: { type: 'enum', values: ['button', 'submit', 'reset'], default: 'button', desc: '原生按钮类型' },
|
|
88
101
|
tooltip: TOOLTIP_PROP,
|
|
89
102
|
permission: { type: 'string', default: '', desc: '权限码;非空且当前身份无此权限时整个按钮不渲染(点击拦截另在事件管道尾段)' },
|
|
@@ -96,8 +109,8 @@ export function createButton(): SomaComponentDefinition {
|
|
|
96
109
|
},
|
|
97
110
|
},
|
|
98
111
|
services: ['permission'],
|
|
99
|
-
templateHtml: `<button data-soma-id="root" data-kit-part="${KIT_PART_BUTTON}" type="button" class="${BUTTON_CLASS.primary.md}"><span data-soma-id="spin" aria-hidden="true" class="hidden"></span><span data-soma-id="icon" aria-hidden="true" class="hidden"></span><span data-soma-id="label"></span></button>`,
|
|
100
|
-
controllerFactory: createKitController(() => withTooltip({
|
|
112
|
+
templateHtml: `<button data-soma-id="root" data-kit-part="${KIT_PART_BUTTON}" type="button" class="${BUTTON_CLASS.primary.md}"><span data-soma-id="spin" aria-hidden="true" class="hidden"><span class="${SPINNER_CLASS}"></span></span><span data-soma-id="icon" aria-hidden="true" class="hidden"></span><span data-soma-id="label"></span></button>`,
|
|
113
|
+
controllerFactory: createKitController(() => withReasonTip(withTooltip({
|
|
101
114
|
attach(root, api) {
|
|
102
115
|
const onClick = (event: Event): void => {
|
|
103
116
|
const p = api.props();
|
|
@@ -115,8 +128,11 @@ export function createButton(): SomaComponentDefinition {
|
|
|
115
128
|
const off = bool(p.disabled) || loading;
|
|
116
129
|
const type = str(p.type, 'button');
|
|
117
130
|
root.setAttribute('type', type === 'submit' || type === 'reset' ? type : 'button');
|
|
131
|
+
const reason = reasonOf(p);
|
|
118
132
|
if (off) {
|
|
119
|
-
|
|
133
|
+
// 带原因:不用原生 disabled(原生禁用的按钮拿不到焦点,读屏 / 键盘用户读不到原因),点击由 onClick 的 disabled 判断拦下
|
|
134
|
+
if (reason === '') root.setAttribute('disabled', '');
|
|
135
|
+
else root.removeAttribute('disabled');
|
|
120
136
|
root.setAttribute('aria-disabled', 'true');
|
|
121
137
|
} else {
|
|
122
138
|
root.removeAttribute('disabled');
|
|
@@ -129,18 +145,24 @@ export function createButton(): SomaComponentDefinition {
|
|
|
129
145
|
applyCommon(root, iconOnly && str(p.aria_label) === '' ? { ...p, aria_label: str(p.label) } : p);
|
|
130
146
|
const [spin, icon, label] = Array.from(root.children) as HTMLElement[];
|
|
131
147
|
if (spin) {
|
|
132
|
-
|
|
148
|
+
if (loading) {
|
|
149
|
+
spin.setAttribute(KIT_BUSY_SPIN_ATTR, '');
|
|
150
|
+
spin.className = SPINNER_WRAP_CLASS;
|
|
151
|
+
} else {
|
|
152
|
+
spin.removeAttribute(KIT_BUSY_SPIN_ATTR);
|
|
153
|
+
spin.className = 'hidden';
|
|
154
|
+
}
|
|
133
155
|
}
|
|
134
156
|
if (icon) {
|
|
135
157
|
const glyph = str(p.icon);
|
|
136
158
|
icon.textContent = glyph;
|
|
137
|
-
icon.className = glyph !== ''
|
|
159
|
+
icon.className = glyph !== '' ? 'inline-block' : 'hidden';
|
|
138
160
|
}
|
|
139
161
|
if (label) {
|
|
140
162
|
label.textContent = str(p.label);
|
|
163
|
+
// 加载态不在这里藏文字:转圈出现时的原内容遮盖只有一个来源(kit-theme 的 kit-busy-conceal,opacity 过渡,保留无障碍名称与宽度)
|
|
141
164
|
label.className = iconOnly ? 'hidden' : '';
|
|
142
165
|
}
|
|
143
|
-
if (icon && iconOnly) icon.className = str(p.icon) !== '' && !loading ? 'inline-block' : 'hidden';
|
|
144
166
|
setAttr(root, 'title', '');
|
|
145
167
|
const hasBadge = paintBadge(root, p);
|
|
146
168
|
const size = sizeOf(p.size);
|
|
@@ -148,9 +170,34 @@ export function createButton(): SomaComponentDefinition {
|
|
|
148
170
|
root.setAttribute(KIT_PART_ATTRIBUTE, kitControlPartOf({ variant, size }));
|
|
149
171
|
// 质感标记:ghost 无底无边(没有「面」),不标;其余变体有实心 / 描边 / 浅底,标 raised
|
|
150
172
|
setKitFace(root, variant === 'ghost' ? null : 'raised');
|
|
151
|
-
const
|
|
152
|
-
|
|
173
|
+
const base = iconOnly ? `${BUTTON_CLASS[variant][size]} ${ICON_ONLY_WIDTH[size]}` : BUTTON_CLASS[variant][size];
|
|
174
|
+
// 带原因的置灰没有原生 disabled,伪类 disabled: 不生效,补静态置灰类(配方 kitDisabledRecipe('aria'))
|
|
175
|
+
const look = reason === '' ? base : `${base} ${kitDisabledRecipe('aria')}`;
|
|
176
|
+
root.className = joinClass(withBadgeAnchor(look, hasBadge || loading), p.class);
|
|
153
177
|
},
|
|
154
|
-
})),
|
|
178
|
+
}))),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 置灰原因气泡:每次渲染之后按 disabled_reason 同步(withTooltip 每次渲染会重写 aria-describedby,所以放在它外面补);
|
|
184
|
+
* 卸载时摘掉。气泡挂 role=tooltip 占位在按钮里面,显示时走浮层端口(见 reason-tip.ts)。
|
|
185
|
+
*/
|
|
186
|
+
function withReasonTip(view: KitView): KitView {
|
|
187
|
+
return {
|
|
188
|
+
attach(root, api) {
|
|
189
|
+
const off = view.attach?.(root, api);
|
|
190
|
+
return () => {
|
|
191
|
+
releaseReasonTip(root);
|
|
192
|
+
if (off) off();
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
render(root, p, api) {
|
|
196
|
+
const done = view.render(root, p, api);
|
|
197
|
+
syncReasonTip(root, reasonOf(p), true);
|
|
198
|
+
return done;
|
|
199
|
+
},
|
|
200
|
+
...(view.handle !== undefined ? { handle: view.handle } : {}),
|
|
201
|
+
...(view.busyAware !== undefined ? { busyAware: view.busyAware } : {}),
|
|
155
202
|
};
|
|
156
203
|
}
|
package/src/base/check-core.ts
CHANGED
|
@@ -21,6 +21,13 @@ export type CheckState = boolean | 'mixed';
|
|
|
21
21
|
|
|
22
22
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
23
23
|
const MARK_ATTR = 'data-kit-mark';
|
|
24
|
+
/** 方形勾选框的标记:主题结构 CSS 据此把半径限到「一个间距单位」以内(胶囊 / 大圆角档下多选框也保持方形小圆角,单选框不带) */
|
|
25
|
+
export const KIT_CHECK_BOX_ATTR = 'data-kit-check-box';
|
|
26
|
+
|
|
27
|
+
/** 给手写的方形勾选框(树 / 授权树 / 穿梭框等自绘的小方块)打上同一标记 */
|
|
28
|
+
export function markCheckBox(el: Element): void {
|
|
29
|
+
el.setAttribute(KIT_CHECK_BOX_ATTR, '');
|
|
30
|
+
}
|
|
24
31
|
|
|
25
32
|
const ROOT_ON = 'group inline-flex cursor-pointer items-center gap-2 rounded-sm transition-colors hover:text-primary-on-soft';
|
|
26
33
|
const ROOT_OFF = 'inline-flex cursor-not-allowed items-center gap-2 rounded-sm text-fg-subtle opacity-60';
|
|
@@ -102,6 +109,7 @@ export function createCheck(doc: Document, kind: CheckKind, paint: CheckPaint =
|
|
|
102
109
|
input.type = kind;
|
|
103
110
|
const box = doc.createElement('span');
|
|
104
111
|
box.setAttribute('aria-hidden', 'true');
|
|
112
|
+
if (kind === 'checkbox') markCheckBox(box);
|
|
105
113
|
slot.append(input, box);
|
|
106
114
|
if (kind === 'checkbox') {
|
|
107
115
|
slot.append(svg(doc, 'M3.5 8.5l3 3 6-7'), svg(doc, 'M4 8h8'));
|
package/src/base/checkbox.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
5
5
|
import { CHOICE_GROUP_DEFAULT_CLASS, createChoiceView } from './choice';
|
|
6
|
-
import { CLASS_PROP, ID_PROPS, OPTIONS_PROP, SIZE_PROP, createKitController } from './shared';
|
|
6
|
+
import { CLASS_PROP, ID_PROPS, INVALID_PROPS, OPTIONS_PROP, SIZE_PROP, createKitController } from './shared';
|
|
7
7
|
|
|
8
8
|
export function createCheckbox(): SomaComponentDefinition {
|
|
9
9
|
return {
|
|
@@ -22,6 +22,7 @@ export function createCheckbox(): SomaComponentDefinition {
|
|
|
22
22
|
disabled: { type: 'boolean', default: false },
|
|
23
23
|
readonly: { type: 'boolean', default: false },
|
|
24
24
|
...ID_PROPS,
|
|
25
|
+
...INVALID_PROPS,
|
|
25
26
|
size: SIZE_PROP,
|
|
26
27
|
class: CLASS_PROP,
|
|
27
28
|
},
|
package/src/base/choice.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// 选项集变化才重建 DOM,其余只更新 input 属性 / 类串,保住焦点。
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
applyCommon, bool, nextUid, optionsKey, optionsOf, sameValue, setAttr, sizeOf, str, joinClass,
|
|
6
|
+
applyCommon, applyGroupA11y, bool, nextUid, optionsKey, optionsOf, sameValue, setAttr, sizeOf, str, joinClass,
|
|
7
7
|
type KitApi, type KitOption, type KitProps, type KitSize, type KitView, type KitViewSetup,
|
|
8
8
|
} from './shared';
|
|
9
9
|
import { attachMarkEvents, createCheck, markChecked, markInput, paintCheck } from './check-core';
|
|
@@ -106,7 +106,26 @@ function paint(kind: ChoiceKind, root: HTMLElement, p: KitProps): void {
|
|
|
106
106
|
if (readonly && kind === 'radio') root.setAttribute('aria-readonly', 'true');
|
|
107
107
|
else root.removeAttribute('aria-readonly');
|
|
108
108
|
// id 已给第一个控件,根上不重复写;这里只写可访问名
|
|
109
|
-
|
|
109
|
+
// 组根写可访问名 / 标签关联;必填 / 无效 / 说明关联:组(radiogroup、多选组)写在根上,单个勾选框写在它的原生 input 上
|
|
110
|
+
const firstMark = marksOf(root)[0];
|
|
111
|
+
const first = single && firstMark ? markInput(firstMark) : null;
|
|
112
|
+
if (first) {
|
|
113
|
+
applyCommon(root, { aria_label: p.aria_label, labelledby: p.labelledby, aria_labelledby: p.aria_labelledby });
|
|
114
|
+
applyCommon(first, {
|
|
115
|
+
id: str(p.id),
|
|
116
|
+
name: first.getAttribute('name') ?? '',
|
|
117
|
+
aria_label: first.getAttribute('aria-label') ?? '',
|
|
118
|
+
required: p.required,
|
|
119
|
+
invalid: p.invalid,
|
|
120
|
+
describedby: p.describedby,
|
|
121
|
+
aria_describedby: p.aria_describedby,
|
|
122
|
+
errormessage: p.errormessage,
|
|
123
|
+
aria_errormessage: p.aria_errormessage,
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
// radiogroup 根支持 aria-required / aria-invalid;多选组(role=group)则落到各原生 checkbox 上
|
|
127
|
+
applyGroupA11y(root, p, root.querySelectorAll('input'));
|
|
128
|
+
}
|
|
110
129
|
// 外部类追加在根节点类串末尾(冲突合并留给以后的编译器)
|
|
111
130
|
const vertical = orientationOf(p.orientation) === 'vertical';
|
|
112
131
|
if (vertical) root.setAttribute('aria-orientation', 'vertical');
|
package/src/base/color-picker.ts
CHANGED
|
@@ -14,9 +14,11 @@ import { createKeyboardWiring } from 'soma-core/keyboard';
|
|
|
14
14
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
15
15
|
import { part, wirePopLayer } from './popover';
|
|
16
16
|
import { KIT_DROPDOWN_CLASS_CANDIDATES } from './popup';
|
|
17
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
18
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
17
19
|
import {
|
|
18
|
-
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
19
|
-
applyCommon, bool, classCandidates, createKitController, joinClass, nextUid, setAttr, sizeOf, str,
|
|
20
|
+
CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
21
|
+
applyCommon, applyCompositeField, bool, classCandidates, createKitController, joinClass, nextUid, setAttr, sizeOf, str,
|
|
20
22
|
type KitSize,
|
|
21
23
|
} from './shared';
|
|
22
24
|
|
|
@@ -63,15 +65,15 @@ export function presetsOf(raw: unknown): string[] {
|
|
|
63
65
|
|
|
64
66
|
const ROOT = 'relative block w-full';
|
|
65
67
|
const TRIGGER: Record<KitSize, string> = {
|
|
66
|
-
sm: 'inline-flex h-
|
|
67
|
-
md: 'inline-flex h-
|
|
68
|
+
sm: 'inline-flex h-6 w-full cursor-pointer items-center gap-2 rounded-md border border-input bg-surface px-2.5 text-sm text-fg transition-colors enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:opacity-60',
|
|
69
|
+
md: 'inline-flex h-8 w-full cursor-pointer items-center gap-2 rounded-md border border-input bg-surface px-3 text-sm text-fg transition-colors enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:opacity-60',
|
|
68
70
|
lg: 'inline-flex h-10 w-full cursor-pointer items-center gap-2 rounded-md border border-input bg-surface px-4 text-base text-fg transition-colors enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:opacity-60',
|
|
69
71
|
};
|
|
70
72
|
const TRIGGER_TEXT = 'min-w-0 flex-1 truncate text-start';
|
|
71
73
|
const TRIGGER_TEXT_EMPTY = 'min-w-0 flex-1 truncate text-start text-fg-subtle';
|
|
72
74
|
const SWATCH_SVG = 'h-4 w-4 shrink-0';
|
|
73
75
|
const SWATCH_RECT = 'stroke-border stroke-1';
|
|
74
|
-
const PANEL = 'absolute z-10 w-64
|
|
76
|
+
const PANEL = mergeClass('absolute z-10 w-64 p-3 focus-visible:outline-none', kitSurfaceRecipe('raised'));
|
|
75
77
|
const HIDDEN = 'hidden';
|
|
76
78
|
const PRESETS = 'flex flex-wrap gap-2';
|
|
77
79
|
const CHIP_IDLE = 'inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md border border-border-subtle transition-colors hover:border-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
@@ -116,6 +118,7 @@ export function createColorPicker(): SomaComponentDefinition {
|
|
|
116
118
|
disabled: { type: 'boolean', default: false },
|
|
117
119
|
readonly: { type: 'boolean', default: false },
|
|
118
120
|
...ID_PROPS,
|
|
121
|
+
...INVALID_PROPS,
|
|
119
122
|
size: SIZE_PROP,
|
|
120
123
|
class: CLASS_PROP,
|
|
121
124
|
},
|
|
@@ -276,6 +279,8 @@ export function createColorPicker(): SomaComponentDefinition {
|
|
|
276
279
|
trigger.className = TRIGGER[sizeOf(p.size)];
|
|
277
280
|
trigger.disabled = disabled;
|
|
278
281
|
applyCommon(trigger, { id: p.id, aria_label: p.aria_label });
|
|
282
|
+
// 作表单字段:根承载字段名 / 说明 / 错误关联与无效标记(触发钮是 button,不写校验属性)
|
|
283
|
+
applyCompositeField(root, p);
|
|
279
284
|
chipHost.textContent = '';
|
|
280
285
|
chipHost.appendChild(swatch(SWATCH_SVG, value));
|
|
281
286
|
text.textContent = value ?? str(p.placeholder, kitText('soma.kit.pick_color', undefined, text));
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from './shared';
|
|
23
23
|
|
|
24
24
|
const ROOT = 'inline-block';
|
|
25
|
-
const TRIGGER = 'inline-flex h-
|
|
25
|
+
const TRIGGER = 'inline-flex h-8 cursor-pointer items-center gap-3 rounded-md border border-border bg-surface px-3 text-sm text-fg-muted transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
26
26
|
const TRIGGER_KEYS = 'rounded-sm border border-border-subtle bg-surface-sunken px-1.5 py-0.5 text-xs text-fg-subtle';
|
|
27
27
|
const HIDDEN = 'hidden';
|
|
28
28
|
const OVERLAY = 'fixed inset-0 z-50 flex items-start justify-center bg-scrim p-4';
|
package/src/base/context-menu.ts
CHANGED
|
@@ -7,19 +7,22 @@
|
|
|
7
7
|
// 见 kit-grammar.json#cssomWrites);端口缺失时降级为按指针象限选四角偏移类的就地定位(不写 CSSOM);键盘打开落在触发区左上。
|
|
8
8
|
// 3. 触发区的外观:虚线框的「右键此处」区域。
|
|
9
9
|
|
|
10
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
10
11
|
import { classCandidates } from './shared';
|
|
11
12
|
|
|
12
13
|
export type Corner = 'tl' | 'tr' | 'bl' | 'br';
|
|
13
14
|
|
|
15
|
+
// 菜单面板的表面(圆角 / hairline 描边 / 浮起底 / 双层阴影 / 高光边)统一取 recipes/surface.ts 的浮起级
|
|
16
|
+
const MENU_PANEL_SURFACE = kitSurfaceRecipe('raised');
|
|
14
17
|
export const CONTEXT_SHOWN: Record<Corner, string> = {
|
|
15
|
-
tl:
|
|
16
|
-
tr:
|
|
17
|
-
bl:
|
|
18
|
-
br:
|
|
18
|
+
tl: `absolute left-4 top-4 z-10 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`,
|
|
19
|
+
tr: `absolute right-4 top-4 z-10 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`,
|
|
20
|
+
bl: `absolute bottom-4 left-4 z-10 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`,
|
|
21
|
+
br: `absolute bottom-4 right-4 z-10 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`,
|
|
19
22
|
};
|
|
20
|
-
/** 按点挂浮层时的面板类(fixed,几何由 portal-core 的 showAtPoint 一次写入;无 style=
|
|
21
|
-
export const CONTEXT_POINT_PANEL =
|
|
22
|
-
export const CONTEXT_AREA ='block w-full cursor-context-menu rounded-lg border border-dashed border-border bg-surface px-4 py-6 text-center text-sm text-fg-muted transition-colors
|
|
23
|
+
/** 按点挂浮层时的面板类(fixed,几何由 portal-core 的 showAtPoint 一次写入;无 style= 字面量;进场由 showAtPoint 打的 data-kit-anchored 规则统一驱动) */
|
|
24
|
+
export const CONTEXT_POINT_PANEL = `fixed z-50 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`;
|
|
25
|
+
export const CONTEXT_AREA ='block w-full cursor-context-menu rounded-lg border border-dashed border-border bg-surface px-4 py-6 text-center text-sm text-fg-muted transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
23
26
|
export const CONTEXT_AREA_OFF = 'block w-full cursor-not-allowed rounded-lg border border-dashed border-border bg-surface-sunken px-4 py-6 text-center text-sm text-fg-subtle opacity-60';
|
|
24
27
|
const LONG_PRESS_MS = 500;
|
|
25
28
|
|
package/src/base/date-range.ts
CHANGED
|
@@ -29,21 +29,21 @@ const RANGE_CLASS: Record<KitSize, string> = {
|
|
|
29
29
|
const FIELDS_CLASS = 'relative inline-flex items-center gap-2';
|
|
30
30
|
const HIDDEN_CLASS = 'hidden';
|
|
31
31
|
const DATE_CLASS: Record<KitSize, string> = {
|
|
32
|
-
sm: 'block h-
|
|
33
|
-
md: 'block h-
|
|
32
|
+
sm: 'block h-6 w-32 rounded-md border border-input bg-surface px-2.5 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
33
|
+
md: 'block h-8 w-36 rounded-md border border-input bg-surface px-3 text-sm text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
34
34
|
lg: 'block h-10 w-40 rounded-md border border-input bg-surface px-4 text-base text-fg transition-colors placeholder:text-fg-subtle enabled:hover:border-input-hover focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
35
35
|
};
|
|
36
36
|
const OPEN_BTN_CLASS: Record<KitSize, string> = {
|
|
37
|
-
sm: 'inline-flex size-8 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
38
|
-
md: 'inline-flex size-9 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
39
|
-
lg: 'inline-flex size-10 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
37
|
+
sm: 'inline-flex size-8 p-0 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
38
|
+
md: 'inline-flex size-9 p-0 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
39
|
+
lg: 'inline-flex size-10 p-0 cursor-pointer items-center justify-center rounded-md border border-input bg-surface text-fg-subtle transition-colors enabled:hover:text-fg enabled:hover:border-input-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
40
40
|
};
|
|
41
41
|
const ICON_CLASS = 'size-4 pointer-events-none';
|
|
42
42
|
|
|
43
43
|
const PRESETS_CLASS = 'inline-flex flex-wrap items-center gap-1';
|
|
44
44
|
const PRESET_CLASS = {
|
|
45
|
-
idle: 'inline-flex h-
|
|
46
|
-
pressed: 'inline-flex h-
|
|
45
|
+
idle: 'inline-flex h-6 border-0 bg-transparent cursor-pointer items-center rounded-md px-2.5 text-sm text-fg-muted transition-colors enabled:hover:bg-state-layer-hover enabled:active:bg-state-layer-press enabled:hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
46
|
+
pressed: 'inline-flex h-6 border-0 cursor-pointer items-center rounded-md bg-primary-soft px-2.5 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
47
47
|
} as const;
|
|
48
48
|
|
|
49
49
|
export const KIT_DATE_RANGE_CLASS_CANDIDATES: readonly string[] = classCandidates(
|