/** IDE-rendered plugin settings; every control edits the dialog's staged form. */ import { useMemo, useRef, useState } from "react"; import { tx } from "@/platform/i18n"; import { Button, Checkbox, IconButton, Input, Select, T } from "@/ui"; import { registerSettingsPages, useSettingsForm } from "@/workbench/contributions"; import { pluginsBackend } from "./backend"; import { localizeContributions, usePluginCatalogs } from "./pluginText"; import { itemsOf } from "./projection"; import { SecretsDetails, type SecretDecl } from "./secrets"; import { usePlugins } from "./store"; import styles from "./PluginSettings.module.css"; export interface SettingSchema { key: string; type: "boolean" | "string" | "number" | "integer" | "array" | "object"; title: string; description?: string | null; default: unknown; options?: string[] | null; multiline?: boolean; group?: string | null; /** A sample drawn in the setting's own style, e.g. the message a severity produces. */ example?: { text: string; style: string } | null; items?: SettingSchema | null; properties?: SettingSchema[]; } interface SettingsAction { title: string; command: string; } interface SettingsPage { id: string; title: string; properties: SettingSchema[]; actions?: SettingsAction[]; } export interface SettingsDecl { title: string; properties: SettingSchema[]; pages?: SettingsPage[]; } type PluginSettings = Record>; /** `null` removes an override, restoring its default. */ export function withPluginSetting( settings: PluginSettings | undefined, pluginId: string, key: string, value: unknown, ): PluginSettings { const own = { ...(settings?.[pluginId] ?? {}) }; if (value === null) delete own[key]; else own[key] = value; const next = { ...(settings ?? {}) }; if (Object.keys(own).length) next[pluginId] = own; else delete next[pluginId]; return next; } export const pluginSettingsPageId = (pluginId: string) => `plugins.${pluginId.replace(/\./g, "-")}`; function ValueControl({ s, value, set, label = s.title, cell = false, }: { s: SettingSchema; value: unknown; set(value: unknown): void; label?: string; cell?: boolean; }) { if (s.type === "array") return ; if (s.type === "boolean") return ; if (s.options) return (