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
package/src/data/code-view.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
9
9
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
10
10
|
import { kitIcon } from '../base/icons';
|
|
11
|
+
import { KIT_PART_ATTRIBUTE, KIT_PART_WELL } from '../recipes';
|
|
11
12
|
import { kitText } from '../i18n/kit-text';
|
|
12
13
|
import { actionButton, classTokens, BUTTON_CLASS_TOKENS, mk, recOf, textOf } from './shape-util';
|
|
13
14
|
import {
|
|
@@ -30,7 +31,9 @@ const EMPTY_CLASS = 'text-fg-subtle';
|
|
|
30
31
|
const CAPTION_CLASS = 'text-xs text-fg-subtle';
|
|
31
32
|
|
|
32
33
|
// variants:同一块位置按页签切换多份文本(如同一服务的多个客户端配置)
|
|
33
|
-
|
|
34
|
+
// 页签行可收缩(min-w-0 flex-1):窄容器里页签自己换行,让位给右侧「复制」钮,钮文案不折行
|
|
35
|
+
const TABS_CLASS = 'flex min-w-0 flex-1 flex-wrap gap-1 border-b border-border-subtle';
|
|
36
|
+
const HEAD_END_BUTTON = 'shrink-0';
|
|
34
37
|
const TAB_CLASS = 'h-8 -mb-px border-b-2 border-transparent bg-transparent px-3 text-sm text-fg-muted hover:text-fg motion-safe:transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
35
38
|
const TAB_ACTIVE_CLASS = 'border-primary font-medium text-fg';
|
|
36
39
|
|
|
@@ -77,7 +80,7 @@ export function codeVariantsFromProps(p: Record<string, unknown>): KitCodeVarian
|
|
|
77
80
|
|
|
78
81
|
// tree:JSON 树(自绘 disclosure:标题 button + aria-expanded / aria-controls,Enter / Space 由 button 触发点击切换)
|
|
79
82
|
const TREE_CLASS = 'm-0 rounded-md border border-border-subtle bg-surface-sunken p-3 font-mono text-xs text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
80
|
-
const TREE_SUMMARY_CLASS = 'block w-full cursor-pointer select-none rounded-sm bg-transparent p-0 text-start font-mono text-xs text-fg hover:bg-
|
|
83
|
+
const TREE_SUMMARY_CLASS = 'block w-full cursor-pointer select-none rounded-sm bg-transparent p-0 text-start font-mono text-xs text-fg hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
81
84
|
const TREE_CHILDREN_CLASS = 'ms-3 border-s border-border-subtle ps-3';
|
|
82
85
|
const TREE_LEAF_CLASS = 'py-0.5 break-all';
|
|
83
86
|
const TREE_KEY_CLASS = 'text-fg-muted';
|
|
@@ -92,7 +95,7 @@ let treeSeq = 0;
|
|
|
92
95
|
export const KIT_CODE_VIEW_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
93
96
|
TREE_CLASS, TREE_SUMMARY_CLASS, TREE_CHILDREN_CLASS, TREE_LEAF_CLASS, TREE_KEY_CLASS, TREE_MARK_CLASS, TREE_HIDDEN_CLASS, Object.values(TREE_VALUE_CLASS), TREE_MORE_CLASS,
|
|
94
97
|
ROOT_CLASS, HEAD_CLASS, TITLE_CLASS, KIT_CODE_PRE_CLASS, Object.values(PRE_HEIGHT), EMPTY_CLASS, CAPTION_CLASS, BUTTON_CLASS_TOKENS,
|
|
95
|
-
TABS_CLASS, TAB_CLASS, TAB_ACTIVE_CLASS,
|
|
98
|
+
TABS_CLASS, TAB_CLASS, TAB_ACTIVE_CLASS, HEAD_END_BUTTON,
|
|
96
99
|
);
|
|
97
100
|
|
|
98
101
|
/** 展示文本(纯函数,便于单测):字符串原样,其余 JSON 缩进;不可序列化回空串 */
|
|
@@ -220,7 +223,7 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
220
223
|
},
|
|
221
224
|
},
|
|
222
225
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
223
|
-
controllerFactory: createKitController({
|
|
226
|
+
controllerFactory: createKitController(() => ({
|
|
224
227
|
attach(root, api) {
|
|
225
228
|
const onClick = (event: Event): void => {
|
|
226
229
|
const btn = (event.target as HTMLElement | null)?.closest<HTMLButtonElement>('[data-kit-action="copy"]');
|
|
@@ -322,7 +325,7 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
322
325
|
render(root, p) {
|
|
323
326
|
renderCode(root, p);
|
|
324
327
|
},
|
|
325
|
-
}),
|
|
328
|
+
})),
|
|
326
329
|
};
|
|
327
330
|
|
|
328
331
|
function renderCode(root: HTMLElement, p: Record<string, unknown>): void {
|
|
@@ -377,7 +380,9 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
377
380
|
head.appendChild(tabs);
|
|
378
381
|
} else head.appendChild(mk('span', TITLE_CLASS, title));
|
|
379
382
|
if (copyable) {
|
|
380
|
-
|
|
383
|
+
const copyBtn = actionButton({ key: 'copy', label: str(p.copy_label, kitText('soma.kit.copy', undefined, root)), tone: 'neutral', disabled: text === '', reason: '' });
|
|
384
|
+
copyBtn.classList.add(HEAD_END_BUTTON);
|
|
385
|
+
head.appendChild(copyBtn);
|
|
381
386
|
}
|
|
382
387
|
root.appendChild(head);
|
|
383
388
|
}
|
|
@@ -388,6 +393,7 @@ export function createCodeView(): SomaComponentDefinition {
|
|
|
388
393
|
: mk('pre', `${KIT_CODE_PRE_CLASS}${height !== '' ? ` ${height}` : ''}`);
|
|
389
394
|
pre.tabIndex = 0;
|
|
390
395
|
pre.setAttribute('data-kit-code', '');
|
|
396
|
+
pre.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_WELL);
|
|
391
397
|
const label = str(p.aria_label) !== '' ? str(p.aria_label) : title;
|
|
392
398
|
if (label !== '') pre.setAttribute('aria-label', label);
|
|
393
399
|
if (stream) {
|
|
@@ -10,6 +10,7 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
10
10
|
import { matchSubmitKey } from 'soma-core/keyboard';
|
|
11
11
|
import { bool, createKitController, formatValue, joinClass, num, str } from '../base/shared';
|
|
12
12
|
import { kitText } from '../i18n/kit-text';
|
|
13
|
+
import { setKitFace } from '../recipes';
|
|
13
14
|
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, rowsOf, textOf, TONE_SOFT } from './shape-util';
|
|
14
15
|
import { AVATAR_CLASS_TOKENS, avatarNode } from './d9-util';
|
|
15
16
|
import { CHAT_MAX_LENGTH, CHAT_MAX_MESSAGES, CHAT_STATUSES } from './d9-limits';
|
|
@@ -29,7 +30,7 @@ const CHAT_META = 'flex items-center gap-2 px-1 text-xs text-fg-subtle';
|
|
|
29
30
|
const CHAT_META_FAILED = 'flex items-center gap-2 px-1 text-xs text-danger-on-soft';
|
|
30
31
|
const CHAT_RETRY = 'rounded-md text-danger-on-soft underline transition-colors hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
31
32
|
const CHAT_LIST = 'flex flex-col gap-4 overflow-y-auto';
|
|
32
|
-
const CHAT_ATTACH = 'inline-flex h-8 items-center justify-center rounded-md border border-
|
|
33
|
+
const CHAT_ATTACH = 'inline-flex h-8 items-center justify-center rounded-md border border-button-edge bg-surface px-3 text-sm text-fg transition-colors state-layer active:opacity-80 disabled:cursor-not-allowed disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
33
34
|
const CHAT_CLASS_TOKENS = classTokens(
|
|
34
35
|
CHAT_MSG, CHAT_MSG_MINE, CHAT_COL, CHAT_COL_MINE, CHAT_NAME, CHAT_BUBBLE, CHAT_THEM, CHAT_ME, CHAT_META, CHAT_META_FAILED, CHAT_RETRY,
|
|
35
36
|
CHAT_LIST, CHAT_ATTACH, AVATAR_CLASS_TOKENS,
|
|
@@ -48,7 +49,7 @@ const TEXT_CLASS = 'whitespace-pre-wrap text-fg';
|
|
|
48
49
|
const ROW_ACTIONS = 'flex items-center gap-3 text-xs';
|
|
49
50
|
const LINK_BUTTON = 'rounded-md text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
50
51
|
const COMPOSER_CLASS = 'flex flex-col gap-2';
|
|
51
|
-
const INPUT_CLASS = 'w-full appearance-none autofill-clear resize-none rounded-md border border-border bg-surface px-3 py-2 text-sm text-fg transition-colors
|
|
52
|
+
const INPUT_CLASS = 'w-full appearance-none autofill-clear resize-none rounded-md border border-border bg-surface px-3 py-2 text-sm text-fg transition-colors state-layer disabled:cursor-not-allowed disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
52
53
|
const COMPOSER_FOOT = 'flex items-center justify-between gap-2';
|
|
53
54
|
const COUNTER_CLASS = 'text-xs text-fg-subtle';
|
|
54
55
|
|
|
@@ -146,7 +147,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
146
147
|
},
|
|
147
148
|
},
|
|
148
149
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
149
|
-
controllerFactory: createKitController({
|
|
150
|
+
controllerFactory: createKitController(() => ({
|
|
150
151
|
attach(root, api) {
|
|
151
152
|
const submit = (): void => {
|
|
152
153
|
const c = parts.get(root);
|
|
@@ -209,6 +210,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
209
210
|
const composer = mk('div', COMPOSER_CLASS);
|
|
210
211
|
composer.setAttribute('data-kit-composer', '');
|
|
211
212
|
const area = mk('textarea', INPUT_CLASS);
|
|
213
|
+
setKitFace(area, 'field');
|
|
212
214
|
area.rows = 3;
|
|
213
215
|
const foot = mk('div', COMPOSER_FOOT);
|
|
214
216
|
const counter = mk('span', COUNTER_CLASS);
|
|
@@ -316,6 +318,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
316
318
|
if (!attach) {
|
|
317
319
|
attach = mk('button', CHAT_ATTACH);
|
|
318
320
|
attach.type = 'button';
|
|
321
|
+
setKitFace(attach, 'raised');
|
|
319
322
|
attach.setAttribute('data-kit-attach', '');
|
|
320
323
|
c.send.parentElement?.insertBefore(attach, c.send);
|
|
321
324
|
}
|
|
@@ -326,7 +329,7 @@ export function createCommentThread(): SomaComponentDefinition {
|
|
|
326
329
|
c.send.textContent = str(p.send_text, kitText('soma.kit.ct_send', undefined, root));
|
|
327
330
|
syncComposer(c, p);
|
|
328
331
|
},
|
|
329
|
-
}),
|
|
332
|
+
})),
|
|
330
333
|
};
|
|
331
334
|
}
|
|
332
335
|
|
|
@@ -4,28 +4,35 @@
|
|
|
4
4
|
// - 返回 Promise<boolean>:确认 = true;取消 / Esc / 点遮罩 / 关闭钮 = false。调用方一律 await,不再有同步阻塞;
|
|
5
5
|
// - 文案只用 textContent 写入(含 `{name}` 之类插值后的结果),不经 innerHTML;
|
|
6
6
|
// - tone = 'danger' 时确认钮用 danger 色调,且焦点落在取消钮(误按回车不会执行危险操作);
|
|
7
|
-
// - typedPhrase:要求键入短语才允许确认(确认钮在输入一致前禁用);
|
|
7
|
+
// - typedPhrase:要求键入短语才允许确认(确认钮在输入一致前禁用);consent:要先勾选「已知晓影响并同意」才允许确认;
|
|
8
|
+
// 两者的判据都是 core 的 confirmSatisfied / confirmKeyAccepts;壳是 alertdialog(名 = 标题,描述 = 正文);
|
|
8
9
|
// - alertOnly:只有一个「确定」钮(取代 window.alert),恒 resolve true。
|
|
9
10
|
// 无 DOM 环境(SSR / 测试)时不弹,直接 resolve whenNoDom(缺省 false)。
|
|
10
11
|
|
|
12
|
+
import type { SomaConfirmSpec } from 'soma-core';
|
|
13
|
+
import { confirmKeyAccepts, confirmSatisfied } from 'soma-core/render-ports';
|
|
14
|
+
import { KIT_CHECK_CLASS_CANDIDATES, createCheck, markInput, setMarkLabel } from '../base/check-core';
|
|
15
|
+
import { nextUid } from '../base/shared';
|
|
11
16
|
import { kitText } from '../i18n/kit-text';
|
|
17
|
+
import { setKitFace } from '../recipes';
|
|
12
18
|
import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal } from './modal-dialog';
|
|
13
19
|
import { BUTTON_CLASS_TOKENS, classTokens, type ActionTone } from './shape-util';
|
|
14
20
|
|
|
15
|
-
const BUTTON_BASE = 'inline-flex h-
|
|
21
|
+
const BUTTON_BASE = 'inline-flex h-8 cursor-pointer items-center justify-center rounded-md px-4 text-sm font-medium transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
16
22
|
const BUTTON_TONE: Readonly<Record<ActionTone, string>> = Object.freeze({
|
|
17
23
|
primary: 'border-0 bg-primary text-primary-fg hover:opacity-90',
|
|
18
24
|
danger: 'border-0 bg-danger text-danger-fg hover:opacity-90',
|
|
19
|
-
neutral: 'border border-
|
|
25
|
+
neutral: 'border border-button-edge bg-surface text-fg state-layer',
|
|
20
26
|
});
|
|
21
27
|
const BUTTON_DISABLED = 'opacity-60 cursor-not-allowed';
|
|
22
28
|
const MESSAGE_CLASS = 'm-0 whitespace-pre-line text-sm text-fg';
|
|
23
29
|
const IMPACT_CLASS = 'm-0 whitespace-pre-line text-xs text-fg-muted';
|
|
24
30
|
const PROMPT_CLASS = 'm-0 text-xs text-fg-muted';
|
|
25
|
-
const INPUT_CLASS = 'h-
|
|
31
|
+
const INPUT_CLASS = 'h-8 w-full rounded-md border border-border bg-surface px-3 text-sm text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
26
32
|
|
|
27
33
|
export const KIT_CONFIRM_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
28
34
|
BUTTON_BASE, Object.values(BUTTON_TONE), BUTTON_DISABLED, MESSAGE_CLASS, IMPACT_CLASS, PROMPT_CLASS, INPUT_CLASS, BUTTON_CLASS_TOKENS, KIT_MODAL_CLASS_CANDIDATES,
|
|
35
|
+
KIT_CHECK_CLASS_CANDIDATES,
|
|
29
36
|
);
|
|
30
37
|
|
|
31
38
|
export interface KitConfirmOptions {
|
|
@@ -39,25 +46,37 @@ export interface KitConfirmOptions {
|
|
|
39
46
|
tone?: Extract<ActionTone, 'primary' | 'danger'>;
|
|
40
47
|
confirmLabel?: string;
|
|
41
48
|
cancelLabel?: string;
|
|
42
|
-
/**
|
|
49
|
+
/** 要求键入的短语(一致才可确认;判据同 core 的 confirmSatisfied:首尾空白忽略、区分大小写) */
|
|
43
50
|
typedPhrase?: string;
|
|
51
|
+
/** consent 级:确认前必须先勾选「已知晓影响并同意」(确认钮在勾选前 aria-disabled;影响说明走 impact) */
|
|
52
|
+
consent?: boolean;
|
|
44
53
|
/** 只有「确定」钮(取代 alert) */
|
|
45
54
|
alertOnly?: boolean;
|
|
46
55
|
/** 调用方元素:取页面语言与书写方向,也是回焦参照 */
|
|
47
56
|
at?: Element | null;
|
|
48
57
|
/** 没有 DOM 时的结果,缺省 false */
|
|
49
58
|
whenNoDom?: boolean;
|
|
59
|
+
/** 调用方卸载 / 作废时中止:已中止直接 resolve(false);打开后中止就关闭对话框并 resolve(false)(确认框不会在调用方卸载后变成孤儿) */
|
|
60
|
+
signal?: AbortSignal;
|
|
50
61
|
}
|
|
51
62
|
|
|
52
63
|
function btn(doc: Document, tone: ActionTone, label: string): HTMLButtonElement {
|
|
53
64
|
const b = doc.createElement('button');
|
|
54
65
|
b.type = 'button';
|
|
55
66
|
b.className = `${BUTTON_BASE} ${BUTTON_TONE[tone]}`;
|
|
67
|
+
setKitFace(b, 'raised');
|
|
56
68
|
b.textContent = label;
|
|
57
69
|
return b;
|
|
58
70
|
}
|
|
59
71
|
|
|
72
|
+
/** 命令式对话框共用的按钮 / 输入框(askKitPrompt 复用同一份外观,不另写一套) */
|
|
73
|
+
export const kitDialogButton = btn;
|
|
74
|
+
export const KIT_DIALOG_INPUT_CLASS = INPUT_CLASS;
|
|
75
|
+
export const KIT_DIALOG_MESSAGE_CLASS = MESSAGE_CLASS;
|
|
76
|
+
export const KIT_DIALOG_HINT_CLASS = PROMPT_CLASS;
|
|
77
|
+
|
|
60
78
|
export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
79
|
+
if (opts.signal?.aborted === true) return Promise.resolve(false);
|
|
61
80
|
if (typeof document === 'undefined' || document.body === null) return Promise.resolve(opts.whenNoDom === true);
|
|
62
81
|
const doc = opts.at?.ownerDocument ?? document;
|
|
63
82
|
return new Promise<boolean>((resolve) => {
|
|
@@ -78,19 +97,31 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
78
97
|
settled = true;
|
|
79
98
|
watch?.disconnect();
|
|
80
99
|
watch = null;
|
|
100
|
+
opts.signal?.removeEventListener('abort', onAbort);
|
|
81
101
|
modal.close();
|
|
82
102
|
modal.destroy();
|
|
83
103
|
resolve(ok);
|
|
84
104
|
};
|
|
105
|
+
const onAbort = (): void => finish(false);
|
|
85
106
|
|
|
86
107
|
const msg = doc.createElement('p');
|
|
87
108
|
msg.className = MESSAGE_CLASS;
|
|
88
109
|
msg.textContent = opts.message;
|
|
110
|
+
msg.id = nextUid('kit-confirm-msg');
|
|
89
111
|
modal.body.appendChild(msg);
|
|
112
|
+
// 无障碍:确认框是 alertdialog(要求用户回应),可访问名 = 标题,描述 = 正文;壳由 mountKitModal 画成 dialog,这里改角色
|
|
113
|
+
const panel = modal.body.parentElement;
|
|
114
|
+
if (panel !== null) {
|
|
115
|
+
panel.setAttribute('role', 'alertdialog');
|
|
116
|
+
panel.setAttribute('aria-describedby', msg.id);
|
|
117
|
+
}
|
|
118
|
+
let impactId = '';
|
|
90
119
|
if (opts.impact !== undefined && opts.impact !== '') {
|
|
91
120
|
const impact = doc.createElement('p');
|
|
92
121
|
impact.className = IMPACT_CLASS;
|
|
93
122
|
impact.textContent = opts.impact;
|
|
123
|
+
impact.id = nextUid('kit-confirm-impact');
|
|
124
|
+
impactId = impact.id;
|
|
94
125
|
modal.body.appendChild(impact);
|
|
95
126
|
}
|
|
96
127
|
|
|
@@ -99,29 +130,59 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
99
130
|
const ok = btn(doc, opts.alertOnly === true ? 'primary' : tone, okLabel);
|
|
100
131
|
let cancel: HTMLButtonElement | null = null;
|
|
101
132
|
let input: HTMLInputElement | null = null;
|
|
133
|
+
let consentBox: HTMLInputElement | null = null;
|
|
134
|
+
|
|
135
|
+
// 确认钮此刻能不能点的判据只有 core 的 confirmSatisfied / confirmKeyAccepts(typed 逐字相等、consent 已勾选)
|
|
136
|
+
const gate: SomaConfirmSpec | null = opts.alertOnly === true ? null
|
|
137
|
+
: opts.typedPhrase !== undefined && opts.typedPhrase !== '' ? { level: 'typed', text: opts.message, phrase: opts.typedPhrase }
|
|
138
|
+
: opts.consent === true ? { level: 'consent', text: opts.message, impact: opts.impact ?? '' }
|
|
139
|
+
: null;
|
|
140
|
+
const gateInput = (): { typed: string; consented: boolean } => ({ typed: input?.value ?? '', consented: consentBox?.checked === true });
|
|
141
|
+
// 未满足:确认钮置灰并标 aria-disabled(原生 disabled 同写,点击 / Enter 都不放行)
|
|
142
|
+
const sync = (): void => {
|
|
143
|
+
if (gate === null) return;
|
|
144
|
+
const met = confirmSatisfied(gate, gateInput());
|
|
145
|
+
ok.disabled = !met;
|
|
146
|
+
if (met) ok.removeAttribute('aria-disabled');
|
|
147
|
+
else ok.setAttribute('aria-disabled', 'true');
|
|
148
|
+
ok.className = `${BUTTON_BASE} ${BUTTON_TONE[tone]}${met ? '' : ` ${BUTTON_DISABLED}`}`;
|
|
149
|
+
};
|
|
150
|
+
const onGateKey = (e: KeyboardEvent): void => {
|
|
151
|
+
if (gate !== null && confirmKeyAccepts(e, gate, gateInput())) { e.preventDefault(); finish(true); }
|
|
152
|
+
};
|
|
102
153
|
|
|
103
|
-
if (
|
|
104
|
-
const phrase =
|
|
154
|
+
if (gate?.level === 'typed') {
|
|
155
|
+
const phrase = gate.phrase ?? '';
|
|
105
156
|
const hint = doc.createElement('p');
|
|
106
157
|
hint.className = PROMPT_CLASS;
|
|
107
158
|
hint.textContent = kitText('soma.kit.typed_confirm', { phrase }, opts.at);
|
|
108
159
|
input = doc.createElement('input');
|
|
109
160
|
input.type = 'text';
|
|
110
161
|
input.className = INPUT_CLASS;
|
|
162
|
+
setKitFace(input, 'field');
|
|
111
163
|
input.setAttribute('aria-label', hint.textContent);
|
|
164
|
+
if (impactId !== '') input.setAttribute('aria-describedby', impactId);
|
|
112
165
|
input.autocomplete = 'off';
|
|
113
|
-
const sync = (): void => {
|
|
114
|
-
const match = input!.value === phrase;
|
|
115
|
-
ok.disabled = !match;
|
|
116
|
-
ok.className = `${BUTTON_BASE} ${BUTTON_TONE[tone]}${match ? '' : ` ${BUTTON_DISABLED}`}`;
|
|
117
|
-
};
|
|
118
166
|
input.addEventListener('input', sync);
|
|
119
|
-
input.addEventListener('keydown',
|
|
120
|
-
if (e.key === 'Enter' && input!.value === phrase) { e.preventDefault(); finish(true); }
|
|
121
|
-
});
|
|
167
|
+
input.addEventListener('keydown', onGateKey);
|
|
122
168
|
modal.body.append(hint, input);
|
|
123
|
-
|
|
169
|
+
} else if (gate?.level === 'consent') {
|
|
170
|
+
// 勾选框用 kit 的 check-core(原生 input 作行为载体:Space 切换、读屏语义);文案是固定词条,影响说明在上面的段落里
|
|
171
|
+
const mark = createCheck(doc, 'checkbox', { checked: false });
|
|
172
|
+
consentBox = markInput(mark);
|
|
173
|
+
const ack = doc.createElement('span');
|
|
174
|
+
ack.className = MESSAGE_CLASS;
|
|
175
|
+
ack.textContent = kitText('soma.kit.consent_ack', undefined, opts.at);
|
|
176
|
+
mark.appendChild(ack);
|
|
177
|
+
if (consentBox !== null) {
|
|
178
|
+
setMarkLabel(mark, ack.textContent);
|
|
179
|
+
if (impactId !== '') consentBox.setAttribute('aria-describedby', impactId);
|
|
180
|
+
consentBox.addEventListener('change', sync);
|
|
181
|
+
consentBox.addEventListener('keydown', onGateKey);
|
|
182
|
+
}
|
|
183
|
+
modal.body.appendChild(mark);
|
|
124
184
|
}
|
|
185
|
+
sync();
|
|
125
186
|
|
|
126
187
|
if (opts.alertOnly !== true) {
|
|
127
188
|
cancel = btn(doc, 'neutral', opts.cancelLabel ?? kitText('soma.kit.cancel', undefined, opts.at));
|
|
@@ -138,7 +199,9 @@ export function askKitConfirm(opts: KitConfirmOptions): Promise<boolean> {
|
|
|
138
199
|
watch = new MutationObserver(() => { if (!modal.layer.isConnected) finish(false); });
|
|
139
200
|
watch.observe(doc.body, { childList: true, subtree: true });
|
|
140
201
|
}
|
|
141
|
-
//
|
|
142
|
-
(
|
|
202
|
+
// 调用方中止(如协调组件卸载):按取消收口,对话框随之关闭
|
|
203
|
+
opts.signal?.addEventListener('abort', onAbort, { once: true });
|
|
204
|
+
// 焦点:键入式 → 输入框;危险 / 要先勾选同意 → 取消钮(安全钮,误按回车不会执行);其余 → 确认钮
|
|
205
|
+
(input ?? ((tone === 'danger' || consentBox !== null) && cancel !== null ? cancel : ok)).focus();
|
|
143
206
|
});
|
|
144
207
|
}
|
package/src/data/context-menu.ts
CHANGED
|
@@ -11,19 +11,19 @@
|
|
|
11
11
|
//
|
|
12
12
|
// 菜单内容复用 base/menu-core 的 wireMenu(键盘、焦点回收、点外部关闭,Esc 只关栈顶);按落点经 showAtPoint 挂浮层
|
|
13
13
|
// (portal-core 的 placeAtPoint 是唯一 CSSOM 写点,见 kit-grammar.json#cssomWrites);浮层端口缺失 → 退回就地绝对定位(不写 CSSOM)。
|
|
14
|
-
//
|
|
14
|
+
// 菜单项点击抛槽位事件 `row_action_<序号>`,载荷与 KitTableActions 完全一致(带整行),页面 `_event` 给每个菜单项各绑一条管道,组件不直连数据写入。
|
|
15
15
|
// 条件显隐 `when`、权限 `permission` 沿用行操作;危险项(tone: danger)红字;`confirm` 尾段在 `_event` 管道里,沿用。
|
|
16
16
|
|
|
17
|
-
import type { SomaComponentDefinition
|
|
17
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
18
18
|
import { classCandidates, createKitController, str } from '../base/shared';
|
|
19
19
|
import { permissionCheckerOf } from '../base/permission-gate';
|
|
20
20
|
import { wireMenu, type MenuHandle, type MenuItemSpec } from '../base/menu-core';
|
|
21
21
|
import {
|
|
22
22
|
CONTEXT_POINT_PANEL, CONTEXT_SHOWN, KIT_CONTEXT_MENU_CLASS_CANDIDATES, wireContextTrigger, type Corner,
|
|
23
23
|
} from '../base/context-menu';
|
|
24
|
-
import { holds } from '../object-renderer/linkage';
|
|
25
|
-
import { evalActionGate, gateOutcomeReader, gateRowKey } from '../base/action-gate';
|
|
26
24
|
import { MORE_MENU_CLASSES, emitRowAction, itemsOf } from '../object-renderer/table-actions';
|
|
25
|
+
import { disabledReasonOf, rowActionState } from '../object-renderer/view-binding';
|
|
26
|
+
import { KIT_ACTION_SLOT_BASE, actionSlotEmits } from '../base/action-slots';
|
|
27
27
|
|
|
28
28
|
const ROOT_CLASS = 'absolute size-0';
|
|
29
29
|
const MENU_HIDDEN = 'hidden';
|
|
@@ -64,32 +64,30 @@ export function createKitContextMenu(): SomaComponentDefinition {
|
|
|
64
64
|
name: 'KitContextMenu',
|
|
65
65
|
layer: 'data',
|
|
66
66
|
props: {
|
|
67
|
-
menu: { type: 'array', default: [], desc: '菜单项 [{ id, name, tone?, builtin?, target?, permission
|
|
67
|
+
menu: { type: 'array', default: [], desc: '菜单项 [{ id, name, tone?, builtin?, target?, permission? }],即 behavior.actions 里被 contextMenu 引用的动作;无权限的项不显示,全部不显示时不拦截系统菜单' },
|
|
68
|
+
actionState: { type: 'object', default: {}, desc: '行级动作状态 { 动作id: { hidden, disabled, disabledReason? } }(仅 mode: row):叶子是行字段路径,core 逐行求值;hidden 为真该行菜单不含此项,disabled 为真置灰且点不到;disabledReason(可选)是置灰原因文案,置灰项里多一段描述文字(aria-describedby);字面量原因写在 menu 项的 disabledReason' },
|
|
68
69
|
row: { type: 'object', default: {}, desc: '行实例的当前行数据,原样随 row_action 上抛' },
|
|
69
70
|
rows: { type: 'array', default: [], desc: 'mode: virtual 时的行数组(与 KitVirtualRows 同源,按 data-kit-index 取行)' },
|
|
70
71
|
mode: { type: 'string', default: 'row', desc: 'row(行实例,监听 [data-kit-ctx])、virtual(监听 [data-kit-vscroll],按下标取行)或 host(监听 [data-kit-ctxhost] 宿主壳,按行主键经组件登记的取行函数取行)' },
|
|
71
72
|
long_press: { type: 'boolean', default: true, desc: '触屏长按 500ms 打开' },
|
|
72
73
|
},
|
|
73
74
|
emits: {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
desc: '点击某个菜单项;载荷自带整行,与行操作同形',
|
|
84
|
-
},
|
|
75
|
+
...actionSlotEmits(KIT_ACTION_SLOT_BASE.row, {
|
|
76
|
+
kit_action: { type: 'string', desc: '动作判别键(同 KitTableActions)' },
|
|
77
|
+
id: { type: 'string', desc: '动作 id' },
|
|
78
|
+
name: { type: 'string', desc: '动作显示名' },
|
|
79
|
+
builtin: { type: 'string', desc: '内置动作名' },
|
|
80
|
+
target: { type: 'string', desc: '目标浮层' },
|
|
81
|
+
row: { type: 'object', desc: '当前行' },
|
|
82
|
+
}, '点击某个菜单项;载荷自带整行,与行操作同形,序号 = 该动作在 menu 数组里的位置'),
|
|
85
83
|
},
|
|
86
84
|
},
|
|
87
|
-
services: ['permission'
|
|
85
|
+
services: ['permission'],
|
|
88
86
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
89
|
-
controllerFactory: (
|
|
90
|
-
const check = permissionCheckerOf(
|
|
91
|
-
return
|
|
92
|
-
attach(root
|
|
87
|
+
controllerFactory: createKitController((api) => {
|
|
88
|
+
const check = permissionCheckerOf(api as unknown as any);
|
|
89
|
+
return {
|
|
90
|
+
attach(root) {
|
|
93
91
|
const modeName = str(api.props().mode, 'row');
|
|
94
92
|
const virtual = modeName === 'virtual';
|
|
95
93
|
const hosted = modeName === 'host';
|
|
@@ -121,19 +119,11 @@ export function createKitContextMenu(): SomaComponentDefinition {
|
|
|
121
119
|
return row === undefined ? null : { row, el };
|
|
122
120
|
};
|
|
123
121
|
|
|
124
|
-
/**
|
|
125
|
-
const visibleActions = (): ReturnType<typeof itemsOf> =>
|
|
126
|
-
|
|
127
|
-
const port = (ctx.services as { data?: SomaDataPort } | undefined)?.data;
|
|
128
|
-
return itemsOf(api.props().menu).filter((a) =>
|
|
129
|
-
!(a.permission !== undefined && check !== null && !check(a.permission)) && holds(a.when, row)
|
|
130
|
-
&& !evalActionGate(a.gate, row, gateOutcomeReader(port, gateRowKey(a.gateKey, row))).hidden);
|
|
131
|
-
};
|
|
132
|
-
// GA2:菜单每次打开才画,打开那一刻读最新的写入结果即可(不需要订阅)
|
|
133
|
-
const gateDisabled = (a: ReturnType<typeof itemsOf>[number]): boolean =>
|
|
134
|
-
evalActionGate(a.gate, current?.row ?? {}, gateOutcomeReader((ctx.services as { data?: SomaDataPort } | undefined)?.data, gateRowKey(a.gateKey, current?.row))).disabled;
|
|
122
|
+
/** 当前命中行下可见的动作(权限) */
|
|
123
|
+
const visibleActions = (): ReturnType<typeof itemsOf> =>
|
|
124
|
+
itemsOf(api.props().menu).filter((a) => !(a.permission !== undefined && check !== null && !check(a.permission)) && !rowActionState(api.props().actionState, a.id).hidden);
|
|
135
125
|
const specs = (): MenuItemSpec[] =>
|
|
136
|
-
visibleActions().map((a) => ({ key: a.id, label: a.name, icon: '', disabled:
|
|
126
|
+
visibleActions().map((a) => ({ key: a.id, label: a.name, icon: '', disabled: rowActionState(api.props().actionState, a.id).disabled, danger: a.tone === 'danger', divider: false, reason: disabledReasonOf(api.props().actionState, a) }));
|
|
137
127
|
|
|
138
128
|
const ensure = (): MenuHandle => {
|
|
139
129
|
if (handle !== null) return handle;
|
|
@@ -158,9 +148,11 @@ export function createKitContextMenu(): SomaComponentDefinition {
|
|
|
158
148
|
locked: () => false,
|
|
159
149
|
clickOpens: () => false,
|
|
160
150
|
onPick: (item) => {
|
|
161
|
-
const hit = visibleActions().find((a) => a.id === item.key);
|
|
151
|
+
const hit = visibleActions().find((a) => a.id === item.key && !rowActionState(api.props().actionState, a.id).disabled);
|
|
162
152
|
const picked = current;
|
|
163
|
-
if (hit !== undefined && picked !== null
|
|
153
|
+
if (hit !== undefined && picked !== null) {
|
|
154
|
+
emitRowAction({ emit: (n, p) => api.emit(n, p), props: () => ({ row: picked.row }) }, hit, itemsOf(api.props().menu).findIndex((a) => a.id === hit.id));
|
|
155
|
+
}
|
|
164
156
|
},
|
|
165
157
|
onToggle: (open) => {
|
|
166
158
|
if (open || current === null) return;
|
|
@@ -210,7 +202,7 @@ export function createKitContextMenu(): SomaComponentDefinition {
|
|
|
210
202
|
render(root) {
|
|
211
203
|
root.className = ROOT_CLASS;
|
|
212
204
|
},
|
|
213
|
-
}
|
|
214
|
-
},
|
|
205
|
+
};
|
|
206
|
+
}),
|
|
215
207
|
};
|
|
216
208
|
}
|
package/src/data/d9-util.ts
CHANGED
|
@@ -51,24 +51,8 @@ export function avatarNode(name: string, src: unknown, size: AvatarSize = 'md'):
|
|
|
51
51
|
|
|
52
52
|
// ── 焦点 ─────────────────────────────────────────────────────
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export function focusablesIn(el: HTMLElement): HTMLElement[] {
|
|
57
|
-
return [...el.querySelectorAll<HTMLElement>(FOCUSABLE)].filter((n) => !n.hasAttribute('hidden'));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Tab 在容器内循环(对话框式浮层的焦点隔离);返回 true = 已处理 */
|
|
61
|
-
export function trapTab(event: KeyboardEvent, container: HTMLElement): boolean {
|
|
62
|
-
if (event.key !== 'Tab') return false;
|
|
63
|
-
const list = focusablesIn(container);
|
|
64
|
-
if (list.length === 0) { event.preventDefault(); container.focus(); return true; }
|
|
65
|
-
const first = list[0]!;
|
|
66
|
-
const last = list[list.length - 1]!;
|
|
67
|
-
const active = document.activeElement;
|
|
68
|
-
if (event.shiftKey && (active === first || !container.contains(active))) { event.preventDefault(); last.focus(); return true; }
|
|
69
|
-
if (!event.shiftKey && (active === last || !container.contains(active))) { event.preventDefault(); first.focus(); return true; }
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
54
|
+
export { focusablesIn, trapTab } from '../base/popup';
|
|
55
|
+
import { focusablesIn, trapTab } from '../base/popup';
|
|
72
56
|
|
|
73
57
|
/** 给 id 里的特殊字符转义,拼进属性选择器 */
|
|
74
58
|
export function attrEsc(value: string): string {
|
package/src/data/diff.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
11
11
|
import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
12
12
|
import { kitText } from '../i18n/kit-text';
|
|
13
|
+
import { setKitFace } from '../recipes';
|
|
13
14
|
import { createKitController, joinClass, str } from '../base/shared';
|
|
14
15
|
import { classTokens, mk, recOf, textOf, type Rec } from './shape-util';
|
|
15
16
|
import { clampInt, singleOf, urlOf } from './display-util';
|
|
@@ -135,7 +136,7 @@ export function createDiff(): SomaComponentDefinition {
|
|
|
135
136
|
},
|
|
136
137
|
},
|
|
137
138
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
138
|
-
controllerFactory: createKitController({
|
|
139
|
+
controllerFactory: createKitController(() => ({
|
|
139
140
|
attach(root, api) {
|
|
140
141
|
const s = stateOf(root);
|
|
141
142
|
const setStep = (next: number): void => {
|
|
@@ -227,6 +228,7 @@ export function createDiff(): SomaComponentDefinition {
|
|
|
227
228
|
handle.appendChild(mk('span', LINE_CLASS));
|
|
228
229
|
const knob = mk('span', KNOB_CLASS, '⇆');
|
|
229
230
|
knob.setAttribute('aria-hidden', 'true');
|
|
231
|
+
setKitFace(knob, 'raised'); // 实心把手有 shadow-md,质感经合成槽叠进去
|
|
230
232
|
handle.appendChild(knob);
|
|
231
233
|
root.appendChild(under);
|
|
232
234
|
root.appendChild(box);
|
|
@@ -234,6 +236,6 @@ export function createDiff(): SomaComponentDefinition {
|
|
|
234
236
|
}
|
|
235
237
|
applyStep(root, s.step);
|
|
236
238
|
},
|
|
237
|
-
}),
|
|
239
|
+
})),
|
|
238
240
|
};
|
|
239
241
|
}
|
package/src/data/dock.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { classTokens, mk, textOf, type Rec } from './shape-util';
|
|
|
13
13
|
import { keyOfRow, listOf, rovingTabIndex, wireRovingRow } from './display-util';
|
|
14
14
|
|
|
15
15
|
const ROOT_CLASS = 'flex items-stretch justify-around gap-1 rounded-lg border border-border-subtle bg-surface p-1 shadow-sm';
|
|
16
|
-
const ITEM_CLASS = 'relative flex min-w-14 flex-1 flex-col items-center justify-center gap-0.5 rounded-md px-2 py-1.5 text-xs text-fg-muted transition-colors hover:bg-
|
|
16
|
+
const ITEM_CLASS = 'relative flex min-w-14 flex-1 flex-col items-center justify-center gap-0.5 rounded-md px-2 py-1.5 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60 data-kit-selected:bg-primary-soft data-kit-selected:text-primary-on-soft';
|
|
17
17
|
const ICON_CLASS = 'text-lg';
|
|
18
18
|
const LABEL_CLASS = 'font-medium';
|
|
19
19
|
const BADGE_CLASS = 'absolute end-2 top-0.5 inline-flex min-w-4 items-center justify-center rounded-full bg-danger px-1 text-xs font-medium text-danger-fg';
|
|
@@ -101,7 +101,7 @@ export function createDock(): SomaComponentDefinition {
|
|
|
101
101
|
keyboard: { layout: 'list', orientation: 'horizontal', wrap: true, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
102
102
|
},
|
|
103
103
|
templateHtml: `<nav data-soma-id="root" class="${ROOT_CLASS}"></nav>`,
|
|
104
|
-
controllerFactory: createKitController({
|
|
104
|
+
controllerFactory: createKitController(() => ({
|
|
105
105
|
attach(root, api) {
|
|
106
106
|
const s = stateOf(root);
|
|
107
107
|
const off = wireRovingRow(root, {
|
|
@@ -147,6 +147,6 @@ export function createDock(): SomaComponentDefinition {
|
|
|
147
147
|
}
|
|
148
148
|
paintSelected(root, s.selected);
|
|
149
149
|
},
|
|
150
|
-
}),
|
|
150
|
+
})),
|
|
151
151
|
};
|
|
152
152
|
}
|