An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Keep mobile insert panels independent of slash hints https://github.com/siyuan-note/siyuan/issues/19696
Daniel159e8f557db3
diff --git a/app/src/config/entryVisibility/mobileSlash.test.ts b/app/src/config/entryVisibility/mobileSlash.test.tsindex 74e55ee2c2..b705ca0881 100644--- a/app/src/config/entryVisibility/mobileSlash.test.ts+++ b/app/src/config/entryVisibility/mobileSlash.test.ts@@ -2,9 +2,10 @@ import * as assert from "node:assert/strict";import {readFileSync} from "node:fs";import {test} from "node:test";import {runInNewContext} from "node:vm";-import {ModuleKind, transpileModule} from "typescript";+import {createSourceFile, isVariableStatement, ModuleKind, ScriptTarget, transpileModule} from "typescript";import * as catalog from "./catalog";import * as profile from "./profile";+import {resolveSlashMenuItems} from "../../protyle/hint/slashMenu";test("slash visibility shares profile settings and only platform defaults differ", () => {const root = catalog.SLASH_MENU_ROOT_PATH;@@ -23,6 +24,25 @@ test("slash visibility shares profile settings and only platform defaults differwindow: runtimeWindow,require: () => ({...catalog, ...profile, TOOLBAR_ENTRY_ROOT_PATH: "editor.toolbar"}),});+ const source = createSourceFile("extend.ts", readFileSync("src/protyle/hint/extend.ts", "utf8"), ScriptTarget.Latest, true);+ const declaration = source.statements.find(statement => isVariableStatement(statement) &&+ statement.declarationList.declarations.some(item => item.name.getText(source) === "hintSlash"));+ const candidates = ["heading1", "heading2", "code", "newFileRef", "separator_6"].map(id => ({+ id, value: id, html: id === "separator_6" ? "separator" : id,+ }));+ const dependencies = {...catalog, resolveSlashMenuItems,+ registerBuiltinSlashHint: (callback: unknown) => callback,+ getConfiguredEntryVisibility: api.getConfiguredEntryVisibility,+ getEntryOrder: (): string[] => [], getBuiltinSlashMenuItems: () => candidates,+ areProtylePluginExtensionsEnabled: () => false,+ getSelection: (): undefined => undefined, Element: class {}, slashBuiltinStyleIDs: {},+ };+ const hintSlash = new Function(...Object.keys(dependencies),+ transpileModule(declaration.getText(source).replace(/^export /, ""), {+ compilerOptions: {target: ScriptTarget.ES2021},+ }).outputText + "\nreturn hintSlash;")(...Object.values(dependencies));+ const editor = {lite: true, hint: {element: {closest: (): unknown => null}},+ options: {upload: {}}, wysiwyg: {element: {}}};for (const mobile of [false, true]) {runtimeWindow.siyuan.mobile = mobile ? {} : undefined;for (const visible of [false, true]) {@@ -38,6 +58,13 @@ test("slash visibility shares profile settings and only platform defaults differruntimeWindow.siyuan.storage["local-mobile-slash-menu"].enabled = legacy;assert.equal(api.isEntryVisible(root), !mobile);assert.equal(api.getConfiguredEntryVisibility(`${root}.heading1`), !mobile);+ assert.equal(api.getConfiguredEntryVisibility(`${root}.heading1`, root), true);+ editor.hint.element.closest = () => null;+ assert.equal(hintSlash("", editor).some((item: IHintData) => item.id === "heading1"), !mobile);+ editor.hint.element.closest = () => ({});+ const items: IHintData[] = hintSlash("", editor);+ assert.ok(items.some(item => item.id === "heading1"));+ assert.equal(items.some(item => item.id === "newFileRef"), false);}}for (const template of ["simple", "full"] as const) {@@ -48,11 +75,18 @@ test("slash visibility shares profile settings and only platform defaults differcustom.entries[root] = enabled;assert.equal(api.isEntryVisible(root), enabled);assert.equal(api.getConfiguredEntryVisibility(`${root}.heading2`), enabled);+ assert.equal(api.getConfiguredEntryVisibility(`${root}.heading2`, root), true);}custom.entries[root] = true;custom.entries[`${root}.heading1`] = false;assert.equal(api.isEntryVisible(`${root}.heading1`), false);assert.equal(api.isEntryVisible(`${root}.heading2`), true);+ custom.entries[root] = false;+ assert.equal(api.getConfiguredEntryVisibility(`${root}.heading1`, root), false);+ assert.equal(api.getConfiguredEntryVisibility(`${root}.heading2`, root), true);+ const items: IHintData[] = hintSlash("", editor);+ assert.equal(items.some(item => item.id === "heading1"), false);+ assert.ok(items.some(item => item.id === "heading2"));custom.entries = {};}config.active = "custom";diff --git a/app/src/config/entryVisibility/runtime.ts b/app/src/config/entryVisibility/runtime.tsindex 433f17703e..737a6e9b56 100644--- a/app/src/config/entryVisibility/runtime.ts+++ b/app/src/config/entryVisibility/runtime.ts@@ -74,7 +74,11 @@ export const isEntryVisible = (path: string): boolean => {return getConfiguredEntryVisibility(path);};-export const getConfiguredEntryVisibility = (path: string): boolean => {+export const getConfiguredEntryVisibility = (path: string, stopAt?: string): boolean => {+ // 独立入口可只复用指定菜单内部的配置,不继承该菜单触发入口的总开关。+ if (path === stopAt) {+ return true;+ }const config = getConfig();const active = config.active;let visible: boolean;@@ -90,7 +94,7 @@ export const getConfiguredEntryVisibility = (path: string): boolean => {}const parentPath = getEntryParentPath(path);if (parentPath && getEntryCatalogNode(parentPath)) {- return getConfiguredEntryVisibility(parentPath);+ return getConfiguredEntryVisibility(parentPath, stopAt);}return true;};diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.tsindex cc7fc0c739..8c68849812 100644--- a/app/src/protyle/hint/extend.ts+++ b/app/src/protyle/hint/extend.ts@@ -452,7 +452,9 @@ export const getBuiltinSlashMenuItems = (protyle: IProtyle): IHintData[] => {};export const hintSlash = registerBuiltinSlashHint((key: string, protyle: IProtyle, sourceOrHideConfiguredCreate: THintSource | boolean = false) => {- const enabled = getConfiguredEntryVisibility(SLASH_MENU_ROOT_PATH);+ // 加号面板由用户主动打开,复用插入项配置但不受输入斜杠的提示开关影响。+ const visibilityRoot = protyle.hint.element.closest("#keyboardToolbar") ? SLASH_MENU_ROOT_PATH : undefined;+ const enabled = getConfiguredEntryVisibility(SLASH_MENU_ROOT_PATH, visibilityRoot);if (!enabled) {return [];}@@ -500,7 +502,7 @@ export const hintSlash = registerBuiltinSlashHint((key: string, protyle: IProtylcanUpload: !!(protyle.options.upload.handler || (protyle.options.upload.url && protyle.upload)),key,order: getEntryOrder(SLASH_MENU_ROOT_PATH),- visible: (entryKey) => getConfiguredEntryVisibility(getSlashMenuEntryPath(entryKey)),+ visible: (entryKey) => getConfiguredEntryVisibility(getSlashMenuEntryPath(entryKey), visibilityRoot),});});