diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts
index 551ed2ab2..656d43b61 100644
--- a/app/src/protyle/render/av/action.ts
+++ b/app/src/protyle/render/av/action.ts
@@ -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: `
-${window.siyuan.languages.insertRowBefore.replace("${x}", ``)}
+${window.siyuan.languages[avType === "table" ? "insertRowBefore" : "insertItemBefore"].replace("${x}", ``)}
`,
bind(element) {
const inputElement = element.querySelector("input");
@@ -581,7 +597,7 @@ ${window.siyuan.languages.insertRowBefore.replace("${x}", `
-${window.siyuan.languages.insertRowAfter.replace("${x}", ``)}
+${window.siyuan.languages[avType === "table" ? "insertRowAfter" : "insertItemAfter"].replace("${x}", ``)}
`,
bind(element) {
const inputElement = element.querySelector("input");
diff --git a/app/src/protyle/render/av/gallery/util.ts b/app/src/protyle/render/av/gallery/util.ts
index 6337178ba..c3f321c89 100644
--- a/app/src/protyle/render/av/gallery/util.ts
+++ b/app/src/protyle/render/av/gallery/util.ts
@@ -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) => {
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 8a067d41c..efe700916 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -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();