feat(panel): modularize 3-tab preferences, add model context windows, and optimize telemetry

- Refactor Preferences into decoupled General, Structure, and Other tabs with unified settings schema, factory reset, and trajectory cache rebuild endpoints
- Extract standalone widget, metric, and step-table column registries to customize topbar/composer slots, hover popup modules, live overview layout, and step detail columns
- Add bilingual zh-CN/en-US i18n dictionaries, theme accent presets, and font scale controls across Shadow DOM overlay and sidebar views
- Support per-model host-advertised context window rules across App and IDE transports
- Preserve CLEARED step generation timings, memoize per-poll model resolution, optimize LOESS sorted-x fitting, and update bilingual READMEs and test suites
This commit is contained in:
fish
2026-11-15 01:18:29 +09:00
parent ad33e9cc62
commit 18c608ae63
63 changed files with 16614 additions and 5873 deletions
@@ -0,0 +1,479 @@
/**
* @fileoverview Preferences Tab 1: `SettingsGeneralTab.js` ("常规").
* Manages UI Language (`zh-CN` / `en-US` / `auto`), Theme Accent (`host` + 6 swatches),
* Panel Font Scale (`sm` / `md` / `lg` / `xl`), Pricing Sync, and Plugin Updates.
*/
import { defineComponent } from '../../core/component.js';
import {
normalizeClientFontScale,
normalizeClientThemeAccent,
} from '../../core/appearance.js';
import { h, patchAttr, patchClasses, patchText } from '../../core/domPatch.js';
import { createSvgIcon } from '../../icons/SvgIcon.js';
import { normalizeI18nLanguage, setI18nLanguage, t } from '../../i18n/index.js';
import {
normalizeClientUpdateMode,
saveSettingsPatch,
triggerCloudSync,
triggerPluginUpdate,
} from '../../store/telemetryStore.js';
import { ThemeColorPicker } from '../../components/settings/ThemeColorPicker.js';
import { CustomSelect } from '../../components/ui/CustomSelect.js';
import { SegmentedControl } from '../../components/ui/SegmentedControl.js';
function getLanguageOptions() {
return [
{ value: 'zh-CN', label: t('settings.gen.langZh') },
{ value: 'en-US', label: t('settings.gen.langEn') },
{ value: 'auto', label: t('settings.gen.langAuto') },
];
}
function getFontScaleOptions() {
return [
{ value: 'sm', label: t('settings.gen.fontSm') },
{ value: 'md', label: t('settings.gen.fontMd') },
{ value: 'lg', label: t('settings.gen.fontLg') },
{ value: 'xl', label: t('settings.gen.fontXl') },
];
}
function getUpdateModeOptions() {
return [
{ value: 'manual', label: t('settings.gen.updateManual') },
{ value: 'auto', label: t('settings.gen.updateAuto') },
{ value: 'off', label: t('settings.gen.updateOff') },
];
}
function formatCloudSyncTimeText(tsMs, updatedAt) {
if (Number(tsMs) > 0) {
const d = new Date(Number(tsMs));
const pad = (n) => String(n).padStart(2, '0');
const timeStr = `${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
return t('settings.gen.syncAt', { time: timeStr });
}
if (updatedAt) {
return t('settings.gen.pubAt', { date: String(updatedAt).slice(0, 10) });
}
return t('settings.gen.defaultPricing');
}
export const SettingsGeneralTab = defineComponent({
name: 'SettingsGeneralTab',
setup({ props, onCleanup }) {
let draftLanguage = 'zh-CN';
let draftThemeAccent = 'host';
let draftFontScale = 'md';
let draftPluginUpdateMode = 'manual';
let latestSettings = null;
let latestCloudStatus = null;
let appearanceTimer = null;
let cloudTimer = null;
const appearanceStatusText = h('span', {
className: 'text-muted',
style: 'font-size: var(--fs-md);',
text: '',
});
const cloudStatusMsg = h('span', {
className: 'text-muted',
style: 'font-size: var(--fs-md);',
text: '',
});
function showAppearanceFeedback(text, autoClearMs = 1500) {
if (appearanceTimer) {
clearTimeout(appearanceTimer);
appearanceTimer = null;
}
patchText(appearanceStatusText, text);
if (text && autoClearMs > 0) {
appearanceTimer = setTimeout(() => {
appearanceTimer = null;
patchText(appearanceStatusText, '');
}, autoClearMs);
}
}
function showCloudFeedback(text, autoClearMs = 3500) {
if (cloudTimer) {
clearTimeout(cloudTimer);
cloudTimer = null;
}
patchText(cloudStatusMsg, text);
if (text && autoClearMs > 0) {
cloudTimer = setTimeout(() => {
cloudTimer = null;
patchText(cloudStatusMsg, '');
}, autoClearMs);
}
}
// --- Card 1: 界面与外观 ---
const appearanceTitleEl = h('span', { text: t('settings.gen.appearanceTitle') });
const langLabelEl = h('span', { className: 'form-label', text: t('settings.gen.language') });
const accentLabelEl = h('span', {
className: 'form-label',
text: t('settings.gen.themeAccent'),
});
const fontLabelEl = h('span', { className: 'form-label', text: t('settings.gen.fontScale') });
const fontHintEl = h('span', {
className: 'settings-hint-text',
text: t('settings.gen.fontHint'),
});
const languageSwitch = SegmentedControl({
ariaLabel: t('settings.gen.language'),
modelValue: draftLanguage,
options: getLanguageOptions(),
onUpdateModelValue: async (val) => {
const nextLang = normalizeI18nLanguage(val);
draftLanguage = nextLang;
setI18nLanguage(nextLang);
languageSwitch.setValue(nextLang);
showAppearanceFeedback(t('settings.saving'), 0);
try {
await saveSettingsPatch({ language: nextLang });
showAppearanceFeedback(t('settings.saved'), 1500);
} catch {
if (latestSettings) renderSettings(latestSettings);
showAppearanceFeedback(t('settings.saveFailed'), 2500);
}
},
});
const themeColorPicker = ThemeColorPicker({
modelValue: draftThemeAccent,
onUpdateModelValue: async (val) => {
const nextAccent = normalizeClientThemeAccent(val);
draftThemeAccent = nextAccent;
themeColorPicker.refs.setValue(nextAccent);
showAppearanceFeedback(t('settings.saving'), 0);
try {
await saveSettingsPatch({ themeAccent: nextAccent });
showAppearanceFeedback(t('settings.saved'), 1500);
} catch {
if (latestSettings) renderSettings(latestSettings);
showAppearanceFeedback(t('settings.saveFailed'), 2500);
}
},
});
const fontScaleSwitch = SegmentedControl({
ariaLabel: t('settings.gen.fontScale'),
modelValue: draftFontScale,
options: getFontScaleOptions(),
onUpdateModelValue: async (val) => {
const nextScale = normalizeClientFontScale(val);
draftFontScale = nextScale;
fontScaleSwitch.setValue(nextScale);
showAppearanceFeedback(t('settings.saving'), 0);
try {
await saveSettingsPatch({ fontScale: nextScale });
showAppearanceFeedback(t('settings.saved'), 1500);
props.onLayoutChange?.();
} catch {
if (latestSettings) renderSettings(latestSettings);
showAppearanceFeedback(t('settings.saveFailed'), 2500);
}
},
});
const appearancePanel = h('section', { className: 'panel' }, [
h('div', { className: 'panel-header' }, [
h('span', { className: 'panel-title' }, [
createSvgIcon('sliders', { size: 13 }),
appearanceTitleEl,
]),
appearanceStatusText,
]),
h('div', { className: 'form-row' }, [langLabelEl, languageSwitch.el]),
h('div', { className: 'form-row' }, [accentLabelEl, themeColorPicker.el]),
h('div', { className: 'form-row' }, [fontLabelEl, fontScaleSwitch.el, fontHintEl]),
]);
// --- Card 2: 版本更新 ---
const updateTitleEl = h('span', { text: t('settings.gen.updateTitle') });
const updateModeLabelEl = h('span', {
className: 'form-label',
text: t('settings.gen.updateMode'),
});
const pricingCellLabelEl = h('span', {
className: 'cell-label',
text: t('settings.gen.pricingLabel'),
});
const versionCellLabelEl = h('span', {
className: 'cell-label',
text: t('settings.gen.versionLabel'),
});
const autoUpdateSelect = CustomSelect({
modelValue: 'manual',
icon: 'refresh',
options: getUpdateModeOptions(),
onUpdateModelValue: async (val) => {
const nextMode = normalizeClientUpdateMode(val);
draftPluginUpdateMode = nextMode;
autoUpdateSelect.setValue(nextMode);
if (latestCloudStatus) {
renderCloudStatus(latestCloudStatus);
}
showCloudFeedback(t('settings.saving'), 0);
try {
await saveSettingsPatch({
pluginUpdateMode: nextMode,
autoUpdatePlugin: nextMode === 'auto',
});
showCloudFeedback(t('settings.saved'), 1800);
} catch {
if (latestSettings) renderSettings(latestSettings);
if (latestCloudStatus) renderCloudStatus(latestCloudStatus);
showCloudFeedback(t('settings.saveFailed'), 2500);
}
},
});
const pricingCountVal = h('strong', { className: 'cell-value', text: '—' });
const pricingSyncSub = h('span', { className: 'cell-sub', text: t('quota.loading') });
const versionVal = h('strong', { className: 'cell-value', text: 'v1.4.4' });
const versionSub = h('span', { className: 'cell-sub', text: t('settings.gen.checkingBtn') });
const syncPricingBtnText = h('span', { text: t('settings.gen.syncBtn') });
const syncPricingBtn = h(
'button',
{
type: 'button',
className: 'btn-secondary',
onClick: async () => {
patchAttr(syncPricingBtn, 'disabled', true);
patchText(syncPricingBtnText, t('settings.gen.syncingBtn'));
showCloudFeedback(t('settings.gen.syncingMsg'), 0);
try {
const res = await triggerCloudSync();
const cs = res?.cloudStatus;
if (res?.ok && cs) {
showCloudFeedback(t('settings.gen.syncedMsg', { count: cs.modelCount }), 3500);
} else {
showCloudFeedback(cs?.lastSyncError || t('settings.gen.syncFallbackMsg'), 4500);
}
} catch (err) {
showCloudFeedback(err?.message || t('settings.gen.syncFallbackMsg'), 4500);
} finally {
patchAttr(syncPricingBtn, 'disabled', false);
patchText(syncPricingBtnText, t('settings.gen.syncBtn'));
}
},
},
[createSvgIcon('refresh', { size: 12 }), syncPricingBtnText]
);
const updatePluginBtnText = h('span', { text: t('settings.gen.checkUpdateBtn') });
const updatePluginBtn = h(
'button',
{
type: 'button',
className: 'btn-secondary',
onClick: async () => {
patchAttr(updatePluginBtn, 'disabled', true);
try {
if (!latestCloudStatus?.updateAvailable) {
patchText(updatePluginBtnText, t('settings.gen.checkingBtn'));
showCloudFeedback(t('settings.gen.checkingMsg'), 0);
const syncRes = await triggerCloudSync();
const cs = syncRes?.cloudStatus || latestCloudStatus;
if (cs) {
latestCloudStatus = cs;
renderCloudStatus(cs);
}
if (!syncRes?.ok && cs?.lastSyncError) {
showCloudFeedback(
t('settings.gen.checkFailedMsg', { err: cs.lastSyncError }),
5000
);
return;
}
if (!cs?.updateAvailable) {
const curVer = cs?.currentPluginVersion || '1.4.4';
showCloudFeedback(t('settings.gen.upToDateMsg', { ver: curVer }), 4500);
return;
}
}
patchText(updatePluginBtnText, t('capsule.updating'));
showCloudFeedback(t('settings.gen.downloadingMsg'), 0);
const res = await triggerPluginUpdate();
if (res?.cloudStatus) {
latestCloudStatus = res.cloudStatus;
}
if (res?.ok) {
showCloudFeedback(res.message || t('settings.gen.updatedRestartMsg'), 5000);
} else {
showCloudFeedback(res?.message || t('settings.gen.updateSkippedMsg'), 5500);
}
} catch (err) {
showCloudFeedback(err?.message || t('settings.gen.updateFailedMsg'), 5000);
} finally {
patchAttr(updatePluginBtn, 'disabled', false);
renderCloudStatus(latestCloudStatus);
}
},
},
[createSvgIcon('arrow-down', { size: 12 }), updatePluginBtnText]
);
const cloudPanel = h('section', { className: 'panel' }, [
h('div', { className: 'panel-header' }, [
h('span', { className: 'panel-title' }, [
createSvgIcon('bolt', { size: 13 }),
updateTitleEl,
]),
cloudStatusMsg,
]),
h('div', { className: 'form-row' }, [updateModeLabelEl, autoUpdateSelect.el]),
h('div', { className: 'dual-grid' }, [
h('div', { className: 'matrix-cell' }, [
pricingCellLabelEl,
pricingCountVal,
pricingSyncSub,
]),
h('div', { className: 'matrix-cell' }, [versionCellLabelEl, versionVal, versionSub]),
]),
h('div', { className: 'cloud-actions-row' }, [syncPricingBtn, updatePluginBtn]),
]);
const rootEl = h('div', { className: 'settings-tab-stack' }, [appearancePanel, cloudPanel]);
function renderSettings(settings) {
if (!settings) return;
latestSettings = settings;
draftLanguage = normalizeI18nLanguage(settings.language);
draftThemeAccent = normalizeClientThemeAccent(settings.themeAccent);
draftFontScale = normalizeClientFontScale(settings.fontScale);
draftPluginUpdateMode = normalizeClientUpdateMode(
settings.pluginUpdateMode,
settings.autoUpdatePlugin
);
languageSwitch.setProps({
modelValue: draftLanguage,
options: getLanguageOptions(),
});
themeColorPicker.refs.setValue(draftThemeAccent);
fontScaleSwitch.setProps({
modelValue: draftFontScale,
options: getFontScaleOptions(),
});
autoUpdateSelect.setProps({
modelValue: draftPluginUpdateMode,
options: getUpdateModeOptions(),
});
}
function renderCloudStatus(cs) {
if (!cs) return;
latestCloudStatus = cs;
const srcLabel =
cs.source === 'remote'
? t('settings.gen.srcRemote')
: cs.source === 'local'
? t('settings.gen.srcLocal')
: t('settings.gen.srcDefault');
patchText(pricingCountVal, t('settings.gen.modelCount', { count: cs.modelCount || 0 }));
patchText(
pricingSyncSub,
`${srcLabel} · ${formatCloudSyncTimeText(cs.lastSyncedAtMs, cs.catalogUpdatedAt)}`
);
const curVer = cs.currentPluginVersion || '1.4.4';
const latVer = cs.latestPluginVersion || curVer;
const modeTag = cs.installMode === 'git' ? 'Git' : 'ZIP';
patchText(versionVal, `v${curVer}`);
if (cs.updateAvailable && draftPluginUpdateMode !== 'off') {
patchText(versionSub, t('settings.gen.canUpgradeSub', { ver: latVer, mode: modeTag }));
patchClasses(versionSub, { 'accent-ok': true });
patchText(updatePluginBtnText, t('settings.gen.upgradeToBtn', { ver: latVer }));
patchClasses(updatePluginBtn, { 'btn-primary': true, 'btn-secondary': false });
} else if (draftPluginUpdateMode === 'off') {
patchText(versionSub, t('settings.gen.updateOffSub', { mode: modeTag }));
patchClasses(versionSub, { 'accent-ok': false });
patchText(
updatePluginBtnText,
cs.updateAvailable
? t('settings.gen.manualUpgradeBtn', { ver: latVer })
: t('settings.gen.checkUpdateBtn')
);
patchClasses(updatePluginBtn, { 'btn-primary': false, 'btn-secondary': true });
} else {
patchText(versionSub, t('settings.gen.latestSub', { mode: modeTag }));
patchClasses(versionSub, { 'accent-ok': false });
patchText(updatePluginBtnText, t('settings.gen.checkUpdateBtn'));
patchClasses(updatePluginBtn, { 'btn-primary': false, 'btn-secondary': true });
}
if (
!cloudTimer &&
(cs.lastUpdateError || (cs.lastUpdateResult?.ok === false && cs.lastUpdateResult?.message))
) {
showCloudFeedback(cs.lastUpdateError || cs.lastUpdateResult.message, 5500);
}
}
function refreshLabels() {
patchText(appearanceTitleEl, t('settings.gen.appearanceTitle'));
patchText(langLabelEl, t('settings.gen.language'));
patchText(accentLabelEl, t('settings.gen.themeAccent'));
patchText(fontLabelEl, t('settings.gen.fontScale'));
patchText(fontHintEl, t('settings.gen.fontHint'));
patchText(updateTitleEl, t('settings.gen.updateTitle'));
patchText(updateModeLabelEl, t('settings.gen.updateMode'));
patchText(pricingCellLabelEl, t('settings.gen.pricingLabel'));
patchText(versionCellLabelEl, t('settings.gen.versionLabel'));
if (!syncPricingBtn.hasAttribute('disabled')) {
patchText(syncPricingBtnText, t('settings.gen.syncBtn'));
}
languageSwitch.setProps({
modelValue: draftLanguage,
options: getLanguageOptions(),
});
themeColorPicker.refs.refreshLabels();
fontScaleSwitch.setProps({
modelValue: draftFontScale,
options: getFontScaleOptions(),
});
autoUpdateSelect.setProps({
modelValue: draftPluginUpdateMode,
options: getUpdateModeOptions(),
});
if (latestCloudStatus) {
renderCloudStatus(latestCloudStatus);
} else {
patchText(pricingSyncSub, t('quota.loading'));
}
}
onCleanup(() => {
if (appearanceTimer) clearTimeout(appearanceTimer);
if (cloudTimer) clearTimeout(cloudTimer);
languageSwitch.destroy();
themeColorPicker.destroy();
fontScaleSwitch.destroy();
autoUpdateSelect.destroy();
});
return {
el: rootEl,
refs: {
languageSwitch,
themeColorPicker,
fontScaleSwitch,
autoUpdateSelect,
syncPricingBtn,
updatePluginBtn,
renderSettings,
renderCloudStatus,
refreshLabels,
},
};
},
});
@@ -0,0 +1,480 @@
/**
* @fileoverview Preferences Tab 3: `SettingsOtherTab.js` ("其他").
* Houses Model Identifier Formatting, Per-Model Context Windows,
* Local Trajectory Cache Rebuild, and Two-Step Factory Preference Reset.
*/
import { defineComponent } from '../../core/component.js';
import { h, patchAttr, patchClasses, patchText } from '../../core/domPatch.js';
import { createSvgIcon } from '../../icons/SvgIcon.js';
import { setI18nLanguage, t } from '../../i18n/index.js';
import {
normalizeClientOrchestratorIdMode,
rebuildTrajectoryCache,
resetAllSettings,
saveModelContextWindow,
saveSettingsPatch,
} from '../../store/telemetryStore.js';
import { CustomSelect } from '../../components/ui/CustomSelect.js';
function getStepModelDisplayOptions() {
return [
{ value: 'short', label: t('settings.oth.modelShort') },
{ value: 'upstream', label: t('settings.oth.modelUpstream') },
];
}
function getOrchestratorIdDisplayOptions() {
return [
{ value: 'compact', label: t('settings.oth.orchCompact') },
{ value: 'full', label: t('settings.oth.orchFull') },
];
}
export const SettingsOtherTab = defineComponent({
name: 'SettingsOtherTab',
setup({ onCleanup, getProps }) {
let draftShowUpstreamModel = false;
let draftOrchestratorIdMode = 'compact';
let latestSettings = null;
let contextWindowModels = [];
let contextModelId = '';
let savingContextWindow = false;
let contextFeedback = '';
let modelTimer = null;
let maintTimer = null;
let resetConfirmTimer = null;
let resetConfirmArmed = false;
let isRebuilding = false;
let isResetting = false;
const modelStatusText = h('span', {
className: 'text-muted',
style: 'font-size: var(--fs-md);',
text: '',
});
const maintStatusText = h('span', {
className: 'text-muted',
style: 'font-size: var(--fs-md);',
text: '',
});
function showModelFeedback(text, autoClearMs = 1500) {
if (modelTimer) {
clearTimeout(modelTimer);
modelTimer = null;
}
patchText(modelStatusText, text);
if (text && autoClearMs > 0) {
modelTimer = setTimeout(() => {
modelTimer = null;
patchText(modelStatusText, '');
}, autoClearMs);
}
}
function showMaintFeedback(text, autoClearMs = 2500) {
if (maintTimer) {
clearTimeout(maintTimer);
maintTimer = null;
}
patchText(maintStatusText, text);
if (text && autoClearMs > 0) {
maintTimer = setTimeout(() => {
maintTimer = null;
patchText(maintStatusText, '');
}, autoClearMs);
}
}
// --- Card 1: 模型标识显示 ---
const modelCardTitleEl = h('span', { text: t('settings.oth.modelTitle') });
const modelFormatLabelEl = h('span', {
className: 'form-label',
text: t('settings.oth.modelFormat'),
});
const orchFormatLabelEl = h('span', {
className: 'form-label',
text: t('settings.oth.orchFormat'),
});
const stepModelSelect = CustomSelect({
modelValue: 'short',
icon: 'table',
options: getStepModelDisplayOptions(),
onUpdateModelValue: async (val) => {
const nextUpstream = val === 'upstream';
draftShowUpstreamModel = nextUpstream;
stepModelSelect.setValue(nextUpstream ? 'upstream' : 'short');
showModelFeedback(t('settings.saving'), 0);
try {
await saveSettingsPatch({ showUpstreamModel: nextUpstream });
showModelFeedback(t('settings.saved'), 1500);
} catch {
if (latestSettings) renderSettings(latestSettings);
showModelFeedback(t('settings.saveFailed'), 2500);
}
},
});
const orchestratorIdSelect = CustomSelect({
modelValue: 'compact',
icon: 'layers',
options: getOrchestratorIdDisplayOptions(),
onUpdateModelValue: async (val) => {
const nextMode = normalizeClientOrchestratorIdMode(val);
draftOrchestratorIdMode = nextMode;
orchestratorIdSelect.setValue(nextMode);
showModelFeedback(t('settings.saving'), 0);
try {
await saveSettingsPatch({ orchestratorIdMode: nextMode });
showModelFeedback(t('settings.saved'), 1500);
} catch {
if (latestSettings) renderSettings(latestSettings);
showModelFeedback(t('settings.saveFailed'), 2500);
}
},
});
const modelPanel = h('section', { className: 'panel' }, [
h('div', { className: 'panel-header' }, [
h('span', { className: 'panel-title' }, [
createSvgIcon('sliders', { size: 13 }),
modelCardTitleEl,
]),
modelStatusText,
]),
h('div', { className: 'form-row' }, [modelFormatLabelEl, stepModelSelect.el]),
h('div', { className: 'form-row' }, [orchFormatLabelEl, orchestratorIdSelect.el]),
]);
// --- Card 2: 按模型设置上下文窗口 ---
const baselineTitleEl = h('span', { text: t('settings.oth.baselineTitle') });
const ctxModelLabel = h('span', { className: 'form-label' });
const ctxWindowLabel = h('span', { className: 'form-label' });
const ctxHint = h('span', { className: 'settings-hint-text' });
const ctxStatus = h('span', { className: 'text-muted', role: 'status' });
const ctxModelSelect = CustomSelect({
className: 'settings-context-model',
options: [],
onUpdateModelValue: (id) => {
if (savingContextWindow) return;
contextModelId = id;
contextFeedback = '';
renderContextWindows();
},
});
const ctxWindowSelect = CustomSelect({
options: [],
onUpdateModelValue: async (value) => {
if (savingContextWindow || !contextModelId) return;
savingContextWindow = true;
contextFeedback = 'settings.saving';
renderContextWindows();
try {
const modelContextWindows = await saveModelContextWindow(contextModelId, value || null);
latestSettings = { ...latestSettings, modelContextWindows };
contextFeedback = 'settings.saved';
} catch {
contextFeedback = 'settings.saveFailed';
} finally {
savingContextWindow = false;
renderContextWindows();
}
},
});
const ctxModelRow = h('div', { className: 'form-row' }, [ctxModelLabel, ctxModelSelect.el]);
const ctxWindowRow = h('div', { className: 'form-row' }, [ctxWindowLabel, ctxWindowSelect.el]);
function renderContextWindows() {
const saved = latestSettings?.modelContextWindows || {};
const models = new Map(contextWindowModels.map((model) => [model.id, model]));
const knownIds = new Set(contextWindowModels.flatMap(({ id, members = [] }) => [id, ...members]));
for (const id of Object.keys(saved)) {
if (!knownIds.has(id)) models.set(id, { id, label: id.replace(/^model:/, ''), options: [] });
}
if (!models.has(contextModelId)) contextModelId = '';
const mixed = '\u0000mixed';
const getSelection = ({ id, members = [] }) => {
const legacy = new Set(members.map((member) => saved[member]).filter(Boolean));
return saved[id] || (legacy.size > 1 ? mixed : legacy.values().next().value) || '';
};
const formatLimit = (value) => /^\d+$/.test(value) ? t('settings.oth.ctxTokens', { count: Number(value).toLocaleString() }) : value;
const isAvailable = (model, value) => model.options.some(({ name }) => name === value) ||
(/^[1-9]\d*$/.test(value) && Number(value) <= model.capacity);
const current = models.get(contextModelId);
const options = current?.options || [];
const selected = current ? getSelection(current) : '';
const choices = [
{ value: '', label: t('settings.oth.ctxDefault') },
...options.map(({ name, expensive, tokens }) => ({
value: name,
label: tokens ? formatLimit(name) :
(expensive ? t('settings.oth.ctxExpensive', { name }) : name),
})),
];
if (selected && !choices.some((item) => item.value === selected)) {
let label = t('settings.oth.ctxMixed');
if (selected !== mixed) {
const name = formatLimit(selected);
label = isAvailable(current, selected) ? name : t('settings.oth.ctxUnavailable', { name });
}
choices.push({ value: selected, label, disabled: true });
}
ctxModelSelect.setProps({
modelValue: contextModelId,
options: [
{ value: '', label: t('settings.oth.ctxChooseModel') },
...[...models.values()].map((model) => {
const value = getSelection(model);
let meta = t('settings.oth.ctxDefault');
if (value === mixed) meta = t('settings.oth.ctxMixed');
else if (value) {
const name = formatLimit(value);
if (!isAvailable(model, value)) meta = t('settings.oth.ctxUnavailable', { name });
else if (/^\d+$/.test(value) && model.reportedLimitTokens && Number(value) !== model.reportedLimitTokens) {
meta = t('settings.oth.ctxConfiguredReported', {
name,
reported: formatLimit(String(model.reportedLimitTokens)),
});
} else meta = t('settings.oth.ctxConfigured', { name });
}
else if (model.reportedLimitTokens) meta = t('settings.oth.ctxDefaultReported', { name: formatLimit(String(model.reportedLimitTokens)) });
return { value: model.id, label: model.label, meta };
}),
],
});
ctxWindowSelect.setProps({ modelValue: selected, options: choices });
patchAttr(ctxModelSelect.refs.triggerBtn, 'disabled', savingContextWindow);
patchAttr(ctxWindowSelect.refs.triggerBtn, 'disabled', savingContextWindow || (!options.length && !selected));
patchAttr(ctxModelSelect.refs.triggerBtn, 'aria-label', t('settings.oth.ctxModel'));
patchAttr(ctxWindowSelect.refs.triggerBtn, 'aria-label', t('settings.oth.ctxBaselineLabel'));
patchAttr(ctxModelRow, 'hidden', !models.size);
patchAttr(ctxWindowRow, 'hidden', !contextModelId);
patchText(ctxModelLabel, t('settings.oth.ctxModel'));
patchText(ctxWindowLabel, t('settings.oth.ctxBaselineLabel'));
const hint = !models.size ? 'ctxNoModels' : selected === mixed ? 'ctxMixedHint' :
contextModelId && !options.length ? 'ctxNoOptions' : 'ctxBaselineHint';
const reported = current?.reportedLimitTokens;
patchText(ctxHint, [t(`settings.oth.${hint}`), reported &&
t('settings.oth.ctxReported', { name: formatLimit(String(reported)) })].filter(Boolean).join(' '));
patchText(ctxStatus, contextFeedback ? t(contextFeedback) : '');
getProps().onLayoutChange?.();
}
const baselinePanel = h('section', { className: 'panel' }, [
h('div', { className: 'panel-header' }, [
h('span', { className: 'panel-title' }, [
createSvgIcon('layers', { size: 13 }),
baselineTitleEl,
]),
ctxStatus,
]),
ctxModelRow,
ctxWindowRow,
h('div', { className: 'form-row' }, [ctxHint]),
]);
renderContextWindows();
// --- Card 3: 缓存与重置 ---
const maintTitleEl = h('span', { text: t('settings.oth.maintTitle') });
const cacheLabelEl = h('span', {
className: 'settings-action-title',
text: t('settings.oth.cacheLabel'),
});
const cacheDescEl = h('span', {
className: 'settings-action-desc',
text: t('settings.oth.cacheDesc'),
});
const rebuildBtnText = h('span', { text: t('settings.oth.rebuildBtn') });
const rebuildCacheBtn = h(
'button',
{
type: 'button',
className: 'btn-secondary',
onClick: async () => {
if (isRebuilding) return;
isRebuilding = true;
patchAttr(rebuildCacheBtn, 'disabled', true);
patchText(rebuildBtnText, t('settings.oth.rebuildingBtn'));
showMaintFeedback(t('settings.oth.rebuildingBtn'), 0);
try {
const res = await rebuildTrajectoryCache();
if (res?.ok !== false) {
showMaintFeedback(t('settings.oth.rebuildDone'), 2800);
} else {
showMaintFeedback(t('settings.oth.rebuildFailed'), 3000);
}
} catch {
showMaintFeedback(t('settings.oth.rebuildFailed'), 3000);
} finally {
isRebuilding = false;
patchAttr(rebuildCacheBtn, 'disabled', false);
patchText(rebuildBtnText, t('settings.oth.rebuildBtn'));
}
},
},
[createSvgIcon('refresh', { size: 12 }), rebuildBtnText]
);
const resetLabelEl = h('span', {
className: 'settings-action-title',
text: t('settings.oth.resetLabel'),
});
const resetDescEl = h('span', {
className: 'settings-action-desc',
text: t('settings.oth.resetDesc'),
});
const resetBtnText = h('span', { text: t('settings.oth.resetAllBtn') });
function disarmResetConfirm() {
resetConfirmArmed = false;
if (resetConfirmTimer) {
clearTimeout(resetConfirmTimer);
resetConfirmTimer = null;
}
patchClasses(resetAllBtn, { 'btn-danger-confirm': false });
if (!isResetting) {
patchText(resetBtnText, t('settings.oth.resetAllBtn'));
}
}
const resetAllBtn = h(
'button',
{
type: 'button',
className: 'btn-secondary',
onClick: async () => {
if (isResetting) return;
if (!resetConfirmArmed) {
resetConfirmArmed = true;
patchClasses(resetAllBtn, { 'btn-danger-confirm': true });
patchText(resetBtnText, t('settings.oth.resetConfirmBtn'));
if (resetConfirmTimer) clearTimeout(resetConfirmTimer);
resetConfirmTimer = setTimeout(() => {
disarmResetConfirm();
}, 3000);
return;
}
disarmResetConfirm();
isResetting = true;
patchAttr(resetAllBtn, 'disabled', true);
patchText(resetBtnText, t('settings.oth.resettingBtn'));
showMaintFeedback(t('settings.oth.resettingBtn'), 0);
try {
const res = await resetAllSettings();
setI18nLanguage(res?.settings?.language || 'zh-CN');
showMaintFeedback(t('settings.oth.resetAllDone'), 2800);
} catch {
showMaintFeedback(t('settings.saveFailed'), 2800);
} finally {
isResetting = false;
patchAttr(resetAllBtn, 'disabled', false);
patchText(resetBtnText, t('settings.oth.resetAllBtn'));
}
},
},
[resetBtnText]
);
const maintPanel = h('section', { className: 'panel' }, [
h('div', { className: 'panel-header' }, [
h('span', { className: 'panel-title' }, [
createSvgIcon('refresh', { size: 13 }),
maintTitleEl,
]),
maintStatusText,
]),
h('div', { className: 'settings-action-block' }, [
h('div', { className: 'settings-action-info' }, [cacheLabelEl, cacheDescEl]),
rebuildCacheBtn,
]),
h('div', { className: 'settings-action-block' }, [
h('div', { className: 'settings-action-info' }, [resetLabelEl, resetDescEl]),
resetAllBtn,
]),
]);
const rootEl = h('div', { className: 'settings-tab-stack' }, [
modelPanel,
baselinePanel,
maintPanel,
]);
function renderSettings(settings, models = contextWindowModels) {
if (!settings) return;
latestSettings = settings;
contextWindowModels = models;
draftShowUpstreamModel = Boolean(settings.showUpstreamModel);
draftOrchestratorIdMode = normalizeClientOrchestratorIdMode(settings.orchestratorIdMode);
stepModelSelect.setProps({
modelValue: draftShowUpstreamModel ? 'upstream' : 'short',
options: getStepModelDisplayOptions(),
});
orchestratorIdSelect.setProps({
modelValue: draftOrchestratorIdMode,
options: getOrchestratorIdDisplayOptions(),
});
renderContextWindows();
}
function refreshLabels() {
patchText(modelCardTitleEl, t('settings.oth.modelTitle'));
patchText(modelFormatLabelEl, t('settings.oth.modelFormat'));
patchText(orchFormatLabelEl, t('settings.oth.orchFormat'));
patchText(baselineTitleEl, t('settings.oth.baselineTitle'));
renderContextWindows();
patchText(maintTitleEl, t('settings.oth.maintTitle'));
patchText(cacheLabelEl, t('settings.oth.cacheLabel'));
patchText(cacheDescEl, t('settings.oth.cacheDesc'));
patchText(resetLabelEl, t('settings.oth.resetLabel'));
patchText(resetDescEl, t('settings.oth.resetDesc'));
if (!isRebuilding) {
patchText(rebuildBtnText, t('settings.oth.rebuildBtn'));
}
if (!isResetting) {
patchText(
resetBtnText,
resetConfirmArmed ? t('settings.oth.resetConfirmBtn') : t('settings.oth.resetAllBtn')
);
}
stepModelSelect.setProps({
modelValue: draftShowUpstreamModel ? 'upstream' : 'short',
options: getStepModelDisplayOptions(),
});
orchestratorIdSelect.setProps({
modelValue: draftOrchestratorIdMode,
options: getOrchestratorIdDisplayOptions(),
});
}
onCleanup(() => {
if (modelTimer) clearTimeout(modelTimer);
if (maintTimer) clearTimeout(maintTimer);
if (resetConfirmTimer) clearTimeout(resetConfirmTimer);
stepModelSelect.destroy();
orchestratorIdSelect.destroy();
ctxModelSelect.destroy();
ctxWindowSelect.destroy();
});
return {
el: rootEl,
refs: {
stepModelSelect,
orchestratorIdSelect,
ctxModelSelect,
ctxWindowSelect,
rebuildCacheBtn,
resetAllBtn,
renderSettings,
refreshLabels,
},
};
},
});
@@ -0,0 +1,507 @@
/**
* @fileoverview Preferences Tab 2: `SettingsStructureTab.js` ("结构").
* Provides 4 collapsible customization sections with `+` / `-` / `↑` / `↓`:
* 1. 挂载与胶囊栏 (`windowMountMode`, `showTopbarMultiSession`, `topbarCapsuleSlots` 1..5)
* 2. 鼠标悬浮窗 (`hoverModules` 0..4)
* 3. 实时监控布局 (`overviewModules` 1..4 + `overviewMetrics` 1..4)
* 4. 调用明细字段 (`stepTableColumns` 2..12)
*/
import { defineComponent } from '../../core/component.js';
import { h, patchAttr, patchText } from '../../core/domPatch.js';
import { t } from '../../i18n/index.js';
import {
getCapsuleMetricOptions,
getOverviewMetricOptions,
} from '../../registries/metricRegistry.js';
import { getStepColumnOptions } from '../../registries/stepColumnRegistry.js';
import { getOverviewModuleOptions } from '../../registries/widgetRegistry.js';
import {
DEFAULT_CLIENT_HOVER_MODULES,
DEFAULT_CLIENT_OVERVIEW_METRICS,
DEFAULT_CLIENT_OVERVIEW_MODULES,
DEFAULT_CLIENT_STEP_COLUMNS,
DEFAULT_CLIENT_TOPBAR_SLOTS,
normalizeClientHoverModules,
normalizeClientOverviewMetrics,
normalizeClientOverviewModules,
normalizeClientStepColumns,
normalizeClientTopbarSlots,
normalizeClientWindowMountMode,
saveSettingsPatch,
} from '../../store/telemetryStore.js';
import { CollapsibleSection } from '../../components/settings/CollapsibleSection.js';
import { EditableSlotList } from '../../components/settings/EditableSlotList.js';
import { CustomSelect } from '../../components/ui/CustomSelect.js';
import { SegmentedControl } from '../../components/ui/SegmentedControl.js';
function getMountModeOptions() {
return [
{ value: 'dual', label: t('settings.str.mountDual') },
{ value: 'composer', label: t('settings.str.mountComposer') },
{ value: 'sidebar', label: t('settings.str.mountSidebar') },
];
}
function getMultiToggleOptions() {
return [
{ value: 'show', label: t('settings.str.show') },
{ value: 'hide', label: t('settings.str.hide') },
];
}
function isSameList(a, b) {
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
for (let i = 0; i < a.length; i += 1) {
if (a[i] !== b[i]) return false;
}
return true;
}
export const SettingsStructureTab = defineComponent({
name: 'SettingsStructureTab',
setup({ props, onCleanup }) {
let draftWindowMountMode = 'dual';
let draftShowTopbarMulti = true;
let draftTopbarSlots = [...DEFAULT_CLIENT_TOPBAR_SLOTS];
let draftHoverModules = [...DEFAULT_CLIENT_HOVER_MODULES];
let draftOverviewModules = [...DEFAULT_CLIENT_OVERVIEW_MODULES];
let draftOverviewMetrics = [...DEFAULT_CLIENT_OVERVIEW_METRICS];
let draftStepColumns = [...DEFAULT_CLIENT_STEP_COLUMNS];
let latestSettings = null;
async function persistStructurePatch(sectionComp, patchObj, successKey = 'settings.saved') {
sectionComp.refs.showStatus(t('settings.saving'), 0);
try {
await saveSettingsPatch(patchObj);
sectionComp.refs.showStatus(t(successKey), 1500);
} catch {
if (latestSettings) {
renderSettings(latestSettings);
}
sectionComp.refs.showStatus(t('settings.saveFailed'), 2500);
}
}
// --- Section 1: 挂载与胶囊栏 (defaultExpanded: true) ---
const mountModeLabelEl = h('span', {
className: 'form-label',
text: t('settings.str.mountMode'),
});
const multiToggleLabelEl = h('span', {
className: 'form-label',
text: t('settings.str.multiToggle'),
});
const capsuleSlotsLabelEl = h('span', {
className: 'form-label',
text: t('settings.str.capsuleSlotsLabel'),
});
const windowMountSelect = CustomSelect({
modelValue: draftWindowMountMode,
icon: 'dock',
options: getMountModeOptions(),
onUpdateModelValue: (val) => {
const nextMode = normalizeClientWindowMountMode(val);
draftWindowMountMode = nextMode;
syncMountSectionMeta();
void persistStructurePatch(mountSection, {
windowMountMode: nextMode,
enableWindowOverlay: nextMode !== 'sidebar',
});
},
});
const multiSessionToggle = SegmentedControl({
ariaLabel: t('settings.str.multiToggle'),
modelValue: 'show',
options: getMultiToggleOptions(),
onUpdateModelValue: (val) => {
draftShowTopbarMulti = val !== 'hide';
syncMountSectionMeta();
void persistStructurePatch(mountSection, {
showTopbarMultiSession: draftShowTopbarMulti,
});
},
});
const topbarSlotsList = EditableSlotList({
items: draftTopbarSlots,
options: getCapsuleMetricOptions(),
minItems: 1,
maxItems: 5,
addBtnTextFn: (count, max) => t('settings.str.addCapsuleSlot', { count, max }),
onChange: (nextItems) => {
draftTopbarSlots = normalizeClientTopbarSlots(nextItems);
syncMountSectionMeta();
props.onLayoutChange?.();
void persistStructurePatch(mountSection, {
topbarCapsuleSlots: draftTopbarSlots,
});
},
});
const mountSection = CollapsibleSection({
icon: 'dock',
title: t('settings.str.mountSection'),
badgeText: t('settings.str.mountBadge', { count: draftTopbarSlots.length }),
defaultExpanded: true,
onToggle: () => props.onLayoutChange?.(),
onReset: () => {
draftWindowMountMode = 'dual';
draftShowTopbarMulti = true;
draftTopbarSlots = [...DEFAULT_CLIENT_TOPBAR_SLOTS];
syncMountSectionMeta();
props.onLayoutChange?.();
void persistStructurePatch(
mountSection,
{
windowMountMode: 'dual',
enableWindowOverlay: true,
showTopbarMultiSession: true,
topbarCapsuleSlots: [...DEFAULT_CLIENT_TOPBAR_SLOTS],
},
'settings.resetDone'
);
},
children: [
h('div', { className: 'form-row' }, [mountModeLabelEl, windowMountSelect.el]),
h('div', { className: 'settings-inline-row' }, [
multiToggleLabelEl,
multiSessionToggle.el,
]),
h('div', { className: 'form-row' }, [capsuleSlotsLabelEl, topbarSlotsList.el]),
],
});
function syncMountSectionMeta() {
windowMountSelect.setProps({
modelValue: draftWindowMountMode,
options: getMountModeOptions(),
});
multiSessionToggle.setProps({
modelValue: draftShowTopbarMulti ? 'show' : 'hide',
options: getMultiToggleOptions(),
});
topbarSlotsList.refs.setProps({
items: draftTopbarSlots,
options: getCapsuleMetricOptions(),
addBtnTextFn: (count, max) => t('settings.str.addCapsuleSlot', { count, max }),
});
mountSection.refs.setBadge(
t('settings.str.mountBadge', { count: draftTopbarSlots.length })
);
const isDefault =
draftWindowMountMode === 'dual' &&
draftShowTopbarMulti === true &&
isSameList(draftTopbarSlots, DEFAULT_CLIENT_TOPBAR_SLOTS);
mountSection.refs.setResetDisabled(isDefault);
}
// --- Section 2: 鼠标悬浮窗 (0..4 items) ---
const hoverModulesLabelEl = h('span', {
className: 'form-label',
text: t('settings.str.hoverModulesLabel'),
});
const hoverModulesList = EditableSlotList({
items: draftHoverModules,
options: getOverviewModuleOptions(),
minItems: 0,
maxItems: 4,
emptyHintText: t('settings.str.hoverEmptyHint'),
addBtnTextFn: (count, max) => t('settings.str.addHoverModule', { count, max }),
onChange: (nextItems) => {
draftHoverModules = normalizeClientHoverModules(nextItems);
syncHoverSectionMeta();
props.onLayoutChange?.();
void persistStructurePatch(hoverSection, {
hoverModules: draftHoverModules,
});
},
});
const hoverSection = CollapsibleSection({
icon: 'layers',
title: t('settings.str.hoverSection'),
badgeText: t('settings.str.hoverBadgeCount', { count: draftHoverModules.length }),
defaultExpanded: false,
onToggle: () => props.onLayoutChange?.(),
onReset: () => {
draftHoverModules = [...DEFAULT_CLIENT_HOVER_MODULES];
syncHoverSectionMeta();
props.onLayoutChange?.();
void persistStructurePatch(
hoverSection,
{ hoverModules: [...DEFAULT_CLIENT_HOVER_MODULES] },
'settings.resetDone'
);
},
children: [h('div', { className: 'form-row' }, [hoverModulesLabelEl, hoverModulesList.el])],
});
function syncHoverSectionMeta() {
hoverModulesList.refs.setProps({
items: draftHoverModules,
options: getOverviewModuleOptions(),
emptyHintText: t('settings.str.hoverEmptyHint'),
addBtnTextFn: (count, max) => t('settings.str.addHoverModule', { count, max }),
});
hoverSection.refs.setBadge(
draftHoverModules.length === 0
? t('settings.str.hoverBadgeOff')
: t('settings.str.hoverBadgeCount', { count: draftHoverModules.length })
);
hoverSection.refs.setResetDisabled(isSameList(draftHoverModules, DEFAULT_CLIENT_HOVER_MODULES));
}
// --- Section 3: 实时监控布局 (Modules 1..4 + First-Row Metrics 1..4) ---
const overviewModulesLabelEl = h('span', {
className: 'form-label',
text: t('settings.str.overviewModulesLabel'),
});
const overviewMetricsLabelEl = h('span', {
className: 'form-label',
text: t('settings.str.overviewMetricsLabel'),
});
const overviewMetricsHintEl = h('span', {
className: 'settings-hint-text',
hidden: true,
text: t('settings.str.overviewMetricsInactiveHint'),
});
const overviewModulesList = EditableSlotList({
items: draftOverviewModules,
options: getOverviewModuleOptions(),
minItems: 1,
maxItems: 4,
addBtnTextFn: (count, max) => t('settings.str.addOverviewModule', { count, max }),
onChange: (nextItems) => {
draftOverviewModules = normalizeClientOverviewModules(nextItems);
syncOverviewSectionMeta();
props.onLayoutChange?.();
void persistStructurePatch(overviewSection, {
overviewModules: draftOverviewModules,
});
},
});
const overviewMetricsList = EditableSlotList({
items: draftOverviewMetrics,
options: getOverviewMetricOptions(),
minItems: 1,
maxItems: 4,
addBtnTextFn: (count, max) => t('settings.str.addOverviewMetric', { count, max }),
onChange: (nextItems) => {
draftOverviewMetrics = normalizeClientOverviewMetrics(nextItems);
syncOverviewSectionMeta();
props.onLayoutChange?.();
void persistStructurePatch(overviewSection, {
overviewMetrics: draftOverviewMetrics,
});
},
});
const overviewSection = CollapsibleSection({
icon: 'pulse',
title: t('settings.str.overviewSection'),
badgeText: t('settings.str.overviewBadge', {
modCount: draftOverviewModules.length,
metCount: draftOverviewMetrics.length,
}),
defaultExpanded: false,
onToggle: () => props.onLayoutChange?.(),
onReset: () => {
draftOverviewModules = [...DEFAULT_CLIENT_OVERVIEW_MODULES];
draftOverviewMetrics = [...DEFAULT_CLIENT_OVERVIEW_METRICS];
syncOverviewSectionMeta();
props.onLayoutChange?.();
void persistStructurePatch(
overviewSection,
{
overviewModules: [...DEFAULT_CLIENT_OVERVIEW_MODULES],
overviewMetrics: [...DEFAULT_CLIENT_OVERVIEW_METRICS],
},
'settings.resetDone'
);
},
children: [
h('div', { className: 'form-row' }, [overviewModulesLabelEl, overviewModulesList.el]),
h('div', { className: 'settings-divider' }),
h('div', { className: 'form-row' }, [
overviewMetricsLabelEl,
overviewMetricsHintEl,
overviewMetricsList.el,
]),
],
});
function syncOverviewSectionMeta() {
overviewModulesList.refs.setProps({
items: draftOverviewModules,
options: getOverviewModuleOptions(),
addBtnTextFn: (count, max) => t('settings.str.addOverviewModule', { count, max }),
});
overviewMetricsList.refs.setProps({
items: draftOverviewMetrics,
options: getOverviewMetricOptions(),
addBtnTextFn: (count, max) => t('settings.str.addOverviewMetric', { count, max }),
});
const metricsModuleActive = draftOverviewModules.includes('metrics');
patchAttr(overviewMetricsHintEl, 'hidden', metricsModuleActive);
overviewSection.refs.setBadge(
t('settings.str.overviewBadge', {
modCount: draftOverviewModules.length,
metCount: draftOverviewMetrics.length,
})
);
const isDefault =
isSameList(draftOverviewModules, DEFAULT_CLIENT_OVERVIEW_MODULES) &&
isSameList(draftOverviewMetrics, DEFAULT_CLIENT_OVERVIEW_METRICS);
overviewSection.refs.setResetDisabled(isDefault);
}
// --- Section 4: 调用明细字段 (Step Table Columns 2..12) ---
const stepColsLabelEl = h('span', {
className: 'form-label',
text: t('settings.str.stepsColsLabel'),
});
const stepColumnsList = EditableSlotList({
items: draftStepColumns,
options: getStepColumnOptions(),
minItems: 2,
maxItems: 12,
addBtnTextFn: (count, max) => t('settings.str.addStepCol', { count, max }),
onChange: (nextItems) => {
draftStepColumns = normalizeClientStepColumns(nextItems);
syncStepsSectionMeta();
props.onLayoutChange?.();
void persistStructurePatch(stepsSection, {
stepTableColumns: draftStepColumns,
});
},
});
const stepsSection = CollapsibleSection({
icon: 'table',
title: t('settings.str.stepsSection'),
badgeText: t('settings.str.stepsBadge', { count: draftStepColumns.length }),
defaultExpanded: false,
onToggle: () => props.onLayoutChange?.(),
onReset: () => {
draftStepColumns = [...DEFAULT_CLIENT_STEP_COLUMNS];
syncStepsSectionMeta();
props.onLayoutChange?.();
void persistStructurePatch(
stepsSection,
{ stepTableColumns: [...DEFAULT_CLIENT_STEP_COLUMNS] },
'settings.resetDone'
);
},
children: [h('div', { className: 'form-row' }, [stepColsLabelEl, stepColumnsList.el])],
});
function syncStepsSectionMeta() {
stepColumnsList.refs.setProps({
items: draftStepColumns,
options: getStepColumnOptions(),
addBtnTextFn: (count, max) => t('settings.str.addStepCol', { count, max }),
});
stepsSection.refs.setBadge(t('settings.str.stepsBadge', { count: draftStepColumns.length }));
stepsSection.refs.setResetDisabled(isSameList(draftStepColumns, DEFAULT_CLIENT_STEP_COLUMNS));
}
const rootEl = h('div', { className: 'settings-tab-stack' }, [
mountSection.el,
hoverSection.el,
overviewSection.el,
stepsSection.el,
]);
function renderSettings(settings) {
if (!settings) return;
latestSettings = settings;
draftWindowMountMode = normalizeClientWindowMountMode(
settings.windowMountMode,
settings.enableWindowOverlay
);
draftShowTopbarMulti = settings.showTopbarMultiSession !== false;
draftTopbarSlots = normalizeClientTopbarSlots(settings.topbarCapsuleSlots);
draftHoverModules = normalizeClientHoverModules(settings.hoverModules);
draftOverviewModules = normalizeClientOverviewModules(settings.overviewModules);
draftOverviewMetrics = normalizeClientOverviewMetrics(settings.overviewMetrics);
draftStepColumns = normalizeClientStepColumns(settings.stepTableColumns);
syncMountSectionMeta();
syncHoverSectionMeta();
syncOverviewSectionMeta();
syncStepsSectionMeta();
}
function refreshLabels() {
mountSection.refs.setTitle(t('settings.str.mountSection'));
mountSection.refs.setResetLabel(t('settings.resetBtn'));
patchText(mountModeLabelEl, t('settings.str.mountMode'));
patchText(multiToggleLabelEl, t('settings.str.multiToggle'));
patchText(capsuleSlotsLabelEl, t('settings.str.capsuleSlotsLabel'));
hoverSection.refs.setTitle(t('settings.str.hoverSection'));
hoverSection.refs.setResetLabel(t('settings.resetBtn'));
patchText(hoverModulesLabelEl, t('settings.str.hoverModulesLabel'));
overviewSection.refs.setTitle(t('settings.str.overviewSection'));
overviewSection.refs.setResetLabel(t('settings.resetBtn'));
patchText(overviewModulesLabelEl, t('settings.str.overviewModulesLabel'));
patchText(overviewMetricsLabelEl, t('settings.str.overviewMetricsLabel'));
patchText(overviewMetricsHintEl, t('settings.str.overviewMetricsInactiveHint'));
stepsSection.refs.setTitle(t('settings.str.stepsSection'));
stepsSection.refs.setResetLabel(t('settings.resetBtn'));
patchText(stepColsLabelEl, t('settings.str.stepsColsLabel'));
syncMountSectionMeta();
syncHoverSectionMeta();
syncOverviewSectionMeta();
syncStepsSectionMeta();
}
syncMountSectionMeta();
syncHoverSectionMeta();
syncOverviewSectionMeta();
syncStepsSectionMeta();
onCleanup(() => {
windowMountSelect.destroy();
multiSessionToggle.destroy();
topbarSlotsList.destroy();
hoverModulesList.destroy();
overviewModulesList.destroy();
overviewMetricsList.destroy();
stepColumnsList.destroy();
mountSection.destroy();
hoverSection.destroy();
overviewSection.destroy();
stepsSection.destroy();
});
return {
el: rootEl,
refs: {
windowMountSelect,
multiSessionToggle,
topbarSlotsList,
hoverModulesList,
overviewModulesList,
overviewMetricsList,
stepColumnsList,
mountSection,
hoverSection,
overviewSection,
stepsSection,
renderSettings,
refreshLabels,
},
};
},
});