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/menu-core.ts
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
import type { CollectionItem } from 'soma-core/keyboard';
|
|
11
11
|
import { createListNav, createPanelPortal, onOutsidePress, showMenuAtPoint, showPopupFitted, type ListNav, type PopPlace } from './popup';
|
|
12
12
|
import type { PointPanel } from './portal-core';
|
|
13
|
+
import { KIT_ANCHORED_ATTR, leaveAnchored, unmarkAnchored } from './anchored-layer';
|
|
14
|
+
import type { KitLeaveHandle } from './overlay-runtime';
|
|
13
15
|
import { nextUid } from './shared';
|
|
14
16
|
import { setKitFace, type KitFaceKind } from '../recipes';
|
|
15
17
|
|
|
@@ -26,6 +28,8 @@ export interface MenuItemSpec {
|
|
|
26
28
|
danger: boolean;
|
|
27
29
|
/** 分隔线(此时只有 key 有意义) */
|
|
28
30
|
divider: boolean;
|
|
31
|
+
/** 置灰原因(只对 disabled 项有意义):项里多一段可见的描述文字,项带 aria-describedby 指向它;空 / 缺省不画 */
|
|
32
|
+
reason?: string;
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
/** 菜单项归一:`[{ key, label, icon?, disabled?, danger?, divider? }]`;key 重复的第二项起丢弃,分隔线不要求 label */
|
|
@@ -63,6 +67,8 @@ export interface MenuClasses {
|
|
|
63
67
|
disabled: string;
|
|
64
68
|
divider: string;
|
|
65
69
|
icon: string;
|
|
70
|
+
/** 置灰原因描述文字的类(项带 reason 时用;缺省不加类) */
|
|
71
|
+
desc?: string;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
/** 面板挂载端口(实现见 data/overlay-portal 的 createPanelPortal;这里只认形状,base 不依赖 data) */
|
|
@@ -125,6 +131,18 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
125
131
|
const portal: MenuPortal = o.portal ?? createPanelPortal(trigger);
|
|
126
132
|
let open = false;
|
|
127
133
|
let pointPanel: PointPanel | null = null;
|
|
134
|
+
// 出场(隐藏前过渡,与其他锚定浮层同一机制):播完退场动画再放回原位 / 整串 hidden;没有退场动画则立即收尾
|
|
135
|
+
let leaving: KitLeaveHandle | null = null;
|
|
136
|
+
const finishHide = (): void => {
|
|
137
|
+
leaving = null;
|
|
138
|
+
portal.hide(true);
|
|
139
|
+
if (pointPanel !== null) {
|
|
140
|
+
pointPanel.hide(true);
|
|
141
|
+
pointPanel = null;
|
|
142
|
+
}
|
|
143
|
+
menu.className = o.hiddenClass;
|
|
144
|
+
unmarkAnchored(menu);
|
|
145
|
+
};
|
|
128
146
|
let cursor: string | null = null;
|
|
129
147
|
let builtKey = '';
|
|
130
148
|
const menuId = menu.id !== '' ? menu.id : nextUid('kit-menu');
|
|
@@ -166,6 +184,15 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
166
184
|
const label = document.createElement('span');
|
|
167
185
|
label.textContent = item.label;
|
|
168
186
|
row.appendChild(label);
|
|
187
|
+
const reason = item.disabled && item.reason !== undefined ? item.reason.trim() : '';
|
|
188
|
+
if (reason !== '') {
|
|
189
|
+
const desc = document.createElement('span');
|
|
190
|
+
desc.id = nextUid('kit-menu-reason');
|
|
191
|
+
if (o.classes.desc !== undefined) desc.className = o.classes.desc;
|
|
192
|
+
desc.textContent = reason;
|
|
193
|
+
row.appendChild(desc);
|
|
194
|
+
row.setAttribute('aria-describedby', desc.id);
|
|
195
|
+
}
|
|
169
196
|
menu.appendChild(row);
|
|
170
197
|
}
|
|
171
198
|
};
|
|
@@ -181,6 +208,11 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
181
208
|
if (item.disabled) el.setAttribute('aria-disabled', 'true');
|
|
182
209
|
else el.removeAttribute('aria-disabled');
|
|
183
210
|
}
|
|
211
|
+
// 退场中被重新打开:撤销退场
|
|
212
|
+
if (open && leaving !== null) {
|
|
213
|
+
leaving.cancel();
|
|
214
|
+
leaving = null;
|
|
215
|
+
}
|
|
184
216
|
const pt = open ? (o.point?.() ?? null) : null;
|
|
185
217
|
const fit = open && pt === null ? (o.fitted?.() ?? null) : null;
|
|
186
218
|
if (pt !== null) {
|
|
@@ -199,16 +231,11 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
199
231
|
} else if (fit !== null) {
|
|
200
232
|
const placed = portal.show(menu, trigger, fit.pref, fit.classFor, { ...(fit.gapPx !== undefined ? { gapPx: fit.gapPx } : {}), onEscape: () => close(true) });
|
|
201
233
|
if (placed === null) showPopupFitted(menu, trigger, fit.pref, fit.classFor, fit.gapPx);
|
|
234
|
+
} else if (!open) {
|
|
235
|
+
if (leaving === null) leaving = menu.hasAttribute(KIT_ANCHORED_ATTR) ? leaveAnchored(menu, finishHide) : (finishHide(), null);
|
|
202
236
|
} else {
|
|
203
|
-
if (!open) {
|
|
204
|
-
portal.hide(true);
|
|
205
|
-
if (pointPanel !== null) {
|
|
206
|
-
pointPanel.hide(true);
|
|
207
|
-
pointPanel = null;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
237
|
const shown = typeof o.shownClass === 'function' ? o.shownClass() : o.shownClass;
|
|
211
|
-
menu.className =
|
|
238
|
+
menu.className = shown;
|
|
212
239
|
}
|
|
213
240
|
trigger.setAttribute('aria-haspopup', 'menu');
|
|
214
241
|
trigger.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
@@ -337,6 +364,8 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
337
364
|
scope.removeEventListener('focusout', onFocusOut);
|
|
338
365
|
menu.removeEventListener('focusout', onFocusOut);
|
|
339
366
|
offOutside();
|
|
367
|
+
leaving?.cancel();
|
|
368
|
+
leaving = null;
|
|
340
369
|
portal.hide(true);
|
|
341
370
|
pointPanel?.hide(true);
|
|
342
371
|
pointPanel = null;
|
|
@@ -14,7 +14,7 @@ import { safeHref } from '../link';
|
|
|
14
14
|
import { HOVER_3D_GRID, MOTION_STRENGTHS, prefersReducedMotion, segmentOf, strengthOf, type MotionStrength } from './limits';
|
|
15
15
|
|
|
16
16
|
const ROOT_CLASS = 'block perspective-normal';
|
|
17
|
-
const CARD_CORE = 'block overflow-hidden rounded-lg border border-border-subtle bg-surface text-fg
|
|
17
|
+
const CARD_CORE = 'block overflow-hidden rounded-lg border border-border-subtle bg-surface text-fg motion-safe:transition-transform focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
18
18
|
const CARD_IDLE = `${CARD_CORE} shadow-sm`;
|
|
19
19
|
const CARD_TILTED = `${CARD_CORE} shadow-md`;
|
|
20
20
|
const IMAGE_CLASS = 'block h-40 w-full object-cover';
|
|
@@ -31,7 +31,7 @@ const TRACK_PAUSED: Record<Speed, string> = {
|
|
|
31
31
|
};
|
|
32
32
|
const GROUP_SCROLL = 'flex shrink-0 items-center gap-8 pe-8 whitespace-nowrap';
|
|
33
33
|
const GROUP_STATIC = 'flex flex-wrap items-center gap-x-6 gap-y-1';
|
|
34
|
-
const PAUSE_CLASS = 'inline-flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-xs text-fg-muted transition-colors hover:bg-
|
|
34
|
+
const PAUSE_CLASS = 'inline-flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
35
35
|
const HIDDEN = 'hidden';
|
|
36
36
|
|
|
37
37
|
/** 本组件自带的类 */
|
package/src/base/otp.ts
CHANGED
|
@@ -7,8 +7,8 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
7
7
|
import { kitKey, kitText } from '../i18n/kit-text';
|
|
8
8
|
import { setKitFace } from '../recipes';
|
|
9
9
|
import {
|
|
10
|
-
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
11
|
-
bool, classCandidates, createKitController, joinClass, num, setAttr, setBoolAttr, sizeOf, str,
|
|
10
|
+
CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
11
|
+
applyGroupA11y, bool, classCandidates, createKitController, joinClass, num, setAttr, setBoolAttr, sizeOf, str,
|
|
12
12
|
type KitSize, type KitView,
|
|
13
13
|
} from './shared';
|
|
14
14
|
|
|
@@ -227,8 +227,8 @@ function makeView(): KitView {
|
|
|
227
227
|
});
|
|
228
228
|
completed = chars.length === length;
|
|
229
229
|
root.setAttribute('role', 'group');
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
// 组名(aria_label 缺省取默认文案)与必填 / 无效 / 说明 / 标签关联一并走 applyCommon(组根不写 name)
|
|
231
|
+
applyGroupA11y(root, { ...p, aria_label: label }, cells);
|
|
232
232
|
setAttr(root, 'id', str(p.id));
|
|
233
233
|
root.className = joinClass(GROUP_CLASS, p.class);
|
|
234
234
|
},
|
|
@@ -248,6 +248,7 @@ export function createOtp(): SomaComponentDefinition {
|
|
|
248
248
|
disabled: { type: 'boolean', default: false },
|
|
249
249
|
readonly: { type: 'boolean', default: false },
|
|
250
250
|
...ID_PROPS,
|
|
251
|
+
...INVALID_PROPS,
|
|
251
252
|
size: SIZE_PROP,
|
|
252
253
|
class: CLASS_PROP,
|
|
253
254
|
},
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// 浮层页面侧运行期:退场过渡 + 向外壳通报「页内浮层栈」。纯 DOM,不依赖 kit 其它模块(base / data / biz / frames 都可 import,不成环)。
|
|
2
|
+
//
|
|
3
|
+
// 一、退场(W3 / D 类机制)
|
|
4
|
+
// core 的显隐只有一个执行点:`SomaContainerAdapter.setVisibility`。core 提供方言中性的端口 `renderPorts.hideTransition`
|
|
5
|
+
// (写 hidden 之前先等钩子返回的 Promise;等待中被再次显示则 abort 信号并直接显示),kit 在这里实现钩子:
|
|
6
|
+
// createKitHideTransition() -> 只处理浮层显隐外层(`_layer` 锚点,直接子节点含 `[data-kit-scrim]`),其余元素返回 void(立即隐藏);
|
|
7
|
+
// 首次收起静默(core 初始化时把未开的浮层收起,从未展示过的浮层不播退场);之后收起 -> beginKitLeave:
|
|
8
|
+
// 标 `data-kit-leaving` + `inert`,等退场动画结束(animationend,带超时兜底)再 resolve,由 core 写真的 hidden;
|
|
9
|
+
// abort(退场中重开)-> 撤销退场状态。
|
|
10
|
+
// 退场是否存在由「标上 data-kit-leaving 后计算样式的 animation-name 有没有变」判定:主题侧没有补退场关键帧时没有任何延迟(立即隐藏),
|
|
11
|
+
// 补了关键帧即自动生效,本文件不写任何时长 / 缓动(时长取计算样式里的 animation-duration)。
|
|
12
|
+
// prefers-reduced-motion: reduce 时不短路:主题侧该偏好下的退场关键帧只有淡出(无位移 / 缩放),时长由令牌归短;不全局压零。
|
|
13
|
+
// 收尾三路任一先到即可:动画对象 finished、animationend / animationcancel 事件、超时兜底(计算出的出场时长 + 真源宽限);el.getAnimations() 为空则立即继续。
|
|
14
|
+
// 接入点(主题侧):`[data-kit-scrim][data-kit-leaving]`、`[data-kit-leaving] [role="dialog"]`、`[data-kit-leaving]`(通知 / 命令式遮罩 / 外壳遮罩)。
|
|
15
|
+
//
|
|
16
|
+
// 二、页内浮层栈 -> 外壳遮罩(W5)
|
|
17
|
+
// 页面在 iframe 里时外壳遮罩盖不到页内浮层之外:页面(本模块)在可见模态面板数变化时向父窗口发
|
|
18
|
+
// `{ type: 'soma-kit:overlay', open: <数量> }`(targetOrigin = 本页 origin);外壳校验 origin 与来源 iframe 后据此显示 / 收回遮罩。
|
|
19
|
+
// 外壳不再窥探 iframe 文档。载荷只含计数。
|
|
20
|
+
// 安装点只有一处:kit 应用的渲染端口装配(`createKitRenderPorts`,app/define-kit-app 经它出端口);监听按文档级 `aria-modal`
|
|
21
|
+
// 统计,业务浮层 / 命令式模态 / 图片查看 / 引导 / 命令面板等一切 aria-modal 浮层自动覆盖,不在各浮层里各装一次。
|
|
22
|
+
|
|
23
|
+
import { KIT_OVERLAY_LIMITS } from 'soma-foundation/kit-limits';
|
|
24
|
+
|
|
25
|
+
export const KIT_OVERLAY_MESSAGE_TYPE = 'soma-kit:overlay';
|
|
26
|
+
/** 退场中的状态属性(主题侧据此挂退场关键帧) */
|
|
27
|
+
export const KIT_LEAVING_ATTR = 'data-kit-leaving';
|
|
28
|
+
/** 兜底超时在出场动画时长之外的宽限(毫秒,真源 kit-limits#overlay.leaveMarginMs) */
|
|
29
|
+
export const KIT_LEAVE_SLACK_MS: number = KIT_OVERLAY_LIMITS.leaveMarginMs;
|
|
30
|
+
/** 兜底超时上限:再长的动画也在这个时间内强制收尾,浮层不会卡在退场态 */
|
|
31
|
+
export const KIT_LEAVE_MAX_MS = 1000;
|
|
32
|
+
|
|
33
|
+
export interface KitOverlayMessage {
|
|
34
|
+
type: typeof KIT_OVERLAY_MESSAGE_TYPE;
|
|
35
|
+
/** 当前可见(非退场、非隐藏)的模态面板数 */
|
|
36
|
+
open: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 解析外壳收到的消息载荷;形状不对一律返回 null(不抛) */
|
|
40
|
+
export function parseKitOverlayMessage(data: unknown): KitOverlayMessage | null {
|
|
41
|
+
if (data === null || typeof data !== 'object') return null;
|
|
42
|
+
const m = data as { type?: unknown; open?: unknown };
|
|
43
|
+
if (m.type !== KIT_OVERLAY_MESSAGE_TYPE) return null;
|
|
44
|
+
if (typeof m.open !== 'number' || !Number.isInteger(m.open) || m.open < 0) return null;
|
|
45
|
+
return { type: KIT_OVERLAY_MESSAGE_TYPE, open: m.open };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ---------------------------------------------------------------- 退场
|
|
49
|
+
|
|
50
|
+
export interface KitLeaveHandle {
|
|
51
|
+
/** 取消退场:移除退场状态,不调 done(元素回到可见) */
|
|
52
|
+
cancel(): void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 参与退场的节点:根本身 + 其内的遮罩 / 对话框面板(动画通常挂在它们身上) */
|
|
56
|
+
function leaveTargets(root: HTMLElement): Element[] {
|
|
57
|
+
return [root, ...Array.from(root.querySelectorAll('[data-kit-scrim], [role="dialog"], [data-kit-part="drawer"]'))];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function animationNameOf(win: Window, el: Element): string {
|
|
61
|
+
try { return win.getComputedStyle(el).animationName ?? ''; } catch { return ''; }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function firstTimeMs(value: string | undefined): number {
|
|
65
|
+
const first = (value ?? '').split(',')[0]?.trim() ?? '';
|
|
66
|
+
const n = parseFloat(first);
|
|
67
|
+
if (!Number.isFinite(n)) return 0;
|
|
68
|
+
return first.endsWith('ms') ? n : n * 1000;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 退场里真在跑的有限动画(挂在参与退场的节点上、非无限循环);浏览器没有 getAnimations 时返回 null(只能靠事件 + 超时) */
|
|
72
|
+
function runningLeaveAnimations(root: HTMLElement, moving: readonly Element[]): Animation[] | null {
|
|
73
|
+
if (typeof root.getAnimations !== 'function') return null;
|
|
74
|
+
try {
|
|
75
|
+
return root.getAnimations({ subtree: true }).filter((a) => {
|
|
76
|
+
const target = (a.effect as KeyframeEffect | null)?.target ?? null;
|
|
77
|
+
if (target === null || !moving.includes(target)) return false;
|
|
78
|
+
return a.effect?.getComputedTiming().iterations !== Infinity;
|
|
79
|
+
});
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 开始退场:给 el 标 data-kit-leaving + inert,等退场动画结束后调 done。
|
|
87
|
+
* 没有退场动画(标上状态后计算样式的 animation-name 没变,或 el.getAnimations() 为空)/ 无窗口 -> 返回 null,什么都没改,由调用方立即收尾。
|
|
88
|
+
* 减弱动效(prefers-reduced-motion: reduce)不在这里短路:主题侧在该偏好下只保留淡出(无位移 / 缩放,时长由令牌归短),
|
|
89
|
+
* 所以这里照常等它结束,退场的存在与否只看有没有动画。
|
|
90
|
+
* 收尾不依赖 animationend / transitionend 必达:三路任一先到即收尾——动画对象的 finished、事件、超时兜底(出场时长 + 真源宽限 KIT_LEAVE_SLACK_MS)。
|
|
91
|
+
*/
|
|
92
|
+
export function beginKitLeave(el: HTMLElement, done: () => void): KitLeaveHandle | null {
|
|
93
|
+
const win = el.ownerDocument.defaultView;
|
|
94
|
+
if (!win) return null;
|
|
95
|
+
const targets = leaveTargets(el);
|
|
96
|
+
const before = targets.map((t) => animationNameOf(win, t));
|
|
97
|
+
el.setAttribute(KIT_LEAVING_ATTR, '');
|
|
98
|
+
const moving: Element[] = [];
|
|
99
|
+
let maxMs = 0;
|
|
100
|
+
targets.forEach((t, i) => {
|
|
101
|
+
const name = animationNameOf(win, t);
|
|
102
|
+
if (name === '' || name === 'none' || name === before[i]) return;
|
|
103
|
+
moving.push(t);
|
|
104
|
+
const cs = win.getComputedStyle(t);
|
|
105
|
+
maxMs = Math.max(maxMs, firstTimeMs(cs.animationDuration) + firstTimeMs(cs.animationDelay));
|
|
106
|
+
});
|
|
107
|
+
// 动画列表为空(浏览器已知没有在跑的退场动画,如 animation-name 变了但元素没有渲染框):立即继续,不等任何事件
|
|
108
|
+
const anims = moving.length === 0 ? null : runningLeaveAnimations(el, moving);
|
|
109
|
+
if (moving.length === 0 || (anims !== null && anims.length === 0)) {
|
|
110
|
+
el.removeAttribute(KIT_LEAVING_ATTR);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
el.setAttribute('inert', '');
|
|
114
|
+
const pending = new Set<Element>(moving);
|
|
115
|
+
let over = false;
|
|
116
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
117
|
+
const stop = (): void => {
|
|
118
|
+
over = true;
|
|
119
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
120
|
+
el.removeEventListener('animationend', onEnd);
|
|
121
|
+
el.removeEventListener('animationcancel', onEnd);
|
|
122
|
+
el.removeAttribute(KIT_LEAVING_ATTR);
|
|
123
|
+
el.removeAttribute('inert');
|
|
124
|
+
};
|
|
125
|
+
const finish = (): void => {
|
|
126
|
+
if (over) return;
|
|
127
|
+
stop();
|
|
128
|
+
done();
|
|
129
|
+
};
|
|
130
|
+
function onEnd(e: Event): void {
|
|
131
|
+
pending.delete(e.target as Element);
|
|
132
|
+
if (pending.size === 0) finish();
|
|
133
|
+
}
|
|
134
|
+
el.addEventListener('animationend', onEnd);
|
|
135
|
+
el.addEventListener('animationcancel', onEnd);
|
|
136
|
+
timer = setTimeout(finish, Math.min(KIT_LEAVE_MAX_MS, maxMs + KIT_LEAVE_SLACK_MS));
|
|
137
|
+
if (anims !== null) {
|
|
138
|
+
void Promise.allSettled(anims.map((a) => a.finished)).then(finish);
|
|
139
|
+
}
|
|
140
|
+
return { cancel: () => { if (!over) stop(); } };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------- core 隐藏前过渡钩子(renderPorts.hideTransition)
|
|
144
|
+
|
|
145
|
+
/** 与 soma-core 的 HideTransition 同形(结构类型,本文件不 import core) */
|
|
146
|
+
export type KitHideTransition = (element: HTMLElement, signal: AbortSignal) => Promise<void> | void;
|
|
147
|
+
|
|
148
|
+
/** 浮层显隐外层:锚点 id 以 _layer 结尾(overlay-shell 的 dialogIds / overlayIds),且直接子节点含遮罩 */
|
|
149
|
+
export function isKitLayerHost(el: HTMLElement): boolean {
|
|
150
|
+
if (!(el.getAttribute('data-soma-id') ?? '').endsWith('_layer')) return false;
|
|
151
|
+
return Array.from(el.children).some((c) => c.hasAttribute('data-kit-scrim'));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** 浮层退场钩子:只处理浮层显隐外层,其余元素立即隐藏(返回 void);首次收起静默,之后播退场(无关键帧 / 减弱动效即时) */
|
|
155
|
+
export function createKitHideTransition(): KitHideTransition {
|
|
156
|
+
const armed = new WeakSet<HTMLElement>();
|
|
157
|
+
return (el, signal) => {
|
|
158
|
+
if (!isKitLayerHost(el)) return undefined;
|
|
159
|
+
if (!armed.has(el)) { armed.add(el); return undefined; }
|
|
160
|
+
let resolveLeave: (() => void) | undefined;
|
|
161
|
+
const done = new Promise<void>((resolve) => { resolveLeave = resolve; });
|
|
162
|
+
const handle = beginKitLeave(el, () => resolveLeave?.());
|
|
163
|
+
if (handle === null) return undefined;
|
|
164
|
+
signal.addEventListener('abort', () => handle.cancel(), { once: true });
|
|
165
|
+
return done;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ---------------------------------------------------------------- 页内浮层栈 -> 外壳
|
|
170
|
+
|
|
171
|
+
/** 可见的模态面板数:aria-modal 面板里,祖先没有 hidden 属性 / hidden 类 / 退场状态的 */
|
|
172
|
+
export function countOpenKitOverlays(doc: Document): number {
|
|
173
|
+
let n = 0;
|
|
174
|
+
doc.querySelectorAll('[aria-modal="true"]').forEach((el) => {
|
|
175
|
+
if (el.closest('[hidden], .hidden, [data-kit-leaving]') === null) n += 1;
|
|
176
|
+
});
|
|
177
|
+
return n;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface RuntimeState { last: number; off: () => void }
|
|
181
|
+
const RUNTIMES = new WeakMap<Document, RuntimeState>();
|
|
182
|
+
|
|
183
|
+
/** 向父窗口通报当前浮层数(数量没变不发;顶层页面 / 无父窗口 / 不透明 origin 不发) */
|
|
184
|
+
export function notifyKitOverlays(doc: Document): void {
|
|
185
|
+
const st = RUNTIMES.get(doc);
|
|
186
|
+
const win = doc.defaultView;
|
|
187
|
+
if (!st || !win) return;
|
|
188
|
+
const open = countOpenKitOverlays(doc);
|
|
189
|
+
if (open === st.last) return;
|
|
190
|
+
st.last = open;
|
|
191
|
+
postOpen(win, open);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function postOpen(win: Window, open: number): void {
|
|
195
|
+
const parent = win.parent;
|
|
196
|
+
if (!parent || parent === win) return;
|
|
197
|
+
const origin = win.location?.origin;
|
|
198
|
+
if (!origin || origin === 'null') return;
|
|
199
|
+
try { parent.postMessage({ type: KIT_OVERLAY_MESSAGE_TYPE, open } satisfies KitOverlayMessage, origin); } catch { /* 父窗口不可达:忽略 */ }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const relevantNode = (n: Node): boolean => n instanceof Element && (n.matches('[aria-modal]') || n.querySelector('[aria-modal]') !== null);
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* 在本页安装浮层通报:监听浮层增删与显隐 / 退场状态变化并向外壳通报计数。幂等;页面卸载时报 0。
|
|
206
|
+
* 唯一安装点:kit 应用渲染端口装配(createKitRenderPorts)。
|
|
207
|
+
*/
|
|
208
|
+
export function installKitOverlayRuntime(doc: Document): void {
|
|
209
|
+
if (RUNTIMES.has(doc)) return;
|
|
210
|
+
const win = doc.defaultView;
|
|
211
|
+
if (!win) return;
|
|
212
|
+
const state: RuntimeState = { last: 0, off: () => {} };
|
|
213
|
+
RUNTIMES.set(doc, state);
|
|
214
|
+
const onChange = (): void => notifyKitOverlays(doc);
|
|
215
|
+
const Observer = (win as Window & { MutationObserver?: typeof MutationObserver }).MutationObserver;
|
|
216
|
+
const root = doc.body ?? doc.documentElement;
|
|
217
|
+
let mo: MutationObserver | null = null;
|
|
218
|
+
if (typeof Observer === 'function' && root) {
|
|
219
|
+
mo = new Observer((records) => {
|
|
220
|
+
const hit = records.some((r) => r.type === 'attributes'
|
|
221
|
+
|| Array.from(r.addedNodes).some(relevantNode) || Array.from(r.removedNodes).some(relevantNode));
|
|
222
|
+
if (hit) onChange();
|
|
223
|
+
});
|
|
224
|
+
mo.observe(root, { childList: true, subtree: true, attributes: true, attributeFilter: ['hidden', KIT_LEAVING_ATTR] });
|
|
225
|
+
}
|
|
226
|
+
const onHide = (): void => { if (state.last !== 0) { state.last = 0; postOpen(win, 0); } };
|
|
227
|
+
win.addEventListener('pagehide', onHide);
|
|
228
|
+
state.off = () => { mo?.disconnect(); win.removeEventListener('pagehide', onHide); RUNTIMES.delete(doc); };
|
|
229
|
+
onChange();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** 卸载运行期(测试与应用销毁用) */
|
|
233
|
+
export function uninstallKitOverlayRuntime(doc: Document): void {
|
|
234
|
+
RUNTIMES.get(doc)?.off();
|
|
235
|
+
}
|
package/src/base/popover.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { mergeClass } from '../object-renderer/merge-class';
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
14
|
import { setKitFace } from '../recipes';
|
|
15
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
15
16
|
import {
|
|
16
17
|
KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, handoffTab, onOutsidePress, popPlaceClass, releaseDropdown,
|
|
17
18
|
syncAnchored, syncDropdown, type PopPlace,
|
|
@@ -67,23 +68,23 @@ const HIDDEN = 'hidden';
|
|
|
67
68
|
|
|
68
69
|
const TRIGGER: Record<PopVariant, Record<KitSize, string>> = {
|
|
69
70
|
neutral: {
|
|
70
|
-
sm: '
|
|
71
|
-
md: '
|
|
72
|
-
lg: '
|
|
71
|
+
sm: kitEmphasisButtonRecipe('button.toolbar', { size: 'sm', pointer: true }),
|
|
72
|
+
md: kitEmphasisButtonRecipe('button.toolbar', { size: 'md', pointer: true }),
|
|
73
|
+
lg: kitEmphasisButtonRecipe('button.toolbar', { size: 'lg', pointer: true }),
|
|
73
74
|
},
|
|
74
75
|
primary: {
|
|
75
|
-
sm: 'inline-flex h-
|
|
76
|
-
md: 'inline-flex h-
|
|
76
|
+
sm: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md bg-primary px-2.5 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
77
|
+
md: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
77
78
|
lg: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md bg-primary px-4 text-base font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
78
79
|
},
|
|
79
80
|
danger: {
|
|
80
|
-
sm: 'inline-flex h-
|
|
81
|
-
md: 'inline-flex h-
|
|
81
|
+
sm: 'inline-flex h-6 cursor-pointer items-center justify-center rounded-md bg-danger px-2.5 text-sm font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
82
|
+
md: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-danger px-3 text-sm font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
82
83
|
lg: 'inline-flex h-10 cursor-pointer items-center justify-center rounded-md bg-danger px-4 text-base font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60',
|
|
83
84
|
},
|
|
84
85
|
};
|
|
85
86
|
|
|
86
|
-
const PANEL_BASE = mergeClass(kitOverlayRecipe({ kind: 'popover', size: 'md' }), 'absolute z-10 w-72 border-border-subtle p-3 text-sm focus-visible:outline-none
|
|
87
|
+
const PANEL_BASE = mergeClass(kitOverlayRecipe({ kind: 'popover', size: 'md' }), 'absolute z-10 w-72 border-border-subtle p-3 text-sm focus-visible:outline-none');
|
|
87
88
|
/** placement 字面 -> 偏好位置(贴边时由 popup.ts 的 showPopupFitted 在闭集位置间翻转) */
|
|
88
89
|
export function popPlaceOf(placement: PopPlacement): PopPlace {
|
|
89
90
|
const [side, align] = placement.split('-') as ['top' | 'bottom', 'start' | 'end'];
|
|
@@ -93,7 +94,7 @@ const panelClass = (place: PopPlace): string => `${PANEL_BASE} ${popPlaceClass(p
|
|
|
93
94
|
const TITLE = 'text-sm font-semibold text-fg';
|
|
94
95
|
const BODY = 'mt-2 text-sm text-fg-muted';
|
|
95
96
|
const ACTIONS = mergeClass(kitPopoverActionsRecipe(), 'mt-2');
|
|
96
|
-
const BTN_CANCEL = '
|
|
97
|
+
const BTN_CANCEL = kitEmphasisButtonRecipe('button.toolbar', { pointer: true });
|
|
97
98
|
const BTN_OK: Record<'primary' | 'danger', string> = {
|
|
98
99
|
primary: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-primary px-3 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
99
100
|
danger: 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md bg-danger px-3 text-sm font-medium text-danger-fg transition-colors hover:bg-danger-hover active:bg-danger-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
package/src/base/popup.ts
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
9
9
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
10
10
|
import { kitDirAt } from '../i18n/kit-text';
|
|
11
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
12
|
+
import { leaveAnchored, markAnchored, unmarkAnchored } from './anchored-layer';
|
|
13
|
+
import type { KitLeaveHandle } from './overlay-runtime';
|
|
11
14
|
import {
|
|
12
15
|
createPanelPortalWith, KIT_PANEL_PORTAL_CLASS_CANDIDATES, showAtPoint,
|
|
13
16
|
type PanelPortal, type PointPanel, type PointPanelOptions, type PointXY,
|
|
@@ -25,6 +28,8 @@ type DropdownRules = {
|
|
|
25
28
|
clamps: readonly { cls: string }[];
|
|
26
29
|
};
|
|
27
30
|
const DD = (grammarJson as unknown as { dropdown: DropdownRules }).dropdown;
|
|
31
|
+
/** 下拉 / 菜单面板的表面:浮起级(圆角 + 发丝描边 + 浮起底色 + 双层阴影 + 高光边,recipes/surface.ts 唯一拼装处) */
|
|
32
|
+
const SURFACE_RAISED = kitSurfaceRecipe('raised');
|
|
28
33
|
|
|
29
34
|
export interface ListNavOptions {
|
|
30
35
|
/** 集合宿主(列表容器;接线需要它判断书写方向) */
|
|
@@ -134,12 +139,12 @@ export function focusCellQuiet(node: HTMLElement | null | undefined): void {
|
|
|
134
139
|
/** 默认的整串面板类:显隐只换整串,`hidden` 不与布局类并存 */
|
|
135
140
|
export const PANEL_HIDDEN_CLASS = 'hidden';
|
|
136
141
|
export const PANEL_SHOWN_CLASS =
|
|
137
|
-
`absolute start-0 top-full z-10 mt-1 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto
|
|
142
|
+
`absolute start-0 top-full z-10 mt-1 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto ${SURFACE_RAISED} py-1`;
|
|
138
143
|
|
|
139
144
|
// 选项行高固定(真源 dropdown.rowClass = h-9),面板最大高才能算成「整数行 + 半行」
|
|
140
145
|
const ROW = DD.rowClass;
|
|
141
146
|
export const OPTION_CLASS = {
|
|
142
|
-
idle: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 px-3 text-sm text-fg transition-colors hover:bg-
|
|
147
|
+
idle: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 px-3 text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press`,
|
|
143
148
|
active: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-surface-sunken px-3 text-sm text-fg transition-colors`,
|
|
144
149
|
selected: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors`,
|
|
145
150
|
selectedActive: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors`,
|
|
@@ -158,9 +163,10 @@ export function optionClass(selected: boolean, active: boolean, disabled: boolea
|
|
|
158
163
|
export const KIT_POPUP_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
159
164
|
'hidden', 'absolute', 'start-0', 'top-full', 'z-10', 'mt-1', DD.panelMaxClass, DD.rowClass, 'w-full', 'w-max', 'min-w-full', 'max-w-screen', 'overflow-auto',
|
|
160
165
|
'rounded-md', 'rounded-lg', 'border', 'border-border', 'border-border-subtle', 'bg-surface-raised', 'py-1', DD.panelShadowClass, 'shadow-sm',
|
|
166
|
+
...SURFACE_RAISED.split(/\s+/),
|
|
161
167
|
'flex', 'cursor-pointer', 'cursor-not-allowed', 'items-center', 'whitespace-nowrap', 'gap-2', 'px-3', 'py-2', 'text-sm',
|
|
162
168
|
'text-fg', 'text-fg-subtle', 'bg-surface-sunken', 'font-medium', 'text-primary-on-soft',
|
|
163
|
-
'transition-colors', 'hover:bg-
|
|
169
|
+
'transition-colors', 'hover:bg-state-layer-hover', 'active:bg-state-layer-press', 'bg-primary-soft', 'text-primary-on-soft', 'opacity-60',
|
|
164
170
|
]);
|
|
165
171
|
|
|
166
172
|
/**
|
|
@@ -263,6 +269,19 @@ export function showPopupFitted(
|
|
|
263
269
|
pref: PopPlace,
|
|
264
270
|
classFor: (place: PopPlace) => string,
|
|
265
271
|
gapPx = 8,
|
|
272
|
+
): PopPlace {
|
|
273
|
+
const place = fitPopupPlace(panel, anchor, pref, classFor, gapPx);
|
|
274
|
+
// 锚定浮层统一标记(anchored-layer.ts):落位后的实际方向,重定位 / 翻转时随之更新
|
|
275
|
+
markAnchored(panel, place);
|
|
276
|
+
return place;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function fitPopupPlace(
|
|
280
|
+
panel: HTMLElement,
|
|
281
|
+
anchor: HTMLElement,
|
|
282
|
+
pref: PopPlace,
|
|
283
|
+
classFor: (place: PopPlace) => string,
|
|
284
|
+
gapPx: number,
|
|
266
285
|
): PopPlace {
|
|
267
286
|
panel.className = classFor(pref);
|
|
268
287
|
if (typeof panel.getBoundingClientRect !== 'function') return pref;
|
|
@@ -290,7 +309,7 @@ export const POPUP_TIP_SHOWN_CLASS = popupTipClass(POPUP_TIP_PREF);
|
|
|
290
309
|
|
|
291
310
|
/** 下拉面板外观类(不含位置类):与 PANEL_SHOWN_CLASS 同一份外观 */
|
|
292
311
|
export const PANEL_BASE_CLASS =
|
|
293
|
-
`absolute z-10 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto
|
|
312
|
+
`absolute z-10 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto ${SURFACE_RAISED} py-1`;
|
|
294
313
|
|
|
295
314
|
/** 空间不足时面板内部滚动的 max-h 闭集档位(px = 刻度 x 4),从大到小;每档都是「整数行 + 半行」(真源 dropdown.clamps),空间不够也不腰斩一行 */
|
|
296
315
|
export const DROPDOWN_CLAMPS: readonly { cls: string; px: number }[] = Object.freeze(
|
|
@@ -356,6 +375,18 @@ export function showDropdownFitted(
|
|
|
356
375
|
base: string,
|
|
357
376
|
prefAlign: PopAlign = 'start',
|
|
358
377
|
gap: 1 | 2 = 1,
|
|
378
|
+
): PopPlace {
|
|
379
|
+
const place = fitDropdownPlace(panel, anchor, base, prefAlign, gap);
|
|
380
|
+
markAnchored(panel, place);
|
|
381
|
+
return place;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function fitDropdownPlace(
|
|
385
|
+
panel: HTMLElement,
|
|
386
|
+
anchor: HTMLElement,
|
|
387
|
+
base: string,
|
|
388
|
+
prefAlign: PopAlign,
|
|
389
|
+
gap: 1 | 2,
|
|
359
390
|
): PopPlace {
|
|
360
391
|
const classFor = (place: PopPlace): string => `${base} ${popPlaceClass(place, gap)}`;
|
|
361
392
|
const pref: PopPlace = { side: 'bottom', align: prefAlign };
|
|
@@ -471,6 +502,7 @@ export function releaseDropdownsIn(scope: Element): void {
|
|
|
471
502
|
|
|
472
503
|
/** 收起并放回原位(restore)或直接销毁(组件卸载) */
|
|
473
504
|
export function releaseDropdown(panel: HTMLElement, restore = true): void {
|
|
505
|
+
cancelLeave(panel);
|
|
474
506
|
const m = DROPDOWN_MOUNTS.get(panel);
|
|
475
507
|
if (!m) return;
|
|
476
508
|
DROPDOWN_MOUNTS.delete(panel);
|
|
@@ -479,6 +511,33 @@ export function releaseDropdown(panel: HTMLElement, restore = true): void {
|
|
|
479
511
|
else m.portal.destroy();
|
|
480
512
|
}
|
|
481
513
|
|
|
514
|
+
// ── 锚定面板的出场 ──
|
|
515
|
+
// 收起时有退场动画(anchored-layer 的 leaveAnchored:标 data-kit-leaving + inert,等动画结束,带超时兜底)就先播完再放回原位并整串 hidden;
|
|
516
|
+
// 没有(无关键帧 / jsdom)立即收尾,行为与改动前一致。退场中被重新打开 / 被销毁时撤销退场。
|
|
517
|
+
const LEAVING = new WeakMap<HTMLElement, KitLeaveHandle>();
|
|
518
|
+
|
|
519
|
+
function cancelLeave(panel: HTMLElement): void {
|
|
520
|
+
LEAVING.get(panel)?.cancel();
|
|
521
|
+
LEAVING.delete(panel);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** 收起锚定面板:已挂出且有退场动画 -> 播完再放回 + hidden;否则立即放回 + hidden */
|
|
525
|
+
function retireAnchored(panel: HTMLElement): void {
|
|
526
|
+
if (LEAVING.has(panel)) return;
|
|
527
|
+
const finish = (): void => {
|
|
528
|
+
LEAVING.delete(panel);
|
|
529
|
+
releaseDropdown(panel);
|
|
530
|
+
panel.className = PANEL_HIDDEN_CLASS;
|
|
531
|
+
unmarkAnchored(panel);
|
|
532
|
+
};
|
|
533
|
+
if (!DROPDOWN_MOUNTS.has(panel)) {
|
|
534
|
+
panel.className = PANEL_HIDDEN_CLASS;
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
const handle = leaveAnchored(panel, finish);
|
|
538
|
+
if (handle !== null) LEAVING.set(panel, handle);
|
|
539
|
+
}
|
|
540
|
+
|
|
482
541
|
/** 挂到端口并落位;返回实际锚点,端口不可用返回 null(调用方走原位) */
|
|
483
542
|
function mountAnchored(panel: HTMLElement, anchor: HTMLElement | undefined, pref: PopPlace, fit: (p: HTMLElement, box: HTMLElement) => PopPlace): HTMLElement | null {
|
|
484
543
|
const prev = DROPDOWN_MOUNTS.get(panel);
|
|
@@ -505,10 +564,10 @@ function mountAnchored(panel: HTMLElement, anchor: HTMLElement | undefined, pref
|
|
|
505
564
|
*/
|
|
506
565
|
export function syncDropdown(panel: HTMLElement, open: boolean, base: string = PANEL_BASE_CLASS, anchor?: HTMLElement, prefAlign: PopAlign = 'start'): void {
|
|
507
566
|
if (!open) {
|
|
508
|
-
|
|
509
|
-
panel.className = PANEL_HIDDEN_CLASS;
|
|
567
|
+
retireAnchored(panel);
|
|
510
568
|
return;
|
|
511
569
|
}
|
|
570
|
+
cancelLeave(panel);
|
|
512
571
|
const live = `${base} ${DROPDOWN_LIVE_CLASS}`;
|
|
513
572
|
const at = mountAnchored(panel, anchor, { side: 'bottom', align: prefAlign }, (p, box) => showDropdownFitted(p, box, live, prefAlign));
|
|
514
573
|
if (at === null) showDropdownFitted(panel, anchor ?? panel.parentElement ?? panel, base, prefAlign);
|
|
@@ -522,10 +581,10 @@ export function syncAnchored(
|
|
|
522
581
|
panel: HTMLElement, open: boolean, anchor: HTMLElement, pref: PopPlace, classFor: (place: PopPlace) => string, gapPx?: number,
|
|
523
582
|
): void {
|
|
524
583
|
if (!open) {
|
|
525
|
-
|
|
526
|
-
panel.className = PANEL_HIDDEN_CLASS;
|
|
584
|
+
retireAnchored(panel);
|
|
527
585
|
return;
|
|
528
586
|
}
|
|
587
|
+
cancelLeave(panel);
|
|
529
588
|
const live = (place: PopPlace): string => `${classFor(place)} ${DROPDOWN_LIVE_CLASS}`;
|
|
530
589
|
const at = mountAnchored(panel, anchor, pref, (p, box) => showPopupFitted(p, box, pref, live, gapPx));
|
|
531
590
|
if (at === null) showPopupFitted(panel, anchor, pref, classFor, gapPx);
|
package/src/base/portal-core.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { getOverlayHost } from 'soma-core/behavior';
|
|
13
13
|
import type { OverlayMount } from 'soma-core/behavior';
|
|
14
14
|
import type { PopPlace } from './popup';
|
|
15
|
+
import { markAnchored, unmarkAnchored } from './anchored-layer';
|
|
15
16
|
|
|
16
17
|
export interface KitOverlayOptions {
|
|
17
18
|
/** 逻辑所有者(组件宿主 / 触发元素):作用域属性从它取,它脱离文档后浮层自动卸载 */
|
|
@@ -124,6 +125,8 @@ export function showAtPoint(panel: HTMLElement, point: PointXY, opts: PointPanel
|
|
|
124
125
|
});
|
|
125
126
|
if (!mount) return null;
|
|
126
127
|
placeAtPoint(panel, point, { rtl: opts.rtl === true, resolve: opts.resolve });
|
|
128
|
+
// 按落点定位的菜单(右键菜单)同属锚定浮层:进场由 [data-kit-anchored] 规则统一驱动(落点在上方,面板向下展开)
|
|
129
|
+
markAnchored(panel, { side: 'bottom' });
|
|
127
130
|
const onMove = (event?: Event): void => {
|
|
128
131
|
const t = event?.target;
|
|
129
132
|
if (t instanceof Node && panel.contains(t)) return;
|
|
@@ -140,6 +143,7 @@ export function showAtPoint(panel: HTMLElement, point: PointXY, opts: PointPanel
|
|
|
140
143
|
hide(restore = true): void {
|
|
141
144
|
if (!alive) return;
|
|
142
145
|
alive = false;
|
|
146
|
+
unmarkAnchored(panel);
|
|
143
147
|
if (opts.onViewportChange && hasWindow) {
|
|
144
148
|
window.removeEventListener('resize', onMove);
|
|
145
149
|
document.removeEventListener('scroll', onMove, true);
|
package/src/base/qty-stepper.ts
CHANGED
|
@@ -14,16 +14,16 @@ import { kitText } from '../i18n/kit-text';
|
|
|
14
14
|
import { setKitFace } from '../recipes';
|
|
15
15
|
|
|
16
16
|
const GROUP: Record<KitSize, string> = {
|
|
17
|
-
sm: 'inline-flex h-
|
|
18
|
-
md: 'inline-flex h-
|
|
17
|
+
sm: 'inline-flex h-6 items-stretch overflow-hidden rounded-md border border-input bg-surface text-sm transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
|
|
18
|
+
md: 'inline-flex h-8 items-stretch overflow-hidden rounded-md border border-input bg-surface text-sm transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
|
|
19
19
|
lg: 'inline-flex h-10 items-stretch overflow-hidden rounded-md border border-input bg-surface text-base transition-colors focus-within:border-primary focus-within:ring-2 focus-within:ring-ring',
|
|
20
20
|
};
|
|
21
21
|
const GROUP_OFF: Record<KitSize, string> = {
|
|
22
|
-
sm: 'inline-flex h-
|
|
23
|
-
md: 'inline-flex h-
|
|
22
|
+
sm: 'inline-flex h-6 items-stretch overflow-hidden rounded-md border border-input bg-surface-sunken text-sm opacity-60',
|
|
23
|
+
md: 'inline-flex h-8 items-stretch overflow-hidden rounded-md border border-input bg-surface-sunken text-sm opacity-60',
|
|
24
24
|
lg: 'inline-flex h-10 items-stretch overflow-hidden rounded-md border border-input bg-surface-sunken text-base opacity-60',
|
|
25
25
|
};
|
|
26
|
-
const BTN_ON = 'inline-flex w-8 shrink-0 cursor-pointer items-center justify-center text-fg-muted transition-colors hover:bg-
|
|
26
|
+
const BTN_ON = 'inline-flex w-8 shrink-0 cursor-pointer items-center justify-center text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
27
27
|
const BTN_OFF = 'inline-flex w-8 shrink-0 cursor-not-allowed items-center justify-center text-fg-subtle opacity-60';
|
|
28
28
|
// 无 preflight:input 不继承分组的字号(浏览器默认 13px),所以按档位自己写 text-sm / text-base
|
|
29
29
|
export const STEPPER_INPUT: Record<KitSize, string> = {
|