refactor: rebuild desktop app with Tauri

This commit is contained in:
leookun committed 2026-08-24 02:49:00 +08:00
1 parent a3ec2a0dfc
commit 4053a7fb20
808 files changed
+87359 -181491

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
import type { ButtonHTMLAttributes } from "react";
import controls from "./Controls.module.scss";
export type ButtonVariant = "primary" | "secondary";
export type ButtonSize = "medium" | "small";
export function Button({
variant = "secondary",
size = "medium",
className,
type = "button",
...props
}: ButtonHTMLAttributes<HTMLButtonElement> & {
variant?: ButtonVariant;
size?: ButtonSize;
}) {
return (
<button
{...props}
type={type}
className={[controls[variant], size === "small" && controls.small, className].filter(Boolean).join(" ")}
/>
);
}
@@ -0,0 +1,6 @@
.root {
padding: 0;
background: var(--vscode-editorWidget-background);
border: 1px solid var(--vscode-sideBar-border);
border-radius: var(--oa-card-radius);
}
+12
View File
@@ -0,0 +1,12 @@
import type { ElementType, ReactNode } from "react";
import styles from "./Card.module.scss";
type CardProps = {
as?: ElementType;
className?: string;
children: ReactNode;
};
export function Card({ as: Component = "div", className, children }: CardProps) {
return <Component className={[styles.root, className].filter(Boolean).join(" ")}>{children}</Component>;
}
@@ -0,0 +1,47 @@
@use "../../styles/typography" as type;
.root {
width: fit-content;
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--vscode-foreground);
font-size: type.$font-size-xs;
cursor: pointer;
input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
pointer-events: none;
}
&:has(input:focus-visible) .control {
outline: 1px solid var(--vscode-focusBorder);
outline-offset: 2px;
}
&:has(input:checked) .control {
color: var(--vscode-button-foreground);
background: var(--vscode-button-background);
border-color: var(--vscode-button-background);
}
&:has(input:disabled) {
opacity: 0.55;
cursor: default;
}
}
.control {
width: 16px;
height: 16px;
flex: 0 0 16px;
display: grid;
place-items: center;
color: var(--vscode-checkbox-foreground, var(--vscode-button-foreground));
background: var(--vscode-checkbox-background, var(--vscode-input-background));
border: 1px solid var(--vscode-checkbox-border, var(--vscode-input-border));
border-radius: 3px;
}
@@ -0,0 +1,16 @@
import { Icon } from "./Icon";
import { checkIcon } from "./icons";
import styles from "./Checkbox.module.scss";
export function Checkbox({ checked, disabled, label, onChange }: {
checked: boolean;
disabled?: boolean;
label: string;
onChange: (checked: boolean) => void;
}) {
return <label className={styles.root}>
<input type="checkbox" checked={checked} disabled={disabled} onChange={(event) => onChange(event.target.checked)} />
<span className={styles.control} aria-hidden="true">{checked && <Icon icon={checkIcon} size="0.875em" />}</span>
<span>{label}</span>
</label>;
}
@@ -0,0 +1,70 @@
.primary {
min-height: 30px;
display: inline-flex;
align-items: center;
gap: 6px;
padding: 0 11px;
color: var(--vscode-button-foreground);
background: var(--vscode-button-background);
border: 0;
border-radius: 5px;
}
.secondary {
min-height: 34px;
height: 34px;
display: inline-flex;
align-items: center;
gap: 6px;
padding: 0 9px;
color: var(--vscode-input-foreground);
background: var(--vscode-input-background);
border: 1px solid var(--vscode-input-border, var(--vscode-sideBar-border));
border-radius: 6px;
white-space: nowrap;
&:hover { background: var(--vscode-list-hoverBackground); }
&:disabled { opacity: .5; cursor: not-allowed; }
}
.small {
min-height: 24px;
height: 24px;
padding-inline: 7px;
border-radius: 4px;
}
.iconButton {
width: 30px;
height: 30px;
display: grid;
place-items: center;
padding: 0;
color: inherit;
text-decoration: none;
background: transparent;
border: 0;
border-radius: 5px;
&:hover {
background: var(--vscode-list-hoverBackground);
}
&:disabled {
opacity: 0.5;
cursor: default;
}
}
.danger:hover {
color: var(--vscode-errorForeground, #f48771);
}
.spin {
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@@ -0,0 +1,108 @@
@use "../../styles/typography" as type;
.root {
width: 100%;
height: 100%;
min-width: 0;
min-height: 0;
display: flex;
flex-direction: column;
gap: 6px;
}
.tableRegion {
position: relative;
flex: 1 1 auto;
min-width: 0;
min-height: 0;
display: flex;
overflow: hidden;
background: var(--vscode-editorWidget-background);
border: 1px solid var(--vscode-sideBar-border);
border-radius: var(--oa-card-radius);
}
.viewport {
position: relative;
flex: 1 1 auto;
width: 100%;
min-width: 0;
min-height: 0;
overflow: hidden;
}
.tableViewport {
overflow-x: auto;
}
.tableContent {
width: max-content;
min-width: 100%;
}
.emptyViewport {
min-height: 0;
}
.emptyState {
position: absolute;
z-index: 4;
inset: 33px 0 0;
display: flex;
align-items: center;
justify-content: center;
color: var(--vscode-descriptionForeground);
font-size: type.$font-size-base;
pointer-events: none;
}
.table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
font-size: type.$font-size-base;
th,
td {
max-width: 220px;
height: 36px;
padding: 0 12px;
overflow: hidden;
text-align: left;
text-overflow: ellipsis;
white-space: nowrap;
border-bottom: 1px solid var(--vscode-sideBar-border);
}
th {
position: sticky;
top: 0;
z-index: 2;
height: 33px;
color: var(--vscode-descriptionForeground);
background: var(--vscode-editor-background);
font-size: type.$font-size-xs;
font-weight: 400;
}
tbody tr:hover td {
background: var(--vscode-list-hoverBackground);
}
}
.stickyRight {
position: sticky;
right: 0;
z-index: 1;
width: 72px;
min-width: 72px;
background: var(--vscode-editor-background);
}
thead .stickyRight {
z-index: 3;
}
tbody .stickyRight {
background: var(--vscode-editorWidget-background);
}
@@ -0,0 +1,43 @@
import { useEffect, useMemo, useState, type ReactNode } from "react";
import { ScrollableContent } from "../virtual/ScrollableContent";
import { Pagination } from "./Pagination";
import styles from "./DataTable.module.scss";
export type DataTableColumn<T> = {
key: string;
header: ReactNode;
render: (row: T) => ReactNode;
title?: (row: T) => string | undefined;
className?: string;
sticky?: "right";
};
export function DataTable<T>({ rows, columns, rowKey, minWidth, emptyText = t("暂无数据") }: {
rows: T[];
columns: DataTableColumn<T>[];
rowKey: (row: T) => string | number;
minWidth?: number | string;
emptyText?: ReactNode;
}) {
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(20);
const pageCount = Math.max(1, Math.ceil(rows.length / pageSize));
useEffect(() => { if (page > pageCount) setPage(pageCount); }, [page, pageCount]);
const pageRows = useMemo(() => rows.slice((page - 1) * pageSize, page * pageSize), [page, pageSize, rows]);
return <div className={styles.root}>
<div className={styles.tableRegion}>
<ScrollableContent horizontal className={[styles.viewport, rows.length === 0 ? styles.emptyViewport : ""].filter(Boolean).join(" ")} viewportClassName={styles.tableViewport} contentClassName={styles.tableContent} scrollbarInsetTop="33px">
<table className={styles.table} style={{ minWidth }}>
<thead><tr>{columns.map((column) => <th key={column.key} className={columnClass(column)}>{column.header}</th>)}</tr></thead>
<tbody>{pageRows.map((row) => <tr key={rowKey(row)}>{columns.map((column) => <td key={column.key} className={columnClass(column)} title={column.title?.(row)}>{column.render(row)}</td>)}</tr>)}</tbody>
</table>
</ScrollableContent>
{rows.length === 0 && <div className={styles.emptyState}>{emptyText}</div>}
</div>
<Pagination page={page} pageCount={pageCount} pageSize={pageSize} total={rows.length} onPageChange={setPage} onPageSizeChange={(nextPageSize) => { setPageSize(nextPageSize); setPage(1); }} />
</div>;
}
function columnClass<T>(column: DataTableColumn<T>) {
return [column.className, column.sticky === "right" ? styles.stickyRight : ""].filter(Boolean).join(" ") || undefined;
}
@@ -0,0 +1,23 @@
@use "../../styles/typography" as type;
.root {
display: grid;
gap: 6px;
color: var(--vscode-descriptionForeground);
font-size: type.$font-size-xs;
input {
width: 100%;
height: 32px;
padding: 0 9px;
color: var(--vscode-input-foreground);
background: var(--vscode-input-background);
border: 1px solid var(--vscode-input-border);
border-radius: 5px;
outline: 0;
&:focus {
border-color: var(--vscode-focusBorder);
}
}
}
+5
View File
@@ -0,0 +1,5 @@
import styles from "./Field.module.scss";
export function Field({ label, value, onChange, type = "text" }: { label: string; value: string; onChange: (value: string) => void; type?: string }) {
return <label className={styles.root}><span>{label}</span><input type={type} value={value} onChange={(event) => onChange(event.target.value)} /></label>;
}
@@ -0,0 +1,50 @@
@use "../../styles/typography" as type;
.field {
min-width: 0;
display: flex;
flex-direction: column;
gap: 6px;
color: var(--vscode-descriptionForeground);
font-size: type.$font-size-xs;
}
.label {
min-height: 20px;
display: flex;
align-items: center;
gap: 5px;
line-height: 20px;
}
.hint {
display: flex;
align-items: center;
justify-content: center;
color: var(--vscode-descriptionForeground);
cursor: help;
&:hover {
color: var(--vscode-foreground);
}
}
.input {
width: 100%;
color: var(--vscode-input-foreground);
background: var(--vscode-input-background);
border: 1px solid var(--vscode-input-border, transparent);
border-radius: 5px;
outline: none;
font: inherit;
&:focus {
border-color: var(--vscode-focusBorder);
}
&:disabled {
opacity: 0.6;
}
}
.input {
height: 34px;
padding: 0 10px;
}
@@ -0,0 +1,19 @@
import type { InputHTMLAttributes } from "react";
import { Icon } from "./Icon";
import { TooltipTrigger } from "./TooltipTrigger";
import { informationOutlineIcon } from "./icons";
import styles from "./FormControls.module.scss";
export function TextInput(props: InputHTMLAttributes<HTMLInputElement>) {
return <input {...props} className={[styles.input, props.className].filter(Boolean).join(" ")} />;
}
export function FormField({ label, hint, className, children }: { label: string; hint?: string; className?: string; children: React.ReactNode }) {
return <label className={[styles.field, className].filter(Boolean).join(" ")}>
<div className={styles.label}>
<div>{label}</div>
{hint && <TooltipTrigger label={hint}><div className={styles.hint}><Icon icon={informationOutlineIcon} size="1.1em" /></div></TooltipTrigger>}
</div>
{children}
</label>;
}
@@ -0,0 +1,15 @@
.icon {
flex: 0 0 auto;
display: flex;
align-items: center;
justify-content: center;
width: 1em;
height: 1em;
line-height: 1;
img {
width: 100%;
height: 100%;
display: block;
}
}
+19
View File
@@ -0,0 +1,19 @@
import { Icon as IconifyIcon, type IconifyIcon as IconData } from "@iconify/react/offline";
import styles from "./Icon.module.scss";
export interface IconProps {
icon?: IconData;
src?: string;
size?: `${number}em`;
className?: string;
}
export function Icon({ icon, src, size = "1em", className }: IconProps) {
return <div
aria-hidden="true"
className={[styles.icon, className].filter(Boolean).join(" ")}
style={{ height: size, width: size }}
>
{src ? <img alt="" src={src} /> : icon ? <IconifyIcon height="100%" icon={icon} width="100%" /> : null}
</div>;
}
@@ -0,0 +1,57 @@
@use "../../styles/typography" as type;
.root {
--json-editor-font-size: #{type.$font-size-2xs};
width: 100%;
height: 150px;
min-width: 0;
position: relative;
overflow: hidden;
background: var(--vscode-input-background);
border: 1px solid var(--vscode-input-border, transparent);
border-radius: 5px;
&:focus-within {
border-color: var(--vscode-focusBorder);
}
}
.detail {
height: 320px;
}
.toolbar {
position: absolute;
z-index: 5;
top: 5px;
right: 12px;
display: flex;
align-items: center;
justify-content: center;
color: var(--vscode-descriptionForeground);
background: var(--vscode-editorWidget-background);
border: 1px solid var(--vscode-editorWidget-border, var(--vscode-input-border));
border-radius: 5px;
box-shadow: 0 2px 6px color-mix(in srgb, #000 22%, transparent);
}
.formatButton {
padding: 2px 4px;
color: inherit;
background: transparent;
border: 0;
border-radius: 4px;
font-size: type.$font-size-xs;
&:hover {
color: var(--vscode-foreground);
background: var(--vscode-list-hoverBackground);
}
}
.host {
width: 100%;
height: 100%;
min-height: 0;
}
@@ -0,0 +1,232 @@
import { useEffect, useRef } from "react";
import type * as Monaco from "monaco-editor/editor/editor.api";
import EditorWorker from "monaco-editor/editor/editor.worker?worker";
import JsonWorker from "monaco-editor/language/json/json.worker?worker";
import styles from "./JsonEditor.module.scss";
type MonacoApi = typeof Monaco;
let monacoPromise: Promise<MonacoApi> | null = null;
function loadMonaco() {
if (!monacoPromise) {
self.MonacoEnvironment = {
getWorker: (_moduleId, label) => label === "json" ? new JsonWorker() : new EditorWorker(),
};
monacoPromise = Promise.all([
import("monaco-editor/editor/editor.api"),
import("monaco-editor/language/json/monaco.contribution"),
]).then(([monaco]) => monaco);
}
return monacoPromise;
}
function json(value: string) {
try {
return JSON.stringify(JSON.parse(value), null, 2);
} catch {
return null;
}
}
export function formatStructuredText(value: string) {
const whole = json(value);
if (whole !== null) return whole;
let changed = false;
const formatted = value.split("\n").map((line) => {
const match = /^(\s*data:\s*)(.*)$/.exec(line);
if (!match || match[2] === "[DONE]") return line;
const payload = json(match[2]);
if (payload === null) return line;
changed = true;
return `${match[1]}${payload}`;
}).join("\n");
return changed ? formatted : value;
}
function hexByte(value: number) {
return Math.round(Math.min(255, Math.max(0, value))).toString(16).padStart(2, "0");
}
function monacoColor(value: string, fallback: string) {
const color = value.trim() || fallback;
const hex = /^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.exec(color);
if (hex) {
const digits = hex[1];
return digits.length <= 4
? `#${[...digits].map((digit) => digit.repeat(2)).join("")}`
: `#${digits}`;
}
const rgb = /^rgba?\((.*)\)$/i.exec(color);
if (rgb) {
const parts = rgb[1].replace(/\s*[,/]\s*/g, " ").trim().split(/\s+/);
if (parts.length === 3 || parts.length === 4) {
const channels = parts.slice(0, 3).map((part) => {
const number = Number.parseFloat(part);
return part.endsWith("%") ? number * 2.55 : number;
});
const alphaPart = parts[3];
const alpha = alphaPart == null
? 255
: (alphaPart.endsWith("%") ? Number.parseFloat(alphaPart) / 100 : Number.parseFloat(alphaPart)) * 255;
if ([...channels, alpha].every(Number.isFinite)) {
return `#${channels.map(hexByte).join("")}${alpha === 255 ? "" : hexByte(alpha)}`;
}
}
}
return fallback;
}
function themeColor(styles: CSSStyleDeclaration, name: string, fallback: string) {
return monacoColor(styles.getPropertyValue(name), fallback);
}
function applyEditorTheme(monaco: MonacoApi) {
const rootStyles = getComputedStyle(document.documentElement);
const light = document.documentElement.dataset.theme === "default-light";
monaco.editor.defineTheme("cursor-byok", {
base: light ? "vs" : "vs-dark",
inherit: true,
rules: [],
colors: {
"editor.background": themeColor(rootStyles, "--vscode-input-background", light ? "#ffffff" : "#222222"),
"editor.foreground": themeColor(rootStyles, "--vscode-input-foreground", light ? "#202020" : "#ffffffe6"),
"editorCursor.foreground": themeColor(rootStyles, "--vscode-editorCursor-foreground", light ? "#202020" : "#ffffff"),
"editorLineNumber.foreground": themeColor(rootStyles, "--vscode-editorLineNumber-foreground", light ? "#999999" : "#ffffff40"),
"editorLineNumber.activeForeground": themeColor(rootStyles, "--vscode-editorLineNumber-activeForeground", light ? "#202020" : "#ffffffe6"),
"editor.selectionBackground": themeColor(rootStyles, "--vscode-editor-selectionBackground", light ? "#0069cc33" : "#49b0ff33"),
},
});
monaco.editor.setTheme("cursor-byok");
}
export function JsonEditor({ value, onChange, readOnly = false, autoFormat = true, detail = false, ariaLabel }: {
value: string;
onChange?: (value: string) => void;
readOnly?: boolean;
autoFormat?: boolean;
detail?: boolean;
ariaLabel: string;
}) {
const rootRef = useRef<HTMLDivElement>(null);
const hostRef = useRef<HTMLDivElement>(null);
const editorRef = useRef<Monaco.editor.IStandaloneCodeEditor | null>(null);
const modelRef = useRef<Monaco.editor.ITextModel | null>(null);
const onChangeRef = useRef(onChange);
const valueRef = useRef(value);
const readOnlyRef = useRef(readOnly);
const autoFormatRef = useRef(autoFormat);
const ariaLabelRef = useRef(ariaLabel);
const changingRef = useRef(false);
onChangeRef.current = onChange;
valueRef.current = value;
readOnlyRef.current = readOnly;
autoFormatRef.current = autoFormat;
ariaLabelRef.current = ariaLabel;
const format = () => {
const model = modelRef.current;
if (!model) return;
const formatted = formatStructuredText(model.getValue());
if (formatted === model.getValue()) return;
changingRef.current = true;
model.setValue(formatted);
changingRef.current = false;
onChangeRef.current?.(formatted);
};
useEffect(() => {
const host = hostRef.current;
const root = rootRef.current;
if (!host || !root) return;
let disposed = false;
let contentSubscription: Monaco.IDisposable | null = null;
let blurSubscription: Monaco.IDisposable | null = null;
let themeObserver: MutationObserver | null = null;
void loadMonaco().then((monaco) => {
if (disposed) return;
applyEditorTheme(monaco);
const rootStyles = getComputedStyle(root);
const fontSize = Number.parseFloat(rootStyles.getPropertyValue("--json-editor-font-size"));
const fontFamily = rootStyles.getPropertyValue("--oa-code-font").trim();
const initialValue = autoFormatRef.current ? formatStructuredText(valueRef.current) : valueRef.current;
const model = monaco.editor.createModel(initialValue, "json");
const editor = monaco.editor.create(host, {
model,
theme: "cursor-byok",
ariaLabel: ariaLabelRef.current,
readOnly: readOnlyRef.current,
domReadOnly: readOnlyRef.current,
automaticLayout: true,
fontFamily: fontFamily || undefined,
fontSize: Number.isFinite(fontSize) ? fontSize : undefined,
minimap: { enabled: false },
glyphMargin: false,
folding: true,
lineNumbersMinChars: 3,
overviewRulerLanes: 0,
overviewRulerBorder: false,
renderLineHighlight: "none",
scrollBeyondLastLine: false,
smoothScrolling: true,
wordWrap: "off",
padding: { top: 8, bottom: 16 },
stickyScroll: { enabled: false },
contextmenu: true,
formatOnPaste: !readOnlyRef.current,
formatOnType: !readOnlyRef.current,
scrollbar: { alwaysConsumeMouseWheel: false },
});
editorRef.current = editor;
modelRef.current = model;
const remeasure = () => {
if (disposed) return;
monaco.editor.remeasureFonts();
editor.layout();
};
requestAnimationFrame(remeasure);
void document.fonts?.ready.then(remeasure);
contentSubscription = model.onDidChangeContent(() => {
if (!changingRef.current) onChangeRef.current?.(model.getValue());
});
blurSubscription = editor.onDidBlurEditorWidget(() => {
if (!readOnlyRef.current && autoFormatRef.current) format();
});
themeObserver = new MutationObserver(() => applyEditorTheme(monaco));
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
});
return () => {
disposed = true;
themeObserver?.disconnect();
blurSubscription?.dispose();
contentSubscription?.dispose();
editorRef.current?.dispose();
modelRef.current?.dispose();
editorRef.current = null;
modelRef.current = null;
};
}, []);
useEffect(() => {
const model = modelRef.current;
const next = readOnly && autoFormat ? formatStructuredText(value) : value;
if (!model || model.getValue() === next) return;
changingRef.current = true;
model.setValue(next);
changingRef.current = false;
}, [autoFormat, readOnly, value]);
useEffect(() => {
editorRef.current?.updateOptions({ readOnly, domReadOnly: readOnly, ariaLabel });
}, [ariaLabel, readOnly]);
return <div ref={rootRef} className={[styles.root, detail && styles.detail].filter(Boolean).join(" ")}>
<div className={styles.toolbar}>
<button type="button" className={styles.formatButton} onClick={format}>{t("格式化")}</button>
</div>
<div ref={hostRef} className={styles.host} />
</div>;
}
@@ -0,0 +1,57 @@
@use "../../styles/typography" as type;
.region {
position: fixed;
z-index: 11000;
top: calc(48px + env(safe-area-inset-top));
right: 0;
left: 0;
display: flex;
justify-content: center;
padding: 0 16px;
pointer-events: none;
}
.message {
max-width: min(520px, calc(100vw - 32px));
padding: 10px 16px;
color: var(--vscode-notifications-foreground);
background: var(--vscode-notifications-background);
border: 1px solid var(--vscode-notifications-border);
border-radius: var(--oa-overlay-radius);
box-shadow: 0 10px 30px rgb(0 0 0 / 38%);
font-size: type.$font-size-base;
line-height: 20px;
text-align: center;
overflow-wrap: anywhere;
pointer-events: auto;
-webkit-user-select: text;
user-select: text;
cursor: text;
animation: enter 200ms ease;
transition: opacity 200ms ease, transform 200ms ease;
}
.leaving {
opacity: 0;
transform: translateY(-8px);
}
@keyframes enter {
from {
opacity: 0;
transform: translateY(-8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (prefers-reduced-motion: reduce) {
.message {
animation: none;
transition: none;
}
}
@@ -0,0 +1,19 @@
import { useSyncExternalStore } from "react";
import { createPortal } from "react-dom";
import { getMessageSnapshot, subscribeToMessages } from "./message";
import styles from "./MessageProvider.module.scss";
export function MessageProvider() {
const { current } = useSyncExternalStore(subscribeToMessages, getMessageSnapshot);
return createPortal(
<div className={styles.region} aria-live="polite" aria-atomic="true">
{current && (
<div key={current.id} className={`${styles.message} ${current.leaving ? styles.leaving : ""}`} role="status">
{current.content}
</div>
)}
</div>,
document.body,
);
}
@@ -0,0 +1,68 @@
@use "../../styles/typography" as type;
.mask {
position: fixed;
z-index: 13000;
inset: 0;
display: grid;
place-items: center;
padding: var(--window-header-height) 24px 24px;
background: rgb(0 0 0 / 52%);
}
.dragLayer {
position: absolute;
z-index: 0;
top: 0;
right: 0;
left: 0;
height: var(--window-header-height);
}
.dialog {
position: relative;
z-index: 1;
width: min(620px, calc(100vw - 48px));
max-height: calc(100vh - var(--window-header-height) - 24px);
display: flex;
flex-direction: column;
overflow: hidden;
color: var(--vscode-foreground);
background: var(--vscode-editorWidget-background);
border: 1px solid var(--vscode-editorWidget-border);
border-radius: var(--oa-overlay-radius);
box-shadow: 0 20px 50px rgb(0 0 0 / 45%);
header {
padding: 10px 18px;
border-bottom: 1px solid var(--vscode-editorWidget-border);
font-size: type.$font-size-base;
font-weight: 630;
}
footer {
display: flex;
justify-content: flex-end;
gap: 8px;
padding: 10px 18px;
border-top: 1px solid var(--vscode-editorWidget-border);
}
}
.wide {
width: min(1080px, calc(100vw - 48px));
}
.body {
flex: 0 1 auto;
min-height: 0;
max-height: calc(100vh - var(--window-header-height) - 112px);
}
.bodyViewport {
height: auto;
max-height: calc(100vh - var(--window-header-height) - 112px);
}
.bodyContent {
padding: 18px;
}
+36
View File
@@ -0,0 +1,36 @@
import { useEffect, useRef, type ReactNode } from "react";
import { createPortal } from "react-dom";
import { ScrollableContent } from "../virtual/ScrollableContent";
import controls from "./Controls.module.scss";
import styles from "./Modal.module.scss";
export function Modal({ id, open, title, children, busy, wide, onClose, onSubmit, closeLabel = t("取消"), submitLabel = t("保存") }: { id?: string; open: boolean; title: string; children: ReactNode; busy?: boolean; wide?: boolean; onClose: () => void; onSubmit?: () => void; closeLabel?: string; submitLabel?: string }) {
const dialog = useRef<HTMLDivElement>(null);
const closeRef = useRef(onClose);
const busyRef = useRef(Boolean(busy));
closeRef.current = onClose;
busyRef.current = Boolean(busy);
useEffect(() => {
if (!open) return;
const previous = document.activeElement as HTMLElement | null;
const onKey = (event: KeyboardEvent) => { if (event.key === "Escape" && !busyRef.current) closeRef.current(); };
document.addEventListener("keydown", onKey);
requestAnimationFrame(() => dialog.current?.querySelector<HTMLElement>("input,button")?.focus());
return () => {
document.removeEventListener("keydown", onKey);
if (previous && document.contains(previous)) previous.focus();
};
}, [open]);
if (!open) return null;
return createPortal(<div className={styles.mask}>
<div className={styles.dragLayer} data-tauri-drag-region aria-hidden="true" />
<div id={id} ref={dialog} className={[styles.dialog, wide && styles.wide].filter(Boolean).join(" ")} role="dialog" aria-modal="true" aria-label={title}>
<header>{title}</header>
<ScrollableContent alwaysShowVertical className={styles.body} viewportClassName={styles.bodyViewport} contentClassName={styles.bodyContent}>{children}</ScrollableContent>
<footer>
<button type="button" className={controls.primary} disabled={busy} onClick={onClose}>{closeLabel}</button>
{onSubmit && <button type="button" className={controls.primary} disabled={busy} onClick={onSubmit}>{busy ? t("处理中…") : submitLabel}</button>}
</footer>
</div>
</div>, document.body);
}
@@ -0,0 +1,139 @@
@use "../../styles/typography" as type;
.target {
width: 100%;
height: 32px;
display: flex;
align-items: center;
overflow: hidden;
background: var(--vscode-input-background);
border: 1px solid var(--vscode-input-border, transparent);
border-radius: 5px;
&:focus-within,
&[data-open] { border-color: var(--vscode-focusBorder); }
}
.trigger {
min-width: 0;
height: 100%;
flex: 1;
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 8px;
padding: 0 8px;
color: var(--vscode-input-foreground);
background: transparent;
border: 0;
font-size: type.$font-size-xs;
text-align: left;
}
.clear {
width: 30px;
height: 100%;
flex: 0 0 30px;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
color: var(--vscode-descriptionForeground);
background: transparent;
border: 0;
&:hover { color: var(--vscode-foreground); background: var(--vscode-list-hoverBackground); }
}
.summary {
overflow: hidden;
color: var(--vscode-descriptionForeground);
text-align: right;
text-overflow: ellipsis;
white-space: nowrap;
}
.menu {
position: fixed;
z-index: 14001;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 4px;
background: var(--vscode-dropdown-background);
border: 1px solid var(--vscode-dropdown-border);
border-radius: var(--oa-overlay-radius);
box-shadow: var(--oa-dropdown-shadow);
button {
width: 100%;
min-height: 32px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 5px 8px;
color: var(--vscode-dropdown-foreground);
background: transparent;
border: 0;
border-radius: 4px;
font-size: type.$font-size-xs;
&:hover {
color: var(--vscode-list-hoverForeground, var(--vscode-dropdown-foreground));
background: var(--vscode-list-hoverBackground);
}
&[aria-selected="true"] {
color: var(--vscode-list-activeSelectionForeground);
background: var(--vscode-list-activeSelectionBackground);
}
&[aria-selected="true"]:hover {
background: var(--vscode-list-inactiveSelectionBackground, var(--vscode-list-activeSelectionBackground));
}
}
}
.listFrame,
.list {
min-height: 32px;
min-width: 0;
}
.listFrame {
flex: 0 1 auto;
overflow: hidden;
}
.option {
min-width: 0;
display: flex;
align-items: center;
gap: 8px;
> span:last-child {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.check { width: 1.1em; flex: 0 0 1.1em; }
.empty { padding: 8px; color: var(--vscode-descriptionForeground); font-size: type.$font-size-xs; }
.footer {
display: flex;
justify-content: flex-end;
gap: 4px;
margin-top: 4px;
padding-top: 4px;
border-top: 1px solid var(--vscode-dropdown-border);
button {
width: auto;
min-height: 28px;
justify-content: center;
color: var(--vscode-textLink-foreground);
}
}
@@ -0,0 +1,127 @@
import { autoUpdate, computePosition, flip, offset, shift, size } from "@floating-ui/dom";
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
import { createPortal } from "react-dom";
import { Icon, type IconProps } from "./Icon";
import { checkIcon, chevronDownIcon, windowCloseIcon } from "./icons";
import { VirtualList } from "../virtual/VirtualList";
import styles from "./MultiSelect.module.scss";
export type MultiSelectOption = {
value: string;
label: string;
icon?: IconProps["icon"];
};
export function MultiSelect({ label, value, options, onChange }: {
label: string;
value: string[];
options: MultiSelectOption[];
onChange: (value: string[]) => void;
}) {
const root = useRef<HTMLDivElement>(null);
const trigger = useRef<HTMLButtonElement>(null);
const menu = useRef<HTMLDivElement>(null);
const firstOption = useRef<HTMLButtonElement>(null);
const menuId = useId();
const [open, setOpen] = useState(false);
const [position, setPosition] = useState({ left: 0, top: 0, width: 220, maxHeight: 280 });
useLayoutEffect(() => {
if (!open || !root.current || !menu.current) return;
return autoUpdate(root.current, menu.current, () => void computePosition(root.current!, menu.current!, {
placement: "bottom-start",
middleware: [offset(5), flip({ padding: 10 }), shift({ padding: 10 }), size({
padding: 10,
apply: ({ rects, availableHeight }) => setPosition((current) => ({
...current,
width: rects.reference.width,
maxHeight: Math.max(120, availableHeight),
})),
})],
}).then(({ x, y }) => setPosition((current) => ({ ...current, left: x, top: y }))));
}, [open]);
useEffect(() => {
if (!open) return;
firstOption.current?.focus();
const closeOutside = (event: PointerEvent) => {
const target = event.target as Node;
if (!root.current?.contains(target) && !menu.current?.contains(target)) setOpen(false);
};
document.addEventListener("pointerdown", closeOutside);
return () => document.removeEventListener("pointerdown", closeOutside);
}, [open]);
const selected = new Set(value);
const summary = value.length === 0 ? t("全部") : t("已选 {count} 项", { count: value.length });
const toggle = (option: string) => onChange(selected.has(option)
? value.filter((item) => item !== option)
: [...value, option]);
const close = () => { setOpen(false); trigger.current?.focus(); };
const openMenu = () => {
const width = root.current?.getBoundingClientRect().width;
if (width) setPosition((current) => ({ ...current, width }));
setOpen(true);
};
return <>
<div ref={root} className={styles.target} data-open={open || undefined}>
<button
ref={trigger}
type="button"
className={styles.trigger}
aria-label={t("筛选项:{label},{summary}", { label, summary })}
aria-haspopup="listbox"
aria-controls={open ? menuId : undefined}
aria-expanded={open}
onClick={() => { if (open) close(); else openMenu(); }}
onKeyDown={(event) => { if (event.key === "ArrowDown") { event.preventDefault(); openMenu(); } }}
>
<span>{label}</span><span className={styles.summary} aria-hidden="true">{summary}</span><Icon icon={chevronDownIcon} size="1.1em" />
</button>
{value.length > 0 && <button type="button" className={styles.clear} aria-label={t("清除{label}筛选", { label })} onClick={() => onChange([])}>
<Icon icon={windowCloseIcon} size="1.1em" />
</button>}
</div>
{open && createPortal(<div
id={menuId}
ref={menu}
className={styles.menu}
aria-label={label}
style={position}
onPointerDown={(event) => event.stopPropagation()}
onKeyDown={(event) => { if (event.key === "Escape") { event.preventDefault(); close(); } }}
>
<div
className={styles.listFrame}
role="listbox"
aria-label={label}
aria-multiselectable="true"
style={{ height: Math.min(options.length * 32, Math.max(32, position.maxHeight - 45)) }}
><VirtualList
items={options}
itemKey="value"
className={styles.list}
style={{ height: "100%" }}
estimatedItemHeight={32}
overscan={4}
empty={<div className={styles.empty}>{t("暂无选项")}</div>}
>{(option, index) => <button
ref={index === 0 ? firstOption : undefined}
type="button"
role="option"
aria-label={option.label}
aria-selected={selected.has(option.value)}
onClick={() => toggle(option.value)}
>
<span className={styles.option}>{option.icon && <Icon icon={option.icon} />}<span>{option.label}</span></span>
<span className={styles.check} aria-hidden="true">{selected.has(option.value) && <Icon icon={checkIcon} size="1.1em" />}</span>
</button>}</VirtualList></div>
{options.length > 0 && <div className={styles.footer}>
<button type="button" onClick={() => onChange(options.map((option) => option.value))}>{t("全选")}</button>
<button type="button" onClick={() => onChange([])}>{t("全不选")}</button>
</div>}
</div>, document.body)}
</>;
}
@@ -0,0 +1,35 @@
@use "../../styles/typography" as type;
.root {
flex: 0 0 auto;
min-height: 34px;
display: flex;
align-items: center;
justify-content: flex-end;
gap: 12px;
padding: 0px 0 6px 0;
color: var(--vscode-descriptionForeground);
font-size: type.$font-size-xs;
background: transparent;
}
.controls {
display: flex;
align-items: center;
gap: 4px;
> button {
width: 26px;
height: 26px;
}
}
.pageSize {
width: 92px;
margin-right: 4px;
> button {
height: 26px;
padding: 0 7px;
}
}
@@ -0,0 +1,30 @@
import controls from "./Controls.module.scss";
import { Icon } from "./Icon";
import { chevronDoubleLeftIcon, chevronDoubleRightIcon, chevronLeftIcon, chevronRightIcon } from "./icons";
import { Select } from "./Select";
import { TooltipTrigger } from "./TooltipTrigger";
import styles from "./Pagination.module.scss";
export function Pagination({ page, pageCount, pageSize, total, pageSizes = [20, 50, 100], onPageChange, onPageSizeChange }: {
page: number;
pageCount: number;
pageSize: number;
total: number;
pageSizes?: number[];
onPageChange: (page: number) => void;
onPageSizeChange: (pageSize: number) => void;
}) {
const disabledPrevious = page <= 1;
const disabledNext = page >= pageCount;
return <div className={styles.root}>
<span>{t("共 {count} 条", { count: total })}</span>
<div className={styles.controls}>
<div className={styles.pageSize}><Select ariaLabel={t("每页条数")} value={String(pageSize)} options={pageSizes.map((size) => ({ value: String(size), label: t("{count} 条/页", { count: size }) }))} onChange={(value) => onPageSizeChange(Number(value))} /></div>
<span>{t("第 {page} / {count} 页", { page, count: pageCount })}</span>
<TooltipTrigger label={t("第一页")}><button className={controls.iconButton} aria-label={t("第一页")} disabled={disabledPrevious} onClick={() => onPageChange(1)}><Icon icon={chevronDoubleLeftIcon} size="1.1em" /></button></TooltipTrigger>
<TooltipTrigger label={t("上一页")}><button className={controls.iconButton} aria-label={t("上一页")} disabled={disabledPrevious} onClick={() => onPageChange(page - 1)}><Icon icon={chevronLeftIcon} size="1.1em" /></button></TooltipTrigger>
<TooltipTrigger label={t("下一页")}><button className={controls.iconButton} aria-label={t("下一页")} disabled={disabledNext} onClick={() => onPageChange(page + 1)}><Icon icon={chevronRightIcon} size="1.1em" /></button></TooltipTrigger>
<TooltipTrigger label={t("最后一页")}><button className={controls.iconButton} aria-label={t("最后一页")} disabled={disabledNext} onClick={() => onPageChange(pageCount)}><Icon icon={chevronDoubleRightIcon} size="1.1em" /></button></TooltipTrigger>
</div>
</div>;
}
@@ -0,0 +1,194 @@
@use "../../styles/typography" as type;
.trigger,
.combo input {
width: 100%;
height: 34px;
color: var(--vscode-input-foreground);
background: var(--vscode-input-background);
border: 1px solid var(--vscode-input-border, transparent);
border-radius: 5px;
outline: none;
font-size: type.$font-size-xs;
&:focus {
border-color: var(--vscode-focusBorder);
}
}
.trigger {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 0 10px;
}
.optionContent {
min-width: 0;
display: flex;
align-items: center;
gap: 8px;
text-align: left;
> :last-child {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.dropdownIcon {
transition: transform 160ms ease;
}
.dropdownIconOpen {
transform: rotate(180deg);
}
.comboRow {
width: 100%;
display: flex;
align-items: center;
gap: 8px;
}
.combo {
min-width: 0;
flex: 1;
height: 34px;
display: flex;
align-items: center;
overflow: hidden;
border: 1px solid var(--vscode-input-border, transparent);
border-radius: 6px;
background: var(--vscode-input-background);
&:focus-within {
border-color: var(--vscode-focusBorder);
}
}
.multiCombo {
min-width: 0;
min-height: 34px;
flex: 1;
display: flex;
align-items: stretch;
overflow: hidden;
background: var(--vscode-input-background);
border: 1px solid var(--vscode-input-border, transparent);
border-radius: 6px;
&:focus-within,
&[data-open] {
border-color: var(--vscode-focusBorder);
}
}
.multiValues {
min-width: 0;
flex: 1;
display: flex;
align-items: center;
gap: 4px;
padding: 4px 6px;
> input {
min-width: 120px;
min-height: 24px;
flex: 1;
padding: 0 3px;
color: var(--vscode-input-foreground);
background: transparent;
border: 0;
outline: 0;
font-size: type.$font-size-xs;
}
}
.multiCount {
height: 24px;
flex: 0 0 auto;
display: inline-flex;
align-items: center;
padding: 0 3px;
color: var(--vscode-descriptionForeground);
font-size: type.$font-size-xs;
white-space: nowrap;
}
.combo input {
min-width: 0;
flex: 1;
padding: 0 10px;
border: 0;
background: transparent;
}
.comboToggle {
width: 34px;
height: 34px;
flex: 0 0 34px;
align-self: center;
padding: 0;
color: var(--vscode-descriptionForeground);
background: transparent;
border: 0;
appearance: none;
font-size: type.$font-size-base;
line-height: 1;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
&:hover {
color: var(--vscode-foreground);
}
&:disabled {
cursor: not-allowed;
opacity: 0.6;
}
}
.menu {
position: fixed;
z-index: 14000;
overflow: hidden;
padding: 4px;
background: var(--vscode-dropdown-background);
border: 1px solid var(--vscode-dropdown-border);
border-radius: 6px;
box-shadow: var(--oa-dropdown-shadow);
button {
width: 100%;
min-height: 30px;
display: block;
padding: 5px 8px;
color: var(--vscode-dropdown-foreground);
text-align: left;
background: transparent;
border: 0;
border-radius: 4px;
font-size: type.$font-size-xs;
&:hover,
&[data-active],
&[aria-selected="true"] {
background: var(--vscode-list-activeSelectionBackground);
color: var(--vscode-list-activeSelectionForeground);
}
}
}
.menu .multiOption {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
> span {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.empty {
padding: 8px;
color: var(--vscode-descriptionForeground);
font-size: type.$font-size-xs;
}
+202
View File
@@ -0,0 +1,202 @@
import { autoUpdate, computePosition, flip, offset, shift, size } from "@floating-ui/dom";
import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";
import { createPortal } from "react-dom";
import { VirtualList } from "../virtual/VirtualList";
import type { VirtualListApi } from "../virtual/virtualTypes";
import { Icon, type IconProps } from "./Icon";
import { checkIcon, chevronDownIcon } from "./icons";
import styles from "./Select.module.scss";
export type SelectOption = { value: string; label: string; icon?: IconProps["icon"] };
export function Select({ value, options, disabled, ariaLabel, onChange }: { value: string; options: SelectOption[]; disabled?: boolean; ariaLabel: string; onChange: (value: string) => void }) {
const button = useRef<HTMLButtonElement>(null);
const menu = useRef<HTMLDivElement>(null);
const listApi = useRef<VirtualListApi | null>(null);
const menuId = useId();
const [open, setOpen] = useState(false);
const [active, setActive] = useState(0);
const [position, setPosition] = useState({ left: 0, top: 0, width: 0, maxHeight: 280 });
const selected = options.find((option) => option.value === value);
useLayoutEffect(() => {
if (!open || !button.current || !menu.current) return;
return autoUpdate(button.current, menu.current, () => void computePosition(button.current!, menu.current!, {
placement: "bottom-start",
middleware: [offset(5), flip({ padding: 10 }), shift({ padding: 10 }), size({ padding: 10, apply: ({ rects, availableHeight }) => setPosition((current) => ({ ...current, width: rects.reference.width, maxHeight: Math.max(120, availableHeight) })) })],
}).then(({ x, y }) => setPosition((current) => ({ ...current, left: x, top: y }))));
}, [open]);
useEffect(() => {
if (open && active >= 0) listApi.current?.scrollToIndex(active);
}, [active, open]);
useEffect(() => {
if (!open) return;
const outside = (event: PointerEvent) => { if (!button.current?.contains(event.target as Node) && !menu.current?.contains(event.target as Node)) setOpen(false); };
document.addEventListener("pointerdown", outside);
return () => document.removeEventListener("pointerdown", outside);
}, [open]);
const move = (step: number) => {
if (!options.length) return;
setOpen(true);
setActive((index) => (index + step + options.length) % options.length);
};
const choose = (option: SelectOption) => { onChange(option.value); setOpen(false); button.current?.focus(); };
return <>
<button ref={button} type="button" className={styles.trigger} aria-label={ariaLabel} aria-haspopup="listbox" aria-controls={open ? menuId : undefined} aria-expanded={open} disabled={disabled} onClick={() => { const nextOpen = !open; setOpen(nextOpen); if (nextOpen) setActive(Math.max(0, options.findIndex((option) => option.value === value))); }} onKeyDown={(event) => {
if (event.key === "ArrowDown") { event.preventDefault(); move(1); }
if (event.key === "ArrowUp") { event.preventDefault(); move(-1); }
if (event.key === "Enter" && open) { event.preventDefault(); choose(options[active]); }
if (event.key === "Escape") setOpen(false);
}}><span className={styles.optionContent}>{selected?.icon && <Icon icon={selected.icon} />}<span>{selected?.label ?? value}</span></span><Icon icon={chevronDownIcon} size="1.1em" className={[styles.dropdownIcon, open && styles.dropdownIconOpen].filter(Boolean).join(" ")} /></button>
{open && createPortal(<div id={menuId} ref={menu} className={styles.menu} role="listbox" style={{ left: position.left, top: position.top, width: position.width }}>
<VirtualList items={options} itemKey="value" estimatedItemHeight={30} onReady={(api) => { listApi.current = api; api.scrollToIndex(active); }} style={{ height: Math.min(options.length * 30, Math.max(30, position.maxHeight - 8)) }}>
{(option, index) => <button type="button" role="option" aria-selected={option.value === value} data-active={index === active || undefined} onMouseEnter={() => setActive(index)} onClick={() => choose(option)}><span className={styles.optionContent}>{option.icon && <Icon icon={option.icon} />}<span>{option.label}</span></span></button>}
</VirtualList>
</div>, document.body)}
</>;
}
export function Combobox({ value, options = [], placeholder, disabled, append, onChange }: { value: string; options?: string[]; placeholder?: string; disabled?: boolean; append?: ReactNode; onChange: (value: string) => void }) {
const root = useRef<HTMLDivElement>(null);
const input = useRef<HTMLInputElement>(null);
const menu = useRef<HTMLDivElement>(null);
const listApi = useRef<VirtualListApi | null>(null);
const menuId = useId();
const [open, setOpen] = useState(false);
const [active, setActive] = useState(-1);
const [position, setPosition] = useState({ left: 0, top: 0, width: 0, maxHeight: 280 });
const filtered = useMemo(() => {
const query = value.trim().toLocaleLowerCase();
return options.filter((option) => !query || option.toLocaleLowerCase().includes(query));
}, [options, value]);
useLayoutEffect(() => {
if (!open || !root.current || !menu.current) return;
return autoUpdate(root.current, menu.current, () => void computePosition(root.current!, menu.current!, {
placement: "bottom-start",
middleware: [offset(6), flip({ padding: 12 }), shift({ padding: 12 }), size({ padding: 12, apply: ({ rects, availableHeight }) => setPosition((current) => ({ ...current, width: rects.reference.width, maxHeight: Math.max(160, availableHeight) })) })],
}).then(({ x, y }) => setPosition((current) => ({ ...current, left: x, top: y }))));
}, [open, filtered.length]);
useEffect(() => {
if (!open) return;
const outside = (event: PointerEvent) => { if (!root.current?.contains(event.target as Node) && !menu.current?.contains(event.target as Node)) setOpen(false); };
document.addEventListener("pointerdown", outside);
return () => document.removeEventListener("pointerdown", outside);
}, [open]);
useEffect(() => {
if (open && active >= 0) listApi.current?.scrollToIndex(active);
}, [active, open]);
const openMenu = () => {
if (disabled || options.length === 0) return;
setOpen(true);
const selected = filtered.indexOf(value);
setActive(selected >= 0 ? selected : 0);
};
const choose = (option: string) => { onChange(option); setOpen(false); input.current?.focus(); };
const move = (step: number) => {
if (!open) { openMenu(); return; }
if (!filtered.length) return;
setActive((index) => (index < 0 ? 0 : (index + step + filtered.length) % filtered.length));
};
return <div className={styles.comboRow}><div ref={root} className={styles.combo}>
<input ref={input} value={value} placeholder={placeholder} disabled={disabled} role="combobox" aria-haspopup="listbox" aria-controls={open ? menuId : undefined} aria-expanded={open} aria-autocomplete="list" onFocus={() => { if (options.length) openMenu(); }} onBlur={() => window.setTimeout(() => setOpen(false), 100)} onChange={(event) => { onChange(event.target.value); setActive(0); if (options.length) setOpen(true); }} onKeyDown={(event) => {
if (event.key === "ArrowDown") { event.preventDefault(); move(1); }
if (event.key === "ArrowUp") { event.preventDefault(); move(-1); }
if (event.key === "Enter" && open && filtered[active]) { event.preventDefault(); choose(filtered[active]); }
if (event.key === "Escape") setOpen(false);
}} />
<button type="button" className={styles.comboToggle} disabled={disabled} aria-label={t("打开模型列表")} aria-expanded={open} tabIndex={-1} onMouseDown={(event) => event.preventDefault()} onClick={() => { if (open) setOpen(false); else { openMenu(); input.current?.focus(); } }}><Icon icon={chevronDownIcon} size="1.1em" className={[styles.dropdownIcon, open && styles.dropdownIconOpen].filter(Boolean).join(" ")} /></button>
{open && createPortal(<div id={menuId} ref={menu} className={styles.menu} role="listbox" style={{ left: position.left, top: position.top, width: position.width }}>
<VirtualList items={filtered} itemKey={(option) => option} estimatedItemHeight={30} onReady={(api) => { listApi.current = api; if (active >= 0) api.scrollToIndex(active); }} style={{ height: Math.min(filtered.length * 30, Math.max(30, position.maxHeight - 8)) }}>
{(option, index) => <button type="button" role="option" aria-selected={option === value} data-active={index === active || undefined} onMouseEnter={() => setActive(index)} onMouseDown={(event) => event.preventDefault()} onClick={() => choose(option)}>{option}</button>}
</VirtualList>
</div>, document.body)}
</div>{append}</div>;
}
export function MultiCombobox({ value, options = [], placeholder, disabled, append, onChange }: {
value: string[];
options?: string[];
placeholder?: string;
disabled?: boolean;
append?: ReactNode;
onChange: (value: string[]) => void;
}) {
const root = useRef<HTMLDivElement>(null);
const input = useRef<HTMLInputElement>(null);
const menu = useRef<HTMLDivElement>(null);
const listApi = useRef<VirtualListApi | null>(null);
const menuId = useId();
const [query, setQuery] = useState("");
const [open, setOpen] = useState(false);
const [active, setActive] = useState(0);
const [position, setPosition] = useState({ left: 0, top: 0, width: 0, maxHeight: 280 });
const selected = useMemo(() => new Set(value), [value]);
const filtered = useMemo(() => {
const normalized = query.trim().toLocaleLowerCase();
return options.filter((option) => !normalized || option.toLocaleLowerCase().includes(normalized));
}, [options, query]);
useLayoutEffect(() => {
if (!open || !root.current || !menu.current) return;
return autoUpdate(root.current, menu.current, () => void computePosition(root.current!, menu.current!, {
placement: "bottom-start",
middleware: [offset(6), flip({ padding: 12 }), shift({ padding: 12 }), size({ padding: 12, apply: ({ rects, availableHeight }) => setPosition((current) => ({ ...current, width: rects.reference.width, maxHeight: Math.max(160, availableHeight) })) })],
}).then(({ x, y }) => setPosition((current) => ({ ...current, left: x, top: y }))));
}, [filtered.length, open]);
useEffect(() => {
if (!open) return;
const outside = (event: PointerEvent) => {
if (!root.current?.contains(event.target as Node) && !menu.current?.contains(event.target as Node)) setOpen(false);
};
document.addEventListener("pointerdown", outside);
return () => document.removeEventListener("pointerdown", outside);
}, [open]);
useEffect(() => {
if (open && active >= 0) listApi.current?.scrollToIndex(active);
}, [active, open]);
const add = (modelId: string) => {
const normalized = modelId.trim();
if (normalized && !selected.has(normalized)) onChange([...value, normalized]);
setQuery("");
};
const toggle = (modelId: string) => {
onChange(selected.has(modelId) ? value.filter((item) => item !== modelId) : [...value, modelId]);
setQuery("");
input.current?.focus();
};
const move = (step: number) => {
if (!filtered.length) return;
setOpen(true);
setActive((index) => (index + step + filtered.length) % filtered.length);
};
return <div className={styles.comboRow}><div ref={root} className={styles.multiCombo} data-open={open || undefined}>
<div className={styles.multiValues}>
{value.length > 0 && <span className={styles.multiCount}>{t("已选择 {count} 个", { count: value.length })}</span>}
<input ref={input} value={query} placeholder={value.length ? t("继续选择或输入") : placeholder} disabled={disabled} role="combobox" aria-haspopup="listbox" aria-controls={open ? menuId : undefined} aria-expanded={open} aria-autocomplete="list" onFocus={() => { if (options.length) setOpen(true); }} onChange={(event) => { setQuery(event.target.value); setActive(0); if (options.length) setOpen(true); }} onKeyDown={(event) => {
if (event.key === "ArrowDown") { event.preventDefault(); move(1); }
if (event.key === "ArrowUp") { event.preventDefault(); move(-1); }
if (event.key === "Enter") {
event.preventDefault();
const normalized = query.trim();
const exact = filtered.find((option) => option.toLocaleLowerCase() === normalized.toLocaleLowerCase());
if (normalized && !exact) add(normalized);
else if (open && filtered[active]) toggle(filtered[active]);
}
if (event.key === "Backspace" && !query && value.length) onChange(value.slice(0, -1));
if (event.key === "Escape") { setOpen(false); input.current?.focus(); }
}} />
</div>
<button type="button" className={styles.comboToggle} disabled={disabled || !options.length} aria-label={t("打开模型列表")} aria-expanded={open} tabIndex={-1} onMouseDown={(event) => event.preventDefault()} onClick={() => { setOpen(!open); input.current?.focus(); }}><Icon icon={chevronDownIcon} size="1.1em" className={[styles.dropdownIcon, open && styles.dropdownIconOpen].filter(Boolean).join(" ")} /></button>
{open && createPortal(<div id={menuId} ref={menu} className={styles.menu} role="listbox" aria-multiselectable="true" style={{ left: position.left, top: position.top, width: position.width }} onPointerDown={(event) => event.stopPropagation()} onKeyDown={(event) => { if (event.key === "Escape") { event.preventDefault(); setOpen(false); input.current?.focus(); } }}>
{filtered.length ? <VirtualList items={filtered} itemKey={(option) => option} estimatedItemHeight={30} onReady={(api) => { listApi.current = api; api.scrollToIndex(active); }} style={{ height: Math.min(filtered.length * 30, Math.max(30, position.maxHeight - 8)) }}>
{(option, index) => <button type="button" className={styles.multiOption} role="option" aria-selected={selected.has(option)} data-active={index === active || undefined} onMouseEnter={() => setActive(index)} onMouseDown={(event) => event.preventDefault()} onClick={() => toggle(option)}><span>{option}</span>{selected.has(option) && <Icon icon={checkIcon} size="1.1em" />}</button>}
</VirtualList> : <div className={styles.empty}>{t("输入模型名称后按 Enter 添加")}</div>}
</div>, document.body)}
</div>{append}</div>;
}
@@ -0,0 +1,28 @@
.root {
position: relative;
width: 38px;
height: 22px;
padding: 0;
border: 0;
border-radius: 999px;
background: color-mix(in srgb, var(--vscode-foreground) 22%, transparent);
transition: background 160ms ease;
&[data-checked] { background: var(--vscode-button-background); }
&:focus-visible { outline: 1px solid var(--vscode-focusBorder); outline-offset: 2px; }
&:disabled { opacity: 0.5; }
span {
position: absolute;
top: 2px;
left: 2px;
width: 18px;
height: 18px;
border-radius: 50%;
background: var(--vscode-button-foreground);
box-shadow: 0 1px 4px rgb(0 0 0 / 28%);
transition: transform 160ms ease;
}
&[data-checked] span { transform: translateX(16px); }
}
+14
View File
@@ -0,0 +1,14 @@
import styles from "./Switch.module.scss";
export function Switch({ checked, disabled, label, onChange }: { checked: boolean; disabled?: boolean; label: string; onChange: (checked: boolean) => void }) {
return <button
type="button"
role="switch"
aria-checked={checked}
aria-label={label}
disabled={disabled}
className={styles.root}
data-checked={checked || undefined}
onClick={() => onChange(!checked)}
><span /></button>;
}
@@ -0,0 +1,45 @@
@use "../../styles/typography" as type;
.root {
min-width: 0;
}
.list {
display: flex;
gap: 4px;
border-bottom: 1px solid var(--vscode-sideBar-border);
}
.tab {
position: relative;
min-height: 32px;
padding: 0 10px;
color: var(--vscode-descriptionForeground);
font-size: type.$font-size-base;
background: transparent;
border: 0;
&:hover {
color: var(--vscode-foreground);
background: var(--vscode-list-hoverBackground);
}
&[aria-selected="true"] {
color: var(--vscode-foreground);
&::after {
position: absolute;
right: 8px;
bottom: -1px;
left: 8px;
height: 2px;
content: "";
background: var(--vscode-focusBorder);
}
}
}
.panel {
min-width: 0;
padding-top: 16px;
}
+57
View File
@@ -0,0 +1,57 @@
import { useId, useState, type KeyboardEvent, type ReactNode } from "react";
import styles from "./Tabs.module.scss";
export type TabItem = {
value: string;
label: string;
content: ReactNode;
};
export function Tabs({ items, defaultValue }: { items: TabItem[]; defaultValue?: string }) {
const initialValue = defaultValue && items.some((item) => item.value === defaultValue)
? defaultValue
: items[0]?.value;
const [activeValue, setActiveValue] = useState(initialValue);
const tabsId = useId();
const activeItem = items.find((item) => item.value === activeValue) ?? items[0];
if (!activeItem) return null;
const selectAdjacent = (event: KeyboardEvent<HTMLButtonElement>, offset: number) => {
const currentIndex = items.findIndex((item) => item.value === activeItem.value);
const nextIndex = (currentIndex + offset + items.length) % items.length;
setActiveValue(items[nextIndex].value);
event.currentTarget.parentElement
?.querySelectorAll<HTMLButtonElement>('[role="tab"]')[nextIndex]
?.focus();
};
return <div className={styles.root}>
<div className={styles.list} role="tablist">
{items.map((item) => {
const selected = item.value === activeItem.value;
return <button
key={item.value}
id={`${tabsId}-tab-${item.value}`}
className={styles.tab}
type="button"
role="tab"
aria-selected={selected}
aria-controls={`${tabsId}-panel-${item.value}`}
tabIndex={selected ? 0 : -1}
onClick={() => setActiveValue(item.value)}
onKeyDown={(event) => {
if (event.key === "ArrowLeft") selectAdjacent(event, -1);
if (event.key === "ArrowRight") selectAdjacent(event, 1);
}}
>{item.label}</button>;
})}
</div>
<div
id={`${tabsId}-panel-${activeItem.value}`}
className={styles.panel}
role="tabpanel"
aria-labelledby={`${tabsId}-tab-${activeItem.value}`}
>{activeItem.content}</div>
</div>;
}
@@ -0,0 +1,34 @@
@use "../../styles/typography" as type;
.root {
min-width: 0;
overflow: hidden;
.header {
position: relative;
min-height: 36px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
border-bottom: 1px solid var(--vscode-sideBar-border);
}
.title {
margin: 0;
font-size: type.$font-size-base;
font-weight: 630;
}
pre {
margin: 14px;
padding: 12px;
overflow-wrap: anywhere;
white-space: pre-wrap;
background: var(--vscode-input-background);
border-radius: 6px;
font-family: var(--oa-code-font);
font-size: type.$font-size-xs;
line-height: 1.55;
}
}
@@ -0,0 +1,7 @@
import type { ReactNode } from "react";
import { Card } from "./Card";
import styles from "./TitledCard.module.scss";
export function TitledCard({ title, action, children }: { title: ReactNode; action?: ReactNode; children: ReactNode }) {
return <Card as="section" className={styles.root}><header className={styles.header}><div className={styles.title}>{title}</div>{action}</header>{children}</Card>;
}
@@ -0,0 +1,16 @@
@use "../../styles/typography" as type;
.root {
position: fixed;
z-index: 15000;
max-width: 420px;
padding: 8px 10px;
color: var(--vscode-editorHoverWidget-foreground, var(--vscode-foreground));
background: var(--vscode-editorHoverWidget-background);
border: 1px solid var(--vscode-editorHoverWidget-border);
border-radius: var(--oa-overlay-radius);
box-shadow: var(--oa-tooltip-shadow);
font-size: type.$font-size-xs;
line-height: 1.5;
overflow-wrap: anywhere;
}
@@ -0,0 +1,43 @@
import { autoUpdate, computePosition, flip, offset, shift, type VirtualElement } from "@floating-ui/dom";
import { useLayoutEffect, useRef, useState, type ReactNode } from "react";
import { createPortal } from "react-dom";
import styles from "./Tooltip.module.scss";
export type TooltipAnchor = VirtualElement;
export function Tooltip({ anchor, children }: { anchor: TooltipAnchor | null; children: ReactNode }) {
const tooltipRef = useRef<HTMLDivElement>(null);
const [position, setPosition] = useState<{ left: number; top: number } | null>(null);
useLayoutEffect(() => {
const tooltip = tooltipRef.current;
if (!anchor || !tooltip) {
setPosition(null);
return;
}
const updatePosition = () => {
void computePosition(anchor, tooltip, {
placement: "top",
middleware: [offset(8), flip({ padding: 12 }), shift({ padding: 12 })],
}).then(({ x, y }) => setPosition({ left: x, top: y }));
};
return autoUpdate(anchor, tooltip, updatePosition);
}, [anchor]);
if (!anchor) return null;
// Tooltip overlays always live under body, outside the trigger's layout and stacking context.
return createPortal(
<div
ref={tooltipRef}
className={styles.root}
role="tooltip"
style={{ left: position?.left ?? 0, top: position?.top ?? 0, visibility: position ? "visible" : "hidden" }}
>
{children}
</div>,
document.body,
);
}
@@ -0,0 +1,40 @@
import { cloneElement, useState, type FocusEventHandler, type MouseEventHandler, type ReactElement } from "react";
import { Tooltip, type TooltipAnchor } from "./Tooltip";
function anchorFor(element: HTMLElement): TooltipAnchor {
return { contextElement: element, getBoundingClientRect: () => element.getBoundingClientRect() };
}
type TriggerProps = {
onMouseEnter?: MouseEventHandler<HTMLElement>;
onMouseLeave?: MouseEventHandler<HTMLElement>;
onFocus?: FocusEventHandler<HTMLElement>;
onBlur?: FocusEventHandler<HTMLElement>;
};
export function TooltipTrigger({ label, children }: { label: string; children: ReactElement<TriggerProps> }) {
const [anchor, setAnchor] = useState<TooltipAnchor | null>(null);
const trigger = cloneElement(children, {
onMouseEnter: (event) => {
children.props.onMouseEnter?.(event);
setAnchor(anchorFor(event.currentTarget));
},
onMouseLeave: (event) => {
children.props.onMouseLeave?.(event);
setAnchor(null);
},
onFocus: (event) => {
children.props.onFocus?.(event);
setAnchor(anchorFor(event.currentTarget));
},
onBlur: (event) => {
children.props.onBlur?.(event);
setAnchor(null);
},
});
return <>
{trigger}
<Tooltip anchor={anchor}>{label}</Tooltip>
</>;
}
+43
View File
@@ -0,0 +1,43 @@
import type { IconifyIcon } from "@iconify/react";
// Selected from the complete @iconify/json catalog. Keeping only the selected
// SVG data here prevents entire icon collections from entering the app bundle.
const icon = (body: string, width = 24, height = 24): IconifyIcon => ({ body, width, height });
export const flatColorAreaChartIcon = icon('<path fill="#3F51B5" d="M42 37H6V25l10-15l14 7L42 6z"/><path fill="#00BCD4" d="M42 42H6V32l10-8l14 2l12-9z"/>', 48, 48);
export const flatColorSalesPerformanceIcon = icon('<g fill="#FFA000"><path d="M32 8h12v32c0 1.1-2.7 2-6 2s-6-.9-6-2zM4 14h12v26c0 1.1-2.7 2-6 2s-6-.9-6-2zM18 23h12v17c0 1.1-2.7 2-6 2s-6-.9-6-2z"/></g><g fill="#FFC107"><ellipse cx="38" cy="8" rx="6" ry="2"/><ellipse cx="10" cy="14" rx="6" ry="2"/><ellipse cx="24" cy="23" rx="6" ry="2"/></g><g fill="none" stroke="#FFC107" stroke-width="2"><path d="M32 11c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2M4 17c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2M18 26c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2m-12 3c0 1.1 2.7 2 6 2s6-.9 6-2"/></g>', 48, 48);
export const flatColorLinkIcon = icon('<path fill="#1976D2" d="M38 13h-3c-5.5 0-10 4.5-10 10s4.5 10 10 10h3c5.5 0 10-4.5 10-10s-4.5-10-10-10m0 16h-3c-3.3 0-6-2.7-6-6s2.7-6 6-6h3c3.3 0 6 2.7 6 6s-2.7 6-6 6M13 13h-3C4.5 13 0 17.5 0 23s4.5 10 10 10h3c5.5 0 10-4.5 10-10s-4.5-10-10-10m0 16h-3c-3.3 0-6-2.7-6-6s2.7-6 6-6h3c3.3 0 6 2.7 6 6s-2.7 6-6 6"/><path fill="#42A5F5" d="M33 21H15c-1.1 0-2 .9-2 2s.9 2 2 2h18c1.1 0 2-.9 2-2s-.9-2-2-2"/>', 48, 48);
export const flatColorOrganizationIcon = icon('<path fill="#90CAF9" d="M42 42H6V10c0-2.2 1.8-4 4-4h28c2.2 0 4 1.8 4 4z"/><path fill="#64B5F6" d="M6 42h36v2H6z"/><path fill="#1565C0" d="M31 27h6v5h-6zm-10 0h6v5h-6zm-10 0h6v5h-6zm20 8h6v5h-6zm-20 0h6v5h-6zm20-16h6v5h-6zm-10 0h6v5h-6zm-10 0h6v5h-6zm20-8h6v5h-6zm-10 0h6v5h-6zm-10 0h6v5h-6zm10 24h6v9h-6z"/>', 48, 48);
export const flatColorBarChartIcon = icon('<path fill="#00BCD4" d="M19 22h10v20H19zM6 12h10v30H6zm26-6h10v36H32z"/>', 48, 48);
export const flatColorComboChartIcon = icon('<path fill="#00BCD4" d="M37 18h6v24h-6zm-8 8h6v16h-6zm-8-4h6v20h-6zm-8 10h6v10h-6zm-8-4h6v14H5z"/><g fill="#3F51B5"><circle cx="8" cy="16" r="3"/><circle cx="16" cy="18" r="3"/><circle cx="24" cy="11" r="3"/><circle cx="32" cy="13" r="3"/><circle cx="40" cy="9" r="3"/><path d="m39.1 7.2l-7.3 3.7l-8.3-2.1l-8 7l-7-1.7l-1 3.8l9 2.3l8-7l7.7 1.9l8.7-4.3z"/></g>', 48, 48);
export const flatColorDataConfigurationIcon = icon('<path fill="#D1C4E9" d="M38 7H10c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h28c1.1 0 2-.9 2-2V9c0-1.1-.9-2-2-2m0 12H10c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h28c1.1 0 2-.9 2-2v-6c0-1.1-.9-2-2-2m0 12H10c-1.1 0-2 .9-2 2v6c0 1.1.9 2 2 2h28c1.1 0 2-.9 2-2v-6c0-1.1-.9-2-2-2"/><path fill="#607D8B" d="M45.2 38.1c.1-.4.1-.8.1-1.1s0-.8-.1-1.1l2.3-1.7c.2-.2.3-.5.2-.7l-2.3-3.9c-.1-.2-.4-.3-.7-.2l-2.6 1.2c-.6-.5-1.3-.9-2-1.2l-.3-2.9c0-.3-.3-.5-.5-.5h-4.5c-.3 0-.5.2-.5.5l-.3 2.9c-.7.3-1.4.7-2 1.2l-2.6-1.2c-.3-.1-.6 0-.7.2l-2.3 3.9c-.1.2-.1.6.2.7l2.3 1.7c-.1.4-.1.8-.1 1.1s0 .8.1 1.1l-2.3 1.7c-.2.2-.3.5-.2.7l2.3 3.9c.1.2.4.3.7.2l2.6-1.2c.6.5 1.3.9 2 1.2l.3 2.9c0 .3.3.5.5.5h4.5c.3 0 .5-.2.5-.5l.3-2.9c.7-.3 1.4-.7 2-1.2l2.6 1.2c.3.1.6 0 .7-.2l2.3-3.9c.1-.2.1-.6-.2-.7zM37 42.2c-2.9 0-5.2-2.3-5.2-5.2s2.3-5.2 5.2-5.2s5.2 2.3 5.2 5.2s-2.3 5.2-5.2 5.2"/><path fill="#455A64" d="M37 31c-3.3 0-6 2.7-6 6s2.7 6 6 6s6-2.7 6-6s-2.7-6-6-6m0 9c-1.7 0-3-1.3-3-3s1.3-3 3-3s3 1.3 3 3s-1.3 3-3 3"/>', 48, 48);
export const flatColorSettingsIcon = icon('<path fill="#607D8B" d="M39.6 27.2c.1-.7.2-1.4.2-2.2s-.1-1.5-.2-2.2l4.5-3.2c.4-.3.6-.9.3-1.4L40 10.8c-.3-.5-.8-.7-1.3-.4l-5 2.3c-1.2-.9-2.4-1.6-3.8-2.2L29.4 5c-.1-.5-.5-.9-1-.9h-8.6c-.5 0-1 .4-1 .9l-.5 5.5c-1.4.6-2.7 1.3-3.8 2.2l-5-2.3c-.5-.2-1.1 0-1.3.4l-4.3 7.4c-.3.5-.1 1.1.3 1.4l4.5 3.2c-.1.7-.2 1.4-.2 2.2s.1 1.5.2 2.2L4 30.4c-.4.3-.6.9-.3 1.4L8 39.2c.3.5.8.7 1.3.4l5-2.3c1.2.9 2.4 1.6 3.8 2.2l.5 5.5c.1.5.5.9 1 .9h8.6c.5 0 1-.4 1-.9l.5-5.5c1.4-.6 2.7-1.3 3.8-2.2l5 2.3c.5.2 1.1 0 1.3-.4l4.3-7.4c.3-.5.1-1.1-.3-1.4zM24 35c-5.5 0-10-4.5-10-10s4.5-10 10-10s10 4.5 10 10s-4.5 10-10 10"/><path fill="#455A64" d="M24 13c-6.6 0-12 5.4-12 12s5.4 12 12 12s12-5.4 12-12s-5.4-12-12-12m0 17c-2.8 0-5-2.2-5-5s2.2-5 5-5s5 2.2 5 5s-2.2 5-5 5"/>', 48, 48);
export const claudeIcon = icon('<path fill="#d97757" d="m50.228 170.321l50.357-28.257l.843-2.463l-.843-1.361h-2.462l-8.426-.518l-28.775-.778l-24.952-1.037l-24.175-1.296l-6.092-1.297L0 125.796l.583-3.759l5.12-3.434l7.324.648l16.202 1.101l24.304 1.685l17.629 1.037l26.118 2.722h4.148l.583-1.685l-1.426-1.037l-1.101-1.037l-25.147-17.045l-27.22-18.017l-14.258-10.37l-7.713-5.25l-3.888-4.925l-1.685-10.758l7-7.713l9.397.649l2.398.648l9.527 7.323l20.35 15.75L94.817 91.9l3.889 3.24l1.555-1.102l.195-.777l-1.75-2.917l-14.453-26.118l-15.425-26.572l-6.87-11.018l-1.814-6.61c-.648-2.723-1.102-4.991-1.102-7.778l7.972-10.823L71.42 0l10.63 1.426l4.472 3.888l6.61 15.101l10.694 23.786l16.591 32.34l4.861 9.592l2.592 8.879l.973 2.722h1.685v-1.556l1.36-18.211l2.528-22.36l2.463-28.776l.843-8.1l4.018-9.722l7.971-5.25l6.222 2.981l5.12 7.324l-.713 4.73l-3.046 19.768l-5.962 30.98l-3.889 20.739h2.268l2.593-2.593l10.499-13.934l17.628-22.036l7.778-8.749l9.073-9.657l5.833-4.601h11.018l8.1 12.055l-3.628 12.443l-11.342 14.388l-9.398 12.184l-13.48 18.147l-8.426 14.518l.778 1.166l2.01-.194l30.46-6.481l16.462-2.982l19.637-3.37l8.88 4.148l.971 4.213l-3.5 8.62l-20.998 5.184l-24.628 4.926l-36.682 8.685l-.454.324l.519.648l16.526 1.555l7.065.389h17.304l32.21 2.398l8.426 5.574l5.055 6.805l-.843 5.184l-12.962 6.611l-17.498-4.148l-40.83-9.721l-14-3.5h-1.944v1.167l11.666 11.406l21.387 19.314l26.767 24.887l1.36 6.157l-3.434 4.86l-3.63-.518l-23.526-17.693l-9.073-7.972l-20.545-17.304h-1.36v1.814l4.73 6.935l25.017 37.59l1.296 11.536l-1.814 3.76l-6.481 2.268l-7.13-1.297l-14.647-20.544l-15.1-23.138l-12.185-20.739l-1.49.843l-7.194 77.448l-3.37 3.953l-7.778 2.981l-6.48-4.925l-3.436-7.972l3.435-15.749l4.148-20.544l3.37-16.333l3.046-20.285l1.815-6.74l-.13-.454l-1.49.194l-15.295 20.999l-23.267 31.433l-18.406 19.702l-4.407 1.75l-7.648-3.954l.713-7.064l4.277-6.286l25.47-32.405l15.36-20.092l9.917-11.6l-.065-1.686h-.583L44.07 198.125l-12.055 1.555l-5.185-4.86l.648-7.972l2.463-2.593l20.35-13.999z"/>', 256, 257);
export const openAiIcon = icon('<path fill="currentColor" d="M20.57 10.18c.45-1.36.3-2.85-.43-4.09a5.03 5.03 0 0 0-5.42-2.42a5.05 5.05 0 0 0-7.14-.38c-.66.59-1.15 1.35-1.43 2.19A4.98 4.98 0 0 0 2.82 7.9c-1.1 1.9-.85 4.29.62 5.91c-.45 1.36-.3 2.85.43 4.09a5.045 5.045 0 0 0 5.43 2.42A5.03 5.03 0 0 0 13.06 22c2.19 0 4.14-1.41 4.81-3.5a4.98 4.98 0 0 0 3.33-2.42a5.04 5.04 0 0 0-.62-5.89Zm-7.52 10.51c-.88 0-1.72-.31-2.4-.87l.12-.07l3.98-2.3c.2-.12.33-.33.33-.57v-5.61l1.68.97s.03.02.03.04v4.65c0 2.07-1.68 3.74-3.75 3.75ZM5 17.25c-.44-.76-.6-1.65-.45-2.51l.12.07l3.99 2.3c.2.12.45.12.65 0l4.87-2.81v1.94s-.01.04-.03.05l-4.03 2.33A3.756 3.756 0 0 1 5 17.25M3.95 8.58a3.7 3.7 0 0 1 1.97-1.64v4.73c0 .23.12.45.32.56l4.85 2.8l-1.68.97h-.06l-4.03-2.32a3.754 3.754 0 0 1-1.37-5.12zm13.83 3.21l-4.86-2.82L14.6 8h.06l4.03 2.33a3.743 3.743 0 0 1 1.37 5.12a3.8 3.8 0 0 1-1.94 1.64v-4.73a.67.67 0 0 0-.34-.56Zm1.68-2.52l-.12-.07l-3.98-2.32a.63.63 0 0 0-.65 0L9.84 9.69V7.75s0-.04.02-.05l4.03-2.32a3.75 3.75 0 0 1 5.12 1.38c.44.76.59 1.64.45 2.51v.02ZM8.93 12.72l-1.68-.97s-.03-.03-.03-.05V7.06c0-2.07 1.68-3.75 3.75-3.74c.87 0 1.72.31 2.39.87l-.12.07l-3.98 2.3c-.2.12-.33.33-.33.57v5.6Zm.91-1.97l2.17-1.25l2.17 1.25v2.5l-2.16 1.25l-2.17-1.25v-2.5Z"/>');
// Menu icons intentionally use filled glyphs from different collections so they
// can be compared in context before settling on one visual family.
export const homeIcon = icon('<g fill="currentColor"><path d="M13 15.4C13 13.3258 13 12.2887 13.659 11.6444C14.318 11 15.3787 11 17.5 11C19.6213 11 20.682 11 21.341 11.6444C22 12.2887 22 13.3258 22 15.4V17.6C22 19.6742 22 20.7113 21.341 21.3556C20.682 22 19.6213 22 17.5 22C15.3787 22 14.318 22 13.659 21.3556C13 20.7113 13 19.6742 13 17.6V15.4Z"/><path d="M2 8.6C2 10.6742 2 11.7113 2.65901 12.3556C3.31802 13 4.37868 13 6.5 13C8.62132 13 9.68198 13 10.341 12.3556C11 11.7113 11 10.6742 11 8.6V6.4C11 4.32582 11 3.28873 10.341 2.64437C9.68198 2 8.62132 2 6.5 2C4.37868 2 3.31802 2 2.65901 2.64437C2 3.28873 2 4.32582 2 6.4V8.6Z"/><path d="M13 5.5C13 4.4128 13 3.8692 13.1713 3.44041C13.3996 2.86867 13.8376 2.41443 14.389 2.17761C14.8024 2 15.3266 2 16.375 2H18.625C19.6734 2 20.1976 2 20.611 2.17761C21.1624 2.41443 21.6004 2.86867 21.8287 3.44041C22 3.8692 22 4.4128 22 5.5C22 6.5872 22 7.1308 21.8287 7.55959C21.6004 8.13133 21.1624 8.58557 20.611 8.82239C20.1976 9 19.6734 9 18.625 9H16.375C15.3266 9 14.8024 9 14.389 8.82239C13.8376 8.58557 13.3996 8.13133 13.1713 7.55959C13 7.1308 13 6.5872 13 5.5Z"/><path d="M2 18.5C2 19.5872 2 20.1308 2.17127 20.5596C2.39963 21.1313 2.83765 21.5856 3.38896 21.8224C3.80245 22 4.32663 22 5.375 22H7.625C8.67337 22 9.19755 22 9.61104 21.8224C10.1624 21.5856 10.6004 21.1313 10.8287 20.5596C11 20.1308 11 19.5872 11 18.5C11 17.4128 11 16.8692 10.8287 16.4404C10.6004 15.8687 10.1624 15.4144 9.61104 15.1776C9.19755 15 8.67337 15 7.625 15H5.375C4.32663 15 3.80245 15 3.38896 15.1776C2.83765 15.4144 2.39963 15.8687 2.17127 16.4404C2 16.8692 2 17.4128 2 18.5Z"/></g>');
export const activityIcon = icon('<path fill="currentColor" fill-rule="evenodd" d="M5.07868 5.06891C8.87402 1.27893 15.0437 1.31923 18.8622 5.13778C22.6824 8.95797 22.7211 15.1313 18.9262 18.9262C15.1312 22.7211 8.95793 22.6824 5.13774 18.8622C2.87389 16.5984 1.93904 13.5099 2.34047 10.5812C2.39672 10.1708 2.775 9.88377 3.18537 9.94002C3.59575 9.99627 3.88282 10.3745 3.82658 10.7849C3.4866 13.2652 4.27782 15.881 6.1984 17.8016C9.44288 21.0461 14.6664 21.0646 17.8655 17.8655C21.0646 14.6664 21.046 9.44292 17.8015 6.19844C14.5587 2.95561 9.33889 2.93539 6.13935 6.12957L6.88705 6.13333C7.30126 6.13541 7.63535 6.47288 7.63327 6.88709C7.63119 7.3013 7.29372 7.63539 6.87951 7.63331L4.33396 7.62052C3.92269 7.61845 3.58981 7.28556 3.58774 6.8743L3.57495 4.32874C3.57286 3.91454 3.90696 3.57707 4.32117 3.57498C4.73538 3.5729 5.07285 3.907 5.07493 4.32121L5.07868 5.06891ZM11.9999 7.24992C12.4141 7.24992 12.7499 7.58571 12.7499 7.99992V11.6893L15.0302 13.9696C15.3231 14.2625 15.3231 14.7374 15.0302 15.0302C14.7373 15.3231 14.2624 15.3231 13.9696 15.0302L11.2499 12.3106V7.99992C11.2499 7.58571 11.5857 7.24992 11.9999 7.24992Z" clip-rule="evenodd"/>'); // solar:history-bold
export const providerIcon = icon('<g fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"><path d="M2 7C2 5.11438 2 4.17157 2.58579 3.58579C3.17157 3 4.11438 3 6 3H18C19.8856 3 20.8284 3 21.4142 3.58579C22 4.17157 22 5.11438 22 7C22 8.88562 22 9.82843 21.4142 10.4142C20.8284 11 19.8856 11 18 11H6C4.11438 11 3.17157 11 2.58579 10.4142C2 9.82843 2 8.88562 2 7ZM6 6.25C5.58579 6.25 5.25 6.58579 5.25 7C5.25 7.41421 5.58579 7.75 6 7.75H8C8.41421 7.75 8.75 7.41421 8.75 7C8.75 6.58579 8.41421 6.25 8 6.25H6ZM10.25 7C10.25 6.58579 10.5858 6.25 11 6.25H18C18.4142 6.25 18.75 6.58579 18.75 7C18.75 7.41421 18.4142 7.75 18 7.75H11C10.5858 7.75 10.25 7.41421 10.25 7Z"/><path d="M2 17C2 15.1144 2 14.1716 2.58579 13.5858C3.17157 13 4.11438 13 6 13H18C19.8856 13 20.8284 13 21.4142 13.5858C22 14.1716 22 15.1144 22 17C22 18.8856 22 19.8284 21.4142 20.4142C20.8284 21 19.8856 21 18 21H6C4.11438 21 3.17157 21 2.58579 20.4142C2 19.8284 2 18.8856 2 17ZM6 16.25C5.58579 16.25 5.25 16.5858 5.25 17C5.25 17.4142 5.58579 17.75 6 17.75H8C8.41421 17.75 8.75 17.41421 8.75 17C8.75 16.5858 8.41421 16.25 8 16.25H6ZM10.25 17C10.25 16.5858 10.5858 16.25 11 16.25H18C18.4142 16.25 18.75 16.5858 18.75 17C18.75 17.4142 18.4142 17.75 18 17.75H11C10.5858 17.75 10.25 17.41421 10.25 17Z"/></g>'); // solar:server-bold
export const settingsIcon = icon('<path fill="currentColor" fill-rule="evenodd" d="M14.2788 2.15224C13.9085 2 13.439 2 12.5 2C11.561 2 11.0915 2 10.7212 2.15224C10.2274 2.35523 9.83509 2.74458 9.63056 3.23463C9.53719 3.45834 9.50065 3.7185 9.48635 4.09799C9.46534 4.65568 9.17716 5.17189 8.69017 5.45093C8.20318 5.72996 7.60864 5.71954 7.11149 5.45876C6.77318 5.2813 6.52789 5.18262 6.28599 5.15102C5.75609 5.08178 5.22018 5.22429 4.79616 5.5472C4.47814 5.78938 4.24339 6.1929 3.7739 6.99993C3.30441 7.80697 3.06967 8.21048 3.01735 8.60491C2.94758 9.1308 3.09118 9.66266 3.41655 10.0835C3.56506 10.2756 3.77377 10.437 4.0977 10.639C4.57391 10.936 4.88032 11.4419 4.88029 12C4.88026 12.5581 4.57386 13.0639 4.0977 13.3608C3.77372 13.5629 3.56497 13.7244 3.41645 13.9165C3.09108 14.3373 2.94749 14.8691 3.01725 15.395C3.06957 15.7894 3.30432 16.193 3.7738 17C4.24329 17.807 4.47804 18.2106 4.79606 18.4527C5.22008 18.7756 5.75599 18.9181 6.28589 18.8489C6.52778 18.8173 6.77305 18.7186 7.11133 18.5412C7.60852 18.2804 8.2031 18.27 8.69012 18.549C9.17714 18.8281 9.46533 19.3443 9.48635 19.9021C9.50065 20.2815 9.53719 20.5417 9.63056 20.7654C9.83509 21.2554 10.2274 21.6448 10.7212 21.8478C11.0915 22 11.561 22 12.5 22C13.439 22 13.9085 22 14.2788 21.8478C14.7726 21.6448 15.1649 21.2554 15.3694 20.7654C15.4628 20.5417 15.4994 20.2815 15.5137 19.902C15.5347 19.3443 15.8228 18.8281 16.3098 18.549C16.7968 18.2699 17.3914 18.2804 17.8886 18.5412C18.2269 18.7186 18.4721 18.8172 18.714 18.8488C19.2439 18.9181 19.7798 18.7756 20.2038 18.4527C20.5219 18.2105 20.7566 17.807 21.2261 16.9999C21.6956 16.1929 21.9303 15.7894 21.9827 15.395C22.0524 14.8691 21.9088 14.3372 21.5835 13.9164C21.4349 13.7243 21.2262 13.5628 20.9022 13.3608C20.4261 13.0639 20.1197 12.558 20.1197 11.9999C20.1197 11.4418 20.4261 10.9361 20.9022 10.6392C21.2263 10.4371 21.435 10.2757 21.5836 10.0835C21.9089 9.66273 22.0525 9.13087 21.9828 8.60497C21.9304 8.21055 21.6957 7.80703 21.2262 7C20.7567 6.19297 20.522 5.78945 20.2039 5.54727C19.7799 5.22436 19.244 5.08185 18.7141 5.15109C18.4722 5.18269 18.2269 5.28136 17.8887 5.4588C17.3915 5.71959 16.7969 5.73002 16.3099 5.45096C15.8229 5.17191 15.5347 4.65566 15.5136 4.09794C15.4993 3.71848 15.4628 3.45833 15.3694 3.23463C15.1649 2.74458 14.7726 2.35523 14.2788 2.15224ZM12.5 15C14.1695 15 15.5228 13.6569 15.5228 12C15.5228 10.3431 14.1695 9 12.5 9C10.8305 9 9.47716 10.3431 9.47716 12C9.47716 13.6569 10.8305 15 12.5 15Z" clip-rule="evenodd"/>'); // solar:settings-bold
// Operation icons use the mdi: family. Keep actions visually outlined where the
// collection provides an outline variant.
export const addIcon = icon('<path fill="currentColor" d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6z"/>'); // mdi:plus
export const editIcon = icon('<path fill="currentColor" d="m14.06 9l.94.94L5.92 19H5v-.92zm3.6-6c-.25 0-.51.1-.7.29l-1.83 1.83l3.75 3.75l1.83-1.83c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29m-3.6 3.19L3 17.25V21h3.75L17.81 9.94z"/>'); // mdi:pencil-outline
export const eyeIcon = icon('<path fill="currentColor" d="M12 9a3 3 0 0 1 3 3a3 3 0 0 1-3 3a3 3 0 0 1-3-3a3 3 0 0 1 3-3m0-4.5c5 0 9.27 3.11 11 7.5c-1.73 4.39-6 7.5-11 7.5S2.73 16.39 1 12c1.73-4.39 6-7.5 11-7.5M3.18 12a9.821 9.821 0 0 0 17.64 0a9.821 9.821 0 0 0-17.64 0"/>'); // mdi:eye-outline
export const informationOutlineIcon = icon('<path fill="currentColor" d="M11 9h2V7h-2m1 13c-4.41 0-8-3.59-8-8s3.59-8 8-8s8 3.59 8 8s-3.59 8-8 8m0-18A10 10 0 0 0 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2m-1 15h2v-6h-2z"/>'); // mdi:information-outline
export const cilBadgeIcon = icon('<path fill="currentColor" d="m328.375 384l3.698 74.999l-75.862-52.719l-76.287 52.769L183.625 384h-32.039l-5.522 112h36.692l73.413-50.78L329.242 496h36.694l-5.522-112zm87.034-229.086l-2.194-48.054L372.7 80.933l-25.932-40.519l-48.055-2.2L256 16.093l-42.713 22.126l-48.055 2.2L139.3 80.933L98.785 106.86l-2.194 48.054l-22.127 42.714l22.127 42.715l2.2 48.053l40.509 25.927l25.928 40.52l48.055 2.195L256 379.164l42.713-22.126l48.055-2.195l25.928-40.52l40.518-25.923l2.195-48.053l22.127-42.715Zm-31.646 76.949L382 270.377l-32.475 20.78l-20.78 32.475l-38.515 1.76L256 343.125l-34.234-17.733l-38.515-1.76l-20.78-32.475L130 270.377l-1.759-38.514l-17.741-34.235l17.737-34.228L130 124.88l32.471-20.78l20.78-32.474l38.515-1.76L256 52.132l34.234 17.733l38.515 1.76l20.78 32.474L382 124.88l1.759 38.515l17.741 34.233Z"/>', 512, 512); // cil:badge
export const refreshIcon = icon('<path fill="currentColor" d="M17.65 6.35A7.96 7.96 0 0 0 12 4a8 8 0 0 0-8 8a8 8 0 0 0 8 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0 1 12 18a6 6 0 0 1-6-6a6 6 0 0 1 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4z"/>'); // mdi:refresh
export const trashIcon = icon('<path fill="currentColor" d="M6 19a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V7H6zM8 9h8v10H8zm7.5-5l-1-1h-5l-1 1H5v2h14V4z"/>'); // mdi:delete-outline
export const checkIcon = icon('<path fill="currentColor" d="M21 7L9 19l-5.5-5.5l1.41-1.41L9 16.17L19.59 5.59z"/>');
export const chevronDownIcon = icon('<path fill="currentColor" d="M7.41 8.58L12 13.17l4.59-4.59L18 10l-6 6l-6-6z"/>');
export const chevronLeftIcon = icon('<path fill="currentColor" d="M15.41 16.58L10.83 12l4.58-4.59L14 6l-6 6l6 6z"/>');
export const chevronRightIcon = icon('<path fill="currentColor" d="M8.59 16.58L13.17 12L8.59 7.41L10 6l6 6l-6 6z"/>');
export const chevronDoubleLeftIcon = icon('<path fill="currentColor" d="M18.41 7.41L17 6l-6 6l6 6l1.41-1.41L13.83 12zm-6 0L11 6l-6 6l6 6l1.41-1.41L7.83 12z"/>');
export const chevronDoubleRightIcon = icon('<path fill="currentColor" d="M5.59 7.41L7 6l6 6l-6 6l-1.41-1.41L10.17 12zm6 0L13 6l6 6l-6 6l-1.41-1.41L16.17 12z"/>');
export const windowCloseIcon = icon('<path fill="currentColor" d="M13.46 12L19 17.54V19h-1.46L12 13.46L6.46 19H5v-1.46L10.54 12L5 6.46V5h1.46L12 10.54L17.54 5H19v1.46z"/>');
export const windowMaximizeIcon = icon('<path fill="currentColor" d="M4 4h16v16H4zm2 4v10h12V8z"/>');
export const windowMinimizeIcon = icon('<path fill="currentColor" d="M20 14H4v-4h16"/>');
export const windowRestoreIcon = icon('<path fill="currentColor" d="M4 8h4V4h12v12h-4v4H4zm12 0v6h2V6h-8v2zM6 12v6h8v-6z"/>');
+99
View File
@@ -0,0 +1,99 @@
const MIN_VISIBLE_MS = 300;
const EXIT_MS = 200;
export type MessageOptions = {
duration?: number;
};
export type MessageItem = {
id: string;
content: string;
leaving: boolean;
};
type MessageSnapshot = {
current: MessageItem | null;
};
type MessageApi = ((content: unknown, options?: MessageOptions) => string | null) & {
remove: (id: string) => void;
clear: () => void;
};
let seed = 0;
let shownAt = 0;
let dismissTimer: number | null = null;
let exitTimer: number | null = null;
let snapshot: MessageSnapshot = { current: null };
const listeners = new Set<() => void>();
function update(current: MessageItem | null) {
snapshot = { current };
listeners.forEach((listener) => listener());
}
function clearTimer(timer: number | null) {
if (timer !== null) window.clearTimeout(timer);
}
function clearTimers() {
clearTimer(dismissTimer);
clearTimer(exitTimer);
dismissTimer = null;
exitTimer = null;
}
function beginExit(id: string, force = false) {
const current = snapshot.current;
if (!current || current.id !== id || current.leaving) return;
const elapsed = Date.now() - shownAt;
if (!force && elapsed < MIN_VISIBLE_MS) {
clearTimer(dismissTimer);
dismissTimer = window.setTimeout(() => beginExit(id, true), MIN_VISIBLE_MS - elapsed);
return;
}
clearTimers();
update({ ...current, leaving: true });
exitTimer = window.setTimeout(() => {
if (snapshot.current?.id === id) update(null);
exitTimer = null;
}, EXIT_MS);
}
function showMessage(content: unknown, options: MessageOptions = {}) {
const normalizedContent = String(content ?? "").trim();
if (!normalizedContent) return null;
clearTimers();
const duration = Number.isFinite(options.duration) ? Math.max(0, options.duration!) : 2400;
const id = `message-${Date.now()}-${seed += 1}`;
shownAt = Date.now();
update({ id, content: normalizedContent, leaving: false });
if (duration > 0) {
dismissTimer = window.setTimeout(() => beginExit(id), Math.max(duration, MIN_VISIBLE_MS));
}
return id;
}
export const message = showMessage as MessageApi;
message.remove = (id) => beginExit(id);
message.clear = () => {
const id = snapshot.current?.id;
if (id) beginExit(id, true);
};
export function subscribeToMessages(listener: () => void) {
listeners.add(listener);
return () => listeners.delete(listener);
}
export function getMessageSnapshot() {
return snapshot;
}
export function useMessage() {
return message;
}