soma-kit 0.1.12 → 0.1.14
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 +5 -4
- package/bin/soma-kit.mjs +31 -1
- package/bin/soma.mjs +0 -0
- package/package.json +5 -4
- package/spec/generated/kit-app.schema.json +172 -4
- package/spec/generated/kit-page.schema.json +164 -5
- package/spec/kit-grammar.json +598 -96
- package/spec/kit-grammar.schema.json +12 -6
- package/src/app/app-config.ts +92 -8
- package/src/app/component-gate.ts +271 -13
- package/src/app/define-kit-app.ts +2 -2
- package/src/app/define-kit-view.ts +9 -5
- package/src/app/dev-diagnostic.ts +5 -0
- package/src/app/index.ts +29 -5
- package/src/app/kit-view-context.ts +181 -15
- package/src/app/render-ports.ts +18 -0
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +55 -8
- package/src/app/theme-runtime.ts +4 -0
- package/src/base/action-busy.ts +101 -4
- package/src/base/action-slots.ts +13 -2
- package/src/base/anchored-layer.ts +50 -0
- package/src/base/button.ts +62 -15
- package/src/base/check-core.ts +8 -0
- package/src/base/checkbox.ts +2 -1
- package/src/base/choice.ts +21 -2
- package/src/base/color-picker.ts +10 -5
- package/src/base/command-palette.ts +1 -1
- package/src/base/context-menu.ts +10 -7
- package/src/base/date-range.ts +7 -7
- package/src/base/date.ts +55 -16
- package/src/base/delta.ts +72 -0
- package/src/base/end-edge.ts +61 -0
- package/src/base/fab.ts +1 -1
- package/src/base/gap-value.ts +168 -0
- package/src/base/hint-tips.ts +170 -0
- package/src/base/icons.ts +8 -0
- package/src/base/illustrations.ts +95 -0
- package/src/base/index.ts +32 -9
- package/src/base/listbox-core.ts +6 -5
- package/src/base/loading-gate.ts +140 -87
- package/src/base/mentions.ts +2 -1
- package/src/base/menu-button.ts +16 -18
- package/src/base/menu-core.ts +37 -8
- package/src/base/motion/hover-3d.ts +1 -1
- package/src/base/motion/marquee.ts +1 -1
- package/src/base/otp.ts +5 -4
- package/src/base/overlay-runtime.ts +235 -0
- package/src/base/popover.ts +10 -9
- package/src/base/popup.ts +67 -8
- package/src/base/portal-core.ts +4 -0
- package/src/base/qty-stepper.ts +5 -5
- package/src/base/radio.ts +2 -1
- package/src/base/range.ts +19 -2
- package/src/base/rating.ts +11 -6
- package/src/base/reason-tip.ts +150 -0
- package/src/base/segmented.ts +36 -24
- package/src/base/shared.ts +180 -36
- package/src/base/state-panel.ts +367 -0
- package/src/base/status-tone.ts +27 -0
- package/src/base/sticky-edge.ts +116 -0
- package/src/base/swap.ts +6 -6
- package/src/base/switch.ts +10 -5
- package/src/base/tag-input.ts +6 -6
- package/src/base/tag.ts +76 -41
- package/src/base/text.ts +43 -14
- package/src/base/time-picker.ts +7 -5
- package/src/base/tree-select.ts +6 -4
- package/src/base/trend-tone.ts +9 -0
- package/src/base/upload.ts +15 -9
- package/src/base/view-transition.ts +77 -0
- package/src/biz/approval-desk/shell.ts +15 -11
- package/src/biz/auth-panel/shell.ts +9 -7
- package/src/biz/category-crud/compile.ts +5 -4
- package/src/biz/category-crud/shell.ts +5 -3
- package/src/biz/checkout-page/compile.ts +2 -1
- package/src/biz/checkout-page/shell.ts +10 -8
- package/src/biz/compose.ts +2 -2
- package/src/biz/data-components.ts +4 -0
- package/src/biz/import-wizard/shell.ts +13 -10
- package/src/biz/landing-page/shell.ts +2 -2
- package/src/biz/link/hub.ts +23 -5
- package/src/biz/link/shared.ts +23 -12
- package/src/biz/master-sub/compile.ts +207 -16
- package/src/biz/master-sub/detail-head.ts +61 -0
- package/src/biz/master-sub/index.ts +7 -3
- package/src/biz/master-sub/shell.ts +133 -24
- package/src/biz/multi-board/compile.ts +167 -9
- package/src/biz/multi-board/composition.ts +58 -0
- package/src/biz/multi-board/index.ts +1 -1
- package/src/biz/multi-board/prose-fold.ts +143 -0
- package/src/biz/multi-board/shell.ts +94 -23
- package/src/biz/notification-center/shell.ts +10 -7
- package/src/biz/page-templates/domain-templates.ts +2 -2
- package/src/biz/page-templates/result-page/shell.ts +4 -3
- package/src/biz/page-templates/sign-in-page/shell.ts +16 -16
- package/src/biz/record-detail/compile.ts +2 -2
- package/src/biz/record-detail/shell.ts +13 -10
- package/src/biz/settings-center/compile.ts +2 -1
- package/src/biz/settings-center/shell.ts +12 -9
- package/src/biz/shared/action-host.ts +6 -0
- package/src/biz/shared/compile-helpers.ts +97 -0
- package/src/biz/shared/coordinator.ts +7 -30
- package/src/biz/shared/index.ts +5 -0
- package/src/biz/shared/object-aliases.ts +154 -0
- package/src/biz/shared/overlay-compile.ts +281 -0
- package/src/biz/shared/overlay-shell.ts +142 -11
- package/src/biz/shared/pipes.ts +11 -5
- package/src/biz/shared/remove-wire.ts +4 -19
- package/src/biz/shared/runtime-hub.ts +10 -0
- package/src/biz/single-form/compile.ts +3 -2
- package/src/biz/single-form/shell.ts +9 -6
- package/src/biz/standard-crud/compile.ts +36 -161
- package/src/biz/standard-crud/shell.ts +23 -60
- package/src/biz/standard-crud/summary.ts +40 -0
- package/src/biz/step-form/shell.ts +15 -13
- package/src/biz/types.ts +6 -1
- package/src/cli/kit-cli.ts +138 -13
- package/src/cli/kit-init.ts +6 -1
- 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/view-writes.ts +69 -60
- package/src/compile/access-gate-attach.ts +27 -0
- package/src/compile/closed-set.ts +65 -4
- package/src/compile/compile-page.ts +66 -11
- package/src/compile/component-candidates.ts +14 -1
- package/src/compile/fragment.ts +11 -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 +267 -0
- package/src/compile/layout-lint/rules-form.ts +191 -0
- package/src/compile/layout-lint/rules-table.ts +278 -0
- package/src/compile/layout-lint/score.ts +52 -0
- package/src/compile/layout-lint/types.ts +51 -0
- package/src/compile/page-composition.ts +189 -0
- package/src/compile/parse.ts +4 -0
- package/src/compile/producer-fingerprint.ts +56 -0
- package/src/compile/remove-guard.ts +10 -7
- package/src/compile/styles.ts +46 -8
- package/src/compile/types.ts +16 -2
- package/src/compile/view-check.ts +149 -16
- package/src/data/access-gate.ts +112 -0
- package/src/data/amount-breakdown.ts +9 -2
- package/src/data/approval-flow.ts +5 -2
- package/src/data/assignment-picker.ts +59 -28
- package/src/data/async-result-panel.ts +49 -3
- package/src/data/breadcrumbs.ts +3 -2
- package/src/data/calendar.ts +8 -3
- package/src/data/carousel.ts +10 -6
- package/src/data/chart.ts +744 -46
- package/src/data/checklist.ts +22 -6
- package/src/data/code-view.ts +8 -4
- package/src/data/comment-thread.ts +3 -2
- package/src/data/confirm-dialog.ts +72 -25
- package/src/data/context-menu.ts +3 -3
- package/src/data/dock.ts +1 -1
- package/src/data/embed.ts +231 -29
- package/src/data/field-mapper.ts +7 -4
- package/src/data/flow-editor-contract.ts +7 -0
- package/src/data/flow-editor.ts +26 -9
- package/src/data/flow-node-options.ts +33 -3
- package/src/data/footer.ts +2 -0
- package/src/data/gantt.ts +192 -27
- package/src/data/hero.ts +4 -1
- package/src/data/image-viewer.ts +7 -4
- package/src/data/index.ts +16 -4
- package/src/data/item-list.ts +27 -12
- package/src/data/kanban.ts +41 -10
- package/src/data/matrix.ts +391 -0
- package/src/data/media-grid.ts +6 -1
- package/src/data/mega-menu.ts +6 -4
- package/src/data/menu-dom.ts +4 -2
- package/src/data/menu.ts +60 -16
- package/src/data/mockup.ts +5 -1
- package/src/data/modal-dialog.ts +146 -26
- package/src/data/navbar.ts +8 -6
- package/src/data/notice-list.ts +301 -0
- package/src/data/notify-renderer.ts +21 -6
- package/src/data/object-form.ts +409 -87
- package/src/data/outcome-watch.ts +61 -2
- package/src/data/pager.ts +19 -8
- package/src/data/panel-head.ts +406 -0
- package/src/data/permission-matrix.ts +36 -11
- package/src/data/permission-tree.ts +52 -23
- package/src/data/pricing-table.ts +22 -11
- package/src/data/prompt-dialog.ts +165 -0
- package/src/data/reaction-bar.ts +6 -4
- package/src/data/record-card.ts +40 -7
- package/src/data/record-picker.ts +13 -7
- package/src/data/resident.ts +8 -0
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +17 -1
- package/src/data/row-editor.ts +77 -24
- package/src/data/rule-builder.ts +14 -9
- package/src/data/shape-util.ts +27 -12
- package/src/data/stat-group.ts +459 -74
- package/src/data/static-lazy.ts +5 -0
- package/src/data/static-registry.ts +8 -0
- package/src/data/steps.ts +8 -3
- package/src/data/survey.ts +7 -4
- package/src/data/system-switcher.ts +3 -2
- package/src/data/text-action-button.ts +17 -0
- package/src/data/timeline.ts +17 -6
- package/src/data/tour-guide.ts +3 -2
- package/src/data/transfer.ts +40 -16
- package/src/data/tree-table.ts +65 -37
- package/src/data/tree.ts +22 -2
- package/src/data/virtual-rows.ts +21 -11
- package/src/data/wrapped-candidates.ts +32 -1
- package/src/frames/index.ts +1 -0
- package/src/frames/list-summary.ts +100 -0
- package/src/frames/page-bar.ts +7 -14
- package/src/frames/page-status.ts +7 -5
- package/src/frames/shared.ts +34 -13
- package/src/frames/split-frame/shell.ts +1 -1
- package/src/frames/tabs-frame/shell.ts +9 -6
- package/src/frames/tabs-frame/wiring.ts +1 -0
- package/src/frames/top-main-frame.ts +3 -3
- package/src/frames/types.ts +3 -1
- package/src/frames/workspace-frame/extras.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +4 -4
- package/src/frames/workspace-frame/tab-scroll.ts +28 -0
- package/src/frames/workspace-frame/view.ts +168 -44
- package/src/generated/kit-grammar-runtime.ts +390 -59
- package/src/i18n/kit-text.ts +90 -4
- package/src/i18n/resolve-text-refs.ts +22 -6
- package/src/object-renderer/action-group.ts +139 -0
- package/src/object-renderer/action-more.ts +144 -0
- package/src/object-renderer/arrange.ts +71 -7
- package/src/object-renderer/candidates.ts +4 -0
- package/src/object-renderer/collection-parts.ts +264 -62
- package/src/object-renderer/collection-table.ts +177 -5
- package/src/object-renderer/collection.ts +188 -37
- package/src/object-renderer/compile-data.ts +28 -3
- package/src/object-renderer/defaults.ts +27 -2
- package/src/object-renderer/display-checks.ts +1 -1
- package/src/object-renderer/emit-events.ts +43 -9
- package/src/object-renderer/emit-object.ts +4 -0
- package/src/object-renderer/emit-static.ts +434 -41
- package/src/object-renderer/filter-plan.ts +84 -0
- package/src/object-renderer/form-detail.ts +1 -2
- package/src/object-renderer/form-notify.ts +45 -0
- package/src/object-renderer/index.ts +5 -0
- package/src/object-renderer/layout-facts.ts +394 -0
- package/src/object-renderer/layout-plan.ts +225 -0
- package/src/object-renderer/layout-plan.types.ts +59 -0
- package/src/object-renderer/parts.ts +6 -7
- package/src/object-renderer/render-object.ts +107 -46
- package/src/object-renderer/request-actions.ts +4 -2
- package/src/object-renderer/skeleton.ts +58 -19
- package/src/object-renderer/table-actions.ts +172 -32
- package/src/object-renderer/table-gap.ts +37 -0
- package/src/object-renderer/table-tools.ts +62 -30
- package/src/object-renderer/types.ts +84 -13
- package/src/object-renderer/view-binding.ts +205 -8
- package/src/page-target/intent-schema.ts +11 -0
- package/src/page-target/target.ts +5 -1
- package/src/recipes/container.ts +77 -1
- package/src/recipes/control.ts +76 -116
- package/src/recipes/emphasis.ts +56 -0
- package/src/recipes/frame-bleed.ts +33 -0
- package/src/recipes/index.ts +72 -0
- package/src/recipes/nowrap.ts +16 -0
- package/src/recipes/overlay.ts +120 -17
- package/src/recipes/placeholder.ts +95 -0
- package/src/recipes/rail-grid.ts +48 -0
- package/src/recipes/slot-align.ts +56 -0
- package/src/recipes/stat-state.ts +65 -0
- package/src/recipes/state.ts +40 -21
- package/src/recipes/status.ts +147 -0
- package/src/recipes/surface-edge.ts +16 -0
- package/src/recipes/surface.ts +40 -0
- package/src/recipes/table-gap.ts +80 -0
- package/src/recipes/table-native-edit.ts +242 -0
- package/src/recipes/table-row.ts +146 -3
- package/src/recipes/tabs.ts +49 -0
- package/src/recipes/title-row.ts +37 -0
- package/src/recipes/typography.ts +30 -37
- package/src/shared/confirm-decl.ts +118 -0
- package/src/shared/envelope.ts +2 -2
- package/src/shared/paged-list-adapter.ts +15 -240
- package/src/shared/theme-runtime-shared.ts +6 -1
- package/src/theme/index.ts +1 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +384 -13
- package/src/theme/kit-theme.tpl +384 -13
- package/src/theme/nine-dim-structure.ts +244 -7
- package/src/theme/surface-layers.ts +10 -1
- package/src/theme/theme-tokens.ts +63 -16
- package/src/theme/theme-types.ts +32 -0
- package/src/theme/typography.ts +21 -17
- package/src/biz/shared/remove-key.ts +0 -6
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 键名可由 `map` 改写(roles / resources / grants 三个顶层键)。
|
|
5
5
|
// 资源是行、角色是列;行头 / 列头各有一个三态勾选(全选 / 半选 / 全不选),半选下点击视为「全选」。
|
|
6
6
|
// 授权草稿(grants)只在这一个组件内流转,归该组件;`data` 内容变化才重置草稿。
|
|
7
|
-
// readonly
|
|
7
|
+
// readonly 角色(如超级管理员恒为全授):画成「已授权」状态标记(成功软底 + 对勾,不是置灰的复选框)、不抛事件,也不计入行头的三态;整表 `disabled` 时全部画成禁用控件(灰显)。
|
|
8
8
|
// 相邻、同 group 的资源归在一条分组标题行下。无资源或无角色时显示 `empty_text`。
|
|
9
9
|
// 任何一次改动抛 `change { value, role?, resource?, on }`:value 是改动后的完整 grants(每个资源的角色键按 roles 顺序排列,
|
|
10
10
|
// readonly 角色的键原样保留);单格改动带 role + resource,整行改动只带 resource,整列改动只带 role。
|
|
@@ -12,8 +12,11 @@
|
|
|
12
12
|
import type { SomaComponentDefinition } from 'soma-core';
|
|
13
13
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
14
14
|
import { kitIcon, type KitIconName } from '../base/icons';
|
|
15
|
+
import { markCheckBox } from '../base/check-core';
|
|
15
16
|
import { kitText } from '../i18n/kit-text';
|
|
16
|
-
import { setKitFace } from '../recipes';
|
|
17
|
+
import { kitStateMarkRecipe, setKitFace } from '../recipes';
|
|
18
|
+
import { markKitEdge } from '../recipes/surface-edge';
|
|
19
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
17
20
|
import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
18
21
|
|
|
19
22
|
// ── 数据规整纯函数:键名对照、三态、data 解析、授权表规整 ──
|
|
@@ -125,22 +128,24 @@ const ROW_HEAD_CLASS = 'px-3 py-2 font-normal text-fg';
|
|
|
125
128
|
const ROW_HEAD_INNER_CLASS = 'flex items-center gap-2';
|
|
126
129
|
const ROW_TEXT_CLASS = 'flex min-w-0 flex-col';
|
|
127
130
|
const DESC_CLASS = 'text-xs text-fg-muted';
|
|
128
|
-
|
|
131
|
+
/** 同行相邻复选框的中心距下限 = 框宽 + 2 × px-3;hit-gap-6 写出 --kit-hit-gap(= 2 × 单元格横向内边距 = 6 步),hit-area-row 据此把横向热区收在中心距内,同行相邻热区任何指针 / 密度下都不重叠(gap 在表格单元格上无布局效果,只写变量) */
|
|
132
|
+
const CELL_CLASS = 'px-3 py-2 text-center hit-gap-6';
|
|
129
133
|
const HEAD_INNER_CLASS = 'flex items-center justify-center gap-2';
|
|
130
|
-
const BOX_CLASS = 'inline-flex h-5 w-5 items-center justify-center rounded-md border border-border bg-surface text-xs text-fg
|
|
131
|
-
const BOX_ON_CLASS = 'inline-flex h-5 w-5 items-center justify-center rounded-md border border-primary bg-primary text-xs text-primary-fg hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
132
|
-
const BOX_MIXED_CLASS = 'inline-flex h-5 w-5 items-center justify-center rounded-md border border-primary bg-primary-soft text-xs text-primary-on-soft hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
134
|
+
const BOX_CLASS = 'hit-area-row inline-flex h-5 w-5 shrink-0 p-0 items-center justify-center rounded-md border border-border bg-surface text-xs text-fg state-layer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
135
|
+
const BOX_ON_CLASS = 'hit-area-row inline-flex h-5 w-5 shrink-0 p-0 items-center justify-center rounded-md border border-primary bg-primary text-xs text-primary-fg hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
136
|
+
const BOX_MIXED_CLASS = 'hit-area-row inline-flex h-5 w-5 shrink-0 p-0 items-center justify-center rounded-md border border-primary bg-primary-soft text-xs text-primary-on-soft hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
137
|
+
const READONLY_MARK_CLASS = kitStateMarkRecipe('done', 'md');
|
|
133
138
|
const EMPTY_CLASS = 'px-3 py-6 text-center text-fg-muted';
|
|
134
139
|
const FOOT_CLASS = 'flex items-center justify-end gap-2';
|
|
135
|
-
const SAVE_CLASS = 'inline-flex h-
|
|
136
|
-
const CANCEL_CLASS = '
|
|
140
|
+
const SAVE_CLASS = 'inline-flex h-8 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-fg hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50';
|
|
141
|
+
const CANCEL_CLASS = kitEmphasisButtonRecipe('button.toolbar');
|
|
137
142
|
|
|
138
143
|
/** 本组件自带的全部类(供编译器并入候选类) */
|
|
139
144
|
export const KIT_PERMISSION_MATRIX_CLASS_CANDIDATES: readonly string[] = Object.freeze(
|
|
140
145
|
[...new Set([
|
|
141
146
|
ROOT_CLASS, WRAP_CLASS, TABLE_CLASS, HEAD_ROW_CLASS, COL_HEAD_CLASS, CORNER_CLASS, GROUP_ROW_CLASS, GROUP_CELL_CLASS,
|
|
142
147
|
ROW_CLASS, ROW_HEAD_CLASS, ROW_HEAD_INNER_CLASS, ROW_TEXT_CLASS, DESC_CLASS, CELL_CLASS, HEAD_INNER_CLASS,
|
|
143
|
-
BOX_CLASS, BOX_ON_CLASS, BOX_MIXED_CLASS, EMPTY_CLASS, FOOT_CLASS, SAVE_CLASS, CANCEL_CLASS,
|
|
148
|
+
BOX_CLASS, BOX_ON_CLASS, BOX_MIXED_CLASS, READONLY_MARK_CLASS, EMPTY_CLASS, FOOT_CLASS, SAVE_CLASS, CANCEL_CLASS,
|
|
144
149
|
].flatMap((s) => s.split(/\s+/)).filter((c) => c !== ''))].sort(),
|
|
145
150
|
);
|
|
146
151
|
|
|
@@ -257,6 +262,7 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
257
262
|
|
|
258
263
|
const box = (state: KitCheckState, label: string, act: string, attrs: Record<string, string>, off: boolean): HTMLButtonElement => {
|
|
259
264
|
const b = el('button', BOX[state]);
|
|
265
|
+
markCheckBox(b);
|
|
260
266
|
if (MARK[state] !== '') b.appendChild(kitIcon(MARK[state] as KitIconName, 'xs'));
|
|
261
267
|
b.type = 'button';
|
|
262
268
|
b.setAttribute('role', 'checkbox');
|
|
@@ -268,6 +274,18 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
268
274
|
return b;
|
|
269
275
|
};
|
|
270
276
|
|
|
277
|
+
/** 只读角色(状态呈现表 readonly):恒授权的状态标记,不是置灰的复选框 */
|
|
278
|
+
const grantedMark = (label: string, act: string, attrs: Record<string, string>): HTMLElement => {
|
|
279
|
+
const m = el('span', READONLY_MARK_CLASS);
|
|
280
|
+
m.setAttribute('role', 'img');
|
|
281
|
+
m.setAttribute('aria-label', label);
|
|
282
|
+
m.setAttribute('data-kit-state-mark', 'done');
|
|
283
|
+
m.setAttribute('data-kit-act', act);
|
|
284
|
+
for (const [k, v] of Object.entries(attrs)) m.setAttribute(k, v);
|
|
285
|
+
m.appendChild(kitIcon('check', 'xs'));
|
|
286
|
+
return m;
|
|
287
|
+
};
|
|
288
|
+
|
|
271
289
|
function paint(): void {
|
|
272
290
|
if (!root) return;
|
|
273
291
|
const p = P();
|
|
@@ -301,6 +319,7 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
301
319
|
}
|
|
302
320
|
const lock = locked();
|
|
303
321
|
const wrap = el('div', WRAP_CLASS);
|
|
322
|
+
markKitEdge(wrap);
|
|
304
323
|
const table = el('table', TABLE_CLASS);
|
|
305
324
|
const thead = el('thead', '');
|
|
306
325
|
const hr = el('tr', HEAD_ROW_CLASS);
|
|
@@ -313,7 +332,10 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
313
332
|
const inner = el('div', HEAD_INNER_CLASS);
|
|
314
333
|
inner.appendChild(el('span', '', role.label));
|
|
315
334
|
const state: KitCheckState = role.readonly ? 'on' : checkStateOf(resources.map((x) => has(x.key, role.key)));
|
|
316
|
-
|
|
335
|
+
const colLabel = kitText(state === 'on' ? 'soma.kit.pm_col_revoke' : 'soma.kit.pm_col_grant', { label: role.label }, root);
|
|
336
|
+
inner.appendChild(role.readonly
|
|
337
|
+
? grantedMark(role.label, 'col', { 'data-kit-role': role.key })
|
|
338
|
+
: box(state, colLabel, 'col', { 'data-kit-role': role.key }, lock));
|
|
317
339
|
th.appendChild(inner);
|
|
318
340
|
hr.appendChild(th);
|
|
319
341
|
}
|
|
@@ -348,7 +370,10 @@ export function createPermissionMatrix(): SomaComponentDefinition {
|
|
|
348
370
|
for (const role of roles) {
|
|
349
371
|
const td = el('td', CELL_CLASS);
|
|
350
372
|
const state: KitCheckState = role.readonly || has(res.key, role.key) ? 'on' : 'off';
|
|
351
|
-
|
|
373
|
+
const cellAttrs = { 'data-kit-res': res.key, 'data-kit-role': role.key };
|
|
374
|
+
td.appendChild(role.readonly
|
|
375
|
+
? grantedMark(`${res.label} · ${role.label}`, 'cell', cellAttrs)
|
|
376
|
+
: box(state, `${res.label} · ${role.label}`, 'cell', cellAttrs, lock));
|
|
352
377
|
tr.appendChild(td);
|
|
353
378
|
}
|
|
354
379
|
tbody.appendChild(tr);
|
|
@@ -36,16 +36,24 @@ import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
|
36
36
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
37
37
|
import { bool, createKitController, joinClass, str } from '../base/shared';
|
|
38
38
|
import { kitIcon } from '../base/icons';
|
|
39
|
+
import { markCheckBox } from '../base/check-core';
|
|
39
40
|
import { kitText, type KitTextKey } from '../i18n/kit-text';
|
|
40
|
-
import { setKitFace } from '../recipes';
|
|
41
|
+
import { kitControlRecipe, kitTextActionRecipe, setKitFace } from '../recipes';
|
|
42
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
43
|
+
import {
|
|
44
|
+
KIT_OVERLAY_FOOT_ATTR, KIT_OVERLAY_FORM_FOOTER_CLASS, KIT_OVERLAY_FORM_SCROLL_ATTR, KIT_OVERLAY_ROOT_FILL_CLASS, kitOverlayFormScrollClass,
|
|
45
|
+
} from '../recipes/overlay';
|
|
41
46
|
import { createKitBusy, KIT_BUSY_PROP_DEFS } from '../base/action-busy';
|
|
42
47
|
import { classTokens, keyMap, mk, recOf } from './shape-util';
|
|
43
48
|
import { KIT_TREE_MAX_DEPTH } from './tree';
|
|
44
49
|
import { aggregateCheck, nextCheckTarget } from './tree-check';
|
|
50
|
+
import { markKitEdge } from '../recipes/surface-edge';
|
|
51
|
+
import { kitTypographyRecipe } from '../recipes/typography';
|
|
45
52
|
|
|
46
53
|
// ── 类串表:全部完整写死,不拼接片段 ──
|
|
47
54
|
|
|
48
|
-
|
|
55
|
+
// 浮层滚动体里(宿主见 KIT_OVERLAY_FORM_HOST_CLASS)根撑满体高,底栏 mt-auto 落在浮层底部
|
|
56
|
+
const ROOT_CLASS = `flex flex-col gap-3 text-sm text-fg ${KIT_OVERLAY_ROOT_FILL_CLASS}`;
|
|
49
57
|
const HELP_CLASS = 'text-sm text-fg-muted';
|
|
50
58
|
const SUBJECT_CLASS = 'flex flex-wrap items-center gap-4';
|
|
51
59
|
const SUBJECT_ITEM_CLASS = 'flex items-center gap-2';
|
|
@@ -53,28 +61,29 @@ const CAPTION_CLASS = 'text-sm text-fg-muted';
|
|
|
53
61
|
const STRONG_CLASS = 'text-sm font-semibold text-fg';
|
|
54
62
|
const ALERT_CLASS = 'rounded-md bg-danger-soft px-3 py-2 text-sm text-danger-on-soft';
|
|
55
63
|
const HEAD_CLASS = 'flex items-center justify-between gap-3';
|
|
56
|
-
const TITLE_CLASS = '
|
|
64
|
+
const TITLE_CLASS = kitTypographyRecipe('sectionTitle');
|
|
57
65
|
const SUMMARY_CLASS = 'text-sm text-fg-muted';
|
|
58
66
|
const CHANGES_CLASS = 'flex flex-wrap items-center gap-2 text-sm text-fg-muted';
|
|
59
|
-
const LINK_CLASS = 'rounded-md px-1 text-sm text-primary-on-soft transition-colors hover:bg-
|
|
67
|
+
const LINK_CLASS = 'rounded-md px-1 text-sm text-primary-on-soft transition-colors hover:bg-state-layer-hover active:bg-state-layer-press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
60
68
|
const DETAIL_CLASS = 'flex flex-col gap-1 rounded-md bg-surface-sunken px-3 py-2 text-sm text-fg';
|
|
61
69
|
const DETAIL_ADDED_CLASS = 'text-success-on-soft';
|
|
62
70
|
const DETAIL_REMOVED_CLASS = 'text-danger-on-soft';
|
|
63
71
|
const TOOLS_CLASS = 'flex flex-wrap items-center gap-2';
|
|
64
72
|
const SEARCH_CLASS = 'block h-9 min-w-40 flex-1 appearance-none autofill-clear rounded-md border border-border bg-surface px-3 text-sm text-fg placeholder:text-fg-subtle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
73
|
+
// 展开 / 收起 / 全选 / 清空:文字链接(唯一主按钮是保存),配方 kitTextActionRecipe
|
|
74
|
+
const TOOL_BTN_CLASS = kitTextActionRecipe('primary');
|
|
75
|
+
const TREE_CLASS = 'flex flex-col overflow-hidden rounded-md border border-border-subtle';
|
|
76
|
+
const ROW_BASE_CLASS = 'flex min-h-table-row items-center hit-gap-2 border-b border-border-divider bg-surface pe-2 py-1.5 text-fg last:border-b-0 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
77
|
+
const ROW_LIVE_CLASS = 'cursor-pointer transition-colors hover:bg-state-layer-hover active:bg-state-layer-press';
|
|
69
78
|
const ROW_LOCKED_CLASS = 'cursor-not-allowed text-fg-subtle';
|
|
70
79
|
const ROW_GROUP_CLASS = 'bg-surface-sunken font-medium';
|
|
71
80
|
const ROW_ADDED_CLASS = 'bg-success-soft text-success-on-soft';
|
|
72
81
|
const ROW_REMOVED_CLASS = 'bg-danger-soft text-danger-on-soft';
|
|
73
82
|
const CURSOR_CLASS = 'ring-1 ring-inset ring-ring';
|
|
74
|
-
const CARET_CLASS = 'w-4 shrink-0 cursor-pointer text-center text-fg-subtle';
|
|
75
|
-
const BOX_OFF_CLASS = 'inline-flex size-4 shrink-0 items-center justify-center rounded-md border border-border bg-surface text-xs';
|
|
76
|
-
const BOX_ON_CLASS = 'inline-flex size-4 shrink-0 items-center justify-center rounded-md border border-primary bg-primary text-xs text-primary-fg';
|
|
77
|
-
const BOX_MIXED_CLASS = 'inline-flex size-4 shrink-0 items-center justify-center rounded-md border border-primary bg-primary-soft text-xs text-primary-on-soft';
|
|
83
|
+
const CARET_CLASS = 'hit-area-row w-4 shrink-0 cursor-pointer text-center text-fg-subtle';
|
|
84
|
+
const BOX_OFF_CLASS = 'relative z-10 inline-flex size-4 shrink-0 items-center justify-center rounded-md border border-border bg-surface text-xs';
|
|
85
|
+
const BOX_ON_CLASS = 'relative z-10 inline-flex size-4 shrink-0 items-center justify-center rounded-md border border-primary bg-primary text-xs text-primary-fg';
|
|
86
|
+
const BOX_MIXED_CLASS = 'relative z-10 inline-flex size-4 shrink-0 items-center justify-center rounded-md border border-primary bg-primary-soft text-xs text-primary-on-soft';
|
|
78
87
|
const BOX_LOCKED_CLASS = 'opacity-60';
|
|
79
88
|
const TEXT_CLASS = 'flex min-w-0 flex-1 flex-col';
|
|
80
89
|
const LABEL_CLASS = 'truncate text-sm';
|
|
@@ -87,8 +96,9 @@ const CHIP_STATUS_CLASS = 'bg-surface-sunken text-fg-muted';
|
|
|
87
96
|
const CHIP_WARN_CLASS = 'bg-warning-soft text-warning-on-soft';
|
|
88
97
|
const EMPTY_CLASS = 'px-2 py-3 text-sm text-fg-muted';
|
|
89
98
|
const FOOT_CLASS = 'flex items-center justify-end gap-2 pt-1';
|
|
90
|
-
|
|
91
|
-
const
|
|
99
|
+
// 保存 / 取消(返回)都是标准高度的实心 / 描边按钮(与对话框底栏同一配方),不再一个文字链接一个按钮
|
|
100
|
+
const SAVE_CLASS = kitControlRecipe({ variant: 'primary' });
|
|
101
|
+
const CANCEL_CLASS = kitEmphasisButtonRecipe('button.toolbar');
|
|
92
102
|
const DEPTH = ['ps-2', 'ps-6', 'ps-10', 'ps-14', 'ps-18', 'ps-22', 'ps-26'] as const;
|
|
93
103
|
|
|
94
104
|
export const KIT_PERMISSION_TREE_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
@@ -97,7 +107,7 @@ export const KIT_PERMISSION_TREE_CLASS_CANDIDATES: readonly string[] = classToke
|
|
|
97
107
|
TOOL_BTN_CLASS, TREE_CLASS, ROW_BASE_CLASS, ROW_LIVE_CLASS, ROW_LOCKED_CLASS, ROW_GROUP_CLASS, ROW_ADDED_CLASS, ROW_REMOVED_CLASS,
|
|
98
108
|
CURSOR_CLASS, CARET_CLASS, BOX_OFF_CLASS, BOX_ON_CLASS, BOX_MIXED_CLASS, BOX_LOCKED_CLASS, TEXT_CLASS, LABEL_CLASS, SUB_CLASS,
|
|
99
109
|
CHIPS_CLASS, CHIP_BASE, CHIP_ADDED_CLASS, CHIP_REMOVED_CLASS, CHIP_STATUS_CLASS, CHIP_WARN_CLASS, EMPTY_CLASS, FOOT_CLASS,
|
|
100
|
-
SAVE_CLASS, CANCEL_CLASS, DEPTH, 'hidden', 'flex', 'flex-1',
|
|
110
|
+
SAVE_CLASS, CANCEL_CLASS, KIT_OVERLAY_FORM_FOOTER_CLASS, kitOverlayFormScrollClass('gap-3'), DEPTH, 'hidden', 'flex', 'flex-1',
|
|
101
111
|
);
|
|
102
112
|
|
|
103
113
|
// ── 数据规整与勾选状态机(纯函数,不碰 DOM) ──
|
|
@@ -235,6 +245,8 @@ export function buildPermissionModel(items: unknown, map: KitPermissionTreeMap):
|
|
|
235
245
|
|
|
236
246
|
export interface KitPermSummary {
|
|
237
247
|
count: number;
|
|
248
|
+
/** 已勾选且不可编辑的授权主体数(锁定 / 只读;未登记节点不提交,不计):只用于摘要展示,不进提交载荷 */
|
|
249
|
+
lockedOn: number;
|
|
238
250
|
added: number[];
|
|
239
251
|
removed: number[];
|
|
240
252
|
}
|
|
@@ -318,15 +330,17 @@ export function createPermissionState(model: KitPermModel, value: readonly strin
|
|
|
318
330
|
},
|
|
319
331
|
summary() {
|
|
320
332
|
let count = 0;
|
|
333
|
+
let lockedOn = 0;
|
|
321
334
|
const added: number[] = [];
|
|
322
335
|
const removed: number[] = [];
|
|
323
336
|
for (let i = 0; i < n; i += 1) {
|
|
324
337
|
if (!submittable(i)) continue;
|
|
325
338
|
if (st[i] === 1 && editable[i] === 1) count += 1;
|
|
339
|
+
else if (st[i] === 1 && nodes[i]!.status !== 'unregistered') lockedOn += 1;
|
|
326
340
|
if (base[i] !== 1 && st[i] === 1) added.push(i);
|
|
327
341
|
else if (base[i] === 1 && st[i] !== 1) removed.push(i);
|
|
328
342
|
}
|
|
329
|
-
return { count, added, removed };
|
|
343
|
+
return { count, lockedOn, added, removed };
|
|
330
344
|
},
|
|
331
345
|
submitValue(keep) {
|
|
332
346
|
const out = new Set<string>();
|
|
@@ -371,6 +385,7 @@ const TEXT_KEYS = Object.freeze({
|
|
|
371
385
|
select_all: 'soma.kit.ptree_select_all',
|
|
372
386
|
clear: 'soma.kit.ptree_clear',
|
|
373
387
|
selected: 'soma.kit.ptree_selected',
|
|
388
|
+
selected_locked: 'soma.kit.ptree_selected_locked',
|
|
374
389
|
no_change: 'soma.kit.ptree_no_change',
|
|
375
390
|
changes: 'soma.kit.ptree_changes',
|
|
376
391
|
detail_open: 'soma.kit.ptree_detail_open',
|
|
@@ -428,7 +443,7 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
428
443
|
props: {
|
|
429
444
|
data: { type: 'object', default: {}, desc: '{ items: 节点树, value: 原有已授权标识[], keep?, subject?, error? }' },
|
|
430
445
|
map: { type: 'object', default: {}, desc: '键名对照:组件期望的键 -> 数据里的键' },
|
|
431
|
-
texts: { type: 'object', default: {}, desc: '文案覆盖(search / expand_all / collapse_all / select_all / clear / selected / no_change / changes / added / removed / locked / unregistered / readonly / locked_hint / empty / invalid …)' },
|
|
446
|
+
texts: { type: 'object', default: {}, desc: '文案覆盖(search / expand_all / collapse_all / select_all / clear / selected(占位 {n},可用 {locked})/ selected_locked / no_change / changes / added / removed / locked / unregistered / readonly / locked_hint / empty / invalid …)' },
|
|
432
447
|
title: { type: 'string', default: '', desc: '树标题(右侧是已选摘要)' },
|
|
433
448
|
help: { type: 'string', default: '', desc: '顶部说明' },
|
|
434
449
|
expand_depth: { type: 'number', default: 1, desc: '初始展开层数:0 全部收起,1 根节点展开,大数 = 全部展开' },
|
|
@@ -586,6 +601,7 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
586
601
|
caret.setAttribute('aria-hidden', 'true');
|
|
587
602
|
caret.setAttribute('data-kit-toggle', '');
|
|
588
603
|
const box = mk('span', BOX_OFF_CLASS);
|
|
604
|
+
markCheckBox(box);
|
|
589
605
|
box.setAttribute('aria-hidden', 'true');
|
|
590
606
|
box.setAttribute('data-kit-box', '');
|
|
591
607
|
const text = mk('span', TEXT_CLASS);
|
|
@@ -651,7 +667,13 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
651
667
|
titleEl.textContent = str(p.title);
|
|
652
668
|
titleEl.hidden = str(p.title) === '';
|
|
653
669
|
const sum = state.summary();
|
|
654
|
-
|
|
670
|
+
// 摘要计数含已勾选的锁定节点(只改展示,不改提交载荷);有锁定项且没有自定义 texts.selected 时用「含 m 项固定」文案;
|
|
671
|
+
// 自定义 texts.selected 仍按原样填 {n},另可用 {locked}
|
|
672
|
+
const shownCount = sum.count + sum.lockedOn;
|
|
673
|
+
const customSelected = typeof recOf(P().texts).selected === 'string' && recOf(P().texts).selected !== '';
|
|
674
|
+
summaryEl.textContent = sum.lockedOn > 0 && !customSelected
|
|
675
|
+
? fill(t.selected_locked, { n: shownCount, locked: sum.lockedOn })
|
|
676
|
+
: fill(t.selected, { n: shownCount, locked: sum.lockedOn });
|
|
655
677
|
changesText.textContent = sum.added.length + sum.removed.length === 0 ? t.no_change : fill(t.changes, { added: sum.added.length, removed: sum.removed.length });
|
|
656
678
|
detailBtn.hidden = sum.added.length + sum.removed.length === 0;
|
|
657
679
|
detailBtn.textContent = detailOpen ? t.detail_close : t.detail_open;
|
|
@@ -814,12 +836,13 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
814
836
|
titleEl = mk('h3', TITLE_CLASS);
|
|
815
837
|
summaryEl = mk('span', SUMMARY_CLASS);
|
|
816
838
|
const head = mk('div', HEAD_CLASS);
|
|
817
|
-
head.append(titleEl
|
|
839
|
+
head.append(titleEl);
|
|
818
840
|
changesText = mk('span', '');
|
|
819
841
|
detailBtn = mk('button', LINK_CLASS);
|
|
820
842
|
detailBtn.type = 'button';
|
|
843
|
+
// 「已选择 n 项」与「本次变更」合成一行状态文字
|
|
821
844
|
const changesRow = mk('div', CHANGES_CLASS);
|
|
822
|
-
changesRow.append(changesText, detailBtn);
|
|
845
|
+
changesRow.append(summaryEl, changesText, detailBtn);
|
|
823
846
|
detailBox = mk('div', DETAIL_CLASS);
|
|
824
847
|
changesBox = mk('div', '');
|
|
825
848
|
changesBox.append(changesRow, detailBox);
|
|
@@ -833,25 +856,31 @@ export function createPermissionTree(): SomaComponentDefinition {
|
|
|
833
856
|
collapseBtn = mk('button', TOOL_BTN_CLASS); collapseBtn.type = 'button';
|
|
834
857
|
allBtn = mk('button', TOOL_BTN_CLASS); allBtn.type = 'button';
|
|
835
858
|
clearBtn = mk('button', TOOL_BTN_CLASS); clearBtn.type = 'button';
|
|
836
|
-
for (const b of [expandBtn, collapseBtn, allBtn, clearBtn]) setKitFace(b, 'raised');
|
|
837
859
|
const bulkRow = mk('div', TOOLS_CLASS);
|
|
838
860
|
bulkRow.append(expandBtn, collapseBtn, allBtn, clearBtn);
|
|
839
861
|
bulkBox = boxOf(bulkRow);
|
|
840
862
|
toolsBox = mk('div', TOOLS_CLASS);
|
|
841
863
|
toolsBox.append(searchBox, bulkBox);
|
|
842
864
|
treeEl = mk('div', TREE_CLASS);
|
|
865
|
+
markKitEdge(treeEl);
|
|
843
866
|
treeEl.setAttribute('role', 'tree');
|
|
844
867
|
cancelBtn = mk('button', CANCEL_CLASS); cancelBtn.type = 'button';
|
|
845
868
|
saveBtn = mk('button', SAVE_CLASS); saveBtn.type = 'button';
|
|
846
|
-
setKitFace(cancelBtn, 'raised');
|
|
847
869
|
setKitFace(saveBtn, 'raised');
|
|
848
870
|
cancelBox = boxOf(cancelBtn);
|
|
849
871
|
saveBox = boxOf(saveBtn);
|
|
850
872
|
const foot = mk('div', FOOT_CLASS);
|
|
851
873
|
foot.append(cancelBox, saveBox);
|
|
852
874
|
footBox = boxOf(foot);
|
|
875
|
+
// 浮层滚动体里底栏吸底并贴着浮层底边(外包层是 sticky 元素;变体只在 group-data-kit-overlay-scroll 祖先下生效)
|
|
876
|
+
footBox.className = KIT_OVERLAY_FORM_FOOTER_CLASS;
|
|
877
|
+
// 滚动区(底栏之外的内容):页面级 contents、浮层里 flex-1 min-h-0 overflow-y-auto;底栏在它之外,不随内容滚动
|
|
878
|
+
const scrollArea = mk('div', kitOverlayFormScrollClass('gap-3'));
|
|
879
|
+
scrollArea.setAttribute(KIT_OVERLAY_FORM_SCROLL_ATTR, '');
|
|
880
|
+
scrollArea.append(helpEl, subjectEl, alertEl, head, changesBox, toolsBox, treeEl);
|
|
881
|
+
footBox.setAttribute(KIT_OVERLAY_FOOT_ATTR, '');
|
|
853
882
|
host.textContent = '';
|
|
854
|
-
host.append(
|
|
883
|
+
host.append(scrollArea, footBox);
|
|
855
884
|
|
|
856
885
|
const on = (target: HTMLElement, type: string, fn: (event: Event) => void): void => {
|
|
857
886
|
target.addEventListener(type, fn);
|
|
@@ -14,6 +14,8 @@ import { createKitController, joinClass, str, type KitView } from '../base/share
|
|
|
14
14
|
import { kitIcon } from '../base/icons';
|
|
15
15
|
import { kitText } from '../i18n/kit-text';
|
|
16
16
|
import { setKitFace } from '../recipes';
|
|
17
|
+
import { kitEmphasisButtonRecipe } from '../recipes/emphasis';
|
|
18
|
+
import { markKitSlot, markKitSlotGrid } from '../recipes/slot-align';
|
|
17
19
|
import { classTokens, emptyNode, mk, recOf, rowsOf, textOf, type Rec } from './shape-util';
|
|
18
20
|
import { singleOf } from './display-util';
|
|
19
21
|
import { attrEsc } from './d9-util';
|
|
@@ -24,9 +26,13 @@ const ROOT_CLASS = '@container flex flex-col gap-5 text-fg';
|
|
|
24
26
|
const CYCLES_CLASS = 'mx-auto inline-flex items-center gap-1 rounded-lg bg-surface-sunken p-1';
|
|
25
27
|
const CYCLE_CLASS = 'inline-flex h-8 items-center gap-1 rounded-md px-3 text-sm font-medium text-fg-muted transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-kit-selected:bg-surface data-kit-selected:text-fg data-kit-selected:shadow-sm';
|
|
26
28
|
const NOTE_CLASS = 'rounded-full bg-success-soft px-1.5 text-xs font-medium text-success-on-soft';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
29
|
+
// 卡片三槽对齐(宽档间距 comfortable,真源 structure.slotAlign.slotGapTiers):卡片是父 grid 的直接子节点,显示方式(subgrid / 不支持时 flex 纵向)与槽间距由结构 CSS 给,
|
|
30
|
+
// 所以卡片类里不写 flex / gap,父 grid 的行距也交给结构 CSS(只写列距 gap-x-4);三槽 = 标题(名称 + 说明)/ 指标(价格)/ 操作(功能列表 + 按钮)
|
|
31
|
+
const GRID_CLASS = 'grid grid-cols-1 gap-x-4 @md:grid-cols-2 @xl:grid-cols-3';
|
|
32
|
+
const CARD_CLASS = 'relative rounded-lg border border-border-subtle bg-surface p-5';
|
|
33
|
+
const CARD_RECOMMENDED_CLASS = 'relative rounded-lg border border-primary bg-surface p-5 shadow-md ring-1 ring-primary';
|
|
34
|
+
const SLOT_TITLE_CLASS = 'flex flex-col gap-4';
|
|
35
|
+
const SLOT_ACTION_CLASS = 'flex flex-1 flex-col gap-4';
|
|
30
36
|
const BADGE_CLASS = 'absolute end-4 top-4 rounded-full bg-primary-soft px-2 py-0.5 text-xs font-medium text-primary-on-soft';
|
|
31
37
|
const NAME_CLASS = 'text-lg font-semibold text-fg';
|
|
32
38
|
const DESC_CLASS = 'text-sm text-fg-muted';
|
|
@@ -40,10 +46,10 @@ const TICK_CLASS = 'inline-flex size-5 shrink-0 items-center justify-center roun
|
|
|
40
46
|
const CROSS_CLASS = 'inline-flex size-5 shrink-0 items-center justify-center rounded-full bg-surface-sunken text-xs text-fg-subtle';
|
|
41
47
|
const VALUE_CLASS = 'ms-auto shrink-0 text-fg-muted';
|
|
42
48
|
const ACTION_CLASS = 'inline-flex h-10 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-fg transition-colors hover:bg-primary-hover active:bg-primary-active focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60';
|
|
43
|
-
const ACTION_PLAIN_CLASS = '
|
|
49
|
+
const ACTION_PLAIN_CLASS = kitEmphasisButtonRecipe('button.toolbar', { size: 'lg' });
|
|
44
50
|
|
|
45
51
|
export const KIT_PRICING_TABLE_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
46
|
-
ROOT_CLASS, CYCLES_CLASS, CYCLE_CLASS, NOTE_CLASS, GRID_CLASS, CARD_CLASS, CARD_RECOMMENDED_CLASS, BADGE_CLASS, NAME_CLASS,
|
|
52
|
+
ROOT_CLASS, CYCLES_CLASS, CYCLE_CLASS, NOTE_CLASS, GRID_CLASS, CARD_CLASS, CARD_RECOMMENDED_CLASS, SLOT_TITLE_CLASS, SLOT_ACTION_CLASS, BADGE_CLASS, NAME_CLASS,
|
|
47
53
|
DESC_CLASS, PRICE_ROW_CLASS, PRICE_CLASS, PERIOD_CLASS, FEATURES_CLASS, FEATURE_CLASS, FEATURE_OFF_CLASS, TICK_CLASS,
|
|
48
54
|
CROSS_CLASS, VALUE_CLASS, ACTION_CLASS, ACTION_PLAIN_CLASS,
|
|
49
55
|
);
|
|
@@ -232,17 +238,20 @@ export function createPricingTable(): SomaComponentDefinition {
|
|
|
232
238
|
}
|
|
233
239
|
const current = textOf(src.current_key);
|
|
234
240
|
const grid = mk('div', GRID_CLASS);
|
|
241
|
+
markKitSlotGrid(grid, 3, 'comfortable');
|
|
235
242
|
for (const plan of plans) {
|
|
236
243
|
const isCurrent = current !== '' && plan.key === current;
|
|
237
244
|
const card = mk('article', plan.recommended ? CARD_RECOMMENDED_CLASS : CARD_CLASS);
|
|
238
245
|
card.setAttribute('data-kit-plan', plan.key);
|
|
239
246
|
const badge = isCurrent ? str(p.current_text, kitText('soma.kit.pt_current', undefined, root)) : plan.badge;
|
|
240
247
|
if (badge !== '') card.appendChild(mk('span', BADGE_CLASS, badge));
|
|
241
|
-
|
|
242
|
-
|
|
248
|
+
const head = markKitSlot(mk('div', SLOT_TITLE_CLASS), 'title');
|
|
249
|
+
head.appendChild(mk('h3', NAME_CLASS, plan.name));
|
|
250
|
+
if (plan.desc !== '') head.appendChild(mk('p', DESC_CLASS, plan.desc));
|
|
251
|
+
card.appendChild(head);
|
|
243
252
|
const price = plan.prices ? pricingTextFor(plan.prices, s.cycle) : plan.price;
|
|
244
253
|
const period = plan.periods ? pricingTextFor(plan.periods, s.cycle) : plan.period;
|
|
245
|
-
const row = mk('div', PRICE_ROW_CLASS);
|
|
254
|
+
const row = markKitSlot(mk('div', PRICE_ROW_CLASS), 'metric');
|
|
246
255
|
row.appendChild(mk('span', PRICE_CLASS, price));
|
|
247
256
|
if (period !== '') row.appendChild(mk('span', PERIOD_CLASS, period));
|
|
248
257
|
card.appendChild(row);
|
|
@@ -258,13 +267,15 @@ export function createPricingTable(): SomaComponentDefinition {
|
|
|
258
267
|
if (f.kind === 'value') li.appendChild(mk('span', VALUE_CLASS, f.value));
|
|
259
268
|
ul.appendChild(li);
|
|
260
269
|
}
|
|
261
|
-
|
|
262
|
-
|
|
270
|
+
const foot = markKitSlot(mk('div', SLOT_ACTION_CLASS), 'action');
|
|
271
|
+
foot.appendChild(ul);
|
|
272
|
+
const btn =mk('button', plan.recommended ? ACTION_CLASS : ACTION_PLAIN_CLASS, plan.actionText || str(p.action_text, kitText('soma.kit.pt_choose', undefined, root)));
|
|
263
273
|
btn.type = 'button';
|
|
264
274
|
setKitFace(btn, 'raised');
|
|
265
275
|
btn.setAttribute('data-kit-plan-action', plan.key);
|
|
266
276
|
if (isCurrent || plan.disabled) { btn.disabled = true; btn.setAttribute('aria-disabled', 'true'); }
|
|
267
|
-
|
|
277
|
+
foot.appendChild(btn);
|
|
278
|
+
card.appendChild(foot);
|
|
268
279
|
grid.appendChild(card);
|
|
269
280
|
}
|
|
270
281
|
root.appendChild(grid);
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// askKitPrompt:命令式的自绘输入对话框(取代浏览器原生 prompt,全 kit 只此一份实现;与 askKitConfirm 同族)。
|
|
2
|
+
//
|
|
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
|
+
|
|
11
|
+
import { kitText } from '../i18n/kit-text';
|
|
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';
|
|
17
|
+
|
|
18
|
+
const FIELD_CLASS = 'flex flex-col gap-1';
|
|
19
|
+
const LABEL_CLASS = kitTypographyRecipe('label');
|
|
20
|
+
const TEXTAREA_CLASS = kitControlRecipe({ multiline: true });
|
|
21
|
+
const ERROR_CLASS = KIT_ERROR_TEXT;
|
|
22
|
+
|
|
23
|
+
export const KIT_PROMPT_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
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,
|
|
25
|
+
);
|
|
26
|
+
|
|
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;
|
|
40
|
+
}
|
|
41
|
+
|
|
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
|
+
}
|
|
56
|
+
|
|
57
|
+
type Control = HTMLInputElement | HTMLTextAreaElement;
|
|
58
|
+
|
|
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);
|
|
62
|
+
const doc = opts.at?.ownerDocument ?? document;
|
|
63
|
+
return new Promise<Record<string, string> | null>((resolve) => {
|
|
64
|
+
let settled = false;
|
|
65
|
+
const modal = mountKitModal({
|
|
66
|
+
title: opts.title ?? kitText('soma.kit.confirm', undefined, opts.at),
|
|
67
|
+
size: 'sm',
|
|
68
|
+
at: opts.at ?? null,
|
|
69
|
+
showClose: false,
|
|
70
|
+
dismissOnScrim: false,
|
|
71
|
+
onClose: () => finish(null),
|
|
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
|
+
|
|
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
|
+
}
|
|
92
|
+
|
|
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;
|
|
101
|
+
label.htmlFor = id;
|
|
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);
|
|
124
|
+
}
|
|
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
|
+
});
|
|
131
|
+
modal.body.appendChild(wrap);
|
|
132
|
+
controls.push({ field, control, error });
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const submit = (): void => {
|
|
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
|
+
}
|
|
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;
|
|
147
|
+
finish(out);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const cancel = kitDialogButton(doc, 'neutral', opts.cancelLabel ?? kitText('soma.kit.cancel', undefined, opts.at));
|
|
151
|
+
cancel.addEventListener('click', () => finish(null));
|
|
152
|
+
const ok = kitDialogButton(doc, 'primary', opts.submitLabel ?? kitText('soma.kit.ok', undefined, opts.at));
|
|
153
|
+
ok.addEventListener('click', submit);
|
|
154
|
+
modal.footer.append(cancel, ok);
|
|
155
|
+
|
|
156
|
+
(opts.at?.isConnected === true ? opts.at.parentNode ?? doc.body : doc.body).appendChild(modal.layer);
|
|
157
|
+
modal.open();
|
|
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();
|
|
164
|
+
});
|
|
165
|
+
}
|
package/src/data/reaction-bar.ts
CHANGED
|
@@ -13,15 +13,17 @@ import { setKitFace } from '../recipes';
|
|
|
13
13
|
import { classTokens, mk, rowsOf, textOf } from './shape-util';
|
|
14
14
|
import { REACTION_MAX_KINDS, REACTION_PALETTE } from './d9-limits';
|
|
15
15
|
import { attrEsc } from './d9-util';
|
|
16
|
+
import { mergeClass } from '../object-renderer/merge-class';
|
|
17
|
+
import { kitSurfaceRecipe } from '../recipes/surface';
|
|
16
18
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, dropdownOwnerOf, queryWithDropdowns, releaseDropdownsIn, syncDropdown } from '../base/popup';
|
|
17
19
|
|
|
18
20
|
const ROOT_CLASS = 'relative flex flex-wrap items-center gap-2 text-sm text-fg';
|
|
19
|
-
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';
|
|
20
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';
|
|
21
|
-
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
|
|
22
|
-
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'));
|
|
23
25
|
const PANEL_CLASS = `${PANEL_BASE_CLASS} start-0 top-full mt-1`;
|
|
24
|
-
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';
|
|
25
27
|
|
|
26
28
|
export const KIT_REACTION_BAR_CLASS_CANDIDATES: readonly string[] = classTokens(
|
|
27
29
|
ROOT_CLASS, PILL_CLASS, PILL_MINE, ADD_CLASS, PANEL_BASE_CLASS, PANEL_CLASS, CHOICE_CLASS, KIT_DROPDOWN_CLASS_CANDIDATES,
|