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/kanban.ts
CHANGED
|
@@ -24,9 +24,12 @@
|
|
|
24
24
|
// 与 `change { value }`(value 为移动后的全部行,供 view.value 写回)。
|
|
25
25
|
// 点卡片抛 `select { id, item }`。data 内容变化(内容签名变)才重置本地顺序。
|
|
26
26
|
|
|
27
|
-
import type {
|
|
28
|
-
import { bool,
|
|
29
|
-
import { kitText } from '../i18n/kit-text';
|
|
27
|
+
import type { SomaComponentDefinition, SomaDataPort } from 'soma-core';
|
|
28
|
+
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
29
|
+
import { kitKey, kitText } from '../i18n/kit-text';
|
|
30
|
+
import { createKeyboardWiring } from 'soma-core/keyboard';
|
|
31
|
+
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
32
|
+
import { setKitFace } from '../recipes';
|
|
30
33
|
import { provideCtxRows } from './context-menu';
|
|
31
34
|
|
|
32
35
|
// ───────── 样式常量:Tailwind 类串与候选类清单 ─────────
|
|
@@ -40,15 +43,15 @@ const COUNT_CLASS = 'text-fg-muted';
|
|
|
40
43
|
const COUNT_OVER_CLASS = 'font-medium text-danger-on-soft';
|
|
41
44
|
const LANE_BODY_CLASS = 'flex min-h-16 flex-col gap-2 rounded-md';
|
|
42
45
|
const DROP_CLASS = 'ring-2 ring-inset ring-ring';
|
|
43
|
-
const CARD_CLASS = 'flex flex-col gap-1 rounded-lg border border-border-subtle bg-surface p-3 text-sm text-fg shadow-xs transition-colors
|
|
46
|
+
const CARD_CLASS = 'flex flex-col gap-1 rounded-lg border border-border-subtle bg-surface p-3 text-sm text-fg shadow-xs transition-colors state-layer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
44
47
|
const CARD_DRAG_CLASS = 'cursor-grab active:cursor-grabbing';
|
|
45
48
|
const CARD_TITLE_CLASS = 'font-medium text-fg';
|
|
46
49
|
const FACT_CLASS = 'flex items-baseline justify-between gap-2 text-xs text-fg-muted';
|
|
47
50
|
const FACT_VALUE_CLASS = 'truncate text-fg';
|
|
48
51
|
const EMPTY_CLASS = 'px-2 py-3 text-center text-sm text-fg-muted';
|
|
49
|
-
const MOVE_BTN_CLASS = 'inline-flex h-7 items-center self-start rounded-md border border-
|
|
52
|
+
const MOVE_BTN_CLASS = 'inline-flex h-7 items-center self-start rounded-md border border-button-edge bg-surface px-4 text-xs text-fg state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
50
53
|
const MENU_CLASS = 'flex flex-col gap-1 rounded-md border border-border bg-surface p-1';
|
|
51
|
-
const MENU_ITEM_CLASS = 'flex h-7 items-center rounded-md px-2 text-start text-xs text-fg hover:bg-
|
|
54
|
+
const MENU_ITEM_CLASS = 'flex h-7 items-center rounded-md px-2 text-start text-xs text-fg hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:text-fg-subtle';
|
|
52
55
|
const NOTICE_CLASS = 'rounded-md border border-border-subtle bg-warning-soft px-3 py-1.5 text-xs text-warning-on-soft';
|
|
53
56
|
const HIDDEN_CLASS = 'hidden';
|
|
54
57
|
const LIVE_CLASS = 'sr-only';
|
|
@@ -192,8 +195,8 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
192
195
|
},
|
|
193
196
|
services: ['engines', 'data', 'notify'],
|
|
194
197
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
195
|
-
controllerFactory: (
|
|
196
|
-
const P = (): Record<string, unknown> =>
|
|
198
|
+
controllerFactory: createKitController((api) => {
|
|
199
|
+
const P = (): Record<string, unknown> => api.props();
|
|
197
200
|
const uid = `kit-kanban-${++instanceCount}`;
|
|
198
201
|
let root: HTMLElement | null = null;
|
|
199
202
|
let noticeEl: HTMLElement | null = null;
|
|
@@ -217,11 +220,11 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
217
220
|
let armTimer: ReturnType<typeof setTimeout> | null = null;
|
|
218
221
|
let offOutcome: (() => void) | null = null;
|
|
219
222
|
const dataPort = (): SomaDataPort | undefined => {
|
|
220
|
-
const port = (
|
|
223
|
+
const port = (api.services as { data?: SomaDataPort } | undefined)?.data;
|
|
221
224
|
return port && typeof port === 'object' ? port : undefined;
|
|
222
225
|
};
|
|
223
226
|
const notifyPort = (): { toast?: (o: { level: string; message: string }) => void } | undefined =>
|
|
224
|
-
(
|
|
227
|
+
(api.services as { notify?: { toast?: (o: { level: string; message: string }) => void } } | undefined)?.notify;
|
|
225
228
|
|
|
226
229
|
const config = (): KitKanbanConfig => {
|
|
227
230
|
const p = P();
|
|
@@ -232,7 +235,7 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
232
235
|
const softWip = (): boolean => str(P().wip_mode) === 'soft';
|
|
233
236
|
const idOf = (r: Row): string => str(r[idField()]);
|
|
234
237
|
const dndPort = (): DragPortLike | null => {
|
|
235
|
-
const engines = (
|
|
238
|
+
const engines = (api.services as { engines?: { dnd?: DragPortLike } } | undefined)?.engines;
|
|
236
239
|
return engines?.dnd ?? null;
|
|
237
240
|
};
|
|
238
241
|
|
|
@@ -263,12 +266,12 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
263
266
|
const restore = first !== undefined && snapEpoch === epoch;
|
|
264
267
|
clearTrack();
|
|
265
268
|
const reason = message !== '' ? message
|
|
266
|
-
: kitText(conflict ? 'soma.kit.order_unsaved_conflict' : 'soma.kit.order_unsaved_unknown', undefined,
|
|
267
|
-
const text = kitText('soma.kit.order_unsaved', { reason },
|
|
269
|
+
: kitText(conflict ? 'soma.kit.order_unsaved_conflict' : 'soma.kit.order_unsaved_unknown', undefined, api.host);
|
|
270
|
+
const text = kitText('soma.kit.order_unsaved', { reason }, api.host);
|
|
268
271
|
if (restore && first !== undefined) {
|
|
269
272
|
rows = first.map((r) => ({ ...r }));
|
|
270
273
|
menuFor = null;
|
|
271
|
-
|
|
274
|
+
api.emit('change', { value: rows.map((r) => ({ ...r })) });
|
|
272
275
|
}
|
|
273
276
|
showNotice(text);
|
|
274
277
|
announce(text);
|
|
@@ -339,17 +342,17 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
339
342
|
if (from !== to && limit !== undefined && laneRows(cfg, to).length >= limit) {
|
|
340
343
|
const laneLabel = cfg.lanes.find((l) => l.value === to)?.label ?? to;
|
|
341
344
|
if (!softWip()) {
|
|
342
|
-
const msg = kitText('soma.kit.wip_limit', { lane: laneLabel, n: limit },
|
|
345
|
+
const msg = kitText('soma.kit.wip_limit', { lane: laneLabel, n: limit }, api.host);
|
|
343
346
|
announce(msg);
|
|
344
347
|
showNotice(msg);
|
|
345
|
-
|
|
348
|
+
api.emit('wip_blocked', { id, to, limit });
|
|
346
349
|
return false;
|
|
347
350
|
}
|
|
348
351
|
// 软上限:只提示与抛事件,移入照常进行(超限的计数由 paint 标红)
|
|
349
|
-
const msg = kitText('soma.kit.wip_exceeded', { lane: laneLabel, n: limit },
|
|
352
|
+
const msg = kitText('soma.kit.wip_exceeded', { lane: laneLabel, n: limit }, api.host);
|
|
350
353
|
announce(msg);
|
|
351
354
|
showNotice(msg);
|
|
352
|
-
|
|
355
|
+
api.emit('wip_exceeded', { id, to, limit });
|
|
353
356
|
}
|
|
354
357
|
const peers = laneRows(cfg, to).filter((r) => idOf(r) !== id);
|
|
355
358
|
const position = Math.max(0, Math.min(index, peers.length));
|
|
@@ -367,7 +370,7 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
367
370
|
menuFor = null;
|
|
368
371
|
tabKey = id;
|
|
369
372
|
pendingFocus = id;
|
|
370
|
-
|
|
373
|
+
api.emit('move', {
|
|
371
374
|
id, from, to, index: position,
|
|
372
375
|
target: id,
|
|
373
376
|
...(orderField !== '' ? { orderField } : {}),
|
|
@@ -375,9 +378,9 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
375
378
|
set: { [cfg.group]: to },
|
|
376
379
|
object: str(P().object),
|
|
377
380
|
});
|
|
378
|
-
|
|
381
|
+
api.emit('change', { value: rows.map((r) => ({ ...r })) });
|
|
379
382
|
showNotice('');
|
|
380
|
-
announce(kitText('soma.kit.moved_to', { lane: cfg.lanes.find((l) => l.value === to)?.label ?? to, n: position + 1 },
|
|
383
|
+
announce(kitText('soma.kit.moved_to', { lane: cfg.lanes.find((l) => l.value === to)?.label ?? to, n: position + 1 }, api.host));
|
|
381
384
|
paint();
|
|
382
385
|
return true;
|
|
383
386
|
};
|
|
@@ -410,9 +413,11 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
410
413
|
line.appendChild(el('span', FACT_VALUE_CLASS, str(v)));
|
|
411
414
|
card.appendChild(line);
|
|
412
415
|
}
|
|
413
|
-
|
|
414
|
-
|
|
416
|
+
// 移动菜单始终提供(WCAG 2.5.7:拖放之外必须有单指针替代;有拖放端口时也不隐藏)
|
|
417
|
+
if (!locked()) {
|
|
418
|
+
const btn = el('button', MOVE_BTN_CLASS, str(P().move_label) || kitText('soma.kit.move_to', undefined, api.host));
|
|
415
419
|
btn.type = 'button';
|
|
420
|
+
setKitFace(btn, 'raised');
|
|
416
421
|
btn.setAttribute('data-kit-move', id);
|
|
417
422
|
btn.setAttribute('aria-haspopup', 'menu');
|
|
418
423
|
btn.setAttribute('aria-expanded', menuFor === id ? 'true' : 'false');
|
|
@@ -451,7 +456,7 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
451
456
|
const cfg = config();
|
|
452
457
|
const port = dndPort();
|
|
453
458
|
const hasDnd = port !== null;
|
|
454
|
-
const emptyText = str(p.empty_text, kitText('soma.kit.empty_card', undefined,
|
|
459
|
+
const emptyText = str(p.empty_text, kitText('soma.kit.empty_card', undefined, api.host));
|
|
455
460
|
const keys = cardKeys(cfg);
|
|
456
461
|
const all = keys.flat();
|
|
457
462
|
if (tabKey === null || !all.includes(tabKey)) tabKey = all[0] ?? null;
|
|
@@ -525,6 +530,22 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
525
530
|
[...board.querySelectorAll<HTMLElement>('[data-kit-key]')].find((n) => n.getAttribute('data-kit-key') === id)?.focus();
|
|
526
531
|
};
|
|
527
532
|
|
|
533
|
+
// 泳道内的纵向导航走 core 的共享键盘接线:集合 = 当前泳道的卡(按键前由 onKeydown 填),游标 = 焦点卡
|
|
534
|
+
let wireLane: string[] = [];
|
|
535
|
+
let wireCursor: string | null = null;
|
|
536
|
+
const laneWiring = createKeyboardWiring({
|
|
537
|
+
host: () => board,
|
|
538
|
+
contract: { layout: 'list', orientation: 'vertical', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
539
|
+
typeaheadDebounceMs: 0,
|
|
540
|
+
paging: {
|
|
541
|
+
listItems: SOMA_SIZE_UNITS.collection.keyboard.pageStep.listItems,
|
|
542
|
+
gridRows: SOMA_SIZE_UNITS.collection.keyboard.pageStep.gridRows,
|
|
543
|
+
},
|
|
544
|
+
items: () => wireLane.map((k) => ({ key: k, text: k })),
|
|
545
|
+
getCursor: () => wireCursor,
|
|
546
|
+
setCursor: (k) => focusCard(k),
|
|
547
|
+
});
|
|
548
|
+
|
|
528
549
|
const onKeydown = (event: Event): void => {
|
|
529
550
|
const e = event as KeyboardEvent;
|
|
530
551
|
if (e.isComposing) return;
|
|
@@ -550,13 +571,14 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
550
571
|
if (li < 0) return;
|
|
551
572
|
const ci = keys[li]!.indexOf(id);
|
|
552
573
|
const lane = cfg.lanes[li]!.value;
|
|
553
|
-
|
|
574
|
+
// 左右键按书写方向换向(RTL 下 ← 去后一条泳道);泳道内的上下 / Home / End / 翻页走共享键盘接线
|
|
575
|
+
const key = kitKey(e.key, root);
|
|
554
576
|
if (key === 'Enter' || key === ' ') {
|
|
555
577
|
e.preventDefault();
|
|
556
|
-
|
|
578
|
+
api.emit('select', { id, item: rows.find((r) => idOf(r) === id) ?? {} });
|
|
557
579
|
return;
|
|
558
580
|
}
|
|
559
|
-
if ((key === 'm' || key === 'M') && !e.altKey && !e.ctrlKey && !e.metaKey && !
|
|
581
|
+
if ((key === 'm' || key === 'M') && !e.altKey && !e.ctrlKey && !e.metaKey && !locked()) {
|
|
560
582
|
e.preventDefault();
|
|
561
583
|
menuFor = menuFor === id ? null : id;
|
|
562
584
|
pendingFocus = menuFor === null ? id : null;
|
|
@@ -569,9 +591,9 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
569
591
|
}
|
|
570
592
|
const horizontal = key === 'ArrowLeft' ? -1 : key === 'ArrowRight' ? 1 : 0;
|
|
571
593
|
const vertical = key === 'ArrowUp' ? -1 : key === 'ArrowDown' ? 1 : 0;
|
|
572
|
-
if (horizontal === 0 && vertical === 0) return;
|
|
573
|
-
e.preventDefault();
|
|
574
594
|
if (e.altKey) {
|
|
595
|
+
if (horizontal === 0 && vertical === 0) return;
|
|
596
|
+
e.preventDefault();
|
|
575
597
|
if (horizontal !== 0) {
|
|
576
598
|
const nl = cfg.lanes[li + horizontal];
|
|
577
599
|
if (nl) move(id, nl.value, laneRows(cfg, nl.value).length);
|
|
@@ -580,7 +602,16 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
580
602
|
}
|
|
581
603
|
return;
|
|
582
604
|
}
|
|
583
|
-
if (
|
|
605
|
+
if (horizontal === 0) {
|
|
606
|
+
// 泳道内:↑ ↓ Home End PageUp PageDown 由共享接线(list / vertical,到边不回绕)决定落点,焦点经 setCursor 落到卡
|
|
607
|
+
if (e.ctrlKey || e.metaKey) return;
|
|
608
|
+
wireLane = keys[li]!;
|
|
609
|
+
wireCursor = id;
|
|
610
|
+
const handled = laneWiring.onKeydown(e);
|
|
611
|
+
if (handled || vertical !== 0) e.preventDefault();
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
e.preventDefault();
|
|
584
615
|
let nl = li + horizontal;
|
|
585
616
|
while (nl >= 0 && nl < keys.length && keys[nl]!.length === 0) nl += horizontal;
|
|
586
617
|
const col = keys[nl];
|
|
@@ -610,13 +641,13 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
610
641
|
if (cardEl) {
|
|
611
642
|
const id = cardEl.getAttribute('data-kit-key')!;
|
|
612
643
|
tabKey = id;
|
|
613
|
-
|
|
644
|
+
api.emit('select', { id, item: rows.find((r) => idOf(r) === id) ?? {} });
|
|
614
645
|
}
|
|
615
646
|
};
|
|
616
647
|
|
|
617
648
|
return {
|
|
618
|
-
|
|
619
|
-
root =
|
|
649
|
+
attach(rootEl) {
|
|
650
|
+
root = rootEl;
|
|
620
651
|
root.textContent = '';
|
|
621
652
|
noticeEl = el('div', HIDDEN_CLASS);
|
|
622
653
|
noticeEl.setAttribute('role', 'alert');
|
|
@@ -639,29 +670,28 @@ export function createKanban(): SomaComponentDefinition {
|
|
|
639
670
|
if (port) offMove = port.onMove(intentMove);
|
|
640
671
|
// 右键菜单(页面声明了 contextMenu 才有宿主壳):按卡主键取行
|
|
641
672
|
removers.push(provideCtxRows(root, (key) => rows.find((r) => idOf(r) === key)));
|
|
642
|
-
|
|
643
|
-
|
|
673
|
+
return () => {
|
|
674
|
+
for (const fn of cleanups) fn();
|
|
675
|
+
cleanups = [];
|
|
676
|
+
for (const fn of removers) fn();
|
|
677
|
+
removers = [];
|
|
678
|
+
offMove?.();
|
|
679
|
+
offMove = null;
|
|
680
|
+
offOutcome?.();
|
|
681
|
+
offOutcome = null;
|
|
682
|
+
clearTrack();
|
|
683
|
+
root = null;
|
|
684
|
+
noticeEl = null;
|
|
685
|
+
board = null;
|
|
686
|
+
live = null;
|
|
687
|
+
};
|
|
644
688
|
},
|
|
645
|
-
|
|
689
|
+
render(rootEl) {
|
|
690
|
+
root = rootEl;
|
|
646
691
|
sync();
|
|
647
692
|
paint();
|
|
648
693
|
},
|
|
649
|
-
onUnmount(): void {
|
|
650
|
-
for (const fn of cleanups) fn();
|
|
651
|
-
cleanups = [];
|
|
652
|
-
for (const fn of removers) fn();
|
|
653
|
-
removers = [];
|
|
654
|
-
offMove?.();
|
|
655
|
-
offMove = null;
|
|
656
|
-
offOutcome?.();
|
|
657
|
-
offOutcome = null;
|
|
658
|
-
clearTrack();
|
|
659
|
-
root = null;
|
|
660
|
-
noticeEl = null;
|
|
661
|
-
board = null;
|
|
662
|
-
live = null;
|
|
663
|
-
},
|
|
664
694
|
};
|
|
665
|
-
},
|
|
695
|
+
}),
|
|
666
696
|
};
|
|
667
697
|
}
|
package/src/data/media-grid.ts
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
// 列数 `columns` 取 kit-grammar#dataLimits.mediaGrid.columns 闭集,窄容器固定 2 列,达到 md 档才用设定列数。
|
|
7
7
|
// 点图片抛 `select { id, item }`;视频自带控件,不抛事件。
|
|
8
8
|
|
|
9
|
-
import type {
|
|
10
|
-
import {
|
|
9
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
10
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
11
|
+
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
11
12
|
import { classTokens, emptyNode, keyMap, mk, rowsOf, textOf } from './shape-util';
|
|
12
13
|
import { rowKey, safeImgSrc } from './d9-util';
|
|
13
14
|
import { kitText } from '../i18n/kit-text';
|
|
@@ -125,10 +126,9 @@ export function createMediaGrid(): SomaComponentDefinition {
|
|
|
125
126
|
},
|
|
126
127
|
},
|
|
127
128
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
128
|
-
controllerFactory: (
|
|
129
|
-
const P = (): Record<string, unknown> =>
|
|
129
|
+
controllerFactory: createKitController((api) => {
|
|
130
|
+
const P = (): Record<string, unknown> => api.props();
|
|
130
131
|
let root: HTMLElement | null = null;
|
|
131
|
-
let off: (() => void) | undefined;
|
|
132
132
|
|
|
133
133
|
const itemNode = (e: KitMediaEntry, aspect: string, flow: boolean, withCaption: boolean): HTMLElement => {
|
|
134
134
|
const box = mk('figure', ITEM_CLASS);
|
|
@@ -157,7 +157,11 @@ export function createMediaGrid(): SomaComponentDefinition {
|
|
|
157
157
|
media = btn;
|
|
158
158
|
}
|
|
159
159
|
box.appendChild(media);
|
|
160
|
-
if (withCaption && e.title !== '')
|
|
160
|
+
if (withCaption && e.title !== '') {
|
|
161
|
+
const caption = mk('figcaption', CAPTION_CLASS, e.title);
|
|
162
|
+
caption.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
163
|
+
box.appendChild(caption);
|
|
164
|
+
}
|
|
161
165
|
return box;
|
|
162
166
|
};
|
|
163
167
|
|
|
@@ -217,30 +221,26 @@ export function createMediaGrid(): SomaComponentDefinition {
|
|
|
217
221
|
};
|
|
218
222
|
|
|
219
223
|
return {
|
|
220
|
-
|
|
221
|
-
root =
|
|
222
|
-
?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
|
|
223
|
-
?? ctx.host;
|
|
224
|
+
attach(rootEl) {
|
|
225
|
+
root = rootEl;
|
|
224
226
|
const r = root;
|
|
225
227
|
const onClick = (event: Event): void => {
|
|
226
228
|
const key = (event.target as HTMLElement | null)?.closest<HTMLElement>('[data-kit-pick]')?.getAttribute('data-kit-pick');
|
|
227
229
|
if (key === null || key === undefined) return;
|
|
228
230
|
const hit = mediaEntriesOf(P().data, P().map).find((e) => e.key === key);
|
|
229
|
-
if (hit)
|
|
231
|
+
if (hit) api.emit('select', { id: hit.key, item: hit.raw });
|
|
230
232
|
};
|
|
231
233
|
r.addEventListener('click', onClick);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
+
return () => {
|
|
235
|
+
r.removeEventListener('click', onClick);
|
|
236
|
+
root = null;
|
|
237
|
+
};
|
|
234
238
|
},
|
|
235
|
-
|
|
239
|
+
render(rootEl) {
|
|
240
|
+
root = rootEl;
|
|
236
241
|
paint();
|
|
237
242
|
},
|
|
238
|
-
onUnmount(): void {
|
|
239
|
-
off?.();
|
|
240
|
-
off = undefined;
|
|
241
|
-
root = null;
|
|
242
|
-
},
|
|
243
243
|
};
|
|
244
|
-
},
|
|
244
|
+
}),
|
|
245
245
|
};
|
|
246
246
|
}
|
package/src/data/mega-menu.ts
CHANGED
|
@@ -13,14 +13,16 @@ import { kitKey, kitText } from '../i18n/kit-text';
|
|
|
13
13
|
import { safeHref } from '../base/link';
|
|
14
14
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, queryWithDropdowns, releaseDropdownsIn, syncDropdown } from '../base/popup';
|
|
15
15
|
import { attrEsc } from './d9-util';
|
|
16
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
17
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
16
18
|
import { classSet, FOCUS, h, isRec, onOutsidePointer, recList, textOf, type Rec } from './menu-dom';
|
|
17
19
|
|
|
18
20
|
const ROOT_CLASS = 'relative flex flex-wrap items-center gap-1 text-sm text-fg';
|
|
19
|
-
const TRIGGER_CLASS = `inline-flex h-
|
|
20
|
-
const TRIGGER_OPEN_CLASS = `inline-flex h-
|
|
21
|
+
const TRIGGER_CLASS = `inline-flex h-8 cursor-pointer items-center gap-1 rounded-md px-3 text-sm font-medium text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg ${FOCUS}`;
|
|
22
|
+
const TRIGGER_OPEN_CLASS = `inline-flex h-8 cursor-pointer items-center gap-1 rounded-md bg-primary-soft px-3 text-sm font-medium text-primary-on-soft ${FOCUS}`;
|
|
21
23
|
const CARET_CLASS = 'inline-flex';
|
|
22
24
|
// 位置类由 popup.ts 的 syncDropdown 贴边翻转时拼上(默认 left-0 top-full mt-1)
|
|
23
|
-
const PANEL_BASE_CLASS = 'absolute z-30 flex w-max max-w-full flex-col gap-3
|
|
25
|
+
const PANEL_BASE_CLASS = mergeClass('absolute z-30 flex w-max max-w-full flex-col gap-3 p-4', kitSurfaceRecipe('raised'));
|
|
24
26
|
const PANEL_CLASS = `${PANEL_BASE_CLASS} start-0 top-full mt-1`;
|
|
25
27
|
const GRID_CLASS: Record<number, string> = {
|
|
26
28
|
1: 'grid grid-cols-1 gap-6',
|
|
@@ -30,7 +32,7 @@ const GRID_CLASS: Record<number, string> = {
|
|
|
30
32
|
};
|
|
31
33
|
const COLUMN_CLASS = 'flex min-w-40 flex-col gap-1';
|
|
32
34
|
const COLUMN_TITLE_CLASS = 'px-3 pb-1 text-xs font-semibold text-fg-subtle';
|
|
33
|
-
const ITEM_CLASS = `flex w-full cursor-pointer flex-col gap-0.5 rounded-md px-3 py-2 text-start transition-colors hover:bg-
|
|
35
|
+
const ITEM_CLASS = `flex w-full cursor-pointer flex-col gap-0.5 rounded-md px-3 py-2 text-start transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${FOCUS}`;
|
|
34
36
|
const ITEM_DISABLED_CLASS = 'flex w-full cursor-not-allowed flex-col gap-0.5 rounded-md px-3 py-2 text-start text-fg-subtle opacity-60';
|
|
35
37
|
const ITEM_HEAD_CLASS = 'flex items-center justify-between gap-2';
|
|
36
38
|
const ITEM_LABEL_CLASS = 'min-w-0 truncate text-sm font-medium text-fg';
|
package/src/data/menu-dom.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// 全部纯函数或无状态:建元素、类串拆候选、记录读取、下拉菜单(弹层 + 焦点进入 / 回焦 / Esc / 点外面关)。
|
|
3
3
|
|
|
4
4
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, dropdownOwnerOf, syncDropdown } from '../base/popup';
|
|
5
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
6
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
5
7
|
|
|
6
8
|
export type Child =Node | string | null | undefined | false;
|
|
7
9
|
|
|
@@ -76,14 +78,14 @@ export interface KitDropdownItem {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
// 外观类;位置类(默认右对齐、下方)由 popup.ts 的 syncDropdown 贴边翻转时拼上
|
|
79
|
-
const DROP_BASE = 'absolute z-30 flex min-w-40 flex-col
|
|
81
|
+
const DROP_BASE = mergeClass('absolute z-30 flex min-w-40 flex-col p-1', kitSurfaceRecipe('raised'));
|
|
80
82
|
const DROP_BOX = `${DROP_BASE} end-0 top-full mt-1.5`;
|
|
81
83
|
|
|
82
84
|
/** 下拉面板已挂进 relative 容器之后调用:贴边翻转(上 / 下、左 / 右端),空间都不够时取较大侧并内部滚动 */
|
|
83
85
|
export function fitDropdownPanel(panel: HTMLElement): void {
|
|
84
86
|
syncDropdown(panel, true, DROP_BASE, undefined, 'end');
|
|
85
87
|
}
|
|
86
|
-
const DROP_ITEM = `flex h-9 w-full cursor-pointer items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-fg transition-colors hover:bg-
|
|
88
|
+
const DROP_ITEM = `flex h-9 w-full cursor-pointer items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-fg transition-colors hover:bg-state-layer-hover active:bg-state-layer-press ${FOCUS_INSET}`;
|
|
87
89
|
const DROP_ITEM_DISABLED = 'flex h-9 w-full cursor-not-allowed items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-fg-subtle opacity-60';
|
|
88
90
|
const DROP_ITEM_DANGER = `flex h-9 w-full cursor-pointer items-center whitespace-nowrap rounded-md px-3 text-start text-sm text-danger-on-soft transition-colors hover:bg-danger-soft ${FOCUS_INSET}`;
|
|
89
91
|
const DROP_SEP = 'my-1 h-px w-full bg-border-subtle';
|
package/src/data/menu.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// - divider: true 的项是「分隔线」:只画一条线,不可聚焦、不可选;
|
|
6
6
|
// - 带 children 的项是可折叠分支,点击展开 / 折叠;openable: true 的分支点击时同时选中(抛 select);
|
|
7
7
|
// - open: true 的分支初始展开;
|
|
8
|
-
// - icon
|
|
8
|
+
// - icon 可写 kit 图标名(home / user / users / key / shield / file / sparkles 等 kitIcon 名,画 SVG),
|
|
9
|
+
// 或一个短字符(emoji 或符号,原样画);缺省收起态取标签首字;badge 是徽标文字或数字。
|
|
9
10
|
// `map` 改写键名(组件期望的键 -> 数据里的键)。当前项由 `selected`(id)给出,祖先分支自动展开;
|
|
10
11
|
// `collapsed` 为真时收成仅图标窄栏:只画一级项,分支点击抛 toggle { rail: true } 交宿主决定(通常是展开侧栏)。
|
|
11
12
|
// 键盘走 core 键盘接线(layout: tree):↑↓ 走可见项,→ 展开 / 进入子项,← 折叠 / 回父项,Home / End,Enter / Space 选中。
|
|
@@ -16,8 +17,9 @@ import { kitText } from '../i18n/kit-text';
|
|
|
16
17
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
17
18
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
18
19
|
import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
20
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
19
21
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
20
|
-
import { kitIcon } from '../base/icons';
|
|
22
|
+
import { KIT_ICON_NAMES, kitIcon, type KitIconName } from '../base/icons';
|
|
21
23
|
import { classSet, cssEscape, firstChar, h, isRec, textOf, type Rec } from './menu-dom';
|
|
22
24
|
import { mountKitMegaMenu } from './mega-menu';
|
|
23
25
|
|
|
@@ -26,16 +28,35 @@ import { mountKitMegaMenu } from './mega-menu';
|
|
|
26
28
|
const ROOT_CLASS = 'flex flex-col text-sm text-fg';
|
|
27
29
|
const LIST_CLASS = 'flex flex-col gap-1';
|
|
28
30
|
const LIST_RAIL_CLASS = 'flex flex-col items-center gap-1';
|
|
29
|
-
|
|
31
|
+
// 子项文字相对父级文字缩进一档(评审 S2:子项不得比父级更靠左):父项有图标时,父级文字起点 = 行内边距 3 + 图标 5 + 间距 2 = 10 个间距单位,
|
|
32
|
+
// 子项行自带 3 的内边距,所以子容器 ps-11(10 + 4 - 3)让子文字落在父文字右侧 4 个单位;父项无图标时父文字起点是 3,子容器 ps-4。
|
|
33
|
+
const GROUP_CLASS = 'flex flex-col gap-1 ps-4';
|
|
34
|
+
const GROUP_ICON_CLASS = 'flex flex-col gap-1 ps-11';
|
|
30
35
|
const ITEM_CLASS = 'flex flex-col gap-1 rounded-md focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
31
36
|
const ITEM_RAIL_CLASS = 'flex w-full flex-col rounded-md focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
32
|
-
const ROW_CLASS = 'flex h-9 cursor-pointer items-center gap-2 rounded-md px-3 text-sm text-fg-muted transition-colors hover:bg-
|
|
37
|
+
const ROW_CLASS = 'flex h-9 cursor-pointer items-center gap-2 rounded-md px-3 text-sm text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg';
|
|
33
38
|
const ROW_ACTIVE_CLASS = 'flex h-9 cursor-pointer items-center gap-2 rounded-md bg-primary-soft px-3 text-sm font-medium text-primary-on-soft';
|
|
34
39
|
const ROW_DISABLED_CLASS = 'flex h-9 cursor-not-allowed items-center gap-2 rounded-md px-3 text-sm text-fg-subtle opacity-60';
|
|
35
|
-
const ROW_RAIL_CLASS = 'flex h-9 w-full cursor-pointer items-center justify-center rounded-md text-sm text-fg-muted transition-colors hover:bg-
|
|
40
|
+
const ROW_RAIL_CLASS = 'flex h-9 w-full cursor-pointer items-center justify-center rounded-md text-sm text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press hover:text-fg';
|
|
36
41
|
const ROW_RAIL_ACTIVE_CLASS = 'flex h-9 w-full cursor-pointer items-center justify-center rounded-md bg-primary-soft text-sm font-medium text-primary-on-soft';
|
|
37
42
|
const HEADING_CLASS = 'px-3 pb-1 pt-3 text-xs font-semibold text-fg-subtle';
|
|
38
43
|
const ICON_CLASS = 'w-5 shrink-0 text-center';
|
|
44
|
+
/** icon 写 kit 图标名时画 SVG:容器居中,不依赖字符基线 */
|
|
45
|
+
const ICON_SVG_CLASS = 'flex w-5 shrink-0 items-center justify-center';
|
|
46
|
+
|
|
47
|
+
/** icon 是 kit 图标名(KitIconName)则返回它,否则 null(仍按短字符原样画,兼容 emoji / 符号 / ≤2 字文本) */
|
|
48
|
+
export function menuIconNameOf(icon: string): KitIconName | null {
|
|
49
|
+
return (KIT_ICON_NAMES as readonly string[]).includes(icon) ? (icon as KitIconName) : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 菜单项图标节点:图标名 → SVG;其余 → 文本(空串返回 null) */
|
|
53
|
+
function menuIconNode(icon: string): HTMLElement | null {
|
|
54
|
+
if (icon === '') return null;
|
|
55
|
+
const name = menuIconNameOf(icon);
|
|
56
|
+
return name !== null
|
|
57
|
+
? h('span', ICON_SVG_CLASS, { 'aria-hidden': 'true' }, kitIcon(name, 'md'))
|
|
58
|
+
: h('span', ICON_CLASS, { 'aria-hidden': 'true' }, icon);
|
|
59
|
+
}
|
|
39
60
|
const LABEL_CLASS = 'min-w-0 flex-1 truncate';
|
|
40
61
|
const CARET_CLASS = 'w-4 shrink-0 text-center text-xs text-fg-subtle';
|
|
41
62
|
const BADGE_CLASS = 'shrink-0 rounded-full bg-surface-sunken px-2 text-xs font-medium text-fg-muted';
|
|
@@ -46,9 +67,9 @@ const SEP_CLASS = 'my-1 h-px w-full bg-border-subtle';
|
|
|
46
67
|
|
|
47
68
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
48
69
|
export const KIT_MENU_CLASS_CANDIDATES: readonly string[] = classSet(
|
|
49
|
-
ROOT_CLASS, LIST_CLASS, LIST_RAIL_CLASS, GROUP_CLASS, ITEM_CLASS, ITEM_RAIL_CLASS, ROW_CLASS, ROW_ACTIVE_CLASS, ROW_DISABLED_CLASS,
|
|
70
|
+
ROOT_CLASS, LIST_CLASS, LIST_RAIL_CLASS, GROUP_CLASS, GROUP_ICON_CLASS, ITEM_CLASS, ITEM_RAIL_CLASS, ROW_CLASS, ROW_ACTIVE_CLASS, ROW_DISABLED_CLASS,
|
|
50
71
|
ROW_RAIL_CLASS, ROW_RAIL_ACTIVE_CLASS, HEADING_CLASS, ICON_CLASS, LABEL_CLASS, CARET_CLASS, BADGE_CLASS, BADGE_PRIMARY_CLASS,
|
|
51
|
-
BADGE_DANGER_CLASS, BADGE_ACTIVE_CLASS, SEP_CLASS,
|
|
72
|
+
BADGE_DANGER_CLASS, BADGE_ACTIVE_CLASS, SEP_CLASS, ICON_SVG_CLASS,
|
|
52
73
|
);
|
|
53
74
|
|
|
54
75
|
// ───────── 数据规整纯函数:键名对照、节点树、祖先链、可见项 ─────────
|
|
@@ -209,6 +230,8 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
209
230
|
let cursor: string | null = null;
|
|
210
231
|
let selected = '';
|
|
211
232
|
let lastGiven: string | null = null;
|
|
233
|
+
/** 手风琴:上一次选中项所在的一级分支('' = 选中的是一级叶子或没有选中);null = 还没选过 */
|
|
234
|
+
let lastTop: string | null = null;
|
|
212
235
|
let dataSig = '';
|
|
213
236
|
let rail = false;
|
|
214
237
|
let props: Rec = {};
|
|
@@ -287,6 +310,7 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
287
310
|
sig = `cyclic:${Math.random()}`;
|
|
288
311
|
}
|
|
289
312
|
const expandAll = bool(props.expand_all);
|
|
313
|
+
const accordion = bool(props.accordion);
|
|
290
314
|
if (sig !== dataSig) {
|
|
291
315
|
dataSig = sig;
|
|
292
316
|
nodes = buildMenuNodes(props.data, map);
|
|
@@ -306,7 +330,14 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
306
330
|
if (given !== lastGiven) {
|
|
307
331
|
lastGiven = given;
|
|
308
332
|
selected = given;
|
|
309
|
-
|
|
333
|
+
const trail = menuAncestors(nodes, given);
|
|
334
|
+
// 手风琴:选中项落进另一个一级分支(或一级叶子)时,先收起其余分支;同一分支内换项、用户手动展开的分支都保留
|
|
335
|
+
if (accordion && given !== '') {
|
|
336
|
+
const top = trail[0] ?? '';
|
|
337
|
+
if (top !== lastTop) open.clear();
|
|
338
|
+
lastTop = top;
|
|
339
|
+
}
|
|
340
|
+
for (const a of trail) open.add(a);
|
|
310
341
|
}
|
|
311
342
|
rail = bool(props.collapsed);
|
|
312
343
|
};
|
|
@@ -336,20 +367,20 @@ export function mountKitMenu(root: HTMLElement, emit: KitMenuEmit): KitMenuHandl
|
|
|
336
367
|
let row: HTMLElement;
|
|
337
368
|
if (rail) {
|
|
338
369
|
row = h('div', active ? ROW_RAIL_ACTIVE_CLASS : ROW_RAIL_CLASS, {},
|
|
339
|
-
h('span', '', { 'aria-hidden': 'true' },
|
|
370
|
+
menuIconNode(n.icon) ?? h('span', '', { 'aria-hidden': 'true' }, firstChar(n.label)));
|
|
340
371
|
} else {
|
|
341
372
|
const badgeClass = active ? BADGE_ACTIVE_CLASS
|
|
342
373
|
: n.badgeTone === 'danger' ? BADGE_DANGER_CLASS
|
|
343
374
|
: n.badgeTone === 'primary' ? BADGE_PRIMARY_CLASS : BADGE_CLASS;
|
|
344
375
|
row = h('div', n.disabled ? ROW_DISABLED_CLASS : active ? ROW_ACTIVE_CLASS : ROW_CLASS, {},
|
|
345
|
-
|
|
346
|
-
h('span', LABEL_CLASS, {}, n.label),
|
|
376
|
+
menuIconNode(n.icon),
|
|
377
|
+
h('span', LABEL_CLASS, { [KIT_TIPS_SCOPE_ATTR]: '' }, n.label),
|
|
347
378
|
n.badge !== '' ? h('span', badgeClass, { 'data-kit-badge': '' }, n.badge) : null,
|
|
348
379
|
branch ? h('span', CARET_CLASS, { 'aria-hidden': 'true', 'data-kit-toggle': '' }, kitIcon(isOpen ? 'chevron-down' : 'chevron-right', 'sm', 'rtl:-scale-x-100')) : null);
|
|
349
380
|
}
|
|
350
381
|
li.append(row);
|
|
351
382
|
if (isOpen) {
|
|
352
|
-
const group = h('ul', GROUP_CLASS, { role: 'group' });
|
|
383
|
+
const group = h('ul', n.icon !== '' ? GROUP_ICON_CLASS : GROUP_CLASS, { role: 'group' });
|
|
353
384
|
for (const child of n.children) for (const node of buildItem(child, tabbable)) group.append(node);
|
|
354
385
|
li.append(group);
|
|
355
386
|
}
|
|
@@ -413,9 +444,10 @@ export function createMenu(): SomaComponentDefinition {
|
|
|
413
444
|
layer: 'data',
|
|
414
445
|
props: {
|
|
415
446
|
layout: { type: 'enum', values: ['tree', 'columns'], default: 'tree', desc: 'tree = 多级菜单(侧栏式);columns = 多列下拉导航(data 为触发钮数组 [{ id, label, columns[{ title?, items[{ id, label, desc?, href?, badge?, disabled? }] }], footer? }])' },
|
|
416
|
-
data: { type: 'array', default: [], desc: '菜单数据 [{ id, label, icon?, badge?, badge_tone?, href?, disabled?, openable?, group?, open?, children? }];group
|
|
447
|
+
data: { type: 'array', default: [], desc: '菜单数据 [{ id, label, icon?, badge?, badge_tone?, href?, disabled?, openable?, group?, open?, children? }];group 为分组标题;icon 可写 kit 图标名(画 SVG)或短字符。layout=columns 时见 layout' },
|
|
417
448
|
map: { type: 'object', default: {}, desc: '键名对照 { id, label, children, icon, badge, href }:组件期望的键 -> 数据里的键' },
|
|
418
449
|
selected: { type: 'string', default: '', desc: '当前项 id;祖先分支自动展开' },
|
|
450
|
+
accordion: { type: 'boolean', default: false, desc: '手风琴:选中项变化时只展开其所在的一级分支(其余收起);用户手动展开的分支保留,直到选中项落进另一个一级分支。工作台侧栏默认开启(sidebar.accordion),独立 Menu 缺省关闭' },
|
|
419
451
|
collapsed: { type: 'boolean', default: false, desc: '收起成仅图标窄栏(只画一级,分支点击抛 toggle { rail: true })' },
|
|
420
452
|
expand_all: { type: 'boolean', default: false, desc: '初始全部展开' },
|
|
421
453
|
label: { type: 'string', default: '', desc: '导航区域的可访问名;缺省取内置文案(按页面语言)' },
|
|
@@ -430,7 +462,7 @@ export function createMenu(): SomaComponentDefinition {
|
|
|
430
462
|
keyboard: { layout: 'tree', wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
431
463
|
},
|
|
432
464
|
templateHtml: `<nav data-soma-id="root" class="${ROOT_CLASS}"></nav>`,
|
|
433
|
-
controllerFactory: createKitController({
|
|
465
|
+
controllerFactory: createKitController(() => ({
|
|
434
466
|
attach(root, api) {
|
|
435
467
|
// 一个基准、两种布局:layout 变了就拆掉旧挂载换新的
|
|
436
468
|
let cur: { layout: string; handle: KitMenuHandle } | null = null;
|
|
@@ -459,6 +491,6 @@ export function createMenu(): SomaComponentDefinition {
|
|
|
459
491
|
render(root, p) {
|
|
460
492
|
HANDLES.get(root)?.update(p);
|
|
461
493
|
},
|
|
462
|
-
}),
|
|
494
|
+
})),
|
|
463
495
|
};
|
|
464
496
|
}
|
package/src/data/mockup.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// 纯展示,无事件。
|
|
9
9
|
|
|
10
10
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
11
|
+
import { KIT_TIPS_SCOPE_ATTR } from '../base/hint-tips';
|
|
11
12
|
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
12
13
|
import { kitText } from '../i18n/kit-text';
|
|
13
14
|
import { classTokens, emptyNode, mk, shapeToneOf, textOf, TONE_SOFT, type Rec, type ShapeTone } from './shape-util';
|
|
@@ -111,7 +112,7 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
111
112
|
emits: {},
|
|
112
113
|
},
|
|
113
114
|
templateHtml: `<figure data-soma-id="root" class="${ROOT_CLASS}"></figure>`,
|
|
114
|
-
controllerFactory: createKitController({
|
|
115
|
+
controllerFactory: createKitController(() => ({
|
|
115
116
|
render(root, p) {
|
|
116
117
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
117
118
|
root.textContent = '';
|
|
@@ -120,7 +121,7 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
120
121
|
root.setAttribute('data-kit-variant', variant);
|
|
121
122
|
if (variant === 'code') {
|
|
122
123
|
const lines = mockupLinesOf(src.lines, num(p.start) ?? 1);
|
|
123
|
-
if (lines.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)))); return; }
|
|
124
|
+
if (lines.length === 0) { root.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)), true)); return; }
|
|
124
125
|
const frame = mk('div', CODE_CLASS);
|
|
125
126
|
const bar = mk('div', BAR_CLASS);
|
|
126
127
|
const dots = mk('div', DOTS_CLASS);
|
|
@@ -147,7 +148,7 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
147
148
|
const frame = mk('div', PHONE_CLASS);
|
|
148
149
|
frame.appendChild(mk('div', NOTCH_CLASS));
|
|
149
150
|
const screen = mk('div', SCREEN_CLASS);
|
|
150
|
-
if (body) screen.appendChild(body); else screen.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root))));
|
|
151
|
+
if (body) screen.appendChild(body); else screen.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)), true));
|
|
151
152
|
frame.appendChild(screen);
|
|
152
153
|
root.appendChild(frame);
|
|
153
154
|
return;
|
|
@@ -160,17 +161,20 @@ export function createMockup(): SomaComponentDefinition {
|
|
|
160
161
|
if (variant === 'browser') {
|
|
161
162
|
const address = mk('div', ADDRESS_CLASS, textOf(src.url));
|
|
162
163
|
address.setAttribute('data-kit-address', '');
|
|
164
|
+
address.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
163
165
|
bar.appendChild(address);
|
|
164
166
|
} else {
|
|
165
|
-
|
|
167
|
+
const barTitle = mk('div', TITLE_CLASS, textOf(src.title));
|
|
168
|
+
barTitle.setAttribute(KIT_TIPS_SCOPE_ATTR, '');
|
|
169
|
+
bar.appendChild(barTitle);
|
|
166
170
|
bar.appendChild(mk('span', SPACER_CLASS));
|
|
167
171
|
}
|
|
168
172
|
frame.appendChild(bar);
|
|
169
173
|
const area = mk('div', BODY_CLASS);
|
|
170
|
-
if (body) area.appendChild(body); else area.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root))));
|
|
174
|
+
if (body) area.appendChild(body); else area.appendChild(emptyNode(str(p.empty_text, kitText('soma.kit.no_content', undefined, root)), true));
|
|
171
175
|
frame.appendChild(area);
|
|
172
176
|
root.appendChild(frame);
|
|
173
177
|
},
|
|
174
|
-
}),
|
|
178
|
+
})),
|
|
175
179
|
};
|
|
176
180
|
}
|