soma-kit 0.1.11 → 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 -1473
|
@@ -5,20 +5,23 @@
|
|
|
5
5
|
// 响应里取不到行数组 -> loading;响应里 errorPath 有文案 -> error;行数组为空 -> empty;否则不显示。
|
|
6
6
|
// core 不暴露读失败状态,所以 error 态只在列表响应自带错误文案时出现。
|
|
7
7
|
|
|
8
|
-
import type {
|
|
9
|
-
import { CLASS_PROP, findRoot, joinClass, str } from '../base/shared';
|
|
8
|
+
import type { SomaComponentDefinition, SomaRegionPort } from 'soma-core';
|
|
9
|
+
import { CLASS_PROP, createKitController, findRoot, joinClass, str } from '../base/shared';
|
|
10
10
|
import { kitIcon } from '../base/icons';
|
|
11
|
+
import { KIT_FACE_FIELD, KIT_FACE_RAISED, KIT_PART_ATTRIBUTE, KIT_PART_TABLE_HEAD, kitFocusRingRecipe, setKitFace } from '../recipes';
|
|
11
12
|
import { KIT_DROPDOWN_CLASS_CANDIDATES, onOutsidePress, popPlaceClass, showDropdownFitted, type PopPlace } from '../base/popup';
|
|
12
13
|
import { createPanelPortal, KIT_PANEL_PORTAL_CLASS_CANDIDATES, type PanelPortal } from '../data/overlay-portal';
|
|
13
14
|
import { trapTab } from '../data/d9-util';
|
|
14
|
-
import {
|
|
15
|
+
import { createReadRollback } from '../data/read-rollback';
|
|
16
|
+
import { KIT_CHECK_CLASS_CANDIDATES, attachMarkEvents, createCheck, isMark, markInput, paintCheck } from '../base/check-core';
|
|
15
17
|
import { KIT_TABLE_EXT } from './defaults';
|
|
16
18
|
import { kitText } from '../i18n/kit-text';
|
|
19
|
+
import { mergeClass } from './merge-class';
|
|
17
20
|
import { KIT_SKELETON_CLASS_CANDIDATES, buildSkeleton, skeletonConfigOf } from './skeleton';
|
|
18
21
|
|
|
19
22
|
// ---------------------------------------------------------------- KitTableHead
|
|
20
23
|
|
|
21
|
-
const HEAD_BUTTON_CLASS = 'inline-flex items-center gap-1 rounded-md text-start font-semibold transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
24
|
+
const HEAD_BUTTON_CLASS = '-mx-3 inline-flex items-center gap-1 rounded-md px-3 py-0.5 text-start font-semibold transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring';
|
|
22
25
|
const HEAD_SR_CLASS = 'sr-only';
|
|
23
26
|
const HEAD_MARK_CLASS = 'text-xs text-fg-subtle';
|
|
24
27
|
const HEAD_MARK_ACTIVE_CLASS = 'text-xs text-fg';
|
|
@@ -156,6 +159,7 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
156
159
|
cells: { type: 'array', default: [], desc: '表头格 [{ label, class, sort?, col?, filter?, group?, resizable? }];sort 非空即可排序列(值 = 排序键);col = 字段名(列显隐标记);filter = { kind: enum | text, param, options? } 时格内出漏斗钮;group = 所属列组下标(groups);resizable = 右缘留列宽拖拽手柄(KitTableTools 补)' },
|
|
157
160
|
groups: { type: 'array', default: [], desc: '列组(多级表头)[{ title, span, cols, blockClass, titleClass, leavesClass }];连续同组的 cells 收进一个组块(组标题格 + 叶子行)' },
|
|
158
161
|
scope: { type: 'string', default: '', desc: '区域作用域 id;给了就把 sort / order 写进 view 切片' },
|
|
162
|
+
readState: { type: 'string', default: '', desc: '列表对象的读状态,用于失败回滚' },
|
|
159
163
|
semantics: { type: 'enum', values: ['none', 'table'], default: 'none', desc: 'table = 表头行是 role=row、格是 columnheader(可排序列带 aria-sort),只在外壳是 role=table 的表格里用;none = 不写角色(树表等外壳没有表格角色的场合)' },
|
|
160
164
|
class: { ...CLASS_PROP, desc: '表头行容器类(栅格 + 底色)' },
|
|
161
165
|
},
|
|
@@ -173,8 +177,8 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
173
177
|
},
|
|
174
178
|
services: ['region'],
|
|
175
179
|
templateHtml: '<div data-soma-id="root"></div>',
|
|
176
|
-
controllerFactory: (
|
|
177
|
-
const P = (): Record<string, unknown> =>
|
|
180
|
+
controllerFactory: createKitController((api) => {
|
|
181
|
+
const P = (): Record<string, unknown> => api.props();
|
|
178
182
|
let root: HTMLElement | null = null;
|
|
179
183
|
let offs: Array<() => void> = [];
|
|
180
184
|
// 表头筛选面板状态(同一时刻至多开一个)
|
|
@@ -189,15 +193,56 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
189
193
|
|
|
190
194
|
const port =(): SomaRegionPort | null => {
|
|
191
195
|
const scope = str(P().scope);
|
|
192
|
-
const svc = (
|
|
196
|
+
const svc = (api.services as { region?: (id: string) => SomaRegionPort | null } | undefined)?.region;
|
|
193
197
|
return scope !== '' && typeof svc === 'function' ? svc(scope) : null;
|
|
194
198
|
};
|
|
195
199
|
|
|
200
|
+
// 重取失败回滚:点表头写了 sort / order(及回第 1 页)而重取失败时,写回最近一次读成功的值(只写切片,不抛 sort);
|
|
201
|
+
// 列筛选是用户输入,不回滚
|
|
202
|
+
const rollback = createReadRollback<{ sort: string; order: string; page: number | null }>({
|
|
203
|
+
readState: () => str(P().readState),
|
|
204
|
+
snapshot: () => {
|
|
205
|
+
const v = port()?.slice('view')?.get();
|
|
206
|
+
const rec = v !== null && typeof v === 'object' ? v as Record<string, unknown> : {};
|
|
207
|
+
const held = sortHeld(rec);
|
|
208
|
+
return { ...held, page: typeof rec.page === 'number' ? rec.page : null };
|
|
209
|
+
},
|
|
210
|
+
restore: (v) => {
|
|
211
|
+
const slice = port()?.slice('view');
|
|
212
|
+
if (!slice) return;
|
|
213
|
+
slice.set(v.sort === '' ? null : v.sort, 'sort');
|
|
214
|
+
slice.set(v.order === '' ? null : v.order, 'order');
|
|
215
|
+
const page = (slice.get() as { page?: unknown } | undefined)?.page;
|
|
216
|
+
if (v.page !== null && page !== v.page) {
|
|
217
|
+
try {
|
|
218
|
+
slice.set(v.page, 'page');
|
|
219
|
+
} catch (err) {
|
|
220
|
+
console.debug('[soma-kit] KitTableHead 无权写 page,页码回滚交给 page 写者', err);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
// 点表头写切片期间,切片订阅会同步触发重绘;这段重绘不是「读状态变了」,不喂给回滚状态机
|
|
226
|
+
let committing = false;
|
|
227
|
+
|
|
196
228
|
const paint = (): void => {
|
|
197
229
|
if (!root) return;
|
|
198
230
|
const p = P();
|
|
199
231
|
const held = sortHeld(port()?.slice('view')?.get());
|
|
200
232
|
root.className = joinClass('', p.class);
|
|
233
|
+
root.setAttribute(KIT_PART_ATTRIBUTE, KIT_PART_TABLE_HEAD);
|
|
234
|
+
// 重绘会换掉全部节点:记下焦点所在的排序钮,重绘后还回去
|
|
235
|
+
const activeEl = root.ownerDocument.activeElement;
|
|
236
|
+
const focusedSort = activeEl && root.contains(activeEl) ? activeEl.closest('[data-kit-sort]')?.getAttribute('data-kit-sort') ?? null : null;
|
|
237
|
+
// 筛选面板内的焦点(文本框 / 枚举选项)同样记下:读取开始 / 完成的重绘不该把正在输入的人踢出面板
|
|
238
|
+
const activePanel = activeEl instanceof HTMLElement ? activeEl.closest('[data-kit-filter-panel]') : null;
|
|
239
|
+
const panelFocus = activePanel !== null && activeEl instanceof HTMLElement
|
|
240
|
+
? {
|
|
241
|
+
text: activeEl.hasAttribute('data-kit-filter-text'),
|
|
242
|
+
opt: activeEl.closest('[data-kit-filter-opt]')?.getAttribute('data-kit-filter-opt') ?? null,
|
|
243
|
+
caret: activeEl instanceof HTMLInputElement ? activeEl.selectionStart : null,
|
|
244
|
+
}
|
|
245
|
+
: null;
|
|
201
246
|
root.replaceChildren();
|
|
202
247
|
let pending: { panel: HTMLElement; anchor: HTMLElement; cell: HTMLElement } | null = null;
|
|
203
248
|
const doc = root.ownerDocument;
|
|
@@ -290,6 +335,7 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
290
335
|
fbtn.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
|
|
291
336
|
fbtn.setAttribute('aria-label', `${kitText('soma.kit.filter_of', { label: cell.label }, root)}${value !== '' ? kitText('soma.kit.filtered', undefined, root) : ''}`);
|
|
292
337
|
fbtn.className = value !== '' ? FILTER_BUTTON_ACTIVE_CLASS : FILTER_BUTTON_CLASS;
|
|
338
|
+
setKitFace(fbtn, value !== '' ? KIT_FACE_RAISED : null); // 仅「已筛选」态有底色(primary-soft),闲置态是幽灵钮不标
|
|
293
339
|
fbtn.appendChild(funnelIcon(doc));
|
|
294
340
|
inner.appendChild(fbtn);
|
|
295
341
|
el.appendChild(inner);
|
|
@@ -319,10 +365,23 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
319
365
|
if (focusPanel && openCol !== null) {
|
|
320
366
|
focusPanel = false;
|
|
321
367
|
panelEl?.querySelector<HTMLElement>('input')?.focus();
|
|
368
|
+
} else if (panelFocus !== null && openCol !== null && panelEl !== null) {
|
|
369
|
+
const target = panelFocus.text
|
|
370
|
+
? panelEl.querySelector<HTMLInputElement>('[data-kit-filter-text]')
|
|
371
|
+
: panelFocus.opt !== null
|
|
372
|
+
? Array.from(panelEl.querySelectorAll<HTMLElement>('[data-kit-filter-opt]')).find((o) => o.getAttribute('data-kit-filter-opt') === panelFocus.opt) ?? null
|
|
373
|
+
: null;
|
|
374
|
+
// 枚举选项的标记挂在 label 上,焦点要落到里面的原生 input
|
|
375
|
+
(target !== null && isMark(target) ? (markInput(target) ?? target) : target)?.focus();
|
|
376
|
+
if (target instanceof HTMLInputElement && panelFocus.caret !== null) target.setSelectionRange(panelFocus.caret, panelFocus.caret);
|
|
322
377
|
} else if (focusBack !== null) {
|
|
323
378
|
const back = root.querySelector<HTMLElement>(`[data-kit-filter="${focusBack}"]`);
|
|
324
379
|
focusBack = null;
|
|
325
380
|
back?.focus();
|
|
381
|
+
} else if (focusedSort !== null) {
|
|
382
|
+
// 排序后整头重绘:焦点还给同一列的排序钮
|
|
383
|
+
const again = Array.from(root.querySelectorAll<HTMLElement>('[data-kit-sort]')).find((b) => b.getAttribute('data-kit-sort') === focusedSort);
|
|
384
|
+
again?.focus();
|
|
326
385
|
}
|
|
327
386
|
};
|
|
328
387
|
|
|
@@ -331,7 +390,7 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
331
390
|
const f = cell.filter!;
|
|
332
391
|
const panel = doc.createElement('div');
|
|
333
392
|
panel.setAttribute('role', 'dialog');
|
|
334
|
-
panel.setAttribute('aria-label', kitText('soma.kit.filter_of', { label: cell.label },
|
|
393
|
+
panel.setAttribute('aria-label', kitText('soma.kit.filter_of', { label: cell.label }, api.host));
|
|
335
394
|
panel.setAttribute('data-kit-filter-panel', cell.col);
|
|
336
395
|
panel.className = FILTER_PANEL_BASE;
|
|
337
396
|
if (f.kind === 'enum') {
|
|
@@ -353,9 +412,10 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
353
412
|
input.setAttribute('type', 'text');
|
|
354
413
|
input.setAttribute('data-kit-filter-text', '');
|
|
355
414
|
input.setAttribute('maxlength', String(KIT_TABLE_EXT.columnFilter.textMaxLen));
|
|
356
|
-
input.setAttribute('aria-label', kitText('soma.kit.contains_of', { label: cell.label },
|
|
357
|
-
input.setAttribute('placeholder', kitText('soma.kit.contains_ph', undefined,
|
|
415
|
+
input.setAttribute('aria-label', kitText('soma.kit.contains_of', { label: cell.label }, api.host));
|
|
416
|
+
input.setAttribute('placeholder', kitText('soma.kit.contains_ph', undefined, api.host));
|
|
358
417
|
input.className = FILTER_INPUT_CLASS;
|
|
418
|
+
setKitFace(input, KIT_FACE_FIELD);
|
|
359
419
|
draftText ??= value;
|
|
360
420
|
input.value = draftText;
|
|
361
421
|
panel.appendChild(input);
|
|
@@ -366,12 +426,14 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
366
426
|
clear.setAttribute('type', 'button');
|
|
367
427
|
clear.setAttribute('data-kit-filter-clear', '');
|
|
368
428
|
clear.className = FILTER_CLEAR_CLASS;
|
|
369
|
-
|
|
429
|
+
setKitFace(clear, KIT_FACE_RAISED);
|
|
430
|
+
clear.textContent = kitText('soma.kit.clear', undefined, api.host);
|
|
370
431
|
const apply = doc.createElement('button');
|
|
371
432
|
apply.setAttribute('type', 'button');
|
|
372
433
|
apply.setAttribute('data-kit-filter-apply', '');
|
|
373
434
|
apply.className = FILTER_APPLY_CLASS;
|
|
374
|
-
|
|
435
|
+
setKitFace(apply, KIT_FACE_RAISED);
|
|
436
|
+
apply.textContent = kitText('soma.kit.apply', undefined, api.host);
|
|
375
437
|
foot.appendChild(clear);
|
|
376
438
|
foot.appendChild(apply);
|
|
377
439
|
panel.appendChild(foot);
|
|
@@ -404,14 +466,13 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
404
466
|
}
|
|
405
467
|
}
|
|
406
468
|
}
|
|
407
|
-
|
|
469
|
+
api.emit('column_filter', { field: col, value });
|
|
408
470
|
closeFilter(true);
|
|
409
471
|
};
|
|
410
472
|
|
|
411
473
|
return {
|
|
412
|
-
|
|
413
|
-
root =
|
|
414
|
-
const r = root;
|
|
474
|
+
attach(r) {
|
|
475
|
+
root = r;
|
|
415
476
|
const onClick = (event: Event): void => {
|
|
416
477
|
const target = event.target as HTMLElement | null;
|
|
417
478
|
const fbtn = target?.closest<HTMLElement>('[data-kit-filter]');
|
|
@@ -443,20 +504,26 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
443
504
|
const slice = port()?.slice('view') ?? null;
|
|
444
505
|
const next = nextSort(sortHeld(slice?.get()), key);
|
|
445
506
|
if (slice) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
507
|
+
rollback.beforeCommit();
|
|
508
|
+
committing = true;
|
|
509
|
+
try {
|
|
510
|
+
slice.set(next.sort === '' ? null : next.sort, 'sort');
|
|
511
|
+
slice.set(next.order === '' ? null : next.order, 'order');
|
|
512
|
+
// 排序一变回第 1 页(本组件是 page 路径写者;没有分页器或写权被让出时忽略)
|
|
513
|
+
const page = (slice.get() as { page?: unknown } | undefined)?.page;
|
|
514
|
+
if (typeof page === 'number' && page > 1) {
|
|
515
|
+
try {
|
|
516
|
+
slice.set(1, 'page');
|
|
517
|
+
} catch (err) {
|
|
518
|
+
// 不是 page 写者(联动场景下由 KitLinkHub 订阅 sort 变化回第 1 页):不在这里回页,但留一条 debug 记录
|
|
519
|
+
console.debug('[soma-kit] KitTableHead 无权写 page,回第 1 页交给 page 写者', err);
|
|
520
|
+
}
|
|
456
521
|
}
|
|
522
|
+
} finally {
|
|
523
|
+
committing = false;
|
|
457
524
|
}
|
|
458
525
|
}
|
|
459
|
-
|
|
526
|
+
api.emit('sort', { sort: next.sort, order: next.order });
|
|
460
527
|
paint();
|
|
461
528
|
};
|
|
462
529
|
// 筛选面板内:勾选 / 输入只改草稿;Enter 应用;Esc 关闭并回漏斗钮
|
|
@@ -514,29 +581,42 @@ export function createKitTableHead(): SomaComponentDefinition {
|
|
|
514
581
|
() => { portal.destroy(); panelPortal = null; shellBind = null; },
|
|
515
582
|
];
|
|
516
583
|
const slice = port()?.slice('view');
|
|
517
|
-
if (typeof slice?.subscribe === 'function') offs.push(slice.subscribe(() =>
|
|
518
|
-
|
|
584
|
+
if (typeof slice?.subscribe === 'function') offs.push(slice.subscribe(() => api.refresh()));
|
|
585
|
+
return () => {
|
|
586
|
+
for (const off of offs) off();
|
|
587
|
+
offs = [];
|
|
588
|
+
root = null;
|
|
589
|
+
};
|
|
519
590
|
},
|
|
520
|
-
|
|
591
|
+
render(r) {
|
|
592
|
+
root = r;
|
|
593
|
+
// 先让回滚状态机看读状态(失败时写回切片),再按最终切片画表头
|
|
594
|
+
if (!committing) rollback.onProps();
|
|
521
595
|
paint();
|
|
522
596
|
},
|
|
523
|
-
onUnmount(): void {
|
|
524
|
-
for (const off of offs) off();
|
|
525
|
-
offs = [];
|
|
526
|
-
root = null;
|
|
527
|
-
},
|
|
528
597
|
};
|
|
529
|
-
},
|
|
598
|
+
}),
|
|
530
599
|
};
|
|
531
600
|
}
|
|
532
601
|
|
|
533
602
|
// ---------------------------------------------------------------- KitCollectionState
|
|
534
603
|
|
|
535
604
|
const STATE_BOX_CLASS = 'flex items-center justify-center rounded-lg border border-dashed border-border-subtle bg-surface-sunken px-4 py-10 text-sm text-fg-muted';
|
|
536
|
-
const STATE_ERROR_BOX_CLASS = 'flex items-center justify-center rounded-lg border border-border-subtle bg-danger-soft px-4 py-10 text-sm text-danger-on-soft';
|
|
605
|
+
const STATE_ERROR_BOX_CLASS = 'flex flex-col items-center justify-center gap-3 rounded-lg border border-border-subtle bg-danger-soft px-4 py-10 text-sm text-danger-on-soft';
|
|
606
|
+
const STATE_RETRY_CLASS = mergeClass(kitFocusRingRecipe('button'), 'px-3 py-1 text-danger-on-soft underline transition-colors hover:opacity-80');
|
|
607
|
+
|
|
608
|
+
/** 重取(只读重读,不是写入):优先用 core 挂在数据对象上的 retry(非枚举),退路是数据端口的 reload(对象名);无权限(forbidden)不给重试 */
|
|
609
|
+
function retryOf(data: unknown, object: string, services: unknown): (() => unknown) | null {
|
|
610
|
+
const d = data !== null && typeof data === 'object' ? data as { retry?: unknown; readState?: unknown } : null;
|
|
611
|
+
if (d?.readState === 'forbidden') return null;
|
|
612
|
+
if (d && typeof d.retry === 'function') return () => (d.retry as () => unknown).call(data);
|
|
613
|
+
const port = (services as { data?: { reload?: (names?: string[]) => unknown } } | undefined)?.data;
|
|
614
|
+
if (object !== '' && port && typeof port.reload === 'function') return () => port.reload!([object]);
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
537
617
|
|
|
538
618
|
export const KIT_COLLECTION_STATE_CLASS_CANDIDATES: readonly string[] = [
|
|
539
|
-
'hidden', STATE_BOX_CLASS, STATE_ERROR_BOX_CLASS,
|
|
619
|
+
'hidden', STATE_BOX_CLASS, STATE_ERROR_BOX_CLASS, STATE_RETRY_CLASS,
|
|
540
620
|
].flatMap((s) => s.split(/\s+/).filter((c) => c !== '')).concat(KIT_SKELETON_CLASS_CANDIDATES);
|
|
541
621
|
|
|
542
622
|
function pick(data: unknown, path: string): unknown {
|
|
@@ -576,78 +656,114 @@ export function createKitCollectionState(): SomaComponentDefinition {
|
|
|
576
656
|
props: {
|
|
577
657
|
data: { type: 'object', default: {}, desc: '列表对象整体(page.data.<对象>);取不到行数组读作加载中' },
|
|
578
658
|
rows: { type: 'array', default: [], desc: '行数组(只用于触发重绘)' },
|
|
579
|
-
config: { type: 'object', default: {}, desc: '{ rowsPath, errorPath, loading, empty, error, skeleton?, mode? }:响应里行数组 / 错误文案的路径与三态文案;skeleton = { kind, cols?, listClass? } 时加载态画骨架屏;mode: single = 单对象视图(只判加载,并藏起紧随其后的 data-kit-skeleton-body
|
|
659
|
+
config: { type: 'object', default: {}, desc: '{ rowsPath, errorPath, loading, empty, error, skeleton?, mode? }:响应里行数组 / 错误文案的路径与三态文案;skeleton = { kind, cols?, listClass? } 时加载态画骨架屏;mode: single = 单对象视图(只判加载,并藏起紧随其后的 data-kit-skeleton-body);mode: errorOnly = 页面关闭了内置三态(state: false),只在读状态 error / forbidden 或错误路径有文案时显示失败面板(含重试),加载 / 空态 / 骨架一律隐藏' },
|
|
580
660
|
class: CLASS_PROP,
|
|
581
661
|
},
|
|
582
662
|
emits: {},
|
|
583
663
|
},
|
|
664
|
+
services: ['data'],
|
|
584
665
|
templateHtml: '<div data-soma-id="root" class="hidden"><div data-soma-id="box" role="status"></div></div>',
|
|
585
|
-
controllerFactory: (
|
|
586
|
-
const P = (): Record<string, unknown> => (ctx.readProps ? ctx.readProps() : ctx.props);
|
|
587
|
-
let root: HTMLElement | null = null;
|
|
666
|
+
controllerFactory: createKitController((api) => {
|
|
588
667
|
let box: HTMLElement | null = null;
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
if (!root || !box) return;
|
|
592
|
-
const p = P();
|
|
593
|
-
const cfg = p.config !== null && typeof p.config === 'object' ? p.config as Record<string, unknown> : {};
|
|
594
|
-
const single = str(cfg.mode) === 'single';
|
|
595
|
-
const { status, message } = single
|
|
596
|
-
? { status: singleStatus(p.data), message: '' }
|
|
597
|
-
: collectionStatus(p.data, str(cfg.rowsPath, 'result.rows'), str(cfg.errorPath, 'result.error'));
|
|
598
|
-
// 单对象视图:加载态藏起紧随其后的内容体(空值内容在骨架下面没有意义)
|
|
599
|
-
if (single) {
|
|
600
|
-
const body = ctx.host.nextElementSibling;
|
|
601
|
-
if (body && body.hasAttribute('data-kit-skeleton-body')) body.classList.toggle('hidden', status === 'loading');
|
|
602
|
-
}
|
|
603
|
-
if (status === 'ready') {
|
|
604
|
-
root.className = joinClass('hidden', p.class);
|
|
605
|
-
box.textContent = '';
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
root.className = joinClass('', p.class);
|
|
609
|
-
const skeleton = status === 'loading' ? skeletonConfigOf(cfg.skeleton) : null;
|
|
610
|
-
if (status === 'loading' && skeleton !== null) {
|
|
611
|
-
box.className = '';
|
|
612
|
-
box.setAttribute('role', 'status');
|
|
613
|
-
box.setAttribute('aria-busy', 'true');
|
|
614
|
-
box.setAttribute('aria-label', str(cfg.loading, kitText('soma.kit.loading', undefined, root)));
|
|
615
|
-
box.replaceChildren(buildSkeleton(box.ownerDocument, skeleton));
|
|
616
|
-
} else if (status === 'loading') {
|
|
617
|
-
box.className = STATE_BOX_CLASS;
|
|
618
|
-
box.setAttribute('role', 'status');
|
|
619
|
-
box.setAttribute('aria-busy', 'true');
|
|
620
|
-
box.removeAttribute('aria-label');
|
|
621
|
-
box.textContent = str(cfg.loading, kitText('soma.kit.loading', undefined, root));
|
|
622
|
-
} else if (status === 'empty') {
|
|
623
|
-
box.className = STATE_BOX_CLASS;
|
|
624
|
-
box.setAttribute('role', 'status');
|
|
625
|
-
box.removeAttribute('aria-busy');
|
|
626
|
-
box.removeAttribute('aria-label');
|
|
627
|
-
box.textContent = str(cfg.empty, kitText('soma.kit.empty', undefined, root));
|
|
628
|
-
} else {
|
|
629
|
-
box.className = STATE_ERROR_BOX_CLASS;
|
|
630
|
-
box.setAttribute('role', 'alert');
|
|
631
|
-
box.removeAttribute('aria-busy');
|
|
632
|
-
box.removeAttribute('aria-label');
|
|
633
|
-
box.textContent = str(cfg.error) !== '' ? str(cfg.error) : message !== '' ? message : kitText('soma.kit.load_failed', undefined, root);
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
|
|
668
|
+
// 「重试」由键盘触发后置位:面板再次渲染出重试按钮时把焦点还给它
|
|
669
|
+
let retryByKeyboard = false;
|
|
637
670
|
return {
|
|
638
|
-
|
|
639
|
-
root = findRoot(ctx.host);
|
|
671
|
+
attach(root) {
|
|
640
672
|
box = root.querySelector<HTMLElement>('[data-soma-scoped-id="box"]') ?? root.querySelector<HTMLElement>('[data-soma-id="box"]');
|
|
641
|
-
|
|
673
|
+
return () => { box = null; };
|
|
642
674
|
},
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
675
|
+
render(root, p) {
|
|
676
|
+
if (!box) return;
|
|
677
|
+
// 重试钮正持有焦点(Tab 停在上面、没点击):无关对象的重取也会让本组件重绘并重建钮,重建后把焦点还给新钮
|
|
678
|
+
const activeAtStart = box.ownerDocument.activeElement;
|
|
679
|
+
const hadRetryFocus = activeAtStart instanceof HTMLElement && box.contains(activeAtStart) && activeAtStart.hasAttribute('data-kit-state-retry');
|
|
680
|
+
const cfg = p.config !== null && typeof p.config === 'object' ? p.config as Record<string, unknown> : {};
|
|
681
|
+
const single = str(cfg.mode) === 'single';
|
|
682
|
+
let { status, message }: { status: KitCollectionStatus; message: string } = single
|
|
683
|
+
? { status: singleStatus(p.data), message: '' }
|
|
684
|
+
: collectionStatus(p.data, str(cfg.rowsPath, 'result.rows'), str(cfg.errorPath, 'result.error'));
|
|
685
|
+
// core 的读状态(不可枚举的 readState / errorMessage)与行数组、错误路径各自独立,按先后顺序合成:
|
|
686
|
+
const readMeta = !single && p.data !== null && typeof p.data === 'object' ? p.data as { readState?: unknown; errorMessage?: unknown } : null;
|
|
687
|
+
const readState = readMeta?.readState;
|
|
688
|
+
if (readState === 'error' || readState === 'forbidden') {
|
|
689
|
+
// ① 读状态失败:不论取没取到行数组(ready / empty / loading)一律判失败——重取失败但旧行还在、或取不到行数组都不再停在加载态;
|
|
690
|
+
// 每次重取失败 core 只更新 errorMessage / readState,错误路径上的占位文案停在第一次失败,所以以最新消息为准(config.error 仍最优先,见下)
|
|
691
|
+
const wasError = status === 'error';
|
|
692
|
+
status = 'error';
|
|
693
|
+
if (typeof readMeta?.errorMessage === 'string' && (!wasError || readMeta.errorMessage !== '')) message = readMeta.errorMessage;
|
|
694
|
+
else if (!wasError) message = '';
|
|
695
|
+
} else if (readState === 'loading') {
|
|
696
|
+
// ② 失败后点重试:错误路径上的失败标记不会清,重试进行中按加载态呈现,不再显示失败与重试按钮;
|
|
697
|
+
// 上一轮是空数组、这一轮显式重取,同样给加载反馈而不是停在「暂无数据」
|
|
698
|
+
if (status === 'error' || status === 'empty') { status = 'loading'; message = ''; }
|
|
699
|
+
}
|
|
700
|
+
// 单对象视图:加载态藏起紧随其后的内容体(空值内容在骨架下面没有意义)
|
|
701
|
+
if (single) {
|
|
702
|
+
const body = api.host.nextElementSibling;
|
|
703
|
+
if (body && body.hasAttribute('data-kit-skeleton-body')) body.classList.toggle('hidden', status === 'loading');
|
|
704
|
+
}
|
|
705
|
+
// 键盘重试的归还标记:旧行还在时重取期间 status 会回到 ready / empty,那是读取进行中、不能清;读完(读状态不是 loading)才清
|
|
706
|
+
if ((status === 'ready' || status === 'empty') && readState !== 'loading') retryByKeyboard = false;
|
|
707
|
+
// errorOnly(state: false):只有失败才画面板,加载 / 空态 / 就绪一律隐藏
|
|
708
|
+
const errorOnly = str(cfg.mode) === 'errorOnly';
|
|
709
|
+
if (status === 'ready' || (errorOnly && status !== 'error')) {
|
|
710
|
+
root.className = joinClass('hidden', p.class);
|
|
711
|
+
box.textContent = '';
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
root.className = joinClass('', p.class);
|
|
715
|
+
const skeleton = status === 'loading' ? skeletonConfigOf(cfg.skeleton) : null;
|
|
716
|
+
if (status === 'loading' && skeleton !== null) {
|
|
717
|
+
box.className = '';
|
|
718
|
+
box.setAttribute('role', 'status');
|
|
719
|
+
box.setAttribute('aria-busy', 'true');
|
|
720
|
+
box.setAttribute('aria-label', str(cfg.loading, kitText('soma.kit.loading', undefined, root)));
|
|
721
|
+
box.replaceChildren(buildSkeleton(box.ownerDocument, skeleton));
|
|
722
|
+
} else if (status === 'loading') {
|
|
723
|
+
box.className = STATE_BOX_CLASS;
|
|
724
|
+
box.setAttribute('role', 'status');
|
|
725
|
+
box.setAttribute('aria-busy', 'true');
|
|
726
|
+
box.removeAttribute('aria-label');
|
|
727
|
+
box.textContent = str(cfg.loading, kitText('soma.kit.loading', undefined, root));
|
|
728
|
+
} else if (status === 'empty') {
|
|
729
|
+
box.className = STATE_BOX_CLASS;
|
|
730
|
+
box.setAttribute('role', 'status');
|
|
731
|
+
box.removeAttribute('aria-busy');
|
|
732
|
+
box.removeAttribute('aria-label');
|
|
733
|
+
box.textContent = str(cfg.empty, kitText('soma.kit.empty', undefined, root));
|
|
734
|
+
} else {
|
|
735
|
+
box.className = STATE_ERROR_BOX_CLASS;
|
|
736
|
+
box.setAttribute('role', 'alert');
|
|
737
|
+
box.removeAttribute('aria-busy');
|
|
738
|
+
box.removeAttribute('aria-label');
|
|
739
|
+
const doc = box.ownerDocument;
|
|
740
|
+
const text = doc.createElement('span');
|
|
741
|
+
text.textContent = str(cfg.error) !== '' ? str(cfg.error) : message !== '' ? message : kitText('soma.kit.load_failed', undefined, root);
|
|
742
|
+
box.replaceChildren(text);
|
|
743
|
+
const retry = retryOf(p.data, str(cfg.object), api.services);
|
|
744
|
+
if (retry !== null) {
|
|
745
|
+
const btn = doc.createElement('button');
|
|
746
|
+
btn.type = 'button';
|
|
747
|
+
btn.className = STATE_RETRY_CLASS;
|
|
748
|
+
btn.setAttribute('data-kit-state-retry', '');
|
|
749
|
+
btn.textContent = kitText('soma.kit.ct_retry', undefined, root);
|
|
750
|
+
btn.addEventListener('click', (event) => {
|
|
751
|
+
// 键盘触发的 click(detail 为 0):面板随即切到加载态、按钮被销毁,焦点会丢;记下来,重试再次失败时还给新按钮
|
|
752
|
+
if (event.detail === 0) retryByKeyboard = true;
|
|
753
|
+
try { void Promise.resolve(retry()).catch(() => {}); } catch { /* 同步抛错同样忽略:失败态由数据对象的读状态呈现 */ }
|
|
754
|
+
});
|
|
755
|
+
box.appendChild(btn);
|
|
756
|
+
if (retryByKeyboard || hadRetryFocus) {
|
|
757
|
+
const active = doc.activeElement;
|
|
758
|
+
if (active === null || active === doc.body) {
|
|
759
|
+
btn.focus({ preventScroll: true });
|
|
760
|
+
retryByKeyboard = false;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
649
765
|
},
|
|
650
766
|
};
|
|
651
|
-
},
|
|
767
|
+
}),
|
|
652
768
|
};
|
|
653
769
|
}
|