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/base/shared.ts
CHANGED
|
@@ -18,8 +18,24 @@ import {
|
|
|
18
18
|
KIT_POPUP_PLACE_CLASS_CANDIDATES, POPUP_TIP_BASE, POPUP_TIP_HIDDEN_CLASS, POPUP_TIP_PREF, POPUP_TIP_SHOWN_CLASS,
|
|
19
19
|
popupTipClass, showPopupFitted,
|
|
20
20
|
} from './popup';
|
|
21
|
+
import { classCandidates } from './class-candidates';
|
|
22
|
+
import { leaveAnchored, unmarkAnchored } from './anchored-layer';
|
|
23
|
+
import type { KitLeaveHandle } from './overlay-runtime';
|
|
24
|
+
import { withKitViewTransition } from './view-transition';
|
|
21
25
|
import { kitBusyOf, onKitActionBusy } from './action-busy';
|
|
26
|
+
import { deniedBy, registerLivePermissionGate } from './permission-gate';
|
|
22
27
|
import { kitText } from '../i18n/kit-text';
|
|
28
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
29
|
+
import {
|
|
30
|
+
KIT_PART_ATTRIBUTE,
|
|
31
|
+
KIT_PART_BADGE,
|
|
32
|
+
kitControlRecipe,
|
|
33
|
+
kitFocusRingRecipe,
|
|
34
|
+
kitInvalidRecipe,
|
|
35
|
+
KIT_TYPOGRAPHY_RECIPE_MAP,
|
|
36
|
+
kitTypographyRecipe,
|
|
37
|
+
type KitTypographyRecipeRole,
|
|
38
|
+
} from '../recipes';
|
|
23
39
|
|
|
24
40
|
// ── 尺寸档 ────────────────────────────────────────────────────
|
|
25
41
|
|
|
@@ -31,16 +47,39 @@ export function sizeOf(raw: unknown): KitSize {
|
|
|
31
47
|
}
|
|
32
48
|
|
|
33
49
|
// ── 文本类控件的统一类串(Input / Textarea 的单行部分 / Number / Date / DateRange / Select)─────
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
// 直接由 kitControlRecipe 与 kitInvalidRecipe 生成,不再维护平行字面量或拆单 token。
|
|
51
|
+
|
|
52
|
+
export const KIT_TYPOGRAPHY: Readonly<Record<KitTypographyRecipeRole, string>> = Object.freeze({
|
|
53
|
+
pageTitle: kitTypographyRecipe('pageTitle'),
|
|
54
|
+
dialogTitle: kitTypographyRecipe('dialogTitle'),
|
|
55
|
+
sectionTitle: kitTypographyRecipe('sectionTitle'),
|
|
56
|
+
statValue: kitTypographyRecipe('statValue'),
|
|
57
|
+
body: kitTypographyRecipe('body'),
|
|
58
|
+
bodyStrong: kitTypographyRecipe('bodyStrong'),
|
|
59
|
+
caption: kitTypographyRecipe('caption'),
|
|
60
|
+
muted: kitTypographyRecipe('muted'),
|
|
61
|
+
code: kitTypographyRecipe('code'),
|
|
62
|
+
label: kitTypographyRecipe('label'),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export { KIT_TYPOGRAPHY_RECIPE_MAP };
|
|
66
|
+
|
|
67
|
+
export const FOCUS_RING = kitFocusRingRecipe('control');
|
|
37
68
|
|
|
38
69
|
export const FIELD_CLASS: Record<KitSize, string> = {
|
|
39
|
-
sm:
|
|
40
|
-
md:
|
|
41
|
-
lg:
|
|
70
|
+
sm: mergeClass(kitControlRecipe({ size: 'sm', variant: 'outline' }), 'aria-invalid:border-danger'),
|
|
71
|
+
md: mergeClass(kitControlRecipe({ size: 'md', variant: 'outline' }), 'aria-invalid:border-danger'),
|
|
72
|
+
lg: mergeClass(kitControlRecipe({ size: 'lg', variant: 'outline' }), 'aria-invalid:border-danger'),
|
|
42
73
|
};
|
|
43
74
|
|
|
75
|
+
export const FIELD_INVALID_CLASS = kitInvalidRecipe();
|
|
76
|
+
|
|
77
|
+
export function withInvalid(base: string, invalid: boolean): string {
|
|
78
|
+
return invalid ? `${base} ${FIELD_INVALID_CLASS}` : base;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const KIT_SPINNER_CLASS = 'inline-block h-4 w-4 motion-safe:animate-spin rounded-full border-2 border-border border-t-primary';
|
|
82
|
+
|
|
44
83
|
// ── props 读取 ────────────────────────────────────────────────
|
|
45
84
|
|
|
46
85
|
export type KitProps = Record<string, unknown>;
|
|
@@ -79,6 +118,8 @@ export interface KitOption {
|
|
|
79
118
|
label: string;
|
|
80
119
|
/** 仅 Tag 读:命中该选项时优先于 tone prop */
|
|
81
120
|
tone?: KitTone;
|
|
121
|
+
/** 选项写了 `tone: unknown`(未知 / 无法判断):tone 按 neutral 归一(不认识 unknown 的组件照 neutral 画),Tag 读此标记画虚线未知外观 */
|
|
122
|
+
unknown?: boolean;
|
|
82
123
|
disabled?: boolean;
|
|
83
124
|
/** Radio / Checkbox 读:选项图标(短字符,emoji 或符号);label 为空时是纯图标选项 */
|
|
84
125
|
icon?: string;
|
|
@@ -127,13 +168,15 @@ export function optionsOf(raw: unknown): KitOption[] {
|
|
|
127
168
|
const icon = typeof rec.icon === 'string' ? rec.icon : '';
|
|
128
169
|
// 带 icon 又没写 label = 纯图标选项(label 为空,可访问名取 aria_label,缺省取 value)
|
|
129
170
|
const label = rec.label !== undefined && rec.label !== null ? String(rec.label) : icon !== '' ? '' : String(rec.value ?? '');
|
|
130
|
-
const
|
|
171
|
+
const unknownTone = rec.tone === 'unknown';
|
|
172
|
+
const tone = unknownTone ? 'neutral' : toneOf(rec.tone, null);
|
|
131
173
|
push({
|
|
132
174
|
value: rec.value,
|
|
133
175
|
label,
|
|
134
176
|
...(icon !== '' ? { icon } : {}),
|
|
135
177
|
...(typeof rec.aria_label === 'string' && rec.aria_label !== '' ? { aria_label: rec.aria_label } : {}),
|
|
136
178
|
...(tone ? { tone } : {}),
|
|
179
|
+
...(unknownTone ? { unknown: true } : {}),
|
|
137
180
|
...(rec.disabled === true ? { disabled: true } : {}),
|
|
138
181
|
});
|
|
139
182
|
}
|
|
@@ -210,6 +253,11 @@ export interface DisplayResult {
|
|
|
210
253
|
* 铁律:只产出文字。有 options 时按选项取 label(命中不到则显示原值);
|
|
211
254
|
* 没有 options 时 bool、0/1 一律显示原值文字,不变成开关或色块。
|
|
212
255
|
*/
|
|
256
|
+
/** 空值判定(displayOf 与 Tag 共用唯一一份):null / undefined / '' / 空数组 */
|
|
257
|
+
export function valueIsEmpty(value: unknown): boolean {
|
|
258
|
+
return value === null || value === undefined || value === '' || (Array.isArray(value) && value.length === 0);
|
|
259
|
+
}
|
|
260
|
+
|
|
213
261
|
export function displayOf(
|
|
214
262
|
value: unknown,
|
|
215
263
|
options: readonly KitOption[],
|
|
@@ -217,7 +265,9 @@ export function displayOf(
|
|
|
217
265
|
locale: string,
|
|
218
266
|
placeholder: string,
|
|
219
267
|
): DisplayResult {
|
|
220
|
-
|
|
268
|
+
// 显式空串 '' 是「有意留白」:渲染为空白;null / undefined / 空数组仍按占位(缺省「-」)
|
|
269
|
+
if (value === '') return { text: '', option: null };
|
|
270
|
+
if (valueIsEmpty(value)) {
|
|
221
271
|
return { text: placeholder, option: null };
|
|
222
272
|
}
|
|
223
273
|
if (options.length > 0) {
|
|
@@ -250,11 +300,109 @@ export function setAttr(el: Element, name: string, value: string): void {
|
|
|
250
300
|
else el.setAttribute(name, value);
|
|
251
301
|
}
|
|
252
302
|
|
|
253
|
-
/**
|
|
303
|
+
/** 上一次由 applyCommon 写进 aria-describedby 的 id 串(合并时只替换自己写的那部分,不抹掉控件自带的说明 id) */
|
|
304
|
+
const APPLIED_DESCRIBEDBY = new WeakMap<Element, string[]>();
|
|
305
|
+
|
|
306
|
+
/** 空白分隔的 id 串拆成去重的令牌表 */
|
|
307
|
+
function idRefTokens(raw: string): string[] {
|
|
308
|
+
return Array.from(new Set(raw.split(/\s+/).filter((t) => t !== '')));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** 在空白分隔的 id 引用属性里加入一个令牌(已在则不动) */
|
|
312
|
+
export function addIdToken(el: Element, attr: string, id: string): void {
|
|
313
|
+
const tokens = idRefTokens(el.getAttribute(attr) ?? '');
|
|
314
|
+
if (id === '' || tokens.includes(id)) return;
|
|
315
|
+
el.setAttribute(attr, [...tokens, id].join(' '));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** 从空白分隔的 id 引用属性里摘掉一个令牌;摘空则移除属性 */
|
|
319
|
+
export function removeIdToken(el: Element, attr: string, id: string): void {
|
|
320
|
+
const tokens = idRefTokens(el.getAttribute(attr) ?? '');
|
|
321
|
+
if (!tokens.includes(id)) return;
|
|
322
|
+
const rest = tokens.filter((t) => t !== id);
|
|
323
|
+
if (rest.length > 0) el.setAttribute(attr, rest.join(' '));
|
|
324
|
+
else el.removeAttribute(attr);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* 合并写 aria-describedby:保留元素上已有、但不是上次 applyCommon 写入的令牌(控件自带的说明节点),
|
|
329
|
+
* 再并入这次的令牌;重复调用不累积。
|
|
330
|
+
*/
|
|
331
|
+
function mergeDescribedby(el: Element, next: string): void {
|
|
332
|
+
const prevOwn = new Set(APPLIED_DESCRIBEDBY.get(el) ?? []);
|
|
333
|
+
const keep = idRefTokens(el.getAttribute('aria-describedby') ?? '').filter((t) => !prevOwn.has(t));
|
|
334
|
+
const own = idRefTokens(next);
|
|
335
|
+
APPLIED_DESCRIBEDBY.set(el, own);
|
|
336
|
+
const merged = [...keep, ...own.filter((t) => !keep.includes(t))];
|
|
337
|
+
if (merged.length > 0) el.setAttribute('aria-describedby', merged.join(' '));
|
|
338
|
+
else el.removeAttribute('aria-describedby');
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* 标签关联、可访问名与程序化无障碍校验关联:`id` / `aria-label` / `aria-labelledby` / `name` / `aria-required` / `aria-invalid` / `aria-describedby`(合并)/ `aria-errormessage`。
|
|
343
|
+
* `labelledby` 只在 props 里带了该键(契约声明过)时才写 / 清,避免只传部分键的调用方误清外部写好的名字。
|
|
344
|
+
*/
|
|
254
345
|
export function applyCommon(el: Element, p: KitProps): void {
|
|
255
346
|
setAttr(el, 'id', str(p.id));
|
|
256
|
-
setAttr(el, 'aria-label', str(p.aria_label));
|
|
257
347
|
setAttr(el, 'name', str(p.name));
|
|
348
|
+
applyAria(el, p);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** applyCommon 去掉 id / name 的部分:名字、标签关联、校验态与说明关联 */
|
|
352
|
+
function applyAria(el: Element, p: KitProps): void {
|
|
353
|
+
setAttr(el, 'aria-label', str(p.aria_label));
|
|
354
|
+
if ('labelledby' in p || 'aria_labelledby' in p) setAttr(el, 'aria-labelledby', str(p.aria_labelledby, str(p.labelledby)));
|
|
355
|
+
// WAI-ARIA 1.2:aria-required / aria-invalid / aria-errormessage 不属于 role=group,写了是无效 ARIA;
|
|
356
|
+
// group 根只留名字与说明关联(+ 一个 data-kit-invalid 标记供表单滚动聚焦),校验态落到组内真正承载值的控件上(见 applyGroupA11y)
|
|
357
|
+
if (el.getAttribute('role') === 'group') {
|
|
358
|
+
el.removeAttribute('aria-required');
|
|
359
|
+
el.removeAttribute('aria-invalid');
|
|
360
|
+
el.removeAttribute('aria-errormessage');
|
|
361
|
+
setAttr(el, KIT_INVALID_MARK, bool(p.invalid) ? 'true' : '');
|
|
362
|
+
} else {
|
|
363
|
+
applyValidity(el, p);
|
|
364
|
+
el.removeAttribute(KIT_INVALID_MARK);
|
|
365
|
+
}
|
|
366
|
+
mergeDescribedby(el, str(p.aria_describedby, str(p.describedby)));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** group 根上的无效标记(ARIA 不允许 group 带 aria-invalid;表单据此找首个出错字段) */
|
|
370
|
+
export const KIT_INVALID_MARK = 'data-kit-invalid';
|
|
371
|
+
|
|
372
|
+
/** 必填 / 无效 / 错误消息关联三个校验属性(只给支持它们的角色:原生输入、radiogroup、combobox、textbox 等) */
|
|
373
|
+
function applyValidity(el: Element, p: KitProps): void {
|
|
374
|
+
if (bool(p.required)) el.setAttribute('aria-required', 'true');
|
|
375
|
+
else el.removeAttribute('aria-required');
|
|
376
|
+
if (bool(p.invalid)) el.setAttribute('aria-invalid', 'true');
|
|
377
|
+
else el.removeAttribute('aria-invalid');
|
|
378
|
+
setAttr(el, 'aria-errormessage', str(p.aria_errormessage, str(p.errormessage)));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* 组类控件(无单一可标注原生元素:radiogroup / group / 自绘组合)的校验与名字写面:
|
|
383
|
+
* 与 applyCommon 同一套 aria 属性,但不碰 id / name(组根不占 id,id 给第一个可聚焦控件)。
|
|
384
|
+
* 组根是 role=group 时(多选组、验证码格组等),必填 / 无效 / 错误消息写到 `targets`(组内承载值的输入),
|
|
385
|
+
* 说明 / 错误节点仍经 aria-describedby 挂在组根上;radiogroup 根支持这些属性,直接写根。
|
|
386
|
+
*/
|
|
387
|
+
export function applyGroupA11y(el: Element, p: KitProps, targets: Iterable<Element> = []): void {
|
|
388
|
+
applyAria(el, p);
|
|
389
|
+
if (el.getAttribute('role') !== 'group') return;
|
|
390
|
+
for (const target of targets) applyValidity(target, p);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** 表单传给字段控件的无障碍 props 键:任一有值就说明该控件被当作表单字段用 */
|
|
394
|
+
const FIELD_A11Y_KEYS = ['labelledby', 'aria_labelledby', 'describedby', 'aria_describedby', 'required', 'invalid'] as const;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* 复合字段控件(上传、取色、选记录、穿梭等:根不是原生可标注元素)的字段无障碍写面:
|
|
398
|
+
* 被当作表单字段用(props 里带了标签 / 说明 / 必填 / 无效)时根写 role=group + 名字 + 说明关联,必填 / 无效落到 `targets`;
|
|
399
|
+
* 没有这些 props 时不加角色(与单独使用时的原有输出一致),并清掉上一轮写的。
|
|
400
|
+
*/
|
|
401
|
+
export function applyCompositeField(el: Element, p: KitProps, targets: Iterable<Element> = []): void {
|
|
402
|
+
const used = FIELD_A11Y_KEYS.some((k) => { const v = p[k]; return v !== undefined && v !== null && v !== '' && v !== false; });
|
|
403
|
+
if (used) el.setAttribute('role', 'group');
|
|
404
|
+
else if (el.getAttribute('role') === 'group') el.removeAttribute('role');
|
|
405
|
+
applyGroupA11y(el, { ...p, aria_label: '' }, targets);
|
|
258
406
|
}
|
|
259
407
|
|
|
260
408
|
/** 禁用态:原生 disabled + aria-disabled 同写 */
|
|
@@ -272,48 +420,174 @@ export function nextUid(prefix: string): string {
|
|
|
272
420
|
|
|
273
421
|
// ── 控制器骨架 ────────────────────────────────────────────────
|
|
274
422
|
|
|
423
|
+
/** createKitController 生成的控制器工厂内部标记(供 component-gate 与 G99 校验) */
|
|
424
|
+
export const KIT_CONTROLLER: unique symbol = Symbol.for('soma.kit.controller');
|
|
425
|
+
const KIT_CONTROLLER_SOURCE: unique symbol = Symbol.for('soma.kit.controller.source');
|
|
426
|
+
|
|
427
|
+
/** 判定一个值是否为经 createKitController 生成的控制器工厂 */
|
|
428
|
+
export function isKitControllerFactory(fn: unknown): fn is SomaComponentControllerFactory {
|
|
429
|
+
return typeof fn === 'function' && (fn as unknown as Record<symbol, unknown>)[KIT_CONTROLLER] === true;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** 读取控制器工厂的内部实现源码(供 KIT-APP-005 扫描禁用原生控件) */
|
|
433
|
+
export function getKitControllerSource(fn: unknown): string {
|
|
434
|
+
if (typeof fn !== 'function') return '';
|
|
435
|
+
const inner = (fn as unknown as Record<symbol, unknown>)[KIT_CONTROLLER_SOURCE];
|
|
436
|
+
return typeof inner === 'string' ? `${inner}\n${Function.prototype.toString.call(fn)}` : Function.prototype.toString.call(fn);
|
|
437
|
+
}
|
|
438
|
+
|
|
275
439
|
export interface KitApi {
|
|
276
440
|
emit(name: string, payload?: unknown): void;
|
|
277
441
|
props(): KitProps;
|
|
278
442
|
host: HTMLElement;
|
|
279
443
|
/** 契约 `services` 白名单过滤后的运行时服务(虚拟滚动取 `engines.virtual`) */
|
|
280
444
|
services?: Record<string, unknown>;
|
|
445
|
+
/** 请求组件重绘(等价于触发新一轮全量 render) */
|
|
446
|
+
refresh(): void;
|
|
447
|
+
/** 当前这轮异步 render 是否仍为最新且组件未卸载 */
|
|
448
|
+
isCurrent(): boolean;
|
|
281
449
|
}
|
|
282
450
|
|
|
283
451
|
export interface KitView {
|
|
284
|
-
/**
|
|
452
|
+
/** 挂监听、观察器、引擎;返回清理函数。只在 onMount 调一次 */
|
|
285
453
|
attach?(root: HTMLElement, api: KitApi): (() => void) | void;
|
|
286
|
-
/**
|
|
287
|
-
render(root: HTMLElement, p: KitProps, api: KitApi): void
|
|
454
|
+
/** 必填;首绘和每次 prop 变化都整份重画(支持异步,后发先至由骨架统一处理) */
|
|
455
|
+
render(root: HTMLElement, p: KitProps, api: KitApi): void | Promise<void>;
|
|
456
|
+
/** 对展示对象公开的方法(由骨架挂到 core 读取的位置,组件不碰 core 内部键) */
|
|
457
|
+
handle?: Record<string, (...a: unknown[]) => unknown>;
|
|
288
458
|
/**
|
|
289
459
|
* 带忙闲通道:为真时骨架订阅 base/action-busy,`busy` / `busy_action` 对应的忙闲状态变了就重绘一次
|
|
290
460
|
* (render 里用 `kitBusyOf(p)` 取状态落到触发钮)。
|
|
291
461
|
*/
|
|
292
462
|
busyAware?: boolean;
|
|
463
|
+
/**
|
|
464
|
+
* 组件声明的数据对象取数完成(外部触发的重算,如 behavior.from 读取回来)后,core 在重渲之后调用一次;
|
|
465
|
+
* 骨架原样挂到控制器上(不包装)。需要在取数后「补画 / 回填」副作用时写在这里(重渲只让派生值重算,不会替你回填);
|
|
466
|
+
* 不要在里面改 props,需要重绘调 `api.refresh()`。抛错由 core 记录,不影响其它组件。
|
|
467
|
+
*/
|
|
468
|
+
onDataObjectsChange?(): void;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export type KitViewSetup = (api: KitApi) => KitView;
|
|
472
|
+
|
|
473
|
+
/** 包装异步引擎调用:若 await 返回时本轮 render 已过期或组件已卸载,自动丢弃旧结果(若刚创建出实例且已卸载则销毁) */
|
|
474
|
+
function guardAsyncServices(
|
|
475
|
+
services: Record<string, unknown> | undefined,
|
|
476
|
+
isCurrent: () => boolean,
|
|
477
|
+
isAlive: () => boolean,
|
|
478
|
+
): Record<string, unknown> | undefined {
|
|
479
|
+
if (!services || typeof services !== 'object') return services;
|
|
480
|
+
const engines = (services as { engines?: Record<string, unknown> }).engines;
|
|
481
|
+
if (!engines || typeof engines !== 'object') return services;
|
|
482
|
+
const wrappedEngines: Record<string, unknown> = { ...engines };
|
|
483
|
+
for (const [k, port] of Object.entries(engines)) {
|
|
484
|
+
if (!port || typeof port !== 'object') continue;
|
|
485
|
+
const pObj = port as Record<string, unknown>;
|
|
486
|
+
const proxyPort: Record<string, unknown> = { ...pObj };
|
|
487
|
+
for (const [m, fn] of Object.entries(pObj)) {
|
|
488
|
+
if (typeof fn !== 'function') continue;
|
|
489
|
+
proxyPort[m] = (...args: unknown[]) => {
|
|
490
|
+
const res = (fn as (...a: unknown[]) => unknown).apply(port, args);
|
|
491
|
+
if (res && typeof (res as Promise<unknown>).then === 'function') {
|
|
492
|
+
return (res as Promise<unknown>).then((val) => {
|
|
493
|
+
if (!isAlive()) {
|
|
494
|
+
if (val && typeof (val as { dispose?: () => void }).dispose === 'function') {
|
|
495
|
+
(val as { dispose: () => void }).dispose();
|
|
496
|
+
}
|
|
497
|
+
return new Promise<never>(() => {});
|
|
498
|
+
}
|
|
499
|
+
if (!isCurrent()) {
|
|
500
|
+
return new Promise<never>(() => {});
|
|
501
|
+
}
|
|
502
|
+
return val;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
return res;
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
wrappedEngines[k] = proxyPort;
|
|
509
|
+
}
|
|
510
|
+
return { ...services, engines: wrappedEngines };
|
|
293
511
|
}
|
|
294
512
|
|
|
295
513
|
/**
|
|
296
|
-
*
|
|
297
|
-
*
|
|
514
|
+
* 控制器挂载钩子:每个 kit 组件实例挂载时按宿主元素各调一次(钩子自己保证幂等)。
|
|
515
|
+
* 给「每页只需装一次」的文档级装置用(按需提示的事件委托,见 hint-tips.ts);这里不 import 它们,避免 shared ↔ reason-tip 循环依赖。
|
|
298
516
|
*/
|
|
299
|
-
|
|
300
|
-
|
|
517
|
+
const MOUNT_HOOKS = new Set<(host: HTMLElement) => void>();
|
|
518
|
+
export function onKitControllerMount(hook: (host: HTMLElement) => void): void {
|
|
519
|
+
MOUNT_HOOKS.add(hook);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* 控制器骨架:每个实例调用一次 setup(api),闭包即实例状态;
|
|
524
|
+
* onMount 取根、挂事件并首绘,onPropsChange 全量重绘,onUnmount 统一执行清理函数。
|
|
525
|
+
* 异步 render 由骨架统一处理后发先至(旧结果自动丢弃);handle 由骨架挂到 core 读取位置。
|
|
526
|
+
*/
|
|
527
|
+
export function createKitController(setup: KitViewSetup | KitView): SomaComponentControllerFactory {
|
|
528
|
+
const setupFn: KitViewSetup | null = typeof setup === 'function' ? setup : (setup && typeof setup === 'object' && typeof (setup as KitView).render === 'function' ? () => setup as KitView : null);
|
|
529
|
+
if (!setupFn) {
|
|
530
|
+
throw new Error('[soma-kit] createKitController 只接受 (api: KitApi) => KitView 构造函数');
|
|
531
|
+
}
|
|
532
|
+
const factory: SomaComponentControllerFactory = (ctx: SomaComponentControllerContext) => {
|
|
301
533
|
let root: HTMLElement | null = null;
|
|
302
534
|
let cleanup: (() => void) | void;
|
|
535
|
+
let alive = false;
|
|
536
|
+
let seq = 0;
|
|
537
|
+
let view: KitView;
|
|
538
|
+
const readProps = (): KitProps => (ctx.readProps ? ctx.readProps() : ctx.props);
|
|
539
|
+
const applyPerm = (): void => {
|
|
540
|
+
const p = readProps();
|
|
541
|
+
if (p && 'permission' in p) {
|
|
542
|
+
if (deniedBy(ctx, p.permission)) ctx.host.setAttribute('hidden', '');
|
|
543
|
+
else ctx.host.removeAttribute('hidden');
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
const paint = (): void => {
|
|
547
|
+
applyPerm();
|
|
548
|
+
if (root) {
|
|
549
|
+
const mine = ++seq;
|
|
550
|
+
const isCurrent = (): boolean => alive && mine === seq;
|
|
551
|
+
const renderApi: KitApi = {
|
|
552
|
+
emit: api.emit,
|
|
553
|
+
props: readProps,
|
|
554
|
+
host: ctx.host,
|
|
555
|
+
services: guardAsyncServices(ctx.services, isCurrent, () => alive),
|
|
556
|
+
refresh: api.refresh,
|
|
557
|
+
isCurrent,
|
|
558
|
+
};
|
|
559
|
+
const out = view.render(root, readProps(), renderApi);
|
|
560
|
+
if (out && typeof (out as Promise<void>).then === 'function') {
|
|
561
|
+
(out as Promise<void>).catch(() => {});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
};
|
|
303
565
|
const api: KitApi = {
|
|
304
566
|
emit: (name, payload) => ctx.emit(name, payload),
|
|
305
|
-
props:
|
|
567
|
+
props: readProps,
|
|
306
568
|
host: ctx.host,
|
|
307
569
|
services: ctx.services,
|
|
570
|
+
refresh: () => {
|
|
571
|
+
if (alive) {
|
|
572
|
+
paint();
|
|
573
|
+
ctx.refresh?.();
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
isCurrent: () => alive,
|
|
308
577
|
};
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
578
|
+
view = setupFn(api);
|
|
579
|
+
if (!view || typeof view.render !== 'function') {
|
|
580
|
+
throw new Error('[soma-kit] createKitController 的 setup 必须返回包含 render(root, p, api) 方法的 KitView');
|
|
581
|
+
}
|
|
312
582
|
let offBusy: (() => void) | null = null;
|
|
583
|
+
let offPerm: (() => void) | null = null;
|
|
313
584
|
let lastBusy = false;
|
|
314
|
-
|
|
585
|
+
const ctrl: Record<string, unknown> = {
|
|
315
586
|
onMount(): void {
|
|
587
|
+
alive = true;
|
|
316
588
|
root = findRoot(ctx.host);
|
|
589
|
+
for (const hook of MOUNT_HOOKS) hook(ctx.host);
|
|
590
|
+
offPerm = registerLivePermissionGate(applyPerm);
|
|
317
591
|
cleanup = view.attach?.(root, api);
|
|
318
592
|
paint();
|
|
319
593
|
if (view.busyAware === true) {
|
|
@@ -331,6 +605,10 @@ export function createKitController(view: KitView): SomaComponentControllerFacto
|
|
|
331
605
|
paint();
|
|
332
606
|
},
|
|
333
607
|
onUnmount(): void {
|
|
608
|
+
alive = false;
|
|
609
|
+
seq += 1;
|
|
610
|
+
offPerm?.();
|
|
611
|
+
offPerm = null;
|
|
334
612
|
offBusy?.();
|
|
335
613
|
offBusy = null;
|
|
336
614
|
if (cleanup) cleanup();
|
|
@@ -338,7 +616,21 @@ export function createKitController(view: KitView): SomaComponentControllerFacto
|
|
|
338
616
|
root = null;
|
|
339
617
|
},
|
|
340
618
|
};
|
|
619
|
+
for (const [k, desc] of Object.entries(Object.getOwnPropertyDescriptors(view))) {
|
|
620
|
+
if (k === 'attach' || k === 'render' || k === 'busyAware' || k === 'onMount' || k === 'onPropsChange' || k === 'onUnmount') continue;
|
|
621
|
+
Object.defineProperty(ctrl, k, desc);
|
|
622
|
+
}
|
|
623
|
+
return ctrl as ReturnType<SomaComponentControllerFactory>;
|
|
341
624
|
};
|
|
625
|
+
const rawSource = typeof setup === 'function'
|
|
626
|
+
? Function.prototype.toString.call(setup)
|
|
627
|
+
: Object.values(setup as unknown as Record<string, unknown>)
|
|
628
|
+
.filter((v): v is (...a: unknown[]) => unknown => typeof v === 'function')
|
|
629
|
+
.map((fn) => Function.prototype.toString.call(fn))
|
|
630
|
+
.join('\n');
|
|
631
|
+
Object.defineProperty(factory, KIT_CONTROLLER, { value: true, enumerable: false, configurable: false });
|
|
632
|
+
Object.defineProperty(factory, KIT_CONTROLLER_SOURCE, { value: rawSource, enumerable: false, configurable: false });
|
|
633
|
+
return factory;
|
|
342
634
|
}
|
|
343
635
|
|
|
344
636
|
// ── 角标(Button / Link / MenuButton / Tag / Avatar 共用)────────
|
|
@@ -378,6 +670,7 @@ export function paintBadge(host: HTMLElement, p: KitProps): boolean {
|
|
|
378
670
|
if (!el) {
|
|
379
671
|
el = document.createElement('span');
|
|
380
672
|
el.setAttribute('data-kit-badge', '');
|
|
673
|
+
el.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_BADGE);
|
|
381
674
|
host.appendChild(el);
|
|
382
675
|
}
|
|
383
676
|
if (text !== '') {
|
|
@@ -417,9 +710,19 @@ export const CLASS_PROP = {
|
|
|
417
710
|
export const ID_PROPS = {
|
|
418
711
|
id: { type: 'string', default: '', desc: '根控件 id,供 label for 关联' },
|
|
419
712
|
aria_label: { type: 'string', default: '', desc: '无可见标签时的可访问名' },
|
|
713
|
+
labelledby: { type: 'string', default: '', desc: '可见标签元素 id(写 aria-labelledby;非原生可标注控件靠它得到可访问名,表单自动传入)' },
|
|
420
714
|
name: { type: 'string', default: '', desc: '表单字段名' },
|
|
421
715
|
} as const;
|
|
422
716
|
|
|
717
|
+
export const INVALID_PROPS = {
|
|
718
|
+
invalid: { type: 'boolean', default: false, desc: '校验无效态(写 aria-invalid="true" 并呈现错误态边框与焦点环)' },
|
|
719
|
+
required: { type: 'boolean', default: false, desc: '必填态(写 aria-required="true")' },
|
|
720
|
+
describedby: { type: 'string', default: '', desc: '关联说明/错误元素 id(写 aria-describedby)' },
|
|
721
|
+
errormessage: { type: 'string', default: '', desc: '关联错误消息元素 id(写 aria-errormessage)' },
|
|
722
|
+
aria_describedby: { type: 'string', default: '', desc: '关联说明/错误元素 id(写 aria-describedby)' },
|
|
723
|
+
aria_errormessage: { type: 'string', default: '', desc: '关联错误消息元素 id(写 aria-errormessage)' },
|
|
724
|
+
} as const;
|
|
725
|
+
|
|
423
726
|
export const OPTIONS_PROP = {
|
|
424
727
|
type: 'array',
|
|
425
728
|
default: [],
|
|
@@ -449,6 +752,8 @@ export interface KitTablistOptions {
|
|
|
449
752
|
orientation?: 'horizontal' | 'vertical';
|
|
450
753
|
/** 选中变化(点击 / 键盘 / select())后回调;silent 的 select 不回调 */
|
|
451
754
|
onSelect?: (id: string, tab: HTMLElement) => void;
|
|
755
|
+
/** 面板切换时用页面过渡(View Transitions,仅内容区参与;不支持 / 减弱动效时直切)。缺省 false;只对真正换了选中项的 select 生效 */
|
|
756
|
+
viewTransition?: boolean;
|
|
452
757
|
}
|
|
453
758
|
|
|
454
759
|
export interface KitTablistHandle {
|
|
@@ -540,15 +845,20 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
|
|
|
540
845
|
const tab = byId(id);
|
|
541
846
|
if (!tab || isDisabled(tab)) return;
|
|
542
847
|
const changed = current !== id;
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
848
|
+
const run = (): void => {
|
|
849
|
+
const sLeft = root.scrollLeft;
|
|
850
|
+
const sTop = root.scrollTop;
|
|
851
|
+
current = id;
|
|
852
|
+
cursor = id;
|
|
853
|
+
paint();
|
|
854
|
+
if (o.focus === true) tab.focus({ preventScroll: true });
|
|
855
|
+
root.scrollLeft = sLeft;
|
|
856
|
+
root.scrollTop = sTop;
|
|
857
|
+
if (changed && o.silent !== true) opts.onSelect?.(id, tab);
|
|
858
|
+
};
|
|
859
|
+
// 过渡路径下 run 由浏览器在下一帧调用;选中状态与回调都在 run 里一起落,顺序与直切一致
|
|
860
|
+
if (changed && opts.viewTransition === true) withKitViewTransition(run);
|
|
861
|
+
else run();
|
|
552
862
|
};
|
|
553
863
|
|
|
554
864
|
const reset = (): void => {
|
|
@@ -615,15 +925,7 @@ export function wireKitTablist(root: HTMLElement, opts: KitTablistOptions = {}):
|
|
|
615
925
|
|
|
616
926
|
// ── 类候选小工具(K9 / D1:补齐波基础组件共用)────────────────
|
|
617
927
|
|
|
618
|
-
|
|
619
|
-
export function classCandidates(...lists: ReadonlyArray<string | readonly string[]>): readonly string[] {
|
|
620
|
-
const set = new Set<string>();
|
|
621
|
-
for (const item of lists) {
|
|
622
|
-
const parts = typeof item === 'string' ? [item] : item;
|
|
623
|
-
for (const part of parts) for (const c of part.split(/\s+/)) if (c !== '') set.add(c);
|
|
624
|
-
}
|
|
625
|
-
return Object.freeze([...set]);
|
|
626
|
-
}
|
|
928
|
+
export { classCandidates } from './class-candidates';
|
|
627
929
|
|
|
628
930
|
// ── 通用 tooltip(按钮类基础组件的可选 prop)─────────────────
|
|
629
931
|
// 提示气泡是目标元素内的一个 role=tooltip 子元素(绝对定位,目标补 `relative`):hover / focus 显示,Esc 与移开隐藏,
|
|
@@ -648,24 +950,52 @@ export const KIT_TOOLTIP_CLASS_CANDIDATES: readonly string[] = classCandidates(
|
|
|
648
950
|
* 给一个控制器视图套上 tooltip:读 `tooltip` prop,渲染后把气泡挂到目标元素(缺省根)里。
|
|
649
951
|
* 视图自己重写 `textContent` 把气泡清掉也没关系,每次渲染后会补挂;卸载时摘掉监听与气泡。
|
|
650
952
|
*/
|
|
651
|
-
export function withTooltip(view:
|
|
953
|
+
export function withTooltip(view: KitViewSetup, targetOf?: (root: HTMLElement) => HTMLElement): KitViewSetup;
|
|
954
|
+
export function withTooltip(view: KitView, targetOf?: (root: HTMLElement) => HTMLElement): KitView & KitViewSetup;
|
|
955
|
+
export function withTooltip(viewOrSetup: KitView | KitViewSetup, targetOf: (root: HTMLElement) => HTMLElement = (r) => r): KitView & KitViewSetup {
|
|
956
|
+
if (typeof viewOrSetup === 'function') {
|
|
957
|
+
return ((api: KitApi) => wrapTooltipView(viewOrSetup(api), targetOf)) as unknown as KitView & KitViewSetup;
|
|
958
|
+
}
|
|
959
|
+
const wrapped = wrapTooltipView(viewOrSetup, targetOf);
|
|
960
|
+
const setupFn = (() => wrapped) as unknown as KitView & KitViewSetup;
|
|
961
|
+
setupFn.attach = wrapped.attach;
|
|
962
|
+
setupFn.render = wrapped.render;
|
|
963
|
+
if (wrapped.handle !== undefined) setupFn.handle = wrapped.handle;
|
|
964
|
+
if (wrapped.busyAware !== undefined) setupFn.busyAware = wrapped.busyAware;
|
|
965
|
+
return setupFn;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
function wrapTooltipView(view: KitView, targetOf: (root: HTMLElement) => HTMLElement = (r) => r): KitView {
|
|
652
969
|
// 视图对象在同一组件定义的所有实例间共享,逐实例状态按根元素存
|
|
653
970
|
// bound / rebind:目标可随渲染变化(如 MenuButton split 时目标由箭头钮换成主钮),监听跟着目标走
|
|
654
|
-
interface TipState { tip: HTMLElement | null; shown: boolean; bound: HTMLElement | null; rebind: ((t: HTMLElement) => void) | null }
|
|
971
|
+
interface TipState { tip: HTMLElement | null; shown: boolean; bound: HTMLElement | null; rebind: ((t: HTMLElement) => void) | null; leave: KitLeaveHandle | null }
|
|
655
972
|
const states = new WeakMap<HTMLElement, TipState>();
|
|
656
973
|
const stateOf = (root: HTMLElement): TipState => {
|
|
657
974
|
let s = states.get(root);
|
|
658
975
|
if (!s) {
|
|
659
|
-
s = { tip: null, shown: false, bound: null, rebind: null };
|
|
976
|
+
s = { tip: null, shown: false, bound: null, rebind: null, leave: null };
|
|
660
977
|
states.set(root, s);
|
|
661
978
|
}
|
|
662
979
|
return s;
|
|
663
980
|
};
|
|
664
981
|
const paintTip = (s: TipState): void => {
|
|
665
|
-
|
|
982
|
+
const tip = s.tip;
|
|
983
|
+
if (tip === null) return;
|
|
666
984
|
// 显示时量一次可用空间,贴边则在闭集位置类间翻转(popup.ts);隐藏只换整串类
|
|
667
|
-
if (s.shown)
|
|
668
|
-
|
|
985
|
+
if (s.shown) {
|
|
986
|
+
// 退场中被重新唤起:撤销退场再落位
|
|
987
|
+
s.leave?.cancel();
|
|
988
|
+
s.leave = null;
|
|
989
|
+
showPopupFitted(tip, tip.parentElement ?? tip, POPUP_TIP_PREF, popupTipClass);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (tip.className === TOOLTIP_HIDDEN_CLASS || s.leave !== null) return;
|
|
993
|
+
// 出场:与其他锚定浮层同一机制(隐藏前过渡,anchored-layer 的 leaveAnchored);没有退场动画则立即收尾
|
|
994
|
+
s.leave = leaveAnchored(tip, () => {
|
|
995
|
+
s.leave = null;
|
|
996
|
+
tip.className = TOOLTIP_HIDDEN_CLASS;
|
|
997
|
+
unmarkAnchored(tip);
|
|
998
|
+
});
|
|
669
999
|
};
|
|
670
1000
|
|
|
671
1001
|
return {
|
|
@@ -697,7 +1027,7 @@ export function withTooltip(view: KitView, targetOf: (root: HTMLElement) => HTML
|
|
|
697
1027
|
};
|
|
698
1028
|
const bind = (t: HTMLElement): void => {
|
|
699
1029
|
if (s.bound === t) return;
|
|
700
|
-
if (s.bound !== null && s.tip !== null
|
|
1030
|
+
if (s.bound !== null && s.tip !== null) removeIdToken(s.bound, 'aria-describedby', s.tip.id);
|
|
701
1031
|
unbind();
|
|
702
1032
|
t.addEventListener('mouseenter', show);
|
|
703
1033
|
t.addEventListener('mouseleave', hide);
|
|
@@ -712,6 +1042,8 @@ export function withTooltip(view: KitView, targetOf: (root: HTMLElement) => HTML
|
|
|
712
1042
|
return () => {
|
|
713
1043
|
unbind();
|
|
714
1044
|
s.rebind = null;
|
|
1045
|
+
s.leave?.cancel();
|
|
1046
|
+
s.leave = null;
|
|
715
1047
|
if (s.tip) s.tip.remove();
|
|
716
1048
|
s.tip = null;
|
|
717
1049
|
s.shown = false;
|
|
@@ -726,7 +1058,7 @@ export function withTooltip(view: KitView, targetOf: (root: HTMLElement) => HTML
|
|
|
726
1058
|
const text = str(p.tooltip);
|
|
727
1059
|
if (text === '') {
|
|
728
1060
|
if (s.tip) {
|
|
729
|
-
|
|
1061
|
+
removeIdToken(target, 'aria-describedby', s.tip.id);
|
|
730
1062
|
s.tip.remove();
|
|
731
1063
|
s.tip = null;
|
|
732
1064
|
}
|
|
@@ -740,12 +1072,18 @@ export function withTooltip(view: KitView, targetOf: (root: HTMLElement) => HTML
|
|
|
740
1072
|
}
|
|
741
1073
|
s.tip.textContent = text;
|
|
742
1074
|
if (s.tip.parentNode !== target) target.appendChild(s.tip);
|
|
743
|
-
target
|
|
1075
|
+
addIdToken(target, 'aria-describedby', s.tip.id);
|
|
744
1076
|
const cls = target.className;
|
|
745
1077
|
if (!/(^|\s)(relative|absolute|fixed|sticky)(\s|$)/.test(cls)) {
|
|
746
1078
|
target.className = cls === '' ? TOOLTIP_ANCHOR_CLASS : `${cls} ${TOOLTIP_ANCHOR_CLASS}`;
|
|
747
1079
|
}
|
|
748
1080
|
paintTip(s);
|
|
749
1081
|
},
|
|
1082
|
+
...(view.handle !== undefined ? { handle: view.handle } : {}),
|
|
1083
|
+
...(view.busyAware !== undefined ? { busyAware: view.busyAware } : {}),
|
|
750
1084
|
};
|
|
751
1085
|
}
|
|
1086
|
+
|
|
1087
|
+
export * from '../recipes';
|
|
1088
|
+
export * from './loading-gate';
|
|
1089
|
+
export { withKitViewTransition, canKitViewTransition } from './view-transition';
|