soma-kit 0.1.13 → 0.1.15
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/package.json +3 -3
- package/packs/finance/reconcile-desk/compile.ts +1 -1
- package/packs/finance/reconcile-desk/shell.ts +1 -1
- package/spec/generated/kit-app.schema.json +18 -2
- package/spec/generated/kit-page.schema.json +95 -0
- package/spec/kit-grammar.json +332 -75
- package/spec/kit-grammar.schema.json +1 -27
- package/src/app/app-config.ts +11 -5
- package/src/app/component-gate.ts +2 -2
- package/src/app/compose-apps.ts +5 -2
- package/src/app/define-kit-actions.ts +82 -10
- package/src/app/define-kit-app.ts +6 -5
- package/src/app/define-kit-view.ts +1 -1
- package/src/app/index.ts +20 -8
- package/src/app/kit-view-context.ts +30 -4
- package/src/app/server-pages.ts +5 -1
- package/src/app/server.ts +15 -5
- package/src/app/theme-endpoint.ts +1 -1
- package/src/app/theme-runtime.ts +7 -2
- package/src/base/alert.ts +23 -20
- package/src/base/anchored-layer.ts +1 -1
- package/src/base/button.ts +34 -17
- package/src/base/cascader.ts +8 -4
- package/src/base/check-core.ts +9 -6
- package/src/base/color-picker.ts +10 -6
- package/src/base/command-palette.ts +10 -4
- package/src/base/context-menu.ts +5 -2
- package/src/base/date-range.ts +9 -6
- package/src/base/date.ts +10 -6
- package/src/base/delta.ts +4 -2
- package/src/base/divider.ts +15 -66
- package/src/base/end-edge.ts +14 -2
- package/src/base/fab.ts +11 -6
- package/src/base/gap-value.ts +25 -5
- package/src/base/hint-tips.ts +1 -1
- package/src/base/illustrations.ts +2 -1
- package/src/base/index.ts +20 -4
- package/src/base/inline-error.ts +84 -0
- package/src/base/input.ts +54 -18
- package/src/base/kbd.ts +4 -3
- package/src/base/link.ts +1 -1
- package/src/base/listbox-core.ts +70 -22
- package/src/base/mentions.ts +6 -3
- package/src/base/menu-button.ts +73 -50
- package/src/base/menu-core.ts +9 -2
- package/src/base/motion/hover-3d.ts +4 -1
- package/src/base/motion/hover-gallery.ts +4 -1
- package/src/base/otp.ts +7 -3
- package/src/base/overlay-runtime.ts +3 -2
- package/src/base/overlay-shell.ts +141 -0
- package/src/base/popover.ts +7 -6
- package/src/base/popup.ts +47 -41
- package/src/base/qty-stepper.ts +14 -9
- package/src/base/reason-tip.ts +2 -2
- package/src/{frames → base}/resize-handle.ts +1 -1
- package/src/base/segmented.ts +44 -35
- package/src/base/select.ts +1 -0
- package/src/base/shared.ts +52 -18
- package/src/base/state-panel.ts +34 -13
- package/src/base/status-tone.ts +1 -1
- package/src/base/tag-input.ts +13 -8
- package/src/base/tag.ts +56 -57
- package/src/base/text.ts +38 -14
- package/src/base/textarea.ts +1 -1
- package/src/base/time-picker.ts +9 -5
- package/src/base/tree-select.ts +12 -9
- package/src/base/upload.ts +26 -17
- package/src/biz/approval-desk/compile.ts +28 -1
- package/src/biz/approval-desk/shell.ts +10 -9
- package/src/biz/auth-panel/compile.ts +1 -1
- package/src/biz/auth-panel/shell.ts +7 -6
- package/src/biz/category-crud/compile.ts +20 -6
- package/src/biz/category-crud/shell.ts +10 -7
- package/src/biz/checkout-page/compile.ts +1 -1
- package/src/biz/checkout-page/shell.ts +15 -13
- package/src/biz/compose.ts +5 -5
- package/src/biz/data-components.ts +4 -0
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +1 -1
- package/src/biz/import-wizard/shell.ts +17 -13
- package/src/biz/index.ts +4 -3
- package/src/biz/landing-page/compile.ts +1 -1
- package/src/biz/landing-page/shell.ts +6 -5
- package/src/biz/link/shared.ts +8 -1
- package/src/biz/master-sub/compile.ts +269 -27
- package/src/biz/master-sub/detail-head.ts +62 -0
- package/src/biz/master-sub/index.ts +5 -4
- package/src/biz/master-sub/shell.ts +138 -69
- package/src/biz/multi-board/compile.ts +166 -11
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +25 -10
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +96 -24
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +9 -2
- package/src/biz/notification-center/shell.ts +15 -7
- package/src/biz/page-templates/domain-templates.ts +7 -3
- package/src/biz/page-templates/result-page/compile.ts +1 -1
- package/src/biz/page-templates/result-page/shell.ts +5 -4
- package/src/biz/page-templates/shared.ts +1 -1
- package/src/biz/page-templates/sign-in-page/compile.ts +1 -1
- package/src/biz/page-templates/sign-in-page/shell.ts +18 -18
- package/src/biz/record-detail/compile.ts +5 -2
- package/src/biz/record-detail/shell.ts +12 -11
- package/src/biz/settings-center/compile.ts +1 -1
- package/src/biz/settings-center/shell.ts +14 -10
- package/src/biz/shared/action-host.ts +12 -5
- package/src/biz/shared/compile-helpers.ts +83 -4
- package/src/biz/shared/coordinator.ts +104 -21
- package/src/biz/shared/overlay-compile.ts +76 -4
- package/src/biz/shared/overlay-shell.ts +65 -112
- package/src/biz/single-form/compile.ts +2 -2
- package/src/biz/single-form/shell.ts +13 -7
- package/src/biz/standard-crud/compile.ts +24 -4
- package/src/biz/standard-crud/shell.ts +38 -30
- package/src/biz/standard-crud/summary.ts +42 -0
- package/src/biz/step-form/compile.ts +1 -1
- package/src/biz/step-form/hub.ts +4 -0
- package/src/biz/step-form/shell.ts +16 -12
- package/src/biz/types.ts +15 -3
- package/src/cli/app-layer-check.ts +375 -0
- package/src/cli/kit-cli.ts +35 -8
- package/src/cli/kit-init.ts +149 -0
- package/src/cli/layout-cli.ts +7 -7
- package/src/compile/access-gate-attach.ts +27 -0
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/compile-page.ts +36 -230
- package/src/compile/component-candidates.ts +4 -1
- package/src/compile/hints.ts +5 -58
- package/src/compile/index.ts +2 -2
- package/src/compile/layout-lint/index.ts +4 -1
- package/src/compile/layout-lint/rules-composition.ts +97 -18
- package/src/compile/layout-lint/rules-form.ts +6 -7
- package/src/compile/layout-lint/rules-table.ts +98 -14
- package/src/compile/page-composition.ts +191 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/redirect.ts +1 -1
- package/src/compile/stages.ts +169 -0
- package/src/compile/styles.ts +80 -32
- package/src/compile/types.ts +5 -3
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +6 -2
- package/src/data/anchor-nav.ts +4 -1
- package/src/data/approval-flow.ts +13 -5
- package/src/data/assignment-picker.ts +35 -20
- package/src/data/async-result-panel.ts +7 -3
- package/src/data/breadcrumbs.ts +13 -9
- package/src/data/calendar.ts +10 -4
- package/src/data/carousel.ts +13 -5
- package/src/data/chart.ts +745 -48
- package/src/data/checklist.ts +9 -5
- package/src/data/code-view.ts +220 -26
- package/src/data/comment-thread.ts +9 -3
- package/src/data/confirm-dialog.ts +57 -20
- package/src/data/diff.ts +4 -1
- package/src/data/dock.ts +5 -1
- package/src/data/embed.ts +1 -1
- package/src/data/engine-ports.ts +126 -0
- package/src/data/field-mapper.ts +16 -7
- package/src/data/flow-editor.ts +106 -29
- package/src/data/footer.ts +8 -2
- package/src/data/gantt.ts +192 -27
- package/src/data/hero.ts +8 -2
- package/src/data/image-viewer.ts +7 -3
- package/src/data/index.ts +22 -8
- package/src/data/item-list.ts +11 -3
- package/src/data/json-view.ts +844 -0
- package/src/data/kanban.ts +13 -8
- package/src/data/markdown-view.ts +487 -0
- package/src/data/matrix.ts +400 -0
- package/src/data/media-grid.ts +5 -2
- package/src/data/mega-menu.ts +4 -3
- package/src/data/menu-dom.ts +9 -8
- package/src/data/menu.ts +35 -17
- package/src/data/mockup.ts +12 -8
- package/src/data/modal-dialog.ts +108 -57
- package/src/data/navbar.ts +13 -7
- package/src/data/notice-list.ts +53 -20
- package/src/data/notify-renderer.ts +21 -10
- package/src/data/object-form.ts +248 -151
- package/src/data/pager.ts +15 -10
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +19 -9
- package/src/data/permission-tree.ts +30 -13
- package/src/data/pricing-table.ts +10 -4
- package/src/data/reaction-bar.ts +6 -3
- package/src/data/record-card.ts +30 -14
- package/src/data/record-picker.ts +8 -4
- package/src/data/redirect.ts +1 -1
- package/src/data/request-console.ts +20 -7
- package/src/data/resident.ts +6 -10
- package/src/data/result-panel.ts +2 -2
- package/src/data/rich-text.ts +58 -96
- package/src/data/row-editor.ts +12 -7
- package/src/data/rule-builder.ts +22 -11
- package/src/data/shape-util.ts +26 -14
- package/src/data/stat-group.ts +369 -84
- package/src/data/static-lazy.ts +7 -0
- package/src/data/static-registry.ts +14 -2
- package/src/data/steps.ts +6 -2
- package/src/data/survey.ts +13 -4
- package/src/data/system-switcher.ts +17 -7
- package/src/data/text-diff.ts +663 -0
- package/src/data/timeline.ts +1 -1
- package/src/data/tour-guide.ts +8 -4
- package/src/data/transfer.ts +24 -11
- package/src/data/tree-table.ts +84 -17
- package/src/data/tree.ts +6 -3
- package/src/data/virtual-rows.ts +22 -11
- package/src/data/wrap.ts +2 -2
- package/src/data/wrapped-candidates.ts +22 -1
- package/src/frames/index.ts +4 -2
- package/src/frames/inherited-shell.ts +178 -0
- package/src/frames/list-summary.ts +123 -0
- package/src/frames/page-bar.ts +10 -16
- package/src/frames/resident-components.ts +20 -0
- package/src/frames/shared.ts +37 -17
- package/src/frames/split-frame/shell.ts +17 -11
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +17 -9
- package/src/frames/top-main-frame.ts +1 -1
- package/src/frames/types.ts +6 -3
- package/src/frames/workspace-frame/extras.ts +19 -5
- package/src/frames/workspace-frame/shell.ts +4 -3
- package/src/frames/workspace-frame/state.ts +8 -2
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +156 -91
- package/src/generated/kit-grammar-runtime.ts +227 -58
- package/src/i18n/kit-text.ts +141 -2
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +169 -0
- package/src/object-renderer/action-more.ts +160 -0
- package/src/object-renderer/arrange.ts +86 -26
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +72 -20
- package/src/object-renderer/collection-table.ts +178 -65
- package/src/object-renderer/collection.ts +129 -83
- package/src/object-renderer/compile-data.ts +1 -1
- package/src/object-renderer/defaults.ts +10 -5
- package/src/object-renderer/emit-events.ts +1 -1
- package/src/object-renderer/emit-object.ts +7 -0
- package/src/object-renderer/emit-static.ts +243 -87
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/filter-toolbar.ts +103 -0
- package/src/{compile → object-renderer}/fragment.ts +13 -2
- package/src/object-renderer/index.ts +6 -1
- package/src/object-renderer/layout-facts.ts +46 -6
- package/src/object-renderer/layout-plan.ts +136 -43
- package/src/object-renderer/layout-plan.types.ts +42 -5
- package/src/object-renderer/overlay-decide.ts +82 -0
- package/src/object-renderer/parts.ts +7 -259
- package/src/object-renderer/render-object.ts +60 -47
- package/src/object-renderer/table-actions.ts +135 -56
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +63 -25
- package/src/object-renderer/types.ts +16 -22
- package/src/recipes/app-blocks.ts +66 -0
- package/src/recipes/code-view.ts +56 -0
- package/src/recipes/compact-group.ts +31 -0
- package/src/recipes/container.ts +54 -13
- package/src/recipes/control.ts +77 -157
- package/src/recipes/desc-list.ts +14 -0
- package/src/recipes/divider.ts +53 -0
- package/src/recipes/emphasis.ts +60 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +34 -1
- package/src/recipes/inherited-shell.ts +37 -0
- package/src/recipes/json-view.ts +49 -0
- package/src/recipes/markdown.ts +86 -0
- package/src/recipes/overlay.ts +149 -18
- package/src/recipes/page-width.ts +20 -0
- package/src/recipes/placeholder.ts +21 -5
- package/src/recipes/rail-grid.ts +3 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +20 -28
- package/src/recipes/status.ts +17 -8
- package/src/recipes/strip.ts +72 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/surface.ts +10 -6
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +120 -11
- package/src/recipes/tabs.ts +126 -0
- package/src/recipes/text-diff.ts +90 -0
- package/src/recipes/title-row.ts +7 -5
- package/src/recipes/typography.ts +24 -43
- package/src/shared/diagnostics.ts +16 -0
- package/src/shared/envelope.ts +1 -1
- package/src/shared/field-value-format.ts +246 -0
- package/src/shared/focus-ring.ts +8 -0
- package/src/shared/hints.ts +56 -0
- package/src/{base → shared}/icons.ts +12 -0
- package/src/shared/kit-error.ts +1 -1
- package/src/{object-renderer → shared}/merge-class.ts +3 -2
- package/src/shared/path-guard.ts +1 -1
- package/src/shared/primitives-types.ts +8 -0
- package/src/shared/theme-runtime-shared.ts +19 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +49 -14
- package/src/theme/kit-theme.tpl +49 -14
- package/src/theme/nine-dim-structure.ts +129 -37
- package/src/theme/surface-layers.ts +17 -4
- package/src/theme/theme-tokens.ts +16 -5
- package/src/theme/typography.ts +21 -17
- package/src/app/envelope.ts +0 -1
- package/src/app/notify-renderer.ts +0 -1
- package/src/app/paged-list-adapter.ts +0 -1
- package/src/app/theme-runtime-shared.ts +0 -1
- package/src/compile/kit-error.ts +0 -1
- /package/src/{base → shared}/class-candidates.ts +0 -0
package/src/base/fab.ts
CHANGED
|
@@ -10,11 +10,16 @@ import {
|
|
|
10
10
|
type KitSize, type KitView,
|
|
11
11
|
} from './shared';
|
|
12
12
|
import { kitText } from '../i18n/kit-text';
|
|
13
|
-
import { kitIcon } from '
|
|
13
|
+
import { kitIcon } from '../shared/icons';
|
|
14
14
|
import { setKitFixed } from '../recipes';
|
|
15
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
16
|
+
import { mergeClass } from '../shared/merge-class';
|
|
15
17
|
import { menuItemsOf, wireMenu, type MenuClasses, type MenuHandle } from './menu-core';
|
|
16
18
|
import { KIT_DROPDOWN_PORTAL_CLASS_CANDIDATES, KIT_POPUP_PLACE_CLASS_CANDIDATES, popPlaceClass, type PopPlace } from './popup';
|
|
17
19
|
|
|
20
|
+
// 悬浮动作钮是浮起的面(KT-B4):发丝描边 + 浮起面 + 双层浮起阴影只取浮起表面配方;胶囊圆角是构件形体
|
|
21
|
+
const FLOAT_EDGE = mergeClass(kitSurfaceRecipe('raised'), 'rounded-full');
|
|
22
|
+
|
|
18
23
|
export type FabPlacement = 'inline' | 'bottom-right' | 'bottom-left';
|
|
19
24
|
|
|
20
25
|
const ROOT_CLASS: Record<FabPlacement, string> = {
|
|
@@ -41,14 +46,14 @@ const MENU_BASE = 'absolute z-10 flex flex-col gap-2';
|
|
|
41
46
|
const MENU_BASE_ROW = 'absolute z-10 flex flex-row items-center gap-2';
|
|
42
47
|
const menuClass = (place: PopPlace): string =>
|
|
43
48
|
place.side === 'start' || place.side === 'end'
|
|
44
|
-
? `${MENU_BASE_ROW} ${popPlaceClass(place
|
|
45
|
-
: `${MENU_BASE} ${popPlaceClass(place
|
|
49
|
+
? `${MENU_BASE_ROW} ${popPlaceClass(place)}`
|
|
50
|
+
: `${MENU_BASE} ${popPlaceClass(place)} ${place.align === 'end' ? 'items-end' : 'items-start'}`;
|
|
46
51
|
const BACK_TOP_HIDDEN = 'hidden';
|
|
47
52
|
const BACK_TOP_OFFSET = 200;
|
|
48
53
|
const MENU_CLASSES: MenuClasses = {
|
|
49
|
-
idle: 'flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-full
|
|
50
|
-
danger: 'flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-full
|
|
51
|
-
disabled: 'flex cursor-not-allowed items-center gap-2 whitespace-nowrap rounded-full
|
|
54
|
+
idle: 'flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-full ' + FLOAT_EDGE + ' px-4 py-2 text-sm font-medium text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
55
|
+
danger: 'flex cursor-pointer items-center gap-2 whitespace-nowrap rounded-full ' + FLOAT_EDGE + ' px-4 py-2 text-sm font-medium text-danger-on-soft transition-colors hover:bg-danger-soft focus-visible:bg-danger-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
56
|
+
disabled: 'flex cursor-not-allowed items-center gap-2 whitespace-nowrap rounded-full ' + FLOAT_EDGE + ' px-4 py-2 text-sm font-medium text-fg-subtle opacity-60',
|
|
52
57
|
divider: 'hidden',
|
|
53
58
|
icon: 'inline-block shrink-0',
|
|
54
59
|
};
|
package/src/base/gap-value.ts
CHANGED
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
|
|
16
16
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
17
17
|
import { kitLocaleAt, kitText } from '../i18n/kit-text';
|
|
18
|
-
import { kitIcon } from '
|
|
18
|
+
import { kitIcon } from '../shared/icons';
|
|
19
|
+
import { resolveTextDisplay } from './text';
|
|
20
|
+
import { KIT_TABLE_GAP, KIT_TABLE_GAP_MARK, KIT_TABLE_GAP_CLASS_CANDIDATES } from '../recipes/table-gap';
|
|
19
21
|
import { KIT_GAP_PILL, KIT_GAP_PILL_FOCUS, KIT_GAP_TEXT_TRUNCATE, KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES, KIT_GAP_VALUE_TEXT, type KitGapKind } from '../recipes/status';
|
|
20
22
|
import {
|
|
21
23
|
CLASS_PROP, SIZE_PROP, TOOLTIP_PROP,
|
|
@@ -24,7 +26,7 @@ import {
|
|
|
24
26
|
} from './shared';
|
|
25
27
|
|
|
26
28
|
/** 本组件自带的类(并入基础组件候选类清单) */
|
|
27
|
-
export const KIT_GAP_VALUE_CLASS_CANDIDATES: readonly string[] = KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES;
|
|
29
|
+
export const KIT_GAP_VALUE_CLASS_CANDIDATES: readonly string[] = [...KIT_GAP_VALUE_RECIPE_CLASS_CANDIDATES, ...KIT_TABLE_GAP_CLASS_CANDIDATES];
|
|
28
30
|
|
|
29
31
|
export type GapState = 'auto' | 'value' | 'gap' | 'unknown';
|
|
30
32
|
|
|
@@ -63,6 +65,15 @@ export function resolveGap(p: KitProps, locale: string): GapResolved {
|
|
|
63
65
|
return { kind: 'value', text: unit === '' ? text : `${text} ${unit}` };
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
/** 表格单元格形态(plain)的展示意图:值在场 = 与 Text 同一套格式化;缺失 = 缺口(原因走悬停提示) */
|
|
69
|
+
function resolvePlainGap(p: KitProps, root: HTMLElement): GapResolved {
|
|
70
|
+
const reason = str(p.reason).trim();
|
|
71
|
+
const state = gapStateOf(p.state);
|
|
72
|
+
if (state === 'gap' || state === 'unknown') return { kind: state, reason };
|
|
73
|
+
if (!gapPresent(p.value)) return { kind: 'gap', reason };
|
|
74
|
+
return { kind: 'value', text: resolveTextDisplay(p, root).text };
|
|
75
|
+
}
|
|
76
|
+
|
|
66
77
|
/** 胶囊里的文字:单行,放不下时截断(胶囊本身 max-w-full + 不换行,图标不缩) */
|
|
67
78
|
function gapTextNode(text: string): HTMLElement {
|
|
68
79
|
const span = document.createElement('span');
|
|
@@ -100,6 +111,7 @@ export function createGapValue(): SomaComponentDefinition {
|
|
|
100
111
|
unit: { type: 'string', default: '', desc: '追加在值后的单位文字' },
|
|
101
112
|
locale: { type: 'string', default: '', desc: '格式化语言;缺省取页面语言(page.locale),都没声明为 zh-CN' },
|
|
102
113
|
compact: { type: 'boolean', default: false, desc: '缺口 / 未知时胶囊只画「缺口」/「未知」,原因走 tooltip(可键盘聚焦读到),用于窄的表格单元格' },
|
|
114
|
+
plain: { type: 'boolean', default: false, desc: '表格单元格形态:有值时与 Text 同一套格式化(金额 / 百分比 / 日期 / 选项),缺失时只画次级色短横、原因走悬停提示(零散缺失);整列同因的原因由表头旁标注承担(recipes/table-gap)' },
|
|
103
115
|
tooltip: TOOLTIP_PROP,
|
|
104
116
|
size: SIZE_PROP,
|
|
105
117
|
class: CLASS_PROP,
|
|
@@ -120,6 +132,13 @@ export function createGapValue(): SomaComponentDefinition {
|
|
|
120
132
|
root.textContent = r.text;
|
|
121
133
|
return;
|
|
122
134
|
}
|
|
135
|
+
// plain(表格单元格):缺失只画次级色短横,原因走悬停提示,不画胶囊
|
|
136
|
+
if (bool(p.plain)) {
|
|
137
|
+
root.className = joinClass(KIT_TABLE_GAP_MARK, p.class);
|
|
138
|
+
root.removeAttribute('tabindex');
|
|
139
|
+
root.textContent = KIT_TABLE_GAP.marker;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
123
142
|
const compact = bool(p.compact);
|
|
124
143
|
const marker = kitText(r.kind === 'gap' ? 'soma.kit.gap_marker' : 'soma.kit.gap_unknown_marker', undefined, root);
|
|
125
144
|
const text = !compact && r.reason !== ''
|
|
@@ -137,9 +156,10 @@ export function createGapValue(): SomaComponentDefinition {
|
|
|
137
156
|
return {
|
|
138
157
|
attach: (root, a) => view.attach?.(root, a),
|
|
139
158
|
render(root, p, a) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
159
|
+
const plain = bool(p.plain);
|
|
160
|
+
current = plain ? resolvePlainGap(p, root) : resolveGap(p, str(p.locale, kitLocaleAt(root) || 'zh-CN'));
|
|
161
|
+
// tooltip:缺口 / 未知 compact(或 plain)时取原因;其余沿用页面给的 tooltip
|
|
162
|
+
const tooltip = current.kind !== 'value' && (plain || bool(p.compact)) && current.reason !== '' ? current.reason : str(p.tooltip);
|
|
143
163
|
return view.render(root, { ...p, tooltip }, a);
|
|
144
164
|
},
|
|
145
165
|
};
|
package/src/base/hint-tips.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// 也可对任一元素 / 文档显式 `bindHintTips`(应用组件、测试用)。原生 `title=` 不再用于截断文字(见 table-tools 的单元格接线)。
|
|
14
14
|
|
|
15
15
|
import { hasReasonTip, kitTooltip, releaseReasonTip, showReasonTip } from './reason-tip';
|
|
16
|
-
import { kitIcon, kitIconHtml } from '
|
|
16
|
+
import { kitIcon, kitIconHtml } from '../shared/icons';
|
|
17
17
|
import { onKitControllerMount } from './shared';
|
|
18
18
|
import { kitText } from '../i18n/kit-text';
|
|
19
19
|
import { esc } from '../shared/escape';
|
|
@@ -28,7 +28,8 @@ export const KIT_ILLUSTRATION_CLASS_CANDIDATES: readonly string[] = Object.freez
|
|
|
28
28
|
)].sort());
|
|
29
29
|
|
|
30
30
|
const LOOK: Readonly<Record<KitIllustrationKind, { back: string; line: string }>> = Object.freeze({
|
|
31
|
-
|
|
31
|
+
// 空态插画取中性色(小尺寸、不抢主色):与「无权限」同一组中性底形 + 线稿
|
|
32
|
+
empty: { back: BACK_DENIED, line: LINE_DENIED },
|
|
32
33
|
error: { back: BACK_ERROR, line: LINE_ERROR },
|
|
33
34
|
not_ready: { back: BACK_NOT_READY, line: LINE_NOT_READY },
|
|
34
35
|
upstream_broken: { back: BACK_UPSTREAM, line: LINE_UPSTREAM },
|
package/src/base/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { createRadio } from './radio';
|
|
|
12
12
|
import { createCheckbox } from './checkbox';
|
|
13
13
|
import { createSwitch, KIT_SWITCH_CLASS_CANDIDATES } from './switch';
|
|
14
14
|
import { KIT_CHECK_CLASS_CANDIDATES } from './check-core';
|
|
15
|
-
import { KIT_ICON_CLASS_CANDIDATES } from '
|
|
15
|
+
import { KIT_ICON_CLASS_CANDIDATES } from '../shared/icons';
|
|
16
16
|
import { createDate } from './date';
|
|
17
17
|
import { createDateRange } from './date-range';
|
|
18
18
|
import { createButton } from './button';
|
|
@@ -26,8 +26,10 @@ import { createKitDivider, KIT_DIVIDER_CLASS_CANDIDATES } from './divider';
|
|
|
26
26
|
import { KIT_MOTION_COMPONENTS, KIT_MOTION_CLASS_CANDIDATES, type KitMotionId } from './motion';
|
|
27
27
|
export { KIT_MOTION_COMPONENTS, KIT_MOTION_CLASS_CANDIDATES } from './motion';
|
|
28
28
|
// 内置图标集:应用组件经 soma-kit/base 取用(kitIcon 返回 SVGSVGElement,kitIconHtml 返回 SVG 字符串)
|
|
29
|
-
export { kitIcon, kitIconHtml, KIT_ICON_NAMES, KIT_ICON_SIZES } from '
|
|
30
|
-
export type { KitIconName, KitIconSize } from '
|
|
29
|
+
export { kitIcon, kitIconHtml, KIT_ICON_NAMES, KIT_ICON_SIZES } from '../shared/icons';
|
|
30
|
+
export type { KitIconName, KitIconSize } from '../shared/icons';
|
|
31
|
+
// 应用组件内嵌下拉选择器时并入候选类
|
|
32
|
+
export { KIT_SELECT_CLASS_CANDIDATES } from './select';
|
|
31
33
|
// K9 / D1 补齐波:Range Rating Otp Avatar AvatarGroup Kbd KitProgress(环/条) Countdown Swap Fab Image MenuButton
|
|
32
34
|
import { createRange, KIT_RANGE_CLASS_CANDIDATES } from './range';
|
|
33
35
|
import { createRating, KIT_RATING_CLASS_CANDIDATES } from './rating';
|
|
@@ -98,6 +100,20 @@ export const KIT_D1_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
98
100
|
]),
|
|
99
101
|
]);
|
|
100
102
|
|
|
103
|
+
// 表格缺失值的原生表格出口(判定 / 单元格 / 列头标注;约定与阈值见 recipes/table-gap)
|
|
104
|
+
export { analyzeTableGaps, kitTableGapCell, kitTableGapHeadNote, type TableGapColumn } from '../recipes/table-gap';
|
|
105
|
+
// 应用组件的版式配方出口(P15:区块纵向栈 / 并排区块 / 节标题 / 元信息行;节奏、字阶、断点都由框架给,应用组件不自写 gap-N / text-N / @md:)
|
|
106
|
+
export {
|
|
107
|
+
KIT_APP_BLOCK_CLASS_CANDIDATES, kitAppMetaRowRecipe, kitAppSectionTitleRecipe, kitAppSideBySideRecipe, kitAppStackRecipe,
|
|
108
|
+
type KitAppRhythm, type KitAppSideBySide,
|
|
109
|
+
} from '../recipes/app-blocks';
|
|
110
|
+
// 应用组件的边界出口(knowledge/Kit主题规则与算法.md KT-B2 / KT-B5 / KT-B7):面板外缘(kitShellRecipe:读容器令牌)、分隔线(发丝宽一个灰)、紧凑组合
|
|
111
|
+
export { kitShellRecipe, type KitShellRecipeOptions, type KitShellTone } from '../recipes/container';
|
|
112
|
+
export {
|
|
113
|
+
KIT_DIVIDER_CLASS_CANDIDATES, KIT_DIVIDER_FOOT_CLASS, KIT_DIVIDER_HEAD_CLASS, kitDivideRecipe, kitDividerRecipe, type KitDividerSide,
|
|
114
|
+
} from '../recipes/divider';
|
|
115
|
+
export { KIT_COMPACT_GROUP_CLASS_CANDIDATES, kitCompactGroupRecipe } from '../recipes/compact-group';
|
|
116
|
+
|
|
101
117
|
export type KitBaseId =
|
|
102
118
|
| 'Text' | 'Tag' | 'Input' | 'Textarea' | 'Number' | 'Select' | 'Radio'
|
|
103
119
|
| 'Checkbox' | 'Switch' | 'Date' | 'DateRange' | 'Button' | 'Link'
|
|
@@ -185,7 +201,7 @@ export const KIT_BASE_CORE_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
185
201
|
'border-dashed', 'border-primary', 'flex-1', 'flex-col',
|
|
186
202
|
'focus-within:ring-2', 'focus-within:ring-ring',
|
|
187
203
|
'h-2', 'h-8', 'h-full', 'items-start', 'justify-between', 'start-0',
|
|
188
|
-
'
|
|
204
|
+
'shadow-lg', 'shadow-xl', 'top-0.5', 'start-4.5', 'start-5.5', 'start-7.5',
|
|
189
205
|
'peer-checked:start-4.5', 'peer-checked:start-5.5', 'peer-checked:start-7.5', 'transition-all', 'min-h-11', 'min-h-6', 'min-w-6', 'min-h-8', 'min-h-9', 'min-w-0', 'min-w-24', 'me-1.5', 'mt-1',
|
|
190
206
|
'object-cover', 'overflow-auto', 'p-1',
|
|
191
207
|
'ps-10', 'ps-14', 'ps-18', 'ps-2', 'ps-22', 'ps-6', 'pe-2', 'px-0.5', 'px-1', 'py-4', 'py-6',
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// 就地错误提示条(KT-K-feedback-3,§6.1 G-17):动作失败在发起处给提示条,不再用自动消失的轻提示承载错误。
|
|
2
|
+
// · 发起处在窗口里(from 在 [role=dialog] 内,或焦点停在窗口里):提示条进窗口体的最前(窗口的提示条槽);
|
|
3
|
+
// · 页面级动作(行动作 / 页头动作 / 具名动作):提示条进页头之后、内容之前,常驻至用户关闭或同一动作(同 key)下一次成功;
|
|
4
|
+
// · 同 key 再失败 = 替换文案,不叠加;找不到槽(无页头 / 无窗口,如纯命令式挂载)返回 false,调用方回退原通道,错误不丢。
|
|
5
|
+
// 外观复用 base/alert.ts 的提示条配方(danger:浅底 + 语气图标 + 正文,无描边)。
|
|
6
|
+
|
|
7
|
+
import { kitText } from '../i18n/kit-text';
|
|
8
|
+
import { kitIcon } from '../shared/icons';
|
|
9
|
+
import { classCandidates } from '../shared/class-candidates';
|
|
10
|
+
import { BODY_CLASS, BOX_CLASS, CLOSE_CLASS, ICON_CLASS } from './alert';
|
|
11
|
+
|
|
12
|
+
/** 极小的建节点帮手(base 层不依赖 data 层的 menu-dom,G112 四层方向) */
|
|
13
|
+
function h(tag: string, cls: string, attrs: Record<string, string>, ...kids: Array<Node | string>): HTMLElement {
|
|
14
|
+
const el = document.createElement(tag);
|
|
15
|
+
if (cls !== '') el.className = cls;
|
|
16
|
+
for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, v);
|
|
17
|
+
for (const kid of kids) el.append(kid);
|
|
18
|
+
return el;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const KEY_ATTR = 'data-kit-inline-error';
|
|
22
|
+
const WRAP_CLASS = 'mb-4';
|
|
23
|
+
/** 页头壳的标记:headerFragment 的 `<header data-soma-id="…frame__header">` */
|
|
24
|
+
const PAGE_HEADER_SELECTOR = 'header[data-soma-id$="frame__header"]';
|
|
25
|
+
const DIALOG_BODY_SELECTOR = '[data-kit-dialog-body], [data-kit-overlay-body]';
|
|
26
|
+
|
|
27
|
+
/** 本部件自带的全部类(并入运行期常驻候选,见 compile/component-candidates.ts) */
|
|
28
|
+
export const KIT_INLINE_ERROR_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
29
|
+
WRAP_CLASS, BOX_CLASS.md.danger, ICON_CLASS.danger, BODY_CLASS, CLOSE_CLASS,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
function dialogOf(from: Element | null): Element | null {
|
|
33
|
+
const doc = from?.ownerDocument ?? (typeof document === 'undefined' ? null : document);
|
|
34
|
+
const origin = from ?? doc?.activeElement ?? null;
|
|
35
|
+
const own = origin?.closest('[role="dialog"]') ?? null;
|
|
36
|
+
if (own !== null) return own;
|
|
37
|
+
// from 是页面上的宿主(隐藏的动作宿主不在窗口里):窗口底栏动作被点击时焦点停在窗口内的按钮上
|
|
38
|
+
return doc?.activeElement?.closest('[role="dialog"]') ?? null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function pageHeaderOf(from: Element | null): Element | null {
|
|
42
|
+
const doc = from?.ownerDocument ?? (typeof document === 'undefined' ? null : document);
|
|
43
|
+
return doc?.querySelector(PAGE_HEADER_SELECTOR) ?? null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function build(message: string, key: string, from: Element | null): HTMLElement {
|
|
47
|
+
const close = h('button', CLOSE_CLASS, { type: 'button', 'aria-label': kitText('soma.kit.close', undefined, from) }, kitIcon('close', 'sm'));
|
|
48
|
+
const box = h('div', BOX_CLASS.md.danger, {},
|
|
49
|
+
h('span', ICON_CLASS.danger, { 'aria-hidden': 'true' }, kitIcon('error', 'sm')),
|
|
50
|
+
h('div', BODY_CLASS, {}, h('span', 'block', { 'data-kit-inline-error-text': '' }, message)),
|
|
51
|
+
close);
|
|
52
|
+
const wrap = h('div', WRAP_CLASS, { role: 'alert', [KEY_ATTR]: key }, box);
|
|
53
|
+
close.addEventListener('click', () => wrap.remove());
|
|
54
|
+
return wrap;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 清掉某个 key 的就地提示条(同一动作下一次成功时调用;没有则无操作) */
|
|
58
|
+
export function clearKitInlineError(from: Element | null, key: string): void {
|
|
59
|
+
const doc = from?.ownerDocument ?? (typeof document === 'undefined' ? null : document);
|
|
60
|
+
if (doc === null) return;
|
|
61
|
+
for (const el of Array.from(doc.querySelectorAll(`[${KEY_ATTR}]`))) {
|
|
62
|
+
if (el.getAttribute(KEY_ATTR) === key) el.remove();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 显示就地错误提示条;返回是否找到了槽(false = 调用方回退原通道) */
|
|
67
|
+
export function showKitInlineError(from: Element | null, message: string, key: string): boolean {
|
|
68
|
+
if (message === '') return false;
|
|
69
|
+
if (typeof document === 'undefined') return false;
|
|
70
|
+
const dialog = dialogOf(from);
|
|
71
|
+
const body = dialog?.querySelector(DIALOG_BODY_SELECTOR) ?? null;
|
|
72
|
+
const header = body === null ? pageHeaderOf(from) : null;
|
|
73
|
+
if (body === null && header === null) return false;
|
|
74
|
+
clearKitInlineError(from, key);
|
|
75
|
+
const el = build(message, key, from);
|
|
76
|
+
if (body !== null) body.insertBefore(el, body.firstChild);
|
|
77
|
+
else header!.after(el);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 失败上报:先进就地提示条,没有槽才回退到 fallback(原轻提示),保证错误不丢 */
|
|
82
|
+
export function reportKitInlineError(from: Element | null, message: string, key: string, fallback: () => void): void {
|
|
83
|
+
if (!showKitInlineError(from, message, key)) fallback();
|
|
84
|
+
}
|
package/src/base/input.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
type KitApi, type KitProps, type KitSize,
|
|
17
17
|
} from './shared';
|
|
18
18
|
import { kitText } from '../i18n/kit-text';
|
|
19
|
-
import { kitIcon } from '
|
|
19
|
+
import { KIT_ICON_NAMES, kitIcon, type KitIconName } from '../shared/icons';
|
|
20
20
|
import {
|
|
21
21
|
KIT_PART_ATTRIBUTE,
|
|
22
22
|
KIT_PART_BUTTON,
|
|
@@ -28,6 +28,10 @@ import {
|
|
|
28
28
|
kitSelectedRecipe,
|
|
29
29
|
setKitFace,
|
|
30
30
|
} from '../recipes';
|
|
31
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
32
|
+
import { kitFocusRingRecipe } from '../recipes/state';
|
|
33
|
+
import { KIT_COMPACT_GROUP_ATTR, kitCompactGroupRecipe, markKitCompactGroup } from '../recipes/compact-group';
|
|
34
|
+
import { mergeClass } from '../shared/merge-class';
|
|
31
35
|
|
|
32
36
|
export {
|
|
33
37
|
KIT_PART_CONTROL,
|
|
@@ -51,16 +55,24 @@ type BoxState = 'on' | 'ro' | 'off';
|
|
|
51
55
|
|
|
52
56
|
const WRAP_PLAIN = 'block w-full';
|
|
53
57
|
// 装饰模式的外壳:边框 / 底色 / 焦点环在外壳上(focus-within);档位的高度与内边距另给一串
|
|
58
|
+
// 外壳的边只取控件轮廓出口(与裸输入框同一条线,KT-B1 / §4 C6);只读 / 禁用整串不出悬停色
|
|
59
|
+
const BOX_EDGE = {
|
|
60
|
+
outline: { live: kitControlEdgeRecipe({ wrapper: true }), still: kitControlEdgeRecipe({ wrapper: true, hover: false }) },
|
|
61
|
+
filled: { live: kitControlEdgeRecipe({ variant: 'filled', wrapper: true }), still: kitControlEdgeRecipe({ variant: 'filled', wrapper: true, hover: false }) },
|
|
62
|
+
} as const;
|
|
63
|
+
// 装饰外框(前后缀、清除钮)的焦点 = 输入类焦点出口的 focus-within 版(KT-K0-3:主色边 + 2px 外环 + 外晕,与普通输入框同一出口、同一宽度)
|
|
64
|
+
const BOX_FOCUS = kitFocusRingRecipe('wrapper');
|
|
65
|
+
// 填充变体的底取控件引擎 filled 变体的同一底色(KT-K-input-1)
|
|
54
66
|
const BOX_CLASS: Record<InputVariant, Record<BoxState, string>> = {
|
|
55
67
|
outline: {
|
|
56
|
-
on:
|
|
57
|
-
ro:
|
|
58
|
-
off:
|
|
68
|
+
on: `flex w-full items-center gap-2 rounded-md ${BOX_EDGE.outline.live} bg-surface text-fg transition-colors ${BOX_FOCUS}`,
|
|
69
|
+
ro: `flex w-full items-center gap-2 rounded-md ${BOX_EDGE.outline.still} bg-surface-sunken text-fg transition-colors ${BOX_FOCUS}`,
|
|
70
|
+
off: `flex w-full cursor-not-allowed items-center gap-2 rounded-md ${BOX_EDGE.outline.still} bg-control-disabled text-fg-disabled`,
|
|
59
71
|
},
|
|
60
72
|
filled: {
|
|
61
|
-
on:
|
|
62
|
-
ro:
|
|
63
|
-
off:
|
|
73
|
+
on: `flex w-full items-center gap-2 rounded-md ${BOX_EDGE.filled.live} bg-surface-sunken text-fg transition-colors focus-within:bg-surface ${BOX_FOCUS}`,
|
|
74
|
+
ro: `flex w-full items-center gap-2 rounded-md ${BOX_EDGE.filled.still} bg-surface-sunken text-fg transition-colors ${BOX_FOCUS}`,
|
|
75
|
+
off: `flex w-full cursor-not-allowed items-center gap-2 rounded-md ${BOX_EDGE.filled.still} bg-control-disabled text-fg-disabled`,
|
|
64
76
|
},
|
|
65
77
|
};
|
|
66
78
|
const BOX_SIZE: Record<KitSize, string> = {
|
|
@@ -74,14 +86,24 @@ const BARE_CLASS: Record<KitSize, string> = {
|
|
|
74
86
|
lg: 'min-w-0 flex-1 bg-transparent text-base text-fg placeholder:text-fg-subtle focus-visible:outline-none disabled:cursor-not-allowed',
|
|
75
87
|
};
|
|
76
88
|
const AFFIX_CLASS = 'shrink-0 text-fg-muted';
|
|
77
|
-
const
|
|
89
|
+
const ICON_AFFIX_CLASS = 'inline-flex shrink-0 text-fg-subtle';
|
|
90
|
+
const ICON_BTN_CLASS = 'inline-flex min-h-6 min-w-6 shrink-0 items-center justify-center rounded-sm px-1 text-sm text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:text-fg-disabled';
|
|
78
91
|
const COUNTER_CLASS = 'shrink-0 text-xs tabular-nums text-fg-subtle';
|
|
79
|
-
|
|
92
|
+
// 动作类后缀(suffix.action,如「发送验证码」)在框外(KT-K-input-4,二-15):输入框与动作钮成一个紧凑组合(共用一条边、同档高、
|
|
93
|
+
// 悬停 / 聚焦项抬层,KT-B7),动作钮 = 同档的描边中性钮(控件引擎出口,焦点 / 禁用随引擎);辅助类(清除、显隐、单位、计数)仍在框内
|
|
94
|
+
const SUFFIX_BTN_CLASS: Record<KitSize, string> = {
|
|
95
|
+
sm: mergeClass(kitControlRecipe({ size: 'sm', variant: 'neutral', pointer: true }), 'shrink-0 whitespace-nowrap'),
|
|
96
|
+
md: mergeClass(kitControlRecipe({ size: 'md', variant: 'neutral', pointer: true }), 'shrink-0 whitespace-nowrap'),
|
|
97
|
+
lg: mergeClass(kitControlRecipe({ size: 'lg', variant: 'neutral', pointer: true }), 'shrink-0 whitespace-nowrap'),
|
|
98
|
+
};
|
|
99
|
+
/** 外层:没有动作类后缀时只是块级包层;有时成紧凑组合(输入框外框 + 动作钮) */
|
|
100
|
+
const OUTER_PLAIN = 'block w-full';
|
|
101
|
+
const OUTER_GROUP = mergeClass(kitCompactGroupRecipe('x'), 'flex w-full');
|
|
80
102
|
const HIDDEN = 'hidden';
|
|
81
103
|
|
|
82
104
|
export const KIT_INPUT_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
83
105
|
WRAP_PLAIN, Object.values(BOX_CLASS).flatMap((m) => Object.values(m)), Object.values(BOX_SIZE), Object.values(BARE_CLASS),
|
|
84
|
-
AFFIX_CLASS, ICON_BTN_CLASS, COUNTER_CLASS, SUFFIX_BTN_CLASS, HIDDEN, FIELD_INVALID_CLASS,
|
|
106
|
+
AFFIX_CLASS, ICON_AFFIX_CLASS, ICON_BTN_CLASS, COUNTER_CLASS, Object.values(SUFFIX_BTN_CLASS), OUTER_PLAIN, OUTER_GROUP, HIDDEN, FIELD_INVALID_CLASS,
|
|
85
107
|
);
|
|
86
108
|
|
|
87
109
|
// 外壳子元素的固定次序(模板与 render 共用)
|
|
@@ -90,7 +112,8 @@ const CLEAR = 2;
|
|
|
90
112
|
const TOGGLE = 3;
|
|
91
113
|
const COUNTER = 4;
|
|
92
114
|
const SUFFIX_TEXT = 5;
|
|
93
|
-
|
|
115
|
+
/** 动作类后缀钮:外框的下一个兄弟(框外,紧凑组合里的第二项) */
|
|
116
|
+
const suffixBtnOf = (root: HTMLElement): HTMLButtonElement => (root.parentElement as HTMLElement).nextElementSibling as HTMLButtonElement;
|
|
94
117
|
|
|
95
118
|
interface SuffixSpec {
|
|
96
119
|
text: string;
|
|
@@ -154,7 +177,7 @@ function paintLive(el: HTMLInputElement, p: KitProps): void {
|
|
|
154
177
|
|
|
155
178
|
/** 后缀动作钮:文字 / 倒数 / 禁用 */
|
|
156
179
|
function paintAction(root: HTMLElement, p: KitProps): void {
|
|
157
|
-
const btn =
|
|
180
|
+
const btn = suffixBtnOf(root);
|
|
158
181
|
const spec = suffixOf(p.suffix, root);
|
|
159
182
|
if (spec.action === '') {
|
|
160
183
|
btn.className = HIDDEN;
|
|
@@ -163,7 +186,7 @@ function paintAction(root: HTMLElement, p: KitProps): void {
|
|
|
163
186
|
}
|
|
164
187
|
const s = stateOf(root);
|
|
165
188
|
const counting = s.left > 0;
|
|
166
|
-
btn.className = SUFFIX_BTN_CLASS;
|
|
189
|
+
btn.className = SUFFIX_BTN_CLASS[sizeOf(p.size)];
|
|
167
190
|
btn.textContent = counting ? spec.countdownLabel.replace('{n}', String(s.left)) : spec.action;
|
|
168
191
|
btn.disabled = counting || bool(p.disabled) || bool(p.readonly);
|
|
169
192
|
if (btn.disabled) btn.setAttribute('aria-disabled', 'true');
|
|
@@ -182,6 +205,7 @@ export function createInput(): SomaComponentDefinition {
|
|
|
182
205
|
variant: { type: 'enum', values: ['outline', 'filled'], default: 'outline', desc: 'outline = 描边;filled = 浅底' },
|
|
183
206
|
clearable: { type: 'boolean', default: false, desc: '有值时显示清除钮;点后清空并抛 change { value: \'\' } 与 clear' },
|
|
184
207
|
prefix: { type: 'string', default: '', desc: '前缀文字(如 ¥、https://)' },
|
|
208
|
+
icon: { type: 'string', default: '', desc: '前置图标(kit 图标名,如 search);写了就盖过前缀文字' },
|
|
185
209
|
suffix: { type: 'string', default: '', desc: '后缀文字;也可传对象 { text?, action?, countdown?, countdown_label? }:action = 后缀文字钮(点击抛 suffix_click),countdown = 点后倒数秒数(钮禁用),countdown_label 里 {n} 为剩余秒数' },
|
|
186
210
|
counter: { type: 'boolean', default: false, desc: '显示字数;配 max 时显示 n/max' },
|
|
187
211
|
max: { type: 'number', default: 0, desc: '最大字符数(原生 maxlength);0 = 不限' },
|
|
@@ -202,7 +226,7 @@ export function createInput(): SomaComponentDefinition {
|
|
|
202
226
|
suffix_click: { payload: {}, desc: '点后缀动作钮(suffix.action);倒数中与 disabled 时不抛' },
|
|
203
227
|
},
|
|
204
228
|
},
|
|
205
|
-
templateHtml: `<span class="${WRAP_PLAIN}"><span class="${HIDDEN}"></span><input data-soma-id="root" data-kit-part="${KIT_PART_CONTROL}" type="text" class="${INPUT_CLASS.md}" /><button type="button" class="${HIDDEN}"></button><button type="button" class="${HIDDEN}"></button><span class="${HIDDEN}"></span><span class="${HIDDEN}"></span><button type="button" class="${HIDDEN}"></button></span>`,
|
|
229
|
+
templateHtml: `<span class="${OUTER_PLAIN}"><span class="${WRAP_PLAIN}"><span class="${HIDDEN}"></span><input data-soma-id="root" data-kit-part="${KIT_PART_CONTROL}" type="text" class="${INPUT_CLASS.md}" /><button type="button" class="${HIDDEN}"></button><button type="button" class="${HIDDEN}"></button><span class="${HIDDEN}"></span><span class="${HIDDEN}"></span></span><button type="button" class="${HIDDEN}"></button></span>`,
|
|
206
230
|
controllerFactory: createKitController(() => ({
|
|
207
231
|
attach(root, api) {
|
|
208
232
|
const el = root as HTMLInputElement;
|
|
@@ -211,7 +235,7 @@ export function createInput(): SomaComponentDefinition {
|
|
|
211
235
|
const k = kids(root);
|
|
212
236
|
const clear = k[CLEAR] as HTMLElement;
|
|
213
237
|
const toggle = k[TOGGLE] as HTMLElement;
|
|
214
|
-
const sfx =
|
|
238
|
+
const sfx = suffixBtnOf(root);
|
|
215
239
|
const onInput = (): void => {
|
|
216
240
|
const p = api.props();
|
|
217
241
|
paintLive(el, p);
|
|
@@ -291,11 +315,23 @@ export function createInput(): SomaComponentDefinition {
|
|
|
291
315
|
const spec = suffixOf(p.suffix, root);
|
|
292
316
|
const variant: InputVariant = p.variant === 'filled' ? 'filled' : 'outline';
|
|
293
317
|
el.setAttribute(KIT_PART_ATTRIBUTE, kitControlPartOf({ size, variant }));
|
|
294
|
-
const boxed = variant === 'filled' || bool(p.clearable) || bool(p.counter) || toggleOn || prefix !== '' || spec.text !== '' || spec.action !== '';
|
|
318
|
+
const boxed = variant === 'filled' || bool(p.clearable) || bool(p.counter) || toggleOn || prefix !== '' || str(p.icon) !== '' || spec.text !== '' || spec.action !== '';
|
|
319
|
+
// 动作类后缀在框外:外层成紧凑组合(KT-K-input-4);有动作时走装饰外框,外框是组合的直接子项(内侧圆角由结构 CSS 按 data-kit-compact 清)
|
|
320
|
+
const outer = wrap.parentElement as HTMLElement;
|
|
321
|
+
outer.className = spec.action !== '' ? OUTER_GROUP : OUTER_PLAIN;
|
|
322
|
+
if (spec.action !== '') markKitCompactGroup(outer, 'x');
|
|
323
|
+
else outer.removeAttribute(KIT_COMPACT_GROUP_ATTR);
|
|
295
324
|
|
|
296
325
|
const prefixEl = k[PREFIX] as HTMLElement;
|
|
297
|
-
|
|
298
|
-
|
|
326
|
+
// 前置图标(icon 写 kit 图标名,如搜索框的 search)优先于前缀文字
|
|
327
|
+
const iconName = str(p.icon);
|
|
328
|
+
if (iconName !== '' && (KIT_ICON_NAMES as readonly string[]).includes(iconName)) {
|
|
329
|
+
prefixEl.replaceChildren(kitIcon(iconName as KitIconName, 'md'));
|
|
330
|
+
prefixEl.className = ICON_AFFIX_CLASS;
|
|
331
|
+
} else {
|
|
332
|
+
prefixEl.textContent = prefix;
|
|
333
|
+
prefixEl.className = prefix === '' ? HIDDEN : AFFIX_CLASS;
|
|
334
|
+
}
|
|
299
335
|
|
|
300
336
|
const clear = k[CLEAR] as HTMLElement;
|
|
301
337
|
clear.replaceChildren(kitIcon('close', 'sm'));
|
package/src/base/kbd.ts
CHANGED
|
@@ -11,10 +11,11 @@ import {
|
|
|
11
11
|
import { setKitFace } from '../recipes';
|
|
12
12
|
|
|
13
13
|
const ROOT_CLASS = 'inline-flex items-center gap-1';
|
|
14
|
+
// 键帽与芯片同一种形体:浅底、无描边、无阴影(静止的面不画阴影,D-04;控件里 / 正文里不套第二圈线)
|
|
14
15
|
const KEY_CLASS: Record<KitSize, string> = {
|
|
15
|
-
sm: 'inline-flex h-5 min-w-5 items-center justify-center rounded-sm
|
|
16
|
-
md: 'inline-flex h-6 min-w-6 items-center justify-center rounded-md
|
|
17
|
-
lg: 'inline-flex h-8 min-w-8 items-center justify-center rounded-md
|
|
16
|
+
sm: 'inline-flex h-5 min-w-5 items-center justify-center rounded-sm bg-surface-sunken px-1 font-mono text-xs text-fg-muted',
|
|
17
|
+
md: 'inline-flex h-6 min-w-6 items-center justify-center rounded-md bg-surface-sunken px-1.5 font-mono text-xs text-fg-muted',
|
|
18
|
+
lg: 'inline-flex h-8 min-w-8 items-center justify-center rounded-md bg-surface-sunken px-2 font-mono text-sm text-fg-muted',
|
|
18
19
|
};
|
|
19
20
|
const SEP_CLASS = 'text-xs text-fg-subtle';
|
|
20
21
|
|
package/src/base/link.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
5
5
|
import { kitText } from '../i18n/kit-text';
|
|
6
|
-
import { kitIcon } from '
|
|
6
|
+
import { kitIcon } from '../shared/icons';
|
|
7
7
|
import {
|
|
8
8
|
CLASS_PROP, ID_PROPS, SIZE_PROP, TOOLTIP_PROP, BADGE_PROPS, KIT_BADGE_CLASS_CANDIDATES,
|
|
9
9
|
applyCommon, bool, classCandidates, createKitController, joinClass, paintBadge, setAttr, sizeOf, str, withBadgeAnchor, withTooltip, type KitSize,
|