diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index acc2d7af9a6..2368bbe60ad 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 c7d6dce9360..4acdb7bd24f 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 0fe28bb038c..556943f7f5f 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: ``, - bind(menuItemElement) { - const inputElement = menuItemElement.querySelector("input"); - inputElement.value = element.getAttribute("data-subtype") === "d" ? "" : element.textContent; - inputElement.addEventListener("input", () => { - if (inputElement.value) { - // 不能使用 textContent,否则 < 会变为 < - 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: ``, + bind(menuItemElement) { + const inputElement = menuItemElement.querySelector("input"); + inputElement.value = element.getAttribute("data-subtype") === "d" ? "" : element.textContent; + inputElement.addEventListener("input", () => { + if (inputElement.value) { + // 不能使用 textContent,否则 < 会变为 < + 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}`; + 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}`; - 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 = `${element.innerHTML}`; - 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 = `${element.innerHTML}`; + 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 = `
${nodeElement.querySelector(".protyle-attr").outerHTML}
`; + 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 = `
${nodeElement.querySelector(".protyle-attr").outerHTML}
`; - 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", ""); - 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", ""); + 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 bf9570e1d79..c15c16aa216 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"); diff --git a/scripts/win-build.bat b/scripts/win-build.bat index 68f1b64acca..8e2f50da4a6 100644 --- a/scripts/win-build.bat +++ b/scripts/win-build.bat @@ -33,9 +33,9 @@ echo 'Building Electron' cd app call pnpm run dist -@REM cd .. +cd .. -@REM echo 'Building Appx' -@REM echo 'Building Appx should be disabled if you do not need it. Not configured correctly will lead to build failures' -@REM cd . > app\build\win-unpacked\resources\ms-store -@REM electron-windows-store --input-directory app\build\win-unpacked --output-directory app\build\ --package-version 1.0.0.0 --package-name SiYuan --manifest app\appx\AppxManifest.xml --assets app\appx\assets\ --make-pri true +echo 'Building Appx' +echo 'Building Appx should be disabled if you do not need it. Not configured correctly will lead to build failures' +cd . > app\build\win-unpacked\resources\ms-store +electron-windows-store --input-directory app\build\win-unpacked --output-directory app\build\ --package-version 1.0.0.0 --package-name SiYuan --manifest app\appx\AppxManifest.xml --assets app\appx\assets\ --make-pri true