This commit is contained in:
Vanessa 2023-02-06 21:50:28 +08:00
parent 9a1b8148e1
commit 7928856696
3 changed files with 74 additions and 2 deletions

View file

@ -5,6 +5,9 @@ import {setPadding} from "../protyle/ui/initUI";
import {setPosition} from "../util/setPosition";
import {hideElements} from "../protyle/ui/hideElements";
import {Constants} from "../constants";
/// #if !BROWSER
import {openNewWindowById} from "../window/openNewWindow";
/// #endif
import {disabledProtyle} from "../protyle/util/onGet";
export class BlockPanel {
@ -221,6 +224,10 @@ export class BlockPanel {
target.setAttribute("aria-label", window.siyuan.languages.unpin);
this.element.setAttribute("data-pin", "true");
}
} else if (type === "open") {
/// #if !BROWSER
openNewWindowById(this.nodeIds[0])
/// #endif
}
event.preventDefault();
event.stopPropagation();
@ -256,6 +263,12 @@ export class BlockPanel {
editorElement.addEventListener("mouseleave", () => {
hideElements(["gutter"], editor.protyle);
});
// 浮窗完整文档面包屑应不显示 退出聚焦
if (editor.protyle.breadcrumb && editor.protyle.block.id === editor.protyle.block.rootID) {
const exitFocusElement = editor.protyle.breadcrumb.element.parentElement.querySelector('[data-type="exit-focus"]')
exitFocusElement.classList.add("fn__none")
exitFocusElement.nextElementSibling.classList.add("fn__none")
}
}
});
this.editors.push(editor);
@ -286,8 +299,15 @@ export class BlockPanel {
this.destroy();
return;
}
let openHTML = ""
/// #if !BROWSER
if (this.nodeIds.length === 1) {
openHTML = `<span data-type="open" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.openByNewWindow}"><svg style="width: 10px"><use xlink:href="#iconMove"></use></svg></span>
<span class="fn__space"></span>`
}
/// #endif
let html = `<div class="block__icons block__icons--border">
<span class="fn__space fn__flex-1"></span>
<span class="fn__space fn__flex-1"></span>${openHTML}
<span data-type="pin" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.pin}"><svg><use xlink:href="#iconPin"></use></svg></span>
<span class="fn__space"></span>
<span data-type="close" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.close}"><svg style="width: 10px"><use xlink:href="#iconClose"></use></svg></span>

View file

@ -27,6 +27,7 @@ import {pasteAsPlainText, pasteText} from "../protyle/util/paste";
/// #if !MOBILE
import {openFileById, updateBacklinkGraph} from "../editor/util";
import {openGlobalSearch} from "../search/util";
import {openNewWindowById} from "../window/openNewWindow";
/// #endif
import {getSearch, isMobile} from "../util/functions";
import {removeFoldHeading} from "../protyle/util/heading";
@ -149,6 +150,14 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
});
}
}).element);
/// #if !BROWSER
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.openByNewWindow,
icon: "iconMove",
click() {
openNewWindowById(refBlockId)
}
}).element);
/// #endif
/// #endif
let submenu: IMenu[] = [];

View file

@ -1,9 +1,10 @@
import {layoutToJSON} from "../layout/util";
/// #if !BROWSER
import { ipcRenderer } from "electron";
import {ipcRenderer} from "electron";
/// #endif
import {Constants} from "../constants";
import {Tab} from "../layout/Tab";
import {fetchPost} from "../util/fetch";
export const openNewWindow = (tab: Tab) => {
const json = {};
@ -13,3 +14,45 @@ export const openNewWindow = (tab: Tab) => {
/// #endif
tab.parent.removeTab(tab.id);
};
export const openNewWindowById = (id: string) => {
fetchPost("api/block/getBlockInfo", {id}, (response) => {
const json: any = {
title: response.data.rootTitle,
docIcon: response.data.rootIcon,
pin: false,
active: true,
instance: "Tab",
action: "Tab",
children: {
notebookId: response.data.box,
blockId: id,
rootId: response.data.rootID,
mode: "wysiwyg",
instance: "Editor",
}
}
if (response.data.rootID === id) {
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
json.children.scrollAttr = JSON.parse(attrResponse.data.scroll || "{}");
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`);
/// #endif
});
} else {
json.children.action = Constants.CB_GET_ALL;
json.children.scrollAttr = {
startId: id,
endId: id,
scrollTop: 0,
focusId: id,
focusStart: 0,
focusEnd: 0
}
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`);
/// #endif
}
});
};