@dsh-workbench/shared 1.5.2-alpha.4 → 1.5.2-alpha.5
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/dist/components/Activity.css +69 -0
- package/dist/components/Activity.d.ts +56 -0
- package/dist/components/Activity.js +47 -0
- package/dist/components/ApprovalDetail.css +3 -0
- package/dist/components/ApprovalDetail.d.ts +42 -0
- package/dist/components/ApprovalDetail.js +53 -0
- package/dist/components/ApprovalPlan.css +39 -0
- package/dist/components/ApprovalPlan.d.ts +27 -0
- package/dist/components/ApprovalPlan.js +19 -0
- package/dist/components/Card.css +19 -0
- package/dist/components/Card.d.ts +26 -0
- package/dist/components/Card.js +18 -0
- package/dist/components/CardAnchor.d.ts +21 -0
- package/dist/components/CardAnchor.js +19 -0
- package/dist/components/CardAnchor.module.css +3 -0
- package/dist/components/CardBoundary.d.ts +42 -0
- package/dist/components/CardBoundary.js +58 -0
- package/dist/components/CardBoundary.module.css +5 -0
- package/dist/components/CardHead.css +87 -0
- package/dist/components/CardHead.d.ts +30 -0
- package/dist/components/CardHead.js +27 -0
- package/dist/components/ChoiceGroup.css +182 -0
- package/dist/components/ChoiceGroup.d.ts +54 -0
- package/dist/components/ChoiceGroup.js +63 -0
- package/dist/components/ConfirmBar.css +26 -0
- package/dist/components/ConfirmBar.d.ts +36 -0
- package/dist/components/ConfirmBar.js +26 -0
- package/dist/components/EmptyIllustration.d.ts +12 -0
- package/dist/components/EmptyIllustration.js +32 -0
- package/dist/components/Field.css +20 -0
- package/dist/components/Field.d.ts +18 -0
- package/dist/components/Field.js +15 -0
- package/dist/components/Form.css +6 -0
- package/dist/components/Form.d.ts +22 -0
- package/dist/components/Form.js +60 -0
- package/dist/components/FormActions.css +13 -0
- package/dist/components/FormActions.d.ts +29 -0
- package/dist/components/FormActions.js +43 -0
- package/dist/components/FormNodes.d.ts +107 -0
- package/dist/components/FormNodes.js +165 -0
- package/dist/components/FormRows.css +107 -0
- package/dist/components/FormRows.d.ts +36 -0
- package/dist/components/FormRows.js +26 -0
- package/dist/components/FormTypes.d.ts +84 -0
- package/dist/components/FormTypes.js +1 -0
- package/dist/components/Link.css +22 -0
- package/dist/components/Link.d.ts +22 -0
- package/dist/components/Link.js +17 -0
- package/dist/components/LongTaskRow.css +171 -0
- package/dist/components/LongTaskRow.d.ts +94 -0
- package/dist/components/LongTaskRow.js +103 -0
- package/dist/components/Note.css +13 -0
- package/dist/components/Note.d.ts +20 -0
- package/dist/components/Note.js +14 -0
- package/dist/components/ResourceStates.css +114 -0
- package/dist/components/ResourceStates.d.ts +44 -0
- package/dist/components/ResourceStates.js +41 -0
- package/dist/components/Rows.css +42 -0
- package/dist/components/Rows.d.ts +28 -0
- package/dist/components/Rows.js +21 -0
- package/dist/components/SaveBar.d.ts +24 -0
- package/dist/components/SaveBar.js +25 -0
- package/dist/components/SelectField.css +182 -0
- package/dist/components/SelectField.d.ts +89 -0
- package/dist/components/SelectField.js +260 -0
- package/dist/components/SelectFieldNodes.d.ts +49 -0
- package/dist/components/SelectFieldNodes.js +43 -0
- package/dist/components/SettingsSection.css +25 -0
- package/dist/components/SettingsSection.d.ts +20 -0
- package/dist/components/SettingsSection.js +17 -0
- package/dist/components/SetupShell.d.ts +93 -0
- package/dist/components/SetupShell.js +64 -0
- package/dist/components/SetupShell.module.css +81 -0
- package/dist/components/Spinner.css +5 -0
- package/dist/components/Spinner.d.ts +15 -0
- package/dist/components/Spinner.js +13 -0
- package/dist/components/Stack.css +6 -0
- package/dist/components/Stack.d.ts +14 -0
- package/dist/components/Stack.js +10 -0
- package/dist/components/StateBlock.css +38 -0
- package/dist/components/StateBlock.d.ts +24 -0
- package/dist/components/StateBlock.js +22 -0
- package/dist/components/TextField.css +32 -0
- package/dist/components/TextField.d.ts +14 -0
- package/dist/components/TextField.js +10 -0
- package/dist/components/board-module.d.ts +307 -0
- package/dist/components/board-module.js +1 -0
- package/dist/components/card-view-validate.d.ts +5 -0
- package/dist/components/card-view-validate.js +256 -0
- package/dist/components/icons.d.ts +63 -0
- package/dist/components/icons.js +107 -0
- package/dist/components/layout/icon-command.d.ts +8 -0
- package/dist/components/layout/icon-command.js +21 -0
- package/dist/contract/capture.d.ts +16 -0
- package/dist/contract/capture.js +1 -0
- package/dist/contract/diagnostics.d.ts +34 -0
- package/dist/contract/diagnostics.js +124 -0
- package/dist/contract/protocol/unit-manager.d.ts +50 -0
- package/dist/contract/protocol/unit-manager.js +2 -0
- package/dist/host/adapter-contract.d.ts +3 -0
- package/dist/host/adapter-contract.js +95 -0
- package/dist/host/adapter-set.d.ts +27 -0
- package/dist/host/adapter-set.js +258 -0
- package/dist/host/adapter-types.d.ts +87 -0
- package/dist/host/adapter-types.js +23 -0
- package/dist/host/adapters/platform.d.ts +14 -0
- package/dist/host/adapters/platform.js +40 -0
- package/dist/host/adapters.d.ts +28 -0
- package/dist/host/adapters.js +9 -0
- package/dist/host/auth-loss.d.ts +33 -0
- package/dist/host/auth-loss.js +107 -0
- package/dist/host/board-fact.d.ts +8 -0
- package/dist/host/board-fact.js +16 -0
- package/dist/host/boot-record.d.ts +11 -0
- package/dist/host/boot-record.js +31 -0
- package/dist/host/browser.d.ts +3 -0
- package/dist/host/browser.js +3 -0
- package/dist/host/bundle-manager.d.ts +4 -0
- package/dist/host/bundle-manager.js +338 -0
- package/dist/host/changelog.d.ts +28 -0
- package/dist/host/changelog.js +201 -0
- package/dist/host/cli-error.d.ts +8 -0
- package/dist/host/cli-error.js +70 -0
- package/dist/host/cli.d.ts +4 -0
- package/dist/host/cli.js +9 -0
- package/dist/host/config-sync.d.ts +40 -0
- package/dist/host/config-sync.js +267 -0
- package/dist/host/context-ref.d.ts +13 -0
- package/dist/host/context-ref.js +41 -0
- package/dist/host/data-error.d.ts +15 -0
- package/dist/host/data-error.js +23 -0
- package/dist/host/data-plan-check.d.ts +10 -0
- package/dist/host/data-plan-check.js +315 -0
- package/dist/host/data-plan.d.ts +15 -0
- package/dist/host/data-plan.js +283 -0
- package/dist/host/data-root.d.ts +5 -0
- package/dist/host/data-root.js +23 -0
- package/dist/host/diy-debug.d.ts +80 -0
- package/dist/host/diy-debug.js +89 -0
- package/dist/host/diy-preset.d.ts +26 -0
- package/dist/host/diy-preset.js +115 -0
- package/dist/host/diy-record.d.ts +135 -0
- package/dist/host/diy-record.js +163 -0
- package/dist/host/dsh-compat.d.ts +27 -0
- package/dist/host/dsh-compat.js +75 -0
- package/dist/host/dsh-plugins.d.ts +5 -0
- package/dist/host/dsh-plugins.js +51 -0
- package/dist/host/env-policy.d.ts +82 -0
- package/dist/host/env-policy.js +181 -0
- package/dist/host/extension.d.ts +7 -0
- package/dist/host/extension.js +40 -0
- package/dist/host/facts.d.ts +31 -0
- package/dist/host/facts.js +58 -0
- package/dist/host/fs-write.d.ts +96 -0
- package/dist/host/fs-write.js +183 -0
- package/dist/host/git.d.ts +5 -0
- package/dist/host/git.js +1 -0
- package/dist/host/host-actions.d.ts +2 -0
- package/dist/host/host-actions.js +5 -0
- package/dist/host/host-kit.d.ts +37 -0
- package/dist/host/host-kit.js +27 -0
- package/dist/host/http.d.ts +47 -0
- package/dist/host/http.js +289 -0
- package/dist/host/install-failure.d.ts +50 -0
- package/dist/host/install-failure.js +184 -0
- package/dist/host/installed-module.d.ts +25 -0
- package/dist/host/installed-module.js +289 -0
- package/dist/host/installed-sources.d.ts +10 -0
- package/dist/host/installed-sources.js +63 -0
- package/dist/host/lease.d.ts +70 -0
- package/dist/host/lease.js +264 -0
- package/dist/host/lib-capabilities.d.ts +22 -0
- package/dist/host/lib-capabilities.js +37 -0
- package/dist/host/lib-install.d.ts +19 -0
- package/dist/host/lib-install.js +40 -0
- package/dist/host/lib-runners.d.ts +18 -0
- package/dist/host/lib-runners.js +46 -0
- package/dist/host/local-declaration.d.ts +7 -0
- package/dist/host/local-declaration.js +33 -0
- package/dist/host/long-task.d.ts +97 -0
- package/dist/host/long-task.js +297 -0
- package/dist/host/market-index-claim.d.ts +19 -0
- package/dist/host/market-index-claim.js +87 -0
- package/dist/host/market-index-doc.d.ts +12 -0
- package/dist/host/market-index-doc.js +1 -0
- package/dist/host/market-index-parse.d.ts +28 -0
- package/dist/host/market-index-parse.js +413 -0
- package/dist/host/market-index.d.ts +13 -0
- package/dist/host/market-index.js +105 -0
- package/dist/host/module-root.d.ts +1 -0
- package/dist/host/module-root.js +5 -0
- package/dist/host/needs.d.ts +4 -0
- package/dist/host/needs.js +2 -0
- package/dist/host/npm-registry.d.ts +10 -0
- package/dist/host/npm-registry.js +16 -0
- package/dist/host/package-content.d.ts +8 -0
- package/dist/host/package-content.js +90 -0
- package/dist/host/package-kind.d.ts +13 -0
- package/dist/host/package-kind.js +51 -0
- package/dist/host/package-route.d.ts +33 -0
- package/dist/host/package-route.js +68 -0
- package/dist/host/panel-state.d.ts +120 -0
- package/dist/host/panel-state.js +177 -0
- package/dist/host/patch-blocks.d.ts +13 -0
- package/dist/host/patch-blocks.js +52 -0
- package/dist/host/patch.d.ts +4 -0
- package/dist/host/patch.js +7 -0
- package/dist/host/paths.d.ts +12 -0
- package/dist/host/paths.js +20 -0
- package/dist/host/payload.d.ts +12 -0
- package/dist/host/payload.js +16 -0
- package/dist/host/plan-results.d.ts +5 -0
- package/dist/host/plan-results.js +71 -0
- package/dist/host/plan-run.d.ts +41 -0
- package/dist/host/plan-run.js +87 -0
- package/dist/host/platform.d.ts +14 -0
- package/dist/host/platform.js +40 -0
- package/dist/host/plugin-ledger.d.ts +32 -0
- package/dist/host/plugin-ledger.js +106 -0
- package/dist/host/plugin.d.ts +3 -0
- package/dist/host/plugin.js +38 -0
- package/dist/host/port-types.d.ts +233 -0
- package/dist/host/port-types.js +1 -0
- package/dist/host/preflight.d.ts +32 -0
- package/dist/host/preflight.js +1 -0
- package/dist/host/process-alive.d.ts +6 -0
- package/dist/host/process-alive.js +16 -0
- package/dist/host/profile-bundles.d.ts +20 -0
- package/dist/host/profile-bundles.js +48 -0
- package/dist/host/profile-create.d.ts +19 -0
- package/dist/host/profile-create.js +124 -0
- package/dist/host/profile-port.d.ts +4 -0
- package/dist/host/profile-port.js +4 -0
- package/dist/host/profile-registries.d.ts +10 -0
- package/dist/host/profile-registries.js +149 -0
- package/dist/host/provision.d.ts +32 -0
- package/dist/host/provision.js +105 -0
- package/dist/host/read-json.d.ts +1 -0
- package/dist/host/read-json.js +11 -0
- package/dist/host/recipe-rules.d.ts +5 -0
- package/dist/host/recipe-rules.js +412 -0
- package/dist/host/recipe.d.ts +14 -0
- package/dist/host/recipe.js +332 -0
- package/dist/host/registry-declaration.d.ts +21 -0
- package/dist/host/registry-declaration.js +42 -0
- package/dist/host/reinstall-record.d.ts +16 -0
- package/dist/host/reinstall-record.js +54 -0
- package/dist/host/release-age.d.ts +24 -0
- package/dist/host/release-age.js +92 -0
- package/dist/host/release-packages.generated.d.ts +1 -0
- package/dist/host/release-packages.generated.js +10 -0
- package/dist/host/release-probe.d.ts +37 -0
- package/dist/host/release-probe.js +156 -0
- package/dist/host/runtime/browser-argv.d.ts +1 -0
- package/dist/host/runtime/browser-argv.js +9 -0
- package/dist/host/runtime/front-app.d.ts +6 -0
- package/dist/host/runtime/front-app.js +70 -0
- package/dist/host/shell-render.d.ts +52 -0
- package/dist/host/shell-render.js +117 -0
- package/dist/host/shell-text.d.ts +30 -0
- package/dist/host/shell-text.js +40 -0
- package/dist/host/shell.d.ts +25 -0
- package/dist/host/shell.js +55 -0
- package/dist/host/site.d.ts +45 -0
- package/dist/host/site.js +182 -0
- package/dist/host/spec.d.ts +8 -0
- package/dist/host/spec.js +24 -0
- package/dist/host/submit-confirm.d.ts +19 -0
- package/dist/host/submit-confirm.js +45 -0
- package/dist/host/supply-index.d.ts +38 -0
- package/dist/host/supply-index.js +209 -0
- package/dist/host/supply-port.d.ts +5 -0
- package/dist/host/supply-port.js +50 -0
- package/dist/host/time.d.ts +22 -0
- package/dist/host/time.js +33 -0
- package/dist/host/tokens.d.ts +26 -0
- package/dist/host/tokens.js +154 -0
- package/dist/host/tool-approval.d.ts +86 -0
- package/dist/host/tool-approval.js +118 -0
- package/dist/host/tool-kit.d.ts +8 -0
- package/dist/host/tool-kit.js +22 -0
- package/dist/host/toolbox-port.d.ts +16 -0
- package/dist/host/toolbox-port.js +1 -0
- package/dist/host/unit-config.d.ts +34 -0
- package/dist/host/unit-config.js +28 -0
- package/dist/host/unit-data.d.ts +3 -0
- package/dist/host/unit-data.js +127 -0
- package/dist/host/unit-face.d.ts +95 -0
- package/dist/host/unit-face.js +1 -0
- package/dist/host/unit-plugin.d.ts +24 -0
- package/dist/host/unit-plugin.js +25 -0
- package/dist/host/update-journal-manifest.d.ts +19 -0
- package/dist/host/update-journal-manifest.js +134 -0
- package/dist/host/update-journal-types.d.ts +33 -0
- package/dist/host/update-journal-types.js +2 -0
- package/dist/host/update-journal.d.ts +43 -0
- package/dist/host/update-journal.js +409 -0
- package/dist/host/value-handoff.d.ts +16 -0
- package/dist/host/value-handoff.js +22 -0
- package/dist/host/version-range.d.ts +2 -0
- package/dist/host/version-range.js +13 -0
- package/dist/host/version.d.ts +4 -0
- package/dist/host/version.js +32 -0
- package/dist/host/workspace-store.d.ts +19 -0
- package/dist/host/workspace-store.js +133 -0
- package/dist/host/write-result.d.ts +1 -0
- package/dist/host/write-result.js +18 -0
- package/dist/lib/dsh-client.d.ts +1 -1
- package/package.json +51 -47
- package/src/lib/dsh-client.ts +2 -1
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { h, useEffect, useMemo, useRef, useState } from '../lib/react.js';
|
|
2
|
+
import { IconSearchOutlineRegular, Menu } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
3
|
+
import { selectLoadingNode, selectTriggerNode } from './SelectFieldNodes.js';
|
|
4
|
+
import { Field } from './Field.js';
|
|
5
|
+
import { TextField } from './TextField.js';
|
|
6
|
+
import './SelectField.css';
|
|
7
|
+
const FOOTER_ID = '__wb-select-footer__';
|
|
8
|
+
const EMPTY_ID = '__wb-select-empty__';
|
|
9
|
+
function mergeClass(...parts) {
|
|
10
|
+
return parts.filter((one) => one !== undefined && one !== '').join(' ');
|
|
11
|
+
}
|
|
12
|
+
function triggerClassOf(variantClass, iconOnly) {
|
|
13
|
+
return mergeClass('wb-selectTrigger', variantClass, iconOnly ? 'wb-selectIconOnly' : undefined);
|
|
14
|
+
}
|
|
15
|
+
function itemOf(option) {
|
|
16
|
+
return {
|
|
17
|
+
id: option.value,
|
|
18
|
+
label: option.label,
|
|
19
|
+
...(option.icon === undefined ? {} : { icon: option.icon }),
|
|
20
|
+
...(option.disabled === true ? { disabled: true } : {}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function selectValueNode(current, renderValue, placeholder) {
|
|
24
|
+
if (current === undefined) {
|
|
25
|
+
return h("span", { className: "wb-selectPlaceholder" }, placeholder ?? '—');
|
|
26
|
+
}
|
|
27
|
+
return renderValue === undefined ? current.label : renderValue(current);
|
|
28
|
+
}
|
|
29
|
+
function searchNode(args) {
|
|
30
|
+
return (h("span", { ref: args.boxRef, className: args.className },
|
|
31
|
+
h("span", { className: "wb-selectSearchIcon" },
|
|
32
|
+
h(IconSearchOutlineRegular, { size: 14 })),
|
|
33
|
+
h(TextField, { id: args.id, name: args.name, className: "wb-selectSearchInput", "aria-label": args.ariaLabel, placeholder: args.placeholder, value: args.query, onChange: (event) => args.onQuery(event.currentTarget.value), onKeyDown: (event) => {
|
|
34
|
+
if (event.nativeEvent.isComposing)
|
|
35
|
+
return;
|
|
36
|
+
args.onKey(event);
|
|
37
|
+
} })));
|
|
38
|
+
}
|
|
39
|
+
function menuNode(args) {
|
|
40
|
+
return (h(Menu, { open: args.open, portal: true, className: "wb-selectAnchor", listClassName: args.listClassName, anchor: args.anchor, align: "start", side: "bottom", selection: args.selection, selectedId: args.selectedId, items: args.items, footer: args.footer, onSelect: args.onPick, onClose: args.onCancel }));
|
|
41
|
+
}
|
|
42
|
+
function framed(label, hint, className, control) {
|
|
43
|
+
const inner = label === undefined
|
|
44
|
+
? hint === undefined
|
|
45
|
+
? control
|
|
46
|
+
: (h("span", { className: "wb-select" },
|
|
47
|
+
control,
|
|
48
|
+
h("span", { className: "wb-selectHint" }, hint)))
|
|
49
|
+
: (h(Field, { label: label, hint: hint }, control));
|
|
50
|
+
return className === undefined ? inner : h("div", { className: className }, inner);
|
|
51
|
+
}
|
|
52
|
+
/** 算候选项用来匹配搜索的文本:有 `searchText` 就用它,否则取字符串标签;标签不是字符串又没给它是空串(这项搜不到)。 */
|
|
53
|
+
export function searchTextOf(option) {
|
|
54
|
+
if (option.searchText !== undefined)
|
|
55
|
+
return option.searchText;
|
|
56
|
+
return typeof option.label === 'string' ? option.label : '';
|
|
57
|
+
}
|
|
58
|
+
/** 默认匹配:查询去空白折成小写后看它是不是 `searchTextOf` 的子串;查询为空或纯空白时一律命中(留在列表里)。 */
|
|
59
|
+
export function defaultSelectFilter(option, query) {
|
|
60
|
+
const needle = query.trim().toLowerCase();
|
|
61
|
+
if (needle === '')
|
|
62
|
+
return true;
|
|
63
|
+
return searchTextOf(option).toLowerCase().includes(needle);
|
|
64
|
+
}
|
|
65
|
+
/** 按查询过滤候选 —— 组件与模块自己算列表都用它,好让同一份口径管两处:`filter` 不给就用 `defaultSelectFilter`,顺序不变。 */
|
|
66
|
+
export function filterSelectOptions(options, query, filter = defaultSelectFilter) {
|
|
67
|
+
return options.filter((option) => filter(option, query));
|
|
68
|
+
}
|
|
69
|
+
/** 把键盘游标换算成当前该高亮那项的 value:游标 `null`(还没动过键盘)或列表为空时没有高亮;太大的游标收到最后一项,负游标取不到项也回 `null`。 */
|
|
70
|
+
export function selectCursorValue(shown, cursor) {
|
|
71
|
+
if (cursor === null || shown.length === 0)
|
|
72
|
+
return null;
|
|
73
|
+
return shown[Math.min(cursor, shown.length - 1)]?.value ?? null;
|
|
74
|
+
}
|
|
75
|
+
/** 按上下键移动游标(两头环绕):还没选过时向下取第一项、向上取最后一项;列表为空回 `null`(一步都动不了)。`step` 1 向下、-1 向上。 */
|
|
76
|
+
export function stepSelectCursor(shown, cursor, step) {
|
|
77
|
+
if (shown.length === 0)
|
|
78
|
+
return null;
|
|
79
|
+
if (cursor === null)
|
|
80
|
+
return step === 1 ? 0 : shown.length - 1;
|
|
81
|
+
return (cursor + step + shown.length) % shown.length;
|
|
82
|
+
}
|
|
83
|
+
/** 把候选排成 `Menu` 要的条目表:按 `group` 插分组标题(`groups: false` 时平铺);一项都没有时退回 `emptyText` 那一行(不给就是空表)。 */
|
|
84
|
+
export function selectEntries(shown, emptyText, options = {}) {
|
|
85
|
+
if (shown.length === 0) {
|
|
86
|
+
return emptyText === undefined ? [] : [{ type: 'label', id: EMPTY_ID, text: emptyText }];
|
|
87
|
+
}
|
|
88
|
+
const grouped = options.groups ?? true;
|
|
89
|
+
const out = [];
|
|
90
|
+
let group = null;
|
|
91
|
+
for (const option of shown) {
|
|
92
|
+
if (grouped && option.group !== undefined && option.group !== group) {
|
|
93
|
+
out.push({ type: 'label', id: `__wb-select-group-${String(out.length)}`, text: option.group });
|
|
94
|
+
group = option.group;
|
|
95
|
+
}
|
|
96
|
+
out.push(itemOf(option));
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
function useSelectState(props) {
|
|
101
|
+
const { options, filter = defaultSelectFilter, emptyText, open: openProp, onOpenChange } = props;
|
|
102
|
+
const [openState, setOpenState] = useState(false);
|
|
103
|
+
const [query, setQuery] = useState('');
|
|
104
|
+
const [cursor, setCursor] = useState(null);
|
|
105
|
+
const boxRef = useRef(null);
|
|
106
|
+
const triggerRef = useRef(null);
|
|
107
|
+
const wasOpenRef = useRef(false);
|
|
108
|
+
const pickedRef = useRef(false);
|
|
109
|
+
const closedByUsRef = useRef(false);
|
|
110
|
+
const open = openProp ?? openState;
|
|
111
|
+
const setOpen = (next) => {
|
|
112
|
+
if (openProp === undefined)
|
|
113
|
+
setOpenState(next);
|
|
114
|
+
onOpenChange?.(next);
|
|
115
|
+
};
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!open || props.search === false)
|
|
118
|
+
return;
|
|
119
|
+
boxRef.current?.querySelector('input')?.focus();
|
|
120
|
+
}, [open, props.search]);
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (open) {
|
|
123
|
+
wasOpenRef.current = true;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!wasOpenRef.current)
|
|
127
|
+
return;
|
|
128
|
+
wasOpenRef.current = false;
|
|
129
|
+
const closedByUs = closedByUsRef.current;
|
|
130
|
+
const picked = pickedRef.current;
|
|
131
|
+
closedByUsRef.current = false;
|
|
132
|
+
pickedRef.current = false;
|
|
133
|
+
if (!closedByUs || picked)
|
|
134
|
+
return;
|
|
135
|
+
triggerRef.current?.focus();
|
|
136
|
+
}, [open]);
|
|
137
|
+
const shown = useMemo(() => filterSelectOptions(options, query, filter), [options, query, filter]);
|
|
138
|
+
const close = (picked) => {
|
|
139
|
+
closedByUsRef.current = true;
|
|
140
|
+
pickedRef.current = picked;
|
|
141
|
+
setOpen(false);
|
|
142
|
+
setQuery('');
|
|
143
|
+
setCursor(null);
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
open,
|
|
147
|
+
setOpen,
|
|
148
|
+
query,
|
|
149
|
+
cursor,
|
|
150
|
+
setCursor,
|
|
151
|
+
setQuery,
|
|
152
|
+
shown,
|
|
153
|
+
close,
|
|
154
|
+
boxRef,
|
|
155
|
+
triggerRef,
|
|
156
|
+
empty: typeof emptyText === 'function' ? emptyText(query) : emptyText,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 下拉选择:默认是跟 `TextField` 一套的常规下拉框(不是原生 `<select>`),无边框那种给 `variant: 'ghost'`。
|
|
161
|
+
* `open` 不给就内部自己管(两种接法下 `onOpenChange` 都会通知),`loading` 把触发器换成转圈 + `loadingText`(默认 `…`),
|
|
162
|
+
* `selection` 选选中行标记(`fill` 整行底色 / `check` 行尾勾),`footer` 是列表底部那一条(点它走 `onFooter`,不改当前值)。
|
|
163
|
+
* @param props.value - 当前值;在 `options` 里找不到就按"没选"画 `placeholder`。
|
|
164
|
+
* @param props.options - 全量候选;空数组且给了 `fallback` 时改画手填输入框。
|
|
165
|
+
* @param props.onChange - 选中一项后的回调,回的是那一项的 `value`。
|
|
166
|
+
* @param props.label - 没进 `FormRow` 时的标签兜底;进了那一行就别再给它和 `hint`,否则会多一个标签。
|
|
167
|
+
* @param props.renderValue - 自己渲染触发器上那份当前值;不给就用候选项的 `label`。
|
|
168
|
+
* @param props.placeholder - 没选中时那句话;不给是 `—`。
|
|
169
|
+
* @param props.chevronHidden - 箭头留着位置但不画:调用方在那个位置叠自己的操作钮。
|
|
170
|
+
* @param props.search - 是否可搜(默认 true);`false` 时不画搜索框、也不自动聚焦。
|
|
171
|
+
* @param props.filter - 自定义匹配;不给用 `defaultSelectFilter`(空白查询一律命中)。
|
|
172
|
+
* @param props.emptyText - 无匹配时的文案,或按查询生成文案的函数(能说"没有匹配 X 的项")。
|
|
173
|
+
* @param props.fallback - 退路:`options` 为空时改成手填(`value` + `onChange`)。
|
|
174
|
+
* @returns 触发器,以及打开时的搜索框与列表。
|
|
175
|
+
*/
|
|
176
|
+
export function SelectField(props) {
|
|
177
|
+
const { value, options, onChange, label, hint, icon, renderValue, placeholder, search = true, searchLabel, searchPlaceholder, footer, onFooter, disabled = false, invalid = false, loading = false, loadingText, fallback, selection = 'fill', variant = 'boxed', iconOnly = false, chevronHidden = false, ariaLabel, title, id, name, className, menuClassName, } = props;
|
|
178
|
+
const state = useSelectState(props);
|
|
179
|
+
const current = options.find((option) => option.value === value);
|
|
180
|
+
const variantClass = variant === 'ghost' ? 'wb-selectGhost' : undefined;
|
|
181
|
+
const triggerClass = triggerClassOf(variantClass, iconOnly);
|
|
182
|
+
if (loading) {
|
|
183
|
+
return framed(label, hint, className, selectLoadingNode({ id, className: triggerClass, invalid, ariaLabel, loadingText }));
|
|
184
|
+
}
|
|
185
|
+
if (fallback !== undefined && options.length === 0) {
|
|
186
|
+
return framed(label, hint, className, h(TextField, { id: id, name: name, className: "wb-selectFallback", invalid: invalid, "aria-label": ariaLabel, value: fallback.value, onChange: (event) => fallback.onChange(event.currentTarget.value) }));
|
|
187
|
+
}
|
|
188
|
+
const trigger = selectTriggerNode({
|
|
189
|
+
id,
|
|
190
|
+
className: triggerClass,
|
|
191
|
+
disabled,
|
|
192
|
+
invalid,
|
|
193
|
+
open: state.open,
|
|
194
|
+
ariaLabel,
|
|
195
|
+
title,
|
|
196
|
+
icon,
|
|
197
|
+
value: selectValueNode(current, renderValue, placeholder),
|
|
198
|
+
iconOnly,
|
|
199
|
+
chevronHidden,
|
|
200
|
+
onOpen: () => state.setOpen(true),
|
|
201
|
+
ref: state.triggerRef,
|
|
202
|
+
});
|
|
203
|
+
const anchor = state.open && search
|
|
204
|
+
? searchNode({
|
|
205
|
+
boxRef: state.boxRef,
|
|
206
|
+
className: mergeClass('wb-selectSearch', variantClass),
|
|
207
|
+
id,
|
|
208
|
+
name,
|
|
209
|
+
ariaLabel: searchLabel,
|
|
210
|
+
placeholder: searchPlaceholder,
|
|
211
|
+
query: state.query,
|
|
212
|
+
onQuery: (next) => {
|
|
213
|
+
state.setQuery(next);
|
|
214
|
+
state.setCursor(null);
|
|
215
|
+
},
|
|
216
|
+
onKey: (event) => {
|
|
217
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
218
|
+
event.stopPropagation();
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
state.setCursor((at) => stepSelectCursor(state.shown, at, event.key === 'ArrowDown' ? 1 : -1));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (event.key !== 'Enter')
|
|
224
|
+
return;
|
|
225
|
+
event.stopPropagation();
|
|
226
|
+
const pick = state.shown[Math.min(state.cursor ?? 0, state.shown.length - 1)];
|
|
227
|
+
if (pick === undefined)
|
|
228
|
+
return;
|
|
229
|
+
state.close(true);
|
|
230
|
+
onChange(pick.value);
|
|
231
|
+
},
|
|
232
|
+
})
|
|
233
|
+
: trigger;
|
|
234
|
+
return framed(label, hint, className, menuNode({
|
|
235
|
+
open: state.open,
|
|
236
|
+
listClassName: mergeClass('wb-selectMenu', menuClassName),
|
|
237
|
+
anchor,
|
|
238
|
+
selection,
|
|
239
|
+
selectedId: selectCursorValue(state.shown, state.cursor) ?? (value === '' ? undefined : value),
|
|
240
|
+
items: selectEntries(state.shown, state.empty, { groups: state.query.trim() === '' }),
|
|
241
|
+
footer: footer === undefined
|
|
242
|
+
? undefined
|
|
243
|
+
: [
|
|
244
|
+
{
|
|
245
|
+
id: FOOTER_ID,
|
|
246
|
+
label: footer.label,
|
|
247
|
+
...(footer.icon === undefined ? {} : { icon: footer.icon }),
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
onPick: (picked) => {
|
|
251
|
+
state.close(true);
|
|
252
|
+
if (picked === FOOTER_ID) {
|
|
253
|
+
onFooter?.();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
onChange(picked);
|
|
257
|
+
},
|
|
258
|
+
onCancel: () => state.close(false),
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ReactNode, Ref } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 下拉触发器那颗按钮:图标 + 当前值 + 箭头,交给 `Menu` 当 anchor;宽窄两档共用一个形状。
|
|
4
|
+
* @param args.id - 触发器 id。
|
|
5
|
+
* @param args.className - 触发器类名(已含 variant 与 iconOnly 的档)。
|
|
6
|
+
* @param args.disabled - 是否禁用。
|
|
7
|
+
* @param args.invalid - 置真写 `aria-invalid`。
|
|
8
|
+
* @param args.open - 列表是否开着,写进 `aria-expanded`。
|
|
9
|
+
* @param args.ariaLabel - 读屏名。
|
|
10
|
+
* @param args.title - 原生提示。
|
|
11
|
+
* @param args.icon - 值左边那枚图标;不给不占位。
|
|
12
|
+
* @param args.value - 已渲染好的当前值节点(文本或占位)。
|
|
13
|
+
* @param args.iconOnly - 只画图标(窄栏那颗切换钮),值与箭头都不画。
|
|
14
|
+
* @param args.chevronHidden - 箭头占位但不可见;调用方自己在那个位置叠一颗操作钮。
|
|
15
|
+
* @param args.onOpen - 点它做什么,通常是把列表打开。
|
|
16
|
+
* @param args.ref - 挂到这颗 `<button>` 上,取消后回焦点、菜单开着头条滚轮要用它。
|
|
17
|
+
* @returns 一颗 `<button>`。
|
|
18
|
+
*/
|
|
19
|
+
export declare function selectTriggerNode(args: {
|
|
20
|
+
readonly id: string | undefined;
|
|
21
|
+
readonly className: string;
|
|
22
|
+
readonly disabled: boolean;
|
|
23
|
+
readonly invalid: boolean;
|
|
24
|
+
readonly open: boolean;
|
|
25
|
+
readonly ariaLabel: string | undefined;
|
|
26
|
+
readonly title: string | undefined;
|
|
27
|
+
readonly icon: ReactNode | undefined;
|
|
28
|
+
readonly value: ReactNode;
|
|
29
|
+
readonly iconOnly: boolean;
|
|
30
|
+
readonly chevronHidden: boolean;
|
|
31
|
+
readonly onOpen: () => void;
|
|
32
|
+
readonly ref: Ref<HTMLButtonElement> | undefined;
|
|
33
|
+
}): ReactNode;
|
|
34
|
+
/**
|
|
35
|
+
* 名单还没读到时的触发器:禁用 + `aria-busy` 的按钮,`SelectField` 在 `loading` 那档画它。
|
|
36
|
+
* @param args.id - 触发器 id。
|
|
37
|
+
* @param args.className - 触发器类名;它后面会接上 loading 那档的类。
|
|
38
|
+
* @param args.invalid - 置真写 `aria-invalid`。
|
|
39
|
+
* @param args.ariaLabel - 读屏名。
|
|
40
|
+
* @param args.loadingText - 占位文案;不给就是 `…`。
|
|
41
|
+
* @returns 一颗禁用且 `aria-busy` 的按钮。
|
|
42
|
+
*/
|
|
43
|
+
export declare function selectLoadingNode(args: {
|
|
44
|
+
readonly id: string | undefined;
|
|
45
|
+
readonly className: string;
|
|
46
|
+
readonly invalid: boolean;
|
|
47
|
+
readonly ariaLabel: string | undefined;
|
|
48
|
+
readonly loadingText: string | undefined;
|
|
49
|
+
}): ReactNode;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Fragment, h } from '../lib/react.js';
|
|
2
|
+
import { IconChevronDownOutlineRegular, TextShimmer, } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
3
|
+
import { Spinner } from './Spinner.js';
|
|
4
|
+
/**
|
|
5
|
+
* 下拉触发器那颗按钮:图标 + 当前值 + 箭头,交给 `Menu` 当 anchor;宽窄两档共用一个形状。
|
|
6
|
+
* @param args.id - 触发器 id。
|
|
7
|
+
* @param args.className - 触发器类名(已含 variant 与 iconOnly 的档)。
|
|
8
|
+
* @param args.disabled - 是否禁用。
|
|
9
|
+
* @param args.invalid - 置真写 `aria-invalid`。
|
|
10
|
+
* @param args.open - 列表是否开着,写进 `aria-expanded`。
|
|
11
|
+
* @param args.ariaLabel - 读屏名。
|
|
12
|
+
* @param args.title - 原生提示。
|
|
13
|
+
* @param args.icon - 值左边那枚图标;不给不占位。
|
|
14
|
+
* @param args.value - 已渲染好的当前值节点(文本或占位)。
|
|
15
|
+
* @param args.iconOnly - 只画图标(窄栏那颗切换钮),值与箭头都不画。
|
|
16
|
+
* @param args.chevronHidden - 箭头占位但不可见;调用方自己在那个位置叠一颗操作钮。
|
|
17
|
+
* @param args.onOpen - 点它做什么,通常是把列表打开。
|
|
18
|
+
* @param args.ref - 挂到这颗 `<button>` 上,取消后回焦点、菜单开着头条滚轮要用它。
|
|
19
|
+
* @returns 一颗 `<button>`。
|
|
20
|
+
*/
|
|
21
|
+
export function selectTriggerNode(args) {
|
|
22
|
+
return (h("button", { type: "button", ref: args.ref, id: args.id, className: args.className, disabled: args.disabled, "aria-haspopup": "listbox", "aria-expanded": args.open, "aria-invalid": args.invalid || undefined, "aria-label": args.ariaLabel, title: args.title, onClick: args.onOpen }, args.iconOnly ? (h("span", { className: "wb-selectIcon" }, args.icon)) : (h(Fragment, null,
|
|
23
|
+
args.icon === undefined ? null : h("span", { className: "wb-selectIcon" }, args.icon),
|
|
24
|
+
h("span", { className: "wb-selectValue" }, args.value),
|
|
25
|
+
h("span", { className: "wb-selectChevron", "data-hidden": args.chevronHidden ? '' : undefined },
|
|
26
|
+
h(IconChevronDownOutlineRegular, { size: 14 }))))));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 名单还没读到时的触发器:禁用 + `aria-busy` 的按钮,`SelectField` 在 `loading` 那档画它。
|
|
30
|
+
* @param args.id - 触发器 id。
|
|
31
|
+
* @param args.className - 触发器类名;它后面会接上 loading 那档的类。
|
|
32
|
+
* @param args.invalid - 置真写 `aria-invalid`。
|
|
33
|
+
* @param args.ariaLabel - 读屏名。
|
|
34
|
+
* @param args.loadingText - 占位文案;不给就是 `…`。
|
|
35
|
+
* @returns 一颗禁用且 `aria-busy` 的按钮。
|
|
36
|
+
*/
|
|
37
|
+
export function selectLoadingNode(args) {
|
|
38
|
+
return (h("button", { type: "button", id: args.id, className: `${args.className} wb-selectLoading`, disabled: true, "aria-busy": "true", "aria-invalid": args.invalid || undefined, "aria-label": args.ariaLabel, title: args.loadingText },
|
|
39
|
+
h("span", { className: "wb-selectValue" },
|
|
40
|
+
h(TextShimmer, { active: true }, args.loadingText ?? '…')),
|
|
41
|
+
h("span", { className: "wb-selectChevron" },
|
|
42
|
+
h(Spinner, { size: 14 }))));
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
section.wb-settings {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--wb-len-12);
|
|
5
|
+
padding: var(--wb-len-12) var(--wb-len-16);
|
|
6
|
+
border: 0;
|
|
7
|
+
border-radius: var(--dsw-radius-md);
|
|
8
|
+
background: var(--dsw-alias-settings-card-fill);
|
|
9
|
+
}
|
|
10
|
+
.wb-settingsHead {
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
gap: var(--wb-len-8);
|
|
14
|
+
}
|
|
15
|
+
.wb-settings .wb-settingsTitle {
|
|
16
|
+
flex: 1 1 auto;
|
|
17
|
+
min-width: 0;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
text-overflow: ellipsis;
|
|
20
|
+
white-space: nowrap;
|
|
21
|
+
font-size: var(--dsw-font-s-strong-14-font-size);
|
|
22
|
+
line-height: var(--wb-line-24);
|
|
23
|
+
font-weight: 500;
|
|
24
|
+
color: var(--dsw-alias-label-primary);
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactNode } from '../lib/react.js';
|
|
2
|
+
import './SettingsSection.css';
|
|
3
|
+
/**
|
|
4
|
+
* `SettingsSection` 的契约:一节的读屏名、标题、右上动作与内容。
|
|
5
|
+
*/
|
|
6
|
+
export interface SettingsSectionProps {
|
|
7
|
+
readonly label: string;
|
|
8
|
+
readonly title: ReactNode;
|
|
9
|
+
readonly action?: ReactNode | undefined;
|
|
10
|
+
readonly children?: ReactNode | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 设置面里的一节:标题 + 右上那颗动作 + 一节内容,把一屏设置分组。
|
|
14
|
+
* @param props.label - 只给读屏的组名(`aria-label`),不是标题。
|
|
15
|
+
* @param props.title - 人看的标题。
|
|
16
|
+
* @param props.action - 标题右侧的动作(如"添加");不给不占位。
|
|
17
|
+
* @param props.children - 这一节的内容。
|
|
18
|
+
* @returns 一个 `role="group"` 的 section。
|
|
19
|
+
*/
|
|
20
|
+
export declare function SettingsSection({ label, title, action, children }: SettingsSectionProps): JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { h } from '../lib/react.js';
|
|
2
|
+
import './SettingsSection.css';
|
|
3
|
+
/**
|
|
4
|
+
* 设置面里的一节:标题 + 右上那颗动作 + 一节内容,把一屏设置分组。
|
|
5
|
+
* @param props.label - 只给读屏的组名(`aria-label`),不是标题。
|
|
6
|
+
* @param props.title - 人看的标题。
|
|
7
|
+
* @param props.action - 标题右侧的动作(如"添加");不给不占位。
|
|
8
|
+
* @param props.children - 这一节的内容。
|
|
9
|
+
* @returns 一个 `role="group"` 的 section。
|
|
10
|
+
*/
|
|
11
|
+
export function SettingsSection({ label, title, action, children }) {
|
|
12
|
+
return (h("section", { className: "wb-settings", role: "group", "aria-label": label },
|
|
13
|
+
h("header", { className: "wb-settingsHead" },
|
|
14
|
+
h("span", { className: "wb-settingsTitle" }, title),
|
|
15
|
+
action),
|
|
16
|
+
children));
|
|
17
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ReactNode } from '../lib/react.js';
|
|
2
|
+
/**
|
|
3
|
+
* 初始化的一步:渲染什么、能不能走、走去哪、走之前存什么。
|
|
4
|
+
*/
|
|
5
|
+
export interface SetupStep {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly title: string;
|
|
8
|
+
readonly render: (ctx: SetupStepContext) => ReactNode;
|
|
9
|
+
readonly canLeave?: ((values: Readonly<Record<string, unknown>>) => boolean) | undefined;
|
|
10
|
+
readonly next?: ((values: Readonly<Record<string, unknown>>) => string | null) | undefined;
|
|
11
|
+
readonly submit?: ((values: Readonly<Record<string, unknown>>) => Promise<SetupWriteResult>) | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 每步的渲染上下文:当前值、改值、忙碌与错误。
|
|
15
|
+
*/
|
|
16
|
+
export interface SetupStepContext {
|
|
17
|
+
readonly values: Readonly<Record<string, unknown>>;
|
|
18
|
+
readonly setValues: (next: Record<string, unknown>) => void;
|
|
19
|
+
readonly busy: boolean;
|
|
20
|
+
readonly error: string | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 一次配置读取的结果:`configured` 为真表示已经不用再初始化,`values` 是已存的值。
|
|
24
|
+
*/
|
|
25
|
+
export interface SetupSnapshot {
|
|
26
|
+
readonly configured: boolean;
|
|
27
|
+
readonly values?: Readonly<Record<string, unknown>> | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 一次配置写入的结果。
|
|
31
|
+
*/
|
|
32
|
+
export type SetupWriteResult = {
|
|
33
|
+
readonly ok: true;
|
|
34
|
+
} | {
|
|
35
|
+
readonly ok: false;
|
|
36
|
+
readonly code?: string | undefined;
|
|
37
|
+
readonly message: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 初始化流程的归一化相位:正在读 / 要配置 / 已就绪 / 读不到。
|
|
41
|
+
*/
|
|
42
|
+
export type SetupPhase = 'checking' | 'needs-setup' | 'ready' | 'blocked';
|
|
43
|
+
/**
|
|
44
|
+
* `useUnitSetup` 交出来的那台机器;`SetupShell` 只认这一个形状。
|
|
45
|
+
*/
|
|
46
|
+
export interface UnitSetup {
|
|
47
|
+
readonly phase: SetupPhase;
|
|
48
|
+
readonly steps: readonly SetupStep[];
|
|
49
|
+
readonly step: SetupStep | undefined;
|
|
50
|
+
readonly values: Readonly<Record<string, unknown>>;
|
|
51
|
+
readonly setValues: (next: Record<string, unknown>) => void;
|
|
52
|
+
readonly busy: boolean;
|
|
53
|
+
readonly error: string | null;
|
|
54
|
+
readonly canLeave: boolean;
|
|
55
|
+
readonly canBack: boolean;
|
|
56
|
+
readonly next: () => void;
|
|
57
|
+
readonly back: () => void;
|
|
58
|
+
readonly retry: () => void;
|
|
59
|
+
readonly saveAll: () => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* `SetupShell` 自己那几句文案;模块按自己的词表给。
|
|
63
|
+
*/
|
|
64
|
+
export interface SetupShellLabels {
|
|
65
|
+
readonly back: string;
|
|
66
|
+
readonly next: string;
|
|
67
|
+
readonly finish: string;
|
|
68
|
+
readonly save: string;
|
|
69
|
+
readonly saving: string;
|
|
70
|
+
readonly cancel: string;
|
|
71
|
+
readonly reading: string;
|
|
72
|
+
readonly failed: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* `<SetupShell>` 的 prop:一台 `useUnitSetup` 的机器、文案、以及完成后的主页。
|
|
76
|
+
*/
|
|
77
|
+
export interface SetupShellProps {
|
|
78
|
+
readonly setup: UnitSetup;
|
|
79
|
+
readonly labels: SetupShellLabels;
|
|
80
|
+
readonly mode?: 'setup' | 'edit' | undefined;
|
|
81
|
+
readonly renderHome?: (() => ReactNode) | undefined;
|
|
82
|
+
readonly onCancel?: (() => void) | undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 初始化 / 配置的外壳:分步、上一步 / 下一步 / 完成、阻断与错误,完成之后把主页换进来。
|
|
86
|
+
* @param props.setup - `useUnitSetup` 的返回值;壳不自己取数、不自己写配置。
|
|
87
|
+
* @param props.labels - 八句文案:上一步 / 下一步 / 完成 / 保存 / 保存中 / 取消 / 正在读 / 读不到。
|
|
88
|
+
* @param props.mode - `setup`(默认,分步)或 `edit`(同一步骤集合摊成一页,底部 `SaveBar`)。
|
|
89
|
+
* @param props.renderHome - 相位到 `ready` 时渲染什么;不给就只留空。
|
|
90
|
+
* @param props.onCancel - `edit` 模式点取消做什么;不给钮就什么都不做。
|
|
91
|
+
* @returns 一块初始化或配置界面。
|
|
92
|
+
*/
|
|
93
|
+
export declare function SetupShell({ setup, labels, mode, renderHome, onCancel, }: SetupShellProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | JSX.Element | null | undefined;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { h } from '../lib/react.js';
|
|
2
|
+
import { Button } from '@deepseek-ai/dsh-client-ui-primitives';
|
|
3
|
+
import { CenteredState } from './ResourceStates.js';
|
|
4
|
+
import { Note } from './Note.js';
|
|
5
|
+
import { SaveBar } from './SaveBar.js';
|
|
6
|
+
import styles from './SetupShell.module.css';
|
|
7
|
+
/**
|
|
8
|
+
* 初始化 / 配置的外壳:分步、上一步 / 下一步 / 完成、阻断与错误,完成之后把主页换进来。
|
|
9
|
+
* @param props.setup - `useUnitSetup` 的返回值;壳不自己取数、不自己写配置。
|
|
10
|
+
* @param props.labels - 八句文案:上一步 / 下一步 / 完成 / 保存 / 保存中 / 取消 / 正在读 / 读不到。
|
|
11
|
+
* @param props.mode - `setup`(默认,分步)或 `edit`(同一步骤集合摊成一页,底部 `SaveBar`)。
|
|
12
|
+
* @param props.renderHome - 相位到 `ready` 时渲染什么;不给就只留空。
|
|
13
|
+
* @param props.onCancel - `edit` 模式点取消做什么;不给钮就什么都不做。
|
|
14
|
+
* @returns 一块初始化或配置界面。
|
|
15
|
+
*/
|
|
16
|
+
export function SetupShell({ setup, labels, mode = 'setup', renderHome, onCancel, }) {
|
|
17
|
+
if (setup.phase === 'checking') {
|
|
18
|
+
return h(CenteredState, { icon: null, title: labels.reading });
|
|
19
|
+
}
|
|
20
|
+
if (setup.phase === 'blocked') {
|
|
21
|
+
return (h(CenteredState, { icon: null, title: labels.failed, ...(setup.error === null ? {} : { detail: setup.error }) }));
|
|
22
|
+
}
|
|
23
|
+
if (mode === 'edit') {
|
|
24
|
+
return editForm(setup, labels, onCancel);
|
|
25
|
+
}
|
|
26
|
+
if (setup.phase === 'ready') {
|
|
27
|
+
return renderHome === undefined ? null : renderHome();
|
|
28
|
+
}
|
|
29
|
+
const step = setup.step;
|
|
30
|
+
if (step === undefined)
|
|
31
|
+
return null;
|
|
32
|
+
const index = setup.steps.findIndex((candidate) => candidate.id === step.id);
|
|
33
|
+
const last = index === setup.steps.length - 1;
|
|
34
|
+
return (h("div", { className: styles.setup },
|
|
35
|
+
h("ol", { className: styles.steps }, setup.steps.map((candidate, at) => (h("li", { key: candidate.id, className: at === index
|
|
36
|
+
? `${styles.step} ${styles.stepActive}`
|
|
37
|
+
: at < index
|
|
38
|
+
? `${styles.step} ${styles.stepDone}`
|
|
39
|
+
: styles.step, "aria-current": at === index ? 'step' : undefined },
|
|
40
|
+
h("span", { className: styles.stepIndex }, at + 1),
|
|
41
|
+
h("span", { className: styles.stepTitle }, candidate.title))))),
|
|
42
|
+
h("div", { className: styles.body }, step.render(stepContext(setup))),
|
|
43
|
+
setup.error === null ? null : (h(Note, { tone: "problem" }, setup.error)),
|
|
44
|
+
h("div", { className: styles.actions },
|
|
45
|
+
setup.canBack ? (h(Button, { type: "button", variant: "outline", size: "sm", onClick: setup.back }, labels.back)) : null,
|
|
46
|
+
h(Button, { type: "button", variant: "primary", size: "sm", disabled: !setup.canLeave || setup.busy, onClick: setup.next }, last ? labels.finish : labels.next))));
|
|
47
|
+
}
|
|
48
|
+
function editForm(setup, labels, onCancel) {
|
|
49
|
+
return (h("div", { className: styles.edit },
|
|
50
|
+
setup.steps.map((step) => (h("section", { key: step.id, className: styles.editSection },
|
|
51
|
+
h("h3", { className: styles.editTitle }, step.title),
|
|
52
|
+
step.render(stepContext(setup))))),
|
|
53
|
+
setup.error === null ? null : (h(Note, { tone: "problem" }, setup.error)),
|
|
54
|
+
h(SaveBar, { busy: setup.busy, labels: { cancel: labels.cancel, save: labels.save, saving: labels.saving }, onCancel: onCancel ?? noop, onSave: setup.saveAll })));
|
|
55
|
+
}
|
|
56
|
+
function stepContext(setup) {
|
|
57
|
+
return {
|
|
58
|
+
values: setup.values,
|
|
59
|
+
setValues: setup.setValues,
|
|
60
|
+
busy: setup.busy,
|
|
61
|
+
error: setup.error,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function noop() { }
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
.setup {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--wb-len-12);
|
|
5
|
+
}
|
|
6
|
+
.steps {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-wrap: wrap;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: var(--wb-len-8);
|
|
11
|
+
margin: 0;
|
|
12
|
+
padding: 0;
|
|
13
|
+
list-style: none;
|
|
14
|
+
}
|
|
15
|
+
.step {
|
|
16
|
+
display: inline-flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
gap: var(--wb-len-6);
|
|
19
|
+
font-size: var(--dsw-font-xxs-12-font-size);
|
|
20
|
+
line-height: var(--wb-line-18);
|
|
21
|
+
color: var(--dsw-alias-label-tertiary);
|
|
22
|
+
}
|
|
23
|
+
.stepIndex {
|
|
24
|
+
display: inline-flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
width: var(--wb-len-18);
|
|
28
|
+
height: var(--wb-len-18);
|
|
29
|
+
border: 0.5px solid var(--dsw-alias-border-l3);
|
|
30
|
+
border-radius: 50%;
|
|
31
|
+
corner-shape: round;
|
|
32
|
+
font-size: var(--dsw-font-xxxs-11-font-size);
|
|
33
|
+
color: var(--dsw-alias-label-tertiary);
|
|
34
|
+
}
|
|
35
|
+
.stepTitle {
|
|
36
|
+
font-size: var(--dsw-font-xxs-12-font-size);
|
|
37
|
+
line-height: var(--wb-line-18);
|
|
38
|
+
}
|
|
39
|
+
.stepActive {
|
|
40
|
+
color: var(--dsw-alias-label-primary);
|
|
41
|
+
}
|
|
42
|
+
.stepActive .stepIndex {
|
|
43
|
+
border-color: var(--dsw-alias-label-primary);
|
|
44
|
+
color: var(--dsw-alias-label-primary);
|
|
45
|
+
}
|
|
46
|
+
.stepDone {
|
|
47
|
+
color: var(--dsw-alias-label-secondary);
|
|
48
|
+
}
|
|
49
|
+
.body {
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
gap: var(--wb-len-12);
|
|
53
|
+
}
|
|
54
|
+
.actions {
|
|
55
|
+
display: flex;
|
|
56
|
+
justify-content: flex-end;
|
|
57
|
+
gap: var(--wb-len-8);
|
|
58
|
+
}
|
|
59
|
+
.edit {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-direction: column;
|
|
62
|
+
gap: var(--wb-len-16);
|
|
63
|
+
}
|
|
64
|
+
.editSection {
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-direction: column;
|
|
67
|
+
gap: var(--wb-len-12);
|
|
68
|
+
padding-top: var(--wb-len-12);
|
|
69
|
+
border-top: 0.5px solid var(--dsw-alias-border-l3);
|
|
70
|
+
}
|
|
71
|
+
.editSection:first-child {
|
|
72
|
+
padding-top: 0;
|
|
73
|
+
border-top: 0;
|
|
74
|
+
}
|
|
75
|
+
.editTitle {
|
|
76
|
+
margin: 0;
|
|
77
|
+
font-size: var(--dsw-font-s-strong-14-font-size);
|
|
78
|
+
font-weight: 500;
|
|
79
|
+
line-height: var(--wb-line-24);
|
|
80
|
+
color: var(--dsw-alias-label-primary);
|
|
81
|
+
}
|