Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(plugins): enforce declarative settings schema and native row layout

tianma-if7c244e0f8129
diff --git a/apps/web/src/components/plugins/PluginSettingsSection.tsx b/apps/web/src/components/plugins/PluginSettingsSection.tsx
index 795c9cc9..88bf4604 100644
--- a/apps/web/src/components/plugins/PluginSettingsSection.tsx
+++ b/apps/web/src/components/plugins/PluginSettingsSection.tsx
@@ -1,12 +1,93 @@
import { useEffect, useId, useState } from "react";
import { useTranslation } from "react-i18next";
-import type { PluginManifest, PluginSettingValue } from "@edgeever/plugin-api";
+import type { PluginManifest, PluginSettingField, PluginSettingValue } from "@edgeever/plugin-api";
import type { EdgeEverPluginHost } from "@/lib/plugins/plugin-host";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
+const PluginSettingFieldRow = ({
+ configuredSecret,
+ disabled,
+ field,
+ inputId,
+ onChange,
+ value,
+}: {
+ configuredSecret: boolean;
+ disabled: boolean;
+ field: PluginSettingField;
+ inputId: string;
+ onChange: (value: PluginSettingValue | "") => void;
+ value: PluginSettingValue | "";
+}) => {
+ const { t } = useTranslation();
+ const descriptionId = field.description ? `${inputId}-description` : undefined;
+ const label = (
+ <label htmlFor={inputId} className="text-sm font-medium leading-5 text-slate-800">
+ {field.label}
+ {field.required ? <span className="ml-1 text-rose-600" aria-hidden="true">*</span> : null}
+ </label>
+ );
+
+ return (
+ <div className="grid min-w-0 gap-3 py-5 first:pt-0 last:pb-0 md:grid-cols-[minmax(0,14rem)_minmax(0,1fr)] md:gap-8">
+ <div className="min-w-0">
+ {label}
+ {field.description ? <p id={descriptionId} className="mt-1 text-xs leading-5 text-slate-500">{field.description}</p> : null}
+ </div>
+ <div className="min-w-0 md:max-w-xl">
+ {field.type === "boolean" ? (
+ <Switch
+ id={inputId}
+ aria-describedby={descriptionId}
+ aria-label={field.label}
+ checked={value === true}
+ disabled={disabled}
+ onCheckedChange={onChange}
+ />
+ ) : field.type === "select" ? (
+ <Select
+ disabled={disabled}
+ value={value === "" ? (field.required ? "" : "none") : `option:${value}`}
+ onValueChange={(next) => onChange(next === "none" ? "" : next.slice(7))}
+ >
+ <SelectTrigger id={inputId} aria-describedby={descriptionId} aria-required={field.required}>
+ <SelectValue placeholder={t("plugins.settings.none")} />
+ </SelectTrigger>
+ <SelectContent>
+ {!field.required ? <SelectItem value="none">{t("plugins.settings.none")}</SelectItem> : null}
+ {field.options.map((option) => <SelectItem key={option.value} value={`option:${option.value}`}>{option.label}</SelectItem>)}
+ </SelectContent>
+ </Select>
+ ) : (
+ <Input
+ id={inputId}
+ aria-describedby={descriptionId}
+ required={field.required && !(field.type === "secret" && configuredSecret)}
+ autoComplete={field.type === "secret" ? "new-password" : "off"}
+ disabled={disabled}
+ type={field.type === "secret" ? "password" : field.type === "number" ? "number" : "text"}
+ value={String(value)}
+ placeholder={field.type === "secret" && configuredSecret
+ ? t("plugins.settings.secretConfigured")
+ : field.type === "text" || field.type === "secret"
+ ? field.placeholder
+ : undefined}
+ min={field.type === "number" ? field.min : undefined}
+ max={field.type === "number" ? field.max : undefined}
+ step={field.type === "number" ? field.step ?? "any" : undefined}
+ onChange={(event) => onChange(
+ field.type === "number" && event.target.value !== "" ? Number(event.target.value) : event.target.value,
+ )}
+ />
+ )}
+ </div>
+ </div>
+ );
+};
+
export const PluginSettingsSection = ({ host, manifest }: { host: EdgeEverPluginHost; manifest: PluginManifest }) => {
const { t } = useTranslation();
const formId = useId();
@@ -86,80 +167,44 @@ export const PluginSettingsSection = ({ host, manifest }: { host: EdgeEverPlugin
};
return (
- <section className="min-w-0">
- <h3 className="text-xs font-semibold text-slate-700">{t("plugins.settings.title")}</h3>
- <p className="mt-2 max-w-2xl text-xs leading-5 text-slate-500">{t("plugins.settings.description")}</p>
- {loading ? <p className="mt-3 text-xs text-slate-400" role="status">{t("common.loading")}</p> : loadError ? (
- <div className="mt-4 grid justify-items-start gap-3">
- <p className="text-sm text-rose-600" role="alert">{t("plugins.settings.loadFailed", { message: loadError })}</p>
+ <section className="min-w-0" aria-labelledby={`${formId}-title`}>
+ <header className="border-b border-slate-200 pb-5">
+ <h3 id={`${formId}-title`} className="text-base font-semibold text-slate-900">{t("plugins.settings.title")}</h3>
+ <p className="mt-1.5 max-w-3xl text-sm leading-6 text-slate-500">{t("plugins.settings.description")}</p>
+ </header>
+ {loading ? <p className="py-8 text-sm text-slate-500" role="status">{t("common.loading")}</p> : loadError ? (
+ <div className="mt-5 grid justify-items-start gap-3 rounded-lg border border-rose-200 bg-rose-50 p-4">
+ <p className="text-sm leading-6 text-rose-700" role="alert">{t("plugins.settings.loadFailed", { message: loadError })}</p>
<Button size="sm" variant="outline" onClick={() => setLoadAttempt((attempt) => attempt + 1)}>{t("plugins.settings.retry")}</Button>
</div>
) : (
- <form className="mt-5 max-w-2xl" onChange={clearFeedback} onSubmit={(event) => { event.preventDefault(); void save(); }}>
- <fieldset disabled={saving} className="grid min-w-0 gap-5">
+ <form onChange={clearFeedback} onSubmit={(event) => { event.preventDefault(); void save(); }}>
+ <fieldset disabled={saving} className="min-w-0">
+ <div className="divide-y divide-slate-100 py-5">
{fields.map((field) => {
const value = values[field.key] ?? "";
const inputId = `${formId}-${field.key}`;
- const descriptionId = field.description ? `${inputId}-description` : undefined;
return (
- <div key={field.key} className="grid gap-1.5 text-xs text-slate-700">
- <label htmlFor={inputId} className="font-medium">{field.label}{field.required ? " *" : ""}</label>
- {field.type === "boolean" ? (
- <Switch
- id={inputId}
- aria-describedby={descriptionId}
- aria-label={field.label}
- checked={value === true}
- onCheckedChange={(checked) => { clearFeedback(); setValues((current) => ({ ...current, [field.key]: checked })); }}
- />
- ) : field.type === "select" ? (
- <Select
- disabled={saving}
- value={value === "" ? (field.required ? "" : "none") : `option:${value}`}
- onValueChange={(next) => {
- clearFeedback();
- setValues((current) => ({ ...current, [field.key]: next === "none" ? "" : next.slice(7) }));
- }}
- >
- <SelectTrigger id={inputId} aria-describedby={descriptionId} aria-required={field.required}>
- <SelectValue placeholder={t("plugins.settings.none")} />
- </SelectTrigger>
- <SelectContent>
- {!field.required ? <SelectItem value="none">{t("plugins.settings.none")}</SelectItem> : null}
- {field.options.map((option) => <SelectItem key={option.value} value={`option:${option.value}`}>{option.label}</SelectItem>)}
- </SelectContent>
- </Select>
- ) : (
- <Input
- id={inputId}
- aria-describedby={descriptionId}
- required={field.required && !(field.type === "secret" && configuredSecrets[field.key])}
- autoComplete={field.type === "secret" ? "new-password" : "off"}
- type={field.type === "secret" ? "password" : field.type === "number" ? "number" : "text"}
- value={String(value)}
- placeholder={field.type === "secret" && configuredSecrets[field.key]
- ? t("plugins.settings.secretConfigured")
- : field.type === "text" || field.type === "secret"
- ? field.placeholder
- : undefined}
- min={field.type === "number" ? field.min : undefined}
- max={field.type === "number" ? field.max : undefined}
- step={field.type === "number" ? field.step ?? "any" : undefined}
- onChange={(event) => setValues((current) => ({
- ...current,
- [field.key]: field.type === "number" && event.target.value !== "" ? Number(event.target.value) : event.target.value,
- }))}
- />
- )}
- {field.description ? <p id={descriptionId} className="text-slate-500">{field.description}</p> : null}
- </div>
+ <PluginSettingFieldRow
+ key={field.key}
+ configuredSecret={Boolean(configuredSecrets[field.key])}
+ disabled={saving}
+ field={field}
+ inputId={inputId}
+ value={value}
+ onChange={(nextValue) => {
+ clearFeedback();
+ setValues((current) => ({ ...current, [field.key]: nextValue }));
+ }}
+ />
);
})}
- <div className="flex items-center gap-3">
+ </div>
+ <div className="flex min-h-14 flex-wrap items-center justify-end gap-3 border-t border-slate-200 pt-4">
+ {message ? <span className="mr-auto text-sm text-emerald-700" role="status">{message}</span> : null}
+ {error ? <p className="mr-auto text-sm text-rose-700" role="alert">{t("plugins.settings.saveFailed", { message: error })}</p> : null}
<Button type="submit" size="sm" disabled={saving}>{saving ? t("common.saving") : t("common.save")}</Button>
- {message ? <span className="text-xs text-slate-500" role="status">{message}</span> : null}
</div>
- {error ? <p className="text-sm text-rose-600" role="alert">{t("plugins.settings.saveFailed", { message: error })}</p> : null}
</fieldset>
</form>
)}
diff --git a/docs/plugin-development.md b/docs/plugin-development.md
index 303a0500..db224bf0 100644
--- a/docs/plugin-development.md
+++ b/docs/plugin-development.md
@@ -277,6 +277,8 @@ context.events.on("template.updated", ({ template }) => console.log(template.nam
Plugins can declare settings that EdgeEver renders consistently on a dedicated Plugin settings page within plugin details. Installed plugin cards and the plugin toolbar menu link directly to this page. Plugins without settings fields have no settings entry, while disabled plugins remain configurable. Settings are stored on the current device only. Put defaults and credentials in settings, and use plugin commands or functional panels for actual operations; ordinary configuration does not need a separate custom panel. Supported field types are `text`, `secret`, `number`, `boolean`, and `select`:
+The settings Schema is deliberately declarative. EdgeEver owns field layout, controls, spacing, validation, responsive behavior, accessibility, save states, and secret presentation. Presentation properties such as HTML, components, CSS classes, inline styles, colors, typography, or custom setting-page navigation are ignored. A plugin decides what can be configured, not how the settings page looks. Use commands or a clearly named functional panel for complex workflows such as authorization, connectivity tests, migrations, and index rebuilding; do not recreate ordinary settings in a custom panel.
+
```json
{
"settings": {
diff --git a/docs/plugin-development.zh-CN.md b/docs/plugin-development.zh-CN.md
index bd391ce5..3ea7babb 100644
--- a/docs/plugin-development.zh-CN.md
+++ b/docs/plugin-development.zh-CN.md
@@ -277,6 +277,8 @@ context.events.on("template.updated", ({ template }) => console.log(template.nam
插件可以在 Manifest 中声明设置,由 EdgeEver 在插件详情的独立「插件设置」页面统一渲染。已安装插件卡片和插件工具菜单均可直达该页面;未声明配置项的插件不显示设置入口,停用的插件仍可配置。设置仅保存在当前设备。默认行为和凭据应放在设置中,实际操作使用插件命令或功能面板,无需为普通配置另建面板。目前支持 `text`、`secret`、`number`、`boolean` 和 `select`:
+设置 Schema 有意保持为声明式结构。字段布局、控件、间距、校验、响应式行为、无障碍、保存状态和密钥呈现均由 EdgeEver 管理;Manifest 中的 HTML、组件、CSS class、内联样式、颜色、字体以及自定义设置页导航等展示属性会被忽略。插件决定“配置什么”,而不是“设置页长什么样”。授权、连通性测试、数据迁移、索引重建等复杂流程应使用命令或命名清晰的功能面板,不要在自定义面板中重复实现普通设置。
+
```json
{
"settings": {
diff --git a/packages/plugin-api/dist/index.d.ts b/packages/plugin-api/dist/index.d.ts
index 65317553..8983885e 100644
--- a/packages/plugin-api/dist/index.d.ts
+++ b/packages/plugin-api/dist/index.d.ts
@@ -17,6 +17,10 @@ export interface PluginManifest {
networkHosts?: string[];
settings?: PluginSettingsSchema;
}
+/**
+ * Declarative setting metadata. EdgeEver owns the layout, controls, validation,
+ * state feedback, and responsive behavior; plugins cannot supply presentation code or styles.
+ */
interface PluginSettingBase {
key: string;
label: string;
@@ -48,6 +52,7 @@ export type PluginSettingField = (PluginSettingBase & {
}>;
});
export interface PluginSettingsSchema {
+ /** Host-rendered fields in display order. Arbitrary UI markup and styling are intentionally unsupported. */
fields: PluginSettingField[];
}
export type PluginSettingValue = string | number | boolean;
diff --git a/packages/plugin-api/src/index.test.mjs b/packages/plugin-api/src/index.test.mjs
index cd485b45..25a7452e 100644
--- a/packages/plugin-api/src/index.test.mjs
+++ b/packages/plugin-api/src/index.test.mjs
@@ -73,7 +73,15 @@ describe("extension manifests", () => {
permissions: [],
settings: {
fields: [
- { key: "endpoint", type: "text", label: "Endpoint", default: "https://example.com" },
+ {
+ key: "endpoint",
+ type: "text",
+ label: "Endpoint",
+ default: "https://example.com",
+ className: "plugin-owned-layout",
+ style: { color: "red" },
+ html: "<script>alert(1)</script>",
+ },
{ key: "token", type: "secret", label: "Token", required: true },
{ key: "limit", type: "number", label: "Limit", default: 10, min: 1, max: 100 },
{ key: "enabled", type: "boolean", label: "Enabled", default: true },
@@ -85,6 +93,9 @@ describe("extension manifests", () => {
expect(manifest.type).toBe("plugin");
expect(manifest.settings?.fields).toHaveLength(5);
expect(manifest.settings?.fields[0]).toMatchObject({ key: "endpoint", default: "https://example.com" });
+ expect(manifest.settings?.fields[0]).not.toHaveProperty("className");
+ expect(manifest.settings?.fields[0]).not.toHaveProperty("style");
+ expect(manifest.settings?.fields[0]).not.toHaveProperty("html");
});
test("rejects unsafe or ambiguous plugin settings", () => {
diff --git a/packages/plugin-api/src/index.ts b/packages/plugin-api/src/index.ts
index 851dd77b..6b9a0c61 100644
--- a/packages/plugin-api/src/index.ts
+++ b/packages/plugin-api/src/index.ts
@@ -44,6 +44,10 @@ export interface PluginManifest {
settings?: PluginSettingsSchema;
}
+/**
+ * Declarative setting metadata. EdgeEver owns the layout, controls, validation,
+ * state feedback, and responsive behavior; plugins cannot supply presentation code or styles.
+ */
interface PluginSettingBase {
key: string;
label: string;
@@ -59,6 +63,7 @@ export type PluginSettingField =
| (PluginSettingBase & { type: "select"; default?: string; options: Array<{ value: string; label: string }> });
export interface PluginSettingsSchema {
+ /** Host-rendered fields in display order. Arbitrary UI markup and styling are intentionally unsupported. */
fields: PluginSettingField[];
}