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/data/rich-text.ts
CHANGED
|
@@ -7,28 +7,36 @@
|
|
|
7
7
|
// 不可用环境(无 contenteditable 的执行环境)退化:命令钮不出,编辑区变只读。execCommand 缺失时命令钮禁用。
|
|
8
8
|
// 事件:`change { value, empty, length }`(输入或命令后,value 已净化;empty = 无可见文字;length = 文字长度,超 max_length 时计数变警示色,不截断)。
|
|
9
9
|
// `readonly` 为真时只展示净化后的内容,不出工具栏。
|
|
10
|
-
// `source: markdown`(A17):内容是 Markdown
|
|
10
|
+
// `source: markdown`(A17):内容是 Markdown 文本,经 core 端口 engines.markdown 解析、MarkdownView 的块渲染器出 DOM,固定只读;见「Markdown(只读来源)」段。
|
|
11
11
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
13
|
import { ID_PROPS, INVALID_PROPS, applyCommon, bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
14
14
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
15
15
|
import { setKitFace } from '../recipes';
|
|
16
|
+
import { kitControlEdgeRecipe, kitControlRecipe } from '../recipes/control';
|
|
17
|
+
import { KIT_DIVIDER_FOOT_CLASS, KIT_DIVIDER_HEAD_CLASS } from '../recipes/divider';
|
|
18
|
+
import { mergeClass } from '../shared/merge-class';
|
|
16
19
|
import { classTokens, mk, recOf } from './shape-util';
|
|
17
20
|
import { RICH_ALLOWED_TAGS, RICH_COMMANDS, RICH_LINK_PROTOCOLS, RICH_MAX_LENGTH } from './d9-limits';
|
|
21
|
+
import { kitEnginePort, type KitHighlightEnginePort, type KitMarkdownEnginePort } from './engine-ports';
|
|
22
|
+
import { KIT_MARKDOWN_VIEW_CLASS_CANDIDATES, markdownIndentTopLevel, renderMdBlock, renderMdPlain, type KitMdRenderContext } from './markdown-view';
|
|
18
23
|
|
|
19
24
|
// ───────── 样式常量:Tailwind 类串与候选类清单 ─────────
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
// 富文本是一个多行控件:外圈 = 控件轮廓(KT-B1 / §4 C6);工具条是凹底带,与编辑区之间已有面差,不再加线(一处分隔一种手段,KT-B5);
|
|
27
|
+
// 链接条 / 字数脚条只画朝内的一条分隔线(分隔线出口)
|
|
28
|
+
const ROOT_EDGE = kitControlEdgeRecipe({ wrapper: true });
|
|
29
|
+
const ROOT_CLASS = `flex flex-col overflow-hidden rounded-lg ${ROOT_EDGE} bg-surface text-sm text-fg focus-within:ring-2 focus-within:ring-ring`;
|
|
30
|
+
const BAR_CLASS = 'flex flex-wrap items-center gap-1 bg-surface-sunken p-1';
|
|
23
31
|
const BTN_CLASS = 'inline-flex h-8 min-w-8 items-center justify-center rounded-md px-2 text-sm text-fg transition-colors hover:bg-surface active:opacity-80 disabled:cursor-not-allowed disabled:opacity-60 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
24
32
|
const BTN_ON = 'inline-flex h-8 min-w-8 items-center justify-center rounded-md bg-primary-soft px-2 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
25
33
|
const BODY_CLASS = 'relative';
|
|
26
34
|
const AREA_CLASS = 'min-h-32 w-full px-3 py-2 text-sm text-fg focus-visible:outline-none';
|
|
27
35
|
const HOLDER_CLASS = 'pointer-events-none absolute start-3 top-2 text-fg-subtle';
|
|
28
|
-
const LINKBAR_CLASS =
|
|
29
|
-
const LINK_INPUT = '
|
|
30
|
-
const FOOT_CLASS =
|
|
31
|
-
const FOOT_OVER =
|
|
36
|
+
const LINKBAR_CLASS = `flex items-center gap-2 ${KIT_DIVIDER_HEAD_CLASS} p-1`;
|
|
37
|
+
const LINK_INPUT = mergeClass(kitControlRecipe(), 'min-w-0 flex-1');
|
|
38
|
+
const FOOT_CLASS = `flex justify-end ${KIT_DIVIDER_FOOT_CLASS} px-3 py-1 text-xs text-fg-subtle`;
|
|
39
|
+
const FOOT_OVER = `flex justify-end ${KIT_DIVIDER_FOOT_CLASS} px-3 py-1 text-xs text-danger-on-soft`;
|
|
32
40
|
|
|
33
41
|
/**
|
|
34
42
|
* 编辑区 / 只读区里净化后的标签样式。宿主壳把 p / h* / ul / ol 的外边距与列表符号清零、把 a 的颜色与下划线继承掉,
|
|
@@ -46,7 +54,7 @@ export const KIT_RICH_TAG_CLASS: Readonly<Record<string, string>> = Object.freez
|
|
|
46
54
|
|
|
47
55
|
export const KIT_RICH_TEXT_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
48
56
|
ROOT_CLASS, BAR_CLASS, BTN_CLASS, BTN_ON, BODY_CLASS, AREA_CLASS, HOLDER_CLASS, LINKBAR_CLASS, LINK_INPUT, FOOT_CLASS, FOOT_OVER, 'hidden',
|
|
49
|
-
Object.values(KIT_RICH_TAG_CLASS),
|
|
57
|
+
Object.values(KIT_RICH_TAG_CLASS), KIT_MARKDOWN_VIEW_CLASS_CANDIDATES,
|
|
50
58
|
);
|
|
51
59
|
|
|
52
60
|
// ───────── 内容规整:HTML 净化(白名单重建)、链接地址校验、纯文本转段落、工具栏命令解析 ─────────
|
|
@@ -156,88 +164,24 @@ export function plainToFragment(text: string, doc: Document = document): Documen
|
|
|
156
164
|
|
|
157
165
|
// ── Markdown(只读来源)──────────────────────────────────────
|
|
158
166
|
//
|
|
159
|
-
// `readonly` + `source: markdown
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
// `readonly` + `source: markdown`:原文经 core 端口 engines.markdown 解析成块树,由 MarkdownView 的同一个块渲染器
|
|
168
|
+
// (renderMdBlock:按节点类型 createElement / textContent,不经 innerHTML、不渲染原始 HTML、地址白名单在端口)画进只读区。
|
|
169
|
+
// 原先手写的 Markdown 子集转换(markdownToRichHtml / markdownInline)已删除(内容展示批次 ④:一个能力一份实现)。
|
|
170
|
+
// 宿主没装配端口时按纯文本分段显示。
|
|
171
|
+
|
|
172
|
+
/** Markdown 原文 → 只读区(异步;seq 判定后发先至) */
|
|
173
|
+
async function paintRichMarkdown(area: HTMLElement, source: string, services: unknown, isCurrent: () => boolean): Promise<void> {
|
|
174
|
+
const port = kitEnginePort<KitMarkdownEnginePort>(services, 'markdown');
|
|
175
|
+
const text = source.slice(0, RICH_MAX_LENGTH);
|
|
176
|
+
const res = port === null ? null : await port.parse(text).catch(() => null);
|
|
177
|
+
if (!isCurrent()) return;
|
|
178
|
+
area.textContent = '';
|
|
179
|
+
if (res === null || !res.ok) { renderMdPlain(area, res === null ? text : res.plainText); return; }
|
|
180
|
+
const ctx: KitMdRenderContext = {
|
|
181
|
+
root: area, headingOffset: 0, idPrefix: 'krt-', indent: markdownIndentTopLevel(res.blocks),
|
|
182
|
+
highlight: kitEnginePort<KitHighlightEnginePort>(services, 'highlight'), copyCode: false,
|
|
174
183
|
};
|
|
175
|
-
|
|
176
|
-
s = s.replace(/\[([^\]\n]+)\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g, (_m, label: string, url: string) =>
|
|
177
|
-
hold(`<a href="${url.replace(/"/g, '%22')}">${markdownInline(label)}</a>`));
|
|
178
|
-
s = s.replace(/\*\*([^*\n]+)\*\*/g, '<strong>$1</strong>').replace(/(^|[^\w])__([^_\n]+)__(?!\w)/g, '$1<strong>$2</strong>');
|
|
179
|
-
s = s.replace(/\*([^*\n]+)\*/g, '<em>$1</em>').replace(/(^|[^\w])_([^_\n]+)_(?!\w)/g, '$1<em>$2</em>');
|
|
180
|
-
return s.replace(/\u0001(\d+)\u0001/g, (_m, i: string) => stash[Number(i)] ?? '');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/** Markdown -> HTML 串(纯函数;输出尚未净化,必须交给 sanitizeRichFragment / sanitizeRichHtml) */
|
|
184
|
-
export function markdownToRichHtml(md: string): string {
|
|
185
|
-
const lines = md.slice(0, RICH_MAX_LENGTH).replace(/\r\n?/g, '\n').split('\n');
|
|
186
|
-
const out: string[] = [];
|
|
187
|
-
let para: string[] = [];
|
|
188
|
-
const flushPara = (): void => {
|
|
189
|
-
if (para.length > 0) out.push(`<p>${markdownInline(para.join(' '))}</p>`);
|
|
190
|
-
para = [];
|
|
191
|
-
};
|
|
192
|
-
let i = 0;
|
|
193
|
-
while (i < lines.length) {
|
|
194
|
-
const line = lines[i]!;
|
|
195
|
-
if (/^\s*```/.test(line)) {
|
|
196
|
-
flushPara();
|
|
197
|
-
const code: string[] = [];
|
|
198
|
-
i += 1;
|
|
199
|
-
while (i < lines.length && !/^\s*```/.test(lines[i]!)) { code.push(lines[i]!); i += 1; }
|
|
200
|
-
i += 1;
|
|
201
|
-
// 白名单里没有 pre / code:代码块逐行成段,内容转义成纯文字
|
|
202
|
-
for (const c of code) if (c.trim() !== '') out.push(`<p>${escapeText(c)}</p>`);
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
if (line.trim() === '') { flushPara(); i += 1; continue; }
|
|
206
|
-
const heading = /^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(line);
|
|
207
|
-
if (heading) {
|
|
208
|
-
flushPara();
|
|
209
|
-
out.push(`<h${heading[1]!.length}>${markdownInline(heading[2]!)}</h${heading[1]!.length}>`);
|
|
210
|
-
i += 1;
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
if (/^\s*>/.test(line)) {
|
|
214
|
-
flushPara();
|
|
215
|
-
const quote: string[] = [];
|
|
216
|
-
while (i < lines.length && /^\s*>/.test(lines[i]!)) { quote.push(lines[i]!.replace(/^\s*>\s?/, '')); i += 1; }
|
|
217
|
-
out.push(`<blockquote><p>${markdownInline(quote.join(' '))}</p></blockquote>`);
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
const bullet = /^\s*[-*+]\s+(.*)$/.exec(line);
|
|
221
|
-
const ordered = /^\s*\d+[.)]\s+(.*)$/.exec(line);
|
|
222
|
-
if (bullet || ordered) {
|
|
223
|
-
flushPara();
|
|
224
|
-
const tag = bullet ? 'ul' : 'ol';
|
|
225
|
-
const re = bullet ? /^\s*[-*+]\s+(.*)$/ : /^\s*\d+[.)]\s+(.*)$/;
|
|
226
|
-
const items: string[] = [];
|
|
227
|
-
while (i < lines.length) {
|
|
228
|
-
const m2 = re.exec(lines[i]!);
|
|
229
|
-
if (!m2) break;
|
|
230
|
-
items.push(`<li>${markdownInline(m2[1]!)}</li>`);
|
|
231
|
-
i += 1;
|
|
232
|
-
}
|
|
233
|
-
out.push(`<${tag}>${items.join('')}</${tag}>`);
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
para.push(line.trim());
|
|
237
|
-
i += 1;
|
|
238
|
-
}
|
|
239
|
-
flushPara();
|
|
240
|
-
return out.join('');
|
|
184
|
+
for (const b of res.blocks) area.appendChild(renderMdBlock(b, ctx, 0));
|
|
241
185
|
}
|
|
242
186
|
|
|
243
187
|
// ── 命令 ─────────────────────────────────────────────────────
|
|
@@ -286,7 +230,7 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
286
230
|
commands: { type: 'array', default: [], desc: '工具栏命令子集,取 bold / italic / h2 / ul / ol / link / unlink;空则全部' },
|
|
287
231
|
placeholder: { type: 'string', default: '', desc: '空内容时的占位文案' },
|
|
288
232
|
readonly: { type: 'boolean', default: false, desc: '只展示(净化后的)内容,不出工具栏' },
|
|
289
|
-
source: { type: 'enum', values: ['html', 'markdown'], default: 'html', desc: '内容来源:markdown 时 value / data.markdown 是 Markdown
|
|
233
|
+
source: { type: 'enum', values: ['html', 'markdown'], default: 'html', desc: '内容来源:markdown 时 value / data.markdown 是 Markdown 文本,经 core 端口 engines.markdown 解析后由 MarkdownView 的块渲染器出 DOM,组件固定只读(不出工具栏);只读展示 Markdown 优先用 MarkdownView' },
|
|
290
234
|
max_length: { type: 'number', default: 0, desc: '文字长度上限提示;非正数不显示计数。超出只变警示色,不截断' },
|
|
291
235
|
label: { type: 'string', default: '', desc: '编辑区的无障碍名称' },
|
|
292
236
|
...ID_PROPS,
|
|
@@ -299,6 +243,7 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
299
243
|
change: { payload: { value: { type: 'string' }, empty: { type: 'boolean' }, length: { type: 'number' } }, desc: '内容变化;value 已净化' },
|
|
300
244
|
},
|
|
301
245
|
},
|
|
246
|
+
services: ['engines'],
|
|
302
247
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
303
248
|
controllerFactory: createKitController((api) => {
|
|
304
249
|
const P = (): Record<string, unknown> => api.props();
|
|
@@ -315,14 +260,18 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
315
260
|
|
|
316
261
|
/** source: markdown 时内容是 Markdown 文本(value 优先,其次 data.markdown,再退 data.html),一律只读 */
|
|
317
262
|
const isMarkdown = (): boolean => P().source === 'markdown';
|
|
263
|
+
const initialMarkdown = (): string => {
|
|
264
|
+
const v = str(P().value);
|
|
265
|
+
const d = recOf(P().data);
|
|
266
|
+
return v !== '' ? v : str(d.markdown) !== '' ? str(d.markdown) : str(d.html);
|
|
267
|
+
};
|
|
318
268
|
const initialHtml = (): string => {
|
|
269
|
+
if (isMarkdown()) return '';
|
|
319
270
|
const v = str(P().value);
|
|
320
|
-
if (isMarkdown()) {
|
|
321
|
-
const d = recOf(P().data);
|
|
322
|
-
return markdownToRichHtml(v !== '' ? v : str(d.markdown) !== '' ? str(d.markdown) : str(d.html));
|
|
323
|
-
}
|
|
324
271
|
return v !== '' ? v : str(recOf(P().data).html);
|
|
325
272
|
};
|
|
273
|
+
let mdSeq = 0;
|
|
274
|
+
let lastMarkdown: string | null = null;
|
|
326
275
|
|
|
327
276
|
const refresh = (): void => {
|
|
328
277
|
if (!area) return;
|
|
@@ -605,10 +554,23 @@ export function createRichTextEditor(): SomaComponentDefinition {
|
|
|
605
554
|
// 模式切换要重建 DOM:先带走当前内容
|
|
606
555
|
const keep = area ? sanitizeRichHtml(area.innerHTML) : null;
|
|
607
556
|
build();
|
|
557
|
+
lastMarkdown = null;
|
|
608
558
|
if (keep !== null) { setContent(keep); lastInit = initialHtml(); }
|
|
609
559
|
}
|
|
610
|
-
|
|
611
|
-
|
|
560
|
+
if (isMarkdown()) {
|
|
561
|
+
// Markdown 来源:经端口解析、块渲染器出 DOM(只读);原文没变不重画
|
|
562
|
+
const md = initialMarkdown();
|
|
563
|
+
if (area && md !== lastMarkdown) {
|
|
564
|
+
lastMarkdown = md;
|
|
565
|
+
const mine = (mdSeq += 1);
|
|
566
|
+
const target = area;
|
|
567
|
+
void paintRichMarkdown(target, md, api.services, () => mdSeq === mine && area === target).then(() => { if (mdSeq === mine) refresh(); });
|
|
568
|
+
}
|
|
569
|
+
} else {
|
|
570
|
+
lastMarkdown = null;
|
|
571
|
+
const init = initialHtml();
|
|
572
|
+
if (init !== lastInit) { lastInit = init; setContent(init); }
|
|
573
|
+
}
|
|
612
574
|
if (holder) holder.textContent = str(p.placeholder);
|
|
613
575
|
// 编辑区(role=textbox)承载 id / 可访问名 / 必填 / 无效 / 说明与标签关联;表单经 props 传入,重绘不丢
|
|
614
576
|
if (area) {
|
package/src/data/row-editor.ts
CHANGED
|
@@ -16,6 +16,8 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
16
16
|
import { applyCommon, bool, createKitController, FIELD_CLASS, formatValue, ID_PROPS, INVALID_PROPS, joinClass, nextUid, num, str, type KitApi } from '../base/shared';
|
|
17
17
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
18
18
|
import { setKitFace } from '../recipes';
|
|
19
|
+
import { kitControlEdgeRecipe } from '../recipes/control';
|
|
20
|
+
import { KIT_DIVIDER_FOOT_CLASS, KIT_DIVIDER_HEAD_CLASS, kitDividerRecipe } from '../recipes/divider';
|
|
19
21
|
import { KIT_BUSY_PROP_DEFS, kitBusyOf } from '../base/action-busy';
|
|
20
22
|
import { KIT_DATE_CLASS_CANDIDATES, mountKitDateField } from '../base/date';
|
|
21
23
|
import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
@@ -49,8 +51,11 @@ const FORM_COLS: Readonly<Record<number, string>> = Object.freeze({
|
|
|
49
51
|
const ROOT_CLASS = 'flex flex-col gap-3';
|
|
50
52
|
const TITLE_CLASS = 'text-sm font-semibold text-fg';
|
|
51
53
|
const HINT_CLASS = 'text-xs text-fg-subtle';
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
+
// 表头 / 行 / 合计行的线只经分隔线出口(发丝宽、分隔灰,KT-B1 / KT-B5)
|
|
55
|
+
const HEAD_CLASS = `grid grid-cols-12 items-center gap-2 ${KIT_DIVIDER_HEAD_CLASS} px-2 py-2 text-xs font-medium text-fg-muted`;
|
|
56
|
+
const ROW_LINE = kitDividerRecipe('bottom');
|
|
57
|
+
const DATE_EDGE = kitControlEdgeRecipe();
|
|
58
|
+
const ROW_CLASS = `grid grid-cols-12 items-center gap-2 ${ROW_LINE} px-2 py-2`;
|
|
54
59
|
const CELL_CLASS = 'min-w-0 break-all text-sm text-fg';
|
|
55
60
|
const CELL_MONO = 'min-w-0 break-all font-mono text-xs text-fg-muted';
|
|
56
61
|
const CELL_MUTED = 'min-w-0 break-all text-sm text-fg-muted';
|
|
@@ -71,14 +76,14 @@ const TEXTAREA_LIKE = 'font-mono';
|
|
|
71
76
|
const ERROR_CLASS = 'text-sm text-danger-on-soft';
|
|
72
77
|
const LIST_WRAP = 'flex flex-col';
|
|
73
78
|
const NUM_ALIGN = 'text-end tabular-nums';
|
|
74
|
-
const FOOTER_ROW_CLASS =
|
|
79
|
+
const FOOTER_ROW_CLASS = `grid grid-cols-12 items-center gap-2 ${KIT_DIVIDER_FOOT_CLASS} px-2 py-2 text-sm font-semibold text-fg`;
|
|
75
80
|
const HEAD_END_CLASS = toFlexRow(HEAD_CLASS);
|
|
76
81
|
const ROW_END_CLASS = toFlexRow(ROW_CLASS);
|
|
77
82
|
const FOOTER_END_CLASS = toFlexRow(FOOTER_ROW_CLASS);
|
|
78
83
|
const COUNT_CLASS = 'text-xs text-fg-subtle';
|
|
79
84
|
/** 出错单元格的外框(令牌色环,不撑行高;圆角不在此处手写,沿用单元格自身) */
|
|
80
85
|
const CELL_ERROR_CLASS = 'ring-1 ring-danger';
|
|
81
|
-
const DATE_FIELD_CLASS =
|
|
86
|
+
const DATE_FIELD_CLASS = `block h-9 w-full rounded-md ${DATE_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`;
|
|
82
87
|
|
|
83
88
|
export const KIT_ROW_EDITOR_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
84
89
|
ROOT_CLASS, TITLE_CLASS, HINT_CLASS, HEAD_CLASS, ROW_CLASS, CELL_CLASS, CELL_MONO, CELL_MUTED, END_CLASS, FORM_CLASS, FIELD_WRAP,
|
|
@@ -711,7 +716,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
711
716
|
},
|
|
712
717
|
},
|
|
713
718
|
services: ['data', 'http'],
|
|
714
|
-
templateHtml: `<section data-soma-id="root" class="@container ${ROOT_CLASS}"></section>`,
|
|
719
|
+
templateHtml: `<section data-kit-container="card" data-soma-id="root" class="@container ${ROOT_CLASS}"></section>`,
|
|
715
720
|
controllerFactory: createKitController(() => ({
|
|
716
721
|
busyAware: true,
|
|
717
722
|
attach(root, api) {
|
|
@@ -1053,7 +1058,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1053
1058
|
const structural = !readonly && !fixedRows;
|
|
1054
1059
|
const spanOf = (c: KitRowColumn): string => `${structural ? `${FLEX_SPAN[c.span] ?? 'flex-2'} min-w-0` : SPAN_CLASS[c.span] ?? 'col-span-2'}${isNumericRowKind(c.kind) ? ` ${NUM_ALIGN}` : ''}`;
|
|
1055
1060
|
if (st.rows.length === 0) {
|
|
1056
|
-
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root))
|
|
1061
|
+
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root))));
|
|
1057
1062
|
} else {
|
|
1058
1063
|
const head = mk('div', structural ? HEAD_END_CLASS : HEAD_CLASS);
|
|
1059
1064
|
for (const c of shown) {
|
|
@@ -1214,7 +1219,7 @@ export function createRowEditor(): SomaComponentDefinition {
|
|
|
1214
1219
|
}
|
|
1215
1220
|
} else if (st.rows.length === 0) {
|
|
1216
1221
|
list.textContent = '';
|
|
1217
|
-
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root))
|
|
1222
|
+
list.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.empty', undefined, root))));
|
|
1218
1223
|
} else {
|
|
1219
1224
|
list.textContent = '';
|
|
1220
1225
|
const structural = !readonly && !fixedRows;
|
package/src/data/rule-builder.ts
CHANGED
|
@@ -23,6 +23,11 @@ import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
|
23
23
|
import { createKitEmbedBag, mountKitSelectField, type KitEmbedBag } from './embed';
|
|
24
24
|
import { bool, num, str } from '../base/shared';
|
|
25
25
|
import { setKitFace, type KitFaceKind } from '../recipes';
|
|
26
|
+
import { kitButtonEdgeRecipe, kitControlEdgeRecipe } from '../recipes/control';
|
|
27
|
+
import { kitShellRecipe } from '../recipes/container';
|
|
28
|
+
import { KIT_STATE_EMPTY_BOX } from '../recipes/placeholder';
|
|
29
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
30
|
+
import { mergeClass } from '../shared/merge-class';
|
|
26
31
|
|
|
27
32
|
// ════════════════════════════════════════════════════════════════
|
|
28
33
|
// 单条条件模块(纯函数 + 值控件构造):运算符表、按字段类型取运算符、值形状归一、校验文字、值控件(复用 kit 基础文本类控件的
|
|
@@ -237,10 +242,14 @@ export function describeCondition(cond: RuleCondition, field: RuleField | undefi
|
|
|
237
242
|
|
|
238
243
|
const VALUE_WRAP = 'flex min-w-40 flex-1 flex-wrap items-center gap-2';
|
|
239
244
|
const CONTROL = `${FIELD_CLASS.md} data-kit-invalid:border-danger`;
|
|
240
|
-
|
|
245
|
+
// 日期框的边 = 控件轮廓出口(KT-B1 / §4 C6);条件药丸 = 带文字中性按钮描边;组 / 条件框 = 壳配方(容器边,KT-B2)
|
|
246
|
+
const DATE_EDGE = kitControlEdgeRecipe();
|
|
247
|
+
const PILL_EDGE = kitButtonEdgeRecipe();
|
|
248
|
+
const MODE_EDGE = kitControlEdgeRecipe({ wrapper: true, hover: false });
|
|
249
|
+
const DATE_CONTROL = `block h-8 w-full rounded-md ${DATE_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 data-kit-invalid:border-danger`;
|
|
241
250
|
const RANGE_SEP = 'text-fg-subtle';
|
|
242
251
|
const PILLS = 'flex flex-wrap gap-1.5';
|
|
243
|
-
const PILL =
|
|
252
|
+
const PILL = `inline-flex h-8 items-center rounded-full ${PILL_EDGE} bg-surface px-3 text-xs text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-kit-selected:border-primary data-kit-selected:bg-primary-soft data-kit-selected:text-primary-on-soft`;
|
|
244
253
|
const HALF = 'min-w-28 flex-1';
|
|
245
254
|
|
|
246
255
|
export const KIT_RULE_CONDITION_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
@@ -585,28 +594,30 @@ export const parsePathKey = (key: string): number[] => key.split('.').slice(1).m
|
|
|
585
594
|
// ════════════════════════════════════════════════════════════════
|
|
586
595
|
|
|
587
596
|
const ROOT_CLASS = 'flex flex-col gap-3 text-sm text-fg';
|
|
588
|
-
const GROUP_CLASS = 'flex flex-col gap-2
|
|
589
|
-
const GROUP_NESTED_CLASS = 'flex flex-col gap-2
|
|
597
|
+
const GROUP_CLASS = mergeClass('flex flex-col gap-2 p-3', kitShellRecipe({ tone: 'base', shadow: false }));
|
|
598
|
+
const GROUP_NESTED_CLASS = mergeClass('flex flex-col gap-2 p-3', kitShellRecipe({ tone: 'sunken', shadow: false }));
|
|
590
599
|
const HEAD_CLASS = 'flex flex-wrap items-center gap-2';
|
|
591
|
-
const MODE_WRAP_CLASS =
|
|
600
|
+
const MODE_WRAP_CLASS = `inline-flex rounded-md ${MODE_EDGE} bg-surface p-0.5`;
|
|
592
601
|
const MODE_BTN_CLASS = 'inline-flex h-7 items-center justify-center rounded-md px-3 text-xs font-medium text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-kit-selected:bg-primary data-kit-selected:text-primary-fg data-kit-selected:hover:bg-primary-hover';
|
|
593
|
-
|
|
602
|
+
// 「非」开关:未选 = 色调按钮(次级),选中 = 实心主色(态差靠填充,不靠描边)
|
|
603
|
+
const NOT_BTN_CLASS = mergeClass(kitEmphasisButtonRecipe('button.toolbar'), 'data-kit-selected:bg-primary data-kit-selected:text-primary-fg');
|
|
594
604
|
const SPACER_CLASS = 'flex-1';
|
|
595
|
-
const TOOL_BTN_CLASS = '
|
|
605
|
+
const TOOL_BTN_CLASS = kitEmphasisButtonRecipe('button.toolbar');
|
|
596
606
|
const ACT_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md px-2 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
597
607
|
const DEL_BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md px-2 text-xs text-danger-on-soft transition-colors hover:bg-danger-soft focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
598
608
|
const ACTIONS_CLASS = 'inline-flex items-center gap-0.5';
|
|
599
609
|
const BODY_CLASS = 'flex flex-col gap-2';
|
|
600
|
-
const COND_CLASS = 'flex flex-col gap-1
|
|
610
|
+
const COND_CLASS = mergeClass('flex flex-col gap-1 px-2 py-2', kitShellRecipe({ tone: 'base', shadow: false }));
|
|
601
611
|
const COND_ROW_CLASS = 'flex flex-wrap items-center gap-2';
|
|
602
612
|
const CELL_CLASS = 'min-w-28 flex-1';
|
|
603
613
|
const ERR_CLASS = 'text-xs text-danger-on-soft';
|
|
604
|
-
|
|
614
|
+
// 空态:与全 kit 同一口径(一行标题,无虚线框)
|
|
615
|
+
const EMPTY_CLASS = KIT_STATE_EMPTY_BOX;
|
|
605
616
|
const SUMMARY_CLASS = 'rounded-md bg-surface-sunken px-3 py-2 text-sm text-fg-muted';
|
|
606
617
|
const READONLY_CLASS = 'text-sm text-fg';
|
|
607
618
|
const FOOT_CLASS = 'flex items-center justify-end gap-2';
|
|
608
619
|
const SAVE_CLASS = 'inline-flex h-8 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
609
|
-
const CANCEL_CLASS = '
|
|
620
|
+
const CANCEL_CLASS = kitEmphasisButtonRecipe('button.toolbar');
|
|
610
621
|
|
|
611
622
|
export const KIT_RULE_BUILDER_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
612
623
|
ROOT_CLASS, GROUP_CLASS, GROUP_NESTED_CLASS, HEAD_CLASS, MODE_WRAP_CLASS, MODE_BTN_CLASS, NOT_BTN_CLASS, SPACER_CLASS, TOOL_BTN_CLASS,
|
|
@@ -890,7 +901,7 @@ export function createRuleBuilder(): SomaComponentDefinition {
|
|
|
890
901
|
cancel: { payload: {}, desc: '点取消' },
|
|
891
902
|
},
|
|
892
903
|
},
|
|
893
|
-
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
904
|
+
templateHtml: `<section data-kit-container="card" data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
894
905
|
controllerFactory: createKitController(() => ({
|
|
895
906
|
busyAware: true,
|
|
896
907
|
attach(root, api) {
|
package/src/data/shape-util.ts
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
// 颜色只用语义色名:彩色文字只配 `-on-soft`,实心底只配 `-fg`;空态与分隔用实线。
|
|
7
7
|
|
|
8
8
|
import { setKitFace } from '../recipes';
|
|
9
|
-
import {
|
|
9
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
10
|
+
import { kitControlRecipe } from '../recipes/control';
|
|
11
|
+
import { KIT_STATE_EMPTY_BOX, KIT_STATE_RETRY_CLASS_CANDIDATES, kitRetryRecipe, type KitRetryTone } from '../recipes/placeholder';
|
|
10
12
|
import { kitEmptyPanel } from '../base/state-panel';
|
|
11
13
|
|
|
12
14
|
export type Rec = Record<string, unknown>;
|
|
@@ -65,6 +67,15 @@ export const TONE_DOT: Readonly<Record<ShapeTone, string>> = Object.freeze({
|
|
|
65
67
|
});
|
|
66
68
|
|
|
67
69
|
/** 淡底 + 同语气文字(标签、横幅、图标圈) */
|
|
70
|
+
/** 状态文字的语气色(状态 = 圆点 + 文字、没有容器:只有文字色,彩色只走 on-soft 角色,常态 neutral 用中性灰) */
|
|
71
|
+
export const TONE_TEXT: Readonly<Record<ShapeTone, string>> = Object.freeze({
|
|
72
|
+
neutral: 'text-fg-muted',
|
|
73
|
+
primary: 'text-primary-on-soft',
|
|
74
|
+
info: 'text-info-on-soft',
|
|
75
|
+
success: 'text-success-on-soft',
|
|
76
|
+
warning: 'text-warning-on-soft',
|
|
77
|
+
danger: 'text-danger-on-soft',
|
|
78
|
+
});
|
|
68
79
|
export const TONE_SOFT: Readonly<Record<ShapeTone, string>> = Object.freeze({
|
|
69
80
|
neutral: 'bg-surface-sunken text-fg-muted',
|
|
70
81
|
primary: 'bg-primary-soft text-primary-on-soft',
|
|
@@ -87,23 +98,25 @@ export const TONE_SOLID: Readonly<Record<ShapeTone, string>> = Object.freeze({
|
|
|
87
98
|
/** 标签(小胶囊) */
|
|
88
99
|
export const BADGE_BASE = 'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium';
|
|
89
100
|
|
|
90
|
-
/**
|
|
91
|
-
export const EMPTY_CLASS =
|
|
101
|
+
/** 空态:集合内一行标题(类串来自 recipes/placeholder,受控类只在 recipes 层;无框无虚线) */
|
|
102
|
+
export const EMPTY_CLASS = KIT_STATE_EMPTY_BOX;
|
|
92
103
|
|
|
93
104
|
// ── 动作按钮 ─────────────────────────────────────────────────
|
|
94
105
|
|
|
95
106
|
export type ActionTone = 'primary' | 'danger' | 'neutral';
|
|
96
107
|
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
primary:
|
|
100
|
-
danger: '
|
|
101
|
-
neutral: '
|
|
108
|
+
/** 动作按钮三种语气的整串配方:主 = 实心主按钮,危险 = 三级形体 + 危险色文字(强调等级 button.danger),中性 = 三级文字钮(强调等级 button.toolbar) */
|
|
109
|
+
export const ACTION_BUTTON_TONE: Readonly<Record<ActionTone, string>> = Object.freeze({
|
|
110
|
+
primary: kitControlRecipe({ variant: 'primary' }),
|
|
111
|
+
danger: kitEmphasisButtonRecipe('button.danger'),
|
|
112
|
+
neutral: kitEmphasisButtonRecipe('button.toolbar'),
|
|
102
113
|
});
|
|
114
|
+
/** 确认弹层的确认钮(危险语气):全应用唯一的实心危险色按钮(强调等级 button.dangerConfirm) */
|
|
115
|
+
export const ACTION_BUTTON_CONFIRM_DANGER: string = kitEmphasisButtonRecipe('button.dangerConfirm');
|
|
103
116
|
const BUTTON_DISABLED = 'opacity-50 cursor-not-allowed';
|
|
104
117
|
|
|
105
118
|
export const BUTTON_CLASS_TOKENS: readonly string[] = classTokens(
|
|
106
|
-
|
|
119
|
+
Object.values(ACTION_BUTTON_TONE), ACTION_BUTTON_CONFIRM_DANGER, BUTTON_DISABLED, KIT_STATE_RETRY_CLASS_CANDIDATES,
|
|
107
120
|
);
|
|
108
121
|
|
|
109
122
|
export function actionToneOf(raw: unknown): ActionTone {
|
|
@@ -140,7 +153,7 @@ export function actionsOf(raw: unknown): ShapeAction[] {
|
|
|
140
153
|
export function actionButton(action: ShapeAction, extraClass = ''): HTMLButtonElement {
|
|
141
154
|
const btn = document.createElement('button');
|
|
142
155
|
btn.type = 'button';
|
|
143
|
-
btn.className = [
|
|
156
|
+
btn.className = [ACTION_BUTTON_TONE[action.tone], action.disabled ? BUTTON_DISABLED : '', extraClass]
|
|
144
157
|
.filter((s) => s !== '').join(' ');
|
|
145
158
|
// 质感标记:三种语气都有实心 / 描边底面,同 Button 标 raised(所有经 actionButton 的动作钮单点覆盖)
|
|
146
159
|
setKitFace(btn, 'raised');
|
|
@@ -217,11 +230,10 @@ export function mk<K extends keyof HTMLElementTagNameMap>(
|
|
|
217
230
|
}
|
|
218
231
|
|
|
219
232
|
/**
|
|
220
|
-
* 数据组件的空态:与集合空态同一画法(base/state-panel.ts
|
|
221
|
-
* compact = 只有文案(嵌在表单 / 小容器里,如子表、样机屏幕),其余沿用同一个盒的类。
|
|
233
|
+
* 数据组件的空态:与集合空态同一画法(base/state-panel.ts:一行标题、无插画、role=status),不再分紧凑 / 完整两种。
|
|
222
234
|
*/
|
|
223
|
-
export function emptyNode(text: string
|
|
224
|
-
return kitEmptyPanel(document, text
|
|
235
|
+
export function emptyNode(text: string): HTMLElement {
|
|
236
|
+
return kitEmptyPanel(document, text);
|
|
225
237
|
}
|
|
226
238
|
|
|
227
239
|
/** 值转文字:空值回空串 */
|