perf(panel): optimize P1 hot paths and consolidate P2 shared primitives

This commit is contained in:
fish
2026-11-23 16:21:39 +09:00
parent 3a40bacc9d
commit 424ac73489
48 changed files with 4040 additions and 2745 deletions
@@ -823,7 +823,14 @@ export function createSessionLineChart() {
let hoveredIdx = -1;
let tickElsByIdx = new Map();
let lastSig = '';
let lastPreSig = '';
let lastSummaryBadge = '';
let lastUpdateParams = null;
let cachedPlotSvgRect = null;
function invalidatePlotSvgRect() {
cachedPlotSvgRect = null;
}
function syncViewWidth() {
const measured = Math.round(
@@ -936,8 +943,14 @@ export function createSessionLineChart() {
plotStage.addEventListener('mousemove', (e) => {
if (!currentPoints.length) return;
const rect = svg.getBoundingClientRect();
if (!rect || rect.width <= 0) return;
if (!cachedPlotSvgRect) {
cachedPlotSvgRect = svg.getBoundingClientRect();
}
const rect = cachedPlotSvgRect;
if (!rect || rect.width <= 0) {
cachedPlotSvgRect = null;
return;
}
const relX = ((e.clientX - rect.left) / rect.width) * viewW;
const { leftX, spanX } = resolvePlotBounds(viewW);
const ratio = (relX - leftX) / Math.max(1, spanX);
@@ -947,14 +960,19 @@ export function createSessionLineChart() {
);
showHoverAt(idx);
});
plotStage.addEventListener('mouseleave', clearHover);
plotStage.addEventListener('mouseleave', () => {
invalidatePlotSvgRect();
clearHover();
});
let resizeObs = null;
let onWinResize = null;
if (typeof ResizeObserver === 'function') {
resizeObs = new ResizeObserver(() => {
invalidatePlotSvgRect();
if (syncViewWidth() && lastUpdateParams) {
lastSig = '';
lastPreSig = '';
update(lastUpdateParams);
}
});
@@ -1035,6 +1053,9 @@ export function createSessionLineChart() {
if (!matchedSteps.length) {
currentPoints = [];
lastSig = 'empty';
lastPreSig = '';
lastSummaryBadge = t('chart.step.zeroSteps');
invalidatePlotSvgRect();
patchAttr(areaPath, 'd', '');
patchAttr(linePath, 'd', '');
while (multiAreaGroup.firstChild) multiAreaGroup.removeChild(multiAreaGroup.firstChild);
@@ -1046,7 +1067,23 @@ export function createSessionLineChart() {
patchAttr(peakPill, 'hidden', true);
patchAttr(emptyHintEl, 'hidden', false);
clearHover();
return { summaryBadge: t('chart.step.zeroSteps') };
return { summaryBadge: lastSummaryBadge };
}
const locale = getEffectiveLocale();
const extColorSig = modelColorByGroup
? Array.from(modelColorByGroup.entries())
.map(([k, v]) => `${k}=${v}`)
.join(',')
: '';
let preStepParts = `${matchedSteps.length}:`;
for (let i = 0; i < matchedSteps.length; i += 1) {
const s = matchedSteps[i];
preStepParts += `${s.stepIndex ?? i},${s.agentIndex ?? 0},${s.modelKey || s.modelShort || ''},${s.inputTokens || 0},${s.cacheReadTokens || 0},${s.outputTokens || 0},${s.contextTokens || 0},${s.tokPerSec ?? ''},${s.ttftSec ?? ''},${s.costUsd ?? ''},${s.anomalySig || ''};`;
}
const preSig = `${locale}|${viewW}|${metric}|${showAgentPrefix}|${displaySettings?.modelDisplayMode || ''}|${Boolean(displaySettings?.showUpstreamModel)}|${displaySettings?.orchestratorIdMode || ''}|${targetKeys.join(',')}|${extColorSig}|${preStepParts}`;
if (preSig === lastPreSig && lastSummaryBadge) {
return { summaryBadge: lastSummaryBadge };
}
const modelColorMap = new Map();
@@ -1254,7 +1291,6 @@ export function createSessionLineChart() {
const validPoints = points.filter((p) => p.valid);
patchAttr(emptyHintEl, 'hidden', validPoints.length > 0);
const locale = getEffectiveLocale();
const colorSig = Array.from(modelColorMap.entries())
.map(([k, v]) => `${k}=${v}`)
.join(',');
@@ -1500,6 +1536,8 @@ export function createSessionLineChart() {
});
}
lastPreSig = preSig;
lastSummaryBadge = summaryBadge;
return { summaryBadge };
}
@@ -1764,10 +1802,17 @@ export function createModelFitChart() {
patchClasses(tooltipEl, { 'is-tracking': false });
}
let cachedFitSvgRect = null;
plotStage.addEventListener('mousemove', (e) => {
if (!currentSamples.length) return;
const rect = svg.getBoundingClientRect();
if (!rect || rect.width <= 0) return;
if (!cachedFitSvgRect) {
cachedFitSvgRect = svg.getBoundingClientRect();
}
const rect = cachedFitSvgRect;
if (!rect || rect.width <= 0) {
cachedFitSvgRect = null;
return;
}
const relX = ((e.clientX - rect.left) / rect.width) * viewW;
let lo = 0;
let hi = currentSamples.length - 1;
@@ -1785,12 +1830,16 @@ export function createModelFitChart() {
}
showHoverAt(bestIdx);
});
plotStage.addEventListener('mouseleave', clearHover);
plotStage.addEventListener('mouseleave', () => {
cachedFitSvgRect = null;
clearHover();
});
let resizeObs = null;
let onWinResize = null;
if (typeof ResizeObserver === 'function') {
resizeObs = new ResizeObserver(() => {
cachedFitSvgRect = null;
if (syncViewWidth() && lastUpdateParams) {
lastSig = '';
update(lastUpdateParams);
@@ -427,8 +427,27 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
});
}
let cachedWrapRect = null;
let cachedSvgRect = null;
let cachedHmGridRect = null;
let cachedClipRect = undefined;
function invalidateHoverRects() {
cachedWrapRect = null;
cachedSvgRect = null;
cachedHmGridRect = null;
cachedClipRect = undefined;
}
function getCachedWrapRect() {
if (!cachedWrapRect) {
cachedWrapRect = chartWrap.getBoundingClientRect?.() || null;
}
return cachedWrapRect;
}
function positionTooltipNearAnchor(fallbackX, fallbackY, pointer = null) {
const wrapRect = chartWrap.getBoundingClientRect?.() || null;
const wrapRect = getCachedWrapRect();
const wrapW =
wrapRect && wrapRect.width > 0
? wrapRect.width
@@ -438,13 +457,8 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
? wrapRect.height
: Number(chartWrap.offsetHeight || VIEW_H);
const tipRect = tooltipEl.getBoundingClientRect?.() || null;
const tipW =
Number(tooltipEl.offsetWidth || 0) ||
(tipRect && tipRect.width > 0 ? tipRect.width : 216);
const tipH =
Number(tooltipEl.offsetHeight || 0) ||
(tipRect && tipRect.height > 0 ? tipRect.height : 104);
const tipW = Number(tooltipEl.offsetWidth || 0) || 216;
const tipH = Number(tooltipEl.offsetHeight || 0) || 104;
const hasPointer =
pointer &&
@@ -457,8 +471,11 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
const anchorX = hasPointer ? Number(pointer.clientX) - wrapRect.left : fallbackX;
const anchorY = hasPointer ? Number(pointer.clientY) - wrapRect.top : fallbackY;
const clipEl = chartWrap.closest?.('.view-pane, .cons-view-stage') || null;
const clipRect = clipEl?.getBoundingClientRect?.() || null;
if (cachedClipRect === undefined) {
const clipEl = chartWrap.closest?.('.view-pane, .cons-view-stage') || null;
cachedClipRect = clipEl?.getBoundingClientRect?.() || null;
}
const clipRect = cachedClipRect;
const hasClip = Boolean(
clipRect && clipRect.height > 0 && wrapRect && wrapRect.height > 0
);
@@ -524,7 +541,7 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
}
}
const wrapRect = chartWrap.getBoundingClientRect?.() || null;
const wrapRect = getCachedWrapRect();
const wrapW =
wrapRect && wrapRect.width > 0
? wrapRect.width
@@ -571,7 +588,7 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
populateTooltipContent(slot);
}
const wrapRect = chartWrap.getBoundingClientRect?.() || null;
const wrapRect = getCachedWrapRect();
const cellRect = targetCell.getBoundingClientRect?.() || null;
const wrapW =
wrapRect && wrapRect.width > 0
@@ -596,6 +613,7 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
}
function clearHover() {
invalidateHoverRects();
cancelTipTrackRaf();
hoveredIdx = -1;
lastPointer = null;
@@ -642,8 +660,14 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
function handlePointerMove(e) {
if (currentIsHeatmap || !currentSlots.length) return;
const rect = svg.getBoundingClientRect();
if (!rect || rect.width <= 0) return;
if (!cachedSvgRect) {
cachedSvgRect = svg.getBoundingClientRect();
}
const rect = cachedSvgRect;
if (!rect || rect.width <= 0) {
cachedSvgRect = null;
return;
}
const relX = ((e.clientX - rect.left) / rect.width) * viewW;
const { leftX, spanX } = resolvePlotBounds(viewW);
const ratio = (relX - leftX) / Math.max(1, spanX);
@@ -686,8 +710,12 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
return null;
}
const rect = hmGridEl.getBoundingClientRect?.();
if (!cachedHmGridRect) {
cachedHmGridRect = hmGridEl.getBoundingClientRect?.() || null;
}
const rect = cachedHmGridRect;
if (!rect || !(rect.width > 0) || !(rect.height > 0) || currentHeatmapWeeks <= 0) {
cachedHmGridRect = null;
if (hoveredIdx >= 0 && hoveredIdx < currentSlots.length && currentCellEls[hoveredIdx]) {
return { idx: hoveredIdx, cellEl: currentCellEls[hoveredIdx] };
}
@@ -842,6 +870,7 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) {
let onWinResize = null;
if (typeof ResizeObserver === 'function') {
resizeObs = new ResizeObserver(() => {
invalidateHoverRects();
if (!currentIsHeatmap && syncViewWidth() && currentSlots.length > 0) {
lastRenderSig = '';
update(currentSlots);
@@ -932,6 +932,51 @@ function getLeftSidebarRightEdge(vw) {
/**
* 在主窗口挂载双栖顶栏胶囊与完整四标签悬浮面板,并注册 `window.__AGUsageMonitorOverlay` 生命周期句柄。
*/
const CAPSULE_EXCLUDED_CSS_SECTIONS = new Set([
'src/styles/views-overview.css',
'src/styles/views-consumption.css',
'src/styles/views-tables.css',
'src/styles/views-settings.css',
'src/styles/controls.css',
]);
let sharedOverlayStyleSheetMemo = { rawCss: '', sheet: null };
function buildSlimCapsuleCss(fullCss) {
if (!fullCss || !fullCss.includes('/* --- src/styles/')) return fullCss;
return fullCss
.split(/(?=\/\* --- src\/styles\/)/)
.filter((block) => {
const m = block.match(/^\/\* --- (src\/styles\/[^\s]+) --- \*\//);
return !m || !CAPSULE_EXCLUDED_CSS_SECTIONS.has(m[1]);
})
.join('');
}
function attachShadowStyles(shadowRoot, fullCss, { slimCapsule = false } = {}) {
if (!shadowRoot) return;
if (
fullCss &&
typeof CSSStyleSheet === 'function' &&
Array.isArray(shadowRoot.adoptedStyleSheets)
) {
try {
if (sharedOverlayStyleSheetMemo.rawCss !== fullCss || !sharedOverlayStyleSheetMemo.sheet) {
const sheet = new CSSStyleSheet();
sheet.replaceSync(fullCss);
sharedOverlayStyleSheetMemo = { rawCss: fullCss, sheet };
}
shadowRoot.adoptedStyleSheets = [sharedOverlayStyleSheetMemo.sheet];
return;
} catch {
// 降级到传统 <style> 节点
}
}
const styleEl = document.createElement('style');
styleEl.textContent = slimCapsule ? buildSlimCapsuleCss(fullCss) : fullCss;
shadowRoot.appendChild(styleEl);
}
export function mountWindowOverlay() {
if (typeof window === 'undefined' || typeof document === 'undefined') return null;
@@ -1123,10 +1168,7 @@ export function mountWindowOverlay() {
}
});
const capsuleShadow = capsuleHost.attachShadow({ mode: 'open' });
const capsuleStyleEl = document.createElement('style');
capsuleStyleEl.textContent = stylesCss;
capsuleShadow.appendChild(capsuleStyleEl);
attachShadowStyles(capsuleShadow, stylesCss, { slimCapsule: true });
// 左侧无边框多会话实时触发按钮(固定预占宽度,不随运行数跳动)
const multiDot = h('span', { className: 'wm-multi-dot' });
@@ -1346,10 +1388,7 @@ export function mountWindowOverlay() {
portalHost.id = PORTAL_HOST_ID;
portalHost.className = 'wm-portal-host';
const portalShadow = portalHost.attachShadow({ mode: 'open' });
const portalStyleEl = document.createElement('style');
portalStyleEl.textContent = stylesCss;
portalShadow.appendChild(portalStyleEl);
attachShadowStyles(portalShadow, stylesCss, { slimCapsule: false });
const initialSettings = telemetryStore.getState().telemetry?.settings;
@@ -1460,9 +1499,9 @@ export function mountWindowOverlay() {
[multiHeaderEl, multiEmptyEl, multiRunningWidget.el]
);
// 完整四标签悬浮容器
// 完整四标签悬浮容器(首次打开主弹窗时按需懒挂载 App,彻底消除宿主窗口冷启动开销)
uiStore.setState({ monitorVisible: false });
const appInstance = App();
let appInstance = null;
const popoverEl = h(
'div',
{
@@ -1471,9 +1510,17 @@ export function mountWindowOverlay() {
'aria-label': t('capsule.ariaMonitor'),
hidden: true,
},
[appInstance.el]
[]
);
function ensureAppMounted() {
if (!appInstance) {
appInstance = App();
popoverEl.appendChild(appInstance.el);
}
return appInstance;
}
function syncPortalAppearance(settings) {
applyAppearanceToRoot(capsuleHost, settings, { includeFontScale: false });
applyAppearanceToRoot(portalHost, settings, { includeFontScale: true });
@@ -2218,6 +2265,7 @@ export function mountWindowOverlay() {
}
function refreshActiveViewScrollbars() {
if (!appInstance) return;
const activeView = uiStore.getState().activeView;
const refs = appInstance.refs;
if (activeView === 'overview') {
@@ -2315,6 +2363,9 @@ export function mountWindowOverlay() {
}
if (popoverOpen === targetOpen) return;
popoverOpen = targetOpen;
if (popoverOpen) {
ensureAppMounted();
}
patchClasses(capsuleBtn, { 'is-open': popoverOpen });
patchClasses(popoverEl, { 'is-instant': Boolean(instant && popoverOpen) });
patchAttr(capsuleBtn, 'aria-expanded', popoverOpen ? 'true' : 'false');
@@ -2670,6 +2721,40 @@ export function mountWindowOverlay() {
};
let hostDomObserver = null;
let hostDomRafId = 0;
let hostDomMicrotaskPending = false;
function flushHostDomMutationCheck() {
if (disposed) return;
syncHostRouteIfChanged();
if (!observedWorkbench) {
ensureWorkbenchThemeObserved();
}
const dock = resolveRuntimeDockTarget();
if (!isDockPlacementSynced(dock)) {
scheduleDockSync();
}
}
function scheduleHostDomMutationCheck() {
if (disposed) return;
const rafFn =
(typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function'
? window.requestAnimationFrame.bind(window)
: null) || (typeof requestAnimationFrame === 'function' ? requestAnimationFrame : null);
if (rafFn) {
if (hostDomRafId) return;
hostDomRafId = rafFn(() => {
hostDomRafId = 0;
flushHostDomMutationCheck();
});
return;
}
if (hostDomMicrotaskPending) return;
hostDomMicrotaskPending = true;
queueMicrotask(() => {
hostDomMicrotaskPending = false;
flushHostDomMutationCheck();
});
}
try {
if (typeof ResizeObserver !== 'undefined') {
resizeObserver = new ResizeObserver(() => updateResponsiveLayout());
@@ -2708,14 +2793,7 @@ export function mountWindowOverlay() {
) {
return;
}
syncHostRouteIfChanged();
if (!observedWorkbench) {
ensureWorkbenchThemeObserved();
}
const dock = resolveRuntimeDockTarget();
if (!isDockPlacementSynced(dock)) {
scheduleDockSync();
}
scheduleHostDomMutationCheck();
});
hostDomObserver.observe(document.body, {
childList: true,
@@ -2897,6 +2975,14 @@ export function mountWindowOverlay() {
cancelAnimationFrame(dockRafId);
dockRafId = 0;
}
if (hostDomRafId) {
const cancelRaf =
(typeof window !== 'undefined' && typeof window.cancelAnimationFrame === 'function'
? window.cancelAnimationFrame.bind(window)
: null) || (typeof cancelAnimationFrame === 'function' ? cancelAnimationFrame : null);
cancelRaf?.(hostDomRafId);
hostDomRafId = 0;
}
stopPolling();
stopAsyncTelemetryLoop();
unsubStore();
@@ -2928,7 +3014,7 @@ export function mountWindowOverlay() {
hoverWidgetHost.destroy();
} catch {}
try {
appInstance.destroy();
appInstance?.destroy?.();
} catch {}
try {
capsuleHost.remove();
@@ -7,37 +7,16 @@
import { defineComponent } from '../../core/component.js';
import { h, patchAttr, patchClasses, patchText } from '../../core/domPatch.js';
import { isWindowOverlayMode } from '../../core/httpClient.js';
import {
copyPlainTextToClipboard,
createCopiedFeedbackController,
} from '../../core/stepInspector.js';
import { createSvgIcon, patchSvgIcon } from '../../icons/SvgIcon.js';
import { t } from '../../i18n/index.js';
import { triggerBridgeHostRelaunch } from '../../store/telemetryStore.js';
const LAUNCH_FLAG_TEXT = '--remote-debugging-port=0';
async function copyTextToClipboard(text) {
try {
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(text);
return true;
}
} catch {
// Fallback to temporary textarea inside restricted webview contexts
}
try {
if (typeof document === 'undefined' || !document.body) return false;
const area = document.createElement('textarea');
area.value = text;
area.setAttribute('readonly', 'true');
area.style.cssText = 'position:fixed;left:-9999px;top:-9999px;opacity:0;';
document.body.appendChild(area);
area.select?.();
const ok = Boolean(document.execCommand?.('copy'));
document.body.removeChild(area);
return ok;
} catch {
return false;
}
}
export const BridgeStatusNotice = defineComponent({
name: 'BridgeStatusNotice',
setup({ props, onCleanup }) {
@@ -49,11 +28,16 @@ export const BridgeStatusNotice = defineComponent({
hostPlatform: 'win32',
};
let dismissed = false;
let copied = false;
let copiedTimer = null;
let relaunchState = 'idle'; // 'idle' | 'relaunching' | 'failed'
let relaunchResetTimer = null;
let destroyed = false;
const copyFeedback = createCopiedFeedbackController({
durationMs: 1800,
onCleanup,
onChange: () => {
if (!destroyed) syncActionButtons();
},
});
const headIconEl = createSvgIcon('warning', { size: 13, className: 'settings-bridge-icon' });
const titleEl = h('strong', { className: 'settings-bridge-title', text: '' });
@@ -146,18 +130,9 @@ export const BridgeStatusNotice = defineComponent({
type: 'button',
className: 'btn-ghost-sm settings-bridge-copy-btn',
onClick: async () => {
await copyTextToClipboard(LAUNCH_FLAG_TEXT);
await copyPlainTextToClipboard(LAUNCH_FLAG_TEXT);
if (destroyed) return;
copied = true;
if (copiedTimer) clearTimeout(copiedTimer);
syncActionButtons();
copiedTimer = setTimeout(() => {
copiedTimer = null;
if (destroyed) return;
copied = false;
syncActionButtons();
}, 1800);
copiedTimer?.unref?.();
copyFeedback.trigger(true);
},
},
[copyBtnIconEl, copyBtnTextEl]
@@ -200,10 +175,11 @@ export const BridgeStatusNotice = defineComponent({
: t('settings.bridge.relaunchBtn')
);
patchSvgIcon(copyBtnIconEl, copied ? 'check' : 'copy');
const isCopied = copyFeedback.isCopied(true);
patchSvgIcon(copyBtnIconEl, isCopied ? 'check' : 'copy');
patchText(
copyBtnTextEl,
copied
isCopied
? t('settings.bridge.copiedBtn')
: t('settings.bridge.copyFlagBtn', { cmd: LAUNCH_FLAG_TEXT })
);
@@ -288,10 +264,6 @@ export const BridgeStatusNotice = defineComponent({
onCleanup(() => {
destroyed = true;
if (copiedTimer) {
clearTimeout(copiedTimer);
copiedTimer = null;
}
if (relaunchResetTimer) {
clearTimeout(relaunchResetTimer);
relaunchResetTimer = null;
@@ -6,6 +6,7 @@
import { defineComponent } from '../../core/component.js';
import { h, patchAttr, patchClasses, patchText } from '../../core/domPatch.js';
import { isWindowOverlayMode } from '../../core/httpClient.js';
import { copyPlainTextToClipboard } from '../../core/stepInspector.js';
import { createSvgIcon } from '../../icons/SvgIcon.js';
import { isEnglishLocale, t } from '../../i18n/index.js';
import {
@@ -14,35 +15,11 @@ import {
} from '../../store/telemetryStore.js';
import { CustomScrollbar } from '../ui/CustomScrollbar.js';
import { CustomSelect } from '../ui/CustomSelect.js';
import { createSearchInput } from '../ui/SearchInput.js';
import { SegmentedControl } from '../ui/SegmentedControl.js';
const SMIG_OUTSIDE_PROJECT_ID = 'outside-of-project';
async function smigCopyText(text) {
try {
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(text);
return true;
}
} catch {
// 退回受限 Webview 的隐藏文本域复制
}
try {
if (typeof document === 'undefined' || !document.body) return false;
const area = document.createElement('textarea');
area.value = text;
area.setAttribute('readonly', 'true');
area.style.cssText = 'position:fixed;left:-9999px;top:-9999px;opacity:0;';
document.body.appendChild(area);
area.select?.();
const ok = Boolean(document.execCommand?.('copy'));
document.body.removeChild(area);
return ok;
} catch {
return false;
}
}
function smigGetClientLabel(clientId) {
if (clientId === 'cli') return t('settings.oth.migClientCli');
if (clientId === 'ide_legacy') return t('settings.oth.migClientIdeLegacy');
@@ -202,41 +179,27 @@ export const SessionMigrationCard = defineComponent({
projectSelect.el,
]);
searchInput = h('input', {
type: 'text',
className: 'smig-search-input',
autocomplete: 'off',
spellcheck: 'false',
const searchBox = createSearchInput({
wrapClassName: 'smig-search-wrap',
iconClassName: 'smig-search-icon',
inputClassName: 'smig-search-input',
clearClassName: 'smig-search-clear',
placeholder: t('settings.oth.migSearchPlaceholder'),
value: '',
});
searchClearBtn = h(
'button',
{
type: 'button',
className: 'smig-search-clear',
hidden: true,
'aria-label': t('select.clearSearch'),
onClick: () => {
searchQuery = '';
searchInput.value = '';
patchAttr(searchClearBtn, 'hidden', true);
renderSessionList();
searchInput.focus?.();
},
clearAriaLabel: t('select.clearSearch'),
closeIconSize: 10,
onInput: (val) => {
searchQuery = String(val || '').trim();
renderSessionList();
},
onClear: () => {
searchQuery = '';
renderSessionList();
searchInput.focus?.();
},
[createSvgIcon('close', { size: 10 })]
);
searchInput.addEventListener?.('input', () => {
searchQuery = String(searchInput.value || '').trim();
patchAttr(searchClearBtn, 'hidden', !searchQuery);
renderSessionList();
});
const searchWrap = h('div', { className: 'smig-search-wrap' }, [
createSvgIcon('search', { size: 12, className: 'smig-search-icon' }),
searchInput,
searchClearBtn,
]);
searchInput = searchBox.inputEl;
searchClearBtn = searchBox.clearBtnEl;
const searchWrap = searchBox.el;
toggleAllBtn = h('button', {
type: 'button',
@@ -662,7 +625,7 @@ export const SessionMigrationCard = defineComponent({
className: 'btn-ghost-sm smig-cmd-copy',
text: isCopied ? t('settings.oth.migCopied') : t('settings.oth.migCopyCmd'),
onClick: async () => {
const ok = await smigCopyText(item.resumeCommand);
const ok = await copyPlainTextToClipboard(item.resumeCommand);
if (!ok || destroyed) return;
copiedCmdId = item.newCascadeId;
renderResultBox();
@@ -16,6 +16,7 @@ import {
} from '../../core/domPatch.js';
import { isEnglishLocale, t } from '../../i18n/index.js';
import { createSvgIcon, patchSvgIcon } from '../../icons/SvgIcon.js';
import { createSearchInput } from './SearchInput.js';
function normalizeMultiSelection(rawValue, options = [], allValue = '') {
const arr = Array.isArray(rawValue)
@@ -105,44 +106,29 @@ export const CustomSelect = defineComponent({
[leadIcon, triggerLabel, chevronIcon]
);
const searchIcon = createSvgIcon('search', { size: 12, className: 'select-search-icon' });
const searchInput = h('input', {
type: 'text',
className: 'select-search-input',
autocomplete: 'off',
spellcheck: 'false',
const searchBox = createSearchInput({
wrapClassName: 'select-search-wrap',
iconClassName: 'select-search-icon',
inputClassName: 'select-search-input',
clearClassName: 'select-search-clear',
placeholder: getProps().searchPlaceholder || t('select.searchPlaceholder'),
onClick: (e) => e.stopPropagation(),
onInput: (e) => {
searchQuery = String(e?.target?.value ?? searchInput.value ?? '');
clearAriaLabel: t('select.clearSearch'),
hidden: true,
stopClickPropagation: true,
closeIconSize: 10,
onInput: (val) => {
searchQuery = val;
focusedIndex = 0;
renderMenuOptions();
},
onClear: () => {
clearSearchQuery(true);
},
onKeydown: handleKeydown,
});
const searchClearBtn = h(
'button',
{
type: 'button',
className: 'select-search-clear',
hidden: true,
'aria-label': t('select.clearSearch'),
onClick: (e) => {
e.stopPropagation();
clearSearchQuery(true);
},
},
[createSvgIcon('close', { size: 10 })]
);
const searchWrap = h(
'div',
{
className: 'select-search-wrap',
hidden: true,
onClick: (e) => e.stopPropagation(),
},
[searchIcon, searchInput, searchClearBtn]
);
const searchWrap = searchBox.el;
const searchInput = searchBox.inputEl;
const searchClearBtn = searchBox.clearBtnEl;
const optionsListEl = h('div', { className: 'select-options-list' });
const emptyHintEl = h('div', {
@@ -0,0 +1,118 @@
/**
* @fileoverview Shared compact search input bar (`SearchInput.js`) with leading search icon
* and conditional clear button, reused across `CustomSelect`, `StepsDetailView`, and `SessionMigrationCard`.
*/
import { h, patchAttr } from '../../core/domPatch.js';
import { createSvgIcon } from '../../icons/SvgIcon.js';
/**
* Creates a unified search input box while preserving caller-specific modifier classes.
*
* @param {{
* wrapClassName?: string,
* iconClassName?: string,
* inputClassName?: string,
* clearClassName?: string,
* placeholder?: string,
* ariaLabel?: string,
* clearAriaLabel?: string,
* hidden?: boolean,
* stopClickPropagation?: boolean,
* closeIconSize?: number,
* onInput?: (value: string, event: any) => void,
* onClear?: (event: any) => void,
* onKeydown?: (event: any) => void,
* }} [options={}]
*/
export function createSearchInput({
wrapClassName = '',
iconClassName = '',
inputClassName = '',
clearClassName = '',
placeholder = '',
ariaLabel = '',
clearAriaLabel = '',
hidden = false,
stopClickPropagation = false,
closeIconSize = 10,
onInput = null,
onClear = null,
onKeydown = null,
} = {}) {
const iconEl = createSvgIcon('search', {
size: 12,
className: ['ui-search-icon', iconClassName].filter(Boolean).join(' '),
});
const inputEl = h('input', {
type: 'text',
className: ['ui-search-input', inputClassName].filter(Boolean).join(' '),
autocomplete: 'off',
spellcheck: 'false',
placeholder,
...(ariaLabel ? { 'aria-label': ariaLabel } : {}),
...(stopClickPropagation ? { onClick: (e) => e.stopPropagation?.() } : {}),
onInput: (e) => {
const val = String(e?.target?.value ?? inputEl.value ?? '');
patchAttr(clearBtnEl, 'hidden', !val.trim());
onInput?.(val, e);
},
...(onKeydown ? { onKeydown } : {}),
});
const clearBtnEl = h(
'button',
{
type: 'button',
className: ['ui-search-clear', clearClassName].filter(Boolean).join(' '),
hidden: true,
...(clearAriaLabel ? { 'aria-label': clearAriaLabel } : {}),
onClick: (e) => {
if (stopClickPropagation) e?.stopPropagation?.();
inputEl.value = '';
patchAttr(clearBtnEl, 'hidden', true);
if (onClear) {
onClear(e);
} else {
onInput?.('', e);
inputEl.focus?.();
}
},
},
[createSvgIcon('close', { size: closeIconSize })]
);
const wrapEl = h(
'div',
{
className: ['ui-search-wrap', wrapClassName].filter(Boolean).join(' '),
...(hidden ? { hidden: true } : {}),
...(stopClickPropagation ? { onClick: (e) => e.stopPropagation?.() } : {}),
},
[iconEl, inputEl, clearBtnEl]
);
return {
el: wrapEl,
iconEl,
inputEl,
clearBtnEl,
getValue() {
return String(inputEl.value || '');
},
setValue(nextVal) {
const str = String(nextVal ?? '');
inputEl.value = str;
patchAttr(clearBtnEl, 'hidden', !str.trim());
},
syncLabels({ placeholder: nextPlaceholder, ariaLabel: nextAria, clearAriaLabel: nextClearAria } = {}) {
if (nextPlaceholder !== undefined) patchAttr(inputEl, 'placeholder', nextPlaceholder);
if (nextAria !== undefined) patchAttr(inputEl, 'aria-label', nextAria);
if (nextClearAria !== undefined) patchAttr(clearBtnEl, 'aria-label', nextClearAria);
},
focus() {
inputEl.focus?.();
},
};
}
@@ -0,0 +1,129 @@
/**
* @fileoverview Zero-ResizeObserver binary toggle switch (`ToggleSwitch.js`).
* Uses a pure-CSS 2-column grid glider (`--seg-active-idx`) so Settings tabs do not
* instantiate 10+ ResizeObservers or force synchronous layout measurements for simple
* on/off or show/hide switches, while preserving `.segmented` / `.seg-btn` semantics.
*/
import { defineComponent } from '../../core/component.js';
import { h, patchAttr, patchClasses, patchStyleVar, patchText } from '../../core/domPatch.js';
import { i18nStore, t } from '../../i18n/index.js';
const TOGGLE_PRESET_DEFS = Object.freeze({
enable: Object.freeze([
{ value: 'on', labelKey: 'settings.str.on' },
{ value: 'off', labelKey: 'settings.str.off' },
]),
visibility: Object.freeze([
{ value: 'show', labelKey: 'settings.str.show' },
{ value: 'hide', labelKey: 'settings.str.hide' },
]),
modernUi: Object.freeze([
{ value: 'on', labelKey: 'settings.gen.modernUiOn' },
{ value: 'off', labelKey: 'settings.gen.modernUiOff' },
]),
});
function resolveToggleOptions(props) {
if (Array.isArray(props.options) && props.options.length === 2) {
return props.options;
}
const defs = TOGGLE_PRESET_DEFS[props.preset] || TOGGLE_PRESET_DEFS.enable;
return [
{ value: defs[0].value, label: t(defs[0].labelKey) },
{ value: defs[1].value, label: t(defs[1].labelKey) },
];
}
export const ToggleSwitch = defineComponent({
name: 'ToggleSwitch',
setup({ getProps, setProps, emit, onCleanup }) {
const gliderEl = h('div', { className: 'seg-glider is-ready', 'aria-hidden': 'true' });
const btns = [0, 1].map((slotIdx) =>
h('button', {
type: 'button',
className: 'seg-btn',
onClick: (e) => {
e.stopPropagation();
const opts = resolveToggleOptions(getProps());
const opt = opts[slotIdx];
if (opt) selectValue(opt.value);
},
onKeydown: (e) => {
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
e.preventDefault();
const opts = resolveToggleOptions(getProps());
const nextIdx = slotIdx === 0 ? 1 : 0;
const targetOpt = opts[nextIdx];
if (targetOpt) {
selectValue(targetOpt.value);
btns[nextIdx]?.focus?.();
}
}
},
})
);
const rootEl = h(
'div',
{
className: 'segmented segmented--binary has-glider toggle-switch',
role: 'group',
'aria-label': getProps().ariaLabel || t('ui.seg.defaultAria'),
},
[gliderEl, btns[0], btns[1]]
);
function selectValue(nextVal) {
if (getProps().modelValue !== nextVal) {
setProps({ modelValue: nextVal });
emit('update:modelValue', nextVal);
}
}
function syncToggle() {
const props = getProps();
const opts = resolveToggleOptions(props);
const aria = props.ariaLabelKey ? t(props.ariaLabelKey) : props.ariaLabel || t('ui.seg.defaultAria');
patchAttr(rootEl, 'aria-label', aria);
let activeIdx = 0;
for (let i = 0; i < 2; i += 1) {
const opt = opts[i];
const btn = btns[i];
const active = opt.value === props.modelValue;
if (active) activeIdx = i;
patchText(btn, opt.label);
patchClasses(btn, { 'is-active': active });
patchAttr(btn, 'aria-pressed', active ? 'true' : 'false');
patchAttr(btn, 'data-seg-value', opt.value);
}
patchStyleVar(rootEl, '--seg-active-idx', String(activeIdx));
}
const unsubI18n = i18nStore.subscribe(
(st) => st.locale,
() => {
syncToggle();
},
{ immediate: false }
);
onCleanup(unsubI18n);
syncToggle();
return {
el: rootEl,
onPropsChange: syncToggle,
methods: {
setValue(val) {
setProps({ modelValue: val });
},
setOptions(options) {
setProps({ options });
},
refreshGeometry() {},
},
};
},
});
+50 -132
View File
@@ -1,5 +1,5 @@
/**
* @fileoverview 统一文本文件导出及剪贴板复制客户端 (`fileExportClient.js`)。
* @fileoverview 统一文本/二进制文件导出及剪贴板复制客户端 (`fileExportClient.js`)。
* 优先调用本机后端 `/api/export-file` 落盘到用户 Downloads(或插件 `.data/exports`)并返回真实绝对路径,
* 同时通过全局 Toast 清晰展示保存位置并提供「打开位置」快捷按钮;
* 当后端不可达或处于远程浏览器访问时,自动平滑降级到 `showSaveFilePicker` 或浏览器 Blob 下载并给出明确提示。
@@ -8,7 +8,7 @@
import { t } from '../i18n/index.js';
import { showUiToast } from '../store/uiStore.js';
import { callSidecarApi, isWindowOverlayMode } from './httpClient.js';
import { triggerTextFileDownload } from './settingsBackup.js';
import { triggerBlobDownload } from './settingsBackup.js';
import { copyPlainTextToClipboard } from './stepInspector.js';
import { uint8ArrayToBase64 } from './xlsxBuilder.js';
@@ -17,36 +17,6 @@ function isHostEmbeddedWebview() {
return Boolean(window.sidecar?.fetch) || isWindowOverlayMode();
}
function triggerBinaryFileDownload(filename, bytes, mimeType) {
try {
if (
typeof Blob === 'undefined' ||
typeof URL === 'undefined' ||
typeof URL.createObjectURL !== 'function' ||
typeof document === 'undefined'
) {
return false;
}
const blob = new Blob([bytes], { type: mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('href', url);
a.setAttribute('download', String(filename || 'export.xlsx'));
a.style.display = 'none';
document.body?.appendChild?.(a);
a.click?.();
a.remove?.();
setTimeout(() => {
try {
URL.revokeObjectURL(url);
} catch {}
}, 1000);
return true;
} catch {
return false;
}
}
function getPickerTypesForFilename(filename, mimeType) {
const lower = String(filename || '').toLowerCase();
if (lower.endsWith('.xlsx') || String(mimeType || '').includes('spreadsheetml')) {
@@ -140,28 +110,15 @@ async function requestLocalBackendExport(payload) {
}
/**
* 统一文本导出入口:优先本机后端落盘(返回精确路径 + 支持一键打开所在目录),
* 仅在真正独立浏览器上下文(非 Sidecar / 非 Electron 宿主)下降级为浏览器保存,避免宿主静默吞掉 Blob 下载后误报成功。
*
* @param {string} filename
* @param {string} content
* @param {string} [mimeType='text/plain;charset=utf-8']
* @returns {Promise<{ ok: boolean, mode: 'local' | 'picker' | 'browser' | 'cancelled' | 'failed', filePath?: string, fileName?: string }>}
* 共享多阶段导出与 Toast 反馈骨架(本机落盘 -> 宿主拦截保护 -> File System Access Picker -> Blob 下载)。
*/
export async function exportTextFileWithFeedback(
filename,
content,
mimeType = 'application/json;charset=utf-8'
) {
const safeName = String(filename || 'export.txt');
const text = String(content ?? '');
// 1. 优先通过本机后端落盘到 Downloads(含 /api/settings 穿透兼容旧常驻 main.mjs)
const { res: localRes } = await requestLocalBackendExport({
filename: safeName,
content: text,
mimeType,
});
async function runExportPipelineWithFeedback({
safeName,
mimeType,
backendPayload,
writablePayload,
}) {
const { res: localRes } = await requestLocalBackendExport(backendPayload);
if (localRes && localRes.ok && localRes.filePath) {
const savedPath = String(localRes.filePath);
const savedName = String(localRes.fileName || safeName);
@@ -178,7 +135,7 @@ export async function exportTextFileWithFeedback(
return { ok: true, mode: 'local', filePath: savedPath, fileName: savedName };
}
// 2. 在 Antigravity Sidecar / 双栖 Electron 宿主内,<a download> 会被静默吞掉,绝不误报“已下载到浏览器”
// 在 Antigravity Sidecar / 双栖 Electron 宿主内,<a download> 会被静默吞掉,绝不误报“已下载到浏览器”
if (isHostEmbeddedWebview()) {
showUiToast({
message: t('export.failed'),
@@ -189,7 +146,6 @@ export async function exportTextFileWithFeedback(
return { ok: false, mode: 'failed' };
}
// 3. 普通独立浏览器原生「另存为」对话框
if (typeof window !== 'undefined' && typeof window.showSaveFilePicker === 'function') {
try {
const handle = await window.showSaveFilePicker({
@@ -197,7 +153,7 @@ export async function exportTextFileWithFeedback(
types: getPickerTypesForFilename(safeName, mimeType),
});
const writable = await handle.createWritable();
await writable.write(text);
await writable.write(writablePayload);
await writable.close();
const pickedName = handle.name || safeName;
showUiToast({
@@ -210,12 +166,10 @@ export async function exportTextFileWithFeedback(
if (err && err.name === 'AbortError') {
return { ok: false, mode: 'cancelled' };
}
// 沙箱/iframe 抛出 SecurityError 等时继续降级到 Blob 下载
}
}
// 4. 独立浏览器标准 Blob 兜底下载
const ok = triggerTextFileDownload(safeName, text, mimeType);
const ok = triggerBlobDownload(safeName, writablePayload, mimeType);
if (ok) {
showUiToast({
message: t('export.savedBrowser', { file: safeName }),
@@ -234,9 +188,36 @@ export async function exportTextFileWithFeedback(
return { ok: false, mode: 'failed' };
}
/**
* 统一文本导出入口:优先本机后端落盘(返回精确路径 + 支持一键打开所在目录),
* 仅在真正独立浏览器上下文下降级为浏览器保存。
*
* @param {string} filename
* @param {string} content
* @param {string} [mimeType='application/json;charset=utf-8']
* @returns {Promise<{ ok: boolean, mode: 'local' | 'picker' | 'browser' | 'cancelled' | 'failed', filePath?: string, fileName?: string }>}
*/
export async function exportTextFileWithFeedback(
filename,
content,
mimeType = 'application/json;charset=utf-8'
) {
const safeName = String(filename || 'export.txt');
const text = String(content ?? '');
return runExportPipelineWithFeedback({
safeName,
mimeType,
backendPayload: {
filename: safeName,
content: text,
mimeType,
},
writablePayload: text,
});
}
/**
* 统一二进制文件导出入口(用于原生 `.xlsx` Excel 工作簿)。
* 优先转 Base64 经本机后端落盘到 Downloads 并展示完整路径 + 「打开位置」直达按钮。
*
* @param {string} filename
* @param {Uint8Array} bytes
@@ -253,80 +234,17 @@ export async function exportBinaryFileWithFeedback(
showUiToast({ message: t('export.failed'), tone: 'warn', durationMs: 3600 });
return { ok: false, mode: 'failed' };
}
const base64Content = uint8ArrayToBase64(bytes);
const { res: localRes } = await requestLocalBackendExport({
filename: safeName,
content: base64Content,
encoding: 'base64',
return runExportPipelineWithFeedback({
safeName,
mimeType,
backendPayload: {
filename: safeName,
content: uint8ArrayToBase64(bytes),
encoding: 'base64',
mimeType,
},
writablePayload: bytes,
});
if (localRes && localRes.ok && localRes.filePath) {
const savedPath = String(localRes.filePath);
const savedName = String(localRes.fileName || safeName);
showUiToast({
message: t('export.savedLocal', { file: savedName }),
detail: savedPath,
actionLabel: t('export.openFolder'),
onAction: () => {
void revealExportedFile(savedPath);
},
tone: 'ok',
durationMs: 7000,
});
return { ok: true, mode: 'local', filePath: savedPath, fileName: savedName };
}
if (isHostEmbeddedWebview()) {
showUiToast({
message: t('export.failed'),
detail: t('export.hostUnavailable'),
tone: 'warn',
durationMs: 5200,
});
return { ok: false, mode: 'failed' };
}
if (typeof window !== 'undefined' && typeof window.showSaveFilePicker === 'function') {
try {
const handle = await window.showSaveFilePicker({
suggestedName: safeName,
types: getPickerTypesForFilename(safeName, mimeType),
});
const writable = await handle.createWritable();
await writable.write(bytes);
await writable.close();
const pickedName = handle.name || safeName;
showUiToast({
message: t('export.savedPicked', { file: pickedName }),
tone: 'ok',
durationMs: 4200,
});
return { ok: true, mode: 'picker', fileName: pickedName };
} catch (err) {
if (err && err.name === 'AbortError') {
return { ok: false, mode: 'cancelled' };
}
}
}
const ok = triggerBinaryFileDownload(safeName, bytes, mimeType);
if (ok) {
showUiToast({
message: t('export.savedBrowser', { file: safeName }),
detail: t('export.savedBrowserHint'),
tone: 'info',
durationMs: 5000,
});
return { ok: true, mode: 'browser', fileName: safeName };
}
showUiToast({
message: t('export.failed'),
tone: 'warn',
durationMs: 3600,
});
return { ok: false, mode: 'failed' };
}
/**
+152 -136
View File
@@ -1,6 +1,6 @@
/**
* @fileoverview 偏好设置便携 JSON 备份及恢复工具 (`settingsBackup.js`).
* 仅处理经过白名单归一化的用户界面偏好项,不包含账号凭证及高风险上下文窗口覆盖。
* 通过单一声明式字段描述符表同时驱动导出与导入归一化,消除双遍手写 30 个键的漏同步风险。
*/
import {
@@ -36,17 +36,17 @@ function sanitizePositiveBudgetNum(val) {
}
/**
* 在浏览器端通过内存 Blob 触发文件下载(零本地磁盘外部写入)。
* 在浏览器端通过内存 Blob 触发文件下载(统一承载文本与二进制载荷)。
*
* @param {string} filename
* @param {string} content
* @param {BlobPart} blobPart
* @param {string} [mimeType]
* @returns {boolean}
*/
export function triggerTextFileDownload(
export function triggerBlobDownload(
filename,
content,
mimeType = 'application/json;charset=utf-8'
blobPart,
mimeType = 'application/octet-stream'
) {
try {
if (
@@ -57,11 +57,11 @@ export function triggerTextFileDownload(
) {
return false;
}
const blob = new Blob([String(content ?? '')], { type: mimeType });
const blob = new Blob([blobPart], { type: mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('href', url);
a.setAttribute('download', String(filename || 'export.json'));
a.setAttribute('download', String(filename || 'export.dat'));
a.style.display = 'none';
document.body?.appendChild?.(a);
a.click?.();
@@ -77,6 +77,143 @@ export function triggerTextFileDownload(
}
}
/**
* 在浏览器端通过内存 Blob 触发文本文件下载。
*
* @param {string} filename
* @param {string} content
* @param {string} [mimeType]
* @returns {boolean}
*/
export function triggerTextFileDownload(
filename,
content,
mimeType = 'application/json;charset=utf-8'
) {
return triggerBlobDownload(
String(filename || 'export.json'),
String(content ?? ''),
mimeType
);
}
const normField = (key, normalizeFn) => ({
exportTo: (src, out) => {
out[key] = normalizeFn(src[key]);
},
importTo: (src, hasKey, patch) => {
if (hasKey(key)) patch[key] = normalizeFn(src[key]);
},
});
const boolField = (key, defaultVal) => ({
exportTo: (src, out) => {
out[key] = defaultVal ? src[key] !== false : src[key] === true;
},
importTo: (src, hasKey, patch) => {
if (hasKey(key) && typeof src[key] === 'boolean') patch[key] = src[key];
},
});
const arrayField = (key, normalizeFn) => ({
exportTo: (src, out) => {
out[key] = normalizeFn(src[key]);
},
importTo: (src, hasKey, patch) => {
if (hasKey(key) && Array.isArray(src[key])) patch[key] = normalizeFn(src[key]);
},
});
const positiveBudgetField = (key, fallbackVal) => ({
exportTo: (src, out) => {
out[key] = sanitizePositiveBudgetNum(src[key]) ?? fallbackVal;
},
importTo: (src, hasKey, patch) => {
if (hasKey(key)) {
const num = sanitizePositiveBudgetNum(src[key]);
if (num !== null) patch[key] = num;
}
},
});
const PORTABLE_SETTING_DESCRIPTORS = Object.freeze([
normField('language', normalizeLanguageSetting),
normField('themeAccent', normalizeThemeAccent),
normField('fontScale', normalizeFontScale),
{
exportTo: (src, out) => {
out.modernUi = src.modernUi !== undefined ? normalizeModernUi(src.modernUi) : true;
},
importTo: (src, hasKey, patch) => {
if (hasKey('modernUi')) {
const val = normalizeModernUi(src.modernUi);
patch.modernUi = val;
patch.experimentalModernUi = val;
}
},
},
normField('weeklyLimitMode', normalizeWeeklyLimitMode),
positiveBudgetField('weeklyTokenBudget', 150000000),
positiveBudgetField('weeklyCostBudget', 100),
{
exportTo: (src, out) => {
const mode = normalizeModelDisplayMode(src.modelDisplayMode, src.showUpstreamModel);
out.modelDisplayMode = mode;
out.showUpstreamModel = mode !== 'short';
},
importTo: (src, hasKey, patch) => {
if (hasKey('modelDisplayMode') || hasKey('showUpstreamModel')) {
const mode = normalizeModelDisplayMode(src.modelDisplayMode, src.showUpstreamModel);
patch.modelDisplayMode = mode;
patch.showUpstreamModel = mode !== 'short';
}
},
},
normField('orchestratorIdMode', normalizeOrchestratorIdMode),
{
exportTo: (src, out) => {
out.pluginUpdateMode = normalizePluginUpdateMode(src.pluginUpdateMode, src.autoUpdatePlugin);
},
importTo: (src, hasKey, patch) => {
if (hasKey('pluginUpdateMode') || hasKey('autoUpdatePlugin')) {
const mode = normalizePluginUpdateMode(src.pluginUpdateMode, src.autoUpdatePlugin);
patch.pluginUpdateMode = mode;
patch.autoUpdatePlugin = mode === 'auto';
}
},
},
{
exportTo: (src, out) => {
out.windowMountMode = normalizeWindowMountMode(src.windowMountMode, src.enableWindowOverlay);
},
importTo: (src, hasKey, patch) => {
if (hasKey('windowMountMode') || hasKey('enableWindowOverlay')) {
const mode = normalizeWindowMountMode(src.windowMountMode, src.enableWindowOverlay);
patch.windowMountMode = mode;
patch.enableWindowOverlay = mode !== 'sidebar';
}
},
},
normField('popoverWidthMode', normalizePopoverWidthMode),
normField('popoverWidth', normalizePopoverWidth),
boolField('enableCliStatusLine', true),
normField('cliStatusLineSlots', normalizeCliStatusLineSlots),
normField('standalonePort', normalizeStandalonePort),
boolField('showTopbarMultiSession', true),
normField('contextAgentMode', normalizeContextAgentMode),
arrayField('topbarCapsuleSlots', normalizeTopbarCapsuleSlots),
arrayField('hoverModules', normalizeHoverModules),
arrayField('overviewModules', normalizeOverviewModules),
arrayField('overviewMetrics', normalizeOverviewMetrics),
boolField('showStepTurnRail', false),
boolField('showStepAgentBadge', true),
boolField('showStepSpeedColor', false),
boolField('showStepFilterToolbar', false),
normField('stepTokenComboFormat', normalizeStepTokenComboFormat),
arrayField('stepTableColumns', normalizeStepTableColumns),
normField('experimentalQuotaReservation', normalizeExperimentalQuotaReservation),
]);
/**
* 将当前用户偏好设置序列化为跨设备可迁移的安全 JSON 备份文本(仅包含便携偏好项,不包含凭证或高风险覆盖开关)。
*
@@ -85,46 +222,15 @@ export function triggerTextFileDownload(
*/
export function buildExportableSettingsJson(settings = {}) {
const src = settings && typeof settings === 'object' ? settings : {};
const modelDisplayMode = normalizeModelDisplayMode(src.modelDisplayMode, src.showUpstreamModel);
const modernUi = src.modernUi !== undefined ? normalizeModernUi(src.modernUi) : true;
const outSettings = {};
for (const desc of PORTABLE_SETTING_DESCRIPTORS) {
desc.exportTo(src, outSettings);
}
const payload = {
schema: SETTINGS_BACKUP_SCHEMA,
version: 1,
exportedAt: new Date().toISOString(),
settings: {
language: normalizeLanguageSetting(src.language),
themeAccent: normalizeThemeAccent(src.themeAccent),
fontScale: normalizeFontScale(src.fontScale),
modernUi,
weeklyLimitMode: normalizeWeeklyLimitMode(src.weeklyLimitMode),
weeklyTokenBudget: sanitizePositiveBudgetNum(src.weeklyTokenBudget) ?? 150000000,
weeklyCostBudget: sanitizePositiveBudgetNum(src.weeklyCostBudget) ?? 100,
modelDisplayMode,
showUpstreamModel: modelDisplayMode !== 'short',
orchestratorIdMode: normalizeOrchestratorIdMode(src.orchestratorIdMode),
pluginUpdateMode: normalizePluginUpdateMode(src.pluginUpdateMode, src.autoUpdatePlugin),
windowMountMode: normalizeWindowMountMode(src.windowMountMode, src.enableWindowOverlay),
popoverWidthMode: normalizePopoverWidthMode(src.popoverWidthMode),
popoverWidth: normalizePopoverWidth(src.popoverWidth),
enableCliStatusLine: src.enableCliStatusLine !== false,
cliStatusLineSlots: normalizeCliStatusLineSlots(src.cliStatusLineSlots),
standalonePort: normalizeStandalonePort(src.standalonePort),
showTopbarMultiSession: src.showTopbarMultiSession !== false,
contextAgentMode: normalizeContextAgentMode(src.contextAgentMode),
topbarCapsuleSlots: normalizeTopbarCapsuleSlots(src.topbarCapsuleSlots),
hoverModules: normalizeHoverModules(src.hoverModules),
overviewModules: normalizeOverviewModules(src.overviewModules),
overviewMetrics: normalizeOverviewMetrics(src.overviewMetrics),
showStepTurnRail: src.showStepTurnRail === true,
showStepAgentBadge: src.showStepAgentBadge !== false,
showStepSpeedColor: src.showStepSpeedColor === true,
showStepFilterToolbar: src.showStepFilterToolbar === true,
stepTokenComboFormat: normalizeStepTokenComboFormat(src.stepTokenComboFormat),
stepTableColumns: normalizeStepTableColumns(src.stepTableColumns),
experimentalQuotaReservation: normalizeExperimentalQuotaReservation(
src.experimentalQuotaReservation
),
},
settings: outSettings,
};
return `${JSON.stringify(payload, null, 2)}\n`;
}
@@ -158,98 +264,8 @@ export function parseImportedSettingsJson(rawText) {
const hasKey = (k) => Object.prototype.hasOwnProperty.call(src, k);
const patch = {};
if (hasKey('language')) patch.language = normalizeLanguageSetting(src.language);
if (hasKey('themeAccent')) patch.themeAccent = normalizeThemeAccent(src.themeAccent);
if (hasKey('fontScale')) patch.fontScale = normalizeFontScale(src.fontScale);
if (hasKey('modernUi')) {
const val = normalizeModernUi(src.modernUi);
patch.modernUi = val;
patch.experimentalModernUi = val;
}
if (hasKey('weeklyLimitMode')) {
patch.weeklyLimitMode = normalizeWeeklyLimitMode(src.weeklyLimitMode);
}
if (hasKey('weeklyTokenBudget')) {
const num = sanitizePositiveBudgetNum(src.weeklyTokenBudget);
if (num !== null) patch.weeklyTokenBudget = num;
}
if (hasKey('weeklyCostBudget')) {
const num = sanitizePositiveBudgetNum(src.weeklyCostBudget);
if (num !== null) patch.weeklyCostBudget = num;
}
if (hasKey('modelDisplayMode') || hasKey('showUpstreamModel')) {
const mode = normalizeModelDisplayMode(src.modelDisplayMode, src.showUpstreamModel);
patch.modelDisplayMode = mode;
patch.showUpstreamModel = mode !== 'short';
}
if (hasKey('orchestratorIdMode')) {
patch.orchestratorIdMode = normalizeOrchestratorIdMode(src.orchestratorIdMode);
}
if (hasKey('pluginUpdateMode') || hasKey('autoUpdatePlugin')) {
const mode = normalizePluginUpdateMode(src.pluginUpdateMode, src.autoUpdatePlugin);
patch.pluginUpdateMode = mode;
patch.autoUpdatePlugin = mode === 'auto';
}
if (hasKey('windowMountMode') || hasKey('enableWindowOverlay')) {
const mode = normalizeWindowMountMode(src.windowMountMode, src.enableWindowOverlay);
patch.windowMountMode = mode;
patch.enableWindowOverlay = mode !== 'sidebar';
}
if (hasKey('popoverWidthMode')) {
patch.popoverWidthMode = normalizePopoverWidthMode(src.popoverWidthMode);
}
if (hasKey('popoverWidth')) {
patch.popoverWidth = normalizePopoverWidth(src.popoverWidth);
}
if (hasKey('enableCliStatusLine') && typeof src.enableCliStatusLine === 'boolean') {
patch.enableCliStatusLine = src.enableCliStatusLine;
}
if (hasKey('cliStatusLineSlots')) {
patch.cliStatusLineSlots = normalizeCliStatusLineSlots(src.cliStatusLineSlots);
}
if (hasKey('standalonePort')) {
patch.standalonePort = normalizeStandalonePort(src.standalonePort);
}
if (hasKey('showTopbarMultiSession') && typeof src.showTopbarMultiSession === 'boolean') {
patch.showTopbarMultiSession = src.showTopbarMultiSession;
}
if (hasKey('contextAgentMode')) {
patch.contextAgentMode = normalizeContextAgentMode(src.contextAgentMode);
}
if (hasKey('topbarCapsuleSlots') && Array.isArray(src.topbarCapsuleSlots)) {
patch.topbarCapsuleSlots = normalizeTopbarCapsuleSlots(src.topbarCapsuleSlots);
}
if (hasKey('hoverModules') && Array.isArray(src.hoverModules)) {
patch.hoverModules = normalizeHoverModules(src.hoverModules);
}
if (hasKey('overviewModules') && Array.isArray(src.overviewModules)) {
patch.overviewModules = normalizeOverviewModules(src.overviewModules);
}
if (hasKey('overviewMetrics') && Array.isArray(src.overviewMetrics)) {
patch.overviewMetrics = normalizeOverviewMetrics(src.overviewMetrics);
}
if (hasKey('showStepTurnRail') && typeof src.showStepTurnRail === 'boolean') {
patch.showStepTurnRail = src.showStepTurnRail;
}
if (hasKey('showStepAgentBadge') && typeof src.showStepAgentBadge === 'boolean') {
patch.showStepAgentBadge = src.showStepAgentBadge;
}
if (hasKey('showStepSpeedColor') && typeof src.showStepSpeedColor === 'boolean') {
patch.showStepSpeedColor = src.showStepSpeedColor;
}
if (hasKey('showStepFilterToolbar') && typeof src.showStepFilterToolbar === 'boolean') {
patch.showStepFilterToolbar = src.showStepFilterToolbar;
}
if (hasKey('stepTokenComboFormat')) {
patch.stepTokenComboFormat = normalizeStepTokenComboFormat(src.stepTokenComboFormat);
}
if (hasKey('stepTableColumns') && Array.isArray(src.stepTableColumns)) {
patch.stepTableColumns = normalizeStepTableColumns(src.stepTableColumns);
}
if (hasKey('experimentalQuotaReservation')) {
patch.experimentalQuotaReservation = normalizeExperimentalQuotaReservation(
src.experimentalQuotaReservation
);
for (const desc of PORTABLE_SETTING_DESCRIPTORS) {
desc.importTo(src, hasKey, patch);
}
const appliedCount = Object.keys(patch).length;
+65 -1
View File
@@ -340,7 +340,11 @@ export async function copyPlainTextToClipboard(text) {
document.body.appendChild(ta);
ta.select?.();
const ok = document.execCommand('copy');
ta.remove?.();
if (typeof ta.remove === 'function') {
ta.remove();
} else {
document.body.removeChild?.(ta);
}
return Boolean(ok);
}
} catch {
@@ -348,3 +352,63 @@ export async function copyPlainTextToClipboard(text) {
}
return false;
}
/**
* 统一的「已复制」临时反馈计时器控制器(自动重置定时器并在组件销毁时清理)。
*
* @param {{
* durationMs?: number,
* onChange?: (copiedKey: any) => void,
* onCleanup?: (cleanupFn: () => void) => void,
* }} [options={}]
*/
export function createCopiedFeedbackController({
durationMs = 1800,
onChange = null,
onCleanup = null,
} = {}) {
let activeKey = null;
let timer = null;
let disposed = false;
function clear() {
if (timer) {
clearTimeout(timer);
timer = null;
}
if (activeKey !== null) {
activeKey = null;
if (!disposed) onChange?.(null);
}
}
function trigger(key = true) {
if (disposed) return;
if (timer) clearTimeout(timer);
activeKey = key;
onChange?.(activeKey);
timer = setTimeout(() => {
timer = null;
if (disposed) return;
activeKey = null;
onChange?.(null);
}, durationMs);
timer?.unref?.();
}
onCleanup?.(() => {
disposed = true;
if (timer) {
clearTimeout(timer);
timer = null;
}
activeKey = null;
});
return {
isCopied: (key = true) => activeKey === key,
getActiveKey: () => activeKey,
trigger,
clear,
};
}
+49 -14
View File
@@ -376,32 +376,35 @@
overflow: hidden;
}
.select-search-wrap {
.ui-search-wrap {
display: flex;
align-items: center;
gap: 5px;
padding: 4px 7px;
margin-bottom: 4px;
padding: 2px 8px;
border-radius: var(--radius-xs);
border: 1px solid var(--border-hairline);
background: var(--surface-bg);
flex-shrink: 0;
background: var(--surface-subtle);
transition:
border-color var(--dur-instant) var(--ease-fast),
background-color var(--dur-instant) var(--ease-fast),
box-shadow var(--dur-instant) var(--ease-fast);
}
.select-search-wrap[hidden] {
.ui-search-wrap[hidden] {
display: none !important;
}
.select-search-wrap:focus-within {
.ui-search-wrap:focus-within {
border-color: var(--accent-primary);
}
.select-search-icon {
.ui-search-icon {
color: var(--text-muted);
flex-shrink: 0;
pointer-events: none;
}
.select-search-input {
.ui-search-input {
flex: 1;
min-width: 0;
border: none;
@@ -414,11 +417,11 @@
padding: 0;
}
.select-search-input::placeholder {
.ui-search-input::placeholder {
color: var(--text-muted);
}
.select-search-clear {
.ui-search-clear {
display: inline-flex;
align-items: center;
justify-content: center;
@@ -431,17 +434,27 @@
color: var(--text-muted);
cursor: pointer;
flex-shrink: 0;
transition:
color var(--dur-instant) var(--ease-fast),
background-color var(--dur-instant) var(--ease-fast);
}
.select-search-clear:hover {
.ui-search-clear:hover {
color: var(--text-primary);
background: var(--surface-hover);
}
.select-search-clear[hidden] {
.ui-search-clear[hidden] {
display: none !important;
}
.select-search-wrap {
padding: 4px 7px;
margin-bottom: 4px;
background: var(--surface-bg);
flex-shrink: 0;
}
.select-options-list {
display: flex;
flex-direction: column;
@@ -750,6 +763,10 @@
opacity: 0;
pointer-events: none;
z-index: 0;
}
.segmented:hover .seg-glider,
.segmented:focus-within .seg-glider {
will-change: transform, width;
}
@@ -807,6 +824,20 @@
font-weight: 600;
}
.segmented--binary {
--seg-pad: 0px;
display: inline-grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.segmented--binary.has-glider > .seg-glider {
top: var(--seg-pad, 0px);
left: var(--seg-pad, 0px);
width: calc((100% - 2 * var(--seg-pad, 0px) - 2px) / 2);
height: calc(100% - 2 * var(--seg-pad, 0px));
transform: translate3d(calc(var(--seg-active-idx, 0) * (100% + 2px)), 0, 0);
}
/* --- 7. 独立槽位自定义滚动条 (Bespoke Custom Scrollbar) --- */
.custom-scroll-host {
position: relative;
@@ -866,10 +897,14 @@
border-radius: var(--radius-pill);
background: color-mix(in srgb, var(--text-secondary) 32%, transparent);
transform: translate3d(0, var(--thumb-y, 0px), 0);
will-change: transform, height;
transition: background-color var(--dur-instant) var(--ease-fast);
}
.custom-scroll-host:hover .scrollbar-thumb,
.scrollbar-rail.is-dragging .scrollbar-thumb {
will-change: transform, height;
}
.scrollbar-rail:hover .scrollbar-thumb,
.scrollbar-rail.is-dragging .scrollbar-thumb {
background: color-mix(in srgb, var(--accent-primary) 72%, transparent);
+4 -4
View File
@@ -193,6 +193,7 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell {
}
[data-modern-ui="true"] .segmented {
--seg-pad: 2px;
padding: 2px;
border-radius: var(--radius-xs);
background: var(--modern-inline-track-bg);
@@ -631,7 +632,6 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell {
/* --- 6. 设置表单、折叠面板、槽位排序与输入控件去边框 --- */
[data-modern-ui="true"] .collapsible-body,
[data-modern-ui="true"] .settings-action-block + .settings-action-block,
[data-modern-ui="true"] .settings-account-entry,
[data-modern-ui="true"] .dt-time-row {
border-top: none;
}
@@ -671,8 +671,7 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell {
[data-modern-ui="true"] .number-input,
[data-modern-ui="true"] .dt-trigger,
[data-modern-ui="true"] .dt-mini-step,
[data-modern-ui="true"] .settings-text-input,
[data-modern-ui="true"] .settings-account-form input {
[data-modern-ui="true"] .settings-text-input {
border: none;
background: var(--modern-surface-subtle);
transition:
@@ -691,13 +690,14 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell {
[data-modern-ui="true"] .number-input:focus-within,
[data-modern-ui="true"] .settings-text-input:focus,
[data-modern-ui="true"] .settings-account-form input:focus,
[data-modern-ui="true"] .ui-search-wrap:focus-within,
[data-modern-ui="true"] .smig-search-wrap:focus-within,
[data-modern-ui="true"] .steps-search-wrap:focus-within {
border: none;
box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--accent-primary) 55%, transparent);
}
[data-modern-ui="true"] .ui-search-wrap,
[data-modern-ui="true"] .smig-search-wrap,
[data-modern-ui="true"] .steps-search-wrap {
border: none;
@@ -641,60 +641,6 @@
line-height: 1.35;
}
.settings-account-identity {
overflow-wrap: anywhere;
user-select: text;
}
.settings-account-list,
.settings-account-form,
.settings-account-form label {
display: grid;
gap: var(--space-2);
}
.settings-account-list:empty {
display: none;
}
.settings-account-entry {
display: grid;
gap: var(--space-2);
padding: var(--space-2) 0;
border-top: 1px solid var(--border-hairline);
}
.settings-account-form label {
font-size: var(--fs-sm);
color: var(--text-secondary);
}
.settings-account-form input {
min-width: 0;
padding: var(--space-2);
background: var(--surface-subtle);
border: 1px solid var(--border-hairline);
border-radius: var(--radius-sm);
font: inherit;
color: var(--text-primary);
}
.settings-account-form button {
justify-self: start;
}
.settings-account-buttons {
display: flex;
flex-wrap: wrap;
gap: var(--space-2);
}
.settings-account-quota {
text-align: right;
color: var(--text-secondary);
font-variant-numeric: tabular-nums;
}
.settings-context-model .select-option-meta {
max-width: 62%;
text-align: right;
@@ -1067,69 +1013,9 @@
}
.smig-search-wrap {
display: flex;
align-items: center;
gap: 5px;
flex: 1;
min-width: 0;
min-height: calc(28px * var(--ui-font-scale, 1));
padding: 2px 8px;
border-radius: var(--radius-xs);
border: 1px solid var(--border-hairline);
background: var(--surface-subtle);
transition:
border-color var(--dur-instant) var(--ease-fast),
background-color var(--dur-instant) var(--ease-fast),
box-shadow var(--dur-instant) var(--ease-fast);
}
.smig-search-wrap:focus-within {
border-color: var(--accent-primary);
}
.smig-search-icon {
color: var(--text-muted);
flex-shrink: 0;
}
.smig-search-input {
flex: 1;
min-width: 0;
border: none;
background: transparent;
color: var(--text-primary);
font-family: var(--font-sans);
font-size: var(--fs-md);
line-height: 1.3;
outline: none;
padding: 0;
}
.smig-search-input::placeholder {
color: var(--text-muted);
}
.smig-search-clear {
display: inline-flex;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
padding: 0;
border: none;
border-radius: var(--radius-pill);
background: transparent;
color: var(--text-muted);
cursor: pointer;
flex-shrink: 0;
transition:
color var(--dur-instant) var(--ease-fast),
background-color var(--dur-instant) var(--ease-fast);
}
.smig-search-clear:hover {
color: var(--text-primary);
background: var(--surface-hover);
}
.smig-search-clear[hidden] {
@@ -1238,70 +1238,9 @@
}
.steps-search-wrap {
display: flex;
align-items: center;
gap: 5px;
flex: 1 1 160px;
min-width: 120px;
min-height: calc(28px * var(--ui-font-scale, 1));
padding: 2px 8px;
border-radius: var(--radius-xs);
border: 1px solid var(--border-hairline);
background: var(--surface-subtle);
transition:
border-color var(--dur-instant) var(--ease-fast),
background-color var(--dur-instant) var(--ease-fast),
box-shadow var(--dur-instant) var(--ease-fast);
}
.steps-search-wrap:focus-within {
border-color: var(--accent-primary);
}
.steps-search-icon {
color: var(--text-muted);
flex-shrink: 0;
pointer-events: none;
}
.steps-search-input {
flex: 1;
min-width: 0;
border: none;
outline: none;
background: transparent;
color: var(--text-primary);
font-family: var(--font-sans);
font-size: var(--fs-md);
line-height: 1.3;
padding: 0;
}
.steps-search-input::placeholder {
color: var(--text-muted);
}
.steps-search-clear {
display: inline-flex;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
padding: 0;
border: none;
border-radius: var(--radius-pill);
background: transparent;
color: var(--text-muted);
cursor: pointer;
flex-shrink: 0;
transition:
color var(--dur-instant) var(--ease-fast),
background-color var(--dur-instant) var(--ease-fast);
}
.steps-search-clear:hover {
color: var(--text-primary);
background: var(--surface-hover);
}
.steps-search-clear[hidden] {
+29 -19
View File
@@ -538,6 +538,8 @@ export const ConsumptionView = defineComponent({
});
let activeHoverTargetEl = null;
let cachedBreakdownRootRect = null;
let cachedBreakdownAnchorRect = null;
const popoverContent = createConsumptionBreakdownContent({
showModelDot: true,
@@ -550,6 +552,8 @@ export const ConsumptionView = defineComponent({
);
function hideBreakdownPopover() {
cachedBreakdownRootRect = null;
cachedBreakdownAnchorRect = null;
if (activeHoverTargetEl) {
patchClasses(activeHoverTargetEl, { 'is-hovered': false });
activeHoverTargetEl = null;
@@ -559,27 +563,29 @@ export const ConsumptionView = defineComponent({
}
function positionBreakdownPopover(anchorEl, pointerClientX = null, pointerClientY = null) {
const rootRect = rootEl.getBoundingClientRect?.() || {
left: 0,
top: 0,
width: 360,
height: 600,
};
const anchorRect = anchorEl?.getBoundingClientRect?.() || {
left: 0,
top: 0,
bottom: 0,
width: 0,
height: 0,
};
const tipRect = breakdownPopoverEl.getBoundingClientRect?.() || {
width: 216,
height: 108,
};
if (!cachedBreakdownRootRect) {
cachedBreakdownRootRect = rootEl.getBoundingClientRect?.() || {
left: 0,
top: 0,
width: 360,
height: 600,
};
}
const rootRect = cachedBreakdownRootRect;
if (!cachedBreakdownAnchorRect) {
cachedBreakdownAnchorRect = anchorEl?.getBoundingClientRect?.() || {
left: 0,
top: 0,
bottom: 0,
width: 0,
height: 0,
};
}
const anchorRect = cachedBreakdownAnchorRect;
const tipW = Number(breakdownPopoverEl.offsetWidth || 0) || 216;
const tipH = Number(breakdownPopoverEl.offsetHeight || 0) || 108;
const rootW = rootRect.width > 0 ? rootRect.width : 360;
const rootH = rootRect.height > 0 ? rootRect.height : 600;
const tipW = tipRect.width > 0 ? tipRect.width : 216;
const tipH = tipRect.height > 0 ? tipRect.height : 108;
const hasPointerX = Number.isFinite(pointerClientX) && pointerClientX > 0 && rootRect.width > 0;
const hasPointerY = Number.isFinite(pointerClientY) && pointerClientY > 0 && rootRect.height > 0;
@@ -625,6 +631,10 @@ export const ConsumptionView = defineComponent({
}
if (activeHoverTargetEl && activeHoverTargetEl !== anchorEl) {
patchClasses(activeHoverTargetEl, { 'is-hovered': false });
cachedBreakdownAnchorRect = null;
} else if (!activeHoverTargetEl) {
cachedBreakdownRootRect = null;
cachedBreakdownAnchorRect = null;
}
activeHoverTargetEl = anchorEl;
patchClasses(anchorEl, { 'is-hovered': true });
+20 -31
View File
@@ -74,6 +74,7 @@ import {
import { CustomScrollbar } from '../components/ui/CustomScrollbar.js';
import { CustomSelect } from '../components/ui/CustomSelect.js';
import { createFourSegmentBar } from '../components/ui/FourSegmentBar.js';
import { createSearchInput } from '../components/ui/SearchInput.js';
import { SegmentedControl } from '../components/ui/SegmentedControl.js';
import { StepTableWidget } from '../components/widgets/StepTableWidget.js';
import { sortStepsByColumn } from '../registries/stepColumnRegistry.js';
@@ -434,40 +435,30 @@ export const StepsDetailView = defineComponent({
);
// --- 步骤搜索栏及快捷诊断芯片 ---
const stepSearchClearBtn = h(
'button',
{
type: 'button',
className: 'steps-search-clear',
hidden: true,
'aria-label': t('steps.searchClearAria'),
onclick: () => {
stepSearchQuery = '';
stepSearchInput.value = '';
patchAttr(stepSearchClearBtn, 'hidden', true);
if (latestSlice) renderStepsData(latestSlice);
stepSearchInput.focus?.();
},
},
[createSvgIcon('close', { size: 11 })]
);
const stepSearchInput = h('input', {
type: 'text',
className: 'steps-search-input',
const stepSearchBox = createSearchInput({
wrapClassName: 'steps-search-wrap',
iconClassName: 'steps-search-icon',
inputClassName: 'steps-search-input',
clearClassName: 'steps-search-clear',
placeholder: t('steps.searchPlaceholder'),
'aria-label': t('steps.searchPlaceholder'),
onInput: (e) => {
stepSearchQuery = String(e?.target?.value ?? '');
patchAttr(stepSearchClearBtn, 'hidden', !stepSearchQuery.trim());
ariaLabel: t('steps.searchPlaceholder'),
clearAriaLabel: t('steps.searchClearAria'),
closeIconSize: 11,
onInput: (val) => {
stepSearchQuery = String(val ?? '');
if (latestSlice) renderStepsData(latestSlice);
},
onClear: () => {
stepSearchQuery = '';
if (latestSlice) renderStepsData(latestSlice);
stepSearchInput.focus?.();
},
onKeydown: (e) => {
if (e?.key === 'Escape') {
e.stopPropagation?.();
if (stepSearchQuery) {
stepSearchQuery = '';
stepSearchInput.value = '';
patchAttr(stepSearchClearBtn, 'hidden', true);
stepSearchBox.setValue('');
if (latestSlice) renderStepsData(latestSlice);
} else {
stepSearchInput.blur?.();
@@ -475,11 +466,9 @@ export const StepsDetailView = defineComponent({
}
},
});
const stepSearchWrapEl = h('div', { className: 'steps-search-wrap' }, [
createSvgIcon('search', { size: 12, className: 'steps-search-icon' }),
stepSearchInput,
stepSearchClearBtn,
]);
const stepSearchWrapEl = stepSearchBox.el;
const stepSearchInput = stepSearchBox.inputEl;
const stepSearchClearBtn = stepSearchBox.clearBtnEl;
const QUICK_CHIP_DEFS = [
{ key: 'anomaly', i18nKey: 'steps.chipAnomaly', tone: 'is-warn' },
@@ -24,6 +24,7 @@ import {
import { ThemeColorPicker } from '../../components/settings/ThemeColorPicker.js';
import { CustomSelect } from '../../components/ui/CustomSelect.js';
import { SegmentedControl } from '../../components/ui/SegmentedControl.js';
import { ToggleSwitch } from '../../components/ui/ToggleSwitch.js';
function getLanguageOptions() {
return [
@@ -42,13 +43,6 @@ function getFontScaleOptions() {
];
}
function getModernUiOptions() {
return [
{ value: 'on', label: t('settings.gen.modernUiOn') },
{ value: 'off', label: t('settings.gen.modernUiOff') },
];
}
function getUpdateModeOptions() {
return [
{ value: 'manual', label: t('settings.gen.updateManual') },
@@ -216,10 +210,10 @@ export const SettingsGeneralTab = defineComponent({
},
});
const modernUiSwitch = SegmentedControl({
ariaLabel: t('settings.gen.modernUi'),
const modernUiSwitch = ToggleSwitch({
ariaLabelKey: 'settings.gen.modernUi',
preset: 'modernUi',
modelValue: 'on',
options: getModernUiOptions(),
onUpdateModelValue: async (val) => {
const nextModernUi = val !== 'off';
draftModernUi = nextModernUi;
@@ -441,7 +435,6 @@ export const SettingsGeneralTab = defineComponent({
});
modernUiSwitch.setProps({
modelValue: draftModernUi ? 'on' : 'off',
options: getModernUiOptions(),
});
autoUpdateSelect.setProps({
modelValue: draftPluginUpdateMode,
@@ -523,9 +516,7 @@ export const SettingsGeneralTab = defineComponent({
options: getFontScaleOptions(),
});
modernUiSwitch.setProps({
ariaLabel: t('settings.gen.modernUi'),
modelValue: draftModernUi ? 'on' : 'off',
options: getModernUiOptions(),
});
autoUpdateSelect.setProps({
modelValue: draftPluginUpdateMode,
@@ -27,17 +27,10 @@ import {
saveSettingsPatch,
} from '../../store/telemetryStore.js';
import { CustomSelect } from '../../components/ui/CustomSelect.js';
import { SegmentedControl } from '../../components/ui/SegmentedControl.js';
import { ToggleSwitch } from '../../components/ui/ToggleSwitch.js';
import { BridgeStatusNotice } from '../../components/settings/BridgeStatusNotice.js';
import { SessionMigrationCard } from '../../components/settings/SessionMigrationCard.js';
function getEnableToggleOptions() {
return [
{ value: 'on', label: t('settings.str.on') },
{ value: 'off', label: t('settings.str.off') },
];
}
function formatQuotaReservationLogForClipboard(snapshot) {
const safe = snapshot && typeof snapshot === 'object' ? snapshot : {};
const buckets = Array.isArray(safe.buckets) ? safe.buckets : [];
@@ -275,16 +268,15 @@ export const SettingsOtherTab = defineComponent({
[createSvgIcon('copy', { size: 12 }), exportReserveLogBtnText]
);
const quotaReserveToggle = SegmentedControl({
const quotaReserveToggle = ToggleSwitch({
modelValue: 'off',
ariaLabel: t('settings.oth.quotaReserveLabel'),
options: getEnableToggleOptions(),
ariaLabelKey: 'settings.oth.quotaReserveLabel',
preset: 'enable',
onUpdateModelValue: async (val) => {
const nextEnabled = val === 'on';
draftExperimentalQuotaReservation = nextEnabled;
quotaReserveToggle.setProps({
modelValue: nextEnabled ? 'on' : 'off',
options: getEnableToggleOptions(),
});
showExpFeedback(t('settings.saving'), 0);
try {
@@ -366,10 +358,10 @@ export const SettingsOtherTab = defineComponent({
className: 'form-label',
text: t('settings.oth.ctxMainLabel'),
});
const ctxMainToggle = SegmentedControl({
const ctxMainToggle = ToggleSwitch({
modelValue: 'on',
ariaLabel: t('settings.oth.ctxMainLabel'),
options: getEnableToggleOptions(),
ariaLabelKey: 'settings.oth.ctxMainLabel',
preset: 'enable',
onUpdateModelValue: async (val) => {
if (!draftContextRiskAccepted || savingContextScope) return;
const nextEnabled = val === 'on';
@@ -396,10 +388,10 @@ export const SettingsOtherTab = defineComponent({
className: 'form-label',
text: t('settings.oth.ctxSwarmLabel'),
});
const ctxSwarmToggle = SegmentedControl({
const ctxSwarmToggle = ToggleSwitch({
modelValue: 'off',
ariaLabel: t('settings.oth.ctxSwarmLabel'),
options: getEnableToggleOptions(),
ariaLabelKey: 'settings.oth.ctxSwarmLabel',
preset: 'enable',
onUpdateModelValue: async (val) => {
if (!draftContextRiskAccepted || savingContextScope) return;
const nextEnabled = val === 'on';
@@ -519,14 +511,10 @@ export const SettingsOtherTab = defineComponent({
patchText(ctxMainLabelEl, t('settings.oth.ctxMainLabel'));
ctxMainToggle.setProps({
modelValue: draftContextMainEnabled ? 'on' : 'off',
options: getEnableToggleOptions(),
ariaLabel: t('settings.oth.ctxMainLabel'),
});
patchText(ctxSwarmLabelEl, t('settings.oth.ctxSwarmLabel'));
ctxSwarmToggle.setProps({
modelValue: draftContextSwarmEnabled ? 'on' : 'off',
options: getEnableToggleOptions(),
ariaLabel: t('settings.oth.ctxSwarmLabel'),
});
const syncErrorText =
@@ -913,8 +901,6 @@ export const SettingsOtherTab = defineComponent({
});
quotaReserveToggle.setProps({
modelValue: draftExperimentalQuotaReservation ? 'on' : 'off',
options: getEnableToggleOptions(),
ariaLabel: t('settings.oth.quotaReserveLabel'),
});
renderContextWindows();
void sessionMigrationCard.refs.ensureLoaded();
@@ -933,8 +919,6 @@ export const SettingsOtherTab = defineComponent({
patchText(exportReserveLogBtnText, t('settings.oth.exportReserveLogBtn'));
quotaReserveToggle.setProps({
modelValue: draftExperimentalQuotaReservation ? 'on' : 'off',
options: getEnableToggleOptions(),
ariaLabel: t('settings.oth.quotaReserveLabel'),
});
patchText(baselineTitleEl, t('settings.oth.baselineTitle'));
renderContextWindows();
@@ -58,6 +58,7 @@ import { buildStructurePreviewTelemetry } from '../../components/settings/struct
import { CustomNumberInput } from '../../components/ui/CustomNumberInput.js';
import { CustomSelect } from '../../components/ui/CustomSelect.js';
import { SegmentedControl } from '../../components/ui/SegmentedControl.js';
import { ToggleSwitch } from '../../components/ui/ToggleSwitch.js';
import {
CapsuleBarWidget,
buildCapsuleSlotContext,
@@ -84,20 +85,6 @@ function getMountModeOptions() {
];
}
function getMultiToggleOptions() {
return [
{ value: 'show', label: t('settings.str.show') },
{ value: 'hide', label: t('settings.str.hide') },
];
}
function getEnableToggleOptions() {
return [
{ value: 'on', label: t('settings.str.on') },
{ value: 'off', label: t('settings.str.off') },
];
}
function getPopoverWidthModeOptions() {
return [
{ value: 'auto', label: t('settings.str.popoverWidthAuto') },
@@ -520,10 +507,10 @@ export const SettingsStructureTab = defineComponent({
},
});
const multiSessionToggle = SegmentedControl({
ariaLabel: t('settings.str.multiToggle'),
const multiSessionToggle = ToggleSwitch({
ariaLabelKey: 'settings.str.multiToggle',
preset: 'visibility',
modelValue: 'show',
options: getMultiToggleOptions(),
onUpdateModelValue: (val) => {
draftShowTopbarMulti = val !== 'hide';
syncMountSectionMeta();
@@ -549,10 +536,10 @@ export const SettingsStructureTab = defineComponent({
},
});
const cliCapsuleToggle = SegmentedControl({
ariaLabel: t('settings.str.cliCapsuleToggle'),
const cliCapsuleToggle = ToggleSwitch({
ariaLabelKey: 'settings.str.cliCapsuleToggle',
preset: 'enable',
modelValue: 'on',
options: getEnableToggleOptions(),
onUpdateModelValue: (val) => {
draftEnableCliStatusLine = val !== 'off';
syncMountSectionMeta();
@@ -783,7 +770,6 @@ export const SettingsStructureTab = defineComponent({
}
multiSessionToggle.setProps({
modelValue: draftShowTopbarMulti ? 'show' : 'hide',
options: getMultiToggleOptions(),
});
contextAgentModeToggle.setProps({
modelValue: draftContextAgentMode,
@@ -794,7 +780,6 @@ export const SettingsStructureTab = defineComponent({
patchAttr(cliStatusGroupEl, 'hidden', !cliInstalled);
cliCapsuleToggle.setProps({
modelValue: draftEnableCliStatusLine ? 'on' : 'off',
options: getEnableToggleOptions(),
});
patchAttr(cliStatusDetailEl, 'hidden', !draftEnableCliStatusLine);
const effectiveCliSlots = getEffectiveDraftCliSlots();
@@ -1144,10 +1129,10 @@ export const SettingsStructureTab = defineComponent({
text: t('settings.str.stepsColsLabel'),
});
const stepTurnRailToggle = SegmentedControl({
ariaLabel: t('settings.str.stepTurnRailToggle'),
const stepTurnRailToggle = ToggleSwitch({
ariaLabelKey: 'settings.str.stepTurnRailToggle',
preset: 'visibility',
modelValue: 'hide',
options: getMultiToggleOptions(),
onUpdateModelValue: (val) => {
draftShowStepTurnRail = val !== 'hide';
syncStepsSectionMeta();
@@ -1157,10 +1142,10 @@ export const SettingsStructureTab = defineComponent({
},
});
const stepAgentBadgeToggle = SegmentedControl({
ariaLabel: t('settings.str.stepAgentBadgeToggle'),
const stepAgentBadgeToggle = ToggleSwitch({
ariaLabelKey: 'settings.str.stepAgentBadgeToggle',
preset: 'visibility',
modelValue: 'show',
options: getMultiToggleOptions(),
onUpdateModelValue: (val) => {
draftShowStepAgentBadge = val !== 'hide';
syncStepsSectionMeta();
@@ -1170,10 +1155,10 @@ export const SettingsStructureTab = defineComponent({
},
});
const stepSpeedColorToggle = SegmentedControl({
ariaLabel: t('settings.str.stepSpeedColorToggle'),
const stepSpeedColorToggle = ToggleSwitch({
ariaLabelKey: 'settings.str.stepSpeedColorToggle',
preset: 'enable',
modelValue: 'off',
options: getEnableToggleOptions(),
onUpdateModelValue: (val) => {
draftShowStepSpeedColor = val !== 'off';
syncStepsSectionMeta();
@@ -1183,10 +1168,10 @@ export const SettingsStructureTab = defineComponent({
},
});
const stepFilterToolbarToggle = SegmentedControl({
ariaLabel: t('settings.str.stepFilterToolbarToggle'),
const stepFilterToolbarToggle = ToggleSwitch({
ariaLabelKey: 'settings.str.stepFilterToolbarToggle',
preset: 'enable',
modelValue: 'off',
options: getEnableToggleOptions(),
onUpdateModelValue: (val) => {
draftShowStepFilterToolbar = val !== 'off';
syncStepsSectionMeta();
@@ -1365,19 +1350,15 @@ export const SettingsStructureTab = defineComponent({
function syncStepsSectionMeta() {
stepTurnRailToggle.setProps({
modelValue: draftShowStepTurnRail ? 'show' : 'hide',
options: getMultiToggleOptions(),
});
stepAgentBadgeToggle.setProps({
modelValue: draftShowStepAgentBadge ? 'show' : 'hide',
options: getMultiToggleOptions(),
});
stepSpeedColorToggle.setProps({
modelValue: draftShowStepSpeedColor ? 'on' : 'off',
options: getEnableToggleOptions(),
});
stepFilterToolbarToggle.setProps({
modelValue: draftShowStepFilterToolbar ? 'on' : 'off',
options: getEnableToggleOptions(),
});
if (document?.activeElement !== stepTokenComboInput) {
stepTokenComboInput.value = rawStepTokenComboText;