soma-kit 0.1.10 → 0.1.12
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 +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -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 +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- 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 +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- 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 +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- 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 +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- 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 +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- 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/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -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 +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- 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/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- 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 +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -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 +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- 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 +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- 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 +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- 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 +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -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 +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -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 +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -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/data/prompt-dialog.ts +0 -235
- 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 -1278
package/src/data/pager.ts
CHANGED
|
@@ -5,21 +5,24 @@
|
|
|
5
5
|
// 页面接一行 `<id>.change: SCOPE | window-reload | <scope>` 重取。没有 scope(或端口不可用)时只上抛 change。
|
|
6
6
|
// 总数 total 由页面从列表响应(`into: result` 之后的 `result.total`)绑进来。
|
|
7
7
|
|
|
8
|
-
import type {
|
|
8
|
+
import type { SomaComponentDefinition, SomaRegionPort } from 'soma-core';
|
|
9
9
|
import { SOMA_QUERY_LIMITS_CORE } from 'soma-foundation/data/generated';
|
|
10
10
|
import { KIT_COLLECTION_LIMITS } from 'soma-foundation/kit-limits';
|
|
11
11
|
import { kitIcon } from '../base/icons';
|
|
12
|
-
import { applyDisabled,
|
|
12
|
+
import { applyDisabled, createKitController, joinClass, num, str } from '../base/shared';
|
|
13
13
|
import { attachSpin, type SpinHandle } from '../base/qty-stepper';
|
|
14
|
+
import { isImeComposing } from '../base/popup';
|
|
14
15
|
import { kitText } from '../i18n/kit-text';
|
|
16
|
+
import { setKitFace } from '../recipes';
|
|
15
17
|
import { createKitEmbedBag, mountKitSelectField, type KitSelectField } from './embed';
|
|
18
|
+
import { createReadRollback } from './read-rollback';
|
|
16
19
|
import { KIT_LISTBOX_CLASS_CANDIDATES } from '../base/listbox-core';
|
|
17
20
|
|
|
18
21
|
const BUTTON_CLASS = 'inline-flex h-9 items-center justify-center rounded-md border border-border bg-surface px-3 text-sm font-medium text-fg transition-colors hover:bg-surface-sunken active:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
19
22
|
/** 页长下拉槽(里面是命令式嵌入的自绘 Select)与 Select 根上的宽度类 */
|
|
20
23
|
const SELECT_SLOT_CLASS = 'w-36';
|
|
21
24
|
const SELECT_WIDTH = 'w-full';
|
|
22
|
-
const INPUT_CLASS = 'appearance-none autofill-clear h-9 w-
|
|
25
|
+
const INPUT_CLASS = 'appearance-none autofill-clear h-9 w-16 rounded-md border border-border bg-surface px-3 text-sm text-fg transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
23
26
|
const ROOT_CLASS = 'flex flex-wrap items-center justify-between gap-3 text-sm text-fg';
|
|
24
27
|
const GROUP_CLASS = 'flex flex-wrap items-center gap-2';
|
|
25
28
|
const MUTED_CLASS = 'text-fg-muted';
|
|
@@ -54,7 +57,7 @@ export function pageSequence(page: number, pages: number, slots: number): PagerS
|
|
|
54
57
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
55
58
|
export const KIT_PAGER_CLASS_CANDIDATES: readonly string[] = Object.freeze([
|
|
56
59
|
'appearance-none', 'autofill-clear', 'flex', 'flex-wrap', 'items-center', 'justify-between', 'gap-3', 'gap-2', 'text-sm', 'text-fg', 'text-fg-muted',
|
|
57
|
-
'inline-flex', 'h-9', 'justify-center', 'rounded-md', 'border', 'border-border', 'bg-surface', 'px-3', 'px-2', 'w-
|
|
60
|
+
'inline-flex', 'h-9', 'justify-center', 'rounded-md', 'border', 'border-border', 'bg-surface', 'px-3', 'px-2', 'w-16',
|
|
58
61
|
'hover:bg-surface-sunken', 'focus-visible:outline-none', 'focus-visible:ring-2', 'focus-visible:ring-ring',
|
|
59
62
|
'disabled:cursor-not-allowed', 'disabled:opacity-60',
|
|
60
63
|
'font-medium', 'transition-colors', 'active:opacity-80', 'hidden',
|
|
@@ -111,15 +114,15 @@ function numList(raw: unknown): number[] {
|
|
|
111
114
|
const TEMPLATE = `<div data-soma-id="root" class="${ROOT_CLASS}">`
|
|
112
115
|
+ `<span data-soma-id="total" class="${MUTED_CLASS}"></span>`
|
|
113
116
|
+ `<div data-soma-id="bar" class="${GROUP_CLASS}">`
|
|
114
|
-
+ `<button data-soma-id="prev" type="button" class="${BUTTON_CLASS}"></button>`
|
|
117
|
+
+ `<button data-soma-id="prev" type="button" data-kit-face="raised" class="${BUTTON_CLASS}"></button>`
|
|
115
118
|
+ '<span data-soma-id="pages" class="hidden"></span>'
|
|
116
119
|
+ `<span data-soma-id="status"></span>`
|
|
117
|
-
+ `<button data-soma-id="next" type="button" class="${BUTTON_CLASS}"></button>`
|
|
120
|
+
+ `<button data-soma-id="next" type="button" data-kit-face="raised" class="${BUTTON_CLASS}"></button>`
|
|
118
121
|
+ `<div data-soma-id="size" class="hidden"></div>`
|
|
119
122
|
+ `<label data-soma-id="jumpbox" class="${GROUP_CLASS}"><span data-soma-id="jumplabel" class="${MUTED_CLASS}"></span>`
|
|
120
|
-
+ `<input data-soma-id="jump" type="text" inputmode="decimal" role="spinbutton" autocomplete="off" class="${INPUT_CLASS}" /></label>`
|
|
123
|
+
+ `<input data-soma-id="jump" type="text" inputmode="decimal" role="spinbutton" autocomplete="off" data-kit-face="field" class="${INPUT_CLASS}" /></label>`
|
|
121
124
|
+ '</div>'
|
|
122
|
-
+ `<div data-soma-id="morebar" class="hidden"><button data-soma-id="more" type="button" class="${BUTTON_CLASS}"></button>`
|
|
125
|
+
+ `<div data-soma-id="morebar" class="hidden"><button data-soma-id="more" type="button" data-kit-face="raised" class="${BUTTON_CLASS}"></button>`
|
|
123
126
|
+ `<span data-soma-id="moretip" class="${MUTED_CLASS}"></span></div>`
|
|
124
127
|
+ '<div data-soma-id="sentinel" class="hidden" aria-hidden="true"></div>'
|
|
125
128
|
+ '</div>';
|
|
@@ -143,6 +146,7 @@ export function createPager(): SomaComponentDefinition {
|
|
|
143
146
|
layout: { type: 'string', default: '', desc: '版式(闭集 simple / pages / full,仅 mode: pager):simple = 上一页 / 第几页 / 下一页;pages = 上一页 + 页码序列(首尾页、当前页高亮、省略号折叠,键盘左右键移动、当前页 aria-current)+ 下一页;full = pages + 页长选择(sizes 多于一档时)+ 跳页;缺省 = 状态文字版式(状态文字,页长 / 跳页按各自 prop)' },
|
|
144
147
|
show_total: { type: 'boolean', default: true, desc: '显示「共 N 条」;false 时不显示总数' },
|
|
145
148
|
scope: { type: 'string', default: '', desc: '区域作用域 id;给了就把 { page, size } 写进 view 切片' },
|
|
149
|
+
readState: { type: 'string', default: '', desc: '列表对象的读状态,用于失败回滚' },
|
|
146
150
|
class: { type: 'string', default: '', desc: '外部传入的类,追加在根节点类串末尾' },
|
|
147
151
|
},
|
|
148
152
|
emits: {
|
|
@@ -152,11 +156,13 @@ export function createPager(): SomaComponentDefinition {
|
|
|
152
156
|
},
|
|
153
157
|
services: ['region'],
|
|
154
158
|
templateHtml: TEMPLATE,
|
|
155
|
-
controllerFactory: (
|
|
156
|
-
const P = (): Record<string, unknown> =>
|
|
159
|
+
controllerFactory: createKitController((api) => {
|
|
160
|
+
const P = (): Record<string, unknown> => api.props();
|
|
157
161
|
let root: HTMLElement | null = null;
|
|
158
162
|
let page = 1;
|
|
159
163
|
let size = 0;
|
|
164
|
+
let lastEmittedPage: number | undefined;
|
|
165
|
+
let lastEmittedSize: number | undefined;
|
|
160
166
|
let cleanup: Array<() => void> = [];
|
|
161
167
|
// 页长下拉是命令式嵌入的自绘 Select:卸载时经释放袋统一收起浮层、解绑监听
|
|
162
168
|
const embeds = createKitEmbedBag();
|
|
@@ -167,7 +173,7 @@ export function createPager(): SomaComponentDefinition {
|
|
|
167
173
|
|
|
168
174
|
const port = (): SomaRegionPort | null => {
|
|
169
175
|
const scope = str(P().scope);
|
|
170
|
-
const svc = (
|
|
176
|
+
const svc = (api.services as { region?: (id: string) => SomaRegionPort | null } | undefined)?.region;
|
|
171
177
|
return scope !== '' && typeof svc === 'function' ? svc(scope) : null;
|
|
172
178
|
};
|
|
173
179
|
|
|
@@ -233,25 +239,53 @@ export function createPager(): SomaComponentDefinition {
|
|
|
233
239
|
const wanted = page;
|
|
234
240
|
if (page > pages) page = pages;
|
|
235
241
|
if (page < 1) page = 1;
|
|
236
|
-
// 总数缩小把页码夹住后写回 view
|
|
237
|
-
// total 为 0
|
|
238
|
-
|
|
242
|
+
// 总数缩小把页码夹住后写回 view 切片或派发 change 事件,取数用的才是合法页码。
|
|
243
|
+
// total 为 0 维持现有语义:视为「数据还没到」,不写也不派发(否则会把切片或宿主持有的页码冲成 1);
|
|
244
|
+
// 只有在页码被夹回(page !== wanted)且 total > 0 时处理。
|
|
245
|
+
if (page !== wanted && totalOf() > 0) {
|
|
246
|
+
if (pageHeld !== page) port()?.slice('view')?.set(page, 'page');
|
|
247
|
+
// 无 scope 模式(或未通过切片写回)下,页码被夹回时派发一次 change,通知宿主更新页码避免停留在空页;
|
|
248
|
+
// 只在派发的值变化时派发一次,防止宿主重渲染回环。
|
|
249
|
+
if (page !== lastEmittedPage || size !== lastEmittedSize) {
|
|
250
|
+
lastEmittedPage = page;
|
|
251
|
+
lastEmittedSize = size;
|
|
252
|
+
api.emit('change', { page, size });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
239
255
|
};
|
|
240
256
|
|
|
241
257
|
const totalOf = (): number => Math.max(0, Math.floor(num(P().total) ?? 0));
|
|
242
258
|
const pageCount = (): number => Math.max(1, Math.ceil(totalOf() / Math.max(1, size)));
|
|
243
259
|
|
|
260
|
+
// 重取失败回滚:翻页写了切片而重取失败时,把页码 / 页长写回最近一次读成功的值(只写切片,不抛 change)
|
|
261
|
+
const rollback = createReadRollback<{ page: number; size: number }>({
|
|
262
|
+
readState: () => str(P().readState),
|
|
263
|
+
snapshot: () => ({ page, size }),
|
|
264
|
+
restore: (v) => {
|
|
265
|
+
page = v.page;
|
|
266
|
+
size = v.size;
|
|
267
|
+
const view = port()?.slice('view');
|
|
268
|
+
view?.set(page, 'page');
|
|
269
|
+
view?.set(size, 'size');
|
|
270
|
+
lastEmittedPage = page;
|
|
271
|
+
lastEmittedSize = size;
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
|
|
244
275
|
const commit = (nextPage: number, nextSize: number): void => {
|
|
245
276
|
const pages = Math.max(1, Math.ceil(totalOf() / Math.max(1, nextSize)));
|
|
246
277
|
const clamped = Math.min(Math.max(1, Math.floor(nextPage)), pages);
|
|
247
278
|
if (clamped === page && nextSize === size) return;
|
|
279
|
+
rollback.beforeCommit();
|
|
248
280
|
page = clamped;
|
|
249
281
|
size = nextSize;
|
|
250
282
|
// 分路径写:整槽 set 会把表头写的 sort / order 冲掉
|
|
251
283
|
const view = port()?.slice('view');
|
|
252
284
|
view?.set(page, 'page');
|
|
253
285
|
view?.set(size, 'size');
|
|
254
|
-
|
|
286
|
+
lastEmittedPage = page;
|
|
287
|
+
lastEmittedSize = size;
|
|
288
|
+
api.emit('change', { page, size });
|
|
255
289
|
paint();
|
|
256
290
|
};
|
|
257
291
|
|
|
@@ -275,6 +309,8 @@ export function createPager(): SomaComponentDefinition {
|
|
|
275
309
|
btn.setAttribute('aria-label', kitText('soma.kit.go_page', { n: slot }, root));
|
|
276
310
|
if (current) btn.setAttribute('aria-current', 'page');
|
|
277
311
|
btn.className = current ? PAGE_CUR_CLASS : PAGE_BTN_CLASS;
|
|
312
|
+
// 当前页是主色柔底(有面)标 raised;其余页钮无边无底(ghost)不标
|
|
313
|
+
if (current) setKitFace(btn, 'raised');
|
|
278
314
|
btn.textContent = String(slot);
|
|
279
315
|
} else {
|
|
280
316
|
btn.setAttribute('data-kit-jump', slot);
|
|
@@ -378,9 +414,8 @@ export function createPager(): SomaComponentDefinition {
|
|
|
378
414
|
};
|
|
379
415
|
|
|
380
416
|
return {
|
|
381
|
-
|
|
382
|
-
root =
|
|
383
|
-
sync();
|
|
417
|
+
attach(rootEl) {
|
|
418
|
+
root = rootEl;
|
|
384
419
|
const prev = part(root, 'prev');
|
|
385
420
|
const next = part(root, 'next');
|
|
386
421
|
const jump = part<HTMLInputElement>(root, 'jump');
|
|
@@ -388,7 +423,7 @@ export function createPager(): SomaComponentDefinition {
|
|
|
388
423
|
const onPrev = (): void => commit(page - 1, size);
|
|
389
424
|
const onNext = (): void => commit(page + 1, size);
|
|
390
425
|
const onJump = (event: KeyboardEvent): void => {
|
|
391
|
-
if (event.key !== 'Enter') return;
|
|
426
|
+
if (event.key !== 'Enter' || isImeComposing(event)) return;
|
|
392
427
|
const n = num(jump?.value);
|
|
393
428
|
if (n !== null) commit(n, size);
|
|
394
429
|
};
|
|
@@ -441,17 +476,24 @@ export function createPager(): SomaComponentDefinition {
|
|
|
441
476
|
() => pagesBox?.removeEventListener('keydown', onPagesKey as EventListener),
|
|
442
477
|
() => prev?.removeEventListener('click', onPrev),
|
|
443
478
|
() => next?.removeEventListener('click', onNext),
|
|
444
|
-
() => { embeds.release(root); sizeSelect = null; sizeKey = ''; },
|
|
479
|
+
() => { embeds.release(root!); sizeSelect = null; sizeKey = ''; },
|
|
445
480
|
() => jump?.removeEventListener('keydown', onJump as EventListener),
|
|
446
481
|
() => { jumpSpin?.destroy(); jumpSpin = null; },
|
|
447
482
|
];
|
|
448
483
|
subscribeScope();
|
|
449
|
-
|
|
484
|
+
return () => {
|
|
485
|
+
for (const fn of cleanup) fn();
|
|
486
|
+
cleanup = [];
|
|
487
|
+
unsubscribeScope();
|
|
488
|
+
root = null;
|
|
489
|
+
};
|
|
450
490
|
},
|
|
451
|
-
|
|
491
|
+
render(rootEl) {
|
|
492
|
+
root = rootEl;
|
|
452
493
|
// scope 变了:退订旧 scope、订阅新 scope,再按新切片同步页码页长
|
|
453
494
|
if (str(P().scope) !== subScope) subscribeScope();
|
|
454
495
|
sync();
|
|
496
|
+
rollback.onProps();
|
|
455
497
|
paint();
|
|
456
498
|
// 新数据到了:放开节流;哨兵若仍在视口内(内容不够长)重新观察一次,才会继续加载
|
|
457
499
|
busy = false;
|
|
@@ -460,13 +502,7 @@ export function createPager(): SomaComponentDefinition {
|
|
|
460
502
|
if (sentinel) { observer.unobserve(sentinel); observer.observe(sentinel); }
|
|
461
503
|
}
|
|
462
504
|
},
|
|
463
|
-
onUnmount(): void {
|
|
464
|
-
for (const fn of cleanup) fn();
|
|
465
|
-
cleanup = [];
|
|
466
|
-
unsubscribeScope();
|
|
467
|
-
root = null;
|
|
468
|
-
},
|
|
469
505
|
};
|
|
470
|
-
},
|
|
506
|
+
}),
|
|
471
507
|
};
|
|
472
508
|
}
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
// 任何一次改动抛 `change { value, role?, resource?, on }`:value 是改动后的完整 grants(每个资源的角色键按 roles 顺序排列,
|
|
10
10
|
// readonly 角色的键原样保留);单格改动带 role + resource,整行改动只带 resource,整列改动只带 role。
|
|
11
11
|
|
|
12
|
-
import type {
|
|
13
|
-
import { bool,
|
|
12
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
|
+
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
14
14
|
import { kitIcon, type KitIconName } from '../base/icons';
|
|
15
15
|
import { kitText } from '../i18n/kit-text';
|
|
16
|
+
import { setKitFace } from '../recipes';
|
|
16
17
|
import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
17
18
|
|
|
18
19
|
// ── 数据规整纯函数:键名对照、三态、data 解析、授权表规整 ──
|
|
@@ -179,8 +180,8 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
179
180
|
},
|
|
180
181
|
},
|
|
181
182
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
182
|
-
controllerFactory: (
|
|
183
|
-
const P = (): Record<string, unknown> =>
|
|
183
|
+
controllerFactory: createKitController((api) => {
|
|
184
|
+
const P = (): Record<string, unknown> => api.props();
|
|
184
185
|
let root: HTMLElement | null = null;
|
|
185
186
|
let roles: KitPermissionRole[] = [];
|
|
186
187
|
let resources: KitPermissionResource[] = [];
|
|
@@ -188,7 +189,6 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
188
189
|
let origin: KitPermissionGrants = {};
|
|
189
190
|
let sig = '';
|
|
190
191
|
let foot: HTMLElement | null = null;
|
|
191
|
-
let cleanup: (() => void) | undefined;
|
|
192
192
|
|
|
193
193
|
const locked = (): boolean => bool(P().disabled);
|
|
194
194
|
const kb = createKitBusy(P);
|
|
@@ -220,7 +220,7 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
220
220
|
const emitChange = (extra: { role?: string; resource?: string; on: boolean }): void => {
|
|
221
221
|
grants = normalizeGrants(grants, roles, resources);
|
|
222
222
|
paint();
|
|
223
|
-
|
|
223
|
+
api.emit('change', { value: JSON.parse(JSON.stringify(grants)) as KitPermissionGrants, ...extra });
|
|
224
224
|
};
|
|
225
225
|
|
|
226
226
|
const toggleCell = (res: string, role: string): void => {
|
|
@@ -370,12 +370,14 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
370
370
|
if (cancelLabel !== '') {
|
|
371
371
|
const c = el('button', CANCEL_CLASS, cancelLabel);
|
|
372
372
|
c.type = 'button';
|
|
373
|
+
setKitFace(c, 'raised');
|
|
373
374
|
c.setAttribute('data-kit-cancel', '');
|
|
374
375
|
foot.appendChild(c);
|
|
375
376
|
}
|
|
376
377
|
if (saveLabel !== '') {
|
|
377
378
|
const s = el('button', SAVE_CLASS, saveLabel);
|
|
378
379
|
s.type = 'button';
|
|
380
|
+
setKitFace(s, 'raised');
|
|
379
381
|
s.setAttribute('data-kit-save', '');
|
|
380
382
|
kb.paint(s, locked());
|
|
381
383
|
foot.appendChild(s);
|
|
@@ -384,22 +386,21 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
384
386
|
}
|
|
385
387
|
|
|
386
388
|
return {
|
|
387
|
-
|
|
388
|
-
root =
|
|
389
|
-
sync();
|
|
389
|
+
attach(rootEl) {
|
|
390
|
+
root = rootEl;
|
|
390
391
|
const r = root;
|
|
391
392
|
const onClick = (event: Event): void => {
|
|
392
393
|
const target = event.target as HTMLElement | null;
|
|
393
394
|
if (target?.closest('[data-kit-cancel]')) {
|
|
394
395
|
grants = JSON.parse(JSON.stringify(origin)) as KitPermissionGrants;
|
|
395
396
|
paint();
|
|
396
|
-
|
|
397
|
+
api.emit('cancel', {});
|
|
397
398
|
return;
|
|
398
399
|
}
|
|
399
400
|
if (target?.closest('[data-kit-save]')) {
|
|
400
401
|
if (locked() || kb.busy()) return;
|
|
401
402
|
const value = JSON.parse(JSON.stringify(normalizeGrants(grants, roles, resources))) as KitPermissionGrants;
|
|
402
|
-
|
|
403
|
+
api.emit('saved', { values: { value }, object: str(P().object), model: { value }, mode: str(P().mode, 'edit'), value });
|
|
403
404
|
return;
|
|
404
405
|
}
|
|
405
406
|
const btn = target?.closest<HTMLButtonElement>('[data-kit-act]');
|
|
@@ -412,21 +413,19 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
412
413
|
else if (act === 'col') toggleCol(role);
|
|
413
414
|
};
|
|
414
415
|
r.addEventListener('click', onClick);
|
|
415
|
-
cleanup = () => r.removeEventListener('click', onClick);
|
|
416
|
-
paint();
|
|
417
416
|
kb.subscribe(() => { if (root) paint(); });
|
|
417
|
+
return () => {
|
|
418
|
+
kb.dispose();
|
|
419
|
+
r.removeEventListener('click', onClick);
|
|
420
|
+
root = null;
|
|
421
|
+
};
|
|
418
422
|
},
|
|
419
|
-
|
|
423
|
+
render(rootEl) {
|
|
424
|
+
root = rootEl;
|
|
420
425
|
sync();
|
|
421
426
|
paint();
|
|
422
427
|
},
|
|
423
|
-
onUnmount(): void {
|
|
424
|
-
kb.dispose();
|
|
425
|
-
if (cleanup) cleanup();
|
|
426
|
-
cleanup = undefined;
|
|
427
|
-
root = null;
|
|
428
|
-
},
|
|
429
428
|
};
|
|
430
|
-
},
|
|
429
|
+
}),
|
|
431
430
|
};
|
|
432
431
|
}
|
|
@@ -31,12 +31,13 @@
|
|
|
31
31
|
// 每次勾选抛 `change { value, added, removed }`;save_label 非空时底部出现保存钮,抛 `saved`(载荷同对象表单,另带 added / removed);
|
|
32
32
|
// 勾中了「未登记」节点时拒绝保存,抛 `blocked { reason: 'unregistered', ids }`;cancel_label 非空时出现取消钮,抛 `cancel {}` 并还原草稿。
|
|
33
33
|
|
|
34
|
-
import type {
|
|
34
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
35
35
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
36
36
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
37
|
-
import { bool,
|
|
37
|
+
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
38
38
|
import { kitIcon } from '../base/icons';
|
|
39
39
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
40
|
+
import { setKitFace } from '../recipes';
|
|
40
41
|
import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
41
42
|
import { classTokens, keyMap, mk, recOf } from './shape-util';
|
|
42
43
|
import { KIT_TREE_MAX_DEPTH } from './tree';
|
|
@@ -55,7 +56,7 @@ const HEAD_CLASS = 'flex items-center justify-between gap-3';
|
|
|
55
56
|
const TITLE_CLASS = 'text-base font-semibold text-fg';
|
|
56
57
|
const SUMMARY_CLASS = 'text-sm text-fg-muted';
|
|
57
58
|
const CHANGES_CLASS = 'flex flex-wrap items-center gap-2 text-sm text-fg-muted';
|
|
58
|
-
const LINK_CLASS = 'rounded-md px-1 text-sm text-primary transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
59
|
+
const LINK_CLASS = 'rounded-md px-1 text-sm text-primary-on-soft transition-colors hover:bg-surface-sunken focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
59
60
|
const DETAIL_CLASS = 'flex flex-col gap-1 rounded-md bg-surface-sunken px-3 py-2 text-sm text-fg';
|
|
60
61
|
const DETAIL_ADDED_CLASS = 'text-success-on-soft';
|
|
61
62
|
const DETAIL_REMOVED_CLASS = 'text-danger-on-soft';
|
|
@@ -456,8 +457,8 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
456
457
|
keyboard: { layout: 'tree', wrap: false, typeahead: false, focus_model: 'roving', space: 'toggle_select' },
|
|
457
458
|
},
|
|
458
459
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
459
|
-
controllerFactory: (
|
|
460
|
-
const P = (): Record<string, unknown> =>
|
|
460
|
+
controllerFactory: createKitController((api) => {
|
|
461
|
+
const P = (): Record<string, unknown> => api.props();
|
|
461
462
|
const uid = `kit-ptree-${++instanceCount}`;
|
|
462
463
|
let root: HTMLElement | null = null;
|
|
463
464
|
let model: KitPermModel = { nodes: [], byId: new Map() };
|
|
@@ -483,7 +484,7 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
483
484
|
let saveBtn: HTMLButtonElement; let cancelBtn: HTMLButtonElement;
|
|
484
485
|
let error = '';
|
|
485
486
|
|
|
486
|
-
const T = (): KitPermissionTreeTexts => textsOf(P().texts,
|
|
487
|
+
const T = (): KitPermissionTreeTexts => textsOf(P().texts, api.host);
|
|
487
488
|
const locked = (): boolean => bool(P().disabled);
|
|
488
489
|
const strict = (): boolean => bool(P().strict);
|
|
489
490
|
const mixedAction = (): 'clear' | 'select' => (P().mixed_action === 'select' ? 'select' : 'clear');
|
|
@@ -695,7 +696,7 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
695
696
|
|
|
696
697
|
const emitChange = (): void => {
|
|
697
698
|
const sum = state.summary();
|
|
698
|
-
|
|
699
|
+
api.emit('change', {
|
|
699
700
|
value: state.submitValue(keep),
|
|
700
701
|
added: sum.added.map((i) => model.nodes[i]!.id),
|
|
701
702
|
removed: sum.removed.map((i) => model.nodes[i]!.id),
|
|
@@ -791,10 +792,10 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
791
792
|
if (locked() || error !== '' || busy()) return;
|
|
792
793
|
const bad = state.unsubmittable();
|
|
793
794
|
if (bad.length > 0) {
|
|
794
|
-
const names = bad.map((i) => model.nodes[i]!.label).join(kitText('soma.kit.list_sep', undefined,
|
|
795
|
+
const names = bad.map((i) => model.nodes[i]!.label).join(kitText('soma.kit.list_sep', undefined, api.host));
|
|
795
796
|
notice = fill(T().invalid, { names });
|
|
796
797
|
paintHeader();
|
|
797
|
-
|
|
798
|
+
api.emit('blocked', { reason: 'unregistered', ids: bad.map((i) => model.nodes[i]!.id) });
|
|
798
799
|
return;
|
|
799
800
|
}
|
|
800
801
|
const sum = state.summary();
|
|
@@ -802,7 +803,7 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
802
803
|
const added = sum.added.map((i) => model.nodes[i]!.id);
|
|
803
804
|
const removed = sum.removed.map((i) => model.nodes[i]!.id);
|
|
804
805
|
const body = { value, added, removed };
|
|
805
|
-
|
|
806
|
+
api.emit('saved', { values: body, object: str(P().object), model: body, mode: str(P().mode, 'edit'), value, added, removed });
|
|
806
807
|
};
|
|
807
808
|
|
|
808
809
|
const build = (host: HTMLElement): void => {
|
|
@@ -823,6 +824,7 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
823
824
|
changesBox = mk('div', '');
|
|
824
825
|
changesBox.append(changesRow, detailBox);
|
|
825
826
|
search = mk('input', SEARCH_CLASS);
|
|
827
|
+
setKitFace(search, 'field');
|
|
826
828
|
search.type = 'search';
|
|
827
829
|
search.setAttribute('autocomplete', 'off');
|
|
828
830
|
searchBox = boxOf(search);
|
|
@@ -831,6 +833,7 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
831
833
|
collapseBtn = mk('button', TOOL_BTN_CLASS); collapseBtn.type = 'button';
|
|
832
834
|
allBtn = mk('button', TOOL_BTN_CLASS); allBtn.type = 'button';
|
|
833
835
|
clearBtn = mk('button', TOOL_BTN_CLASS); clearBtn.type = 'button';
|
|
836
|
+
for (const b of [expandBtn, collapseBtn, allBtn, clearBtn]) setKitFace(b, 'raised');
|
|
834
837
|
const bulkRow = mk('div', TOOLS_CLASS);
|
|
835
838
|
bulkRow.append(expandBtn, collapseBtn, allBtn, clearBtn);
|
|
836
839
|
bulkBox = boxOf(bulkRow);
|
|
@@ -840,6 +843,8 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
840
843
|
treeEl.setAttribute('role', 'tree');
|
|
841
844
|
cancelBtn = mk('button', CANCEL_CLASS); cancelBtn.type = 'button';
|
|
842
845
|
saveBtn = mk('button', SAVE_CLASS); saveBtn.type = 'button';
|
|
846
|
+
setKitFace(cancelBtn, 'raised');
|
|
847
|
+
setKitFace(saveBtn, 'raised');
|
|
843
848
|
cancelBox = boxOf(cancelBtn);
|
|
844
849
|
saveBox = boxOf(saveBtn);
|
|
845
850
|
const foot = mk('div', FOOT_CLASS);
|
|
@@ -882,35 +887,32 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
882
887
|
state.reset();
|
|
883
888
|
notice = '';
|
|
884
889
|
afterChange();
|
|
885
|
-
|
|
890
|
+
api.emit('cancel', {});
|
|
886
891
|
});
|
|
887
892
|
};
|
|
888
893
|
|
|
889
894
|
return {
|
|
890
|
-
|
|
891
|
-
root =
|
|
895
|
+
attach(rootEl) {
|
|
896
|
+
root = rootEl;
|
|
892
897
|
build(root);
|
|
893
|
-
sync();
|
|
894
|
-
renderTree();
|
|
895
|
-
paintHeader();
|
|
896
898
|
kb.subscribe(() => { if (root) paintHeader(); });
|
|
899
|
+
return () => {
|
|
900
|
+
kb.dispose();
|
|
901
|
+
for (const fn of removers) fn();
|
|
902
|
+
removers = [];
|
|
903
|
+
rowEls = new Map();
|
|
904
|
+
root = null;
|
|
905
|
+
};
|
|
897
906
|
},
|
|
898
|
-
|
|
899
|
-
|
|
907
|
+
render(rootEl) {
|
|
908
|
+
root = rootEl;
|
|
900
909
|
const before = sig;
|
|
901
910
|
sync();
|
|
902
911
|
if (sig !== before) renderTree();
|
|
903
912
|
paintHeader();
|
|
904
913
|
if (sig === before) patchRows();
|
|
905
914
|
},
|
|
906
|
-
onUnmount(): void {
|
|
907
|
-
kb.dispose();
|
|
908
|
-
for (const fn of removers) fn();
|
|
909
|
-
removers = [];
|
|
910
|
-
rowEls = new Map();
|
|
911
|
-
root = null;
|
|
912
|
-
},
|
|
913
915
|
};
|
|
914
|
-
},
|
|
916
|
+
}),
|
|
915
917
|
};
|
|
916
918
|
}
|
|
@@ -13,6 +13,7 @@ import type { SomaComponentDefinition } from 'soma-core';
|
|
|
13
13
|
import { createKitController, joinClass, str, type KitView } from '../base/shared';
|
|
14
14
|
import { kitIcon } from '../base/icons';
|
|
15
15
|
import { kitText } from '../i18n/kit-text';
|
|
16
|
+
import { setKitFace } from '../recipes';
|
|
16
17
|
import { classTokens, emptyNode, mk, recOf, rowsOf, textOf, type Rec } from './shape-util';
|
|
17
18
|
import { singleOf } from './display-util';
|
|
18
19
|
import { attrEsc } from './d9-util';
|
|
@@ -135,7 +136,6 @@ const stateOf = (root: HTMLElement): State => {
|
|
|
135
136
|
};
|
|
136
137
|
|
|
137
138
|
export function createPricingTable(): SomaComponentDefinition {
|
|
138
|
-
let self: KitView;
|
|
139
139
|
return {
|
|
140
140
|
contract: {
|
|
141
141
|
name: 'PricingTable',
|
|
@@ -157,8 +157,10 @@ export function createPricingTable(): SomaComponentDefinition {
|
|
|
157
157
|
},
|
|
158
158
|
},
|
|
159
159
|
templateHtml: `<section data-soma-id="root" class="${ROOT_CLASS}"></section>`,
|
|
160
|
-
controllerFactory: createKitController(
|
|
161
|
-
|
|
160
|
+
controllerFactory: createKitController((api) => {
|
|
161
|
+
let self: KitView;
|
|
162
|
+
return (self = {
|
|
163
|
+
attach(root) {
|
|
162
164
|
const s = stateOf(root);
|
|
163
165
|
const onClick = (event: Event): void => {
|
|
164
166
|
const t = event.target as HTMLElement | null;
|
|
@@ -171,6 +173,7 @@ export function createPricingTable(): SomaComponentDefinition {
|
|
|
171
173
|
for (const el of Array.from(root.querySelectorAll<HTMLElement>('[data-kit-cycle]'))) {
|
|
172
174
|
const on = el.getAttribute('data-kit-cycle') === key;
|
|
173
175
|
if (on) el.setAttribute('data-kit-selected', ''); else el.removeAttribute('data-kit-selected');
|
|
176
|
+
setKitFace(el, on ? 'raised' : null);
|
|
174
177
|
el.setAttribute('aria-pressed', on ? 'true' : 'false');
|
|
175
178
|
}
|
|
176
179
|
// 价格文案随周期换:整体重绘(周期条与卡片都在 render 里画)
|
|
@@ -220,6 +223,7 @@ export function createPricingTable(): SomaComponentDefinition {
|
|
|
220
223
|
const on = c.key === s.cycle;
|
|
221
224
|
btn.setAttribute('aria-pressed', on ? 'true' : 'false');
|
|
222
225
|
if (on) btn.setAttribute('data-kit-selected', '');
|
|
226
|
+
setKitFace(btn, on ? 'raised' : null); // 选中的周期钮才有底色 + shadow-sm(分段滑块式),未选中透明无面
|
|
223
227
|
btn.appendChild(mk('span', '', c.label));
|
|
224
228
|
if (c.note !== '') btn.appendChild(mk('span', NOTE_CLASS, c.note));
|
|
225
229
|
bar.appendChild(btn);
|
|
@@ -257,6 +261,7 @@ export function createPricingTable(): SomaComponentDefinition {
|
|
|
257
261
|
card.appendChild(ul);
|
|
258
262
|
const btn = mk('button', plan.recommended ? ACTION_CLASS : ACTION_PLAIN_CLASS, plan.actionText || str(p.action_text, kitText('soma.kit.pt_choose', undefined, root)));
|
|
259
263
|
btn.type = 'button';
|
|
264
|
+
setKitFace(btn, 'raised');
|
|
260
265
|
btn.setAttribute('data-kit-plan-action', plan.key);
|
|
261
266
|
if (isCurrent || plan.disabled) { btn.disabled = true; btn.setAttribute('aria-disabled', 'true'); }
|
|
262
267
|
card.appendChild(btn);
|
|
@@ -264,6 +269,7 @@ export function createPricingTable(): SomaComponentDefinition {
|
|
|
264
269
|
}
|
|
265
270
|
root.appendChild(grid);
|
|
266
271
|
},
|
|
272
|
+
});
|
|
267
273
|
}),
|
|
268
274
|
};
|
|
269
275
|
}
|