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): render declarative setting lists in a dialog

tianma-ifcb58b3c568a7
diff --git a/apps/web/src/components/plugins/PluginSettingsSection.tsx b/apps/web/src/components/plugins/PluginSettingsSection.tsx
index 5478d5ee..b209bc57 100644
--- a/apps/web/src/components/plugins/PluginSettingsSection.tsx
+++ b/apps/web/src/components/plugins/PluginSettingsSection.tsx
@@ -1,5 +1,6 @@
import { useEffect, useId, useState } from "react";
import { useTranslation } from "react-i18next";
+import { ChevronRight } from "lucide-react";
import type { PluginManifest, PluginSettingField, PluginSettingValue } from "@edgeever/plugin-api";
import type { EdgeEverPluginHost } from "@/lib/plugins/plugin-host";
import { Button } from "@/components/ui/button";
@@ -7,8 +8,60 @@ import { Card } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
+import {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
import { groupPluginSettingFields } from "./plugin-settings-layout";
+const PluginSettingListDialog = ({ field }: { field: PluginSettingField }) => {
+ const { t } = useTranslation();
+ const list = field.list;
+ if (!list) return null;
+
+ return (
+ <Dialog>
+ <DialogTrigger asChild>
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ className="-ml-2 mt-0.5 h-7 gap-0.5 px-2 text-xs text-emerald-700 hover:bg-emerald-50 hover:text-emerald-800"
+ aria-haspopup="dialog"
+ >
+ {list.actionLabel ?? t("plugins.settings.viewList")}
+ <ChevronRight className="h-3.5 w-3.5" />
+ </Button>
+ </DialogTrigger>
+ <DialogContent className="grid max-h-[min(720px,calc(100dvh-2rem))] grid-rows-[auto_minmax(0,1fr)_auto] gap-0 overflow-hidden p-0 sm:max-w-md">
+ <DialogHeader className="space-y-1.5 border-b border-slate-200 p-6 pb-4 pr-12 text-left">
+ <DialogTitle>{list.title ?? field.label}</DialogTitle>
+ <DialogDescription>{t("plugins.settings.listCount", { count: list.items.length })}</DialogDescription>
+ </DialogHeader>
+ <ul className="min-h-0 divide-y divide-slate-100 overflow-y-auto pb-1">
+ {list.items.map((item, index) => (
+ <li key={`${item.title}:${item.description ?? ""}:${index}`} className="px-6 py-3">
+ <div className="text-sm font-medium text-slate-800">{item.title}</div>
+ {item.description ? <div className="mt-0.5 text-xs leading-5 text-slate-500">{item.description}</div> : null}
+ </li>
+ ))}
+ </ul>
+ <DialogFooter className="border-t border-slate-200 p-4 sm:justify-end">
+ <DialogClose asChild>
+ <Button type="button" variant="outline" size="sm">{t("common.close")}</Button>
+ </DialogClose>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+};
+
const PluginSettingFieldRow = ({
configuredSecret,
compact = false,
@@ -29,7 +82,7 @@ const PluginSettingFieldRow = ({
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">
+ <label htmlFor={inputId} className="block 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>
@@ -40,6 +93,7 @@ const PluginSettingFieldRow = ({
<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}
+ <PluginSettingListDialog field={field} />
</div>
<div className={field.type === "boolean" ? "shrink-0 pt-0.5" : "min-w-0 md:max-w-xl"}>
{field.type === "boolean" ? (
diff --git a/docs/plugin-development.md b/docs/plugin-development.md
index 4599eafe..df23b806 100644
--- a/docs/plugin-development.md
+++ b/docs/plugin-development.md
@@ -281,7 +281,7 @@ context.events.on("template.updated", ({ template }) => console.log(template.nam
## Host-rendered settings
-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`:
+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`. A field may also declare a read-only `list` of titles and optional descriptions; EdgeEver shows a small entry next to the field and opens the items in a host-rendered dialog.
Plugin API v2 requires `settingsUi: "host"`. 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. Custom settings pages are rejected by the host. Use commands or a clearly named functional panel for workflows such as authorization, connectivity tests, migrations, and index rebuilding; do not recreate ordinary settings in a custom panel.
@@ -294,7 +294,20 @@ Plugin API v2 requires `settingsUi: "host"`. The settings Schema is deliberately
{ "key": "format", "type": "select", "label": "Format", "default": "md", "options": [
{ "value": "md", "label": "Markdown" },
{ "value": "html", "label": "HTML" }
- ] }
+ ] },
+ {
+ "key": "topics.ai",
+ "type": "boolean",
+ "label": "AI",
+ "default": true,
+ "list": {
+ "title": "AI sources",
+ "actionLabel": "View sources",
+ "items": [
+ { "title": "OpenAI News", "description": "openai.com" }
+ ]
+ }
+ }
]
}
}
diff --git a/docs/plugin-development.zh-CN.md b/docs/plugin-development.zh-CN.md
index b5b165e9..7c5d9a7b 100644
--- a/docs/plugin-development.zh-CN.md
+++ b/docs/plugin-development.zh-CN.md
@@ -281,7 +281,7 @@ context.events.on("template.updated", ({ template }) => console.log(template.nam
## 宿主统一渲染的设置
-插件可以在 Manifest 中声明设置,由 EdgeEver 在插件详情的独立「插件设置」页面统一渲染。已安装插件卡片和插件工具菜单均可直达该页面;未声明配置项的插件不显示设置入口,停用的插件仍可配置。设置仅保存在当前设备。默认行为和凭据应放在设置中,实际操作使用插件命令或功能面板,无需为普通配置另建面板。目前支持 `text`、`secret`、`number`、`boolean` 和 `select`:
+插件可以在 Manifest 中声明设置,由 EdgeEver 在插件详情的独立「插件设置」页面统一渲染。已安装插件卡片和插件工具菜单均可直达该页面;未声明配置项的插件不显示设置入口,停用的插件仍可配置。设置仅保存在当前设备。默认行为和凭据应放在设置中,实际操作使用插件命令或功能面板,无需为普通配置另建面板。目前支持 `text`、`secret`、`number`、`boolean` 和 `select`。字段还可以声明只读的 `list`(标题和可选说明);EdgeEver 会在字段旁显示一个小入口,并用宿主对话框以列表展示这些条目。
插件 API v2 强制要求 `settingsUi: "host"`。设置 Schema 有意保持为声明式结构:字段布局、控件、间距、校验、响应式行为、无障碍、保存状态和密钥呈现均由 EdgeEver 管理;Manifest 中的 HTML、组件、CSS class、内联样式、颜色、字体以及自定义设置页导航等展示属性会被忽略。插件决定“配置什么”,而不是“设置页长什么样”。宿主会拒绝自定义设置页。授权、连通性测试、数据迁移、索引重建等流程应使用命令或命名清晰的功能面板,不要在自定义面板中重复实现普通设置。
@@ -294,7 +294,20 @@ context.events.on("template.updated", ({ template }) => console.log(template.nam
{ "key": "format", "type": "select", "label": "格式", "default": "md", "options": [
{ "value": "md", "label": "Markdown" },
{ "value": "html", "label": "HTML" }
- ] }
+ ] },
+ {
+ "key": "topics.ai",
+ "type": "boolean",
+ "label": "主题 · AI 前沿",
+ "default": true,
+ "list": {
+ "title": "AI 前沿信源",
+ "actionLabel": "查看信源",
+ "items": [
+ { "title": "OpenAI News", "description": "openai.com" }
+ ]
+ }
+ }
]
}
}
diff --git a/packages/plugin-api/dist/index.d.ts b/packages/plugin-api/dist/index.d.ts
index a53d60f0..74ada4d9 100644
--- a/packages/plugin-api/dist/index.d.ts
+++ b/packages/plugin-api/dist/index.d.ts
@@ -19,6 +19,15 @@ export interface PluginManifest {
networkHosts?: string[];
settings?: PluginSettingsSchema;
}
+export interface PluginSettingListItem {
+ title: string;
+ description?: string;
+}
+export interface PluginSettingList {
+ title?: string;
+ actionLabel?: string;
+ items: PluginSettingListItem[];
+}
/**
* Declarative setting metadata. EdgeEver owns the layout, controls, validation,
* state feedback, and responsive behavior; plugins cannot supply presentation code or styles.
@@ -28,6 +37,8 @@ interface PluginSettingBase {
label: string;
description?: string;
required?: boolean;
+ /** Host-rendered read-only items, opened from a small entry next to the field. */
+ list?: PluginSettingList;
}
export type PluginSettingField = (PluginSettingBase & {
type: "text";
diff --git a/packages/plugin-api/dist/index.js b/packages/plugin-api/dist/index.js
index e78792ac..9a903c72 100644
--- a/packages/plugin-api/dist/index.js
+++ b/packages/plugin-api/dist/index.js
@@ -112,6 +112,36 @@ var normalizeThemeTokens = (value) => {
return tokens;
};
var SETTING_KEY_PATTERN = /^[a-z][a-z0-9._-]*$/;
+var normalizeSettingList = (field, key) => {
+ if (field.list === undefined)
+ return;
+ if (!isRecord(field.list) || !Array.isArray(field.list.items) || field.list.items.length === 0 || field.list.items.length > 100) {
+ throw new Error(`Plugin setting ${key} list requires between 1 and 100 items.`);
+ }
+ if (field.list.title !== undefined && (typeof field.list.title !== "string" || !field.list.title.trim() || field.list.title.length > 200)) {
+ throw new Error(`Plugin setting ${key} list title must be at most 200 characters.`);
+ }
+ if (field.list.actionLabel !== undefined && (typeof field.list.actionLabel !== "string" || !field.list.actionLabel.trim() || field.list.actionLabel.length > 40)) {
+ throw new Error(`Plugin setting ${key} list action label must be at most 40 characters.`);
+ }
+ const items = field.list.items.map((item, index) => {
+ if (!isRecord(item) || typeof item.title !== "string" || !item.title.trim() || item.title.length > 200) {
+ throw new Error(`Plugin setting ${key} list item ${index + 1} requires a title of at most 200 characters.`);
+ }
+ if (item.description !== undefined && (typeof item.description !== "string" || item.description.length > 200)) {
+ throw new Error(`Plugin setting ${key} list item ${index + 1} description is too long.`);
+ }
+ return {
+ title: item.title.trim(),
+ ...typeof item.description === "string" && item.description.trim() ? { description: item.description.trim() } : {}
+ };
+ });
+ return {
+ items,
+ ...typeof field.list.title === "string" ? { title: field.list.title.trim() } : {},
+ ...typeof field.list.actionLabel === "string" ? { actionLabel: field.list.actionLabel.trim() } : {}
+ };
+};
var normalizePluginSettings = (value) => {
if (!isRecord(value) || !Array.isArray(value.fields))
throw new Error("Plugin settings must contain a fields array.");
@@ -129,11 +159,13 @@ var normalizePluginSettings = (value) => {
throw new Error(`Plugin setting ${field.key} requires a label of at most 200 characters.`);
if (typeof field.description === "string" && field.description.length > 1000)
throw new Error(`Plugin setting ${field.key} description is too long.`);
+ const list = normalizeSettingList(field, field.key);
const common = {
key: field.key,
label: field.label.trim(),
...typeof field.description === "string" && field.description.trim() ? { description: field.description.trim() } : {},
- ...field.required === true ? { required: true } : {}
+ ...field.required === true ? { required: true } : {},
+ ...list ? { list } : {}
};
if (field.type === "text" || field.type === "secret") {
if (field.type === "secret" && field.default !== undefined)
diff --git a/packages/plugin-api/src/index.test.mjs b/packages/plugin-api/src/index.test.mjs
index b430119a..cf52b2eb 100644
--- a/packages/plugin-api/src/index.test.mjs
+++ b/packages/plugin-api/src/index.test.mjs
@@ -129,16 +129,42 @@ describe("extension manifests", () => {
{ key: "limit", type: "number", label: "Limit", default: 10, min: 1, max: 100 },
{ key: "enabled", type: "boolean", label: "Enabled", default: true },
{ key: "format", type: "select", label: "Format", options: [{ value: "md", label: "Markdown" }] },
+ {
+ key: "topics.ai",
+ type: "boolean",
+ label: "AI",
+ default: true,
+ className: "plugin-owned-layout",
+ list: {
+ title: "AI sources",
+ actionLabel: "View sources",
+ className: "ignored",
+ items: [
+ { title: "OpenAI News", description: "openai.com", html: "<script>" },
+ { title: "Google AI" },
+ ],
+ },
+ },
],
},
});
expect(manifest.type).toBe("plugin");
- expect(manifest.settings?.fields).toHaveLength(5);
+ expect(manifest.settings?.fields).toHaveLength(6);
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");
+ expect(manifest.settings?.fields[5]).toMatchObject({
+ key: "topics.ai",
+ list: {
+ title: "AI sources",
+ actionLabel: "View sources",
+ items: [{ title: "OpenAI News", description: "openai.com" }, { title: "Google AI" }],
+ },
+ });
+ expect(manifest.settings?.fields[5].list).not.toHaveProperty("className");
+ expect(manifest.settings?.fields[5].list.items[0]).not.toHaveProperty("html");
});
test("rejects unsafe or ambiguous plugin settings", () => {
@@ -160,6 +186,10 @@ describe("extension manifests", () => {
...base,
settings: { fields: [{ key: "mode", type: "select", label: "Mode", options: [{ value: "a", label: "A" }, { value: "a", label: "Again" }] }] },
})).toThrow("duplicate select value");
+ expect(() => parseExtensionManifest({
+ ...base,
+ settings: { fields: [{ key: "topics.ai", type: "boolean", label: "AI", list: { items: [] } }] },
+ })).toThrow("between 1 and 100 items");
});
});
diff --git a/packages/plugin-api/src/index.ts b/packages/plugin-api/src/index.ts
index f5065af6..24a5cf58 100644
--- a/packages/plugin-api/src/index.ts
+++ b/packages/plugin-api/src/index.ts
@@ -46,6 +46,17 @@ export interface PluginManifest {
settings?: PluginSettingsSchema;
}
+export interface PluginSettingListItem {
+ title: string;
+ description?: string;
+}
+
+export interface PluginSettingList {
+ title?: string;
+ actionLabel?: string;
+ items: PluginSettingListItem[];
+}
+
/**
* Declarative setting metadata. EdgeEver owns the layout, controls, validation,
* state feedback, and responsive behavior; plugins cannot supply presentation code or styles.
@@ -55,6 +66,8 @@ interface PluginSettingBase {
label: string;
description?: string;
required?: boolean;
+ /** Host-rendered read-only items, opened from a small entry next to the field. */
+ list?: PluginSettingList;
}
export type PluginSettingField =
@@ -548,6 +561,36 @@ const normalizeThemeTokens = (value: unknown): ThemeTokens => {
const SETTING_KEY_PATTERN = /^[a-z][a-z0-9._-]*$/;
+const normalizeSettingList = (field: Record<string, unknown>, key: string): PluginSettingList | undefined => {
+ if (field.list === undefined) return undefined;
+ if (!isRecord(field.list) || !Array.isArray(field.list.items) || field.list.items.length === 0 || field.list.items.length > 100) {
+ throw new Error(`Plugin setting ${key} list requires between 1 and 100 items.`);
+ }
+ if (field.list.title !== undefined && (typeof field.list.title !== "string" || !field.list.title.trim() || field.list.title.length > 200)) {
+ throw new Error(`Plugin setting ${key} list title must be at most 200 characters.`);
+ }
+ if (field.list.actionLabel !== undefined && (typeof field.list.actionLabel !== "string" || !field.list.actionLabel.trim() || field.list.actionLabel.length > 40)) {
+ throw new Error(`Plugin setting ${key} list action label must be at most 40 characters.`);
+ }
+ const items = field.list.items.map((item, index): PluginSettingListItem => {
+ if (!isRecord(item) || typeof item.title !== "string" || !item.title.trim() || item.title.length > 200) {
+ throw new Error(`Plugin setting ${key} list item ${index + 1} requires a title of at most 200 characters.`);
+ }
+ if (item.description !== undefined && (typeof item.description !== "string" || item.description.length > 200)) {
+ throw new Error(`Plugin setting ${key} list item ${index + 1} description is too long.`);
+ }
+ return {
+ title: item.title.trim(),
+ ...(typeof item.description === "string" && item.description.trim() ? { description: item.description.trim() } : {}),
+ };
+ });
+ return {
+ items,
+ ...(typeof field.list.title === "string" ? { title: field.list.title.trim() } : {}),
+ ...(typeof field.list.actionLabel === "string" ? { actionLabel: field.list.actionLabel.trim() } : {}),
+ };
+};
+
const normalizePluginSettings = (value: unknown): PluginSettingsSchema => {
if (!isRecord(value) || !Array.isArray(value.fields)) throw new Error("Plugin settings must contain a fields array.");
if (value.fields.length > 50) throw new Error("Plugin settings cannot contain more than 50 fields.");
@@ -560,11 +603,13 @@ const normalizePluginSettings = (value: unknown): PluginSettingsSchema => {
keys.add(field.key);
if (typeof field.label !== "string" || !field.label.trim() || field.label.length > 200) throw new Error(`Plugin setting ${field.key} requires a label of at most 200 characters.`);
if (typeof field.description === "string" && field.description.length > 1000) throw new Error(`Plugin setting ${field.key} description is too long.`);
+ const list = normalizeSettingList(field, field.key);
const common = {
key: field.key,
label: field.label.trim(),
...(typeof field.description === "string" && field.description.trim() ? { description: field.description.trim() } : {}),
...(field.required === true ? { required: true } : {}),
+ ...(list ? { list } : {}),
};
if (field.type === "text" || field.type === "secret") {
if (field.type === "secret" && field.default !== undefined) throw new Error(`Secret setting ${field.key} cannot declare a default value.`);
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index bd85b5ab..7df7f20a 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -708,6 +708,8 @@ export const enUS = {
required: "{{name}} is required.",
secretConfigured: "Configured — leave blank to keep unchanged",
none: "None",
+ viewList: "View list",
+ listCount: "{{count}} items",
},
details: {
title: "Plugin details",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index db8c967a..4086d080 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -708,6 +708,8 @@ export const zhCN = {
required: "{{name}} 为必填项。",
secretConfigured: "已配置,留空表示保持不变",
none: "无",
+ viewList: "查看列表",
+ listCount: "共 {{count}} 项",
},
details: {
title: "插件详情",