mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): dual-mount topbar capsule, live multi-session HUD, and customizable topbar metrics (v1.4.3)
This commit is contained in:
@@ -10,17 +10,22 @@ import { h, patchAttr, patchClasses, patchStyleVar, patchText } from '../../core
|
||||
import { formatTokensPrecise, formatUsd } from '../../core/formatters.js';
|
||||
import { SVG_NS } from '../../icons/SvgIcon.js';
|
||||
|
||||
let chartUidCounter = 0;
|
||||
|
||||
function safeSlotTokens(v) {
|
||||
const n = Number(v);
|
||||
return Number.isFinite(n) && n > 0 ? n : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将二维采样点序列转换为水平张力平滑的三次贝塞尔曲线 SVG 路径 (`M ... C ...`)。
|
||||
* 控制点沿 X 轴取相邻点间距的 `0.42` 张力系数,Y 轴与各自端点齐平,
|
||||
* 保证曲线在极值点处平缓过渡且不会产生上下过冲 (Overshoot)。
|
||||
*
|
||||
* @param {Array<{ x: number, y: number }>} points SVG 坐标系下的采样点数组
|
||||
* @param {Array<{ x: number, y: number }>} points SVG 坐标系下的采样点数组(长度 >= 2)
|
||||
* @returns {string} SVG `<path>` 的 `d` 属性字符串
|
||||
*/
|
||||
function buildSmoothSplinePath(points) {
|
||||
if (!points.length) return '';
|
||||
if (points.length === 1) return `M ${points[0].x} ${points[0].y}`;
|
||||
let d = `M ${points[0].x.toFixed(1)} ${points[0].y.toFixed(1)}`;
|
||||
for (let i = 0; i < points.length - 1; i++) {
|
||||
const p0 = points[i];
|
||||
@@ -77,10 +82,11 @@ export function createTrendAreaChart() {
|
||||
svg.setAttribute('class', 'trend-svg');
|
||||
svg.setAttribute('aria-hidden', 'true');
|
||||
|
||||
// 垂直线性渐变
|
||||
// 垂直线性渐变(每实例独立 ID,避免多图表挂载时 SVG url(#...) 冲突)
|
||||
const gradId = `trend-area-grad-${++chartUidCounter}`;
|
||||
const defs = document.createElementNS(SVG_NS, 'defs');
|
||||
const grad = document.createElementNS(SVG_NS, 'linearGradient');
|
||||
grad.setAttribute('id', 'trend-area-grad');
|
||||
grad.setAttribute('id', gradId);
|
||||
grad.setAttribute('x1', '0');
|
||||
grad.setAttribute('y1', '0');
|
||||
grad.setAttribute('x2', '0');
|
||||
@@ -119,7 +125,7 @@ export function createTrendAreaChart() {
|
||||
svg.appendChild(vGridGroup);
|
||||
|
||||
const areaPath = document.createElementNS(SVG_NS, 'path');
|
||||
areaPath.setAttribute('fill', 'url(#trend-area-grad)');
|
||||
areaPath.setAttribute('fill', `url(#${gradId})`);
|
||||
svg.appendChild(areaPath);
|
||||
|
||||
const linePath = document.createElementNS(SVG_NS, 'path');
|
||||
@@ -202,18 +208,20 @@ export function createTrendAreaChart() {
|
||||
patchAttr(tooltipEl, 'hidden', false);
|
||||
|
||||
patchText(tipTimeEl, slot.fullLabel || slot.label || '--');
|
||||
patchText(tipCallsEl, `${Number(slot.calls || 0)} 次`);
|
||||
patchText(tipTokensEl, `${formatTokensPrecise(Number(slot.tokens || 0))} tok`);
|
||||
patchText(tipCallsEl, `${Math.max(0, Math.floor(Number(slot.calls) || 0))} 次`);
|
||||
const slotTok = safeSlotTokens(slot.tokens);
|
||||
patchText(tipTokensEl, `${formatTokensPrecise(slotTok)} tok`);
|
||||
const slotCost = Number.isFinite(Number(slot.costUsd)) ? Math.max(0, Number(slot.costUsd)) : 0;
|
||||
patchText(
|
||||
tipCostEl,
|
||||
formatUsd(Number(slot.costUsd || 0), {
|
||||
formatUsd(slotCost, {
|
||||
unpricedCalls: slot.unpricedCalls,
|
||||
precise: Number(slot.costUsd || 0) > 0 && Number(slot.costUsd || 0) < 0.1,
|
||||
precise: slotCost > 0 && slotCost < 0.1,
|
||||
})
|
||||
);
|
||||
|
||||
const hasSubBreakdown =
|
||||
Number(slot.tokens || 0) > 0 &&
|
||||
slotTok > 0 &&
|
||||
(slot.inputTokens !== undefined ||
|
||||
slot.cacheReadTokens !== undefined ||
|
||||
slot.outputTokens !== undefined);
|
||||
@@ -221,7 +229,7 @@ export function createTrendAreaChart() {
|
||||
if (hasSubBreakdown) {
|
||||
patchText(
|
||||
tipSubEl,
|
||||
`入 ${formatTokensPrecise(slot.inputTokens || 0)} · 缓 ${formatTokensPrecise(slot.cacheReadTokens || 0)} · 出 ${formatTokensPrecise(slot.outputTokens || 0)}`
|
||||
`入 ${formatTokensPrecise(safeSlotTokens(slot.inputTokens))} · 缓 ${formatTokensPrecise(safeSlotTokens(slot.cacheReadTokens))} · 出 ${formatTokensPrecise(safeSlotTokens(slot.outputTokens))}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -268,7 +276,7 @@ export function createTrendAreaChart() {
|
||||
*/
|
||||
function update(series = []) {
|
||||
const slots =
|
||||
Array.isArray(series) && series.length >= 2
|
||||
Array.isArray(series) && series.length >= 1
|
||||
? series
|
||||
: [
|
||||
{ label: '00:00', fullLabel: '00:00 - 01:00', tokens: 0, calls: 0, costUsd: 0 },
|
||||
@@ -281,7 +289,7 @@ export function createTrendAreaChart() {
|
||||
let maxTokens = 0;
|
||||
let peakIdx = 0;
|
||||
for (let i = 0; i < slots.length; i++) {
|
||||
const t = Number(slots[i].tokens || 0);
|
||||
const t = safeSlotTokens(slots[i]?.tokens);
|
||||
if (t >= maxTokens) {
|
||||
maxTokens = t;
|
||||
peakIdx = i;
|
||||
@@ -289,22 +297,32 @@ export function createTrendAreaChart() {
|
||||
}
|
||||
|
||||
const denom = Math.max(1, maxTokens);
|
||||
const isSingle = slots.length === 1;
|
||||
const pts = slots.map((s, idx) => {
|
||||
const x = LEFT_X + (idx / Math.max(1, slots.length - 1)) * SPAN_X;
|
||||
const ratio = maxTokens > 0 ? Number(s.tokens || 0) / denom : 0;
|
||||
const tok = safeSlotTokens(s?.tokens);
|
||||
const x = isSingle ? (LEFT_X + RIGHT_X) / 2 : LEFT_X + (idx / Math.max(1, slots.length - 1)) * SPAN_X;
|
||||
const ratio = maxTokens > 0 ? tok / denom : 0;
|
||||
const y = BOTTOM_Y - ratio * SPAN_Y;
|
||||
return { x, y, tokens: Number(s.tokens || 0) };
|
||||
return { x, y, tokens: tok };
|
||||
});
|
||||
currentPts = pts;
|
||||
|
||||
const sig = slots
|
||||
.map((s) => `${s.label}:${s.fullLabel || ''}:${s.tokens}:${s.costUsd}:${s.calls}`)
|
||||
.map((s) => `${s?.label || ''}:${s?.fullLabel || ''}:${safeSlotTokens(s?.tokens)}:${Number(s?.costUsd || 0)}:${Number(s?.calls || 0)}`)
|
||||
.join('|');
|
||||
|
||||
if (sig !== lastRenderSig) {
|
||||
lastRenderSig = sig;
|
||||
const lineD = buildSmoothSplinePath(pts);
|
||||
const areaD = `${lineD} L ${pts[pts.length - 1].x.toFixed(1)} ${BOTTOM_Y} L ${pts[0].x.toFixed(1)} ${BOTTOM_Y} Z`;
|
||||
let lineD;
|
||||
let areaD;
|
||||
if (isSingle) {
|
||||
const yStr = pts[0].y.toFixed(1);
|
||||
lineD = `M ${LEFT_X.toFixed(1)} ${yStr} L ${RIGHT_X.toFixed(1)} ${yStr}`;
|
||||
areaD = `${lineD} L ${RIGHT_X.toFixed(1)} ${BOTTOM_Y} L ${LEFT_X.toFixed(1)} ${BOTTOM_Y} Z`;
|
||||
} else {
|
||||
lineD = buildSmoothSplinePath(pts);
|
||||
areaD = `${lineD} L ${pts[pts.length - 1].x.toFixed(1)} ${BOTTOM_Y} L ${pts[0].x.toFixed(1)} ${BOTTOM_Y} Z`;
|
||||
}
|
||||
patchAttr(linePath, 'd', lineD);
|
||||
patchAttr(areaPath, 'd', areaD);
|
||||
|
||||
@@ -329,8 +347,8 @@ export function createTrendAreaChart() {
|
||||
vGridGroup.appendChild(vLine);
|
||||
}
|
||||
|
||||
const isFirst = i === 0;
|
||||
const isLast = i === tickIndices.length - 1;
|
||||
const isFirst = !isSingle && i === 0;
|
||||
const isLast = !isSingle && i === tickIndices.length - 1;
|
||||
const pct = (pt.x / VIEW_W) * 100;
|
||||
const tickEl = h('span', {
|
||||
className: `trend-x-tick text-mono${isFirst ? ' is-start' : isLast ? ' is-end' : ''}`,
|
||||
@@ -371,7 +389,9 @@ export function createTrendAreaChart() {
|
||||
const pctLeft = Math.max(12, Math.min(88, (peakPt.x / VIEW_W) * 100));
|
||||
patchStyleVar(peakPill, '--peak-x', `${pctLeft.toFixed(1)}%`);
|
||||
|
||||
if (hoveredIdx >= 0 && hoveredIdx < slots.length) {
|
||||
if (hoveredIdx >= slots.length) {
|
||||
clearHover();
|
||||
} else if (hoveredIdx >= 0) {
|
||||
showHoverAtIndex(hoveredIdx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,22 +113,64 @@ export const TopSessionHeader = defineComponent({
|
||||
lastActiveCascadeId = currentCascadeId;
|
||||
}
|
||||
|
||||
const actConv = telemetry?.activeConversation;
|
||||
const convs = telemetry?.conversations || [];
|
||||
const latestTitle = convs[0]?.title ? `最新 (${convs[0].title})` : '跟随最新会话';
|
||||
const hostRouteId = telSt.hostRouteConversationId || '';
|
||||
const hostMatchedConv = hostRouteId
|
||||
? convs.find((c) => c.cascadeId === hostRouteId) ||
|
||||
(actConv?.cascadeId === hostRouteId ? actConv : null)
|
||||
: null;
|
||||
const defaultOptLabel = hostRouteId
|
||||
? hostMatchedConv?.title
|
||||
? `当前窗口 (${hostMatchedConv.title})`
|
||||
: `当前窗口 (${hostRouteId.slice(0, 8)})`
|
||||
: convs[0]?.title
|
||||
? `最新 (${convs[0].title})`
|
||||
: '跟随最新会话';
|
||||
const defaultOptMeta = hostRouteId
|
||||
? hostMatchedConv
|
||||
? formatConvOptionMeta({
|
||||
stepCount: hostMatchedConv.stepCount,
|
||||
subagentCount: hostMatchedConv.subagentCount,
|
||||
totalStepCount: hostMatchedConv.totalStepCount ?? hostMatchedConv.totalStepsAllAgents,
|
||||
})
|
||||
: ''
|
||||
: convs[0]
|
||||
? formatConvOptionMeta(convs[0])
|
||||
: '';
|
||||
const options = [
|
||||
{ value: '', label: latestTitle, meta: convs[0] ? formatConvOptionMeta(convs[0]) : '' },
|
||||
{ value: '', label: defaultOptLabel, meta: defaultOptMeta },
|
||||
...convs.map((c) => ({
|
||||
value: c.cascadeId,
|
||||
label: c.title || c.cascadeId.slice(0, 8),
|
||||
meta: formatConvOptionMeta(c),
|
||||
})),
|
||||
];
|
||||
const lockedId = telSt.selectedConversationId;
|
||||
if (lockedId && !convs.some((c) => c.cascadeId === lockedId)) {
|
||||
const isLoadedLocked = actConv?.cascadeId === lockedId;
|
||||
const lockedTitle =
|
||||
isLoadedLocked && actConv?.title
|
||||
? actConv.title
|
||||
: `已锁定会话 (${String(lockedId).slice(0, 8)})`;
|
||||
const lockedMeta = isLoadedLocked
|
||||
? formatConvOptionMeta({
|
||||
stepCount: actConv.stepCount,
|
||||
subagentCount: actConv.subagentCount,
|
||||
totalStepCount: actConv.totalStepsAllAgents,
|
||||
})
|
||||
: '已锁定';
|
||||
options.splice(1, 0, {
|
||||
value: lockedId,
|
||||
label: lockedTitle,
|
||||
meta: lockedMeta,
|
||||
});
|
||||
}
|
||||
convSelect.setProps({
|
||||
modelValue: telSt.selectedConversationId,
|
||||
options,
|
||||
});
|
||||
|
||||
const actConv = telemetry?.activeConversation;
|
||||
const hasSubagents = Boolean(actConv?.hasSubagents || (actConv?.subagentCount || 0) > 0);
|
||||
const aggregated = actConv?.aggregated;
|
||||
|
||||
@@ -211,6 +253,7 @@ export const TopSessionHeader = defineComponent({
|
||||
const unsubTelemetry = telemetryStore.subscribe(
|
||||
(st) => ({
|
||||
selectedConversationId: st.selectedConversationId,
|
||||
hostRouteConversationId: st.hostRouteConversationId,
|
||||
syncState: st.syncState,
|
||||
telemetry: st.telemetry,
|
||||
}),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,14 @@
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../../core/component.js';
|
||||
import { h, patchAttr, patchClasses, patchKeyedList, patchText } from '../../core/domPatch.js';
|
||||
import {
|
||||
h,
|
||||
isEventInside,
|
||||
patchAttr,
|
||||
patchClasses,
|
||||
patchKeyedList,
|
||||
patchText,
|
||||
} from '../../core/domPatch.js';
|
||||
import { formatCompactDateTime } from '../../core/formatters.js';
|
||||
import { createSvgIcon } from '../../icons/SvgIcon.js';
|
||||
|
||||
@@ -118,9 +125,9 @@ export const CustomDateTimePicker = defineComponent({
|
||||
function adjustTime(part, delta) {
|
||||
const cur = new Date(getProps().modelValue || Date.now());
|
||||
if (part === 'hour') {
|
||||
cur.setHours((cur.getHours() + delta + 24) % 24);
|
||||
cur.setHours(cur.getHours() + delta);
|
||||
} else {
|
||||
cur.setMinutes((cur.getMinutes() + delta + 60) % 60);
|
||||
cur.setMinutes(cur.getMinutes() + delta);
|
||||
}
|
||||
const nextMs = cur.getTime();
|
||||
viewYear = cur.getFullYear();
|
||||
@@ -251,7 +258,7 @@ export const CustomDateTimePicker = defineComponent({
|
||||
}
|
||||
|
||||
const handleDocClick = (e) => {
|
||||
if (isOpen && !rootEl.contains(e.target)) {
|
||||
if (isOpen && !isEventInside(e, rootEl)) {
|
||||
togglePopover(false);
|
||||
}
|
||||
};
|
||||
@@ -267,16 +274,6 @@ export const CustomDateTimePicker = defineComponent({
|
||||
el: rootEl,
|
||||
refs: { triggerBtn, triggerText, popoverEl, daysGrid, hourValSpan, minValSpan },
|
||||
onPropsChange: syncDisplay,
|
||||
getValue: () => Number(getProps().modelValue || 0),
|
||||
methods: {
|
||||
open: () => togglePopover(true),
|
||||
close: () => togglePopover(false),
|
||||
selectDayByOffset: (daysDelta) => {
|
||||
const cur = new Date(getProps().modelValue || Date.now());
|
||||
cur.setDate(cur.getDate() + daysDelta);
|
||||
emit('update:modelValue', cur.getTime());
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import { createSvgIcon } from '../../icons/SvgIcon.js';
|
||||
|
||||
export const CustomNumberInput = defineComponent({
|
||||
name: 'CustomNumberInput',
|
||||
setup({ getProps, emit }) {
|
||||
setup({ getProps, setProps, emit }) {
|
||||
function clampValue(raw) {
|
||||
const { min = -Infinity, max = Infinity, precision = 0 } = getProps();
|
||||
const num = Number(raw);
|
||||
@@ -27,6 +27,7 @@ export const CustomNumberInput = defineComponent({
|
||||
const next = clampValue(current + direction * step * multiplier);
|
||||
syncFieldDisplay(next);
|
||||
if (next !== current) {
|
||||
setProps({ modelValue: next });
|
||||
emit('update:modelValue', next);
|
||||
}
|
||||
}
|
||||
@@ -80,11 +81,22 @@ export const CustomNumberInput = defineComponent({
|
||||
});
|
||||
|
||||
function commitManualInput() {
|
||||
const rawText = String(textField.value || '').replace(/[^0-9.-]/g, '');
|
||||
const next = clampValue(rawText);
|
||||
const raw = String(textField.value ?? '').trim();
|
||||
if (!raw || !/\d/.test(raw)) {
|
||||
syncFieldDisplay(getProps().modelValue);
|
||||
return;
|
||||
}
|
||||
const cleaned = raw.replace(/[^0-9.-]/g, '');
|
||||
const parsed = Number(cleaned);
|
||||
if (!Number.isFinite(parsed)) {
|
||||
syncFieldDisplay(getProps().modelValue);
|
||||
return;
|
||||
}
|
||||
const next = clampValue(parsed);
|
||||
const prev = Number(getProps().modelValue);
|
||||
syncFieldDisplay(next);
|
||||
if (next !== prev) {
|
||||
setProps({ modelValue: next });
|
||||
emit('update:modelValue', next);
|
||||
}
|
||||
}
|
||||
@@ -107,10 +119,8 @@ export const CustomNumberInput = defineComponent({
|
||||
el: rootEl,
|
||||
refs: { decBtn, incBtn, textField },
|
||||
onPropsChange: () => syncFieldDisplay(),
|
||||
getValue: () => clampValue(textField.value),
|
||||
methods: {
|
||||
stepUp: (mult = 1) => applyStep(1, mult),
|
||||
stepDown: (mult = 1) => applyStep(-1, mult),
|
||||
commit: () => commitManualInput(),
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @fileoverview Bespoke custom scrollbar component (零原生滚动条).
|
||||
* Hides native OS scrollbars completely and renders a precision 4px floating
|
||||
* rail + GPU-translated thumb with drag, track-jump, and modelValue ratio emit.
|
||||
* rail + GPU-translated thumb with drag and track-jump support.
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../../core/component.js';
|
||||
@@ -9,7 +9,7 @@ import { h, patchClasses, patchStyleVar } from '../../core/domPatch.js';
|
||||
|
||||
export const CustomScrollbar = defineComponent({
|
||||
name: 'CustomScrollbar',
|
||||
setup({ getProps, emit, onCleanup }) {
|
||||
setup({ getProps, onCleanup }) {
|
||||
const contentEl = getProps().contentEl || h('div');
|
||||
contentEl.classList.add('custom-scroll-content');
|
||||
|
||||
@@ -61,11 +61,6 @@ export const CustomScrollbar = defineComponent({
|
||||
|
||||
function onContentScroll() {
|
||||
syncThumb();
|
||||
const overflow = (contentEl.scrollHeight || 0) - (contentEl.clientHeight || 0);
|
||||
if (overflow > 1) {
|
||||
const ratio = +Math.max(0, Math.min(1, (contentEl.scrollTop || 0) / overflow)).toFixed(3);
|
||||
emit('update:modelValue', ratio);
|
||||
}
|
||||
}
|
||||
|
||||
function onDocMouseMove(e) {
|
||||
@@ -163,12 +158,6 @@ export const CustomScrollbar = defineComponent({
|
||||
refresh() {
|
||||
scheduleSyncThumb();
|
||||
},
|
||||
scrollToRatio(ratio) {
|
||||
const r = Math.max(0, Math.min(1, Number(ratio || 0)));
|
||||
const overflow = Math.max(0, (contentEl.scrollHeight || 0) - (contentEl.clientHeight || 0));
|
||||
contentEl.scrollTop = Math.round(r * overflow);
|
||||
syncThumb();
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -4,12 +4,19 @@
|
||||
*/
|
||||
|
||||
import { defineComponent } from '../../core/component.js';
|
||||
import { h, patchAttr, patchClasses, patchKeyedList, patchText } from '../../core/domPatch.js';
|
||||
import {
|
||||
h,
|
||||
isEventInside,
|
||||
patchAttr,
|
||||
patchClasses,
|
||||
patchKeyedList,
|
||||
patchText,
|
||||
} from '../../core/domPatch.js';
|
||||
import { createSvgIcon, patchSvgIcon } from '../../icons/SvgIcon.js';
|
||||
|
||||
export const CustomSelect = defineComponent({
|
||||
name: 'CustomSelect',
|
||||
setup({ getProps, emit, onCleanup }) {
|
||||
setup({ getProps, setProps, emit, onCleanup }) {
|
||||
let isOpen = false;
|
||||
let focusedIndex = -1;
|
||||
|
||||
@@ -67,6 +74,7 @@ export const CustomSelect = defineComponent({
|
||||
const prevVal = getProps().modelValue;
|
||||
toggleOpen(false);
|
||||
if (option.value !== prevVal) {
|
||||
setProps({ modelValue: option.value });
|
||||
emit('update:modelValue', option.value);
|
||||
}
|
||||
}
|
||||
@@ -82,6 +90,7 @@ export const CustomSelect = defineComponent({
|
||||
} else {
|
||||
focusedIndex = (focusedIndex + 1) % opts.length;
|
||||
renderMenuOptions();
|
||||
menuEl.children[focusedIndex]?.scrollIntoView?.({ block: 'nearest' });
|
||||
}
|
||||
} else if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
@@ -90,6 +99,7 @@ export const CustomSelect = defineComponent({
|
||||
} else {
|
||||
focusedIndex = (focusedIndex - 1 + opts.length) % opts.length;
|
||||
renderMenuOptions();
|
||||
menuEl.children[focusedIndex]?.scrollIntoView?.({ block: 'nearest' });
|
||||
}
|
||||
} else if (e.key === 'Enter' && isOpen) {
|
||||
e.preventDefault();
|
||||
@@ -150,17 +160,17 @@ export const CustomSelect = defineComponent({
|
||||
if (icon) {
|
||||
patchSvgIcon(leadIcon, icon);
|
||||
}
|
||||
const selectedOpt =
|
||||
options.find((o) => o.value === modelValue) ||
|
||||
(!modelValue ? options[0] : undefined);
|
||||
patchText(triggerLabel, selectedOpt ? selectedOpt.label : placeholder);
|
||||
const matchedOpt = options.find((o) => o.value === modelValue);
|
||||
const selectedOpt = matchedOpt || (!modelValue ? options[0] : undefined);
|
||||
const fallbackText = modelValue ? `${placeholder} (${String(modelValue).slice(0, 8)})` : placeholder;
|
||||
patchText(triggerLabel, selectedOpt ? selectedOpt.label : fallbackText);
|
||||
if (isOpen) {
|
||||
renderMenuOptions();
|
||||
}
|
||||
}
|
||||
|
||||
const handleDocClick = (e) => {
|
||||
if (isOpen && !rootEl.contains(e.target)) {
|
||||
if (isOpen && !isEventInside(e, rootEl)) {
|
||||
toggleOpen(false);
|
||||
}
|
||||
};
|
||||
@@ -176,14 +186,8 @@ export const CustomSelect = defineComponent({
|
||||
el: rootEl,
|
||||
refs: { triggerBtn, triggerLabel, menuEl },
|
||||
onPropsChange: syncTriggerAndMenu,
|
||||
getValue: () => getProps().modelValue,
|
||||
methods: {
|
||||
open: () => toggleOpen(true),
|
||||
close: () => toggleOpen(false),
|
||||
selectByValue: (val) => {
|
||||
const found = (getProps().options || []).find((o) => o.value === val);
|
||||
if (found) chooseOption(found);
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ import { h, patchAttr, patchClasses, patchKeyedList, patchText } from '../../cor
|
||||
|
||||
export const SegmentedControl = defineComponent({
|
||||
name: 'SegmentedControl',
|
||||
setup({ getProps, emit }) {
|
||||
setup({ getProps, setProps, emit }) {
|
||||
const rootEl = h('div', {
|
||||
className: 'segmented',
|
||||
role: 'group',
|
||||
@@ -27,6 +27,7 @@ export const SegmentedControl = defineComponent({
|
||||
onClick: (e) => {
|
||||
e.stopPropagation();
|
||||
if (getProps().modelValue !== opt.value) {
|
||||
setProps({ modelValue: opt.value });
|
||||
emit('update:modelValue', opt.value);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user