An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: fix https://github.com/siyuan-note/siyuan/issues/11549
Vanessa750303da7ec9
diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.tsindex 39b2029abe..7dfc31aa4f 100644--- a/app/src/block/Panel.ts+++ b/app/src/block/Panel.ts@@ -9,13 +9,13 @@ import {openNewWindowById} from "../window/openNewWindow";/// #endif/// #if !MOBILEimport {moveResize} from "../dialog/moveResize";+import {openFileById} from "../editor/util";/// #endifimport {fetchPost} from "../util/fetch";import {showMessage} from "../dialog/message";import {App} from "../index";import {isMobile} from "../util/functions";import {resize} from "../protyle/util/resize";-import {openFileById} from "../editor/util";export class BlockPanel {public element: HTMLElement;@@ -120,11 +120,13 @@ export class BlockPanel {openNewWindowById(this.nodeIds[0]);/// #endif} else if (type === "stickTab") {+ /// #if !BROWSERopenFileById({app: options.app,id: this.nodeIds[0],action: this.editors[0].protyle.block.rootID !== this.nodeIds[0] ? [Constants.CB_GET_ALL] : [Constants.CB_GET_CONTEXT],});+ /// #endif}event.preventDefault();event.stopPropagation();diff --git a/app/src/card/openCard.ts b/app/src/card/openCard.tsindex c4e6a2d5fc..804a3403ad 100644--- a/app/src/card/openCard.ts+++ b/app/src/card/openCard.ts@@ -174,7 +174,6 @@ export const bindCardEvent = async (options: {action: [Constants.CB_GET_ALL],render: {background: false,- title: false,gutter: true,breadcrumbDocName: true,},diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.tsindex 99eb970687..5895356aeb 100644--- a/app/src/dialog/processSystem.ts+++ b/app/src/dialog/processSystem.ts@@ -56,7 +56,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRootid: window.siyuan.mobile.editor.protyle.block.rootID}, (response) => {setTitle(response.data.name);- (document.getElementById("toolbarName") as HTMLInputElement).value = response.data.name === window.siyuan.languages.untitled ? "" : response.data.name;+ window.siyuan.mobile.editor.protyle.title.setTitle(response.data.name);});}}diff --git a/app/src/history/diff.ts b/app/src/history/diff.tsindex 5f229ec6ba..c33ae0d50d 100644--- a/app/src/history/diff.ts+++ b/app/src/history/diff.ts@@ -50,7 +50,6 @@ const renderCompare = (app: App, element: HTMLElement) => {action: [Constants.CB_GET_HISTORY],render: {background: false,- title: false,gutter: false,breadcrumb: false,breadcrumbDocName: false,@@ -66,7 +65,6 @@ const renderCompare = (app: App, element: HTMLElement) => {},render: {background: false,- title: false,gutter: false,breadcrumb: false,breadcrumbDocName: false,diff --git a/app/src/history/doc.ts b/app/src/history/doc.tsindex 51221293a5..0df93c9220 100644--- a/app/src/history/doc.ts+++ b/app/src/history/doc.ts@@ -116,7 +116,6 @@ export const openDocHistory = (options: {action: [Constants.CB_GET_HISTORY],render: {background: false,- title: false,gutter: false,breadcrumb: false,breadcrumbDocName: false,diff --git a/app/src/history/history.ts b/app/src/history/history.tsindex 0e2a890ddc..92716f25c4 100644--- a/app/src/history/history.ts+++ b/app/src/history/history.ts@@ -471,7 +471,6 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {action: [Constants.CB_GET_HISTORY],render: {background: false,- title: false,gutter: false,breadcrumb: false,breadcrumbDocName: false,diff --git a/app/src/layout/dock/Backlink.ts b/app/src/layout/dock/Backlink.tsindex 2f75d385b2..8f2a2b3175 100644--- a/app/src/layout/dock/Backlink.ts+++ b/app/src/layout/dock/Backlink.ts@@ -450,7 +450,6 @@ export class Backlink extends Model {backlinkData: isMention ? response.data.backmentions : response.data.backlinks,render: {background: false,- title: false,gutter: true,scroll: false,breadcrumb: false,diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.tsindex 468756db61..a1e1f82bfc 100644--- a/app/src/mobile/editor.ts+++ b/app/src/mobile/editor.ts@@ -58,6 +58,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_action,render: {scroll: true,+ title: true,background: true,gutter: true,},@@ -67,6 +68,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_}};if (window.siyuan.mobile.editor) {+ window.siyuan.mobile.editor.protyle.title.element.removeAttribute("data-render");pushBack();addLoading(window.siyuan.mobile.editor.protyle);if (window.siyuan.mobile.editor.protyle.block.rootID !== data.data.rootID) {@@ -105,7 +107,6 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_} else {window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), protyleOptions);}- (document.getElementById("toolbarName") as HTMLInputElement).value = data.data.rootTitle === window.siyuan.languages.untitled ? "" : data.data.rootTitle;setEditor();closePanel();});diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.tsindex ef29611936..94abfaa066 100644--- a/app/src/mobile/util/MobileBackFoward.ts+++ b/app/src/mobile/util/MobileBackFoward.ts@@ -44,7 +44,7 @@ const focusStack = (backStack: IBackStack) => {id: backStack.id,}, (response) => {setTitle(response.data.name);- (document.getElementById("toolbarName") as HTMLInputElement).value = response.data.name === window.siyuan.languages.untitled ? "" : response.data.name;+ protyle.title.setTitle(response.data.name);protyle.background.render(response.data.ial, protyle.block.rootID);protyle.wysiwyg.renderCustom(response.data.ial);});diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.tsindex c3082e0531..0279d02d29 100644--- a/app/src/protyle/header/Title.ts+++ b/app/src/protyle/header/Title.ts@@ -37,6 +37,7 @@ export class Title {if (window.siyuan.config.editor.displayBookmarkIcon) {this.element.classList.add("protyle-wysiwyg--attr");}+ /// #if !MOBILE// 标题内需要一个空格,避免首次加载出现`请输入文档名`干扰this.element.innerHTML = `<span aria-label="${isMac() ? window.siyuan.languages.gutterTip2 : window.siyuan.languages.gutterTip2.replace("⇧", "Shift+")}" data-position="right" class="protyle-title__icon ariaLabel"><svg><use xlink:href="#iconFile"></use></svg></span><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}" class="protyle-title__input" data-tip="${window.siyuan.languages._kernel[16]}"> </div><div class="protyle-attr"></div>`;@@ -248,6 +249,9 @@ export class Title {}).element);window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY});});+ /// #else+ this.element.innerHTML = '<div class="protyle-attr"></div>';+ /// #endifthis.element.querySelector(".protyle-attr").addEventListener("click", (event: MouseEvent & {target: HTMLElement}) => {@@ -282,13 +286,20 @@ export class Title {}public setTitle(title: string) {+ /// #if MOBILE+ const inputElement = document.getElementById("toolbarName") as HTMLInputElement;+ if (code160to32(title) !== code160to32(inputElement.value)) {+ inputElement.value = title === window.siyuan.languages.untitled ? "" : title;+ }+ /// #elseif (code160to32(title) !== code160to32(this.editElement.textContent)) {this.editElement.textContent = title === window.siyuan.languages.untitled ? "" : title;}+ /// #endif}public render(protyle: IProtyle, response: IWebSocketData) {- if (this.editElement.getAttribute("data-render") === "true") {+ if (this.element.getAttribute("data-render") === "true") {return false;}this.element.setAttribute("data-node-id", protyle.block.rootID);@@ -297,7 +308,7 @@ export class Title {}protyle.background?.render(response.data.ial, protyle.block.rootID);protyle.wysiwyg.renderCustom(response.data.ial);- this.editElement.setAttribute("data-render", "true");+ this.element.setAttribute("data-render", "true");this.setTitle(response.data.ial.title);let nodeAttrHTML = "";if (response.data.ial.bookmark) {@@ -327,7 +338,7 @@ export class Title {this.element.querySelector(".protyle-attr").insertAdjacentHTML("beforeend", `<div class="protyle-attr--refcount popover__block" data-defids='${JSON.stringify([protyle.block.rootID])}' data-id='${JSON.stringify(response.data.refIDs)}'>${response.data.refCount}</div>`);}// 存在设置新建文档名模板,不能使用 Untitled 进行判断,https://ld246.com/article/1649301009888- if (new Date().getTime() - dayjs(response.data.id.split("-")[0]).toDate().getTime() < 2000) {+ if (this.editElement && new Date().getTime() - dayjs(response.data.id.split("-")[0]).toDate().getTime() < 2000) {const range = this.editElement.ownerDocument.createRange();range.selectNodeContents(this.editElement);focusByRange(range);diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.tsindex f7b1b033f1..3c5dc5718d 100644--- a/app/src/protyle/index.ts+++ b/app/src/protyle/index.ts@@ -23,10 +23,10 @@ import {} from "./wysiwyg/transaction";import {fetchPost} from "../util/fetch";/// #if !MOBILE-import {Title} from "./header/Title";import {updatePanelByEditor} from "../editor/util";import {setPanelFocus} from "../layout/util";/// #endif+import {Title} from "./header/Title";import {Background} from "./header/Background";import {onGet, setReadonlyByConfig} from "./util/onGet";import {reloadProtyle} from "./util/reload";@@ -77,11 +77,9 @@ export class Protyle {if (mergedOptions.render.breadcrumb) {this.protyle.breadcrumb = new Breadcrumb(this.protyle);}- /// #if !MOBILEif (mergedOptions.render.title) {this.protyle.title = new Title(this.protyle);}- /// #endifif (mergedOptions.render.background) {this.protyle.background = new Background(this.protyle);}@@ -178,7 +176,8 @@ export class Protyle {}}if (this.protyle.options.render.title && this.protyle.block.parentID === data.data.id) {- if (getSelection().rangeCount > 0 && this.protyle.title.editElement.contains(getSelection().getRangeAt(0).startContainer)) {+ if (!document.body.classList.contains("body--blur") && getSelection().rangeCount > 0 &&+ this.protyle.title.editElement?.contains(getSelection().getRangeAt(0).startContainer)) {// 标题编辑中的不用更新 https://github.com/siyuan-note/siyuan/issues/6565} else {this.protyle.title.setTitle(data.data.title);diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex f347cd58c7..6bcee1029c 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -290,10 +290,9 @@ export const disabledProtyle = (protyle: IProtyle) => {window.siyuan.menus.menu.remove();hideElements(["gutter", "toolbar", "select", "hint", "util"], protyle);protyle.disabled = true;- if (protyle.title) {- const titleElement = protyle.title.element.querySelector(".protyle-title__input") as HTMLElement;- titleElement.setAttribute("contenteditable", "false");- titleElement.style.userSelect = "text";+ if (protyle.title && protyle.title.editElement) {+ protyle.title.editElement.setAttribute("contenteditable", "false");+ protyle.title.editElement.style.userSelect = "text";}/// #if MOBILEdocument.getElementById("toolbarName").setAttribute("readonly", "readonly");@@ -351,10 +350,9 @@ export const enableProtyle = (protyle: IProtyle) => {}// 用于区分移动端样式protyle.wysiwyg.element.setAttribute("data-readonly", "false");- if (protyle.title) {- const titleElement = protyle.title.element.querySelector(".protyle-title__input") as HTMLElement;- titleElement.setAttribute("contenteditable", "true");- titleElement.style.userSelect = "";+ if (protyle.title && protyle.title.editElement) {+ protyle.title.editElement.setAttribute("contenteditable", "true");+ protyle.title.editElement.style.userSelect = "";}if (protyle.background) {protyle.background.element.classList.add("protyle-background--enable");diff --git a/app/src/protyle/util/reload.ts b/app/src/protyle/util/reload.tsindex 57b46a505c..7a0a1c64e0 100644--- a/app/src/protyle/util/reload.ts+++ b/app/src/protyle/util/reload.ts@@ -16,7 +16,7 @@ export const reloadProtyle = (protyle: IProtyle, focus: boolean, updateReadonly?protyle.wysiwyg.element.classList.remove("protyle-wysiwyg--attr");}if (protyle.title) {- protyle.title.editElement.removeAttribute("data-render");+ protyle.title.element.removeAttribute("data-render");protyle.title.element.setAttribute("spellcheck", window.siyuan.config.editor.spellcheck.toString());if (window.siyuan.config.editor.displayBookmarkIcon) {protyle.title.element.classList.add("protyle-wysiwyg--attr");diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex 5fbb38662e..ecdad4e38b 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -248,8 +248,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {previousElement = foldElement;}}- } else if (protyle.title && (protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" ||- protyle.contentElement.scrollTop === 0)) {+ } else if (protyle.title && protyle.title.editElement &&+ (protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" || protyle.contentElement.scrollTop === 0)) {protyle.title.editElement.focus();} else if (protyle.contentElement.scrollTop !== 0) {protyle.contentElement.scrollTop = 0;@@ -636,7 +636,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {(!firstEditElement && nodeElement.isSameNode(protyle.wysiwyg.element.firstElementChild))) {// 不能用\n判断,否则文字过长折行将错误 https://github.com/siyuan-note/siyuan/issues/6156if (getSelectionPosition(nodeElement, range).top - protyle.wysiwyg.element.getBoundingClientRect().top < 40 || nodeElement.classList.contains("av")) {- if (protyle.title && (protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" ||+ if (protyle.title && protyle.title.editElement &&+ (protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" ||protyle.contentElement.scrollTop === 0)) {protyle.title.editElement.focus();} else {diff --git a/app/src/util/highlightById.ts b/app/src/util/highlightById.tsindex ed3b4a2c97..c92e573e92 100644--- a/app/src/util/highlightById.ts+++ b/app/src/util/highlightById.ts@@ -32,7 +32,7 @@ export const highlightById = (protyle: IProtyle, id: string, top = false) => {bgFade(nodeElement);return nodeElement;// 仅配合前进后退使用}- if (id === protyle.block.rootID && protyle.options.render.title) {+ if (id === protyle.block.rootID && protyle.options.render.title && protyle.title.editElement) {bgFade(protyle.title.editElement);return protyle.title.editElement;}