soma-kit 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -112
- package/bin/soma-kit.mjs +32 -2
- package/bin/soma.mjs +22 -0
- package/package.json +14 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +929 -37
- package/spec/generated/kit-page.schema.json +1684 -161
- package/spec/kit-grammar.json +1176 -584
- package/spec/kit-grammar.schema.json +1971 -393
- package/src/app/app-config.ts +449 -347
- package/src/app/component-gate.ts +283 -28
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +176 -33
- package/src/app/define-kit-view.ts +104 -0
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +29 -6
- package/src/app/kit-view-context.ts +439 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +11 -3
- package/src/app/server.ts +530 -103
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +667 -0
- package/src/base/action-busy.ts +103 -6
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +58 -0
- package/src/base/alert.ts +5 -3
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +99 -37
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +9 -1
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +49 -28
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +16 -11
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +10 -6
- package/src/base/context-menu.ts +10 -7
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +32 -18
- package/src/base/date.ts +135 -28
- package/src/base/delta.ts +72 -0
- package/src/base/divider.ts +2 -2
- package/src/base/end-edge.ts +49 -0
- package/src/base/fab.ts +12 -5
- package/src/base/gap-value.ts +148 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +94 -0
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +35 -11
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +56 -35
- package/src/base/loading-gate.ts +186 -0
- package/src/base/mentions.ts +7 -6
- package/src/base/menu-button.ts +28 -12
- package/src/base/menu-core.ts +41 -8
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +3 -3
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +3 -3
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +9 -5
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +48 -16
- package/src/base/popup.ts +143 -19
- package/src/base/portal-core.ts +4 -0
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +14 -8
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +21 -4
- package/src/base/rating.ts +12 -7
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +27 -21
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +387 -49
- package/src/base/state-panel.ts +346 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +10 -7
- package/src/base/switch.ts +11 -6
- package/src/base/tag-input.ts +20 -16
- package/src/base/tag.ts +68 -34
- package/src/base/text.ts +80 -18
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +18 -13
- package/src/base/tree-select.ts +21 -12
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +48 -14
- package/src/base/view-transition.ts +77 -0
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/approval-desk/shell.ts +11 -8
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/auth-panel/shell.ts +5 -4
- package/src/biz/category-crud/compile.ts +23 -37
- package/src/biz/category-crud/shell.ts +2 -1
- package/src/biz/checkout-page/compile.ts +22 -5
- package/src/biz/checkout-page/shell.ts +4 -3
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +5 -4
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +69 -22
- package/src/biz/link/shared.ts +127 -119
- package/src/biz/master-sub/compile.ts +127 -48
- package/src/biz/master-sub/index.ts +5 -2
- package/src/biz/master-sub/shell.ts +95 -18
- package/src/biz/multi-board/compile.ts +38 -50
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +32 -20
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/notification-center/shell.ts +6 -4
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/result-page/shell.ts +2 -1
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/page-templates/sign-in-page/shell.ts +2 -2
- package/src/biz/record-detail/compile.ts +48 -43
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/record-detail/shell.ts +8 -6
- package/src/biz/settings-center/compile.ts +7 -5
- package/src/biz/settings-center/shell.ts +6 -4
- package/src/biz/shared/action-host.ts +97 -211
- package/src/biz/shared/compile-helpers.ts +98 -0
- package/src/biz/shared/coordinator.ts +472 -92
- package/src/biz/shared/index.ts +13 -2
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +239 -0
- package/src/biz/shared/overlay-shell.ts +209 -0
- package/src/biz/shared/pipes.ts +50 -31
- package/src/biz/shared/remove-wire.ts +14 -0
- package/src/biz/shared/runtime-hub.ts +226 -24
- package/src/biz/single-form/compile.ts +16 -37
- package/src/biz/single-form/shell.ts +4 -3
- package/src/biz/standard-crud/compile.ts +72 -255
- package/src/biz/standard-crud/shell.ts +21 -99
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/step-form/shell.ts +5 -5
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +254 -25
- package/src/cli/kit-init.ts +227 -0
- package/src/cli/layout-cli.ts +167 -0
- package/src/cli/migrate/index.ts +10 -0
- package/src/cli/migrate/migrate.ts +248 -0
- package/src/cli/migrate/text-utils.ts +306 -0
- package/src/cli/migrate/theme-map.ts +104 -0
- package/src/cli/migrate/ts-rules.ts +235 -0
- package/src/cli/migrate/types.ts +95 -0
- package/src/cli/migrate/view-skeleton.ts +159 -0
- package/src/cli/migrate/yaml-report.ts +376 -0
- package/src/cli/migrate/yaml-rules.ts +465 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +761 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +570 -0
- package/src/compile/compile-page.ts +267 -76
- package/src/compile/component-candidates.ts +13 -2
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/layout-lint/engine.ts +82 -0
- package/src/compile/layout-lint/index.ts +55 -0
- package/src/compile/layout-lint/rules-composition.ts +218 -0
- package/src/compile/layout-lint/rules-form.ts +192 -0
- package/src/compile/layout-lint/rules-table.ts +194 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +63 -2
- package/src/compile/types.ts +31 -3
- package/src/compile/view-check.ts +284 -0
- package/src/data/amount-breakdown.ts +8 -3
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +3 -3
- package/src/data/assignment-picker.ts +92 -55
- package/src/data/async-result-panel.ts +111 -9
- package/src/data/breadcrumbs.ts +5 -4
- package/src/data/calendar.ts +24 -27
- package/src/data/carousel.ts +13 -8
- package/src/data/chart.ts +183 -44
- package/src/data/checklist.ts +20 -7
- package/src/data/code-view.ts +12 -6
- package/src/data/comment-thread.ts +7 -4
- package/src/data/confirm-dialog.ts +81 -18
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +3 -3
- package/src/data/embed.ts +233 -30
- package/src/data/field-mapper.ts +35 -30
- package/src/data/flow-editor-contract.ts +8 -1
- package/src/data/flow-editor.ts +113 -108
- package/src/data/flow-node-options.ts +120 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +19 -19
- package/src/data/hero.ts +4 -3
- package/src/data/image-viewer.ts +27 -30
- package/src/data/index.ts +5 -2
- package/src/data/item-list.ts +48 -31
- package/src/data/kanban.ts +82 -52
- package/src/data/media-grid.ts +20 -20
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +47 -15
- package/src/data/mockup.ts +10 -6
- package/src/data/modal-dialog.ts +49 -25
- package/src/data/navbar.ts +12 -7
- package/src/data/notice-list.ts +268 -0
- package/src/data/notify-renderer.ts +250 -0
- package/src/data/object-form.ts +1360 -666
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +80 -34
- package/src/data/permission-matrix.ts +52 -31
- package/src/data/permission-tree.ts +71 -44
- package/src/data/pricing-table.ts +30 -14
- package/src/data/prompt-dialog.ts +124 -194
- package/src/data/reaction-bar.ts +83 -92
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +26 -5
- package/src/data/record-picker.ts +104 -55
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +8 -4
- package/src/data/rich-text.ts +61 -55
- package/src/data/row-editor.ts +362 -76
- package/src/data/rule-builder.ts +26 -20
- package/src/data/shape-util.ts +27 -9
- package/src/data/stat-group.ts +392 -109
- package/src/data/static-lazy.ts +1 -0
- package/src/data/static-registry.ts +24 -11
- package/src/data/steps.ts +10 -5
- package/src/data/survey.ts +27 -32
- package/src/data/system-switcher.ts +3 -3
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +19 -8
- package/src/data/tour-guide.ts +23 -30
- package/src/data/transfer.ts +62 -38
- package/src/data/tree-table.ts +152 -78
- package/src/data/tree.ts +49 -36
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +133 -82
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/data/wrapped-candidates.ts +10 -0
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +26 -24
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +9 -7
- package/src/frames/shared.ts +36 -25
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +6 -6
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +4 -14
- package/src/frames/tabs-frame/wiring.ts +5 -8
- package/src/frames/top-main-frame.ts +3 -2
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +21 -5
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +3 -2
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +250 -48
- package/src/generated/kit-grammar-runtime.ts +645 -397
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +84 -29
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +112 -84
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +401 -104
- package/src/object-renderer/collection-table.ts +287 -45
- package/src/object-renderer/collection.ts +258 -104
- package/src/object-renderer/compile-data.ts +112 -102
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +38 -16
- package/src/object-renderer/display-checks.ts +4 -25
- package/src/object-renderer/emit-events.ts +224 -176
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +533 -151
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +111 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/layout-facts.ts +386 -0
- package/src/object-renderer/layout-plan.ts +132 -0
- package/src/object-renderer/layout-plan.types.ts +22 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/parts.ts +252 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +456 -89
- package/src/object-renderer/request-actions.ts +232 -249
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +319 -111
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +429 -94
- package/src/object-renderer/types.ts +204 -127
- package/src/object-renderer/view-binding.ts +393 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +165 -28
- package/src/page-target/target.ts +262 -51
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +210 -0
- package/src/recipes/control.ts +277 -0
- package/src/recipes/index.ts +312 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +240 -0
- package/src/recipes/placeholder.ts +79 -0
- package/src/recipes/rail-grid.ts +45 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/state.ts +99 -0
- package/src/recipes/status.ts +139 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-row.ts +88 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +99 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +15 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +180 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +13 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +407 -10
- package/src/theme/kit-theme.tpl +407 -10
- package/src/theme/nine-dim-structure.ts +247 -0
- package/src/theme/surface-layers.ts +101 -0
- package/src/theme/theme-tokens.ts +130 -84
- package/src/theme/theme-types.ts +103 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1473
|
@@ -22,20 +22,25 @@
|
|
|
22
22
|
// 每次勾选抛 `change { value, added, removed, reason }`;save_label 非空时底部出现保存钮,校验通过抛
|
|
23
23
|
// `saved { values, object, model, mode, value, added, removed, reason }`;cancel_label 非空时出现取消钮,抛 `cancel {}` 并还原草稿。
|
|
24
24
|
|
|
25
|
-
import type {
|
|
25
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
26
26
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
27
27
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
28
|
-
import { bool,
|
|
28
|
+
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
29
29
|
import { kitIcon } from '../base/icons';
|
|
30
|
+
import { markCheckBox } from '../base/check-core';
|
|
30
31
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
31
|
-
import {
|
|
32
|
+
import { kitControlRecipe, setKitFace } from '../recipes';
|
|
33
|
+
import {
|
|
34
|
+
KIT_OVERLAY_FOOT_ATTR, KIT_OVERLAY_FORM_FOOTER_CLASS, KIT_OVERLAY_FORM_SCROLL_ATTR, KIT_OVERLAY_ROOT_FILL_CLASS, kitOverlayFormScrollClass,
|
|
35
|
+
} from '../recipes/overlay';
|
|
36
|
+
import { kitBusyOf, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
32
37
|
import { classTokens, keyMap, mk, recOf } from './shape-util';
|
|
33
38
|
import { envelopeOf } from './permission-tree';
|
|
34
39
|
import { attrEsc } from './d9-util';
|
|
35
40
|
|
|
36
41
|
// ── 类串表:全部完整写死,不拼接片段 ──
|
|
37
42
|
|
|
38
|
-
const ROOT_CLASS =
|
|
43
|
+
const ROOT_CLASS = `@container flex h-full flex-col gap-4 text-sm text-fg ${KIT_OVERLAY_ROOT_FILL_CLASS}`;
|
|
39
44
|
const HELP_CLASS = 'text-sm text-fg-muted';
|
|
40
45
|
const SUBJECT_CLASS = 'flex flex-wrap items-center gap-4';
|
|
41
46
|
const SUBJECT_ITEM_CLASS = 'flex items-center gap-2';
|
|
@@ -44,8 +49,6 @@ const STRONG_CLASS = 'text-sm font-semibold text-fg';
|
|
|
44
49
|
const ALERT_CLASS = 'rounded-md bg-danger-soft px-3 py-2 text-sm text-danger-on-soft';
|
|
45
50
|
const GRID_CLASS = 'grid grid-cols-12 gap-4';
|
|
46
51
|
const MAIN_FULL_CLASS = 'col-span-12';
|
|
47
|
-
const MAIN_SPLIT_CLASS = 'col-span-12 @md:col-span-7';
|
|
48
|
-
const SIDE_CLASS = 'col-span-12 @md:col-span-5';
|
|
49
52
|
const MAIN_INNER_CLASS = 'flex flex-col gap-3';
|
|
50
53
|
const SIDE_INNER_CLASS = 'flex flex-col gap-2';
|
|
51
54
|
const HEAD_CLASS = 'flex items-center justify-between gap-3';
|
|
@@ -54,16 +57,16 @@ const SUMMARY_CLASS = 'text-sm text-fg-muted';
|
|
|
54
57
|
const CHANGES_CLASS = 'text-sm text-fg-muted';
|
|
55
58
|
const TOOLS_CLASS = 'flex flex-wrap items-center gap-2';
|
|
56
59
|
const SEARCH_CLASS = 'block h-9 min-w-40 flex-1 appearance-none autofill-clear rounded-md border border-border bg-surface px-3 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
57
|
-
const TOOL_BTN_CLASS = 'inline-flex h-9 items-center justify-center rounded-md border border-
|
|
58
|
-
const LIST_CLASS = 'flex flex-col
|
|
59
|
-
const GROUP_CLASS = 'flex flex-col
|
|
60
|
+
const TOOL_BTN_CLASS = 'inline-flex h-9 items-center justify-center rounded-md border border-button-edge bg-surface px-3 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
61
|
+
const LIST_CLASS = 'flex flex-col overflow-hidden rounded-md border border-border-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
62
|
+
const GROUP_CLASS = 'flex flex-col';
|
|
60
63
|
const GROUP_HEAD_CLASS = 'flex items-center justify-between gap-2 rounded-md bg-surface-sunken px-3 py-1.5 text-xs font-medium text-fg-muted';
|
|
61
|
-
const GROUP_BTN_CLASS = 'rounded-md border border-border-subtle bg-surface px-2 py-0.5 text-xs text-primary-on-soft transition-colors
|
|
62
|
-
const ITEM_CLASS = 'flex cursor-pointer items-center gap-3
|
|
63
|
-
const ITEM_OFF_CLASS = 'flex cursor-not-allowed items-center gap-3
|
|
64
|
-
const ITEM_ADDED_CLASS = 'flex cursor-pointer items-center gap-3
|
|
65
|
-
const ITEM_REMOVED_CLASS = 'flex cursor-pointer items-center gap-3
|
|
66
|
-
const CURSOR_CLASS = 'ring-2 ring-ring';
|
|
64
|
+
const GROUP_BTN_CLASS = 'rounded-md border border-border-subtle bg-surface px-2 py-0.5 text-xs text-primary-on-soft transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
65
|
+
const ITEM_CLASS = 'flex cursor-pointer items-center gap-3 border-b border-border-divider bg-surface px-3 py-2 text-fg transition-colors last:border-b-0 state-layer';
|
|
66
|
+
const ITEM_OFF_CLASS = 'flex cursor-not-allowed items-center gap-3 border-b border-border-divider bg-surface px-3 py-2 text-fg-subtle last:border-b-0';
|
|
67
|
+
const ITEM_ADDED_CLASS = 'flex cursor-pointer items-center gap-3 border-b border-border-divider bg-success-soft px-3 py-2 text-success-on-soft transition-colors last:border-b-0';
|
|
68
|
+
const ITEM_REMOVED_CLASS = 'flex cursor-pointer items-center gap-3 border-b border-border-divider bg-danger-soft px-3 py-2 text-danger-on-soft transition-colors last:border-b-0';
|
|
69
|
+
const CURSOR_CLASS = 'ring-2 ring-inset ring-ring';
|
|
67
70
|
const BOX_OFF_CLASS = 'inline-flex size-4 shrink-0 items-center justify-center rounded-md border border-border bg-surface text-xs';
|
|
68
71
|
const BOX_ON_CLASS = 'inline-flex size-4 shrink-0 items-center justify-center rounded-md border border-primary bg-primary text-xs text-primary-fg';
|
|
69
72
|
const TEXT_CLASS = 'flex min-w-0 flex-1 flex-col';
|
|
@@ -78,17 +81,19 @@ const FIELD_LABEL_CLASS = 'flex items-center gap-1 text-sm text-fg';
|
|
|
78
81
|
const STAR_CLASS = 'text-danger-on-soft';
|
|
79
82
|
const AREA_CLASS = 'block w-full appearance-none autofill-clear resize-none rounded-md border border-border bg-surface px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
80
83
|
const FIELD_ERROR_CLASS = 'text-xs text-danger-on-soft';
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
+
// mt-auto:根随容器拉高时按钮区贴在面板底部,不悬在中间
|
|
85
|
+
const FOOT_CLASS = 'mt-auto flex items-center justify-end gap-2 pt-1';
|
|
86
|
+
// 保存 / 取消(返回):标准高度(32)的实心 / 描边按钮,与对话框底栏、授权树同一配方(原手写 h-9 = 36)
|
|
87
|
+
const SAVE_CLASS = kitControlRecipe({ variant: 'primary' });
|
|
88
|
+
const CANCEL_CLASS = kitControlRecipe({ variant: 'neutral' });
|
|
84
89
|
|
|
85
90
|
export const KIT_ASSIGNMENT_PICKER_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
86
91
|
ROOT_CLASS, HELP_CLASS, SUBJECT_CLASS, SUBJECT_ITEM_CLASS, CAPTION_CLASS, STRONG_CLASS, ALERT_CLASS, GRID_CLASS, MAIN_FULL_CLASS,
|
|
87
|
-
|
|
92
|
+
MAIN_INNER_CLASS, SIDE_INNER_CLASS, HEAD_CLASS, TITLE_CLASS, SUMMARY_CLASS, CHANGES_CLASS, TOOLS_CLASS, 'hidden',
|
|
88
93
|
SEARCH_CLASS, TOOL_BTN_CLASS, LIST_CLASS, GROUP_CLASS, GROUP_HEAD_CLASS, GROUP_BTN_CLASS, ITEM_CLASS, ITEM_OFF_CLASS, ITEM_ADDED_CLASS,
|
|
89
94
|
ITEM_REMOVED_CLASS, CURSOR_CLASS, BOX_OFF_CLASS, BOX_ON_CLASS, TEXT_CLASS, LABEL_CLASS, SUB_CLASS, CHIP_BASE, CHIP_KEPT_CLASS,
|
|
90
95
|
CHIP_ADDED_CLASS, CHIP_REMOVED_CLASS, EMPTY_CLASS, FIELD_LABEL_CLASS, STAR_CLASS, AREA_CLASS, FIELD_ERROR_CLASS, FOOT_CLASS,
|
|
91
|
-
SAVE_CLASS, CANCEL_CLASS, 'hidden', 'flex', 'flex-1',
|
|
96
|
+
SAVE_CLASS, CANCEL_CLASS, KIT_OVERLAY_FORM_FOOTER_CLASS, kitOverlayFormScrollClass('gap-4'), 'hidden', 'flex', 'flex-1', 'rounded-full',
|
|
92
97
|
);
|
|
93
98
|
|
|
94
99
|
// ── 数据规整纯函数:解析、对比、过滤、分组、文案 ──
|
|
@@ -237,6 +242,7 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
237
242
|
value: { type: 'array', default: null, desc: '原有已授予 id(view.value 绑定);给了就覆盖 data 里的 value' },
|
|
238
243
|
object: { type: 'string', default: '', desc: '数据对象名(saved 载荷的 object)' },
|
|
239
244
|
mode: { type: 'string', default: 'edit', desc: '模式(saved 载荷的 mode)' },
|
|
245
|
+
multiple: { type: 'boolean', default: true, desc: '多选(缺省);false = 单选:点另一项即换选,勾选标记画成单选圆点,不出「全选」与分组「全选」钮(清空仍在)' },
|
|
240
246
|
save_label: { type: 'string', default: '', desc: '非空时底部出现保存钮,点击校验后抛 saved' },
|
|
241
247
|
...KIT_BUSY_PROP_DEFS,
|
|
242
248
|
cancel_label: { type: 'string', default: '', desc: '非空时底部出现取消钮,点击抛 cancel 并还原草稿' },
|
|
@@ -254,8 +260,8 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
254
260
|
keyboard: { layout: 'list', wrap: false, typeahead: false, focus_model: 'activedescendant', space: 'toggle_select' },
|
|
255
261
|
},
|
|
256
262
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
257
|
-
controllerFactory: (
|
|
258
|
-
const P = (): Record<string, unknown> =>
|
|
263
|
+
controllerFactory: createKitController((api) => {
|
|
264
|
+
const P = (): Record<string, unknown> => api.props();
|
|
259
265
|
const uid = `kit-assign-${++instanceCount}`;
|
|
260
266
|
let root: HTMLElement | null = null;
|
|
261
267
|
let items: KitAssignItem[] = [];
|
|
@@ -277,7 +283,7 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
277
283
|
let fieldLabel: HTMLLabelElement; let area: HTMLTextAreaElement; let fieldError: HTMLElement; let errorBox: HTMLElement;
|
|
278
284
|
let footBox: HTMLElement; let saveBox: HTMLElement; let cancelBox: HTMLElement; let saveBtn: HTMLButtonElement; let cancelBtn: HTMLButtonElement;
|
|
279
285
|
|
|
280
|
-
const T = (): KitAssignmentPickerTexts => textsOf(P().texts,
|
|
286
|
+
const T = (): KitAssignmentPickerTexts => textsOf(P().texts, api.host);
|
|
281
287
|
const locked = (): boolean => bool(P().disabled);
|
|
282
288
|
const boxOf = (child: HTMLElement): HTMLElement => { const b = document.createElement('div'); b.appendChild(child); return b; };
|
|
283
289
|
const mapOf = (): KitAssignmentPickerMap => keyMap(KIT_ASSIGNMENT_PICKER_DEFAULT_MAP, P().map) as KitAssignmentPickerMap;
|
|
@@ -294,6 +300,13 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
294
300
|
};
|
|
295
301
|
|
|
296
302
|
const pageStep = SOMA_SIZE_UNITS.collection.keyboard.pageStep;
|
|
303
|
+
// 方向键移动光标后,把活动项滚进可见区(测试环境无 scrollIntoView 时不抛)
|
|
304
|
+
const scrollCursorIntoView = (): void => {
|
|
305
|
+
const id = listEl?.getAttribute('aria-activedescendant');
|
|
306
|
+
if (id == null || id === '') return;
|
|
307
|
+
const node = listEl?.querySelector<HTMLElement>(`[id="${id.replace(/"/g, '\\"')}"]`);
|
|
308
|
+
node?.scrollIntoView?.({ block: 'nearest' });
|
|
309
|
+
};
|
|
297
310
|
const wiring = createKeyboardWiring({
|
|
298
311
|
contract: { layout: 'list', wrap: false, typeahead: false, focus_model: 'activedescendant', space: 'toggle_select' },
|
|
299
312
|
host: () => listEl ?? null,
|
|
@@ -301,18 +314,25 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
301
314
|
typeaheadDebounceMs: 0,
|
|
302
315
|
paging: { listItems: pageStep.listItems, gridRows: pageStep.gridRows },
|
|
303
316
|
getCursor: () => cursor,
|
|
304
|
-
setCursor: (key) => { cursor = key; paintList(); },
|
|
317
|
+
setCursor: (key) => { cursor = key; paintList(); scrollCursorIntoView(); },
|
|
305
318
|
onActivate: (key) => toggle(key),
|
|
306
319
|
onToggle: (key) => toggle(key),
|
|
307
320
|
});
|
|
308
321
|
|
|
309
|
-
const emitChange = (): void => {
|
|
322
|
+
const emitChange = (): void => { api.emit('change', payload()); };
|
|
323
|
+
|
|
324
|
+
const multiple = (): boolean => P().multiple !== false && P().multiple !== 'false';
|
|
310
325
|
|
|
311
326
|
const toggle = (id: string): void => {
|
|
312
327
|
const item = byId().get(id);
|
|
313
328
|
if (!item || !canToggle(item)) return;
|
|
314
329
|
cursor = id;
|
|
315
|
-
if (now.has(id)) now.delete(id);
|
|
330
|
+
if (now.has(id)) now.delete(id);
|
|
331
|
+
else {
|
|
332
|
+
// 单选:先清掉已选再选这一项(换选)
|
|
333
|
+
if (!multiple()) now.clear();
|
|
334
|
+
now.add(id);
|
|
335
|
+
}
|
|
316
336
|
reasonError = '';
|
|
317
337
|
notice = '';
|
|
318
338
|
paint();
|
|
@@ -375,7 +395,9 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
375
395
|
if (state !== '') row.setAttribute('data-kit-change', state);
|
|
376
396
|
const tone = !ok ? ITEM_OFF_CLASS : state === 'added' ? ITEM_ADDED_CLASS : state === 'removed' ? ITEM_REMOVED_CLASS : ITEM_CLASS;
|
|
377
397
|
row.className = cursor === item.id ? `${tone} ${CURSOR_CLASS}` : tone;
|
|
378
|
-
const
|
|
398
|
+
const boxClass = on ? BOX_ON_CLASS : BOX_OFF_CLASS;
|
|
399
|
+
const box = mk('span', multiple() ? boxClass : boxClass.replace('rounded-md', 'rounded-full'), '');
|
|
400
|
+
if (multiple()) markCheckBox(box);
|
|
379
401
|
if (on) box.appendChild(kitIcon('check', 'xs'));
|
|
380
402
|
box.setAttribute('aria-hidden', 'true');
|
|
381
403
|
const text = mk('span', TEXT_CLASS);
|
|
@@ -394,7 +416,7 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
394
416
|
listEl.textContent = '';
|
|
395
417
|
groupBarEl.textContent = '';
|
|
396
418
|
groupBarEl.className = 'hidden';
|
|
397
|
-
listEl.setAttribute('aria-multiselectable', 'true');
|
|
419
|
+
listEl.setAttribute('aria-multiselectable', multiple() ? 'true' : 'false');
|
|
398
420
|
if (vis.length === 0) {
|
|
399
421
|
const empty = mk('div', EMPTY_CLASS, str(P().empty_text) || t.empty);
|
|
400
422
|
empty.setAttribute('role', 'status');
|
|
@@ -420,11 +442,14 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
420
442
|
const allOn = pickable.length > 0 && pickable.every((i) => now.has(i.id));
|
|
421
443
|
const btn = mk('button', GROUP_BTN_CLASS, `${g.name}:${allOn ? t.group_none : t.group_all}`);
|
|
422
444
|
btn.type = 'button';
|
|
445
|
+
setKitFace(btn, 'raised');
|
|
423
446
|
btn.disabled = locked() || pickable.length === 0;
|
|
424
447
|
btn.setAttribute('data-kit-group', g.name);
|
|
425
448
|
btn.setAttribute('data-kit-group-on', allOn ? 'off' : 'on');
|
|
426
|
-
|
|
427
|
-
|
|
449
|
+
if (multiple()) {
|
|
450
|
+
groupBarEl.appendChild(btn);
|
|
451
|
+
groupBarEl.className = TOOLS_CLASS;
|
|
452
|
+
}
|
|
428
453
|
}
|
|
429
454
|
for (const item of g.items) wrap.appendChild(buildItem(item, t));
|
|
430
455
|
frag.appendChild(wrap);
|
|
@@ -469,12 +494,13 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
469
494
|
search.placeholder = t.search;
|
|
470
495
|
search.setAttribute('aria-label', t.search);
|
|
471
496
|
allBtn.textContent = t.select_all;
|
|
497
|
+
// 单选没有「全选」:钮收起(显隐落在类名上,外包层的 inline-flex 会盖住 [hidden])
|
|
498
|
+
allBtn.className = multiple() ? TOOL_BTN_CLASS : 'hidden';
|
|
472
499
|
clearBtn.textContent = t.clear;
|
|
473
500
|
allBtn.disabled = locked();
|
|
474
501
|
clearBtn.disabled = locked();
|
|
475
502
|
const reasonLabel = str(p.reason_label);
|
|
476
503
|
sideBox.hidden = reasonLabel === '';
|
|
477
|
-
mainBox.className = reasonLabel === '' ? MAIN_FULL_CLASS : MAIN_SPLIT_CLASS;
|
|
478
504
|
fieldLabel.textContent = '';
|
|
479
505
|
if (bool(p.reason_required)) {
|
|
480
506
|
const star = mk('span', STAR_CLASS, '*');
|
|
@@ -503,8 +529,7 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
503
529
|
paintList();
|
|
504
530
|
}
|
|
505
531
|
|
|
506
|
-
const
|
|
507
|
-
const busy = kb.busy;
|
|
532
|
+
const busy = (): boolean => kitBusyOf(P());
|
|
508
533
|
const save = (): void => {
|
|
509
534
|
if (locked() || error !== '' || busy()) return;
|
|
510
535
|
const p = P();
|
|
@@ -515,26 +540,26 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
515
540
|
notice = '';
|
|
516
541
|
paint();
|
|
517
542
|
area.focus();
|
|
518
|
-
|
|
543
|
+
api.emit('invalid', { field: 'reason' });
|
|
519
544
|
return;
|
|
520
545
|
}
|
|
521
546
|
const min = num(p.min_selected) ?? 0;
|
|
522
547
|
if (min > 0 && now.size < min) {
|
|
523
548
|
notice = fill(t.min_selected, { n: min });
|
|
524
549
|
paint();
|
|
525
|
-
|
|
550
|
+
api.emit('invalid', { field: 'min_selected' });
|
|
526
551
|
return;
|
|
527
552
|
}
|
|
528
553
|
const out = payload();
|
|
529
554
|
if (bool(p.require_change) && out.added.length + out.removed.length === 0) {
|
|
530
555
|
notice = t.need_change;
|
|
531
556
|
paint();
|
|
532
|
-
|
|
557
|
+
api.emit('invalid', { field: 'change' });
|
|
533
558
|
return;
|
|
534
559
|
}
|
|
535
560
|
notice = '';
|
|
536
561
|
paint();
|
|
537
|
-
|
|
562
|
+
api.emit('saved', { values: out, object: str(p.object), model: out, mode: str(p.mode, 'edit'), ...out });
|
|
538
563
|
};
|
|
539
564
|
|
|
540
565
|
const build = (host: HTMLElement): void => {
|
|
@@ -548,12 +573,15 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
548
573
|
head.append(titleEl, summaryEl);
|
|
549
574
|
changesEl = mk('p', CHANGES_CLASS);
|
|
550
575
|
search = mk('input', SEARCH_CLASS);
|
|
576
|
+
setKitFace(search, 'field');
|
|
551
577
|
search.type = 'search';
|
|
552
578
|
search.setAttribute('autocomplete', 'off');
|
|
553
579
|
searchBox = boxOf(search);
|
|
554
580
|
searchBox.className = 'flex flex-1';
|
|
555
581
|
allBtn = mk('button', TOOL_BTN_CLASS); allBtn.type = 'button';
|
|
556
582
|
clearBtn = mk('button', TOOL_BTN_CLASS); clearBtn.type = 'button';
|
|
583
|
+
setKitFace(allBtn, 'raised');
|
|
584
|
+
setKitFace(clearBtn, 'raised');
|
|
557
585
|
const tools = mk('div', TOOLS_CLASS);
|
|
558
586
|
tools.append(searchBox, allBtn, clearBtn);
|
|
559
587
|
groupBarEl = mk('div', 'hidden');
|
|
@@ -566,6 +594,7 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
566
594
|
mainBox.appendChild(mainInner);
|
|
567
595
|
fieldLabel = mk('label', FIELD_LABEL_CLASS);
|
|
568
596
|
area = mk('textarea', AREA_CLASS);
|
|
597
|
+
setKitFace(area, 'field');
|
|
569
598
|
area.rows = 4;
|
|
570
599
|
const areaId = `${uid}-reason`;
|
|
571
600
|
area.id = areaId;
|
|
@@ -573,21 +602,32 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
573
602
|
fieldError = mk('p', FIELD_ERROR_CLASS);
|
|
574
603
|
fieldError.setAttribute('role', 'alert');
|
|
575
604
|
errorBox = boxOf(fieldError);
|
|
605
|
+
// 申请原因:列表下方的整宽多行文本字段(不再是右侧分栏小框)
|
|
606
|
+
// 外层不带 flex(flex 会盖住 [hidden]),布局在内层
|
|
576
607
|
const sideInner = mk('div', SIDE_INNER_CLASS);
|
|
577
608
|
sideInner.append(fieldLabel, area, errorBox);
|
|
578
|
-
sideBox = mk('div',
|
|
609
|
+
sideBox = mk('div', '');
|
|
579
610
|
sideBox.appendChild(sideInner);
|
|
580
611
|
const grid = mk('div', GRID_CLASS);
|
|
581
|
-
grid.append(mainBox
|
|
612
|
+
grid.append(mainBox);
|
|
582
613
|
cancelBtn = mk('button', CANCEL_CLASS); cancelBtn.type = 'button';
|
|
583
614
|
saveBtn = mk('button', SAVE_CLASS); saveBtn.type = 'button';
|
|
615
|
+
setKitFace(cancelBtn, 'raised');
|
|
616
|
+
setKitFace(saveBtn, 'raised');
|
|
584
617
|
cancelBox = boxOf(cancelBtn);
|
|
585
618
|
saveBox = boxOf(saveBtn);
|
|
586
619
|
const foot = mk('div', FOOT_CLASS);
|
|
587
620
|
foot.append(cancelBox, saveBox);
|
|
588
621
|
footBox = boxOf(foot);
|
|
622
|
+
// 浮层滚动体里底栏吸底并贴着浮层底边(外包层是 sticky 元素;变体只在 group-data-kit-overlay-scroll 祖先下生效)
|
|
623
|
+
footBox.className = KIT_OVERLAY_FORM_FOOTER_CLASS;
|
|
624
|
+
// 滚动区(底栏之外的内容):页面级 contents、浮层里 flex-1 min-h-0 overflow-y-auto;底栏在它之外,不随内容滚动
|
|
625
|
+
const scrollArea = mk('div', kitOverlayFormScrollClass('gap-4'));
|
|
626
|
+
scrollArea.setAttribute(KIT_OVERLAY_FORM_SCROLL_ATTR, '');
|
|
627
|
+
scrollArea.append(helpEl, subjectEl, alertEl, grid, sideBox);
|
|
628
|
+
footBox.setAttribute(KIT_OVERLAY_FOOT_ATTR, '');
|
|
589
629
|
host.textContent = '';
|
|
590
|
-
host.append(
|
|
630
|
+
host.append(scrollArea, footBox);
|
|
591
631
|
|
|
592
632
|
const on = (target: HTMLElement, type: string, fn: (event: Event) => void): void => {
|
|
593
633
|
target.addEventListener(type, fn);
|
|
@@ -623,30 +663,27 @@ export function createAssignmentPicker(): SomaComponentDefinition {
|
|
|
623
663
|
notice = '';
|
|
624
664
|
reason = str(envelopeOf(P().data, mapOf().items)[mapOf().reason]);
|
|
625
665
|
paint();
|
|
626
|
-
|
|
666
|
+
api.emit('cancel', {});
|
|
627
667
|
});
|
|
628
668
|
};
|
|
629
669
|
|
|
630
670
|
return {
|
|
631
|
-
|
|
632
|
-
|
|
671
|
+
busyAware: true,
|
|
672
|
+
attach(rootEl) {
|
|
673
|
+
root = rootEl;
|
|
633
674
|
build(root);
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
675
|
+
return () => {
|
|
676
|
+
for (const fn of removers) fn();
|
|
677
|
+
removers = [];
|
|
678
|
+
root = null;
|
|
679
|
+
};
|
|
637
680
|
},
|
|
638
|
-
|
|
639
|
-
|
|
681
|
+
render(rootEl) {
|
|
682
|
+
root = rootEl;
|
|
640
683
|
sync();
|
|
641
684
|
paint();
|
|
642
685
|
},
|
|
643
|
-
onUnmount(): void {
|
|
644
|
-
kb.dispose();
|
|
645
|
-
for (const fn of removers) fn();
|
|
646
|
-
removers = [];
|
|
647
|
-
root = null;
|
|
648
|
-
},
|
|
649
686
|
};
|
|
650
|
-
},
|
|
687
|
+
}),
|
|
651
688
|
};
|
|
652
689
|
}
|
|
@@ -6,16 +6,28 @@
|
|
|
6
6
|
// result:{ title?, summary?, tone?, lines[{ label?, text }] },非空才出结果框;tone 取 neutral / info / success / warning / danger(默认 info)。
|
|
7
7
|
// adopt_label 非空出「采纳」钮,dismiss_label 非空出「忽略」钮。
|
|
8
8
|
// 指令输入(show_prompt,默认真)是组件内草稿,重画不丢焦点;change 时抛 `prompt_change { value }`,点运行抛 `run { prompt }`。
|
|
9
|
+
// 无内容态:空闲且没有标题 / 副标题、指令框、运行钮、状态行、结果时,画共享三态空面板 +「暂无结果」词条(soma.kit.async_idle),
|
|
10
|
+
// 不留一张空白卡;页面不必(也不应)为此写装饰性的标题 + 说明。
|
|
9
11
|
// 不改数据:运行 / 取消 / 采纳 / 忽略都只抛事件,状态由页面经 data 下行。
|
|
10
12
|
|
|
11
13
|
import type { SomaComponentDefinition, SomaDataPort } from 'soma-core';
|
|
12
14
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
15
|
+
import {
|
|
16
|
+
createLoadingGate,
|
|
17
|
+
KIT_LOADING_GATE_DEFAULTS,
|
|
18
|
+
type KitLoadingGate,
|
|
19
|
+
type KitLoadingPhase,
|
|
20
|
+
} from '../base/loading-gate';
|
|
21
|
+
import { kitEmptyPanel } from '../base/state-panel';
|
|
13
22
|
import { watchKitOutcome, type KitOutcome } from './outcome-watch';
|
|
23
|
+
import { KIT_MS_ASIDE_IDLE_ATTR, KIT_MS_ROOT_ATTR } from '../recipes/container';
|
|
14
24
|
import { kitText } from '../i18n/kit-text';
|
|
25
|
+
import { setKitFace } from '../recipes';
|
|
15
26
|
import { KIT_BUSY_PROP_DEFS, cancelKitAction, kitBusyOf } from '../base/action-busy';
|
|
16
27
|
import {
|
|
17
28
|
actionButton, BADGE_BASE, BUTTON_CLASS_TOKENS, classTokens, mk, recOf, rowsOf, shapeToneOf, textOf, TONE_SOFT,
|
|
18
29
|
} from './shape-util';
|
|
30
|
+
import { TEXT_ACTION_CLASS_TOKENS, textActionButton } from './text-action-button';
|
|
19
31
|
|
|
20
32
|
const ROOT_CLASS = 'flex flex-col gap-3';
|
|
21
33
|
const HEAD_CLASS = 'flex flex-col gap-1';
|
|
@@ -34,7 +46,7 @@ const LINE_LABEL = 'font-medium';
|
|
|
34
46
|
|
|
35
47
|
export const KIT_ASYNC_RESULT_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
36
48
|
ROOT_CLASS, HEAD_CLASS, TITLE_CLASS, SUBTITLE_CLASS, LABEL_WRAP, LABEL_CLASS, AREA_CLASS, BUTTONS_CLASS, MESSAGE_CLASS, MESSAGE_FAILED,
|
|
37
|
-
RESULT_BASE, RESULT_TITLE, LINE_CLASS, LINE_LABEL, BADGE_BASE, Object.values(TONE_SOFT), BUTTON_CLASS_TOKENS,
|
|
49
|
+
RESULT_BASE, RESULT_TITLE, LINE_CLASS, LINE_LABEL, BADGE_BASE, Object.values(TONE_SOFT), BUTTON_CLASS_TOKENS, TEXT_ACTION_CLASS_TOKENS,
|
|
38
50
|
);
|
|
39
51
|
|
|
40
52
|
export type KitAsyncStatus = 'idle' | 'busy' | 'ready' | 'failed';
|
|
@@ -67,12 +79,22 @@ export function asyncResultOf(raw: unknown): KitAsyncResult | null {
|
|
|
67
79
|
export function outcomePanelData(o: KitOutcome): Record<string, unknown> {
|
|
68
80
|
switch (o.status) {
|
|
69
81
|
case 'pending': return { status: 'busy' };
|
|
70
|
-
|
|
82
|
+
// 业务失败(通道成功、展示对象 ctx.failOutcome 判为否):保留响应体里的阶段行,整体换成危险语气(响应体自带 warning 语气的保留)
|
|
83
|
+
case 'failed':
|
|
84
|
+
if (o.business === true) return { status: 'failed', message: o.message, result: businessFailureResult(o.data) };
|
|
85
|
+
return { status: 'failed', message: o.message };
|
|
86
|
+
case 'conflict': case 'held': return { status: 'failed', message: o.message };
|
|
71
87
|
case 'saved': return { status: 'ready', result: outcomeResultOf(o.data) };
|
|
72
88
|
default: return { status: 'idle' };
|
|
73
89
|
}
|
|
74
90
|
}
|
|
75
91
|
|
|
92
|
+
/** 业务失败的结果框:同成功时一样从响应体取阶段行,语气只许 warning / danger(其余一律 danger) */
|
|
93
|
+
export function businessFailureResult(body: unknown): Record<string, unknown> {
|
|
94
|
+
const result = outcomeResultOf(body);
|
|
95
|
+
return { ...result, tone: result.tone === 'warning' ? 'warning' : 'danger' };
|
|
96
|
+
}
|
|
97
|
+
|
|
76
98
|
export function outcomeResultOf(body: unknown): Record<string, unknown> {
|
|
77
99
|
const top = recOf(body);
|
|
78
100
|
const payload = recOf(top.data !== undefined && top.data !== null && typeof top.data === 'object' ? top.data : top);
|
|
@@ -101,13 +123,47 @@ interface PanelState {
|
|
|
101
123
|
btnSlot: HTMLElement | null;
|
|
102
124
|
msg: HTMLElement | null;
|
|
103
125
|
resSlot: HTMLElement | null;
|
|
126
|
+
/** 无内容时的空面板(共享三态空面板,惰性创建) */
|
|
127
|
+
idle: HTMLElement | null;
|
|
128
|
+
/** 加载反馈三阈值状态机 */
|
|
129
|
+
gate: KitLoadingGate;
|
|
130
|
+
wasBusy: boolean;
|
|
104
131
|
}
|
|
105
132
|
|
|
106
133
|
export function createAsyncResultPanel(): SomaComponentDefinition {
|
|
107
134
|
const states = new WeakMap<HTMLElement, PanelState>();
|
|
108
135
|
const stateOf = (root: HTMLElement): PanelState => {
|
|
109
136
|
let s = states.get(root);
|
|
110
|
-
if (!s) {
|
|
137
|
+
if (!s) {
|
|
138
|
+
const gate = createLoadingGate(
|
|
139
|
+
{
|
|
140
|
+
delayMs: KIT_LOADING_GATE_DEFAULTS.delayMs,
|
|
141
|
+
minDurationMs: KIT_LOADING_GATE_DEFAULTS.minDurationMs,
|
|
142
|
+
doneHoldMs: KIT_LOADING_GATE_DEFAULTS.doneHoldMs,
|
|
143
|
+
},
|
|
144
|
+
(phase: KitLoadingPhase) => {
|
|
145
|
+
root.setAttribute('data-kit-loading-phase', phase);
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
s = {
|
|
149
|
+
outcomeName: '',
|
|
150
|
+
offOutcome: null,
|
|
151
|
+
outcome: null,
|
|
152
|
+
area: null,
|
|
153
|
+
top: null,
|
|
154
|
+
mid: null,
|
|
155
|
+
bottom: null,
|
|
156
|
+
promptVisible: false,
|
|
157
|
+
body: null,
|
|
158
|
+
btnSlot: null,
|
|
159
|
+
msg: null,
|
|
160
|
+
resSlot: null,
|
|
161
|
+
idle: null,
|
|
162
|
+
gate,
|
|
163
|
+
wasBusy: false,
|
|
164
|
+
};
|
|
165
|
+
states.set(root, s);
|
|
166
|
+
}
|
|
111
167
|
return s;
|
|
112
168
|
};
|
|
113
169
|
|
|
@@ -143,17 +199,22 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
|
|
|
143
199
|
},
|
|
144
200
|
services: ['data'],
|
|
145
201
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
146
|
-
controllerFactory: createKitController({
|
|
202
|
+
controllerFactory: createKitController(() => ({
|
|
147
203
|
busyAware: true,
|
|
148
204
|
attach(root, api) {
|
|
149
205
|
const onClick = (event: Event): void => {
|
|
150
206
|
const btn = (event.target as HTMLElement | null)?.closest<HTMLButtonElement>('[data-kit-action]');
|
|
151
207
|
if (!btn || btn.disabled) return;
|
|
152
208
|
const key = btn.getAttribute('data-kit-action');
|
|
153
|
-
if (key === 'run') api.emit('run', { prompt: stateOf(root).area?.value ?? '' });
|
|
209
|
+
if (key === 'run' || key === 'retry') api.emit('run', { prompt: stateOf(root).area?.value ?? '' });
|
|
154
210
|
else if (key === 'cancel' || key === 'adopt' || key === 'dismiss') {
|
|
155
211
|
// 所接 request 动作声明了 cancelable:真正中止在途请求(没声明则只发 cancel 事件,行为同前)
|
|
156
|
-
if (key === 'cancel')
|
|
212
|
+
if (key === 'cancel') {
|
|
213
|
+
const st = stateOf(root);
|
|
214
|
+
st.wasBusy = false;
|
|
215
|
+
st.gate.cancel();
|
|
216
|
+
cancelKitAction(str(api.props().busy_action, ''));
|
|
217
|
+
}
|
|
157
218
|
api.emit(key, {});
|
|
158
219
|
}
|
|
159
220
|
};
|
|
@@ -166,7 +227,9 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
|
|
|
166
227
|
return () => {
|
|
167
228
|
root.removeEventListener('click', onClick);
|
|
168
229
|
root.removeEventListener('change', onChange);
|
|
169
|
-
states.get(root)
|
|
230
|
+
const st = states.get(root);
|
|
231
|
+
st?.gate.cancel();
|
|
232
|
+
st?.offOutcome?.();
|
|
170
233
|
states.delete(root);
|
|
171
234
|
};
|
|
172
235
|
},
|
|
@@ -193,11 +256,23 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
|
|
|
193
256
|
if (outName !== '' && st.outcome?.status === 'cancelled') data.message = kitText('soma.kit.request_cancelled', undefined, root);
|
|
194
257
|
const status = asyncStatusOf(data.status);
|
|
195
258
|
const busy = status === 'busy';
|
|
259
|
+
const actionBusy = kitBusyOf(p);
|
|
260
|
+
const isBusy = busy || actionBusy;
|
|
261
|
+
if (isBusy && !st.wasBusy) {
|
|
262
|
+
st.wasBusy = true;
|
|
263
|
+
st.gate.start();
|
|
264
|
+
} else if (!isBusy && st.wasBusy) {
|
|
265
|
+
st.wasBusy = false;
|
|
266
|
+
if (status === 'idle') st.gate.cancel();
|
|
267
|
+
else st.gate.finish();
|
|
268
|
+
}
|
|
269
|
+
root.setAttribute('data-kit-loading-phase', st.gate.phase());
|
|
196
270
|
const showPrompt = bool(p.show_prompt);
|
|
197
271
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
198
272
|
|
|
199
273
|
if (!st.top || !st.mid || !st.bottom) {
|
|
200
274
|
root.textContent = '';
|
|
275
|
+
st.idle = null;
|
|
201
276
|
st.top = mk('div', '');
|
|
202
277
|
st.mid = mk('div', '');
|
|
203
278
|
st.bottom = mk('div', '');
|
|
@@ -224,6 +299,7 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
|
|
|
224
299
|
const wrap = mk('label', LABEL_WRAP);
|
|
225
300
|
if (str(p.prompt_label) !== '') wrap.appendChild(mk('span', LABEL_CLASS, str(p.prompt_label)));
|
|
226
301
|
const area = mk('textarea', AREA_CLASS);
|
|
302
|
+
setKitFace(area, 'field');
|
|
227
303
|
area.setAttribute('data-kit-prompt', '');
|
|
228
304
|
area.value = str(p.prompt_value);
|
|
229
305
|
area.setAttribute('data-kit-given', str(p.prompt_value));
|
|
@@ -259,7 +335,6 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
|
|
|
259
335
|
bottom.appendChild(st.body);
|
|
260
336
|
}
|
|
261
337
|
const body = st.resSlot;
|
|
262
|
-
const actionBusy = kitBusyOf(p);
|
|
263
338
|
const buttons = mk('div', BUTTONS_CLASS);
|
|
264
339
|
if (p.show_run !== false) {
|
|
265
340
|
buttons.appendChild(actionButton({
|
|
@@ -271,6 +346,10 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
|
|
|
271
346
|
}));
|
|
272
347
|
if (actionBusy) (buttons.firstElementChild as HTMLElement).setAttribute('aria-busy', 'true');
|
|
273
348
|
}
|
|
349
|
+
// 失败行的「重试」:主色文字链接(不与同行的危险色错误文案同红),等同再点一次运行
|
|
350
|
+
if (status === 'failed' && !isBusy && p.show_run !== false && !bool(p.run_disabled)) {
|
|
351
|
+
buttons.appendChild(textActionButton('retry', kitText('soma.kit.ct_retry', undefined, root), 'primary'));
|
|
352
|
+
}
|
|
274
353
|
if (busy) buttons.appendChild(actionButton({ key: 'cancel', label: str(p.cancel_label, kitText('soma.kit.cancel', undefined, root)), tone: 'neutral', disabled: false, reason: '' }));
|
|
275
354
|
st.btnSlot.replaceChildren(buttons);
|
|
276
355
|
const message = textOf(data.message);
|
|
@@ -302,7 +381,30 @@ export function createAsyncResultPanel(): SomaComponentDefinition {
|
|
|
302
381
|
}
|
|
303
382
|
body.appendChild(box);
|
|
304
383
|
}
|
|
384
|
+
// 没有任何可画的内容(空闲、无标题 / 副标题、无指令框、无运行钮、无状态行、无结果):不留一张空白卡,
|
|
385
|
+
// 画共享的三态空面板 + 中性词条「暂无结果」(不是装饰性标题 + 说明);一有内容立刻让位
|
|
386
|
+
const quiet = status === 'idle' && !isBusy && textOf(data.title) === '' && textOf(data.subtitle) === ''
|
|
387
|
+
&& !showPrompt && p.show_run === false && message === '' && !result;
|
|
388
|
+
bottom.hidden = quiet;
|
|
389
|
+
// 主从工作台的辅助栏(aside)里放它时:尚无结果(quiet)整栏收起、中栏占满,有结果再出现——只切根上的状态标记,
|
|
390
|
+
// 外观由壳上已写好的变体类(group-data-kit-aside-idle/ms:)决定,不写内联样式
|
|
391
|
+
const msRoot = root.closest<HTMLElement>(`[${KIT_MS_ROOT_ATTR}]`);
|
|
392
|
+
if (msRoot !== null) {
|
|
393
|
+
if (quiet) msRoot.setAttribute(KIT_MS_ASIDE_IDLE_ATTR, ''); else msRoot.removeAttribute(KIT_MS_ASIDE_IDLE_ATTR);
|
|
394
|
+
}
|
|
395
|
+
if (quiet) {
|
|
396
|
+
const text = kitText('soma.kit.async_idle', undefined, root);
|
|
397
|
+
if (st.idle === null) {
|
|
398
|
+
st.idle = kitEmptyPanel(document, text, true);
|
|
399
|
+
root.appendChild(st.idle);
|
|
400
|
+
} else if (st.idle.textContent !== text) {
|
|
401
|
+
st.idle.textContent = text;
|
|
402
|
+
}
|
|
403
|
+
st.idle.hidden = false;
|
|
404
|
+
} else if (st.idle !== null) {
|
|
405
|
+
st.idle.hidden = true;
|
|
406
|
+
}
|
|
305
407
|
},
|
|
306
|
-
}),
|
|
408
|
+
})),
|
|
307
409
|
};
|
|
308
410
|
}
|
package/src/data/breadcrumbs.ts
CHANGED
|
@@ -19,10 +19,11 @@ const ROOT_SCROLL_CLASS = 'flex min-w-0 items-center overflow-x-auto text-sm tex
|
|
|
19
19
|
const LIST_CLASS = 'flex min-w-0 flex-wrap items-center gap-1';
|
|
20
20
|
const LIST_SCROLL_CLASS = 'flex flex-nowrap items-center gap-1 whitespace-nowrap';
|
|
21
21
|
const ITEM_CLASS = 'flex min-w-0 items-center gap-1';
|
|
22
|
-
|
|
22
|
+
// border-0 bg-transparent p-0:按钮型面包屑项没有 preflight 时带浏览器默认 6px 横向内边距,会让分隔符两侧间距不等、首项比当前项缩进多 6px
|
|
23
|
+
const LINK_CLASS = `min-w-0 cursor-pointer truncate rounded-sm border-0 bg-transparent p-0 text-start text-fg-muted transition-colors hover:text-fg hover:underline ${FOCUS}`;
|
|
23
24
|
const CURRENT_CLASS = 'min-w-0 truncate font-medium text-fg';
|
|
24
25
|
const SEP_CLASS = 'shrink-0 text-fg-subtle';
|
|
25
|
-
const ELLIPSIS_CLASS = `inline-flex h-6 min-w-6 cursor-pointer items-center justify-center rounded-sm px-1 text-fg-muted transition-colors hover:bg-
|
|
26
|
+
const ELLIPSIS_CLASS = `inline-flex h-6 min-w-6 cursor-pointer items-center justify-center rounded-sm px-1 text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg ${FOCUS}`;
|
|
26
27
|
const ELLIPSIS_STATIC_CLASS = 'shrink-0 px-1 text-fg-muted';
|
|
27
28
|
|
|
28
29
|
/** 本组件自带的全部类(供编译器并入候选类,页面框静态页头同用) */
|
|
@@ -183,7 +184,7 @@ export function createBreadcrumbs(): SomaComponentDefinition {
|
|
|
183
184
|
},
|
|
184
185
|
},
|
|
185
186
|
templateHtml: `<nav data-soma-id="root" class="${ROOT_CLASS}"></nav>`,
|
|
186
|
-
controllerFactory: createKitController({
|
|
187
|
+
controllerFactory: createKitController(() => ({
|
|
187
188
|
attach(root, api) {
|
|
188
189
|
const handle = mountKitBreadcrumbs(root, (name, payload) => api.emit(name, payload));
|
|
189
190
|
HANDLES.set(root, handle);
|
|
@@ -192,6 +193,6 @@ export function createBreadcrumbs(): SomaComponentDefinition {
|
|
|
192
193
|
render(root, p) {
|
|
193
194
|
HANDLES.get(root)?.update(p);
|
|
194
195
|
},
|
|
195
|
-
}),
|
|
196
|
+
})),
|
|
196
197
|
};
|
|
197
198
|
}
|