soma-kit 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -110
- package/bin/soma-kit.mjs +1 -1
- package/bin/soma.mjs +22 -0
- package/package.json +13 -7
- package/packs/finance/reconcile-board.ts +5 -2
- package/packs/finance/reconcile-desk/compile.ts +3 -2
- package/spec/generated/kit-app.schema.json +776 -38
- package/spec/generated/kit-page.schema.json +1613 -224
- package/spec/kit-grammar.json +770 -529
- package/spec/kit-grammar.schema.json +1962 -392
- package/src/app/app-config.ts +371 -347
- package/src/app/component-gate.ts +12 -15
- package/src/app/compose-apps.ts +79 -8
- package/src/app/define-kit-actions.ts +245 -41
- package/src/app/define-kit-app.ts +174 -31
- package/src/app/define-kit-view.ts +100 -0
- package/src/app/envelope.ts +1 -161
- package/src/app/index.ts +13 -2
- package/src/app/kit-view-context.ts +290 -0
- package/src/app/notify-renderer.ts +1 -115
- package/src/app/paged-list-adapter.ts +1 -240
- package/src/app/server-pages.ts +8 -2
- package/src/app/server.ts +491 -101
- package/src/app/submit.types.ts +1 -1
- package/src/app/theme-endpoint.ts +63 -0
- package/src/app/theme-runtime-shared.ts +1 -0
- package/src/app/theme-runtime.ts +663 -0
- package/src/base/action-busy.ts +2 -2
- package/src/base/action-gate.ts +4 -255
- package/src/base/action-slots.ts +47 -0
- package/src/base/alert.ts +5 -3
- package/src/base/avatar.ts +2 -2
- package/src/base/button.ts +46 -29
- package/src/base/cascader.ts +11 -12
- package/src/base/check-core.ts +1 -1
- package/src/base/choice.ts +28 -26
- package/src/base/class-candidates.ts +17 -0
- package/src/base/color-picker.ts +6 -6
- package/src/base/combobox.ts +5 -3
- package/src/base/command-palette.ts +9 -5
- package/src/base/countdown.ts +1 -1
- package/src/base/date-range.ts +25 -11
- package/src/base/date.ts +85 -17
- package/src/base/divider.ts +2 -2
- package/src/base/fab.ts +11 -4
- package/src/base/image.ts +1 -1
- package/src/base/index.ts +9 -3
- package/src/base/input.ts +42 -13
- package/src/base/kbd.ts +3 -1
- package/src/base/link.ts +4 -4
- package/src/base/listbox-core.ts +50 -30
- package/src/base/loading-gate.ts +133 -0
- package/src/base/mentions.ts +5 -5
- package/src/base/menu-button.ts +6 -1
- package/src/base/menu-core.ts +4 -0
- package/src/base/motion/aura.ts +2 -2
- package/src/base/motion/hover-3d.ts +2 -2
- package/src/base/motion/hover-gallery.ts +2 -2
- package/src/base/motion/marquee.ts +2 -2
- package/src/base/motion/text-rotate.ts +2 -2
- package/src/base/number.ts +93 -80
- package/src/base/otp.ts +4 -1
- package/src/base/permission-gate.ts +6 -0
- package/src/base/popover.ts +40 -8
- package/src/base/popup.ts +79 -14
- package/src/base/price-text.ts +2 -2
- package/src/base/progress.ts +2 -2
- package/src/base/qr-code.ts +4 -4
- package/src/base/qty-stepper.ts +9 -3
- package/src/base/range.ts +2 -2
- package/src/base/rating.ts +1 -1
- package/src/base/segmented.ts +4 -0
- package/src/base/select.ts +4 -3
- package/src/base/shared.ts +221 -29
- package/src/base/swap.ts +4 -1
- package/src/base/switch.ts +1 -1
- package/src/base/tag-input.ts +14 -10
- package/src/base/tag.ts +5 -1
- package/src/base/text.ts +39 -6
- package/src/base/textarea.ts +37 -11
- package/src/base/time-picker.ts +12 -9
- package/src/base/tree-select.ts +15 -8
- package/src/base/upload.ts +34 -5
- package/src/base/virtual-list.ts +107 -1
- package/src/biz/approval-desk/compile.ts +23 -41
- package/src/biz/auth-panel/compile.ts +37 -52
- package/src/biz/auth-panel/index.ts +1 -1
- package/src/biz/category-crud/compile.ts +22 -36
- package/src/biz/checkout-page/compile.ts +21 -5
- package/src/biz/compose.ts +13 -27
- package/src/biz/define.ts +5 -4
- package/src/biz/import-wizard/compile.ts +22 -26
- package/src/biz/import-wizard/hub.ts +126 -61
- package/src/biz/import-wizard/shell.ts +3 -3
- package/src/biz/index.ts +3 -3
- package/src/biz/landing-page/compile.ts +19 -3
- package/src/biz/link/hub.ts +49 -20
- package/src/biz/link/shared.ts +115 -118
- package/src/biz/master-sub/compile.ts +31 -44
- package/src/biz/multi-board/compile.ts +34 -49
- package/src/biz/multi-board/index.ts +18 -1
- package/src/biz/multi-board/shell.ts +24 -15
- package/src/biz/notification-center/compile.ts +21 -33
- package/src/biz/page-templates/domain-templates.ts +80 -13
- package/src/biz/page-templates/result-page/compile.ts +11 -2
- package/src/biz/page-templates/shared.ts +34 -36
- package/src/biz/record-detail/compile.ts +47 -42
- package/src/biz/record-detail/index.ts +11 -1
- package/src/biz/settings-center/compile.ts +6 -5
- package/src/biz/shared/action-host.ts +91 -211
- package/src/biz/shared/compile-helpers.ts +80 -0
- package/src/biz/shared/coordinator.ts +486 -83
- package/src/biz/shared/index.ts +8 -2
- package/src/biz/shared/overlay-shell.ts +80 -0
- package/src/biz/shared/pipes.ts +43 -30
- package/src/biz/shared/remove-key.ts +6 -0
- package/src/biz/shared/remove-wire.ts +29 -0
- package/src/biz/shared/runtime-hub.ts +216 -24
- package/src/biz/single-form/compile.ts +15 -37
- package/src/biz/standard-crud/compile.ts +62 -107
- package/src/biz/standard-crud/shell.ts +16 -66
- package/src/biz/step-form/compile.ts +26 -97
- package/src/biz/step-form/hub.ts +34 -41
- package/src/biz/types.ts +4 -3
- package/src/cli/core-imports.ts +54 -0
- package/src/cli/kit-cli.ts +130 -26
- package/src/cli/kit-init.ts +222 -0
- package/src/cli/service-endpoint-check.ts +425 -0
- package/src/cli/source-path-check.d.mts +17 -0
- package/src/cli/source-path-check.mjs +334 -0
- package/src/cli/view-writes.ts +752 -0
- package/src/compile/action-host-attach.ts +21 -29
- package/src/compile/closed-set.ts +509 -0
- package/src/compile/compile-page.ts +219 -72
- package/src/compile/component-candidates.ts +1 -1
- package/src/compile/hints.ts +30 -1
- package/src/compile/index.ts +1 -0
- package/src/compile/kit-error.ts +1 -0
- package/src/compile/locate.ts +21 -1
- package/src/compile/parse.ts +370 -41
- package/src/compile/redirect.ts +6 -2
- package/src/compile/styles.ts +35 -2
- package/src/compile/types.ts +18 -2
- package/src/compile/view-check.ts +151 -0
- package/src/data/amount-breakdown.ts +2 -2
- package/src/data/anchor-nav.ts +2 -2
- package/src/data/approval-flow.ts +2 -2
- package/src/data/assignment-picker.ts +40 -29
- package/src/data/async-result-panel.ts +62 -6
- package/src/data/breadcrumbs.ts +2 -2
- package/src/data/calendar.ts +22 -25
- package/src/data/carousel.ts +5 -2
- package/src/data/chart.ts +42 -34
- package/src/data/checklist.ts +2 -2
- package/src/data/code-view.ts +4 -2
- package/src/data/comment-thread.ts +5 -2
- package/src/data/confirm-dialog.ts +10 -0
- package/src/data/context-menu.ts +29 -37
- package/src/data/d9-util.ts +2 -18
- package/src/data/diff.ts +4 -2
- package/src/data/dock.ts +2 -2
- package/src/data/embed.ts +2 -1
- package/src/data/field-mapper.ts +31 -26
- package/src/data/flow-editor-contract.ts +1 -1
- package/src/data/flow-editor.ts +89 -100
- package/src/data/flow-node-options.ts +90 -0
- package/src/data/flow-remote-options.ts +0 -103
- package/src/data/footer.ts +2 -2
- package/src/data/form-draft-registry.ts +2 -4
- package/src/data/gantt.ts +14 -17
- package/src/data/hero.ts +2 -2
- package/src/data/image-viewer.ts +20 -26
- package/src/data/index.ts +0 -2
- package/src/data/item-list.ts +31 -22
- package/src/data/kanban.ts +43 -42
- package/src/data/media-grid.ts +14 -19
- package/src/data/menu.ts +2 -2
- package/src/data/mockup.ts +2 -2
- package/src/data/modal-dialog.ts +22 -18
- package/src/data/navbar.ts +7 -2
- package/src/data/notify-renderer.ts +235 -0
- package/src/data/object-form.ts +1036 -648
- package/src/data/pager.ts +65 -29
- package/src/data/permission-matrix.ts +20 -21
- package/src/data/permission-tree.ts +28 -26
- package/src/data/pricing-table.ts +9 -3
- package/src/data/reaction-bar.ts +77 -88
- package/src/data/read-rollback.ts +73 -0
- package/src/data/record-card.ts +3 -3
- package/src/data/record-picker.ts +93 -50
- package/src/data/redirect.ts +32 -32
- package/src/data/remote-options.ts +13 -6
- package/src/data/request-console.ts +5 -3
- package/src/data/resident.ts +2 -1
- package/src/data/result-panel.ts +4 -2
- package/src/data/rich-text.ts +45 -55
- package/src/data/row-editor.ts +285 -52
- package/src/data/rule-builder.ts +18 -12
- package/src/data/shape-util.ts +4 -0
- package/src/data/stat-group.ts +243 -101
- package/src/data/static-registry.ts +22 -11
- package/src/data/steps.ts +2 -2
- package/src/data/survey.ts +24 -29
- package/src/data/system-switcher.ts +2 -2
- package/src/data/timeline.ts +2 -2
- package/src/data/tour-guide.ts +22 -29
- package/src/data/transfer.ts +27 -23
- package/src/data/tree-table.ts +96 -48
- package/src/data/tree.ts +27 -34
- package/src/data/trend-line.ts +6 -24
- package/src/data/virtual-rows.ts +118 -76
- package/src/data/watermark.ts +2 -2
- package/src/data/wrap.ts +63 -38
- package/src/frames/blank-frame.ts +1 -0
- package/src/frames/index.ts +2 -2
- package/src/frames/page-bar.ts +12 -11
- package/src/frames/page-header.ts +14 -5
- package/src/frames/page-status.ts +2 -2
- package/src/frames/shared.ts +23 -17
- package/src/frames/single-frame.ts +1 -0
- package/src/frames/split-frame/shell.ts +5 -5
- package/src/frames/split-frame/wiring.ts +2 -2
- package/src/frames/tabs-frame/shell.ts +2 -13
- package/src/frames/tabs-frame/wiring.ts +4 -8
- package/src/frames/top-main-frame.ts +1 -0
- package/src/frames/types.ts +13 -2
- package/src/frames/workspace-frame/extras.ts +20 -4
- package/src/frames/workspace-frame/index.ts +1 -1
- package/src/frames/workspace-frame/shell.ts +1 -0
- package/src/frames/workspace-frame/state.ts +13 -6
- package/src/frames/workspace-frame/view.ts +119 -25
- package/src/generated/kit-grammar-runtime.ts +430 -366
- package/src/generated/page-origin.ts +0 -11
- package/src/i18n/kit-text.ts +23 -27
- package/src/index.ts +2 -1
- package/src/object-renderer/action-gate.ts +11 -147
- package/src/object-renderer/arrange.ts +71 -77
- package/src/object-renderer/collapse-wiring.ts +2 -2
- package/src/object-renderer/collection-expand.ts +2 -2
- package/src/object-renderer/collection-parts.ts +216 -100
- package/src/object-renderer/collection-table.ts +180 -42
- package/src/object-renderer/collection.ts +95 -79
- package/src/object-renderer/compile-data.ts +85 -100
- package/src/object-renderer/crud-bridge.ts +32 -0
- package/src/object-renderer/defaults.ts +8 -14
- package/src/object-renderer/display-checks.ts +3 -24
- package/src/object-renderer/emit-events.ts +186 -172
- package/src/object-renderer/emit-object.ts +15 -2
- package/src/object-renderer/emit-static.ts +174 -132
- package/src/object-renderer/field-value.ts +593 -396
- package/src/object-renderer/filter-reload.ts +70 -0
- package/src/object-renderer/form-detail.ts +112 -2
- package/src/object-renderer/index.ts +26 -0
- package/src/object-renderer/key-field.ts +12 -0
- package/src/object-renderer/linkage.ts +7 -270
- package/src/object-renderer/merge-class.ts +18 -1
- package/src/object-renderer/path-pick.ts +27 -0
- package/src/object-renderer/render-object.ts +405 -86
- package/src/object-renderer/request-actions.ts +230 -249
- package/src/object-renderer/table-actions.ts +195 -95
- package/src/object-renderer/table-summary.ts +2 -2
- package/src/object-renderer/table-tools.ts +418 -84
- package/src/object-renderer/types.ts +128 -122
- package/src/object-renderer/view-binding.ts +196 -0
- package/src/page-target/ai-surface.ts +37 -0
- package/src/page-target/compile.ts +48 -8
- package/src/page-target/index.ts +8 -1
- package/src/page-target/intent-schema.ts +154 -28
- package/src/page-target/target.ts +257 -50
- package/src/page-target/writer-policy.ts +14 -3
- package/src/recipes/container.ts +165 -0
- package/src/recipes/control.ts +219 -0
- package/src/recipes/index.ts +263 -0
- package/src/recipes/overlay.ts +182 -0
- package/src/recipes/state.ts +70 -0
- package/src/recipes/table-row.ts +51 -0
- package/src/recipes/typography.ts +87 -0
- package/src/shared/action-field-guard.ts +41 -0
- package/src/shared/envelope.ts +207 -0
- package/src/shared/escape.ts +57 -0
- package/src/shared/kit-error.ts +21 -0
- package/src/shared/paged-list-adapter.ts +240 -0
- package/src/shared/path-guard.ts +127 -0
- package/src/shared/theme-runtime-shared.ts +175 -0
- package/src/shared/view-info.ts +10 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/kit-theme-text.ts +1 -1
- package/src/theme/kit-theme.css +38 -1
- package/src/theme/kit-theme.tpl +38 -1
- package/src/theme/nine-dim-structure.ts +77 -0
- package/src/theme/surface-layers.ts +97 -0
- package/src/theme/theme-tokens.ts +85 -79
- package/src/theme/theme-types.ts +71 -0
- package/src/theme/typography.ts +17 -17
- package/src/biz/shared/step-values.ts +0 -25
- package/src/biz/step-form/steps-ref.ts +0 -112
- package/src/data/options-bus.ts +0 -24
- package/src/data/prompt-dialog.ts +0 -235
- package/src/object-renderer/adopt-gate.ts +0 -333
- package/src/object-renderer/field-policy.ts +0 -89
- package/src/object-renderer/outcome-draft.ts +0 -61
- package/src/theme/nine-dim-palettes.ts +0 -1278
package/src/data/reaction-bar.ts
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
// 选一个抛 `add { emoji }`(已存在的表情等同点它的药丸)。选择层 Esc 关闭并回焦「+」,点外面关闭,方向键在候选间移动。
|
|
7
7
|
// 表情种类上限同真源 maxKinds。
|
|
8
8
|
|
|
9
|
-
import type {
|
|
10
|
-
import { bool, joinClass, num, str } from '../base/shared';
|
|
9
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
10
|
+
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
11
11
|
import { kitKey, kitText } from '../i18n/kit-text';
|
|
12
|
+
import { setKitFace } from '../recipes';
|
|
12
13
|
import { classTokens, mk, rowsOf, textOf } from './shape-util';
|
|
13
14
|
import { REACTION_MAX_KINDS, REACTION_PALETTE } from './d9-limits';
|
|
14
15
|
import { attrEsc } from './d9-util';
|
|
@@ -66,13 +67,12 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
66
67
|
},
|
|
67
68
|
},
|
|
68
69
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
69
|
-
controllerFactory: (
|
|
70
|
-
const P = (): Record<string, unknown> =>
|
|
70
|
+
controllerFactory: createKitController((api) => {
|
|
71
|
+
const P = (): Record<string, unknown> => api.props();
|
|
71
72
|
let root: HTMLElement | null = null;
|
|
72
73
|
let panelOpen = false;
|
|
73
74
|
let sig = '';
|
|
74
75
|
const flipped = new Map<string, boolean>();
|
|
75
|
-
let removeListeners: Array<() => void> = [];
|
|
76
76
|
// 添加层挂到浮层端口后不再是 root 的后代,root 上的委托收不到它的事件:重画出的面板元素直接绑这两个处理函数
|
|
77
77
|
let panelClick: EventListener | null = null;
|
|
78
78
|
let panelKeydown: EventListener | null = null;
|
|
@@ -95,78 +95,20 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
95
95
|
const on = !(cur?.mine ?? false);
|
|
96
96
|
if (base) flipped.set(emoji, on);
|
|
97
97
|
const next = view().find((r) => r.emoji === emoji);
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
api.emit('toggle', { emoji, on, count: next?.count ?? (on ? 1 : 0) });
|
|
99
|
+
api.refresh();
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
const closePanel = (focusAdd: boolean): void => {
|
|
103
103
|
if (!panelOpen) return;
|
|
104
104
|
panelOpen = false;
|
|
105
|
-
|
|
105
|
+
api.refresh();
|
|
106
106
|
if (focusAdd) root?.querySelector<HTMLElement>('[data-kit-add]')?.focus();
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
function paint(): void {
|
|
110
|
-
if (!root) return;
|
|
111
|
-
const p = P();
|
|
112
|
-
const dataSig = JSON.stringify(reactionsOf(p.data));
|
|
113
|
-
if (dataSig !== sig) { sig = dataSig; flipped.clear(); }
|
|
114
|
-
root.className = joinClass(ROOT_CLASS, p.class);
|
|
115
|
-
// 整条重建会丢焦点(键盘点药丸 / 「+」后):记下焦点所在,重绘后落回同一个
|
|
116
|
-
const focused = root.contains(document.activeElement) ? document.activeElement as HTMLElement : null;
|
|
117
|
-
const focusEmoji = focused?.closest('[data-kit-reaction]')?.getAttribute('data-kit-reaction') ?? null;
|
|
118
|
-
const focusAdd = focused?.closest('[data-kit-add]') != null;
|
|
119
|
-
releaseDropdownsIn(root);
|
|
120
|
-
root.textContent = '';
|
|
121
|
-
const disabled = bool(p.disabled);
|
|
122
|
-
for (const r of view()) {
|
|
123
|
-
const b = mk('button', r.mine ? PILL_MINE : PILL_CLASS);
|
|
124
|
-
b.type = 'button';
|
|
125
|
-
b.setAttribute('data-kit-reaction', r.emoji);
|
|
126
|
-
b.setAttribute('aria-pressed', r.mine ? 'true' : 'false');
|
|
127
|
-
b.setAttribute('aria-label', `${r.label !== '' ? r.label : r.emoji} ${r.count}`);
|
|
128
|
-
if (disabled) { b.disabled = true; b.setAttribute('aria-disabled', 'true'); }
|
|
129
|
-
b.appendChild(mk('span', '', r.emoji));
|
|
130
|
-
b.appendChild(mk('span', '', String(r.count)));
|
|
131
|
-
root.appendChild(b);
|
|
132
|
-
}
|
|
133
|
-
if (bool(p.addable) && !disabled && view().length < REACTION_MAX_KINDS) {
|
|
134
|
-
const add = mk('button', ADD_CLASS, '+');
|
|
135
|
-
add.type = 'button';
|
|
136
|
-
add.setAttribute('data-kit-add', '');
|
|
137
|
-
add.setAttribute('aria-label', str(p.add_text, kitText('soma.kit.add_reaction', undefined, root)));
|
|
138
|
-
add.setAttribute('aria-haspopup', 'true');
|
|
139
|
-
add.setAttribute('aria-expanded', panelOpen ? 'true' : 'false');
|
|
140
|
-
root.appendChild(add);
|
|
141
|
-
if (panelOpen) {
|
|
142
|
-
const panel = mk('div', PANEL_CLASS);
|
|
143
|
-
panel.setAttribute('role', 'group');
|
|
144
|
-
panel.setAttribute('aria-label', str(p.add_text, kitText('soma.kit.add_reaction', undefined, root)));
|
|
145
|
-
panel.setAttribute('data-kit-panel', '');
|
|
146
|
-
palette().forEach((e, i) => {
|
|
147
|
-
const c = mk('button', CHOICE_CLASS, e);
|
|
148
|
-
c.type = 'button';
|
|
149
|
-
c.setAttribute('data-kit-choice', e);
|
|
150
|
-
c.tabIndex = i === 0 ? 0 : -1;
|
|
151
|
-
panel.appendChild(c);
|
|
152
|
-
});
|
|
153
|
-
root.appendChild(panel);
|
|
154
|
-
syncDropdown(panel, true, PANEL_BASE_CLASS, root);
|
|
155
|
-
if (!root.contains(panel)) {
|
|
156
|
-
if (panelClick) panel.addEventListener('click', panelClick);
|
|
157
|
-
if (panelKeydown) panel.addEventListener('keydown', panelKeydown);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (focusEmoji !== null) root.querySelector<HTMLElement>(`[data-kit-reaction="${attrEsc(focusEmoji)}"]`)?.focus();
|
|
162
|
-
else if (focusAdd) root.querySelector<HTMLElement>('[data-kit-add]')?.focus();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
109
|
return {
|
|
166
|
-
|
|
167
|
-
root =
|
|
168
|
-
?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
|
|
169
|
-
?? ctx.host;
|
|
110
|
+
attach(rootEl) {
|
|
111
|
+
root = rootEl;
|
|
170
112
|
const r = root;
|
|
171
113
|
const onClick = (event: Event): void => {
|
|
172
114
|
const t = event.target as HTMLElement | null;
|
|
@@ -174,7 +116,7 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
174
116
|
if (pill) { toggle(pill.getAttribute('data-kit-reaction') ?? ''); return; }
|
|
175
117
|
if (t?.closest('[data-kit-add]')) {
|
|
176
118
|
panelOpen = !panelOpen;
|
|
177
|
-
|
|
119
|
+
api.refresh();
|
|
178
120
|
if (panelOpen) queryWithDropdowns(r, '[data-kit-choice]')?.focus();
|
|
179
121
|
return;
|
|
180
122
|
}
|
|
@@ -182,7 +124,7 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
182
124
|
if (choice) {
|
|
183
125
|
const emoji = choice.getAttribute('data-kit-choice') ?? '';
|
|
184
126
|
panelOpen = false;
|
|
185
|
-
if (reactionsOf(P().data).some((x) => x.emoji === emoji)) toggle(emoji); else {
|
|
127
|
+
if (reactionsOf(P().data).some((x) => x.emoji === emoji)) toggle(emoji); else { api.refresh(); api.emit('add', { emoji }); }
|
|
186
128
|
r.querySelector<HTMLElement>('[data-kit-add]')?.focus();
|
|
187
129
|
}
|
|
188
130
|
};
|
|
@@ -211,26 +153,73 @@ export function createEmojiReactionBar(): SomaComponentDefinition {
|
|
|
211
153
|
r.addEventListener('click', onClick);
|
|
212
154
|
r.addEventListener('keydown', onKeydown as EventListener);
|
|
213
155
|
document.addEventListener('pointerdown', onDocDown);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
156
|
+
return () => {
|
|
157
|
+
r.removeEventListener('click', onClick);
|
|
158
|
+
r.removeEventListener('keydown', onKeydown as EventListener);
|
|
159
|
+
document.removeEventListener('pointerdown', onDocDown);
|
|
160
|
+
flipped.clear();
|
|
161
|
+
if (root) releaseDropdownsIn(root);
|
|
162
|
+
panelClick = null;
|
|
163
|
+
panelKeydown = null;
|
|
164
|
+
root = null;
|
|
165
|
+
};
|
|
223
166
|
},
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
flipped.clear();
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
167
|
+
render(rootEl, p) {
|
|
168
|
+
root = rootEl;
|
|
169
|
+
const dataSig = JSON.stringify(reactionsOf(p.data));
|
|
170
|
+
if (dataSig !== sig) { sig = dataSig; flipped.clear(); }
|
|
171
|
+
root.className = joinClass(ROOT_CLASS, p.class);
|
|
172
|
+
// 整条重建会丢焦点(键盘点药丸 / 「+」后):记下焦点所在,重绘后落回同一个
|
|
173
|
+
const focused = root.contains(document.activeElement) ? document.activeElement as HTMLElement : null;
|
|
174
|
+
const focusEmoji = focused?.closest('[data-kit-reaction]')?.getAttribute('data-kit-reaction') ?? null;
|
|
175
|
+
const focusAdd = focused?.closest('[data-kit-add]') != null;
|
|
176
|
+
releaseDropdownsIn(root);
|
|
177
|
+
root.textContent = '';
|
|
178
|
+
const disabled = bool(p.disabled);
|
|
179
|
+
for (const r of view()) {
|
|
180
|
+
const b = mk('button', r.mine ? PILL_MINE : PILL_CLASS);
|
|
181
|
+
b.type = 'button';
|
|
182
|
+
setKitFace(b, 'raised');
|
|
183
|
+
b.setAttribute('data-kit-reaction', r.emoji);
|
|
184
|
+
b.setAttribute('aria-pressed', r.mine ? 'true' : 'false');
|
|
185
|
+
b.setAttribute('aria-label', `${r.label !== '' ? r.label : r.emoji} ${r.count}`);
|
|
186
|
+
if (disabled) { b.disabled = true; b.setAttribute('aria-disabled', 'true'); }
|
|
187
|
+
b.appendChild(mk('span', '', r.emoji));
|
|
188
|
+
b.appendChild(mk('span', '', String(r.count)));
|
|
189
|
+
root.appendChild(b);
|
|
190
|
+
}
|
|
191
|
+
if (bool(p.addable) && !disabled && view().length < REACTION_MAX_KINDS) {
|
|
192
|
+
const add = mk('button', ADD_CLASS, '+');
|
|
193
|
+
add.type = 'button';
|
|
194
|
+
add.setAttribute('data-kit-add', '');
|
|
195
|
+
add.setAttribute('aria-label', str(p.add_text, kitText('soma.kit.add_reaction', undefined, root)));
|
|
196
|
+
add.setAttribute('aria-haspopup', 'true');
|
|
197
|
+
add.setAttribute('aria-expanded', panelOpen ? 'true' : 'false');
|
|
198
|
+
root.appendChild(add);
|
|
199
|
+
if (panelOpen) {
|
|
200
|
+
const panel = mk('div', PANEL_CLASS);
|
|
201
|
+
panel.setAttribute('role', 'group');
|
|
202
|
+
panel.setAttribute('aria-label', str(p.add_text, kitText('soma.kit.add_reaction', undefined, root)));
|
|
203
|
+
panel.setAttribute('data-kit-panel', '');
|
|
204
|
+
palette().forEach((e, i) => {
|
|
205
|
+
const c = mk('button', CHOICE_CLASS, e);
|
|
206
|
+
c.type = 'button';
|
|
207
|
+
c.setAttribute('data-kit-choice', e);
|
|
208
|
+
c.tabIndex = i === 0 ? 0 : -1;
|
|
209
|
+
panel.appendChild(c);
|
|
210
|
+
});
|
|
211
|
+
root.appendChild(panel);
|
|
212
|
+
syncDropdown(panel, true, PANEL_BASE_CLASS, root);
|
|
213
|
+
if (!root.contains(panel)) {
|
|
214
|
+
if (panelClick) panel.addEventListener('click', panelClick);
|
|
215
|
+
if (panelKeydown) panel.addEventListener('keydown', panelKeydown);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (focusEmoji !== null) root.querySelector<HTMLElement>(`[data-kit-reaction="${attrEsc(focusEmoji)}"]`)?.focus();
|
|
220
|
+
else if (focusAdd) root.querySelector<HTMLElement>('[data-kit-add]')?.focus();
|
|
232
221
|
},
|
|
233
222
|
};
|
|
234
|
-
},
|
|
223
|
+
}),
|
|
235
224
|
};
|
|
236
225
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// 读失败回滚(rollback-on-failure):分页器 / 可排序表头写 view 切片(页码、排序)后由 core 重取;
|
|
2
|
+
// 重取失败时 core 保留旧行、只把读状态挂成 error,切片里却已是新值,页码与数据不一致。
|
|
3
|
+
// 这里是两个写切片的组件共用的小状态机:记下最近一次读成功时的切片值,重取失败就写回去。
|
|
4
|
+
// 回滚只写切片、不抛事件(不会触发二次重取);失败提示由集合三态组件显示,重试重取的是回滚后的当前值。
|
|
5
|
+
// 读状态取不到(空串)时状态机不工作,行为与没有它一致。
|
|
6
|
+
|
|
7
|
+
/** 读失败态:回滚 */
|
|
8
|
+
const FAILED_STATES: readonly string[] = ['error', 'forbidden'];
|
|
9
|
+
/** 读成功态:记下新的「最近一次成功值」 */
|
|
10
|
+
const SETTLED_STATES: readonly string[] = ['ready', 'partial', 'idle'];
|
|
11
|
+
|
|
12
|
+
type Awaiting = 'none' | 'sent' | 'loading';
|
|
13
|
+
|
|
14
|
+
export interface ReadRollbackIo<T> {
|
|
15
|
+
/** 当前读状态(prop 读到的字符串;取不到为 '') */
|
|
16
|
+
readState: () => string;
|
|
17
|
+
/** 当前切片值(commit 前、读成功时各取一次) */
|
|
18
|
+
snapshot: () => T;
|
|
19
|
+
/** 把切片写回给定值(只写切片,不抛事件) */
|
|
20
|
+
restore: (value: T) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ReadRollback {
|
|
24
|
+
/** 组件写切片之前调用:记下提交时的读状态、进入「已发出」,lastGood 为空时先取当前切片值 */
|
|
25
|
+
beforeCommit(): void;
|
|
26
|
+
/** props 更新(读状态可能变了)时调用 */
|
|
27
|
+
onProps(): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createReadRollback<T>(io: ReadRollbackIo<T>): ReadRollback {
|
|
31
|
+
// 包一层,让 T 本身可以是 null / undefined
|
|
32
|
+
let lastGood: { v: T } | null = null;
|
|
33
|
+
let awaiting: Awaiting = 'none';
|
|
34
|
+
let stateAtCommit = '';
|
|
35
|
+
return {
|
|
36
|
+
beforeCommit(): void {
|
|
37
|
+
const rs = io.readState();
|
|
38
|
+
if (rs === '') return;
|
|
39
|
+
// 此刻切片还是提交前的值:从没记过,或上一轮已发出却一直没观察到 loading、现在是读成功态(上一轮已落定成功),都以它为最近成功值
|
|
40
|
+
if (lastGood === null || (awaiting !== 'none' && SETTLED_STATES.includes(rs))) lastGood = { v: io.snapshot() };
|
|
41
|
+
stateAtCommit = rs;
|
|
42
|
+
awaiting = 'sent';
|
|
43
|
+
},
|
|
44
|
+
onProps(): void {
|
|
45
|
+
const rs = io.readState();
|
|
46
|
+
if (rs === '') return;
|
|
47
|
+
const settled = SETTLED_STATES.includes(rs);
|
|
48
|
+
if (awaiting === 'none') {
|
|
49
|
+
// 初值:首次看到读成功态时的切片值
|
|
50
|
+
if (lastGood === null && settled) lastGood = { v: io.snapshot() };
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (awaiting === 'sent') {
|
|
54
|
+
if (rs === 'loading') {
|
|
55
|
+
awaiting = 'loading';
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// 已发出、还没进入 loading:此时的读成功态是提交前的旧状态(写切片同步触发的重绘、别处的刷新都会带来它),不能当成本轮成功;
|
|
59
|
+
// 只有「提交时不是失败、现在失败了」才算本轮失败(props 合批时可能没观察到 loading)
|
|
60
|
+
if (!(FAILED_STATES.includes(rs) && !FAILED_STATES.includes(stateAtCommit))) return;
|
|
61
|
+
}
|
|
62
|
+
if (settled) {
|
|
63
|
+
lastGood = { v: io.snapshot() };
|
|
64
|
+
awaiting = 'none';
|
|
65
|
+
} else if (FAILED_STATES.includes(rs)) {
|
|
66
|
+
const back = lastGood;
|
|
67
|
+
// 先复位再写回:写切片可能同步触发重绘,重绘里不该再走一遍回滚
|
|
68
|
+
awaiting = 'none';
|
|
69
|
+
if (back !== null) io.restore(back.v);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
package/src/data/record-card.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { safeImgSrc } from './d9-util';
|
|
|
18
18
|
import { kitText } from '../i18n/kit-text';
|
|
19
19
|
import type { SomaDataPort } from 'soma-core';
|
|
20
20
|
import { watchKitOutcome, type KitOutcome } from './outcome-watch';
|
|
21
|
-
import { pickPath } from '../object-renderer/
|
|
21
|
+
import { pickPath } from '../object-renderer/path-pick';
|
|
22
22
|
import type { ShapeTone } from './shape-util';
|
|
23
23
|
|
|
24
24
|
export const KIT_RECORD_CARD_DEFAULT_MAP = Object.freeze({
|
|
@@ -194,7 +194,7 @@ export function createRecordCard(): SomaComponentDefinition {
|
|
|
194
194
|
},
|
|
195
195
|
},
|
|
196
196
|
templateHtml: `<article data-soma-id="root" class="${recordRootClass('outlined', false, false)}"></article>`,
|
|
197
|
-
controllerFactory: createKitController({
|
|
197
|
+
controllerFactory: createKitController(() => ({
|
|
198
198
|
attach(root, api) {
|
|
199
199
|
const pick = (): void => {
|
|
200
200
|
const p = api.props();
|
|
@@ -266,7 +266,7 @@ export function createRecordCard(): SomaComponentDefinition {
|
|
|
266
266
|
ensureOutcome(root, p, api.services);
|
|
267
267
|
renderCard(root, p);
|
|
268
268
|
},
|
|
269
|
-
}),
|
|
269
|
+
})),
|
|
270
270
|
services: ['data'],
|
|
271
271
|
};
|
|
272
272
|
|
|
@@ -11,22 +11,23 @@
|
|
|
11
11
|
// - 键盘:列表是 listbox(aria-activedescendant),↑↓ Home End 走活动项(键盘接线取 soma-core/keyboard);Esc 取消并回焦到触发钮。
|
|
12
12
|
// - 草稿(弹窗里的临时勾选)只在组件内,点「确定」才提交;取消 / Esc 丢弃。
|
|
13
13
|
//
|
|
14
|
-
//
|
|
14
|
+
// 事件:
|
|
15
15
|
// pick { value, values, item, items } 点确定。value:单选为 id 字符串,多选为 id 数组;values 恒为 id 数组;
|
|
16
16
|
// item 为第一条被选记录的「源数据原对象」,items 为全部被选记录的原对象数组。
|
|
17
|
-
// ref.fill 从 item(单选)按 `from → to` 取字段回填;多选回填取 items / values。
|
|
18
17
|
// clear {} 点触发钮旁的清除。
|
|
19
|
-
// search { keyword } remote_search
|
|
20
|
-
//
|
|
18
|
+
// search { keyword } remote_search 下的搜索意图(失败后的重试钮重发上一次 search,关键词不变)。
|
|
19
|
+
// 远程状态:页面把读状态绑到 `loading`(进行中)与 `error_text`(失败消息,空串无错误);组件只画,不取数。
|
|
20
|
+
// 组件不改数据。
|
|
21
21
|
|
|
22
|
-
import type {
|
|
22
|
+
import type { SomaComponentDefinition } from 'soma-core';
|
|
23
23
|
import { createKeyboardWiring, type CollectionItem } from 'soma-core/keyboard';
|
|
24
24
|
import { SOMA_SIZE_UNITS } from 'soma-foundation/theme';
|
|
25
25
|
import { KIT_DATA_LIMITS } from 'soma-foundation/kit-limits';
|
|
26
26
|
import { KIT_GRAMMAR_RUNTIME as grammarJson } from '../generated/kit-grammar-runtime';
|
|
27
|
-
import { bool, joinClass, num, str } from '../base/shared';
|
|
27
|
+
import { bool, createKitController, joinClass, num, str } from '../base/shared';
|
|
28
28
|
import { kitIcon } from '../base/icons';
|
|
29
29
|
import { kitLocaleAt, kitText } from '../i18n/kit-text';
|
|
30
|
+
import { setKitFace } from '../recipes';
|
|
30
31
|
import { actionButton, BUTTON_CLASS_TOKENS, classTokens, keyMap, mk, rowsOf, textOf } from './shape-util';
|
|
31
32
|
import { KIT_MODAL_CLASS_CANDIDATES, mountKitModal, type KitModalHandle, type KitModalSize } from './modal-dialog';
|
|
32
33
|
|
|
@@ -152,6 +153,8 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
152
153
|
selected_text: { type: 'string', default: '', desc: '弹窗里多选的已选计数文案' },
|
|
153
154
|
limit_text: { type: 'string', default: '', desc: '多选到上限的提示文案' },
|
|
154
155
|
empty_text: { type: 'string', default: '', desc: '列表为空的文案' },
|
|
156
|
+
loading: { type: 'boolean', default: false, desc: '远程搜索进行中:无行时列表区显示加载提示,有旧行时保留旧行并标 aria-busy' },
|
|
157
|
+
error_text: { type: 'string', default: '', desc: '远程搜索失败的消息;空串表示无错误,非空时列表区显示消息与重试钮(重发上一次 search,关键词不变)' },
|
|
155
158
|
clearable: { type: 'boolean', default: true, desc: '已选时显示清除钮' },
|
|
156
159
|
disabled: { type: 'boolean', default: false, desc: '禁用触发钮' },
|
|
157
160
|
size: { type: 'enum', values: LIMITS.sizes, default: 'md', desc: '弹窗宽度档' },
|
|
@@ -161,7 +164,7 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
161
164
|
emits: {
|
|
162
165
|
pick: {
|
|
163
166
|
payload: { value: { type: 'string' }, values: { type: 'array' }, item: { type: 'object' }, items: { type: 'array' } },
|
|
164
|
-
desc: '点确定:value 单选为 id、多选为 id 数组;values 恒为 id 数组;item 第一条被选记录的源对象;items
|
|
167
|
+
desc: '点确定:value 单选为 id、多选为 id 数组;values 恒为 id 数组;item 第一条被选记录的源对象;items 全部被选记录的源对象',
|
|
165
168
|
},
|
|
166
169
|
clear: { payload: {}, desc: '点清除钮' },
|
|
167
170
|
search: { payload: { keyword: { type: 'string' } }, desc: 'remote_search 下的搜索意图' },
|
|
@@ -169,8 +172,8 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
169
172
|
keyboard: { layout: 'list', wrap: false, typeahead: false, focus_model: 'activedescendant', space: 'toggle_select' },
|
|
170
173
|
},
|
|
171
174
|
templateHtml: `<div data-soma-id="root" class="${ROOT_CLASS}"></div>`,
|
|
172
|
-
controllerFactory: (
|
|
173
|
-
const P = (): Record<string, unknown> =>
|
|
175
|
+
controllerFactory: createKitController((api) => {
|
|
176
|
+
const P = (): Record<string, unknown> => api.props();
|
|
174
177
|
const uid = `kit-record-picker-${++instanceCount}`;
|
|
175
178
|
let root: HTMLElement | null = null;
|
|
176
179
|
let trigger: HTMLButtonElement | null = null;
|
|
@@ -186,9 +189,11 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
186
189
|
const known = new Map<string, KitPickerRow>();
|
|
187
190
|
let committed: string[] = [];
|
|
188
191
|
let draft: string[] = [];
|
|
192
|
+
let selectionEdited = false;
|
|
189
193
|
let cursor: string | null = null;
|
|
190
194
|
let lastGiven = '\u0000';
|
|
191
|
-
|
|
195
|
+
/** 键盘点「重试」后等待结果:再次失败出现新重试钮时把焦点还给它(开 / 关弹窗清零) */
|
|
196
|
+
let retryFocusPending = false;
|
|
192
197
|
|
|
193
198
|
const multiple = (): boolean => bool(P().multiple);
|
|
194
199
|
const cap = (): number => {
|
|
@@ -206,7 +211,7 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
206
211
|
const given = JSON.stringify([p.value ?? null, p.values ?? null, multiple()]);
|
|
207
212
|
if (given !== lastGiven) {
|
|
208
213
|
lastGiven = given;
|
|
209
|
-
committed = pickerValueOf(multiple() ? p.values : p.value);
|
|
214
|
+
committed = pickerValueOf(multiple() ? (p.values !== undefined && p.values !== null ? p.values : p.value) : p.value);
|
|
210
215
|
if (!multiple()) committed = committed.slice(0, 1);
|
|
211
216
|
}
|
|
212
217
|
};
|
|
@@ -234,6 +239,14 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
234
239
|
};
|
|
235
240
|
|
|
236
241
|
// ── 键盘(listbox,activedescendant) ──
|
|
242
|
+
// 方向键移动光标后,把活动项滚进可见区(测试环境无 scrollIntoView 时不抛)
|
|
243
|
+
const scrollCursorIntoView = (): void => {
|
|
244
|
+
if (!list) return;
|
|
245
|
+
const id = list.getAttribute('aria-activedescendant');
|
|
246
|
+
if (id === null || id === '') return;
|
|
247
|
+
const node = list.querySelector<HTMLElement>(`[id="${id.replace(/"/g, '\\"')}"]`);
|
|
248
|
+
node?.scrollIntoView?.({ block: 'nearest' });
|
|
249
|
+
};
|
|
237
250
|
const keysOf = (): CollectionItem[] => view().map((r) => ({ key: r.id, text: r.title, ...(r.disabled ? { disabled: true } : {}) }));
|
|
238
251
|
const pageStep = SOMA_SIZE_UNITS.collection.keyboard.pageStep;
|
|
239
252
|
const wiring = createKeyboardWiring({
|
|
@@ -244,7 +257,7 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
244
257
|
typeaheadDebounceMs: 0,
|
|
245
258
|
paging: { listItems: pageStep.listItems, gridRows: pageStep.gridRows },
|
|
246
259
|
getCursor: () => cursor,
|
|
247
|
-
setCursor: (key) => { cursor = key; paintList(); },
|
|
260
|
+
setCursor: (key) => { cursor = key; paintList(); scrollCursorIntoView(); },
|
|
248
261
|
onToggle: (key) => toggle(key),
|
|
249
262
|
onActivate: (key) => {
|
|
250
263
|
if (multiple()) { toggle(key); return; }
|
|
@@ -259,10 +272,13 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
259
272
|
cursor = key;
|
|
260
273
|
if (!multiple()) {
|
|
261
274
|
draft = [key];
|
|
275
|
+
selectionEdited = true;
|
|
262
276
|
} else if (draft.includes(key)) {
|
|
263
277
|
draft = draft.filter((d) => d !== key);
|
|
278
|
+
selectionEdited = true;
|
|
264
279
|
} else if (draft.length < cap()) {
|
|
265
280
|
draft = [...draft, key];
|
|
281
|
+
selectionEdited = true;
|
|
266
282
|
}
|
|
267
283
|
paintList();
|
|
268
284
|
};
|
|
@@ -293,18 +309,45 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
293
309
|
const p = P();
|
|
294
310
|
const shown = view();
|
|
295
311
|
if (cursor !== null && !shown.some((r) => r.id === cursor)) cursor = null;
|
|
312
|
+
// 键盘点「重试」后列表整体重画、重试钮被销毁,焦点会掉到 body(Tab 陷阱挂在遮罩上,从 body 发出的 Tab 拦不住):重画前记下
|
|
313
|
+
const retryHadFocus = list.contains(list.ownerDocument.activeElement) && list.ownerDocument.activeElement?.closest('[data-kit-action="retry"]') != null;
|
|
296
314
|
list.textContent = '';
|
|
297
315
|
list.setAttribute('aria-multiselectable', multiple() ? 'true' : 'false');
|
|
298
316
|
list.setAttribute('aria-label', str(p.title, kitText('soma.kit.select_record', undefined, root)));
|
|
317
|
+
const loading = bool(p.loading);
|
|
318
|
+
const failure = loading ? '' : str(p.error_text);
|
|
319
|
+
list.setAttribute('aria-busy', loading ? 'true' : 'false');
|
|
320
|
+
if (failure !== '') {
|
|
321
|
+
const alert = mk('div', EMPTY_CLASS, failure);
|
|
322
|
+
alert.setAttribute('role', 'alert');
|
|
323
|
+
alert.appendChild(actionButton({ key: 'retry', label: kitText('soma.kit.ct_retry', undefined, root), tone: 'neutral', disabled: false, reason: '' }));
|
|
324
|
+
list.appendChild(alert);
|
|
325
|
+
}
|
|
299
326
|
if (shown.length === 0) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
327
|
+
if (loading || failure === '') {
|
|
328
|
+
const empty = mk('div', EMPTY_CLASS, loading ? kitText('soma.kit.loading', undefined, root) : str(p.empty_text, kitText('soma.kit.empty_match', undefined, root)));
|
|
329
|
+
empty.setAttribute('role', 'status');
|
|
330
|
+
list.appendChild(empty);
|
|
331
|
+
}
|
|
303
332
|
} else {
|
|
304
333
|
for (const r of shown) list.appendChild(buildOption(r));
|
|
305
334
|
}
|
|
306
335
|
if (cursor !== null) list.setAttribute('aria-activedescendant', optionId(cursor));
|
|
307
336
|
else list.removeAttribute('aria-activedescendant');
|
|
337
|
+
// 重试后的焦点归还:只在焦点落在 body / null / 列表框本身时发生,不抢走用户当前的焦点
|
|
338
|
+
const doc = list.ownerDocument;
|
|
339
|
+
const idle = doc.activeElement === null || doc.activeElement === doc.body || doc.activeElement === list;
|
|
340
|
+
const retryBtn = list.querySelector<HTMLElement>('[data-kit-action="retry"]');
|
|
341
|
+
if (retryBtn !== null && (retryHadFocus || (retryFocusPending && idle))) {
|
|
342
|
+
retryBtn.focus({ preventScroll: true });
|
|
343
|
+
retryFocusPending = false;
|
|
344
|
+
} else if (retryHadFocus && retryBtn === null) {
|
|
345
|
+
// 重试进行中:重试钮已销毁,焦点先留在弹窗内的列表框,等再次失败时还给新按钮
|
|
346
|
+
list.focus({ preventScroll: true });
|
|
347
|
+
retryFocusPending = loading;
|
|
348
|
+
} else if (!loading) {
|
|
349
|
+
retryFocusPending = false;
|
|
350
|
+
}
|
|
308
351
|
if (countEl) {
|
|
309
352
|
const atCap = multiple() && draft.length >= cap();
|
|
310
353
|
countEl.hidden = !multiple();
|
|
@@ -315,19 +358,19 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
315
358
|
}
|
|
316
359
|
}
|
|
317
360
|
|
|
318
|
-
const closeModal = (): void => { modal?.close(); };
|
|
361
|
+
const closeModal = (): void => { retryFocusPending = false; modal?.close(); };
|
|
319
362
|
|
|
320
363
|
const confirm = (): void => {
|
|
321
|
-
const picked = draft.map((id) => known.get(id)).filter((r): r is KitPickerRow => r !== undefined);
|
|
322
|
-
if (picked.length === 0) { closeModal(); return; }
|
|
323
|
-
committed = picked.map((r) => r.id);
|
|
324
364
|
closeModal();
|
|
365
|
+
if (!selectionEdited) return;
|
|
366
|
+
const ids = [...draft];
|
|
367
|
+
const picked = ids.map((id) => known.get(id)).filter((r): r is KitPickerRow => r !== undefined);
|
|
368
|
+
committed = ids;
|
|
325
369
|
paintTrigger();
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
value: multiple() ? ids : ids[0]!,
|
|
370
|
+
api.emit('pick', {
|
|
371
|
+
value: multiple() ? ids : (ids[0] ?? ''),
|
|
329
372
|
values: ids,
|
|
330
|
-
item:
|
|
373
|
+
item: known.get(ids[0] ?? '')?.raw ?? null,
|
|
331
374
|
items: picked.map((r) => r.raw),
|
|
332
375
|
});
|
|
333
376
|
};
|
|
@@ -352,6 +395,7 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
352
395
|
});
|
|
353
396
|
const row = mk('div', SEARCH_ROW);
|
|
354
397
|
const input = mk('input', SEARCH_CLASS);
|
|
398
|
+
setKitFace(input, 'field');
|
|
355
399
|
input.type = 'search';
|
|
356
400
|
input.autocomplete = 'off';
|
|
357
401
|
input.placeholder = str(p.search_placeholder, kitText('soma.kit.search', undefined, root));
|
|
@@ -373,7 +417,8 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
373
417
|
actionButton({ key: 'confirm', label: str(p.confirm_text, kitText('soma.kit.ok', undefined, root)), tone: 'primary', disabled: false, reason: '' }),
|
|
374
418
|
);
|
|
375
419
|
|
|
376
|
-
|
|
420
|
+
let lastKeyword = '';
|
|
421
|
+
const emitSearch = (): void => { lastKeyword = input.value.trim(); api.emit('search', { keyword: lastKeyword }); };
|
|
377
422
|
const onInput = (): void => { if (!bool(P().remote_search)) paintList(); };
|
|
378
423
|
const onKey = (event: KeyboardEvent): void => {
|
|
379
424
|
if (event.target === input) {
|
|
@@ -395,6 +440,7 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
395
440
|
if (act === 'confirm') { confirm(); return; }
|
|
396
441
|
if (act === 'cancel') { closeModal(); return; }
|
|
397
442
|
if (act === 'search') { emitSearch(); return; }
|
|
443
|
+
if (act === 'retry') { api.emit('search', { keyword: lastKeyword }); return; }
|
|
398
444
|
const key = t?.closest<HTMLElement>('[data-kit-key]')?.getAttribute('data-kit-key');
|
|
399
445
|
if (key) toggle(key);
|
|
400
446
|
};
|
|
@@ -421,6 +467,8 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
421
467
|
if (bool(P().disabled)) return;
|
|
422
468
|
const m = ensureModal();
|
|
423
469
|
draft = [...committed];
|
|
470
|
+
selectionEdited = false;
|
|
471
|
+
retryFocusPending = false;
|
|
424
472
|
cursor = committed[0] ?? null;
|
|
425
473
|
if (search && !bool(P().remote_search)) search.value = '';
|
|
426
474
|
paintList();
|
|
@@ -429,12 +477,12 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
429
477
|
};
|
|
430
478
|
|
|
431
479
|
return {
|
|
432
|
-
|
|
433
|
-
root =
|
|
434
|
-
?? ctx.host.querySelector<HTMLElement>('[data-soma-id="root"]')
|
|
435
|
-
?? ctx.host;
|
|
480
|
+
attach(rootEl) {
|
|
481
|
+
root = rootEl;
|
|
436
482
|
trigger = mk('button', TRIGGER_CLASS);
|
|
437
483
|
trigger.type = 'button';
|
|
484
|
+
// 带边框的选择触发器,读起来是输入框(同 Select 触发器),标 field
|
|
485
|
+
setKitFace(trigger, 'field');
|
|
438
486
|
trigger.setAttribute('aria-haspopup', 'dialog');
|
|
439
487
|
triggerText = mk('span', TRIGGER_TEXT);
|
|
440
488
|
const caret = mk('span', TRIGGER_CARET, '');
|
|
@@ -453,37 +501,32 @@ export function createRecordPicker(): SomaComponentDefinition {
|
|
|
453
501
|
committed = [];
|
|
454
502
|
draft = [];
|
|
455
503
|
paintTrigger();
|
|
456
|
-
|
|
504
|
+
api.emit('clear', {});
|
|
457
505
|
t.focus();
|
|
458
506
|
};
|
|
459
507
|
t.addEventListener('click', onOpen);
|
|
460
508
|
clearBtn.addEventListener('click', onClear);
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
509
|
+
return () => {
|
|
510
|
+
t.removeEventListener('click', onOpen);
|
|
511
|
+
clearBtn.removeEventListener('click', onClear);
|
|
512
|
+
modal?.destroy();
|
|
513
|
+
modal = null;
|
|
514
|
+
search = null;
|
|
515
|
+
list = null;
|
|
516
|
+
countEl = null;
|
|
517
|
+
root = null;
|
|
518
|
+
trigger = null;
|
|
519
|
+
triggerText = null;
|
|
520
|
+
clearBox = null;
|
|
521
|
+
};
|
|
467
522
|
},
|
|
468
|
-
|
|
523
|
+
render(rootEl) {
|
|
524
|
+
root = rootEl;
|
|
469
525
|
sync();
|
|
470
526
|
paintTrigger();
|
|
471
527
|
if (modal?.isOpen()) paintList();
|
|
472
528
|
},
|
|
473
|
-
onUnmount(): void {
|
|
474
|
-
for (const off of removers) off();
|
|
475
|
-
removers = [];
|
|
476
|
-
modal?.destroy();
|
|
477
|
-
modal = null;
|
|
478
|
-
search = null;
|
|
479
|
-
list = null;
|
|
480
|
-
countEl = null;
|
|
481
|
-
root = null;
|
|
482
|
-
trigger = null;
|
|
483
|
-
triggerText = null;
|
|
484
|
-
clearBox = null;
|
|
485
|
-
},
|
|
486
529
|
};
|
|
487
|
-
},
|
|
530
|
+
}),
|
|
488
531
|
};
|
|
489
532
|
}
|