An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Improve the Protyle Lite slash menu https://github.com/siyuan-note/siyuan/issues/19370
Danielcd366dd3b8ef
diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.tsindex ae8b4dbc22..418ee0a307 100644--- a/app/src/plugin/index.ts+++ b/app/src/plugin/index.ts@@ -67,6 +67,8 @@ export class Plugin {filter: string[],html: string,id: string,+ /** 是否在精简版中显示。默认值:false */+ showInLite?: boolean,callback: (protyle: import("../protyle").Protyle, nodeElement: HTMLElement) => void}[] = [];public customBlockRenders: {diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.tsindex 65914c794d..dfb9c620f3 100644--- a/app/src/protyle/hint/extend.ts+++ b/app/src/protyle/hint/extend.ts@@ -441,6 +441,7 @@ export const hintSlash = (key: string, protyle: IProtyle, sourceOrHideConfiguredplugin.protyleSlash.forEach(slash => {allList.push({filter: slash.filter,+ showInLite: slash.showInLite,id: slash.id,entryKey: getPluginSlashEntryKey(plugin.name, slash.id,slash.html === "separator" ? "separator" : "entry"),@@ -468,6 +469,8 @@ export const hintSlash = (key: string, protyle: IProtyle, sourceOrHideConfigured}), {enabled,hideConfiguredCreate,+ lite: protyle.lite,+ canUpload: !!(protyle.options.upload.handler || (protyle.options.upload.url && protyle.upload)),key,order: getEntryOrder(SLASH_MENU_ROOT_PATH),visible: (entryKey) => isEntryVisible(getSlashMenuEntryPath(entryKey)),diff --git a/app/src/protyle/hint/slashMenu.test.ts b/app/src/protyle/hint/slashMenu.test.tsindex 2477b23344..f8c456b791 100644--- a/app/src/protyle/hint/slashMenu.test.ts+++ b/app/src/protyle/hint/slashMenu.test.ts@@ -82,3 +82,37 @@ test("slash menu separator normalization removes leading, trailing, and consecutconst items = [separator("s1"), entry("a"), separator("s2"), separator("s3"), entry("b"), separator("s4")];assert.deepEqual(normalizeSlashMenuSeparators(items).map((item) => item.entryKey), ["a", "s2", "b"]);});++test("lite slash menu hides document-dependent entries and keeps local editing entries", () => {+ const unavailable = ["database", "databaseTableView", "databaseKanbanView", "databaseGalleryView",+ "newFileRef", "newSubDocRef", "template", "blockEmbed", "aiWriting", "widget", "unknown"];+ const available = ["ref", "assets", "heading1", "table", "bold", "mermaid"];+ const items = [...unavailable, ...available].map((id) => entry(id));+ assert.deepEqual(resolve(items, {lite: true}).map((item) => item.id), available);+ assert.deepEqual(resolve(items), items);+ assert.deepEqual(resolve(items, {lite: true, key: "database"}), []);+});++test("lite slash menu only offers uploads when an upload implementation is available", () => {+ const items = [entry("insertAsset"), entry("insertHTMLFile")];+ assert.deepEqual(resolve(items, {lite: true}), []);+ assert.deepEqual(resolve(items, {lite: true, canUpload: true}), items);+});++test("lite slash menu requires plugin opt-in even when its ID matches a built-in entry", () => {+ const hidden = {...entry("plugin:first:bold"), id: "bold"};+ const disabled = {...entry("plugin:second:bold"), id: "bold", showInLite: false};+ const enabled = {...entry("plugin:third:database"), id: "database", showInLite: true};+ const items = [hidden, disabled, enabled];+ assert.deepEqual(resolve(items, {lite: true}), [enabled]);+ assert.deepEqual(resolve(items), items);+ assert.deepEqual(resolve(items, {lite: true, visible: () => false}), []);+});++test("lite slash menu preserves configured order and removes empty groups", () => {+ const items = [separator("separator_1"), entry("database"), separator("separator_2"),+ entry("bold"), separator("separator_3"), entry("template"), separator("separator_4"),+ entry("italic"), separator("separator_5")];+ assert.deepEqual(resolve(items, {lite: true, order: items.map((item) => item.entryKey).reverse()})+ .map((item) => item.entryKey), ["italic", "separator_4", "bold"]);+});diff --git a/app/src/protyle/hint/slashMenu.ts b/app/src/protyle/hint/slashMenu.tsindex 46f74be141..ea273251fc 100644--- a/app/src/protyle/hint/slashMenu.ts+++ b/app/src/protyle/hint/slashMenu.ts@@ -2,6 +2,7 @@ import {reorderEntrySlots} from "../../config/entryVisibility/order";export type TSlashMenuItem = IHintData & {entryKey: string;+ showInLite?: boolean;};interface IResolveSlashMenuOptions {@@ -10,10 +11,23 @@ interface IResolveSlashMenuOptions {key: string;order: string[];visible: (entryKey: string) => boolean;+ lite?: boolean;+ canUpload?: boolean;}const isSeparator = (item?: TSlashMenuItem) => item?.html === "separator";+// 精简模式仅保留不依赖持久化文档上下文的内置项。+const LITE_SLASH_IDS = new Set([+ "assets", "ref", "heading1", "heading2", "heading3", "heading4", "heading5", "heading6",+ "list", "orderedList", "check", "quote", "tabs", "calloutNote", "calloutTip", "calloutImportant",+ "calloutWarning", "calloutCaution", "code", "table", "line", "math", "html",+ "emoji", "link", "bold", "italic", "underline", "strike", "mark", "sup", "sub", "inlineCode",+ "kbd", "tag", "inlineMath", "insertIframeURL", "insertImgURL", "insertVideoURL", "insertAudioURL",+ "staff", "chart", "flowChart", "graph", "mermaid", "mindmap", "UML",+ "infoStyle", "successStyle", "warningStyle", "errorStyle", "clearFontStyle",+]);+export const normalizeSlashMenuSeparators = (items: TSlashMenuItem[]) => {const result: TSlashMenuItem[] = [];items.forEach((item) => {@@ -44,7 +58,10 @@ export const resolveSlashMenuItems = (items: TSlashMenuItem[], options: IResolvereturn true;});const orderedItems = reorderEntrySlots(uniqueItems, options.order, (item) => item.entryKey);- const visibleItems = orderedItems.filter((item) => options.visible(item.entryKey) &&+ const visibleItems = orderedItems.filter((item) => (!options.lite || isSeparator(item) ||+ (item.entryKey === item.id ? LITE_SLASH_IDS.has(item.id) ||+ (options.canUpload && ["insertAsset", "insertHTMLFile"].includes(item.id)) : item.showInLite === true)) &&+ options.visible(item.entryKey) &&!(options.hideConfiguredCreate && item.entryKey === "newFileRef"));const filteredItems = options.key === "" ? visibleItems : visibleItems.filter((item) => item.filter?.some((filter) =>filter.toLowerCase().includes(options.key.toLowerCase())));