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/calendar.ts
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
// 网格键盘走 core 键盘接线的日期网格:方向键逐日 / 逐周,Home / End 本周首末,PageUp / PageDown 翻月,Shift+PageUp / PageDown 翻年,Enter / Space 选中该日。
|
|
7
7
|
// 事件:点日期格(或 Enter)抛 `date { date, events }`;点事件块抛 `event { id, item }`;翻页 / 切视图抛 `navigate { view, anchor, from, to }`(from / to = 可见区间首末日,页面据此取数)。
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
10
10
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
11
11
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
12
|
-
import { joinClass, num, str } from '../base/shared';
|
|
12
|
+
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
13
13
|
import { kitText } from '../i18n/kit-text';
|
|
14
|
+
import { setKitFace } from '../recipes';
|
|
14
15
|
import { classTokens, keyMap, mk, rowsOf, shapeToneOf, textOf, TONE_SOFT, type Rec } from './shape-util';
|
|
15
16
|
import { monthGridCells, monthGridRange, monthGridStep, weekdayHeads, type MonthGridRange } from '../base/month-grid';
|
|
16
17
|
import {
|
|
@@ -25,14 +26,14 @@ const ROOT_CLASS = 'flex flex-col gap-3 text-sm text-fg';
|
|
|
25
26
|
const HEAD_CLASS = 'flex flex-wrap items-center gap-2';
|
|
26
27
|
const TITLE_CLASS = 'min-w-24 text-base font-semibold text-fg';
|
|
27
28
|
const SPACER_CLASS = 'flex-1';
|
|
28
|
-
const BTN_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-
|
|
29
|
+
const BTN_CLASS = '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 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
29
30
|
const BTN_ON_CLASS = 'inline-flex h-8 items-center justify-center rounded-md border border-primary bg-primary-soft px-3 text-sm font-medium text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
30
31
|
const GRID_CLASS = 'flex flex-col overflow-hidden rounded-lg border border-border-subtle bg-surface';
|
|
31
32
|
const ROW_CLASS = 'grid grid-cols-7 border-border-subtle';
|
|
32
33
|
const ROW_BORDER = 'border-t';
|
|
33
34
|
const HEADCELL_CLASS = 'px-2 py-1.5 text-center text-xs font-medium text-fg-muted';
|
|
34
35
|
// 网格外层 overflow-hidden 会把外扩的焦点环切掉,格子与事件块的焦点环一律画在里面(ring-inset)
|
|
35
|
-
const CELL_CLASS = 'flex min-h-24 flex-col gap-1 border-border-subtle p-1.5 text-start transition-colors hover:bg-
|
|
36
|
+
const CELL_CLASS = 'flex min-h-24 flex-col gap-1 border-border-subtle p-1.5 text-start 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';
|
|
36
37
|
const CELL_WEEK = 'min-h-48';
|
|
37
38
|
const CELL_BORDER = 'border-s';
|
|
38
39
|
const CELL_OUT = 'bg-surface-sunken text-fg-subtle';
|
|
@@ -117,15 +118,14 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
117
118
|
keyboard: { layout: 'grid', date_grid: true, wrap: false, typeahead: false, focus_model: 'roving', space: 'activate' },
|
|
118
119
|
},
|
|
119
120
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
120
|
-
controllerFactory: (
|
|
121
|
-
const P = (): Record<string, unknown> =>
|
|
121
|
+
controllerFactory: createKitController((api) => {
|
|
122
|
+
const P = (): Record<string, unknown> => api.props();
|
|
122
123
|
let root: HTMLElement | null = null;
|
|
123
124
|
let view: KitCalendarView = 'month';
|
|
124
125
|
let anchor = 0;
|
|
125
126
|
let cursor = 0;
|
|
126
127
|
let selected: number | null = null;
|
|
127
128
|
let last = { view: '', month: '', selected: '' };
|
|
128
|
-
let removeListeners: Array<() => void> = [];
|
|
129
129
|
|
|
130
130
|
const todayNum = (): number => {
|
|
131
131
|
const given = dayNumOf(str(P().today));
|
|
@@ -138,7 +138,7 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
138
138
|
|
|
139
139
|
const announce = (): void => {
|
|
140
140
|
const r = range();
|
|
141
|
-
|
|
141
|
+
api.emit('navigate', { view, anchor: textOfDayNum(anchor), from: textOfDayNum(r.from), to: textOfDayNum(r.to) });
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
const sync = (): void => {
|
|
@@ -175,7 +175,7 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
175
175
|
paint();
|
|
176
176
|
focusCursor();
|
|
177
177
|
const events = calendarEventsOf(P().data, P().map).filter((e) => e.from <= n && n <= e.to).map((e) => e.raw);
|
|
178
|
-
|
|
178
|
+
api.emit('date', { date: textOfDayNum(n), events });
|
|
179
179
|
};
|
|
180
180
|
|
|
181
181
|
const pageBy = (dir: number): void => {
|
|
@@ -220,12 +220,15 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
220
220
|
const head = mk('div', HEAD_CLASS);
|
|
221
221
|
const prev = mk('button', BTN_CLASS, str(p.prev_text, kitText('soma.kit.prev_page', undefined, root)));
|
|
222
222
|
prev.type = 'button';
|
|
223
|
+
setKitFace(prev, 'raised');
|
|
223
224
|
prev.setAttribute('data-kit-nav', 'prev');
|
|
224
225
|
const next = mk('button', BTN_CLASS, str(p.next_text, kitText('soma.kit.next_page', undefined, root)));
|
|
225
226
|
next.type = 'button';
|
|
227
|
+
setKitFace(next, 'raised');
|
|
226
228
|
next.setAttribute('data-kit-nav', 'next');
|
|
227
229
|
const todayBtn = mk('button', BTN_CLASS, str(p.today_text, kitText('soma.kit.cal_today', undefined, root)));
|
|
228
230
|
todayBtn.type = 'button';
|
|
231
|
+
setKitFace(todayBtn, 'raised');
|
|
229
232
|
todayBtn.setAttribute('data-kit-nav', 'today');
|
|
230
233
|
const title = mk('h2', TITLE_CLASS, view === 'week'
|
|
231
234
|
? `${textOfDayNum(r.from)} ~ ${textOfDayNum(r.to)}`
|
|
@@ -235,6 +238,7 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
235
238
|
for (const v of ['month', 'week'] as const) {
|
|
236
239
|
const b = mk('button', v === view ? BTN_ON_CLASS : BTN_CLASS, str(p[`${v}_text`], kitText(v === 'month' ? 'soma.kit.cal_month' : 'soma.kit.cal_week', undefined, root)));
|
|
237
240
|
b.type = 'button';
|
|
241
|
+
setKitFace(b, 'raised');
|
|
238
242
|
b.setAttribute('data-kit-view', v);
|
|
239
243
|
b.setAttribute('aria-pressed', v === view ? 'true' : 'false');
|
|
240
244
|
head.appendChild(b);
|
|
@@ -295,12 +299,9 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
295
299
|
}
|
|
296
300
|
|
|
297
301
|
return {
|
|
298
|
-
|
|
299
|
-
root =
|
|
300
|
-
?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
|
|
301
|
-
?? ctx.host;
|
|
302
|
+
attach(rootEl) {
|
|
303
|
+
root = rootEl;
|
|
302
304
|
const r = root;
|
|
303
|
-
sync();
|
|
304
305
|
const onClick = (event: Event): void => {
|
|
305
306
|
const target = event.target as HTMLElement | null;
|
|
306
307
|
const nav = target?.closest<HTMLElement>('[data-kit-nav]');
|
|
@@ -319,7 +320,7 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
319
320
|
if (ev) {
|
|
320
321
|
const key = ev.getAttribute('data-kit-event');
|
|
321
322
|
const hit = calendarEventsOf(P().data, P().map).find((e) => e.key === key);
|
|
322
|
-
if (hit)
|
|
323
|
+
if (hit) api.emit('event', { id: hit.key, item: hit.raw });
|
|
323
324
|
return;
|
|
324
325
|
}
|
|
325
326
|
const cell = target?.closest<HTMLElement>('[data-kit-date]');
|
|
@@ -336,23 +337,19 @@ export function createCalendar(): SomaComponentDefinition {
|
|
|
336
337
|
};
|
|
337
338
|
r.addEventListener('click', onClick);
|
|
338
339
|
r.addEventListener('keydown', onKeydown as EventListener);
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
340
|
+
return () => {
|
|
341
|
+
r.removeEventListener('click', onClick);
|
|
342
|
+
r.removeEventListener('keydown', onKeydown as EventListener);
|
|
343
|
+
root = null;
|
|
344
|
+
};
|
|
344
345
|
},
|
|
345
|
-
|
|
346
|
+
render(rootEl) {
|
|
347
|
+
root = rootEl;
|
|
346
348
|
sync();
|
|
347
349
|
paint();
|
|
348
350
|
},
|
|
349
|
-
onUnmount(): void {
|
|
350
|
-
for (const off of removeListeners) off();
|
|
351
|
-
removeListeners = [];
|
|
352
|
-
root = null;
|
|
353
|
-
},
|
|
354
351
|
};
|
|
355
|
-
},
|
|
352
|
+
}),
|
|
356
353
|
};
|
|
357
354
|
}
|
|
358
355
|
|
package/src/data/carousel.ts
CHANGED
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
// 事件:`change { index, item }`(换张)、`select { index, item }`(slide 布局下点当前张内容)。`current` prop 变化时覆盖当前张。
|
|
14
14
|
|
|
15
15
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
16
|
-
import { KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
16
|
+
import { KIT_CAROUSEL_LIMITS, KIT_STATIC_COMPONENT_LIMITS } from 'soma-foundation/kit-limits';
|
|
17
17
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
18
18
|
import { kitIcon } from '../base/icons';
|
|
19
19
|
import { kitText } from '../i18n/kit-text';
|
|
20
|
+
import { setKitFace } from '../recipes';
|
|
20
21
|
import { kitKey } from '../i18n/kit-text';
|
|
21
22
|
import { classTokens, emptyNode, mk, textOf, type Rec } from './shape-util';
|
|
22
23
|
import { clampInt, keyOfRow, listOf, prefersReducedMotion, urlOf } from './display-util';
|
|
@@ -36,10 +37,12 @@ const TITLE_CLASS = 'text-lg font-semibold';
|
|
|
36
37
|
const TEXT_CLASS = 'text-sm text-fg-muted';
|
|
37
38
|
const CARD_TEXT_CLASS = 'text-sm';
|
|
38
39
|
const BAR_CLASS = 'flex items-center justify-between gap-3';
|
|
39
|
-
const NAV_CLASS = 'inline-flex h-8 min-w-8 items-center justify-center rounded-md border border-border bg-surface px-2 text-sm text-fg transition-colors
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
40
|
+
const NAV_CLASS = 'inline-flex h-8 min-w-8 items-center justify-center rounded-md border border-border bg-surface px-2 text-sm text-fg transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
41
|
+
// 圆点尺寸与间距取 design 真源 kit-limits#carousel(间距步数,乘 --spacing);排容器 hit-gap-N 写 gap 与 --kit-hit-gap,
|
|
42
|
+
// 圆点用 hit-area-row(读 hitTarget;沿排热区 = min(命中边长, 中心距),相邻热区相接零重叠,垂直方向仍是完整命中边长),不手写外扩。
|
|
43
|
+
const DOTS_CLASS = `flex flex-1 items-center justify-center hit-gap-${KIT_CAROUSEL_LIMITS.dotGapStep}`;
|
|
44
|
+
const DOT_CLASS = `hit-area-row size-${KIT_CAROUSEL_LIMITS.dotSizeStep} p-0 rounded-full bg-border transition-colors hover:bg-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-kit-selected:bg-primary`;
|
|
45
|
+
const TOGGLE_CLASS = 'inline-flex h-8 items-center justify-center rounded-md px-2 text-xs text-fg-muted transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
43
46
|
|
|
44
47
|
// stack 布局
|
|
45
48
|
const STACK_PAD: Readonly<Record<KitCarouselEdge, string>> = Object.freeze({
|
|
@@ -49,7 +52,7 @@ const STACK_PAD: Readonly<Record<KitCarouselEdge, string>> = Object.freeze({
|
|
|
49
52
|
end: 'grid pe-6',
|
|
50
53
|
});
|
|
51
54
|
const STACK_CARD_BASE = 'col-start-1 row-start-1 flex min-h-32 flex-col gap-2 rounded-lg border border-border-subtle bg-surface p-4 text-start shadow-md motion-safe:transition-transform';
|
|
52
|
-
const STACK_TOP = 'z-30 cursor-pointer hover:bg-
|
|
55
|
+
const STACK_TOP = 'z-30 cursor-pointer hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
53
56
|
/** 后面两张牌的位置:edge × 深度(1、2) */
|
|
54
57
|
const STACK_BEHIND: Readonly<Record<KitCarouselEdge, readonly [string, string]>> = Object.freeze({
|
|
55
58
|
top: ['z-20 -translate-y-3 scale-95 pointer-events-none', 'z-10 -translate-y-6 scale-90 pointer-events-none'],
|
|
@@ -271,7 +274,7 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
271
274
|
},
|
|
272
275
|
},
|
|
273
276
|
templateHtml: `<section data-soma-id="root" role="region" aria-roledescription="carousel" class="${ROOT_CLASS}"></section>`,
|
|
274
|
-
controllerFactory: createKitController({
|
|
277
|
+
controllerFactory: createKitController(() => ({
|
|
275
278
|
attach(root, api) {
|
|
276
279
|
const s = stateOf(root);
|
|
277
280
|
const onClick = (event: Event): void => {
|
|
@@ -372,11 +375,13 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
372
375
|
const prev = mk('button', NAV_CLASS, '');
|
|
373
376
|
prev.appendChild(kitIcon('chevron-left', 'md', 'rtl:-scale-x-100'));
|
|
374
377
|
prev.type = 'button';
|
|
378
|
+
setKitFace(prev, 'raised');
|
|
375
379
|
prev.setAttribute('data-kit-prev', '');
|
|
376
380
|
prev.setAttribute('aria-label', kitText('soma.kit.prev_item', undefined, root));
|
|
377
381
|
const next = mk('button', NAV_CLASS, '');
|
|
378
382
|
next.appendChild(kitIcon('chevron-right', 'md', 'rtl:-scale-x-100'));
|
|
379
383
|
next.type = 'button';
|
|
384
|
+
setKitFace(next, 'raised');
|
|
380
385
|
next.setAttribute('data-kit-next', '');
|
|
381
386
|
next.setAttribute('aria-label', kitText('soma.kit.next_item', undefined, root));
|
|
382
387
|
const dots = mk('div', DOTS_CLASS);
|
|
@@ -403,6 +408,6 @@ export function createCarousel(): SomaComponentDefinition {
|
|
|
403
408
|
applyIndex(root, s, loop, layout, edge);
|
|
404
409
|
syncTimer(root, api);
|
|
405
410
|
},
|
|
406
|
-
}),
|
|
411
|
+
})),
|
|
407
412
|
};
|
|
408
413
|
}
|
package/src/data/chart.ts
CHANGED
|
@@ -10,9 +10,13 @@
|
|
|
10
10
|
// 没装配图表引擎、没数据、配置非法、引擎加载失败,都显示降级空态,不抛。
|
|
11
11
|
// 颜色只取 `--soma-*` 令牌(读运行期计算值交给引擎主题,源码里不写裸色值);样式类只用语义色名与 utilityScales 内的尺度。
|
|
12
12
|
|
|
13
|
-
import type {
|
|
14
|
-
import {
|
|
15
|
-
import { kitText } from '../i18n/kit-text';
|
|
13
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
14
|
+
import { createKitController, joinClass, num, str } from '../base/shared';
|
|
15
|
+
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
16
|
+
import {
|
|
17
|
+
KIT_READ_STATE_EMIT_DEFS, KIT_READ_STATE_PROP_DEFS, KIT_STATE_PANEL_CLASS_CANDIDATES, paintKitStatePanel,
|
|
18
|
+
type KitStateKind, type KitStatePanelOptions,
|
|
19
|
+
} from '../base/state-panel';
|
|
16
20
|
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
17
21
|
import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
|
|
18
22
|
|
|
@@ -38,8 +42,9 @@ const EMPTY_INNER_CLASS = 'flex h-72 w-full items-center justify-center rounded-
|
|
|
38
42
|
|
|
39
43
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
40
44
|
export const KIT_CHART_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
41
|
-
'w-full', 'h-72', 'hidden',
|
|
45
|
+
'w-full', 'h-72', 'hidden', 'sr-only',
|
|
42
46
|
'flex', 'items-center', 'justify-center', 'rounded-md', 'border', 'border-border-subtle', 'bg-surface-sunken', 'text-sm', 'text-fg-muted',
|
|
47
|
+
...KIT_STATE_PANEL_CLASS_CANDIDATES,
|
|
43
48
|
]);
|
|
44
49
|
|
|
45
50
|
// ───────── 数据规整:图形配置解析、层级树、仪表盘分段、引擎 option 生成(均为纯函数) ─────────
|
|
@@ -529,6 +534,61 @@ export function buildChartOption(
|
|
|
529
534
|
};
|
|
530
535
|
}
|
|
531
536
|
|
|
537
|
+
// ───────── 文字替代:可访问名与读屏数据表(纯函数,WCAG 1.1.1 / 1.4.1) ─────────
|
|
538
|
+
|
|
539
|
+
const CHART_TYPE_TEXT: Readonly<Record<KitChartType, KitTextKey>> = Object.freeze({
|
|
540
|
+
line: 'soma.kit.chart_type_line', bar: 'soma.kit.chart_type_bar', area: 'soma.kit.chart_type_area',
|
|
541
|
+
pie: 'soma.kit.chart_type_pie', donut: 'soma.kit.chart_type_donut', funnel: 'soma.kit.chart_type_funnel',
|
|
542
|
+
gauge: 'soma.kit.chart_type_gauge', scatter: 'soma.kit.chart_type_scatter', combo: 'soma.kit.chart_type_combo',
|
|
543
|
+
radar: 'soma.kit.chart_type_radar', heatmap: 'soma.kit.chart_type_heatmap', boxplot: 'soma.kit.chart_type_boxplot',
|
|
544
|
+
candlestick: 'soma.kit.chart_type_candlestick', sankey: 'soma.kit.chart_type_sankey', treemap: 'soma.kit.chart_type_treemap',
|
|
545
|
+
sunburst: 'soma.kit.chart_type_sunburst', chord: 'soma.kit.chart_type_chord',
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
/** 系列数:直角坐标 / 雷达按 y 字段数,其余图型(扇区、阶段、单值、层级、连线)都是一个系列;箱线 / K 线的 y 是同一系列的五 / 四个统计量 */
|
|
549
|
+
export function chartSeriesCount(config: KitChartConfig): number {
|
|
550
|
+
const multi: ReadonlySet<KitChartType> = new Set<KitChartType>(['line', 'bar', 'area', 'scatter', 'combo', 'radar']);
|
|
551
|
+
return multi.has(config.type) ? Math.max(1, config.y.length) : 1;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export interface KitChartAlt {
|
|
555
|
+
/** role=img 的可访问名:标题 + 图型 + 系列数 + 数据点数 */
|
|
556
|
+
label: string;
|
|
557
|
+
/** 数据表:表头(配置里的字段名)+ 至多 altTable.maxRows 行(文字化) */
|
|
558
|
+
columns: string[];
|
|
559
|
+
rows: string[][];
|
|
560
|
+
/** 数据行总数(超出上限时表后附「仅列出前 n 行」) */
|
|
561
|
+
total: number;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** 由图形配置与数据行生成文字替代(纯函数);键名对照 map 与 buildChartOption 一致(配置字段 -> 数据键) */
|
|
565
|
+
export function chartAltOf(
|
|
566
|
+
config: KitChartConfig,
|
|
567
|
+
rows: ReadonlyArray<Record<string, unknown>>,
|
|
568
|
+
mapRaw: unknown,
|
|
569
|
+
title: string,
|
|
570
|
+
at?: Element | string | null,
|
|
571
|
+
): KitChartAlt {
|
|
572
|
+
const map = recOf(mapRaw);
|
|
573
|
+
const src = (k: string): string => (typeof map[k] === 'string' && map[k] !== '' ? String(map[k]) : k);
|
|
574
|
+
const fields: string[] = [];
|
|
575
|
+
for (const f of [config.x, ...config.y, config.value ?? '', config.parent ?? '']) if (f !== '' && !fields.includes(f)) fields.push(f);
|
|
576
|
+
const shown = config.type === 'gauge' ? rows.slice(0, 1) : rows;
|
|
577
|
+
const cap = CHART_NUM.altTable.maxRows;
|
|
578
|
+
const cell = (v: unknown): string => (v === undefined || v === null ? '' : typeof v === 'object' ? JSON.stringify(v) : String(v));
|
|
579
|
+
const type = kitText(CHART_TYPE_TEXT[config.type], undefined, at);
|
|
580
|
+
const params = { type, series: chartSeriesCount(config), points: shown.length };
|
|
581
|
+
const label = title !== ''
|
|
582
|
+
? kitText('soma.kit.chart_alt', { ...params, title }, at)
|
|
583
|
+
: kitText('soma.kit.chart_alt_untitled', params, at);
|
|
584
|
+
return {
|
|
585
|
+
label,
|
|
586
|
+
columns: fields,
|
|
587
|
+
rows: shown.slice(0, cap).map((r) => fields.map((f) => cell(r[src(f)]))),
|
|
588
|
+
total: shown.length,
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
|
|
532
592
|
// ───────── 组件 ─────────
|
|
533
593
|
|
|
534
594
|
interface ChartEnginePort {
|
|
@@ -567,24 +627,29 @@ export function createChart(): SomaComponentDefinition {
|
|
|
567
627
|
chart: { type: 'object', default: {}, desc: '图形配置 { type: line | bar | area | pie | donut | funnel | gauge | scatter | combo | radar | heatmap | boxplot | candlestick | sankey | treemap | sunburst | chord, x: 字段, y: [字段…], stack?: bool, min? / max? / warnAt? / dangerAt?(gauge;radar 的 max 为各指标量程上限), value?: 字段, parent?: 字段 };funnel 行序即流程顺序;gauge 取列表第一行;scatter:x 与每个 y 字段都是数值;combo:柱线组合,line: [字段…] 里的 y 画折线、其余画柱,y2: [字段…] 挂右侧第二纵轴;ref_lines: [{ value 或 stat(average|max|min|median), label?, tone?(neutral|success|warning|danger) }] 虚线参考线(直角坐标系图型);legend: auto|top|bottom|none;value_format: { prefix?, suffix? } 纵轴与标签的数值前后缀;radar:每行一个指标(x 作名)、每个 y 字段一条系列;heatmap:x / y[0] 为横纵类目、value 为格值;boxplot:y 依次为 最小 / 下四分位 / 中位 / 上四分位 / 最大;candlestick:y 依次为 开盘 / 收盘 / 最低 / 最高;sankey / chord:每行一条连线,x 来源、y[0] 去向、value 流量;treemap / sunburst:x 名称、y[0] 数值、parent 父名称(空 = 根)' },
|
|
568
628
|
map: { type: 'object', default: {}, desc: '键名对照:chart 里的字段名 -> 数据里的键' },
|
|
569
629
|
empty: { type: 'string', default: '', desc: '无数据时的空态文案;缺省取内置文案(按页面语言)' },
|
|
630
|
+
title: { type: 'string', default: '', desc: '图表标题:进可访问名(role=img)与读屏数据表标题;缺省只用「图型 + 系列数 + 数据点数」' },
|
|
631
|
+
aria_label: { type: 'string', default: '', desc: '直接指定图的可访问名(覆盖自动生成的)' },
|
|
632
|
+
...KIT_READ_STATE_PROP_DEFS,
|
|
570
633
|
locale: { type: 'string', default: '', desc: '图表语言;空则不传' },
|
|
571
634
|
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
572
635
|
},
|
|
573
|
-
emits: {},
|
|
636
|
+
emits: { ...KIT_READ_STATE_EMIT_DEFS },
|
|
574
637
|
},
|
|
575
638
|
services: ['engines'],
|
|
576
639
|
templateHtml:
|
|
577
640
|
`<div data-soma-id="root" class="${ROOT_CLASS}">`
|
|
578
641
|
+ `<div data-soma-id="stageWrap" class="hidden"><div data-soma-id="stage" class="${STAGE_CLASS}"></div></div>`
|
|
642
|
+
+ '<div data-soma-id="altWrap" class="sr-only"></div>'
|
|
579
643
|
+ `<div data-soma-id="emptyWrap"><div data-soma-id="emptyText" class="${EMPTY_INNER_CLASS}"></div></div>`
|
|
580
644
|
+ '</div>',
|
|
581
|
-
controllerFactory: (
|
|
582
|
-
const P = (): Record<string, unknown> =>
|
|
645
|
+
controllerFactory: createKitController((api) => {
|
|
646
|
+
const P = (): Record<string, unknown> => api.props();
|
|
583
647
|
let root: HTMLElement | null = null;
|
|
584
648
|
let stageWrap: HTMLElement | null = null;
|
|
585
649
|
let stage: HTMLElement | null = null;
|
|
586
650
|
let emptyWrap: HTMLElement | null = null;
|
|
587
651
|
let emptyText: HTMLElement | null = null;
|
|
652
|
+
let altWrap: HTMLElement | null = null;
|
|
588
653
|
let instance: { setOption(o: Record<string, unknown>, m?: 'merge' | 'replace'): void; resize(): void; dispose(): void } | null = null;
|
|
589
654
|
let creating: Promise<void> | null = null;
|
|
590
655
|
let resizeObs: ResizeObserver | null = null;
|
|
@@ -633,11 +698,62 @@ export function createChart(): SomaComponentDefinition {
|
|
|
633
698
|
const find = (id: string): HTMLElement | null =>
|
|
634
699
|
root?.querySelector<HTMLElement>(`[data-soma-scoped-id="${id}"]`) ?? root?.querySelector<HTMLElement>(`[data-soma-id="${id}"]`) ?? null;
|
|
635
700
|
|
|
636
|
-
|
|
701
|
+
// 空 / 加载 / 错误都画进同一个面板位(与集合三态同一画法:base/state-panel.ts);keepStage = 图保留、面板作提示条
|
|
702
|
+
const showPanel = (kind: KitStateKind, text: string, o: Partial<KitStatePanelOptions> = {}, keepStage = false): void => {
|
|
637
703
|
if (!stageWrap || !emptyWrap || !emptyText) return;
|
|
638
|
-
stageWrap.classList.add('hidden');
|
|
704
|
+
if (keepStage) stageWrap.classList.remove('hidden'); else { stageWrap.classList.add('hidden'); clearAlt(); }
|
|
639
705
|
emptyWrap.classList.remove('hidden');
|
|
640
|
-
emptyText
|
|
706
|
+
paintKitStatePanel(emptyText, kind, { ...o, text });
|
|
707
|
+
};
|
|
708
|
+
// 文字替代:只在真有图(舞台可见)时给舞台 role=img + 可访问名,并在旁边放读屏数据表;
|
|
709
|
+
// 空 / 加载 / 错误 / 降级面板没有图,不带 role=img。role=img 会把子孙当装饰,所以数据表是舞台的兄弟而不是子孙。
|
|
710
|
+
const clearAlt = (): void => {
|
|
711
|
+
stageWrap?.removeAttribute('role');
|
|
712
|
+
stageWrap?.removeAttribute('aria-label');
|
|
713
|
+
if (altWrap) altWrap.textContent = '';
|
|
714
|
+
};
|
|
715
|
+
const setAlt = (alt: KitChartAlt, title: string, override: string): void => {
|
|
716
|
+
if (!stageWrap) return;
|
|
717
|
+
stageWrap.setAttribute('role', 'img');
|
|
718
|
+
stageWrap.setAttribute('aria-label', override !== '' ? override : alt.label);
|
|
719
|
+
if (!altWrap) return;
|
|
720
|
+
const doc = altWrap.ownerDocument;
|
|
721
|
+
altWrap.textContent = '';
|
|
722
|
+
const table = doc.createElement('table');
|
|
723
|
+
const caption = doc.createElement('caption');
|
|
724
|
+
caption.textContent = override !== '' ? override : title !== '' ? title : alt.label;
|
|
725
|
+
table.appendChild(caption);
|
|
726
|
+
const head = doc.createElement('tr');
|
|
727
|
+
for (const col of alt.columns) {
|
|
728
|
+
const th = doc.createElement('th');
|
|
729
|
+
th.setAttribute('scope', 'col');
|
|
730
|
+
th.textContent = col;
|
|
731
|
+
head.appendChild(th);
|
|
732
|
+
}
|
|
733
|
+
const thead = doc.createElement('thead');
|
|
734
|
+
thead.appendChild(head);
|
|
735
|
+
table.appendChild(thead);
|
|
736
|
+
const tbody = doc.createElement('tbody');
|
|
737
|
+
for (const r of alt.rows) {
|
|
738
|
+
const tr = doc.createElement('tr');
|
|
739
|
+
r.forEach((value, i) => {
|
|
740
|
+
const td = doc.createElement(i === 0 ? 'th' : 'td');
|
|
741
|
+
if (i === 0) td.setAttribute('scope', 'row');
|
|
742
|
+
td.textContent = value;
|
|
743
|
+
tr.appendChild(td);
|
|
744
|
+
});
|
|
745
|
+
tbody.appendChild(tr);
|
|
746
|
+
}
|
|
747
|
+
table.appendChild(tbody);
|
|
748
|
+
altWrap.appendChild(table);
|
|
749
|
+
if (alt.total > alt.rows.length) {
|
|
750
|
+
const more = doc.createElement('p');
|
|
751
|
+
more.textContent = kitText('soma.kit.chart_table_more', { n: alt.rows.length, total: alt.total }, altWrap);
|
|
752
|
+
altWrap.appendChild(more);
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
const showEmpty = (text: string): void => {
|
|
756
|
+
showPanel('empty', text);
|
|
641
757
|
};
|
|
642
758
|
const showStage = (): void => {
|
|
643
759
|
if (!stageWrap || !emptyWrap) return;
|
|
@@ -646,7 +762,7 @@ export function createChart(): SomaComponentDefinition {
|
|
|
646
762
|
};
|
|
647
763
|
|
|
648
764
|
const portOf = (): ChartEnginePort | null => {
|
|
649
|
-
const engines = (
|
|
765
|
+
const engines = (api.services as { engines?: { chart?: ChartEnginePort } } | undefined)?.engines;
|
|
650
766
|
return engines?.chart ?? null;
|
|
651
767
|
};
|
|
652
768
|
|
|
@@ -655,32 +771,53 @@ export function createChart(): SomaComponentDefinition {
|
|
|
655
771
|
const mine = ++seq;
|
|
656
772
|
const p = P();
|
|
657
773
|
root.className = joinClass(ROOT_CLASS, p.class);
|
|
774
|
+
altWrap ??= find('altWrap');
|
|
658
775
|
const rows = (Array.isArray(p.data) ? p.data : []).filter((r): r is Record<string, unknown> => r !== null && typeof r === 'object');
|
|
659
776
|
const config = chartConfigOf(p.chart);
|
|
660
|
-
|
|
777
|
+
// 读状态(有读接口时编译器自动绑 loading / error_text):没有数据时读取失败 / 读取中不再冒充「暂无数据」;有数据时错误作提示条、读取中保留图
|
|
778
|
+
const errorText = str(p.error_text);
|
|
779
|
+
const retryLabel = str(p.retry_text);
|
|
780
|
+
const retry = retryLabel !== '' ? (): void => { api.emit('retry', {}); } : null;
|
|
781
|
+
const loading = p.loading === true || p.loading === 'true';
|
|
782
|
+
if (rows.length === 0 && errorText !== '') { showPanel('error', errorText, { retry, retryLabel }); return; }
|
|
783
|
+
if (rows.length === 0 && loading) { showPanel('loading', str(p.loading_text, kitText('soma.kit.loading', undefined, root))); return; }
|
|
784
|
+
// 配置 / 引擎问题是页面或环境的错,不是「没数据」:按错误态画(无重试)
|
|
785
|
+
if (config === null) { showPanel('error', kitText('soma.kit.chart_incomplete', undefined, root)); return; }
|
|
661
786
|
if (rows.length === 0) { showEmpty(str(p.empty, kitText('soma.kit.empty', undefined, root))); return; }
|
|
662
787
|
const port = portOf();
|
|
663
|
-
if (port === null) {
|
|
788
|
+
if (port === null) { showPanel('error', kitText('soma.kit.chart_no_engine', undefined, root)); return; }
|
|
664
789
|
try {
|
|
665
790
|
showStage();
|
|
791
|
+
if (errorText !== '') showPanel('error', errorText, { retry, retryLabel }, true);
|
|
666
792
|
const theme = themeOf(root);
|
|
667
|
-
|
|
793
|
+
// 减少动效偏好:关掉引擎的入场 / 更新动画(端口不透出 aria / decal 初始化项,系列区分靠图例 + 数据表)
|
|
794
|
+
const reduceMotion = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
795
|
+
const option = { ...buildChartOption(config, rows, theme, p.map), ...(reduceMotion ? { animation: false } : {}) };
|
|
796
|
+
setAlt(chartAltOf(config, rows, p.map, str(p.title), root), str(p.title), str(p.aria_label));
|
|
668
797
|
if (instance === null) {
|
|
669
798
|
if (creating === null) {
|
|
670
799
|
creating = (async () => {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
800
|
+
try {
|
|
801
|
+
await port.ensure(engineSeriesListOf(config.type), engineComponentsOf(config.type, (config.refLines?.length ?? 0) > 0));
|
|
802
|
+
const locale = str(p.locale);
|
|
803
|
+
const created = await port.create(stage!, { theme: { color: theme.palette }, ...(locale !== '' ? { locale } : {}) });
|
|
804
|
+
if (!alive) { created.dispose(); return; }
|
|
805
|
+
instance = created;
|
|
806
|
+
if (typeof ResizeObserver === 'function') {
|
|
807
|
+
resizeObs = new ResizeObserver(() => instance?.resize());
|
|
808
|
+
resizeObs.observe(stage!);
|
|
809
|
+
}
|
|
810
|
+
} finally {
|
|
811
|
+
creating = null;
|
|
679
812
|
}
|
|
680
813
|
})();
|
|
681
814
|
}
|
|
682
|
-
|
|
683
|
-
|
|
815
|
+
try {
|
|
816
|
+
await creating;
|
|
817
|
+
} catch (err) {
|
|
818
|
+
creating = null;
|
|
819
|
+
throw err;
|
|
820
|
+
}
|
|
684
821
|
}
|
|
685
822
|
// 异步期间又有新一轮 paint 或已卸载:交给最新一轮
|
|
686
823
|
if (!alive || mine !== seq || instance === null) return;
|
|
@@ -689,38 +826,40 @@ export function createChart(): SomaComponentDefinition {
|
|
|
689
826
|
instance.setOption(option, 'replace');
|
|
690
827
|
} catch {
|
|
691
828
|
creating = null;
|
|
692
|
-
if (alive && mine === seq)
|
|
829
|
+
if (alive && mine === seq) showPanel('error', kitText('soma.kit.chart_unavailable', undefined, root));
|
|
693
830
|
}
|
|
694
831
|
};
|
|
695
832
|
|
|
696
833
|
return {
|
|
697
|
-
|
|
834
|
+
attach(rootEl) {
|
|
698
835
|
alive = true;
|
|
699
|
-
root =
|
|
836
|
+
root = rootEl;
|
|
700
837
|
stageWrap = find('stageWrap');
|
|
701
838
|
stage = find('stage');
|
|
702
839
|
emptyWrap = find('emptyWrap');
|
|
703
840
|
emptyText = find('emptyText');
|
|
841
|
+
altWrap = find('altWrap');
|
|
704
842
|
watchScheme();
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
843
|
+
return () => {
|
|
844
|
+
alive = false;
|
|
845
|
+
unwatchScheme();
|
|
846
|
+
resizeObs?.disconnect();
|
|
847
|
+
resizeObs = null;
|
|
848
|
+
instance?.dispose();
|
|
849
|
+
instance = null;
|
|
850
|
+
root = null;
|
|
851
|
+
stageWrap = null;
|
|
852
|
+
stage = null;
|
|
853
|
+
emptyWrap = null;
|
|
854
|
+
emptyText = null;
|
|
855
|
+
altWrap = null;
|
|
856
|
+
};
|
|
709
857
|
},
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
resizeObs?.disconnect();
|
|
714
|
-
resizeObs = null;
|
|
715
|
-
instance?.dispose();
|
|
716
|
-
instance = null;
|
|
717
|
-
root = null;
|
|
718
|
-
stageWrap = null;
|
|
719
|
-
stage = null;
|
|
720
|
-
emptyWrap = null;
|
|
721
|
-
emptyText = null;
|
|
858
|
+
async render(rootEl) {
|
|
859
|
+
root = rootEl;
|
|
860
|
+
await paint();
|
|
722
861
|
},
|
|
723
862
|
};
|
|
724
|
-
},
|
|
863
|
+
}),
|
|
725
864
|
};
|
|
726
865
|
}
|
package/src/data/checklist.ts
CHANGED
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
10
10
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
11
11
|
import { createCheck, markInput } from '../base/check-core';
|
|
12
|
+
import { kitIcon } from '../base/icons';
|
|
13
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
14
|
+
import { kitStateMarkRecipe } from '../recipes/state';
|
|
12
15
|
import { kitText } from '../i18n/kit-text';
|
|
13
16
|
import {
|
|
14
17
|
actionButton, actionsOf, BADGE_BASE, BUTTON_CLASS_TOKENS, classTokens, emptyNode, keyMap, mk, mkProgressBar, PROGRESS_BAR_CLASS_TOKENS, recOf, setProgressBar, rowsOf, shapeToneOf, textOf,
|
|
@@ -26,19 +29,20 @@ const TITLE_CLASS = 'text-base font-semibold text-fg';
|
|
|
26
29
|
const COUNT_CLASS = 'ms-auto text-xs text-fg-muted';
|
|
27
30
|
const PROGRESS_CLASS = 'block w-full';
|
|
28
31
|
const LIST_CLASS = 'flex flex-col gap-1';
|
|
29
|
-
const ITEM_CLASS = 'flex items-start gap-2 rounded-md px-2 py-1.5 transition-colors hover:bg-
|
|
32
|
+
const ITEM_CLASS = 'flex items-start gap-2 rounded-md px-2 py-1.5 transition-colors hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
30
33
|
const BOX_CLASS = 'mt-0.5 shrink-0';
|
|
31
34
|
const MARK_CLASS = 'mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-sm text-xs font-semibold';
|
|
32
35
|
const BODY_CLASS = 'flex flex-1 flex-col gap-0.5';
|
|
33
36
|
const LABEL_CLASS = 'text-fg';
|
|
34
|
-
|
|
37
|
+
// 只读态的状态标记(状态呈现表 readonly:不置灰、不画禁用控件、不加删除线):done = 成功软底 + 对勾,todo = 空心圆;类串取配方 kitStateMarkRecipe
|
|
38
|
+
const STATE_MARK_OFFSET = 'mt-0.5';
|
|
35
39
|
const NOTE_CLASS = 'text-xs text-fg-subtle';
|
|
36
40
|
const BLOCK_NOTE = 'rounded-md px-2 py-0.5 text-xs';
|
|
37
41
|
const FOOT_CLASS = 'flex flex-wrap items-center justify-end gap-2';
|
|
38
42
|
|
|
39
43
|
export const KIT_CHECKLIST_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
40
44
|
ROOT_CLASS, HEAD_CLASS, TITLE_CLASS, COUNT_CLASS, PROGRESS_CLASS, LIST_CLASS, ITEM_CLASS, BOX_CLASS, MARK_CLASS, BODY_CLASS,
|
|
41
|
-
LABEL_CLASS,
|
|
45
|
+
LABEL_CLASS, STATE_MARK_OFFSET, kitStateMarkRecipe('done'), kitStateMarkRecipe('todo'), NOTE_CLASS, BLOCK_NOTE, FOOT_CLASS, BADGE_BASE, BUTTON_CLASS_TOKENS, TONE_SOFT.danger, TONE_SOFT.neutral,
|
|
42
46
|
Object.values(TONE_SOFT), PROGRESS_BAR_CLASS_TOKENS,
|
|
43
47
|
);
|
|
44
48
|
|
|
@@ -104,7 +108,7 @@ export function createChecklist(): SomaComponentDefinition {
|
|
|
104
108
|
},
|
|
105
109
|
},
|
|
106
110
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
107
|
-
controllerFactory: createKitController({
|
|
111
|
+
controllerFactory: createKitController(() => ({
|
|
108
112
|
attach(root, api) {
|
|
109
113
|
const onChange = (event: Event): void => {
|
|
110
114
|
const box = event.target as HTMLInputElement | null;
|
|
@@ -139,7 +143,7 @@ export function createChecklist(): SomaComponentDefinition {
|
|
|
139
143
|
render(root, p) {
|
|
140
144
|
renderChecklist(root, p);
|
|
141
145
|
},
|
|
142
|
-
}),
|
|
146
|
+
})),
|
|
143
147
|
};
|
|
144
148
|
|
|
145
149
|
// 视图渲染(attach 里的乐观重绘也走它;函数声明会提升)
|
|
@@ -182,9 +186,18 @@ export function createChecklist(): SomaComponentDefinition {
|
|
|
182
186
|
const mark = mk('span', `${MARK_CLASS} ${TONE_SOFT.danger}`, '!');
|
|
183
187
|
mark.setAttribute('aria-hidden', 'true');
|
|
184
188
|
li.appendChild(mark);
|
|
189
|
+
} else if (readonly) {
|
|
190
|
+
// 只读:状态标记,不是禁用的复选框
|
|
191
|
+
const done = it.status === 'done';
|
|
192
|
+
const mark = mk('span', mergeClass(kitStateMarkRecipe(done ? 'done' : 'todo'), STATE_MARK_OFFSET));
|
|
193
|
+
mark.setAttribute('role', 'img');
|
|
194
|
+
mark.setAttribute('data-kit-state-mark', done ? 'done' : 'todo');
|
|
195
|
+
mark.setAttribute('aria-label', kitText(done ? 'soma.kit.checklist_done' : 'soma.kit.checklist_todo', undefined, root));
|
|
196
|
+
if (done) mark.appendChild(kitIcon('check', 'xs'));
|
|
197
|
+
li.appendChild(mark);
|
|
185
198
|
} else {
|
|
186
199
|
// 自绘勾选标记(base/check-core.ts);change 事件的 target 是它里面的原生 input,data-kit-check / aria-label 写在 input 上
|
|
187
|
-
const mark = createCheck(root.ownerDocument, 'checkbox', { checked: it.status === 'done',
|
|
200
|
+
const mark = createCheck(root.ownerDocument, 'checkbox', { checked: it.status === 'done', extra: BOX_CLASS });
|
|
188
201
|
const box = markInput(mark);
|
|
189
202
|
if (box) {
|
|
190
203
|
box.setAttribute('data-kit-check', it.key);
|
|
@@ -193,7 +206,7 @@ export function createChecklist(): SomaComponentDefinition {
|
|
|
193
206
|
li.appendChild(mark);
|
|
194
207
|
}
|
|
195
208
|
const body = mk('div', BODY_CLASS);
|
|
196
|
-
body.appendChild(mk('span',
|
|
209
|
+
body.appendChild(mk('span', LABEL_CLASS, it.label));
|
|
197
210
|
if (it.status === 'blocked') {
|
|
198
211
|
body.appendChild(mk('span', `${BLOCK_NOTE} ${TONE_SOFT.danger}`, `${str(p.blocked_text, kitText('soma.kit.flowstat_blocked', undefined, root))}${kitText('soma.kit.colon', undefined, root)}${it.note}`));
|
|
199
212
|
} else if (it.note !== '') {
|