soma-kit 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/data/prompt-dialog.ts +0 -235
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
package/src/base/menu-button.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
applyCommon, bool, classCandidates, createKitController, joinClass, paintBadge, setBoolAttr, sizeOf, str, withBadgeAnchor, withTooltip,
|
|
11
11
|
type KitSize, type KitView,
|
|
12
12
|
} from './shared';
|
|
13
|
+
import { setKitFace } from '../recipes';
|
|
13
14
|
import { menuItemsOf, wireMenu, type MenuClasses, type MenuHandle } from './menu-core';
|
|
14
15
|
import { KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, popPlaceClass, type PopPlace } from './popup';
|
|
15
16
|
import {
|
|
@@ -176,6 +177,8 @@ function makeView(): KitView {
|
|
|
176
177
|
applyCommon(btn, { id: split ? '' : p.id, aria_label: split ? str(p.more_label, kitText('soma.kit.more_actions', undefined, btn)) : p.aria_label });
|
|
177
178
|
const base = ctx ? (off ? CONTEXT_AREA_OFF : CONTEXT_AREA) : TRIGGER_CLASS[variant][size];
|
|
178
179
|
btn.className = split ? `${base} ${SPLIT_TRIGGER_CLASS[variant]}` : base;
|
|
180
|
+
// 质感标记:实心 / 描边变体有面标 raised;ghost 与右键虚线区不标
|
|
181
|
+
setKitFace(btn, ctx || variant === 'ghost' ? null : 'raised');
|
|
179
182
|
}
|
|
180
183
|
if (main) {
|
|
181
184
|
if (split) {
|
|
@@ -185,8 +188,10 @@ function makeView(): KitView {
|
|
|
185
188
|
else main.removeAttribute('aria-disabled');
|
|
186
189
|
applyCommon(main, { id: p.id, aria_label: p.aria_label });
|
|
187
190
|
main.className = `${TRIGGER_CLASS[variant][size]} ${SPLIT_MAIN_CLASS}`;
|
|
191
|
+
setKitFace(main, variant === 'ghost' ? null : 'raised');
|
|
188
192
|
badgeHost = main;
|
|
189
193
|
} else {
|
|
194
|
+
setKitFace(main, null);
|
|
190
195
|
main.textContent = '';
|
|
191
196
|
main.className = MENU_HIDDEN;
|
|
192
197
|
}
|
|
@@ -235,6 +240,6 @@ export function createMenuButton(): SomaComponentDefinition {
|
|
|
235
240
|
},
|
|
236
241
|
},
|
|
237
242
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"><button type="button" class="${TRIGGER_CLASS.neutral.md}"><span></span><span aria-hidden="true" class="${CARET_CLASS}">${kitIconHtml('chevron-down', 'sm')}</span></button><div class="${MENU_HIDDEN}"></div><button type="button" class="${MENU_HIDDEN}"></button></div>`,
|
|
238
|
-
controllerFactory: (
|
|
243
|
+
controllerFactory: createKitController(() => withTooltip(makeView(), tooltipTarget)),
|
|
239
244
|
};
|
|
240
245
|
}
|
package/src/base/menu-core.ts
CHANGED
|
@@ -11,6 +11,7 @@ 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
13
|
import { nextUid } from './shared';
|
|
14
|
+
import { setKitFace, type KitFaceKind } from '../recipes';
|
|
14
15
|
|
|
15
16
|
/** 浮层端口缺失时的降级提示,整个页面只提示一次 */
|
|
16
17
|
let pointFallbackWarned = false;
|
|
@@ -98,6 +99,8 @@ export interface MenuWireOptions {
|
|
|
98
99
|
/** 按点挂出时的整串面板类(必须含 fixed) */
|
|
99
100
|
pointClass?: string;
|
|
100
101
|
classes: MenuClasses;
|
|
102
|
+
/** 菜单项自带底色 + 边框 + 阴影(Fab 的药丸项)时给每项打质感标记;平铺菜单项不传 */
|
|
103
|
+
rowFace?: KitFaceKind;
|
|
101
104
|
items: () => MenuItemSpec[];
|
|
102
105
|
/** 触发钮被禁用 / 只读:不能打开 */
|
|
103
106
|
locked: () => boolean;
|
|
@@ -174,6 +177,7 @@ export function wireMenu(o: MenuWireOptions): MenuHandle {
|
|
|
174
177
|
const el = elOf(item.key);
|
|
175
178
|
if (!el) continue;
|
|
176
179
|
el.className = classOf(item);
|
|
180
|
+
if (o.rowFace) setKitFace(el, o.rowFace);
|
|
177
181
|
if (item.disabled) el.setAttribute('aria-disabled', 'true');
|
|
178
182
|
else el.removeAttribute('aria-disabled');
|
|
179
183
|
}
|
package/src/base/motion/aura.ts
CHANGED
|
@@ -71,7 +71,7 @@ export function createAura(): SomaComponentDefinition {
|
|
|
71
71
|
'</div>',
|
|
72
72
|
'</div>',
|
|
73
73
|
].join(''),
|
|
74
|
-
controllerFactory: createKitController({
|
|
74
|
+
controllerFactory: createKitController(() => ({
|
|
75
75
|
render(root, p) {
|
|
76
76
|
const halo = part(root, 'halo');
|
|
77
77
|
const box = part(root, 'box');
|
|
@@ -89,6 +89,6 @@ export function createAura(): SomaComponentDefinition {
|
|
|
89
89
|
text.textContent = content;
|
|
90
90
|
text.className = content === '' ? HIDDEN : TEXT_CLASS;
|
|
91
91
|
},
|
|
92
|
-
}),
|
|
92
|
+
})),
|
|
93
93
|
};
|
|
94
94
|
}
|
|
@@ -146,9 +146,9 @@ export function createHover3d(): SomaComponentDefinition {
|
|
|
146
146
|
'</a>',
|
|
147
147
|
'</div>',
|
|
148
148
|
].join(''),
|
|
149
|
-
controllerFactory: createKitController({
|
|
149
|
+
controllerFactory: createKitController(() => ({
|
|
150
150
|
attach: attachTilt,
|
|
151
151
|
render: renderTilt,
|
|
152
|
-
}),
|
|
152
|
+
})),
|
|
153
153
|
};
|
|
154
154
|
}
|
|
@@ -177,9 +177,9 @@ export function createHoverGallery(): SomaComponentDefinition {
|
|
|
177
177
|
`<span data-soma-id="status" role="status" class="${SR_ONLY}"></span>`,
|
|
178
178
|
'</div>',
|
|
179
179
|
].join(''),
|
|
180
|
-
controllerFactory: createKitController({
|
|
180
|
+
controllerFactory: createKitController(() => ({
|
|
181
181
|
attach: attachGallery,
|
|
182
182
|
render: renderGallery,
|
|
183
|
-
}),
|
|
183
|
+
})),
|
|
184
184
|
};
|
|
185
185
|
}
|
|
@@ -149,9 +149,9 @@ export function createMarquee(): SomaComponentDefinition {
|
|
|
149
149
|
`<button data-soma-id="pause" type="button" aria-pressed="false" class="${HIDDEN}">⏸</button>`,
|
|
150
150
|
'</div>',
|
|
151
151
|
].join(''),
|
|
152
|
-
controllerFactory: createKitController({
|
|
152
|
+
controllerFactory: createKitController(() => ({
|
|
153
153
|
attach: attachMarquee,
|
|
154
154
|
render: renderMarquee,
|
|
155
|
-
}),
|
|
155
|
+
})),
|
|
156
156
|
};
|
|
157
157
|
}
|
|
@@ -187,9 +187,9 @@ export function createTextRotate(): SomaComponentDefinition {
|
|
|
187
187
|
`<span data-soma-id="all" class="${SR_ONLY}"></span>`,
|
|
188
188
|
'</span>',
|
|
189
189
|
].join(''),
|
|
190
|
-
controllerFactory: createKitController({
|
|
190
|
+
controllerFactory: createKitController(() => ({
|
|
191
191
|
attach: attachRotate,
|
|
192
192
|
render: renderRotate,
|
|
193
|
-
}),
|
|
193
|
+
})),
|
|
194
194
|
};
|
|
195
195
|
}
|
package/src/base/number.ts
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
// Number:数字输入,处理 min / max / step。自绘数字框(qty-stepper.ts 的 attachSpin:type=text + inputmode=decimal + role=spinbutton,
|
|
2
2
|
// 输入过滤、↑↓ PageUp/PageDown Home/End 调值、aria-valuenow/min/max),不用系统原生 type=number。
|
|
3
|
-
//
|
|
4
|
-
//
|
|
3
|
+
// 交互传输层铁律:输入与失焦(change)如实上报用户输入解析出的数值(空或残余中间态符号为 null),
|
|
4
|
+
// 不在 blur / input 时把超出 min / max 的手输值静默截断改写为 min / max(超界交由校验规则报错;步进按钮受 min / max 禁用控制不变)。
|
|
5
5
|
|
|
6
6
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
7
7
|
import {
|
|
8
|
-
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
9
|
-
FIELD_CLASS, applyCommon, applyDisabled, bool, createKitController, joinClass, num, setBoolAttr, sizeOf, str, type KitSize,
|
|
8
|
+
CLASS_PROP, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
9
|
+
FIELD_CLASS, applyCommon, applyDisabled, bool, createKitController, joinClass, num, setBoolAttr, sizeOf, str, withInvalid, type KitSize,
|
|
10
10
|
} from './shared';
|
|
11
11
|
import { STEPPER_INPUT, attachStepper, type StepperHandle } from './qty-stepper';
|
|
12
12
|
|
|
13
13
|
const NUMBER_CLASS: Record<KitSize, string> = { sm: FIELD_CLASS.sm, md: FIELD_CLASS.md, lg: FIELD_CLASS.lg };
|
|
14
14
|
const steppers = new WeakMap<HTMLElement, StepperHandle>();
|
|
15
15
|
|
|
16
|
-
function clamp(n: number, min: number | null, max: number | null): number {
|
|
17
|
-
let out = n;
|
|
18
|
-
if (min !== null && out < min) out = min;
|
|
19
|
-
if (max !== null && out > max) out = max;
|
|
20
|
-
return out;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
16
|
export function createNumber(): SomaComponentDefinition {
|
|
24
17
|
return {
|
|
25
18
|
contract: {
|
|
@@ -38,6 +31,7 @@ export function createNumber(): SomaComponentDefinition {
|
|
|
38
31
|
disabled: { type: 'boolean', default: false },
|
|
39
32
|
readonly: { type: 'boolean', default: false },
|
|
40
33
|
...ID_PROPS,
|
|
34
|
+
...INVALID_PROPS,
|
|
41
35
|
size: SIZE_PROP,
|
|
42
36
|
class: CLASS_PROP,
|
|
43
37
|
},
|
|
@@ -45,77 +39,96 @@ export function createNumber(): SomaComponentDefinition {
|
|
|
45
39
|
change: { payload: { value: { type: 'number' } }, desc: '数值变化(空为 null);disabled / readonly 时不抛' },
|
|
46
40
|
},
|
|
47
41
|
},
|
|
48
|
-
templateHtml: `<input data-soma-id="root" type="text" inputmode="decimal" role="spinbutton" autocomplete="off" class="${NUMBER_CLASS.md}" />`,
|
|
49
|
-
controllerFactory: createKitController({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
42
|
+
templateHtml: `<input data-soma-id="root" type="text" inputmode="decimal" role="spinbutton" autocomplete="off" data-kit-face="field" class="${NUMBER_CLASS.md}" />`,
|
|
43
|
+
controllerFactory: createKitController(() => {
|
|
44
|
+
let last: number | null | undefined;
|
|
45
|
+
return {
|
|
46
|
+
attach(root, api) {
|
|
47
|
+
const el = root as HTMLInputElement;
|
|
48
|
+
let stepperRef: { refresh(): void } | null = null;
|
|
49
|
+
const locked = (): boolean => {
|
|
50
|
+
const p = api.props();
|
|
51
|
+
return bool(p.disabled) || bool(p.readonly);
|
|
52
|
+
};
|
|
53
|
+
const onInput = (): void => {
|
|
54
|
+
if (locked()) return;
|
|
55
|
+
if (el.value === '') {
|
|
56
|
+
last = null;
|
|
57
|
+
api.emit('change', { value: null });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const n = Number(el.value);
|
|
61
|
+
if (!Number.isFinite(n)) return;
|
|
62
|
+
last = n;
|
|
63
|
+
api.emit('change', { value: n });
|
|
64
|
+
};
|
|
65
|
+
const onCommit = (): void => {
|
|
66
|
+
if (locked()) return;
|
|
67
|
+
if (el.value === '') {
|
|
68
|
+
if (last !== null) {
|
|
69
|
+
last = null;
|
|
70
|
+
api.emit('change', { value: null });
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const raw = Number(el.value);
|
|
75
|
+
if (!Number.isFinite(raw)) {
|
|
76
|
+
el.value = '';
|
|
77
|
+
stepperRef?.refresh();
|
|
78
|
+
if (last !== null) {
|
|
79
|
+
last = null;
|
|
80
|
+
api.emit('change', { value: null });
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (raw !== last) {
|
|
85
|
+
last = raw;
|
|
86
|
+
api.emit('change', { value: raw });
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
// 数字输入自绘核心(spinbutton:过滤、键盘步进、aria-value*)要先于下面的 input 监听挂上,过滤先于读值
|
|
90
|
+
const stepper = attachStepper(el, () => api.props());
|
|
91
|
+
steppers.set(el, stepper);
|
|
92
|
+
stepperRef = stepper;
|
|
93
|
+
el.addEventListener('input', onInput);
|
|
94
|
+
el.addEventListener('change', onCommit);
|
|
95
|
+
el.addEventListener('blur', onCommit);
|
|
96
|
+
return () => {
|
|
97
|
+
el.removeEventListener('input', onInput);
|
|
98
|
+
el.removeEventListener('change', onCommit);
|
|
99
|
+
el.removeEventListener('blur', onCommit);
|
|
100
|
+
stepper.destroy();
|
|
101
|
+
steppers.delete(el);
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
render(root, p) {
|
|
105
|
+
const el = root as HTMLInputElement;
|
|
106
|
+
const v = num(p.value);
|
|
107
|
+
const next = v === null ? '' : String(v);
|
|
108
|
+
// 空输入框的 Number('') 是 0:value 为 0 时不能用数值相等判「已同步」
|
|
109
|
+
if (el.value !== next && (el.value === '' || Number(el.value) !== v)) {
|
|
110
|
+
el.value = next;
|
|
111
|
+
last = v;
|
|
112
|
+
} else if (last === undefined) {
|
|
113
|
+
last = v;
|
|
79
114
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
115
|
+
el.placeholder = str(p.placeholder);
|
|
116
|
+
setBoolAttr(el, 'readonly', bool(p.readonly));
|
|
117
|
+
applyDisabled(el, bool(p.disabled));
|
|
118
|
+
applyCommon(el, p);
|
|
119
|
+
const invalid = bool(p.invalid);
|
|
120
|
+
// variant: stepper:输入框包进分组并加 [-] [+](见 qty-stepper.ts);其余形态原样
|
|
121
|
+
const stepper = steppers.get(el);
|
|
122
|
+
stepper?.sync(p);
|
|
123
|
+
if (stepper?.active()) {
|
|
124
|
+
el.className = STEPPER_INPUT[sizeOf(p.size)];
|
|
125
|
+
const group = el.parentElement;
|
|
126
|
+
if (group) group.className = joinClass(withInvalid(group.className, invalid), p.class);
|
|
127
|
+
} else {
|
|
128
|
+
el.className = joinClass(withInvalid(NUMBER_CLASS[sizeOf(p.size)], invalid), p.class);
|
|
83
129
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const stepper = attachStepper(el, () => api.props());
|
|
87
|
-
steppers.set(el, stepper);
|
|
88
|
-
stepperRef = stepper;
|
|
89
|
-
el.addEventListener('input', onInput);
|
|
90
|
-
el.addEventListener('change', onCommit);
|
|
91
|
-
return () => {
|
|
92
|
-
el.removeEventListener('input', onInput);
|
|
93
|
-
el.removeEventListener('change', onCommit);
|
|
94
|
-
stepper.destroy();
|
|
95
|
-
steppers.delete(el);
|
|
96
|
-
};
|
|
97
|
-
},
|
|
98
|
-
render(root, p) {
|
|
99
|
-
const el = root as HTMLInputElement;
|
|
100
|
-
const v = num(p.value);
|
|
101
|
-
const next = v === null ? '' : String(v);
|
|
102
|
-
// 空输入框的 Number('') 是 0:value 为 0 时不能用数值相等判「已同步」
|
|
103
|
-
if (el.value !== next && (el.value === '' || Number(el.value) !== v)) el.value = next;
|
|
104
|
-
el.placeholder = str(p.placeholder);
|
|
105
|
-
setBoolAttr(el, 'readonly', bool(p.readonly));
|
|
106
|
-
applyDisabled(el, bool(p.disabled));
|
|
107
|
-
applyCommon(el, p);
|
|
108
|
-
// variant: stepper:输入框包进分组并加 [-] [+](见 qty-stepper.ts);其余形态原样
|
|
109
|
-
const stepper = steppers.get(el);
|
|
110
|
-
stepper?.sync(p);
|
|
111
|
-
if (stepper?.active()) {
|
|
112
|
-
el.className = STEPPER_INPUT[sizeOf(p.size)];
|
|
113
|
-
const group = el.parentElement;
|
|
114
|
-
if (group) group.className = joinClass(group.className, p.class);
|
|
115
|
-
} else {
|
|
116
|
-
el.className = joinClass(NUMBER_CLASS[sizeOf(p.size)], p.class);
|
|
117
|
-
}
|
|
118
|
-
},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
119
132
|
}),
|
|
120
133
|
};
|
|
121
134
|
}
|
package/src/base/otp.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
7
7
|
import { kitKey, kitText } from '../i18n/kit-text';
|
|
8
|
+
import { setKitFace } from '../recipes';
|
|
8
9
|
import {
|
|
9
10
|
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
10
11
|
bool, classCandidates, createKitController, joinClass, num, setAttr, setBoolAttr, sizeOf, str,
|
|
@@ -221,6 +222,8 @@ function makeView(): KitView {
|
|
|
221
222
|
setBoolAttr(cell, 'readonly', readonly);
|
|
222
223
|
setBoolAttr(cell, 'disabled', disabled);
|
|
223
224
|
cell.className = CELL_CLASS[size];
|
|
225
|
+
// 质感标记:每个格子都是独立带边框的输入(field)
|
|
226
|
+
setKitFace(cell, 'field');
|
|
224
227
|
});
|
|
225
228
|
completed = chars.length === length;
|
|
226
229
|
root.setAttribute('role', 'group');
|
|
@@ -254,6 +257,6 @@ export function createOtp(): SomaComponentDefinition {
|
|
|
254
257
|
},
|
|
255
258
|
},
|
|
256
259
|
templateHtml: `<div data-soma-id="root" role="group" class="${GROUP_CLASS}"></div>`,
|
|
257
|
-
controllerFactory: (
|
|
260
|
+
controllerFactory: createKitController(() => makeView()),
|
|
258
261
|
};
|
|
259
262
|
}
|
|
@@ -97,3 +97,9 @@ export function withPermissionGate(ctx: SomaComponentControllerContext, inner: C
|
|
|
97
97
|
};
|
|
98
98
|
return { ...inner, onMount: wrap('onMount'), onPropsChange: wrap('onPropsChange'), onUnmount };
|
|
99
99
|
}
|
|
100
|
+
|
|
101
|
+
/** 注册单个实例的权限门回调,返回注销函数(供 createKitController 统一托管) */
|
|
102
|
+
export function registerLivePermissionGate(apply: () => void): () => void {
|
|
103
|
+
liveGates.add(apply);
|
|
104
|
+
return () => { liveGates.delete(apply); };
|
|
105
|
+
}
|
package/src/base/popover.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
1
2
|
// Popover(通用气泡卡片)与 Popconfirm(气泡确认)。D8 组。
|
|
2
3
|
//
|
|
3
4
|
// 归类(2.1a 四问):触发钮 + 一小块浮出的文字 / 确认条,不带对象形状 -> 基础组件。
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
|
|
11
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
12
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
|
+
import { setKitFace } from '../recipes';
|
|
13
15
|
import {
|
|
14
16
|
KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, handoffTab, onOutsidePress, popPlaceClass, releaseDropdown,
|
|
15
17
|
syncAnchored, syncDropdown, type PopPlace,
|
|
@@ -21,6 +23,31 @@ import {
|
|
|
21
23
|
applyCommon, bool, classCandidates, createKitController, joinClass, nextUid, sizeOf, str,
|
|
22
24
|
type KitApi, type KitProps, type KitSize,
|
|
23
25
|
} from './shared';
|
|
26
|
+
import {
|
|
27
|
+
KIT_PART_DIALOG,
|
|
28
|
+
KIT_PART_DRAWER,
|
|
29
|
+
KIT_PART_POPOVER,
|
|
30
|
+
kitOverlayBodyRecipe,
|
|
31
|
+
kitOverlayFooterRecipe,
|
|
32
|
+
kitOverlayHeaderRecipe,
|
|
33
|
+
kitPopoverActionsRecipe,
|
|
34
|
+
kitOverlayPartOf,
|
|
35
|
+
kitOverlayRecipe,
|
|
36
|
+
} from '../recipes/overlay';
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
KIT_PART_DIALOG,
|
|
40
|
+
KIT_PART_DRAWER,
|
|
41
|
+
KIT_PART_POPOVER,
|
|
42
|
+
kitOverlayRecipe,
|
|
43
|
+
kitOverlayHeaderRecipe,
|
|
44
|
+
kitPopoverActionsRecipe,
|
|
45
|
+
kitOverlayBodyRecipe,
|
|
46
|
+
kitOverlayFooterRecipe,
|
|
47
|
+
kitOverlayPartOf,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
24
51
|
|
|
25
52
|
export type PopPlacement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end';
|
|
26
53
|
const PLACEMENTS: readonly PopPlacement[] = ['bottom-start', 'bottom-end', 'top-start', 'top-end'];
|
|
@@ -56,7 +83,7 @@ const TRIGGER: Record<PopVariant, Record<KitSize, string>> = {
|
|
|
56
83
|
},
|
|
57
84
|
};
|
|
58
85
|
|
|
59
|
-
const PANEL_BASE = 'absolute z-10 w-72
|
|
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 motion-safe:animate-kit-menu-in');
|
|
60
87
|
/** placement 字面 -> 偏好位置(贴边时由 popup.ts 的 showPopupFitted 在闭集位置间翻转) */
|
|
61
88
|
export function popPlaceOf(placement: PopPlacement): PopPlace {
|
|
62
89
|
const [side, align] = placement.split('-') as ['top' | 'bottom', 'start' | 'end'];
|
|
@@ -65,7 +92,7 @@ export function popPlaceOf(placement: PopPlacement): PopPlace {
|
|
|
65
92
|
const panelClass = (place: PopPlace): string => `${PANEL_BASE} ${popPlaceClass(place, 2)}`;
|
|
66
93
|
const TITLE = 'text-sm font-semibold text-fg';
|
|
67
94
|
const BODY = 'mt-2 text-sm text-fg-muted';
|
|
68
|
-
const ACTIONS = 'mt-2
|
|
95
|
+
const ACTIONS = mergeClass(kitPopoverActionsRecipe(), 'mt-2');
|
|
69
96
|
const BTN_CANCEL = 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md border border-border bg-surface px-3 text-sm text-fg transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
70
97
|
const BTN_OK: Record<'primary' | 'danger', string> = {
|
|
71
98
|
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',
|
|
@@ -115,6 +142,9 @@ export function wirePopLayer(o: PopLayerOptions): PopLayer {
|
|
|
115
142
|
const panelId = panel.id !== '' ? panel.id : nextUid('kit-pop');
|
|
116
143
|
panel.id = panelId;
|
|
117
144
|
panel.setAttribute('role', 'dialog');
|
|
145
|
+
if (!panel.hasAttribute('data-kit-part')) {
|
|
146
|
+
panel.setAttribute('data-kit-part', kitOverlayPartOf('popover'));
|
|
147
|
+
}
|
|
118
148
|
panel.tabIndex = -1;
|
|
119
149
|
|
|
120
150
|
const paint = (): void => {
|
|
@@ -237,6 +267,8 @@ function paintCommon(root: HTMLElement, p: KitProps, st: PopState): void {
|
|
|
237
267
|
const variant = popVariantOf(p.variant);
|
|
238
268
|
trigger.textContent = str(p.label);
|
|
239
269
|
trigger.className = TRIGGER[variant][sizeOf(p.size)];
|
|
270
|
+
// 触发钮三个变体都有底 / 边,同 Button 标 raised
|
|
271
|
+
setKitFace(trigger, 'raised');
|
|
240
272
|
trigger.disabled = bool(p.disabled);
|
|
241
273
|
applyCommon(trigger, { id: p.id, aria_label: p.aria_label });
|
|
242
274
|
title.textContent = str(p.title);
|
|
@@ -297,11 +329,11 @@ export function createPopover(): SomaComponentDefinition {
|
|
|
297
329
|
},
|
|
298
330
|
templateHtml:
|
|
299
331
|
`${TEMPLATE_HEAD}<div data-soma-id="actions" class="${ACTIONS}">` +
|
|
300
|
-
`<button data-soma-id="cancel" type="button" class="${BTN_CANCEL}"></button>` +
|
|
301
|
-
`<button data-soma-id="ok" type="button" class="${BTN_OK.primary}"></button></div></div></div>`,
|
|
302
|
-
controllerFactory: (
|
|
332
|
+
`<button data-soma-id="cancel" type="button" data-kit-face="raised" class="${BTN_CANCEL}"></button>` +
|
|
333
|
+
`<button data-soma-id="ok" type="button" data-kit-face="raised" class="${BTN_OK.primary}"></button></div></div></div>`,
|
|
334
|
+
controllerFactory: createKitController(() => {
|
|
303
335
|
const st: PopState = { layer: null, api: null, lastOpenProp: null };
|
|
304
|
-
return
|
|
336
|
+
return {
|
|
305
337
|
attach(root, api) {
|
|
306
338
|
st.api = api;
|
|
307
339
|
const ok = part(root, 'ok');
|
|
@@ -346,7 +378,7 @@ export function createPopover(): SomaComponentDefinition {
|
|
|
346
378
|
ok.className = BTN_OK[p.confirm_variant === 'danger' ? 'danger' : 'primary'];
|
|
347
379
|
part(root, 'actions').className = bool(p.confirm) ? ACTIONS : HIDDEN;
|
|
348
380
|
},
|
|
349
|
-
}
|
|
350
|
-
},
|
|
381
|
+
};
|
|
382
|
+
}),
|
|
351
383
|
};
|
|
352
384
|
}
|
package/src/base/popup.ts
CHANGED
|
@@ -49,6 +49,11 @@ export interface ListNav {
|
|
|
49
49
|
handle(event: KeyboardEvent): boolean;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/** 判断键盘事件是否处于 IME 输入法合成中(选词阶段) */
|
|
53
|
+
export function isImeComposing(event: KeyboardEvent): boolean {
|
|
54
|
+
return event.isComposing || event.keyCode === 229;
|
|
55
|
+
}
|
|
56
|
+
|
|
52
57
|
export function createListNav(o: ListNavOptions): ListNav {
|
|
53
58
|
const pageStep = SOMA_SIZE_UNITS.collection.keyboard.pageStep;
|
|
54
59
|
const textFocus = o.textFocus === true;
|
|
@@ -74,6 +79,7 @@ export function createListNav(o: ListNavOptions): ListNav {
|
|
|
74
79
|
const wiring = createKeyboardWiring(wiringOptions);
|
|
75
80
|
return {
|
|
76
81
|
handle(event) {
|
|
82
|
+
if (isImeComposing(event)) return false;
|
|
77
83
|
if (textFocus && (event.key === 'Home' || event.key === 'End' || event.key === ' ')) return false;
|
|
78
84
|
return wiring.onKeydown(event);
|
|
79
85
|
},
|
|
@@ -128,19 +134,19 @@ export function focusCellQuiet(node: HTMLElement | null | undefined): void {
|
|
|
128
134
|
/** 默认的整串面板类:显隐只换整串,`hidden` 不与布局类并存 */
|
|
129
135
|
export const PANEL_HIDDEN_CLASS = 'hidden';
|
|
130
136
|
export const PANEL_SHOWN_CLASS =
|
|
131
|
-
`absolute start-0 top-full z-10 mt-1 ${DD.panelMaxClass} w-full overflow-auto rounded-lg ${DD.panelBorderClass} bg-surface-raised py-1 ${DD.panelShadowClass}`;
|
|
137
|
+
`absolute start-0 top-full z-10 mt-1 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto rounded-lg ${DD.panelBorderClass} bg-surface-raised py-1 ${DD.panelShadowClass}`;
|
|
132
138
|
|
|
133
139
|
// 选项行高固定(真源 dropdown.rowClass = h-9),面板最大高才能算成「整数行 + 半行」
|
|
134
140
|
const ROW = DD.rowClass;
|
|
135
141
|
export const OPTION_CLASS = {
|
|
136
|
-
idle: `flex ${ROW} cursor-pointer items-center gap-2 px-3 text-sm text-fg transition-colors hover:bg-surface-sunken`,
|
|
137
|
-
active: `flex ${ROW} cursor-pointer items-center gap-2 bg-surface-sunken px-3 text-sm text-fg transition-colors`,
|
|
138
|
-
selected: `flex ${ROW} cursor-pointer items-center gap-2 bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors`,
|
|
139
|
-
selectedActive: `flex ${ROW} cursor-pointer items-center gap-2 bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors`,
|
|
140
|
-
disabled: `flex ${ROW} cursor-not-allowed items-center gap-2 px-3 text-sm text-fg-subtle opacity-60`,
|
|
142
|
+
idle: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 px-3 text-sm text-fg transition-colors hover:bg-surface-sunken`,
|
|
143
|
+
active: `flex ${ROW} cursor-pointer items-center whitespace-nowrap gap-2 bg-surface-sunken px-3 text-sm text-fg transition-colors`,
|
|
144
|
+
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
|
+
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`,
|
|
146
|
+
disabled: `flex ${ROW} cursor-not-allowed items-center whitespace-nowrap gap-2 px-3 text-sm text-fg-subtle opacity-60`,
|
|
141
147
|
} as const;
|
|
142
148
|
|
|
143
|
-
export const EMPTY_ROW_CLASS = `flex ${ROW} items-center px-3 text-sm text-fg-subtle`;
|
|
149
|
+
export const EMPTY_ROW_CLASS = `flex ${ROW} items-center whitespace-nowrap px-3 text-sm text-fg-subtle`;
|
|
144
150
|
|
|
145
151
|
export function optionClass(selected: boolean, active: boolean, disabled: boolean): string {
|
|
146
152
|
if (disabled) return OPTION_CLASS.disabled;
|
|
@@ -150,10 +156,10 @@ export function optionClass(selected: boolean, active: boolean, disabled: boolea
|
|
|
150
156
|
|
|
151
157
|
/** 本文件自带的类(供各组件并入候选类清单) */
|
|
152
158
|
export const KIT_POPUP_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
153
|
-
'hidden', 'absolute', 'start-0', 'top-full', 'z-10', 'mt-1', DD.panelMaxClass, DD.rowClass, 'w-full', 'overflow-auto',
|
|
159
|
+
'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',
|
|
154
160
|
'rounded-md', 'rounded-lg', 'border', 'border-border', 'border-border-subtle', 'bg-surface-raised', 'py-1', DD.panelShadowClass, 'shadow-sm',
|
|
155
|
-
'flex', 'cursor-pointer', 'cursor-not-allowed', 'items-center', 'gap-2', 'px-3', 'py-2', 'text-sm',
|
|
156
|
-
'text-fg', 'text-fg-subtle', 'bg-surface-sunken', 'font-medium', 'text-primary',
|
|
161
|
+
'flex', 'cursor-pointer', 'cursor-not-allowed', 'items-center', 'whitespace-nowrap', 'gap-2', 'px-3', 'py-2', 'text-sm',
|
|
162
|
+
'text-fg', 'text-fg-subtle', 'bg-surface-sunken', 'font-medium', 'text-primary-on-soft',
|
|
157
163
|
'transition-colors', 'hover:bg-surface-sunken', 'bg-primary-soft', 'text-primary-on-soft', 'opacity-60',
|
|
158
164
|
]);
|
|
159
165
|
|
|
@@ -284,7 +290,7 @@ export const POPUP_TIP_SHOWN_CLASS = popupTipClass(POPUP_TIP_PREF);
|
|
|
284
290
|
|
|
285
291
|
/** 下拉面板外观类(不含位置类):与 PANEL_SHOWN_CLASS 同一份外观 */
|
|
286
292
|
export const PANEL_BASE_CLASS =
|
|
287
|
-
`absolute z-10 ${DD.panelMaxClass} w-full overflow-auto rounded-lg ${DD.panelBorderClass} bg-surface-raised py-1 ${DD.panelShadowClass}`;
|
|
293
|
+
`absolute z-10 ${DD.panelMaxClass} w-max min-w-full max-w-screen overflow-auto rounded-lg ${DD.panelBorderClass} bg-surface-raised py-1 ${DD.panelShadowClass}`;
|
|
288
294
|
|
|
289
295
|
/** 空间不足时面板内部滚动的 max-h 闭集档位(px = 刻度 x 4),从大到小;每档都是「整数行 + 半行」(真源 dropdown.clamps),空间不够也不腰斩一行 */
|
|
290
296
|
export const DROPDOWN_CLAMPS: readonly { cls: string; px: number }[] = Object.freeze(
|
|
@@ -525,7 +531,66 @@ export function syncAnchored(
|
|
|
525
531
|
if (at === null) showPopupFitted(panel, anchor, pref, classFor, gapPx);
|
|
526
532
|
}
|
|
527
533
|
|
|
528
|
-
const TAB_STOPS = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
534
|
+
const TAB_STOPS = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"]),[contenteditable]:not([contenteditable="false"])';
|
|
535
|
+
|
|
536
|
+
function hiddenFromFocus(el: HTMLElement): boolean {
|
|
537
|
+
const win = el.ownerDocument.defaultView;
|
|
538
|
+
let cur: HTMLElement | null = el;
|
|
539
|
+
while (cur !== null) {
|
|
540
|
+
if (cur.hasAttribute('hidden') || cur.hasAttribute('inert') || cur.getAttribute('aria-hidden')?.toLowerCase() === 'true') return true;
|
|
541
|
+
const style = win?.getComputedStyle(cur);
|
|
542
|
+
if (style?.display === 'none' || style?.visibility === 'hidden' || style?.visibility === 'collapse') return true;
|
|
543
|
+
cur = cur.parentElement;
|
|
544
|
+
}
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** 焦点域的唯一可交互序:排除自身或祖先 hidden / inert / aria-hidden / display:none / visibility:hidden */
|
|
549
|
+
export function focusablesIn(container: HTMLElement): HTMLElement[] {
|
|
550
|
+
const visible = [...container.querySelectorAll<HTMLElement>(TAB_STOPS)].filter((el) => !hiddenFromFocus(el));
|
|
551
|
+
// 原生 radio 组折叠成一个 tab stop:组内有选中的取选中的,都没选取组内文档顺序第一个;无 name 的 radio 各自独立
|
|
552
|
+
const groupKey = (el: HTMLElement): { scope: Node; name: string } | null => {
|
|
553
|
+
const radio = el as HTMLInputElement;
|
|
554
|
+
if (el.tagName !== 'INPUT' || radio.type !== 'radio' || radio.name === '') return null;
|
|
555
|
+
return { scope: radio.form ?? el.getRootNode(), name: radio.name };
|
|
556
|
+
};
|
|
557
|
+
const chosen = new Map<Node, Map<string, HTMLElement>>();
|
|
558
|
+
for (const el of visible) {
|
|
559
|
+
const key = groupKey(el);
|
|
560
|
+
if (key === null) continue;
|
|
561
|
+
const byName = chosen.get(key.scope) ?? new Map<string, HTMLElement>();
|
|
562
|
+
chosen.set(key.scope, byName);
|
|
563
|
+
const cur = byName.get(key.name);
|
|
564
|
+
if (cur === undefined || (!(cur as HTMLInputElement).checked && (el as HTMLInputElement).checked)) byName.set(key.name, el);
|
|
565
|
+
}
|
|
566
|
+
return visible.filter((el) => {
|
|
567
|
+
const key = groupKey(el);
|
|
568
|
+
return key === null || chosen.get(key.scope)?.get(key.name) === el;
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** 两个元素是同一个 tab stop:同一元素,或同组(同 name、同 form / 同根)的原生 radio */
|
|
573
|
+
export function sameTabStop(a: Element | null, b: Element | null): boolean {
|
|
574
|
+
if (a === null || b === null) return false;
|
|
575
|
+
if (a === b) return true;
|
|
576
|
+
const ra = a as HTMLInputElement;
|
|
577
|
+
const rb = b as HTMLInputElement;
|
|
578
|
+
if (ra.type !== 'radio' || rb.type !== 'radio' || !ra.name || ra.name !== rb.name) return false;
|
|
579
|
+
return ra.form !== null || rb.form !== null ? ra.form === rb.form : ra.getRootNode() === rb.getRootNode();
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** Tab 在对话框内循环;零可交互子项时将焦点留在容器本身 */
|
|
583
|
+
export function trapTab(event: KeyboardEvent, container: HTMLElement): boolean {
|
|
584
|
+
if (event.key !== 'Tab') return false;
|
|
585
|
+
const list = focusablesIn(container);
|
|
586
|
+
if (list.length === 0) { event.preventDefault(); container.focus(); return true; }
|
|
587
|
+
const first = list[0]!;
|
|
588
|
+
const last = list[list.length - 1]!;
|
|
589
|
+
const active = container.ownerDocument.activeElement;
|
|
590
|
+
if (event.shiftKey && (sameTabStop(active, first) || active === container || !container.contains(active))) { event.preventDefault(); last.focus(); return true; }
|
|
591
|
+
if (!event.shiftKey && (sameTabStop(active, last) || !container.contains(active))) { event.preventDefault(); first.focus(); return true; }
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
529
594
|
|
|
530
595
|
/**
|
|
531
596
|
* 面板挂在浮层里后,Tab 走出面板会落到 body 末尾而不是触发钮后面。面板里在首 / 尾元素上继续 Tab 时,
|
|
@@ -533,10 +598,10 @@ const TAB_STOPS = 'a[href],button:not([disabled]),input:not([disabled]),select:n
|
|
|
533
598
|
*/
|
|
534
599
|
export function handoffTab(event: KeyboardEvent, panel: HTMLElement, trigger: HTMLElement): boolean {
|
|
535
600
|
if (event.key !== 'Tab') return false;
|
|
536
|
-
const stops =
|
|
601
|
+
const stops = focusablesIn(panel);
|
|
537
602
|
const active = panel.ownerDocument.activeElement;
|
|
538
603
|
const edge = event.shiftKey ? (stops[0] ?? panel) : (stops[stops.length - 1] ?? panel);
|
|
539
|
-
if (active
|
|
604
|
+
if (!sameTabStop(active, edge) && !(stops.length === 0 && active === panel)) return false;
|
|
540
605
|
trigger.focus();
|
|
541
606
|
return true;
|
|
542
607
|
}
|
package/src/base/price-text.ts
CHANGED
|
@@ -97,7 +97,7 @@ export function createPriceText(): SomaComponentDefinition {
|
|
|
97
97
|
templateHtml:
|
|
98
98
|
`<span data-soma-id="root" class="${ROOT.md}">` +
|
|
99
99
|
`<span data-soma-id="now" class="${NOW.normal}"></span><del data-soma-id="was" class="${HIDDEN}"></del></span>`,
|
|
100
|
-
controllerFactory: createKitController({
|
|
100
|
+
controllerFactory: createKitController(() => ({
|
|
101
101
|
render(root, p) {
|
|
102
102
|
const spec = priceSpecOf({ ...p, locale: str(p.locale, kitLocaleAt(root)) });
|
|
103
103
|
const placeholder = str(p.placeholder, '-');
|
|
@@ -121,6 +121,6 @@ export function createPriceText(): SomaComponentDefinition {
|
|
|
121
121
|
const sz = p.size === 'sm' || p.size === 'lg' ? p.size : 'md';
|
|
122
122
|
root.className = joinClass(ROOT[sz], p.class);
|
|
123
123
|
},
|
|
124
|
-
}),
|
|
124
|
+
})),
|
|
125
125
|
};
|
|
126
126
|
}
|