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:
@@ -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