From 9a1b8148e1e693bf64c75fb524b08850e43892af Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 6 Feb 2023 18:40:31 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/4025 --- app/src/menus/block.ts | 40 +++++++++++++++++++++++++++++++++ app/src/menus/protyle.ts | 1 + app/src/protyle/gutter/index.ts | 35 ++--------------------------- app/src/protyle/header/Title.ts | 5 +++++ 4 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 app/src/menus/block.ts diff --git a/app/src/menus/block.ts b/app/src/menus/block.ts new file mode 100644 index 000000000..b0b8c84a5 --- /dev/null +++ b/app/src/menus/block.ts @@ -0,0 +1,40 @@ +import {MenuItem} from "./Menu"; +import {Dialog} from "../dialog"; +import {isMobile} from "../util/functions"; +import {fetchPost} from "../util/fetch"; + +export const transferBlockRef = (id:string) => { + window.siyuan.menus.menu.append(new MenuItem({ + label: window.siyuan.languages.transferBlockRef, + click() { + const renameDialog = new Dialog({ + title: window.siyuan.languages.transferBlockRef, + content: `
+ +
${window.siyuan.languages.transferBlockRefTip}
+
+
+
+ +
`, + width: isMobile() ? "80vw" : "520px", + }); + const inputElement = renameDialog.element.querySelector("input") as HTMLInputElement; + const btnsElement = renameDialog.element.querySelectorAll(".b3-button"); + renameDialog.bindInput(inputElement, () => { + (btnsElement[1] as HTMLButtonElement).click(); + }); + inputElement.focus(); + btnsElement[0].addEventListener("click", () => { + renameDialog.destroy(); + }); + btnsElement[1].addEventListener("click", () => { + fetchPost("/api/block/transferBlockRef", { + fromID: id, + toID: inputElement.value, + }); + renameDialog.destroy(); + }); + } + }).element); +} diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index a25461d17..6bf314049 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -150,6 +150,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => { } }).element); /// #endif + /// #endif let submenu: IMenu[] = []; if (element.getAttribute("data-subtype") === "s") { submenu.push({ diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 7b9ab9a1a..6f346d3d9 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -35,6 +35,7 @@ import {hintMoveBlock} from "../hint/extend"; import {makeCard} from "../../card/makeCard"; import {Dialog} from "../../dialog"; import {isMobile} from "../../util/functions"; +import {transferBlockRef} from "../../menus/block"; export class Gutter { public element: HTMLElement; @@ -1374,39 +1375,7 @@ export class Gutter { }).element); const countElement = nodeElement.lastElementChild.querySelector(".protyle-attr--refcount") if (countElement && countElement.textContent) { - window.siyuan.menus.menu.append(new MenuItem({ - label: window.siyuan.languages.transferBlockRef, - click() { - const renameDialog = new Dialog({ - title: window.siyuan.languages.transferBlockRef, - content: `
- -
${window.siyuan.languages.transferBlockRefTip}
-
-
-
- -
`, - width: isMobile() ? "80vw" : "520px", - }); - const inputElement = renameDialog.element.querySelector("input") as HTMLInputElement; - const btnsElement = renameDialog.element.querySelectorAll(".b3-button"); - renameDialog.bindInput(inputElement, () => { - (btnsElement[1] as HTMLButtonElement).click(); - }); - inputElement.focus(); - btnsElement[0].addEventListener("click", () => { - renameDialog.destroy(); - }); - btnsElement[1].addEventListener("click", () => { - fetchPost("/api/block/transferBlockRef", { - fromID: id, - toID: inputElement.value, - }); - renameDialog.destroy(); - }); - } - }).element); + transferBlockRef(id) } } window.siyuan.menus.menu.append(new MenuItem({ diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 57955c517..07b6e525c 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -32,6 +32,7 @@ import {deleteFile} from "../../editor/deleteFile"; import {genEmptyElement} from "../../block/util"; import {transaction} from "../wysiwyg/transaction"; import {hideTooltip} from "../../dialog/tooltip"; +import {transferBlockRef} from "../../menus/block"; export class Title { public element: HTMLElement; @@ -307,6 +308,10 @@ export class Title { } }).element); window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); + const countElement = this.element.lastElementChild.querySelector(".protyle-attr--refcount") + if (countElement && countElement.textContent) { + transferBlockRef(protyle.block.rootID); + } window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.attr, accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"),