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
|
@@ -1,235 +1,165 @@
|
|
|
1
|
-
// askKitPrompt
|
|
1
|
+
// askKitPrompt:命令式的自绘输入对话框(取代浏览器原生 prompt,全 kit 只此一份实现;与 askKitConfirm 同族)。
|
|
2
2
|
//
|
|
3
|
-
// 壳用 mountKitModal(经 core 浮层端口挂出:Esc 走层栈只关栈顶、Tab
|
|
4
|
-
// - 返回 Promise<Record | null>:确认 =
|
|
5
|
-
// -
|
|
6
|
-
//
|
|
7
|
-
// -
|
|
8
|
-
// -
|
|
9
|
-
//
|
|
3
|
+
// 壳用 mountKitModal(经 core 浮层端口挂出:Esc 走层栈只关栈顶、Tab 焦点陷阱、关闭后回焦);本文件只补字段与按钮:
|
|
4
|
+
// - 返回 Promise<Record<string, string> | null>:确认 = { 字段名: 值 };取消 / Esc / 点遮罩 / 关闭 = null。调用方一律 await;
|
|
5
|
+
// - 字段 type 只有 text(单行,Enter 提交)与 textarea(多行,Ctrl / ⌘ + Enter 提交);required 的字段空白时就地报错、不关窗;
|
|
6
|
+
// - 文案只用 textContent / value 写入,不经 innerHTML;
|
|
7
|
+
// - 值一律是字符串(原样,不 trim);调用方按需处理空串;
|
|
8
|
+
// - 无 DOM 环境(SSR / 测试)时不弹,直接 resolve whenNoDom(缺省 null)。
|
|
9
|
+
// 页面里的 request.prompt(点动作先问再发请求)由页面级 KitActionHost 调本函数;展示对象里用 ctx.prompt。
|
|
10
10
|
|
|
11
11
|
import { kitText } from '../i18n/kit-text';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
12
|
+
import { kitControlRecipe, kitTypographyRecipe, setKitFace } from '../recipes';
|
|
13
|
+
import { KIT_ERROR_TEXT } from '../recipes/typography';
|
|
14
|
+
import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal } from './modal-dialog';
|
|
15
|
+
import { KIT_DIALOG_HINT_CLASS, KIT_DIALOG_INPUT_CLASS, KIT_DIALOG_MESSAGE_CLASS, kitDialogButton } from './confirm-dialog';
|
|
16
|
+
import { classTokens } from './shape-util';
|
|
15
17
|
|
|
16
|
-
const BUTTON_BASE = 'inline-flex h-9 cursor-pointer items-center justify-center rounded-md px-4 text-sm font-medium transition-colors active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
17
|
-
const BUTTON_PRIMARY = 'border-0 bg-primary text-primary-fg hover:opacity-90';
|
|
18
|
-
const BUTTON_NEUTRAL = 'border border-border bg-surface text-fg hover:bg-surface-sunken';
|
|
19
18
|
const FIELD_CLASS = 'flex flex-col gap-1';
|
|
20
|
-
const LABEL_CLASS = '
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const AREA_CLASS = 'block w-full resize-none rounded-md border border-border bg-surface px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none focus-visible:border-primary focus-visible:ring-2 focus-visible:ring-ring';
|
|
24
|
-
const ERROR_CLASS = 'm-0 text-xs text-danger-on-soft';
|
|
25
|
-
const GROUP_CLASS = 'flex max-h-48 flex-col gap-1 overflow-y-auto rounded-md border border-border bg-surface p-1';
|
|
26
|
-
// 选中态 / 开关态用整串字面量切换(不拼接类名,候选类一次收齐)
|
|
27
|
-
const RADIO_OFF = 'flex h-8 w-full border-0 bg-transparent cursor-pointer items-center rounded-md px-3 text-start text-sm text-fg transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
28
|
-
const RADIO_ON = 'flex h-8 w-full border-0 cursor-pointer items-center rounded-md bg-primary-soft px-3 text-start text-sm text-primary-on-soft transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
29
|
-
const SWITCH_OFF = 'inline-flex h-6 w-10 cursor-pointer items-center rounded-full border border-border bg-surface-sunken px-0.5 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
30
|
-
const SWITCH_ON = 'inline-flex h-6 w-10 cursor-pointer items-center rounded-full border border-primary bg-primary px-0.5 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
31
|
-
const KNOB_OFF = 'block size-4 translate-x-0 rounded-full bg-surface shadow-sm transition-transform motion-safe:duration-150';
|
|
32
|
-
const KNOB_ON = 'block size-4 translate-x-4 rounded-full bg-surface shadow-sm transition-transform motion-safe:duration-150';
|
|
33
|
-
const HIDDEN = 'hidden';
|
|
19
|
+
const LABEL_CLASS = kitTypographyRecipe('label');
|
|
20
|
+
const TEXTAREA_CLASS = kitControlRecipe({ multiline: true });
|
|
21
|
+
const ERROR_CLASS = KIT_ERROR_TEXT;
|
|
34
22
|
|
|
35
23
|
export const KIT_PROMPT_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
36
|
-
|
|
37
|
-
SWITCH_OFF, SWITCH_ON, KNOB_OFF, KNOB_ON, HIDDEN, BUTTON_CLASS_TOKENS, KIT_MODAL_CLASS_CANDIDATES,
|
|
24
|
+
FIELD_CLASS, LABEL_CLASS, TEXTAREA_CLASS, ERROR_CLASS, KIT_DIALOG_INPUT_CLASS, KIT_DIALOG_MESSAGE_CLASS, KIT_DIALOG_HINT_CLASS, KIT_MODAL_CLASS_CANDIDATES,
|
|
38
25
|
);
|
|
39
26
|
|
|
40
|
-
export interface
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
export interface KitPromptField {
|
|
28
|
+
/** 结果里的键 */
|
|
29
|
+
name: string;
|
|
30
|
+
label?: string;
|
|
31
|
+
/** text(单行,缺省)/ textarea(多行) */
|
|
32
|
+
type?: 'text' | 'textarea';
|
|
33
|
+
placeholder?: string;
|
|
34
|
+
initial?: string;
|
|
35
|
+
/** 必填:空白(去空格后为空)时就地报错、不关窗 */
|
|
36
|
+
required?: boolean;
|
|
37
|
+
/** 必填报错文案,缺省取词条「此项必填」 */
|
|
38
|
+
requiredMessage?: string;
|
|
39
|
+
help?: string;
|
|
45
40
|
}
|
|
46
41
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
export interface KitPromptOptions {
|
|
43
|
+
title?: string;
|
|
44
|
+
/** 正文说明(纯文本) */
|
|
45
|
+
message?: string;
|
|
46
|
+
fields: readonly KitPromptField[];
|
|
47
|
+
submitLabel?: string;
|
|
48
|
+
cancelLabel?: string;
|
|
49
|
+
/** 调用方元素:取页面语言与书写方向,也是回焦参照 */
|
|
50
|
+
at?: Element | null;
|
|
51
|
+
/** 没有 DOM 时的结果,缺省 null */
|
|
52
|
+
whenNoDom?: Record<string, string> | null;
|
|
53
|
+
/** 调用方卸载 / 作废时中止:已中止直接 resolve(null);打开后中止就关闭对话框并 resolve(null) */
|
|
54
|
+
signal?: AbortSignal;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
const node = doc.createElement(tag);
|
|
59
|
-
if (cls !== '') node.className = cls;
|
|
60
|
-
if (text !== undefined) node.textContent = text;
|
|
61
|
-
return node;
|
|
62
|
-
}
|
|
57
|
+
type Control = HTMLInputElement | HTMLTextAreaElement;
|
|
63
58
|
|
|
64
|
-
export function askKitPrompt(opts: KitPromptOptions): Promise<Record<string,
|
|
65
|
-
if (
|
|
59
|
+
export function askKitPrompt(opts: KitPromptOptions): Promise<Record<string, string> | null> {
|
|
60
|
+
if (opts.signal?.aborted === true) return Promise.resolve(null);
|
|
61
|
+
if (typeof document === 'undefined' || document.body === null) return Promise.resolve(opts.whenNoDom ?? null);
|
|
66
62
|
const doc = opts.at?.ownerDocument ?? document;
|
|
67
|
-
return new Promise((resolve) => {
|
|
63
|
+
return new Promise<Record<string, string> | null>((resolve) => {
|
|
68
64
|
let settled = false;
|
|
69
|
-
let unwatch: () => void = () => {};
|
|
70
|
-
const finish = (value: Record<string, unknown> | null): void => {
|
|
71
|
-
if (settled) return;
|
|
72
|
-
settled = true;
|
|
73
|
-
unwatch();
|
|
74
|
-
modal.close();
|
|
75
|
-
modal.destroy();
|
|
76
|
-
resolve(value);
|
|
77
|
-
};
|
|
78
65
|
const modal = mountKitModal({
|
|
79
|
-
title: opts.title ?? kitText('soma.kit.
|
|
66
|
+
title: opts.title ?? kitText('soma.kit.confirm', undefined, opts.at),
|
|
80
67
|
size: 'sm',
|
|
81
68
|
at: opts.at ?? null,
|
|
82
69
|
showClose: false,
|
|
70
|
+
dismissOnScrim: false,
|
|
83
71
|
onClose: () => finish(null),
|
|
84
72
|
}, doc);
|
|
73
|
+
let watch: MutationObserver | null = null;
|
|
74
|
+
const finish = (value: Record<string, string> | null): void => {
|
|
75
|
+
if (settled) return;
|
|
76
|
+
settled = true;
|
|
77
|
+
watch?.disconnect();
|
|
78
|
+
watch = null;
|
|
79
|
+
opts.signal?.removeEventListener('abort', onAbort);
|
|
80
|
+
modal.close();
|
|
81
|
+
modal.destroy();
|
|
82
|
+
resolve(value);
|
|
83
|
+
};
|
|
84
|
+
const onAbort = (): void => finish(null);
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (typeof f.name !== 'string' || f.name === '') continue;
|
|
93
|
-
uid += 1;
|
|
94
|
-
const id = `kit-prompt-${uid}-${f.name}`;
|
|
95
|
-
const wrap = mk(doc, 'div', FIELD_CLASS);
|
|
96
|
-
const label = mk(doc, 'label', LABEL_CLASS, f.label ?? f.name);
|
|
97
|
-
label.id = `${id}-label`;
|
|
98
|
-
if (f.required === true) {
|
|
99
|
-
const star = mk(doc, 'span', STAR_CLASS, ' *');
|
|
100
|
-
star.setAttribute('aria-hidden', 'true');
|
|
101
|
-
label.appendChild(star);
|
|
102
|
-
}
|
|
103
|
-
wrap.appendChild(label);
|
|
104
|
-
const initial = defaults[f.name];
|
|
105
|
-
const err = mk(doc, 'p', HIDDEN);
|
|
106
|
-
err.setAttribute('role', 'alert');
|
|
107
|
-
errors.set(f.name, err);
|
|
86
|
+
if (opts.message !== undefined && opts.message !== '') {
|
|
87
|
+
const msg = doc.createElement('p');
|
|
88
|
+
msg.className = KIT_DIALOG_MESSAGE_CLASS;
|
|
89
|
+
msg.textContent = opts.message;
|
|
90
|
+
modal.body.appendChild(msg);
|
|
91
|
+
}
|
|
108
92
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
buttons.forEach((b, i) => {
|
|
118
|
-
const on = options[i]!.value === current;
|
|
119
|
-
b.setAttribute('aria-checked', on ? 'true' : 'false');
|
|
120
|
-
b.className = on ? RADIO_ON : RADIO_OFF;
|
|
121
|
-
// roving tabindex:已选项(没有选中则第一项)进 Tab 序
|
|
122
|
-
b.tabIndex = on || (current === undefined && i === 0) ? 0 : -1;
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
options.forEach((o, i) => {
|
|
126
|
-
const b = mk(doc, 'button', RADIO_OFF, o.label);
|
|
127
|
-
b.type = 'button';
|
|
128
|
-
b.setAttribute('role', 'radio');
|
|
129
|
-
b.addEventListener('click', () => { current = o.value; paint(); });
|
|
130
|
-
b.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
131
|
-
const last = options.length - 1;
|
|
132
|
-
let next = -1;
|
|
133
|
-
if (e.key === 'ArrowDown' || e.key === 'ArrowRight') next = i === last ? 0 : i + 1;
|
|
134
|
-
else if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') next = i === 0 ? last : i - 1;
|
|
135
|
-
else if (e.key === 'Home') next = 0;
|
|
136
|
-
else if (e.key === 'End') next = last;
|
|
137
|
-
if (next < 0) return;
|
|
138
|
-
e.preventDefault();
|
|
139
|
-
current = options[next]!.value;
|
|
140
|
-
paint();
|
|
141
|
-
buttons[next]!.focus();
|
|
142
|
-
});
|
|
143
|
-
buttons.push(b);
|
|
144
|
-
group.appendChild(b);
|
|
145
|
-
});
|
|
146
|
-
paint();
|
|
147
|
-
wrap.appendChild(group);
|
|
148
|
-
readers.set(f.name, { read: () => current, blank: () => current === undefined, focus: () => (buttons.find((b) => b.tabIndex === 0) ?? buttons[0])?.focus() });
|
|
149
|
-
} else if (f.type === 'switch') {
|
|
150
|
-
let on = initial === true;
|
|
151
|
-
const sw = mk(doc, 'button', SWITCH_OFF);
|
|
152
|
-
sw.type = 'button';
|
|
153
|
-
sw.setAttribute('role', 'switch');
|
|
154
|
-
sw.setAttribute('aria-labelledby', label.id);
|
|
155
|
-
const knob = mk(doc, 'span', KNOB_OFF);
|
|
156
|
-
sw.appendChild(knob);
|
|
157
|
-
const paint = (): void => {
|
|
158
|
-
sw.setAttribute('aria-checked', on ? 'true' : 'false');
|
|
159
|
-
sw.className = on ? SWITCH_ON : SWITCH_OFF;
|
|
160
|
-
knob.className = on ? KNOB_ON : KNOB_OFF;
|
|
161
|
-
};
|
|
162
|
-
paint();
|
|
163
|
-
sw.addEventListener('click', () => { on = !on; paint(); });
|
|
164
|
-
wrap.appendChild(sw);
|
|
165
|
-
readers.set(f.name, { read: () => on, blank: () => false, focus: () => sw.focus() });
|
|
166
|
-
} else if (f.type === 'textarea') {
|
|
167
|
-
const area = mk(doc, 'textarea', AREA_CLASS);
|
|
168
|
-
area.id = id;
|
|
169
|
-
area.rows = 4;
|
|
170
|
-
area.value = typeof initial === 'string' || typeof initial === 'number' ? String(initial) : '';
|
|
171
|
-
area.placeholder = f.placeholder ?? '';
|
|
172
|
-
label.htmlFor = id;
|
|
173
|
-
wrap.appendChild(area);
|
|
174
|
-
readers.set(f.name, { read: () => area.value, blank: () => area.value.trim() === '', focus: () => area.focus() });
|
|
175
|
-
} else {
|
|
176
|
-
const input = mk(doc, 'input', INPUT_CLASS);
|
|
177
|
-
input.id = id;
|
|
178
|
-
input.type = f.type === 'number' ? 'number' : 'text';
|
|
179
|
-
input.autocomplete = 'off';
|
|
180
|
-
input.value = typeof initial === 'string' || typeof initial === 'number' ? String(initial) : '';
|
|
181
|
-
input.placeholder = f.placeholder ?? '';
|
|
93
|
+
const controls: Array<{ field: KitPromptField; control: Control; error: HTMLElement }> = [];
|
|
94
|
+
opts.fields.forEach((field, i) => {
|
|
95
|
+
const wrap = doc.createElement('div');
|
|
96
|
+
wrap.className = FIELD_CLASS;
|
|
97
|
+
const id = `kit-prompt-${i}-${Math.random().toString(36).slice(2, 8)}`;
|
|
98
|
+
if (field.label !== undefined && field.label !== '') {
|
|
99
|
+
const label = doc.createElement('label');
|
|
100
|
+
label.className = LABEL_CLASS;
|
|
182
101
|
label.htmlFor = id;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
102
|
+
label.textContent = field.required === true ? `${field.label} *` : field.label;
|
|
103
|
+
wrap.appendChild(label);
|
|
104
|
+
}
|
|
105
|
+
const multi = field.type === 'textarea';
|
|
106
|
+
const control: Control = multi ? doc.createElement('textarea') : doc.createElement('input');
|
|
107
|
+
if (control instanceof HTMLInputElement) { control.type = 'text'; control.autocomplete = 'off'; }
|
|
108
|
+
control.id = id;
|
|
109
|
+
control.className = multi ? TEXTAREA_CLASS : KIT_DIALOG_INPUT_CLASS;
|
|
110
|
+
setKitFace(control, 'field');
|
|
111
|
+
control.value = field.initial ?? '';
|
|
112
|
+
if (field.placeholder !== undefined) control.placeholder = field.placeholder;
|
|
113
|
+
wrap.appendChild(control);
|
|
114
|
+
const error = doc.createElement('p');
|
|
115
|
+
error.className = ERROR_CLASS;
|
|
116
|
+
error.hidden = true;
|
|
117
|
+
error.setAttribute('role', 'alert');
|
|
118
|
+
wrap.appendChild(error);
|
|
119
|
+
if (field.help !== undefined && field.help !== '') {
|
|
120
|
+
const help = doc.createElement('p');
|
|
121
|
+
help.className = KIT_DIALOG_HINT_CLASS;
|
|
122
|
+
help.textContent = field.help;
|
|
123
|
+
wrap.appendChild(help);
|
|
196
124
|
}
|
|
197
|
-
|
|
125
|
+
control.addEventListener('input', () => { error.hidden = true; error.textContent = ''; });
|
|
126
|
+
control.addEventListener('keydown', (event: Event) => {
|
|
127
|
+
const e = event as KeyboardEvent;
|
|
128
|
+
if (e.key !== 'Enter') return;
|
|
129
|
+
if (multi ? (e.ctrlKey || e.metaKey) : !e.isComposing) { e.preventDefault(); submit(); }
|
|
130
|
+
});
|
|
198
131
|
modal.body.appendChild(wrap);
|
|
199
|
-
|
|
132
|
+
controls.push({ field, control, error });
|
|
133
|
+
});
|
|
200
134
|
|
|
201
135
|
const submit = (): void => {
|
|
202
|
-
let
|
|
203
|
-
for (const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
err.className = bad ? ERROR_CLASS : HIDDEN;
|
|
210
|
-
if (bad && firstBad === null) firstBad = r;
|
|
211
|
-
}
|
|
212
|
-
if (firstBad !== null) { (firstBad as Reader).focus(); return; }
|
|
213
|
-
const out: Record<string, unknown> = {};
|
|
214
|
-
for (const f of opts.fields as Field[]) {
|
|
215
|
-
const v = readers.get(f.name)?.read();
|
|
216
|
-
if (v !== undefined) out[f.name] = v;
|
|
136
|
+
let first: Control | null = null;
|
|
137
|
+
for (const { field, control, error } of controls) {
|
|
138
|
+
if (field.required === true && control.value.trim() === '') {
|
|
139
|
+
error.textContent = field.requiredMessage ?? kitText('soma.kit.field_required', undefined, opts.at);
|
|
140
|
+
error.hidden = false;
|
|
141
|
+
first ??= control;
|
|
142
|
+
}
|
|
217
143
|
}
|
|
144
|
+
if (first !== null) { first.focus(); return; }
|
|
145
|
+
const out: Record<string, string> = {};
|
|
146
|
+
for (const { field, control } of controls) out[field.name] = control.value;
|
|
218
147
|
finish(out);
|
|
219
148
|
};
|
|
220
149
|
|
|
221
|
-
const cancel =
|
|
222
|
-
cancel.type = 'button';
|
|
150
|
+
const cancel = kitDialogButton(doc, 'neutral', opts.cancelLabel ?? kitText('soma.kit.cancel', undefined, opts.at));
|
|
223
151
|
cancel.addEventListener('click', () => finish(null));
|
|
224
|
-
const ok =
|
|
225
|
-
ok.type = 'button';
|
|
152
|
+
const ok = kitDialogButton(doc, 'primary', opts.submitLabel ?? kitText('soma.kit.ok', undefined, opts.at));
|
|
226
153
|
ok.addEventListener('click', submit);
|
|
227
154
|
modal.footer.append(cancel, ok);
|
|
228
155
|
|
|
229
156
|
(opts.at?.isConnected === true ? opts.at.parentNode ?? doc.body : doc.body).appendChild(modal.layer);
|
|
230
157
|
modal.open();
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
158
|
+
if (typeof MutationObserver !== 'undefined') {
|
|
159
|
+
watch = new MutationObserver(() => { if (!modal.layer.isConnected) finish(null); });
|
|
160
|
+
watch.observe(doc.body, { childList: true, subtree: true });
|
|
161
|
+
}
|
|
162
|
+
opts.signal?.addEventListener('abort', onAbort, { once: true });
|
|
163
|
+
(controls[0]?.control ?? ok).focus();
|
|
234
164
|
});
|
|
235
165
|
}
|
package/src/data/reaction-bar.ts
CHANGED
|
@@ -6,21 +6,24 @@
|
|
|
6
6
|
// 选一个抛 `add { emoji }`(已存在的表情等同点它的药丸)。选择层 Esc 关闭并回焦「+」,点外面关闭,方向键在候选间移动。
|
|
7
7
|
// 表情种类上限同真源 maxKinds。
|
|
8
8
|
|
|
9
|
-
import type {
|
|
10
|
-
import { bool, joinClass, num, str } from '../base/shared';
|
|
9
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
10
|
+
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
11
11
|
import { kitKey, kitText } from '../i18n/kit-text';
|
|
12
|
+
import { setKitFace } from '../recipes';
|
|
12
13
|
import { classTokens, mk, rowsOf, textOf } from './shape-util';
|
|
13
14
|
import { REACTION_MAX_KINDS, REACTION_PALETTE } from './d9-limits';
|
|
14
15
|
import { attrEsc } from './d9-util';
|
|
16
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
17
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
15
18
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, dropdownOwnerOf, queryWithDropdowns, releaseDropdownsIn, syncDropdown } from '../base/popup';
|
|
16
19
|
|
|
17
20
|
const ROOT_CLASS = 'relative flex flex-wrap items-center gap-2 text-sm text-fg';
|
|
18
|
-
const PILL_CLASS = 'inline-flex h-7 items-center gap-1 rounded-full border border-border bg-surface px-2.5 text-xs text-fg transition-colors
|
|
21
|
+
const PILL_CLASS = 'inline-flex h-7 items-center gap-1 rounded-full border border-border bg-surface px-2.5 text-xs text-fg transition-colors state-layer active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
19
22
|
const PILL_MINE = 'inline-flex h-7 items-center gap-1 rounded-full border border-primary bg-primary-soft px-2.5 text-xs font-medium text-primary-on-soft transition-colors hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
20
|
-
const ADD_CLASS = 'inline-flex size-7 items-center justify-center rounded-full border border-dashed border-border bg-surface text-sm text-fg-muted transition-colors
|
|
21
|
-
const PANEL_BASE_CLASS = 'absolute z-20 flex flex-wrap gap-1
|
|
23
|
+
const ADD_CLASS = 'inline-flex size-7 p-0 items-center justify-center rounded-full border border-dashed border-border bg-surface text-sm text-fg-muted transition-colors state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
24
|
+
const PANEL_BASE_CLASS = mergeClass('absolute z-20 flex flex-wrap gap-1 p-2', kitSurfaceRecipe('raised'));
|
|
22
25
|
const PANEL_CLASS = `${PANEL_BASE_CLASS} start-0 top-full mt-1`;
|
|
23
|
-
const CHOICE_CLASS = 'inline-flex size-8 items-center justify-center rounded-md text-base transition-colors hover:bg-
|
|
26
|
+
const CHOICE_CLASS = 'inline-flex size-8 p-0 items-center justify-center rounded-md text-base transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
24
27
|
|
|
25
28
|
export const KIT_REACTION_BAR_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
26
29
|
ROOT_CLASS, PILL_CLASS, PILL_MINE, ADD_CLASS, PANEL_BASE_CLASS, PANEL_CLASS, CHOICE_CLASS, KIT_DROPDOWN_CLASS_CANDIDATES,
|
|
@@ -66,13 +69,12 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
66
69
|
},
|
|
67
70
|
},
|
|
68
71
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
69
|
-
controllerFactory: (
|
|
70
|
-
const P = (): Record<string, unknown> =>
|
|
72
|
+
controllerFactory: createKitController((api) => {
|
|
73
|
+
const P = (): Record<string, unknown> => api.props();
|
|
71
74
|
let root: HTMLElement | null = null;
|
|
72
75
|
let panelOpen = false;
|
|
73
76
|
let sig = '';
|
|
74
77
|
const flipped = new Map<string, boolean>();
|
|
75
|
-
let removeListeners: Array<() => void> = [];
|
|
76
78
|
// 添加层挂到浮层端口后不再是 root 的后代,root 上的委托收不到它的事件:重画出的面板元素直接绑这两个处理函数
|
|
77
79
|
let panelClick: EventListener | null = null;
|
|
78
80
|
let panelKeydown: EventListener | null = null;
|
|
@@ -95,78 +97,20 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
95
97
|
const on = !(cur?.mine ?? false);
|
|
96
98
|
if (base) flipped.set(emoji, on);
|
|
97
99
|
const next = view().find((r) => r.emoji === emoji);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
api.emit('toggle', { emoji, on, count: next?.count ?? (on ? 1 : 0) });
|
|
101
|
+
api.refresh();
|
|
100
102
|
};
|
|
101
103
|
|
|
102
104
|
const closePanel = (focusAdd: boolean): void => {
|
|
103
105
|
if (!panelOpen) return;
|
|
104
106
|
panelOpen = false;
|
|
105
|
-
|
|
107
|
+
api.refresh();
|
|
106
108
|
if (focusAdd) root?.querySelector<HTMLElement>('[data-kit-add]')?.focus();
|
|
107
109
|
};
|
|
108
110
|
|
|
109
|
-
function paint(): void {
|
|
110
|
-
if (!root) return;
|
|
111
|
-
const p = P();
|
|
112
|
-
const dataSig = JSON.stringify(reactionsOf(p.data));
|
|
113
|
-
if (dataSig !== sig) { sig = dataSig; flipped.clear(); }
|
|
114
|
-
root.className = joinClass(ROOT_CLASS, p.class);
|
|
115
|
-
// 整条重建会丢焦点(键盘点药丸 / 「+」后):记下焦点所在,重绘后落回同一个
|
|
116
|
-
const focused = root.contains(document.activeElement) ? document.activeElement as HTMLElement : null;
|
|
117
|
-
const focusEmoji = focused?.closest('[data-kit-reaction]')?.getAttribute('data-kit-reaction') ?? null;
|
|
118
|
-
const focusAdd = focused?.closest('[data-kit-add]') != null;
|
|
119
|
-
releaseDropdownsIn(root);
|
|
120
|
-
root.textContent = '';
|
|
121
|
-
const disabled = bool(p.disabled);
|
|
122
|
-
for (const r of view()) {
|
|
123
|
-
const b = mk('button', r.mine ? PILL_MINE : PILL_CLASS);
|
|
124
|
-
b.type = 'button';
|
|
125
|
-
b.setAttribute('data-kit-reaction', r.emoji);
|
|
126
|
-
b.setAttribute('aria-pressed', r.mine ? 'true' : 'false');
|
|
127
|
-
b.setAttribute('aria-label', `${r.label !== '' ? r.label : r.emoji} ${r.count}`);
|
|
128
|
-
if (disabled) { b.disabled = true; b.setAttribute('aria-disabled', 'true'); }
|
|
129
|
-
b.appendChild(mk('span', '', r.emoji));
|
|
130
|
-
b.appendChild(mk('span', '', String(r.count)));
|
|
131
|
-
root.appendChild(b);
|
|
132
|
-
}
|
|
133
|
-
if (bool(p.addable) && !disabled && view().length < REACTION_MAX_KINDS) {
|
|
134
|
-
const add = mk('button', ADD_CLASS, '+');
|
|
135
|
-
add.type = 'button';
|
|
136
|
-
add.setAttribute('data-kit-add', '');
|
|
137
|
-
add.setAttribute('aria-label', str(p.add_text, kitText('soma.kit.add_reaction', undefined, root)));
|
|
138
|
-
add.setAttribute('aria-haspopup', 'true');
|
|
139
|
-
add.setAttribute('aria-expanded', panelOpen ? 'true' : 'false');
|
|
140
|
-
root.appendChild(add);
|
|
141
|
-
if (panelOpen) {
|
|
142
|
-
const panel = mk('div', PANEL_CLASS);
|
|
143
|
-
panel.setAttribute('role', 'group');
|
|
144
|
-
panel.setAttribute('aria-label', str(p.add_text, kitText('soma.kit.add_reaction', undefined, root)));
|
|
145
|
-
panel.setAttribute('data-kit-panel', '');
|
|
146
|
-
palette().forEach((e, i) => {
|
|
147
|
-
const c = mk('button', CHOICE_CLASS, e);
|
|
148
|
-
c.type = 'button';
|
|
149
|
-
c.setAttribute('data-kit-choice', e);
|
|
150
|
-
c.tabIndex = i === 0 ? 0 : -1;
|
|
151
|
-
panel.appendChild(c);
|
|
152
|
-
});
|
|
153
|
-
root.appendChild(panel);
|
|
154
|
-
syncDropdown(panel, true, PANEL_BASE_CLASS, root);
|
|
155
|
-
if (!root.contains(panel)) {
|
|
156
|
-
if (panelClick) panel.addEventListener('click', panelClick);
|
|
157
|
-
if (panelKeydown) panel.addEventListener('keydown', panelKeydown);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (focusEmoji !== null) root.querySelector<HTMLElement>(`[data-kit-reaction="${attrEsc(focusEmoji)}"]`)?.focus();
|
|
162
|
-
else if (focusAdd) root.querySelector<HTMLElement>('[data-kit-add]')?.focus();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
111
|
return {
|
|
166
|
-
|
|
167
|
-
root =
|
|
168
|
-
?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
|
|
169
|
-
?? ctx.host;
|
|
112
|
+
attach(rootEl) {
|
|
113
|
+
root = rootEl;
|
|
170
114
|
const r = root;
|
|
171
115
|
const onClick = (event: Event): void => {
|
|
172
116
|
const t = event.target as HTMLElement | null;
|
|
@@ -174,7 +118,7 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
174
118
|
if (pill) { toggle(pill.getAttribute('data-kit-reaction') ?? ''); return; }
|
|
175
119
|
if (t?.closest('[data-kit-add]')) {
|
|
176
120
|
panelOpen = !panelOpen;
|
|
177
|
-
|
|
121
|
+
api.refresh();
|
|
178
122
|
if (panelOpen) queryWithDropdowns(r, '[data-kit-choice]')?.focus();
|
|
179
123
|
return;
|
|
180
124
|
}
|
|
@@ -182,7 +126,7 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
182
126
|
if (choice) {
|
|
183
127
|
const emoji = choice.getAttribute('data-kit-choice') ?? '';
|
|
184
128
|
panelOpen = false;
|
|
185
|
-
if (reactionsOf(P().data).some((x) => x.emoji === emoji)) toggle(emoji); else {
|
|
129
|
+
if (reactionsOf(P().data).some((x) => x.emoji === emoji)) toggle(emoji); else { api.refresh(); api.emit('add', { emoji }); }
|
|
186
130
|
r.querySelector<HTMLElement>('[data-kit-add]')?.focus();
|
|
187
131
|
}
|
|
188
132
|
};
|
|
@@ -211,26 +155,73 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
211
155
|
r.addEventListener('click', onClick);
|
|
212
156
|
r.addEventListener('keydown', onKeydown as EventListener);
|
|
213
157
|
document.addEventListener('pointerdown', onDocDown);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
158
|
+
return () => {
|
|
159
|
+
r.removeEventListener('click', onClick);
|
|
160
|
+
r.removeEventListener('keydown', onKeydown as EventListener);
|
|
161
|
+
document.removeEventListener('pointerdown', onDocDown);
|
|
162
|
+
flipped.clear();
|
|
163
|
+
if (root) releaseDropdownsIn(root);
|
|
164
|
+
panelClick = null;
|
|
165
|
+
panelKeydown = null;
|
|
166
|
+
root = null;
|
|
167
|
+
};
|
|
223
168
|
},
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
flipped.clear();
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
169
|
+
render(rootEl, p) {
|
|
170
|
+
root = rootEl;
|
|
171
|
+
const dataSig = JSON.stringify(reactionsOf(p.data));
|
|
172
|
+
if (dataSig !== sig) { sig = dataSig; flipped.clear(); }
|
|
173
|
+
root.className = joinClass(ROOT_CLASS, p.class);
|
|
174
|
+
// 整条重建会丢焦点(键盘点药丸 / 「+」后):记下焦点所在,重绘后落回同一个
|
|
175
|
+
const focused = root.contains(document.activeElement) ? document.activeElement as HTMLElement : null;
|
|
176
|
+
const focusEmoji = focused?.closest('[data-kit-reaction]')?.getAttribute('data-kit-reaction') ?? null;
|
|
177
|
+
const focusAdd = focused?.closest('[data-kit-add]') != null;
|
|
178
|
+
releaseDropdownsIn(root);
|
|
179
|
+
root.textContent = '';
|
|
180
|
+
const disabled = bool(p.disabled);
|
|
181
|
+
for (const r of view()) {
|
|
182
|
+
const b = mk('button', r.mine ? PILL_MINE : PILL_CLASS);
|
|
183
|
+
b.type = 'button';
|
|
184
|
+
setKitFace(b, 'raised');
|
|
185
|
+
b.setAttribute('data-kit-reaction', r.emoji);
|
|
186
|
+
b.setAttribute('aria-pressed', r.mine ? 'true' : 'false');
|
|
187
|
+
b.setAttribute('aria-label', `${r.label !== '' ? r.label : r.emoji} ${r.count}`);
|
|
188
|
+
if (disabled) { b.disabled = true; b.setAttribute('aria-disabled', 'true'); }
|
|
189
|
+
b.appendChild(mk('span', '', r.emoji));
|
|
190
|
+
b.appendChild(mk('span', '', String(r.count)));
|
|
191
|
+
root.appendChild(b);
|
|
192
|
+
}
|
|
193
|
+
if (bool(p.addable) && !disabled && view().length < REACTION_MAX_KINDS) {
|
|
194
|
+
const add = mk('button', ADD_CLASS, '+');
|
|
195
|
+
add.type = 'button';
|
|
196
|
+
add.setAttribute('data-kit-add', '');
|
|
197
|
+
add.setAttribute('aria-label', str(p.add_text, kitText('soma.kit.add_reaction', undefined, root)));
|
|
198
|
+
add.setAttribute('aria-haspopup', 'true');
|
|
199
|
+
add.setAttribute('aria-expanded', panelOpen ? 'true' : 'false');
|
|
200
|
+
root.appendChild(add);
|
|
201
|
+
if (panelOpen) {
|
|
202
|
+
const panel = mk('div', PANEL_CLASS);
|
|
203
|
+
panel.setAttribute('role', 'group');
|
|
204
|
+
panel.setAttribute('aria-label', str(p.add_text, kitText('soma.kit.add_reaction', undefined, root)));
|
|
205
|
+
panel.setAttribute('data-kit-panel', '');
|
|
206
|
+
palette().forEach((e, i) => {
|
|
207
|
+
const c = mk('button', CHOICE_CLASS, e);
|
|
208
|
+
c.type = 'button';
|
|
209
|
+
c.setAttribute('data-kit-choice', e);
|
|
210
|
+
c.tabIndex = i === 0 ? 0 : -1;
|
|
211
|
+
panel.appendChild(c);
|
|
212
|
+
});
|
|
213
|
+
root.appendChild(panel);
|
|
214
|
+
syncDropdown(panel, true, PANEL_BASE_CLASS, root);
|
|
215
|
+
if (!root.contains(panel)) {
|
|
216
|
+
if (panelClick) panel.addEventListener('click', panelClick);
|
|
217
|
+
if (panelKeydown) panel.addEventListener('keydown', panelKeydown);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (focusEmoji !== null) root.querySelector<HTMLElement>(`[data-kit-reaction="${attrEsc(focusEmoji)}"]`)?.focus();
|
|
222
|
+
else if (focusAdd) root.querySelector<HTMLElement>('[data-kit-add]')?.focus();
|
|
232
223
|
},
|
|
233
224
|
};
|
|
234
|
-
},
|
|
225
|
+
}),
|
|
235
226
|
};
|
|
236
227
|
}
|