soma-kit 0.1.14 → 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 +4 -2
- package/spec/generated/kit-page.schema.json +72 -2
- package/spec/kit-grammar.json +163 -57
- package/spec/kit-grammar.schema.json +0 -24
- package/src/app/app-config.ts +1 -1
- 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 +7 -7
- package/src/app/kit-view-context.ts +11 -2
- 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 +30 -15
- 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/fab.ts +11 -6
- package/src/base/gap-value.ts +1 -1
- package/src/base/hint-tips.ts +1 -1
- package/src/base/index.ts +15 -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 +63 -27
- 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 +2 -2
- 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 +35 -36
- package/src/base/select.ts +1 -0
- package/src/base/shared.ts +43 -7
- package/src/base/status-tone.ts +1 -1
- package/src/base/tag-input.ts +13 -8
- package/src/base/tag.ts +53 -59
- package/src/base/text.ts +37 -13
- 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 +21 -13
- package/src/biz/approval-desk/compile.ts +28 -1
- package/src/biz/approval-desk/shell.ts +2 -2
- package/src/biz/auth-panel/compile.ts +1 -1
- package/src/biz/auth-panel/shell.ts +2 -2
- package/src/biz/category-crud/compile.ts +17 -4
- package/src/biz/category-crud/shell.ts +7 -5
- package/src/biz/checkout-page/compile.ts +1 -1
- package/src/biz/checkout-page/shell.ts +7 -6
- package/src/biz/compose.ts +3 -3
- package/src/biz/define.ts +1 -1
- package/src/biz/import-wizard/compile.ts +1 -1
- package/src/biz/import-wizard/shell.ts +6 -4
- package/src/biz/index.ts +4 -3
- package/src/biz/landing-page/compile.ts +1 -1
- package/src/biz/landing-page/shell.ts +5 -4
- package/src/biz/link/shared.ts +8 -1
- package/src/biz/master-sub/compile.ts +162 -19
- package/src/biz/master-sub/detail-head.ts +7 -6
- package/src/biz/master-sub/index.ts +3 -3
- package/src/biz/master-sub/shell.ts +90 -53
- package/src/biz/multi-board/compile.ts +3 -3
- package/src/biz/multi-board/index.ts +24 -9
- package/src/biz/multi-board/prose-fold.ts +2 -2
- package/src/biz/multi-board/shell.ts +17 -13
- package/src/biz/names.ts +1 -0
- package/src/biz/notification-center/compile.ts +9 -2
- package/src/biz/notification-center/shell.ts +9 -2
- package/src/biz/page-templates/domain-templates.ts +6 -2
- package/src/biz/page-templates/result-page/compile.ts +1 -1
- package/src/biz/page-templates/result-page/shell.ts +4 -3
- 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 +4 -4
- package/src/biz/record-detail/compile.ts +5 -2
- package/src/biz/record-detail/shell.ts +4 -4
- package/src/biz/settings-center/compile.ts +1 -1
- package/src/biz/settings-center/shell.ts +8 -5
- package/src/biz/shared/action-host.ts +12 -5
- package/src/biz/shared/compile-helpers.ts +4 -4
- package/src/biz/shared/coordinator.ts +104 -21
- package/src/biz/shared/overlay-compile.ts +48 -18
- package/src/biz/shared/overlay-shell.ts +63 -112
- package/src/biz/single-form/compile.ts +2 -2
- package/src/biz/single-form/shell.ts +8 -4
- package/src/biz/standard-crud/compile.ts +11 -4
- package/src/biz/standard-crud/shell.ts +26 -9
- package/src/biz/standard-crud/summary.ts +3 -1
- 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 +6 -4
- package/src/biz/types.ts +11 -4
- 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/compile/access-gate-attach.ts +1 -1
- package/src/compile/action-host-attach.ts +1 -1
- package/src/compile/compile-page.ts +29 -234
- package/src/compile/component-candidates.ts +2 -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 +43 -13
- package/src/compile/page-composition.ts +33 -31
- package/src/compile/redirect.ts +1 -1
- package/src/compile/stages.ts +169 -0
- package/src/compile/styles.ts +70 -32
- package/src/compile/types.ts +2 -2
- package/src/data/amount-breakdown.ts +4 -2
- package/src/data/anchor-nav.ts +4 -1
- package/src/data/approval-flow.ts +9 -4
- package/src/data/assignment-picker.ts +28 -18
- package/src/data/async-result-panel.ts +6 -2
- package/src/data/breadcrumbs.ts +13 -9
- package/src/data/calendar.ts +4 -3
- package/src/data/carousel.ts +11 -5
- package/src/data/chart.ts +153 -23
- package/src/data/checklist.ts +5 -4
- package/src/data/code-view.ts +220 -26
- package/src/data/comment-thread.ts +7 -2
- package/src/data/confirm-dialog.ts +56 -13
- 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 +12 -6
- package/src/data/flow-editor.ts +105 -29
- package/src/data/footer.ts +6 -2
- package/src/data/gantt.ts +11 -8
- package/src/data/hero.ts +6 -2
- package/src/data/image-viewer.ts +7 -3
- package/src/data/index.ts +12 -5
- package/src/data/item-list.ts +6 -5
- package/src/data/json-view.ts +844 -0
- package/src/data/kanban.ts +11 -8
- package/src/data/markdown-view.ts +487 -0
- package/src/data/matrix.ts +23 -14
- 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 +15 -9
- package/src/data/mockup.ts +9 -5
- package/src/data/modal-dialog.ts +39 -88
- package/src/data/navbar.ts +11 -7
- package/src/data/notice-list.ts +1 -1
- package/src/data/notify-renderer.ts +21 -10
- package/src/data/object-form.ts +129 -48
- package/src/data/pager.ts +12 -8
- package/src/data/panel-head.ts +1 -1
- package/src/data/permission-matrix.ts +15 -8
- package/src/data/permission-tree.ts +24 -11
- package/src/data/pricing-table.ts +8 -3
- package/src/data/reaction-bar.ts +6 -3
- package/src/data/record-card.ts +13 -9
- 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 +0 -12
- package/src/data/result-panel.ts +2 -2
- package/src/data/rich-text.ts +58 -96
- package/src/data/row-editor.ts +10 -5
- package/src/data/rule-builder.ts +14 -8
- package/src/data/shape-util.ts +14 -3
- package/src/data/stat-group.ts +63 -22
- package/src/data/static-lazy.ts +3 -0
- package/src/data/static-registry.ts +8 -2
- package/src/data/steps.ts +6 -2
- package/src/data/survey.ts +9 -3
- package/src/data/system-switcher.ts +15 -6
- package/src/data/text-diff.ts +663 -0
- package/src/data/timeline.ts +1 -1
- package/src/data/tour-guide.ts +6 -3
- package/src/data/transfer.ts +19 -10
- package/src/data/tree-table.ts +77 -12
- package/src/data/tree.ts +5 -2
- package/src/data/virtual-rows.ts +17 -7
- package/src/data/wrap.ts +2 -2
- package/src/frames/index.ts +3 -2
- package/src/frames/inherited-shell.ts +178 -0
- package/src/frames/list-summary.ts +59 -36
- package/src/frames/page-bar.ts +4 -2
- package/src/frames/resident-components.ts +20 -0
- package/src/frames/shared.ts +18 -14
- 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 +12 -6
- package/src/frames/types.ts +3 -2
- package/src/frames/workspace-frame/extras.ts +19 -5
- package/src/frames/workspace-frame/shell.ts +2 -1
- package/src/frames/workspace-frame/state.ts +8 -2
- package/src/frames/workspace-frame/view.ts +125 -76
- package/src/generated/kit-grammar-runtime.ts +61 -39
- package/src/i18n/kit-text.ts +114 -2
- package/src/i18n/resolve-text-refs.ts +1 -1
- package/src/object-renderer/action-group.ts +31 -1
- package/src/object-renderer/action-more.ts +28 -12
- package/src/object-renderer/arrange.ts +37 -7
- package/src/object-renderer/collection-parts.ts +38 -7
- package/src/object-renderer/collection-table.ts +68 -23
- package/src/object-renderer/collection.ts +63 -30
- package/src/object-renderer/compile-data.ts +1 -1
- package/src/object-renderer/defaults.ts +8 -0
- package/src/object-renderer/emit-events.ts +1 -1
- package/src/object-renderer/emit-object.ts +3 -0
- package/src/object-renderer/emit-static.ts +140 -37
- package/src/object-renderer/field-value.ts +12 -239
- package/src/object-renderer/filter-toolbar.ts +103 -0
- package/src/{compile → object-renderer}/fragment.ts +2 -2
- package/src/object-renderer/index.ts +1 -1
- package/src/object-renderer/layout-facts.ts +37 -5
- package/src/object-renderer/overlay-decide.ts +82 -0
- package/src/object-renderer/render-object.ts +1 -1
- package/src/object-renderer/table-actions.ts +70 -23
- package/src/object-renderer/table-tools.ts +12 -5
- package/src/object-renderer/types.ts +9 -15
- 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 +25 -15
- package/src/recipes/control.ts +21 -3
- package/src/recipes/desc-list.ts +14 -0
- package/src/recipes/divider.ts +53 -0
- package/src/recipes/emphasis.ts +12 -8
- package/src/recipes/frame-bleed.ts +3 -3
- package/src/recipes/index.ts +11 -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 +112 -26
- package/src/recipes/page-width.ts +20 -0
- package/src/recipes/placeholder.ts +1 -1
- package/src/recipes/stat-state.ts +1 -1
- package/src/recipes/state.ts +10 -8
- package/src/recipes/status.ts +13 -12
- package/src/recipes/strip.ts +72 -0
- package/src/recipes/surface.ts +10 -6
- package/src/recipes/table-gap.ts +1 -1
- package/src/recipes/table-native-edit.ts +4 -4
- package/src/recipes/table-row.ts +11 -8
- package/src/recipes/tabs.ts +108 -31
- package/src/recipes/text-diff.ts +90 -0
- package/src/recipes/title-row.ts +4 -2
- package/src/recipes/typography.ts +2 -2
- 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 +38 -14
- package/src/theme/kit-theme.tpl +38 -14
- package/src/theme/nine-dim-structure.ts +66 -41
- package/src/theme/surface-layers.ts +11 -3
- package/src/theme/theme-tokens.ts +5 -1
- 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
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
14
|
import { setKitFace, setKitFixed } from '../recipes';
|
|
15
|
+
import { kitButtonEdgeRecipe } from '../recipes/control';
|
|
16
|
+
import { KIT_DIVIDER_HEAD_CLASS } from '../recipes/divider';
|
|
17
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
18
|
+
import { mergeClass } from '../shared/merge-class';
|
|
15
19
|
import type { CollectionItem } from 'soma-core/keyboard';
|
|
16
20
|
import {
|
|
17
21
|
EMPTY_ROW_CLASS, cssEscape, createListNav, optionClass, scrollIntoViewIfAny,
|
|
@@ -22,12 +26,14 @@ import {
|
|
|
22
26
|
} from './shared';
|
|
23
27
|
|
|
24
28
|
const ROOT = 'inline-block';
|
|
25
|
-
|
|
26
|
-
const
|
|
29
|
+
// 触发钮 = 带文字中性按钮描边(KT-B1);快捷键提示 = 浅底芯片(无描边);面板 = 浮层表面(KT-B4);搜索框只画朝内的一条分隔线
|
|
30
|
+
const TRIGGER_EDGE = kitButtonEdgeRecipe();
|
|
31
|
+
const TRIGGER = `inline-flex h-8 cursor-pointer items-center gap-3 rounded-md ${TRIGGER_EDGE} bg-surface px-3 text-sm text-fg-muted transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60`;
|
|
32
|
+
const TRIGGER_KEYS = 'rounded-sm bg-surface-sunken px-1.5 py-0.5 text-xs text-fg-subtle';
|
|
27
33
|
const HIDDEN = 'hidden';
|
|
28
34
|
const OVERLAY = 'fixed inset-0 z-50 flex items-start justify-center bg-scrim p-4';
|
|
29
|
-
const DIALOG = 'mt-24 flex max-h-96 w-full max-w-lg flex-col overflow-hidden
|
|
30
|
-
const SEARCH =
|
|
35
|
+
const DIALOG = mergeClass('mt-24 flex max-h-96 w-full max-w-lg flex-col overflow-hidden motion-safe:animate-kit-rise', kitSurfaceRecipe('overlay'));
|
|
36
|
+
const SEARCH = `block h-10 w-full appearance-none autofill-clear ${KIT_DIVIDER_HEAD_CLASS} bg-transparent px-4 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none`;
|
|
31
37
|
const LIST = 'min-h-0 flex-1 overflow-auto py-1';
|
|
32
38
|
const GROUP_LABEL = 'px-4 pb-1 pt-2 text-xs font-semibold text-fg-subtle';
|
|
33
39
|
const STATUS = 'sr-only';
|
package/src/base/context-menu.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// 3. 触发区的外观:虚线框的「右键此处」区域。
|
|
9
9
|
|
|
10
10
|
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
11
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
11
12
|
import { classCandidates } from './shared';
|
|
12
13
|
|
|
13
14
|
export type Corner = 'tl' | 'tr' | 'bl' | 'br';
|
|
@@ -22,8 +23,10 @@ export const CONTEXT_SHOWN: Record<Corner, string> = {
|
|
|
22
23
|
};
|
|
23
24
|
/** 按点挂浮层时的面板类(fixed,几何由 portal-core 的 showAtPoint 一次写入;无 style= 字面量;进场由 showAtPoint 打的 data-kit-anchored 规则统一驱动) */
|
|
24
25
|
export const CONTEXT_POINT_PANEL = `fixed z-50 flex min-w-40 flex-col ${MENU_PANEL_SURFACE} p-1`;
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
// 右键触发区 = 控件(虚线控件轮廓,与上传投放区同一出口,KT-B1 / §4 C6)
|
|
27
|
+
const AREA_EDGE = kitControlEdgeRecipe({ wrapper: true, hover: false });
|
|
28
|
+
export const CONTEXT_AREA ='block w-full cursor-context-menu rounded-lg ' + AREA_EDGE + ' border-dashed bg-surface px-4 py-6 text-center text-sm text-fg-muted transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
29
|
+
export const CONTEXT_AREA_OFF = 'block w-full cursor-not-allowed rounded-lg ' + AREA_EDGE + ' border-dashed bg-surface-sunken px-4 py-6 text-center text-sm text-fg-subtle opacity-60';
|
|
27
30
|
const LONG_PRESS_MS = 500;
|
|
28
31
|
|
|
29
32
|
export const KIT_CONTEXT_MENU_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
package/src/base/date-range.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from './date';
|
|
19
19
|
import { weekStartProp } from './month-grid';
|
|
20
20
|
import { setKitFace } from '../recipes';
|
|
21
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
21
22
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
22
23
|
|
|
23
24
|
const RANGE_CLASS: Record<KitSize, string> = {
|
|
@@ -28,15 +29,17 @@ const RANGE_CLASS: Record<KitSize, string> = {
|
|
|
28
29
|
|
|
29
30
|
const FIELDS_CLASS = 'relative inline-flex items-center gap-2';
|
|
30
31
|
const HIDDEN_CLASS = 'hidden';
|
|
32
|
+
// 两个日期框与日历钮的边 = 控件轮廓出口(KT-B1 / §4 C6)
|
|
33
|
+
const EDGE = kitControlEdgeRecipe();
|
|
31
34
|
const DATE_CLASS: Record<KitSize, string> = {
|
|
32
|
-
sm:
|
|
33
|
-
md:
|
|
34
|
-
lg:
|
|
35
|
+
sm: `block h-6 w-32 rounded-md ${EDGE} bg-surface px-2.5 text-sm text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger`,
|
|
36
|
+
md: `block h-8 w-36 rounded-md ${EDGE} bg-surface px-3 text-sm text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger`,
|
|
37
|
+
lg: `block h-10 w-40 rounded-md ${EDGE} bg-surface px-4 text-base text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger`,
|
|
35
38
|
};
|
|
36
39
|
const OPEN_BTN_CLASS: Record<KitSize, string> = {
|
|
37
|
-
sm:
|
|
38
|
-
md:
|
|
39
|
-
lg:
|
|
40
|
+
sm: `inline-flex size-6 shrink-0 p-0 cursor-pointer items-center justify-center rounded-md ${EDGE} bg-surface text-fg-subtle transition-colors enabled:hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60`,
|
|
41
|
+
md: `inline-flex size-8 shrink-0 p-0 cursor-pointer items-center justify-center rounded-md ${EDGE} bg-surface text-fg-subtle transition-colors enabled:hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60`,
|
|
42
|
+
lg: `inline-flex size-10 shrink-0 p-0 cursor-pointer items-center justify-center rounded-md ${EDGE} bg-surface text-fg-subtle transition-colors enabled:hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60`,
|
|
40
43
|
};
|
|
41
44
|
const ICON_CLASS = 'size-4 pointer-events-none';
|
|
42
45
|
|
package/src/base/date.ts
CHANGED
|
@@ -20,9 +20,13 @@ import {
|
|
|
20
20
|
CLASS_PROP, FIELD_INVALID_CLASS, ID_PROPS, INVALID_PROPS, SIZE_PROP,
|
|
21
21
|
applyCommon, classCandidates, bool, createKitController, joinClass, nextUid, setAttr, sizeOf, str, withInvalid, type KitApi, type KitProps, type KitSize,
|
|
22
22
|
} from './shared';
|
|
23
|
-
import { kitIcon } from '
|
|
23
|
+
import { kitIcon } from '../shared/icons';
|
|
24
24
|
import { setKitFace } from '../recipes';
|
|
25
|
-
import {
|
|
25
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
26
|
+
|
|
27
|
+
// 日期框的边 = 控件轮廓出口(KT-B1 / §4 C6,与输入框同一条控件线)
|
|
28
|
+
const CONTROL_EDGE = kitControlEdgeRecipe();
|
|
29
|
+
import { mergeClass } from '../shared/merge-class';
|
|
26
30
|
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
27
31
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, focusCellQuiet, handoffTab, onOutsidePress, releaseDropdown, syncDropdown, trackInputModality } from './popup';
|
|
28
32
|
|
|
@@ -31,15 +35,15 @@ import { KIT_DROPDOWN_CLASS_CANDIDATES, focusCellQuiet, handoffTab, onOutsidePre
|
|
|
31
35
|
const ROOT_CLASS = 'relative block w-full';
|
|
32
36
|
const HIDDEN_CLASS = 'hidden';
|
|
33
37
|
const INPUT_CLASS: Record<KitSize, string> = {
|
|
34
|
-
sm: 'block h-6 w-full appearance-none autofill-clear rounded-md
|
|
35
|
-
md: 'block h-8 w-full appearance-none autofill-clear rounded-md
|
|
36
|
-
lg: 'block h-10 w-full appearance-none autofill-clear rounded-md
|
|
38
|
+
sm: 'block h-6 w-full appearance-none autofill-clear rounded-md ' + CONTROL_EDGE + ' bg-surface ps-2.5 pe-8 text-sm text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
39
|
+
md: 'block h-8 w-full appearance-none autofill-clear rounded-md ' + CONTROL_EDGE + ' bg-surface ps-3 pe-8 text-sm text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
40
|
+
lg: 'block h-10 w-full appearance-none autofill-clear rounded-md ' + CONTROL_EDGE + ' bg-surface ps-4 pe-9 text-base text-fg transition-colors placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:bg-surface-sunken disabled:text-fg-subtle disabled:opacity-60 read-only:bg-surface-sunken aria-invalid:border-danger',
|
|
37
41
|
};
|
|
38
42
|
const OPEN_BTN_CLASS = 'absolute end-0 top-0 border-0 bg-transparent flex h-full w-8 p-0 cursor-pointer items-center justify-center rounded-md text-fg-subtle transition-colors enabled:hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
39
43
|
const CLEAR_BTN_CLASS = 'absolute end-8 top-0 border-0 bg-transparent flex h-full w-6 p-0 cursor-pointer items-center justify-center rounded-md text-fg-subtle transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
40
44
|
const ICON_CLASS = 'size-4 pointer-events-none';
|
|
41
45
|
|
|
42
|
-
const PANEL_BASE = mergeClass('absolute z-10 flex w-max flex-col gap-2 p-4', kitSurfaceRecipe('raised'));
|
|
46
|
+
const PANEL_BASE = mergeClass('absolute z-10 flex w-max min-w-full flex-col gap-2 p-4', kitSurfaceRecipe('raised'));
|
|
43
47
|
const MONTHS_CLASS = 'flex gap-4';
|
|
44
48
|
const MONTH_CLASS = 'flex flex-col gap-1';
|
|
45
49
|
const MONTH_HEAD_CLASS = 'flex items-center justify-between gap-2';
|
package/src/base/delta.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
6
6
|
import { kitLocaleAt, kitText } from '../i18n/kit-text';
|
|
7
|
-
import { kitIcon } from '
|
|
7
|
+
import { kitIcon } from '../shared/icons';
|
|
8
8
|
import {
|
|
9
9
|
CLASS_PROP, ID_PROPS, SIZE_PROP,
|
|
10
10
|
classCandidates, createKitController, formatValue, joinClass, num, setAttr, sizeOf, str,
|
|
@@ -14,11 +14,13 @@ import { trendTone, type TrendTone } from './trend-tone';
|
|
|
14
14
|
import { KIT_DELTA_TEXT } from '../recipes/typography';
|
|
15
15
|
|
|
16
16
|
const ROOT: Readonly<Record<KitSize, string>> = KIT_DELTA_TEXT;
|
|
17
|
-
|
|
17
|
+
/** 涨跌语气 → 文字色(彩色文字只用 -on-soft):KitDelta 与 StatGroup 的趋势共用这一份(趋势 = 文字 + 箭头,无底,不借标签形;KT-K-stat-4) */
|
|
18
|
+
export const KIT_DELTA_TONE_CLASS: Readonly<Record<TrendTone, string>> = {
|
|
18
19
|
good: 'text-success-on-soft',
|
|
19
20
|
bad: 'text-danger-on-soft',
|
|
20
21
|
flat: 'text-fg-muted',
|
|
21
22
|
};
|
|
23
|
+
const TONE_CLASS = KIT_DELTA_TONE_CLASS;
|
|
22
24
|
const SR_ONLY = 'sr-only';
|
|
23
25
|
const EMPTY_TEXT = '—';
|
|
24
26
|
|
package/src/base/divider.ts
CHANGED
|
@@ -7,78 +7,27 @@
|
|
|
7
7
|
|
|
8
8
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
9
|
import { CLASS_PROP, bool, createKitController, joinClass, str, type KitTone } from './shared';
|
|
10
|
+
import { kitDividerRecipe } from '../recipes/divider';
|
|
10
11
|
|
|
11
12
|
export type KitDividerTone = 'neutral' | 'primary' | KitTone;
|
|
12
13
|
const TONES: readonly KitDividerTone[] = ['neutral', 'primary', 'info', 'success', 'warning', 'danger'];
|
|
13
14
|
|
|
14
|
-
//
|
|
15
|
-
const
|
|
16
|
-
neutral: '
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
danger: 'flex-1 border-t border-danger',
|
|
22
|
-
};
|
|
23
|
-
const LINE_DASHED: Record<KitDividerTone, string> = {
|
|
24
|
-
neutral: 'flex-1 border-t border-dashed border-border-subtle',
|
|
25
|
-
primary: 'flex-1 border-t border-dashed border-primary',
|
|
26
|
-
info: 'flex-1 border-t border-dashed border-info',
|
|
27
|
-
success: 'flex-1 border-t border-dashed border-success',
|
|
28
|
-
warning: 'flex-1 border-t border-dashed border-warning',
|
|
29
|
-
danger: 'flex-1 border-t border-dashed border-danger',
|
|
30
|
-
};
|
|
15
|
+
// 线体:中性线只经分隔线出口(发丝宽、分隔灰,KT-B1 / KT-B5);语气线同宽(发丝档)、取语气色
|
|
16
|
+
const lineOf = (side: 'top' | 'start', tone: KitDividerTone): string =>
|
|
17
|
+
tone === 'neutral' ? kitDividerRecipe(side) : `border-${side === 'top' ? 't' : 's'}-hairline border-${tone}`;
|
|
18
|
+
const table = (layout: string, side: 'top' | 'start', dashed: boolean): Record<KitDividerTone, string> =>
|
|
19
|
+
Object.fromEntries(TONES.map((t) => [t, `${layout} ${lineOf(side, t)}${dashed ? ' border-dashed' : ''}`])) as Record<KitDividerTone, string>;
|
|
20
|
+
const LINE_SOLID = table('flex-1', 'top', false);
|
|
21
|
+
const LINE_DASHED = table('flex-1', 'top', true);
|
|
31
22
|
// 靠前 / 靠后时短的那一侧(定宽)
|
|
32
|
-
const LINE_SHORT_SOLID
|
|
33
|
-
|
|
34
|
-
primary: 'w-6 shrink-0 border-t border-primary',
|
|
35
|
-
info: 'w-6 shrink-0 border-t border-info',
|
|
36
|
-
success: 'w-6 shrink-0 border-t border-success',
|
|
37
|
-
warning: 'w-6 shrink-0 border-t border-warning',
|
|
38
|
-
danger: 'w-6 shrink-0 border-t border-danger',
|
|
39
|
-
};
|
|
40
|
-
const LINE_SHORT_DASHED: Record<KitDividerTone, string> = {
|
|
41
|
-
neutral: 'w-6 shrink-0 border-t border-dashed border-border-subtle',
|
|
42
|
-
primary: 'w-6 shrink-0 border-t border-dashed border-primary',
|
|
43
|
-
info: 'w-6 shrink-0 border-t border-dashed border-info',
|
|
44
|
-
success: 'w-6 shrink-0 border-t border-dashed border-success',
|
|
45
|
-
warning: 'w-6 shrink-0 border-t border-dashed border-warning',
|
|
46
|
-
danger: 'w-6 shrink-0 border-t border-dashed border-danger',
|
|
47
|
-
};
|
|
23
|
+
const LINE_SHORT_SOLID = table('w-6 shrink-0', 'top', false);
|
|
24
|
+
const LINE_SHORT_DASHED = table('w-6 shrink-0', 'top', true);
|
|
48
25
|
// 无文字的整条水平线(根自己就是线)
|
|
49
|
-
const BARE_SOLID
|
|
50
|
-
|
|
51
|
-
primary: 'block w-full border-t border-primary',
|
|
52
|
-
info: 'block w-full border-t border-info',
|
|
53
|
-
success: 'block w-full border-t border-success',
|
|
54
|
-
warning: 'block w-full border-t border-warning',
|
|
55
|
-
danger: 'block w-full border-t border-danger',
|
|
56
|
-
};
|
|
57
|
-
const BARE_DASHED: Record<KitDividerTone, string> = {
|
|
58
|
-
neutral: 'block w-full border-t border-dashed border-border-subtle',
|
|
59
|
-
primary: 'block w-full border-t border-dashed border-primary',
|
|
60
|
-
info: 'block w-full border-t border-dashed border-info',
|
|
61
|
-
success: 'block w-full border-t border-dashed border-success',
|
|
62
|
-
warning: 'block w-full border-t border-dashed border-warning',
|
|
63
|
-
danger: 'block w-full border-t border-dashed border-danger',
|
|
64
|
-
};
|
|
26
|
+
const BARE_SOLID = table('block w-full', 'top', false);
|
|
27
|
+
const BARE_DASHED = table('block w-full', 'top', true);
|
|
65
28
|
// 竖线(行内,如操作项之间)
|
|
66
|
-
const VERTICAL_SOLID
|
|
67
|
-
|
|
68
|
-
primary: 'inline-block h-4 border-l border-primary',
|
|
69
|
-
info: 'inline-block h-4 border-l border-info',
|
|
70
|
-
success: 'inline-block h-4 border-l border-success',
|
|
71
|
-
warning: 'inline-block h-4 border-l border-warning',
|
|
72
|
-
danger: 'inline-block h-4 border-l border-danger',
|
|
73
|
-
};
|
|
74
|
-
const VERTICAL_DASHED: Record<KitDividerTone, string> = {
|
|
75
|
-
neutral: 'inline-block h-4 border-l border-dashed border-border-subtle',
|
|
76
|
-
primary: 'inline-block h-4 border-l border-dashed border-primary',
|
|
77
|
-
info: 'inline-block h-4 border-l border-dashed border-info',
|
|
78
|
-
success: 'inline-block h-4 border-l border-dashed border-success',
|
|
79
|
-
warning: 'inline-block h-4 border-l border-dashed border-warning',
|
|
80
|
-
danger: 'inline-block h-4 border-l border-dashed border-danger',
|
|
81
|
-
};
|
|
29
|
+
const VERTICAL_SOLID = table('inline-block h-4', 'start', false);
|
|
30
|
+
const VERTICAL_DASHED = table('inline-block h-4', 'start', true);
|
|
82
31
|
const LABELED_ROOT = 'flex w-full items-center gap-3';
|
|
83
32
|
const LABEL_CLASS = 'shrink-0 text-xs text-fg-muted';
|
|
84
33
|
|
|
@@ -128,7 +77,7 @@ export function createKitDivider(): SomaComponentDefinition {
|
|
|
128
77
|
class: CLASS_PROP,
|
|
129
78
|
},
|
|
130
79
|
},
|
|
131
|
-
templateHtml:
|
|
80
|
+
templateHtml: `<div data-soma-id="root" role="separator" class="${BARE_SOLID.neutral}"></div>`,
|
|
132
81
|
controllerFactory: createKitController(() => ({
|
|
133
82
|
render(root, p) {
|
|
134
83
|
const plan = dividerPlan(p);
|
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,7 @@
|
|
|
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
19
|
import { resolveTextDisplay } from './text';
|
|
20
20
|
import { KIT_TABLE_GAP, KIT_TABLE_GAP_MARK, KIT_TABLE_GAP_CLASS_CANDIDATES } from '../recipes/table-gap';
|
|
21
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';
|
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';
|
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,8 @@ 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
31
|
// 应用组件内嵌下拉选择器时并入候选类
|
|
32
32
|
export { KIT_SELECT_CLASS_CANDIDATES } from './select';
|
|
33
33
|
// K9 / D1 补齐波:Range Rating Otp Avatar AvatarGroup Kbd KitProgress(环/条) Countdown Swap Fab Image MenuButton
|
|
@@ -102,6 +102,17 @@ export const KIT_D1_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
102
102
|
|
|
103
103
|
// 表格缺失值的原生表格出口(判定 / 单元格 / 列头标注;约定与阈值见 recipes/table-gap)
|
|
104
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';
|
|
105
116
|
|
|
106
117
|
export type KitBaseId =
|
|
107
118
|
| 'Text' | 'Tag' | 'Input' | 'Textarea' | 'Number' | 'Select' | 'Radio'
|
|
@@ -190,7 +201,7 @@ export const KIT_BASE_CORE_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
|
190
201
|
'border-dashed', 'border-primary', 'flex-1', 'flex-col',
|
|
191
202
|
'focus-within:ring-2', 'focus-within:ring-ring',
|
|
192
203
|
'h-2', 'h-8', 'h-full', 'items-start', 'justify-between', 'start-0',
|
|
193
|
-
'
|
|
204
|
+
'shadow-lg', 'shadow-xl', 'top-0.5', 'start-4.5', 'start-5.5', 'start-7.5',
|
|
194
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',
|
|
195
206
|
'object-cover', 'overflow-auto', 'p-1',
|
|
196
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'));
|