Vanessa 2025-07-03 21:42:00 +08:00
parent a3c5d92f58
commit 6d6112a50d
3 changed files with 37 additions and 81 deletions

View file

@ -281,7 +281,15 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.stopPropagation();
return true;
} else if (type === "av-gallery-more") {
openGalleryItemMenu({target, blockElement, protyle, returnMenu: false});
const rect = target.getBoundingClientRect();
openGalleryItemMenu({
target,
protyle,
position: {
x: rect.left,
y: rect.bottom
}
});
event.preventDefault();
event.stopPropagation();
return true;
@ -300,15 +308,23 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
if (!blockElement) {
return false;
}
if (!rowElement.classList.contains("av__row--select")) {
clearSelect(["row"], blockElement);
const avType = blockElement.getAttribute("data-av-type") as TAVView;
if (avType === "table") {
if (!rowElement.classList.contains("av__row--select")) {
clearSelect(["row"], blockElement);
}
clearSelect(["cell"], blockElement);
rowElement.classList.add("av__row--select");
rowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconCheck");
updateHeader(rowElement);
} else {
if (!rowElement.classList.contains("av__gallery-item--select")) {
clearSelect(["galleryItem"], blockElement);
}
rowElement.classList.add("av__gallery-item--select");
}
clearSelect(["cell"], blockElement);
const menu = new Menu();
rowElement.classList.add("av__row--select");
rowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconCheck");
const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header)");
updateHeader(rowElement);
const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header), .av__gallery-item--select");
const keyCellElement = rowElements[0].querySelector(".av__cell[data-block-id]") as HTMLElement;
const ids = Array.from(rowElements).map(item => item.getAttribute("data-id"));
if (rowElements.length === 1 && keyCellElement.getAttribute("data-detached") !== "true") {
@ -558,7 +574,7 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
id: "insertRowBefore",
icon: "iconBefore",
label: `<div class="fn__flex" style="align-items: center;">
${window.siyuan.languages.insertRowBefore.replace("${x}", `<span class="fn__space"></span><input style="width:64px" type="number" step="1" min="1" value="1" placeholder="${window.siyuan.languages.enterKey}" class="b3-text-field"><span class="fn__space"></span>`)}
${window.siyuan.languages[avType === "table" ? "insertRowBefore" : "insertItemBefore"].replace("${x}", `<span class="fn__space"></span><input style="width:64px" type="number" step="1" min="1" value="1" placeholder="${window.siyuan.languages.enterKey}" class="b3-text-field"><span class="fn__space"></span>`)}
</div>`,
bind(element) {
const inputElement = element.querySelector("input");
@ -581,7 +597,7 @@ ${window.siyuan.languages.insertRowBefore.replace("${x}", `<span class="fn__spac
id: "insertRowAfter",
icon: "iconAfter",
label: `<div class="fn__flex" style="align-items: center;">
${window.siyuan.languages.insertRowAfter.replace("${x}", `<span class="fn__space"></span><input style="width:64px" type="number" step="1" min="1" placeholder="${window.siyuan.languages.enterKey}" class="b3-text-field" value="1"><span class="fn__space"></span>`)}
${window.siyuan.languages[avType === "table" ? "insertRowAfter" : "insertItemAfter"].replace("${x}", `<span class="fn__space"></span><input style="width:64px" type="number" step="1" min="1" placeholder="${window.siyuan.languages.enterKey}" class="b3-text-field" value="1"><span class="fn__space"></span>`)}
</div>`,
bind(element) {
const inputElement = element.querySelector("input");

View file

@ -1,11 +1,9 @@
import {transaction} from "../../../wysiwyg/transaction";
import {Menu} from "../../../../plugin/Menu";
import * as dayjs from "dayjs";
import {hasClosestByClassName} from "../../../util/hasClosest";
import {genCellValueByElement} from "../cell";
import {clearSelect} from "../../../util/clearSelect";
import {unicode2Emoji} from "../../../../emoji";
import {getColIconByType} from "../col";
import {avContextmenu} from "../action";
export const setGalleryCover = (options: {
view: IAVGallery
@ -233,73 +231,17 @@ export const setGalleryRatio = (options: {
export const openGalleryItemMenu = (options: {
target: HTMLElement,
blockElement: HTMLElement,
protyle: IProtyle,
returnMenu: boolean
position: {
x:number,
y:number
}
}) => {
const menu = new Menu();
const avID = options.blockElement.getAttribute("data-av-id");
const cardElement = hasClosestByClassName(options.target, "av__gallery-item");
if (!cardElement) {
return;
}
if (!cardElement.classList.contains("av__gallery-item--select")) {
clearSelect(["galleryItem"], options.blockElement);
cardElement.classList.add("av__gallery-item--select");
}
menu.addItem({
icon: "iconTrashcan",
warning: true,
label: window.siyuan.languages.delete,
click() {
const srcIDs: string[] = [];
const srcs: IOperationSrcs[] = [];
let previousID = "";
options.blockElement.querySelectorAll(".av__gallery-item--select").forEach((item, index) => {
const blockValue = genCellValueByElement("block", item.querySelector(".av__cell[data-block-id]"));
const id = item.getAttribute("data-id");
srcIDs.push(id);
srcs.push({
id,
isDetached: blockValue.isDetached,
content: blockValue.block.content
});
item.remove();
if (index === 0) {
previousID = item.previousElementSibling?.getAttribute("data-id") || "";
}
});
const newUpdated = dayjs().format("YYYYMMDDHHmmss");
transaction(options.protyle, [{
action: "removeAttrViewBlock",
srcIDs,
avID,
}, {
action: "doUpdateUpdated",
id: options.blockElement.dataset.nodeId,
data: newUpdated,
}], [{
action: "insertAttrViewBlock",
avID,
previousID,
srcs,
blockID: options.blockElement.dataset.nodeId
}, {
action: "doUpdateUpdated",
id: options.blockElement.dataset.nodeId,
data: options.blockElement.getAttribute("updated")
}]);
options.blockElement.setAttribute("updated", newUpdated);
}
});
if (options.returnMenu) {
return menu;
}
const rect = options.target.getBoundingClientRect();
menu.open({
x: rect.left,
y: rect.bottom
});
avContextmenu(options.protyle, cardElement, options.position);
};
export const editGalleryItem = (target: Element) => {

View file

@ -1973,15 +1973,13 @@ export class WYSIWYG {
if (protyle.disabled) {
return false;
}
const menu = openGalleryItemMenu({
openGalleryItemMenu({
target: avGalleryItemElement.querySelector(".protyle-icon--last"),
blockElement: nodeElement,
protyle,
returnMenu: true
});
menu.open({
x: event.clientX,
y: event.clientY
position: {
x: event.clientX,
y: event.clientY
}
});
event.stopPropagation();
event.preventDefault();