2023-06-12 12:42:22 +08:00
|
|
|
import {Menu} from "../../../plugin/Menu";
|
2023-06-08 19:21:33 +08:00
|
|
|
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest";
|
|
|
|
|
import {transaction} from "../../wysiwyg/transaction";
|
2023-06-10 11:59:12 +08:00
|
|
|
import {openEditorTab} from "../../../menus/util";
|
|
|
|
|
import {copySubMenu} from "../../../menus/commonMenuItem";
|
2023-07-15 22:24:54 +08:00
|
|
|
import {openCalcMenu, popTextCell} from "./cell";
|
2023-10-13 11:08:56 +08:00
|
|
|
import {getColIconByType, showColMenu} from "./col";
|
|
|
|
|
import {insertAttrViewBlockAnimation, updateHeader} from "./row";
|
2023-06-29 18:56:46 +08:00
|
|
|
import {emitOpenMenu} from "../../../plugin/EventBus";
|
2023-10-27 21:38:44 +08:00
|
|
|
import {addCol} from "./col";
|
2023-07-02 20:52:16 +08:00
|
|
|
import {openMenuPanel} from "./openMenuPanel";
|
2023-07-28 17:33:35 +08:00
|
|
|
import {hintRef} from "../../hint/extend";
|
2023-08-01 22:09:07 +08:00
|
|
|
import {focusByRange} from "../../util/selection";
|
2023-08-03 15:08:07 +08:00
|
|
|
import {writeText} from "../../util/compatibility";
|
|
|
|
|
import {showMessage} from "../../../dialog/message";
|
2023-09-22 20:40:28 +08:00
|
|
|
import {previewImage} from "../../preview/image";
|
2023-10-11 17:28:40 +08:00
|
|
|
import {isLocalPath, pathPosix} from "../../../util/pathName";
|
|
|
|
|
import {Constants} from "../../../constants";
|
2023-10-15 18:28:09 +08:00
|
|
|
/// #if !MOBILE
|
2023-10-11 17:28:40 +08:00
|
|
|
import {openAsset} from "../../../editor/util";
|
2023-10-15 18:28:09 +08:00
|
|
|
/// #endif
|
|
|
|
|
import {getSearch} from "../../../util/functions";
|
2023-10-13 09:37:24 +08:00
|
|
|
import {unicode2Emoji} from "../../../emoji";
|
2023-10-13 11:08:56 +08:00
|
|
|
import {selectRow} from "./row";
|
2023-10-13 23:06:53 +08:00
|
|
|
import * as dayjs from "dayjs";
|
2023-06-10 17:44:19 +08:00
|
|
|
|
2023-06-08 19:21:33 +08:00
|
|
|
export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => {
|
2023-06-08 22:56:52 +08:00
|
|
|
const blockElement = hasClosestBlock(event.target);
|
2023-06-10 17:56:45 +08:00
|
|
|
if (!blockElement) {
|
2023-06-11 22:58:48 +08:00
|
|
|
return false;
|
2023-06-10 17:56:45 +08:00
|
|
|
}
|
2023-10-13 21:54:35 +08:00
|
|
|
if (event.shiftKey) {
|
|
|
|
|
const rowElement = hasClosestByClassName(event.target, "av__row");
|
|
|
|
|
if (rowElement && !rowElement.classList.contains("av__row--header")) {
|
2023-11-10 09:54:49 +08:00
|
|
|
selectRow(rowElement.querySelector(".av__firstcol"), "toggle");
|
2023-10-13 21:54:35 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-09 23:21:46 +08:00
|
|
|
const copyElement = hasClosestByAttribute(event.target, "data-type", "copy");
|
|
|
|
|
if (copyElement) {
|
2023-11-14 12:09:31 +08:00
|
|
|
const textElement = copyElement.previousElementSibling
|
|
|
|
|
if (textElement.querySelector(".av__cellicon")) {
|
|
|
|
|
writeText(`${textElement.firstChild.textContent} ➡️ ${textElement.lastChild.textContent}`);
|
|
|
|
|
} else {
|
|
|
|
|
writeText(textElement.textContent);
|
|
|
|
|
}
|
2023-09-09 23:21:46 +08:00
|
|
|
showMessage(window.siyuan.languages.copied);
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (protyle.disabled) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-09-28 11:29:58 +08:00
|
|
|
|
2023-06-08 22:56:52 +08:00
|
|
|
const addElement = hasClosestByAttribute(event.target, "data-type", "av-header-add");
|
2023-06-10 17:56:45 +08:00
|
|
|
if (addElement) {
|
2023-07-02 21:53:02 +08:00
|
|
|
const addMenu = addCol(protyle, blockElement);
|
2023-07-02 23:59:01 +08:00
|
|
|
const addRect = addElement.getBoundingClientRect();
|
2023-07-02 21:53:02 +08:00
|
|
|
addMenu.open({
|
|
|
|
|
x: addRect.left,
|
|
|
|
|
y: addRect.bottom,
|
|
|
|
|
h: addRect.height
|
|
|
|
|
});
|
2023-06-08 19:21:33 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
2023-06-08 22:56:52 +08:00
|
|
|
return true;
|
2023-06-08 19:21:33 +08:00
|
|
|
}
|
2023-06-10 11:11:49 +08:00
|
|
|
|
2023-11-10 09:54:49 +08:00
|
|
|
const gutterElement = hasClosestByClassName(event.target, "ariaLabel");
|
|
|
|
|
if (gutterElement && gutterElement.parentElement.classList.contains("av__gutters")) {
|
2023-11-09 17:00:55 +08:00
|
|
|
const rowElement = gutterElement.parentElement.parentElement;
|
2023-11-07 10:36:15 +08:00
|
|
|
if (gutterElement.dataset.action === "add") {
|
2023-11-09 17:00:55 +08:00
|
|
|
const avID = blockElement.getAttribute("data-av-id");
|
|
|
|
|
const srcIDs = [Lute.NewNodeID()];
|
|
|
|
|
const previousID = event.altKey ? (rowElement.previousElementSibling.getAttribute("data-id") || "") : rowElement.getAttribute("data-id");
|
|
|
|
|
transaction(protyle, [{
|
|
|
|
|
action: "insertAttrViewBlock",
|
|
|
|
|
avID,
|
|
|
|
|
previousID,
|
|
|
|
|
srcIDs,
|
|
|
|
|
isDetached: true,
|
|
|
|
|
}], [{
|
|
|
|
|
action: "removeAttrViewBlock",
|
|
|
|
|
srcIDs,
|
|
|
|
|
avID,
|
|
|
|
|
}]);
|
|
|
|
|
insertAttrViewBlockAnimation(blockElement, 1, previousID, avID);
|
2023-11-07 10:36:15 +08:00
|
|
|
} else {
|
|
|
|
|
const gutterRect = gutterElement.getBoundingClientRect();
|
|
|
|
|
avContextmenu(protyle, rowElement, {
|
|
|
|
|
x: gutterRect.left,
|
|
|
|
|
y: gutterRect.bottom,
|
|
|
|
|
w: gutterRect.width,
|
|
|
|
|
h: gutterRect.height
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-06-30 10:26:48 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-10 09:54:49 +08:00
|
|
|
const checkElement = hasClosestByClassName(event.target, "av__firstcol");
|
2023-11-09 17:00:55 +08:00
|
|
|
if (checkElement) {
|
2023-06-30 23:57:11 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-11-09 17:00:55 +08:00
|
|
|
selectRow(checkElement, "toggle");
|
2023-06-10 17:56:45 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 23:58:00 +08:00
|
|
|
const headerMoreElement = hasClosestByAttribute(event.target, "data-type", "av-header-more");
|
2023-07-02 20:52:16 +08:00
|
|
|
if (headerMoreElement) {
|
2023-07-18 01:03:35 +08:00
|
|
|
openMenuPanel({protyle, blockElement, type: "properties"});
|
2023-07-02 20:52:16 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 23:58:00 +08:00
|
|
|
const moreElement = hasClosestByAttribute(event.target, "data-type", "av-more");
|
2023-07-02 20:52:16 +08:00
|
|
|
if (moreElement) {
|
2023-07-18 01:03:35 +08:00
|
|
|
openMenuPanel({protyle, blockElement, type: "config"});
|
2023-07-02 20:52:16 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-07-03 12:25:02 +08:00
|
|
|
|
|
|
|
|
const sortsElement = hasClosestByAttribute(event.target, "data-type", "av-sort");
|
|
|
|
|
if (sortsElement) {
|
2023-07-18 01:03:35 +08:00
|
|
|
openMenuPanel({protyle, blockElement, type: "sorts"});
|
2023-07-03 12:25:02 +08:00
|
|
|
event.preventDefault();
|
2023-07-06 18:56:16 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const filtersElement = hasClosestByAttribute(event.target, "data-type", "av-filter");
|
|
|
|
|
if (filtersElement) {
|
2023-07-18 01:03:35 +08:00
|
|
|
openMenuPanel({protyle, blockElement, type: "filters"});
|
2023-07-06 18:56:16 +08:00
|
|
|
event.preventDefault();
|
2023-07-03 12:25:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 15:08:07 +08:00
|
|
|
const linkElement = hasClosestByClassName(event.target, "av__celltext--url");
|
|
|
|
|
if (linkElement) {
|
2023-09-22 20:40:28 +08:00
|
|
|
let linkAddress = linkElement.textContent.trim();
|
2023-08-09 22:55:34 +08:00
|
|
|
if (linkElement.dataset.type === "phone") {
|
2023-09-22 20:40:28 +08:00
|
|
|
linkAddress = "tel:" + linkAddress;
|
2023-08-09 22:55:34 +08:00
|
|
|
} else if (linkElement.dataset.type === "email") {
|
2023-09-22 20:40:28 +08:00
|
|
|
linkAddress = "mailto:" + linkAddress;
|
|
|
|
|
} else if (linkElement.classList.contains("b3-chip")) {
|
|
|
|
|
linkAddress = linkElement.dataset.url;
|
2023-08-09 22:55:34 +08:00
|
|
|
}
|
2023-10-15 18:28:09 +08:00
|
|
|
/// #if !MOBILE
|
2023-10-11 17:28:40 +08:00
|
|
|
const suffix = pathPosix().extname(linkAddress);
|
2023-10-15 18:28:09 +08:00
|
|
|
if (isLocalPath(linkAddress) && (
|
2023-10-11 17:28:40 +08:00
|
|
|
[".pdf"].concat(Constants.SIYUAN_ASSETS_AUDIO).concat(Constants.SIYUAN_ASSETS_VIDEO).includes(suffix) && (
|
|
|
|
|
suffix !== ".pdf" || (suffix === ".pdf" && !linkAddress.startsWith("file://"))
|
|
|
|
|
)
|
|
|
|
|
)) {
|
|
|
|
|
openAsset(protyle.app, linkAddress.trim(), parseInt(getSearch("page", linkAddress)), "right");
|
|
|
|
|
} else {
|
|
|
|
|
window.open(linkAddress);
|
|
|
|
|
}
|
2023-10-15 18:28:09 +08:00
|
|
|
/// #else
|
|
|
|
|
window.open(linkAddress);
|
|
|
|
|
/// #endif
|
|
|
|
|
|
2023-09-22 20:40:28 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 20:49:47 +08:00
|
|
|
const imgElement = hasClosestByClassName(event.target, "av__cellassetimg") as HTMLImageElement;
|
2023-09-22 20:40:28 +08:00
|
|
|
if (imgElement) {
|
|
|
|
|
previewImage(imgElement.src);
|
2023-08-03 15:08:07 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 23:58:00 +08:00
|
|
|
const cellHeaderElement = hasClosestByClassName(event.target, "av__cellheader");
|
|
|
|
|
if (cellHeaderElement) {
|
2023-07-07 11:12:49 +08:00
|
|
|
showColMenu(protyle, blockElement, cellHeaderElement.parentElement);
|
2023-07-02 23:58:00 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-07-03 12:25:02 +08:00
|
|
|
|
2023-09-28 11:29:58 +08:00
|
|
|
const blockMoreElement = hasClosestByAttribute(event.target, "data-type", "block-more");
|
|
|
|
|
if (blockMoreElement) {
|
|
|
|
|
protyle.toolbar.range = document.createRange();
|
|
|
|
|
protyle.toolbar.range.selectNodeContents(blockMoreElement);
|
|
|
|
|
focusByRange(protyle.toolbar.range);
|
|
|
|
|
hintRef(blockMoreElement.previousElementSibling.textContent.trim(), protyle, "av");
|
2023-09-27 23:58:48 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-08 22:56:52 +08:00
|
|
|
const cellElement = hasClosestByClassName(event.target, "av__cell");
|
2023-07-02 23:58:00 +08:00
|
|
|
if (cellElement && !cellElement.parentElement.classList.contains("av__row--header")) {
|
2023-10-13 11:08:56 +08:00
|
|
|
const type = cellElement.parentElement.parentElement.firstElementChild.querySelector(`[data-col-id="${cellElement.getAttribute("data-col-id")}"]`).getAttribute("data-dtype") as TAVCol;
|
2023-10-13 11:34:19 +08:00
|
|
|
if (type === "updated" || type === "created" || (type === "block" && !cellElement.getAttribute("data-detached"))) {
|
2023-11-10 09:54:49 +08:00
|
|
|
selectRow(cellElement.parentElement.querySelector(".av__firstcol"), "toggle");
|
2023-10-13 11:08:56 +08:00
|
|
|
} else {
|
2023-10-13 11:55:51 +08:00
|
|
|
cellElement.parentElement.parentElement.querySelectorAll(".av__row--select").forEach(item => {
|
2023-11-10 09:54:49 +08:00
|
|
|
item.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconUncheck");
|
2023-10-13 11:55:51 +08:00
|
|
|
item.classList.remove("av__row--select");
|
|
|
|
|
});
|
|
|
|
|
updateHeader(cellElement.parentElement);
|
2023-10-13 11:08:56 +08:00
|
|
|
popTextCell(protyle, [cellElement]);
|
|
|
|
|
}
|
2023-07-02 23:58:00 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
2023-06-08 22:56:52 +08:00
|
|
|
return true;
|
2023-06-08 19:21:33 +08:00
|
|
|
}
|
2023-07-15 22:24:54 +08:00
|
|
|
|
|
|
|
|
const calcElement = hasClosestByClassName(event.target, "av__calc");
|
|
|
|
|
if (calcElement) {
|
|
|
|
|
openCalcMenu(protyle, calcElement);
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-07-28 17:33:35 +08:00
|
|
|
|
2023-11-09 17:00:55 +08:00
|
|
|
const addRowElement = hasClosestByClassName(event.target, "av__row--add");
|
|
|
|
|
if (addRowElement) {
|
|
|
|
|
const avID = blockElement.getAttribute("data-av-id");
|
|
|
|
|
const srcIDs = [Lute.NewNodeID()];
|
|
|
|
|
const previousID = addRowElement.previousElementSibling.getAttribute("data-id") || "";
|
|
|
|
|
transaction(protyle, [{
|
|
|
|
|
action: "insertAttrViewBlock",
|
|
|
|
|
avID,
|
|
|
|
|
previousID,
|
|
|
|
|
srcIDs,
|
|
|
|
|
isDetached: true,
|
|
|
|
|
}], [{
|
|
|
|
|
action: "removeAttrViewBlock",
|
|
|
|
|
srcIDs,
|
|
|
|
|
avID,
|
|
|
|
|
}]);
|
|
|
|
|
insertAttrViewBlockAnimation(blockElement, 1, previousID, avID);
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-08 22:56:52 +08:00
|
|
|
return false;
|
|
|
|
|
};
|
2023-06-10 11:26:56 +08:00
|
|
|
|
2023-10-13 21:50:14 +08:00
|
|
|
export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, position: IPosition) => {
|
2023-06-30 10:26:48 +08:00
|
|
|
if (rowElement.classList.contains("av__row--header")) {
|
2023-07-01 17:06:28 +08:00
|
|
|
return false;
|
2023-06-30 10:26:48 +08:00
|
|
|
}
|
2023-06-10 11:59:12 +08:00
|
|
|
const blockElement = hasClosestBlock(rowElement);
|
|
|
|
|
if (!blockElement) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-06-30 23:57:11 +08:00
|
|
|
if (!rowElement.classList.contains("av__row--select")) {
|
|
|
|
|
blockElement.querySelectorAll(".av__row--select").forEach(item => {
|
|
|
|
|
item.classList.remove("av__row--select");
|
|
|
|
|
});
|
2023-11-10 09:54:49 +08:00
|
|
|
blockElement.querySelectorAll(".av__firstcol use").forEach(item => {
|
2023-06-30 23:57:11 +08:00
|
|
|
item.setAttribute("xlink:href", "#iconUncheck");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const menu = new Menu("av-row-menu");
|
2023-06-10 17:56:45 +08:00
|
|
|
if (menu.isOpen) {
|
2023-06-11 22:58:48 +08:00
|
|
|
return true;
|
2023-06-10 17:56:45 +08:00
|
|
|
}
|
|
|
|
|
rowElement.classList.add("av__row--select");
|
2023-11-10 09:54:49 +08:00
|
|
|
rowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconCheck");
|
2023-06-30 23:57:11 +08:00
|
|
|
const rowIds: string[] = [];
|
|
|
|
|
const blockIds: string[] = [];
|
2023-08-02 00:18:31 +08:00
|
|
|
const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header)");
|
|
|
|
|
rowElements.forEach(item => {
|
2023-06-30 23:57:11 +08:00
|
|
|
rowIds.push(item.getAttribute("data-id"));
|
2023-10-18 23:57:25 +08:00
|
|
|
blockIds.push(item.querySelector(".av__cell[data-block-id]").getAttribute("data-block-id"));
|
2023-06-10 11:59:12 +08:00
|
|
|
});
|
2023-06-30 23:57:11 +08:00
|
|
|
updateHeader(rowElement);
|
2023-06-10 11:59:12 +08:00
|
|
|
menu.addItem({
|
|
|
|
|
icon: "iconTrashcan",
|
|
|
|
|
label: window.siyuan.languages.delete,
|
|
|
|
|
click() {
|
2023-10-21 23:49:28 +08:00
|
|
|
const avID = blockElement.getAttribute("data-av-id");
|
2023-10-18 23:52:20 +08:00
|
|
|
const undoOperations: IOperation[] = [];
|
|
|
|
|
rowElements.forEach(item => {
|
|
|
|
|
undoOperations.push({
|
|
|
|
|
action: "insertAttrViewBlock",
|
|
|
|
|
avID,
|
|
|
|
|
previousID: item.previousElementSibling?.getAttribute("data-id") || "",
|
|
|
|
|
srcIDs: [item.getAttribute("data-id")],
|
|
|
|
|
isDetached: item.querySelector('.av__cell[data-detached="true"]') ? true : false,
|
2023-10-21 23:49:28 +08:00
|
|
|
});
|
|
|
|
|
});
|
2023-06-10 11:59:12 +08:00
|
|
|
transaction(protyle, [{
|
|
|
|
|
action: "removeAttrViewBlock",
|
2023-06-30 23:57:11 +08:00
|
|
|
srcIDs: blockIds,
|
2023-10-18 23:52:20 +08:00
|
|
|
avID,
|
|
|
|
|
}], undoOperations);
|
2023-08-02 00:18:31 +08:00
|
|
|
rowElements.forEach(item => {
|
|
|
|
|
item.remove();
|
|
|
|
|
});
|
2023-10-18 23:52:20 +08:00
|
|
|
updateHeader(blockElement.querySelector(".av__row"));
|
2023-06-10 11:59:12 +08:00
|
|
|
}
|
|
|
|
|
});
|
2023-06-30 23:57:11 +08:00
|
|
|
if (rowIds.length === 1) {
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
openEditorTab(protyle.app, rowIds[0]);
|
|
|
|
|
menu.addItem({
|
|
|
|
|
label: window.siyuan.languages.copy,
|
|
|
|
|
icon: "iconCopy",
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: copySubMenu(rowIds[0])
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
menu.addSeparator();
|
2023-06-10 17:45:04 +08:00
|
|
|
const editAttrSubmenu: IMenu[] = [];
|
2023-07-16 23:19:58 +08:00
|
|
|
rowElement.parentElement.querySelectorAll(".av__row--header .av__cell").forEach((cellElement: HTMLElement) => {
|
2023-10-10 16:15:24 +08:00
|
|
|
let hideBlock = false;
|
|
|
|
|
const selectElements: HTMLElement[] = Array.from(blockElement.querySelectorAll(`.av__row--select:not(.av__row--header) .av__cell[data-col-id="${cellElement.dataset.colId}"]`));
|
2023-10-08 09:38:39 +08:00
|
|
|
if (cellElement.dataset.dtype === "block") {
|
|
|
|
|
selectElements.find(item => {
|
|
|
|
|
if (!item.dataset.detached) {
|
|
|
|
|
hideBlock = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-10-10 16:15:24 +08:00
|
|
|
});
|
2023-10-08 09:38:39 +08:00
|
|
|
}
|
2023-10-13 09:37:24 +08:00
|
|
|
const type = cellElement.getAttribute("data-dtype") as TAVCol;
|
2023-10-13 11:30:44 +08:00
|
|
|
if (!hideBlock && !["updated", "created"].includes(type)) {
|
2023-10-13 09:37:24 +08:00
|
|
|
const icon = cellElement.dataset.icon;
|
2023-10-08 09:38:39 +08:00
|
|
|
editAttrSubmenu.push({
|
2023-10-13 09:37:24 +08:00
|
|
|
iconHTML: icon ? unicode2Emoji(icon, "b3-menu__icon", true) : `<svg class="b3-menu__icon"><use xlink:href="#${getColIconByType(type)}"></use></svg>`,
|
|
|
|
|
label: cellElement.querySelector(".av__celltext").textContent.trim(),
|
2023-10-08 09:38:39 +08:00
|
|
|
click() {
|
|
|
|
|
popTextCell(protyle, selectElements);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-06-10 11:59:12 +08:00
|
|
|
});
|
|
|
|
|
menu.addItem({
|
2023-09-09 17:00:51 +08:00
|
|
|
icon: "iconAttr",
|
2023-06-10 11:59:12 +08:00
|
|
|
label: window.siyuan.languages.attr,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: editAttrSubmenu
|
2023-06-10 17:45:04 +08:00
|
|
|
});
|
2023-06-29 18:56:46 +08:00
|
|
|
if (protyle?.app?.plugins) {
|
|
|
|
|
emitOpenMenu({
|
|
|
|
|
plugins: protyle.app.plugins,
|
|
|
|
|
type: "open-menu-av",
|
|
|
|
|
detail: {
|
|
|
|
|
protyle,
|
2023-10-13 21:50:14 +08:00
|
|
|
element: blockElement,
|
|
|
|
|
selectRowElements: rowElements,
|
2023-06-29 18:56:46 +08:00
|
|
|
},
|
|
|
|
|
separatorPosition: "top",
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-10-13 21:50:14 +08:00
|
|
|
menu.open(position);
|
2023-06-10 11:59:12 +08:00
|
|
|
return true;
|
2023-06-10 17:45:04 +08:00
|
|
|
};
|
2023-07-03 23:02:19 +08:00
|
|
|
|
|
|
|
|
export const updateAVName = (protyle: IProtyle, blockElement: Element) => {
|
|
|
|
|
const avId = blockElement.getAttribute("data-av-id");
|
2023-10-13 23:06:53 +08:00
|
|
|
const id = blockElement.getAttribute("data-node-id");
|
2023-07-03 23:02:19 +08:00
|
|
|
const nameElement = blockElement.querySelector(".av__title") as HTMLElement;
|
2023-10-13 09:37:24 +08:00
|
|
|
const newData = nameElement.textContent.trim();
|
|
|
|
|
if (newData === nameElement.dataset.title.trim()) {
|
2023-07-03 23:02:19 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-10-21 23:49:28 +08:00
|
|
|
const newUpdated = dayjs().format("YYYYMMDDHHmmss");
|
2023-07-03 23:02:19 +08:00
|
|
|
transaction(protyle, [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewName",
|
2023-07-03 23:02:19 +08:00
|
|
|
id: avId,
|
2023-10-13 09:37:24 +08:00
|
|
|
data: newData,
|
2023-10-13 23:06:53 +08:00
|
|
|
}, {
|
|
|
|
|
action: "doUpdateUpdated",
|
|
|
|
|
id,
|
2023-10-14 09:21:44 +08:00
|
|
|
data: newUpdated,
|
2023-07-03 23:02:19 +08:00
|
|
|
}], [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewName",
|
2023-07-03 23:02:19 +08:00
|
|
|
id: avId,
|
2023-10-13 23:50:31 +08:00
|
|
|
data: nameElement.dataset.title,
|
2023-10-13 23:06:53 +08:00
|
|
|
}, {
|
|
|
|
|
action: "doUpdateUpdated",
|
|
|
|
|
id,
|
|
|
|
|
data: blockElement.getAttribute("updated")
|
2023-07-04 09:20:55 +08:00
|
|
|
}]);
|
2023-10-14 10:56:21 +08:00
|
|
|
blockElement.setAttribute("updated", newUpdated);
|
2023-10-13 09:37:24 +08:00
|
|
|
nameElement.dataset.title = newData;
|
2023-10-13 23:50:31 +08:00
|
|
|
blockElement.querySelector(".layout-tab-bar .item__text").textContent = newData;
|
2023-11-03 11:23:44 +08:00
|
|
|
|
|
|
|
|
// 当前页面不能进行推送,否则光标会乱跳
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${avId}"]`)).forEach((item: HTMLElement) => {
|
2023-11-07 10:36:15 +08:00
|
|
|
if (blockElement.isSameNode(item)) {
|
2023-11-03 11:23:44 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const titleElement = item.querySelector(".av__title") as HTMLElement;
|
|
|
|
|
if (!titleElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
titleElement.textContent = newData;
|
|
|
|
|
titleElement.dataset.title = newData;
|
|
|
|
|
item.querySelector(".layout-tab-bar .item__text").textContent = newData;
|
|
|
|
|
});
|
2023-07-04 09:20:55 +08:00
|
|
|
};
|
2023-09-21 09:31:54 +08:00
|
|
|
|
2023-09-21 10:54:17 +08:00
|
|
|
export const updateAttrViewCellAnimation = (cellElement: HTMLElement) => {
|
2023-09-21 10:54:41 +08:00
|
|
|
cellElement.style.opacity = "0.38";
|
2023-09-21 10:54:17 +08:00
|
|
|
cellElement.style.backgroundColor = "var(--b3-theme-surface-light)";
|
2023-09-21 10:54:41 +08:00
|
|
|
};
|
2023-09-21 10:54:17 +08:00
|
|
|
|
|
|
|
|
export const removeAttrViewColAnimation = (blockElement: Element, id: string) => {
|
|
|
|
|
blockElement.querySelectorAll(`.av__cell[data-col-id="${id}"]`).forEach(item => {
|
|
|
|
|
item.remove();
|
2023-09-21 10:54:41 +08:00
|
|
|
});
|
|
|
|
|
};
|