mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-26 11:28:49 +01:00
This commit is contained in:
parent
03831ef891
commit
ea6acffb46
2 changed files with 40 additions and 7 deletions
|
|
@ -242,7 +242,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
return true;
|
||||
} else if (target.classList.contains("item") && target.parentElement.classList.contains("layout-tab-bar")) {
|
||||
if (target.classList.contains("item--focus")) {
|
||||
openViewMenu(target)
|
||||
openViewMenu({protyle, blockElement, element:target})
|
||||
} else {
|
||||
blockElement.removeAttribute("data-render");
|
||||
avRender(blockElement, protyle, undefined, target.dataset.id);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import {Menu} from "../../../plugin/Menu";
|
||||
import {unicode2Emoji} from "../../../emoji";
|
||||
import {transaction} from "../../wysiwyg/transaction";
|
||||
import {openMenuPanel} from "./openMenuPanel";
|
||||
import {removeBlock} from "../../wysiwyg/remove";
|
||||
import {getEditorRange} from "../../util/selection";
|
||||
import {fetchPost} from "../../../util/fetch";
|
||||
|
||||
export const openViewMenu = (element: HTMLElement) => {
|
||||
export const openViewMenu = (options: { protyle: IProtyle, blockElement: HTMLElement, element: HTMLElement }) => {
|
||||
const menu = new Menu("av-view");
|
||||
if (menu.isOpen) {
|
||||
return;
|
||||
|
|
@ -11,14 +15,15 @@ export const openViewMenu = (element: HTMLElement) => {
|
|||
icon: "iconEdit",
|
||||
label: window.siyuan.languages.rename,
|
||||
click() {
|
||||
|
||||
openMenuPanel({protyle: options.protyle, blockElement: options.blockElement, type: "config"});
|
||||
(document.querySelector('.av__panel .b3-text-field[data-type="name"]') as HTMLInputElement).focus()
|
||||
}
|
||||
})
|
||||
menu.addItem({
|
||||
icon: "iconSettings",
|
||||
label: window.siyuan.languages.config,
|
||||
click() {
|
||||
|
||||
openMenuPanel({protyle: options.protyle, blockElement: options.blockElement, type: "config"});
|
||||
}
|
||||
})
|
||||
menu.addSeparator();
|
||||
|
|
@ -26,17 +31,45 @@ export const openViewMenu = (element: HTMLElement) => {
|
|||
icon: "iconCopy",
|
||||
label: window.siyuan.languages.duplicate,
|
||||
click() {
|
||||
|
||||
fetchPost("/api/av/renderAttributeView", {
|
||||
id: options.blockElement.dataset.avId,
|
||||
}, (response) => {
|
||||
const id = Lute.NewNodeID();
|
||||
const data = response.data as IAV;
|
||||
transaction(options.protyle, [{
|
||||
action: "duplicateAttrViewView",
|
||||
avID: data.id,
|
||||
previousID: data.viewID,
|
||||
id
|
||||
}], [{
|
||||
action: "removeAttrViewView",
|
||||
avID: data.id,
|
||||
id
|
||||
}]);
|
||||
});
|
||||
}
|
||||
})
|
||||
menu.addItem({
|
||||
icon: "iconTrashcan",
|
||||
label: window.siyuan.languages.delete,
|
||||
click() {
|
||||
|
||||
fetchPost("/api/av/renderAttributeView", {
|
||||
id: options.blockElement.dataset.avId,
|
||||
}, (response) => {
|
||||
const data = response.data as IAV;
|
||||
if (data.views.length === 1) {
|
||||
removeBlock(options.protyle, options.blockElement, getEditorRange(options.blockElement))
|
||||
} else {
|
||||
transaction(options.protyle, [{
|
||||
action: "removeAttrViewView",
|
||||
avID: data.id,
|
||||
id: data.viewID
|
||||
}]);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
const rect = element.getBoundingClientRect()
|
||||
const rect = options.element.getBoundingClientRect()
|
||||
menu.open({
|
||||
x: rect.left,
|
||||
y: rect.bottom
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue