Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: fix https://github.com/siyuan-note/siyuan/issues/9409

Vanessac8924e37ae8e
diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index acc2d7af9a..2368bbe60a 100644
--- a/app/src/editor/util.ts
+++ b/app/src/editor/util.ts
@@ -40,6 +40,9 @@ export const openFileById = async (options: {
afterOpen?: () => void
}) => {
const response = await fetchSyncPost("/api/block/getBlockInfo", {id: options.id});
+ if (response.code === -1) {
+ return;
+ }
if (response.code === 3) {
showMessage(response.msg);
return;
diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.ts
index c7d6dce936..4acdb7bd24 100644
--- a/app/src/layout/dock/util.ts
+++ b/app/src/layout/dock/util.ts
@@ -32,16 +32,22 @@ export const openBacklink = async (options: {
if (!wnd) {
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
}
- const newWnd = wnd.split("lr");
if (!options.rootId) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
+ if (response.code === -1) {
+ return;
+ }
options.rootId = response.data.rootID;
options.useBlockId = response.data.rootID !== response.data.id;
options.title = response.data.name || "Untitled";
} else if (!options.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
+ if (response.code === -1) {
+ return;
+ }
options.title = response.data.name || "Untitled";
}
+ const newWnd = wnd.split("lr");
newWnd.addTab(new Tab({
icon: "iconLink",
title: options.title,
@@ -82,16 +88,22 @@ export const openGraph = async (options: {
if (!wnd) {
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
}
- const newWnd = wnd.split("lr");
if (!options.rootId) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
+ if (response.code === -1) {
+ return;
+ }
options.rootId = response.data.rootID;
options.useBlockId = response.data.rootID !== response.data.id;
options.title = response.data.name || "Untitled";
} else if (!options.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
+ if (response.code === -1) {
+ return;
+ }
options.title = response.data.name || "Untitled";
}
+ const newWnd = wnd.split("lr");
newWnd.addTab(new Tab({
icon: "iconGraph",
title: options.title,
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 0fe28bb038..556943f7f5 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -155,37 +155,39 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
const id = nodeElement.getAttribute("data-node-id");
let oldHTML = nodeElement.outerHTML;
window.siyuan.menus.menu.remove();
- window.siyuan.menus.menu.append(new MenuItem({
- label: `<input style="margin: 4px 0" class="b3-text-field fn__block" placeholder="${window.siyuan.languages.anchor}">`,
- bind(menuItemElement) {
- const inputElement = menuItemElement.querySelector("input");
- inputElement.value = element.getAttribute("data-subtype") === "d" ? "" : element.textContent;
- inputElement.addEventListener("input", () => {
- if (inputElement.value) {
- // 不能使用 textContent,否则 < 会变为 &lt;
- element.innerHTML = Lute.EscapeHTMLStr(inputElement.value);
- } else {
- fetchPost("/api/block/getRefText", {id: refBlockId}, (response) => {
- element.innerHTML = response.data;
- });
- }
- element.setAttribute("data-subtype", inputElement.value ? "s" : "d");
- });
- inputElement.addEventListener("keydown", (event) => {
- if (event.isComposing) {
- return;
- }
- if (event.key === "Enter" && !event.isComposing) {
- window.siyuan.menus.menu.remove();
- } else if (electronUndo(event)) {
- return;
- }
- });
- }
- }).element);
- window.siyuan.menus.menu.append(new MenuItem({
- type: "separator"
- }).element);
+ if (!protyle.disabled) {
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: `<input style="margin: 4px 0" class="b3-text-field fn__block" placeholder="${window.siyuan.languages.anchor}">`,
+ bind(menuItemElement) {
+ const inputElement = menuItemElement.querySelector("input");
+ inputElement.value = element.getAttribute("data-subtype") === "d" ? "" : element.textContent;
+ inputElement.addEventListener("input", () => {
+ if (inputElement.value) {
+ // 不能使用 textContent,否则 < 会变为 &lt;
+ element.innerHTML = Lute.EscapeHTMLStr(inputElement.value);
+ } else {
+ fetchPost("/api/block/getRefText", {id: refBlockId}, (response) => {
+ element.innerHTML = response.data;
+ });
+ }
+ element.setAttribute("data-subtype", inputElement.value ? "s" : "d");
+ });
+ inputElement.addEventListener("keydown", (event) => {
+ if (event.isComposing) {
+ return;
+ }
+ if (event.key === "Enter" && !event.isComposing) {
+ window.siyuan.menus.menu.remove();
+ } else if (electronUndo(event)) {
+ return;
+ }
+ });
+ }
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ type: "separator"
+ }).element);
+ }
/// #if !MOBILE
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.openBy,
@@ -282,105 +284,107 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
}).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
/// #endif
- let submenu: IMenu[] = [];
- if (element.getAttribute("data-subtype") === "s") {
- submenu.push({
- label: window.siyuan.languages.turnToDynamic,
- click() {
- element.setAttribute("data-subtype", "d");
- fetchPost("/api/block/getRefText", {id: refBlockId}, (response) => {
- element.innerHTML = response.data;
+ if (!protyle.disabled) {
+ let submenu: IMenu[] = [];
+ if (element.getAttribute("data-subtype") === "s") {
+ submenu.push({
+ label: window.siyuan.languages.turnToDynamic,
+ click() {
+ element.setAttribute("data-subtype", "d");
+ fetchPost("/api/block/getRefText", {id: refBlockId}, (response) => {
+ element.innerHTML = response.data;
+ nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
+ updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
+ });
+ focusByRange(protyle.toolbar.range);
+ }
+ });
+ } else {
+ submenu.push({
+ label: window.siyuan.languages.turnToStatic,
+ click() {
+ element.setAttribute("data-subtype", "s");
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
- });
+ focusByRange(protyle.toolbar.range);
+ }
+ });
+ }
+ submenu = submenu.concat([{
+ label: window.siyuan.languages.text,
+ click() {
+ element.outerHTML = `${element.innerHTML}<wbr>`;
+ nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
+ updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
+ focusByWbr(nodeElement, protyle.toolbar.range);
+ }
+ }, {
+ label: "*",
+ click() {
+ element.setAttribute("data-subtype", "s");
+ element.textContent = "*";
+ nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
+ updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
focusByRange(protyle.toolbar.range);
}
- });
- } else {
- submenu.push({
- label: window.siyuan.languages.turnToStatic,
+ }, {
+ label: window.siyuan.languages.text + " *",
click() {
+ element.insertAdjacentHTML("beforebegin", element.innerHTML + " ");
element.setAttribute("data-subtype", "s");
+ element.textContent = "*";
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
focusByRange(protyle.toolbar.range);
}
- });
- }
- submenu = submenu.concat([{
- label: window.siyuan.languages.text,
- click() {
- element.outerHTML = `${element.innerHTML}<wbr>`;
- nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
- focusByWbr(nodeElement, protyle.toolbar.range);
- }
- }, {
- label: "*",
- click() {
- element.setAttribute("data-subtype", "s");
- element.textContent = "*";
- nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
- focusByRange(protyle.toolbar.range);
- }
- }, {
- label: window.siyuan.languages.text + " *",
- click() {
- element.insertAdjacentHTML("beforebegin", element.innerHTML + " ");
- element.setAttribute("data-subtype", "s");
- element.textContent = "*";
- nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
- focusByRange(protyle.toolbar.range);
- }
- }, {
- label: window.siyuan.languages.link,
- icon: "iconLink",
- click() {
- element.outerHTML = `<span data-type="a" data-href="siyuan://blocks/${element.getAttribute("data-id")}">${element.innerHTML}</span><wbr>`;
- nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
- focusByWbr(nodeElement, protyle.toolbar.range);
+ }, {
+ label: window.siyuan.languages.link,
+ icon: "iconLink",
+ click() {
+ element.outerHTML = `<span data-type="a" data-href="siyuan://blocks/${element.getAttribute("data-id")}">${element.innerHTML}</span><wbr>`;
+ nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
+ updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
+ focusByWbr(nodeElement, protyle.toolbar.range);
+ }
+ }]);
+ if (element.parentElement.textContent.trim() === element.textContent.trim() && element.parentElement.tagName === "DIV") {
+ submenu.push({
+ label: window.siyuan.languages.blockEmbed,
+ icon: "iconSQL",
+ click() {
+ const html = `<div data-content="select * from blocks where id='${refBlockId}'" data-node-id="${id}" data-type="NodeBlockQueryEmbed" class="render-node" updated="${dayjs().format("YYYYMMDDHHmmss")}">${nodeElement.querySelector(".protyle-attr").outerHTML}</div>`;
+ nodeElement.outerHTML = html;
+ updateTransaction(protyle, id, html, oldHTML);
+ blockRender(protyle, protyle.wysiwyg.element);
+ }
+ });
}
- }]);
- if (element.parentElement.textContent.trim() === element.textContent.trim() && element.parentElement.tagName === "DIV") {
submenu.push({
- label: window.siyuan.languages.blockEmbed,
- icon: "iconSQL",
+ label: window.siyuan.languages.defBlock,
+ click() {
+ fetchPost("/api/block/swapBlockRef", {
+ refID: id,
+ defID: refBlockId,
+ includeChildren: false
+ });
+ }
+ });
+ submenu.push({
+ label: window.siyuan.languages.defBlockChildren,
click() {
- const html = `<div data-content="select * from blocks where id='${refBlockId}'" data-node-id="${id}" data-type="NodeBlockQueryEmbed" class="render-node" updated="${dayjs().format("YYYYMMDDHHmmss")}">${nodeElement.querySelector(".protyle-attr").outerHTML}</div>`;
- nodeElement.outerHTML = html;
- updateTransaction(protyle, id, html, oldHTML);
- blockRender(protyle, protyle.wysiwyg.element);
+ fetchPost("/api/block/swapBlockRef", {
+ refID: id,
+ defID: refBlockId,
+ includeChildren: true
+ });
}
});
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.turnInto,
+ icon: "iconRefresh",
+ submenu
+ }).element);
}
- submenu.push({
- label: window.siyuan.languages.defBlock,
- click() {
- fetchPost("/api/block/swapBlockRef", {
- refID: id,
- defID: refBlockId,
- includeChildren: false
- });
- }
- });
- submenu.push({
- label: window.siyuan.languages.defBlockChildren,
- click() {
- fetchPost("/api/block/swapBlockRef", {
- refID: id,
- defID: refBlockId,
- includeChildren: true
- });
- }
- });
- window.siyuan.menus.menu.append(new MenuItem({
- label: window.siyuan.languages.turnInto,
- icon: "iconRefresh",
- submenu
- }).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.copy,
icon: "iconCopy",
@@ -389,18 +393,19 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
writeText(`((${refBlockId} ${quote}${element.textContent}${quote}))`);
}
}).element);
- window.siyuan.menus.menu.append(new MenuItem({
- label: window.siyuan.languages.remove,
- icon: "iconTrashcan",
- click() {
- element.insertAdjacentHTML("afterend", "<wbr>");
- element.remove();
- nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
- focusByWbr(nodeElement, protyle.toolbar.range);
- }
- }).element);
-
+ if (!protyle.disabled) {
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.remove,
+ icon: "iconTrashcan",
+ click() {
+ element.insertAdjacentHTML("afterend", "<wbr>");
+ element.remove();
+ nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
+ updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
+ focusByWbr(nodeElement, protyle.toolbar.range);
+ }
+ }).element);
+ }
if (protyle?.app?.plugins) {
emitOpenMenu({
plugins: protyle.app.plugins,
@@ -419,20 +424,22 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
y: rect.top + 26,
h: 26
});
- window.siyuan.menus.menu.element.querySelector("input").select();
- window.siyuan.menus.menu.removeCB = () => {
- if (nodeElement.outerHTML !== oldHTML) {
- nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
- oldHTML = nodeElement.outerHTML;
- }
- const currentRange = getSelection().rangeCount === 0 ? undefined : getSelection().getRangeAt(0);
- if (currentRange && !protyle.element.contains(currentRange.startContainer)) {
- protyle.toolbar.range.selectNodeContents(element);
- protyle.toolbar.range.collapse(false);
- focusByRange(protyle.toolbar.range);
- }
- };
+ if (!protyle.disabled) {
+ window.siyuan.menus.menu.element.querySelector("input").select();
+ window.siyuan.menus.menu.removeCB = () => {
+ if (nodeElement.outerHTML !== oldHTML) {
+ nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
+ updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
+ oldHTML = nodeElement.outerHTML;
+ }
+ const currentRange = getSelection().rangeCount === 0 ? undefined : getSelection().getRangeAt(0);
+ if (currentRange && !protyle.element.contains(currentRange.startContainer)) {
+ protyle.toolbar.range.selectNodeContents(element);
+ protyle.toolbar.range.collapse(false);
+ focusByRange(protyle.toolbar.range);
+ }
+ };
+ }
};
export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
@@ -1664,7 +1671,7 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
focusBlock(nodeElement, undefined, false);
}
}
- nodeElement.querySelectorAll(".img--select, .av__cell--select, .av__row--select").forEach((item:HTMLElement) => {
+ nodeElement.querySelectorAll(".img--select, .av__cell--select, .av__row--select").forEach((item: HTMLElement) => {
if (item.classList.contains("av__row--select")) {
item.classList.remove("av__row--select");
item.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconUncheck");
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index bf9570e1d7..c15c16aa21 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -1302,7 +1302,7 @@ export class WYSIWYG {
if (types.length > 0) {
removeSearchMark(target);
}
- if (types.includes("block-ref") && !protyle.disabled) {
+ if (types.includes("block-ref")) {
refMenu(protyle, target);
// 阻止 popover
target.setAttribute("prevent-popover", "true");