2023-12-19 11:19:10 +08:00
|
|
|
|
import {
|
|
|
|
|
hasClosestBlock,
|
|
|
|
|
hasClosestByClassName,
|
|
|
|
|
hasClosestByMatchTag,
|
2024-04-11 08:55:37 +08:00
|
|
|
|
hasClosestByTag,
|
2024-11-23 09:48:08 +08:00
|
|
|
|
hasTopClosestByClassName,
|
|
|
|
|
isInEmbedBlock
|
2023-12-19 11:19:10 +08:00
|
|
|
|
} from "../util/hasClosest";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {getIconByType} from "../../editor/getIcon";
|
2023-08-20 12:41:00 +08:00
|
|
|
|
import {enterBack, iframeMenu, setFold, tableMenu, videoMenu, zoomOut} from "../../menus/protyle";
|
2023-06-29 18:56:46 +08:00
|
|
|
|
import {MenuItem} from "../../menus/Menu";
|
2024-10-28 12:10:36 +08:00
|
|
|
|
import {copySubMenu, openAttr, openFileAttr, openWechatNotify} from "../../menus/commonMenuItem";
|
2024-08-09 21:27:27 +08:00
|
|
|
|
import {
|
|
|
|
|
copyPlainText,
|
|
|
|
|
isInAndroid,
|
2024-11-23 09:48:08 +08:00
|
|
|
|
isInHarmony,
|
2024-08-09 21:27:27 +08:00
|
|
|
|
isMac,
|
|
|
|
|
isOnlyMeta,
|
|
|
|
|
openByMobile,
|
|
|
|
|
updateHotkeyTip,
|
|
|
|
|
writeText
|
|
|
|
|
} from "../util/compatibility";
|
2022-08-01 11:59:22 +08:00
|
|
|
|
import {
|
|
|
|
|
transaction,
|
2023-02-06 18:11:14 +08:00
|
|
|
|
turnsIntoOneTransaction,
|
2024-11-23 09:48:08 +08:00
|
|
|
|
turnsIntoTransaction,
|
|
|
|
|
turnsOneInto,
|
2022-08-01 11:59:22 +08:00
|
|
|
|
updateBatchTransaction,
|
|
|
|
|
updateTransaction
|
|
|
|
|
} from "../wysiwyg/transaction";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {removeBlock} from "../wysiwyg/remove";
|
2024-06-05 22:50:53 +08:00
|
|
|
|
import {focusBlock, focusByRange, getEditorRange} from "../util/selection";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {hideElements} from "../ui/hideElements";
|
2023-06-07 10:36:20 +08:00
|
|
|
|
import {highlightRender} from "../render/highlightRender";
|
|
|
|
|
import {blockRender} from "../render/blockRender";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {getContenteditableElement, getTopAloneElement, isNotEditBlock} from "../wysiwyg/getBlock";
|
|
|
|
|
import * as dayjs from "dayjs";
|
2024-06-05 22:50:53 +08:00
|
|
|
|
import {fetchPost} from "../../util/fetch";
|
2024-11-23 09:48:08 +08:00
|
|
|
|
import {cancelSB, genEmptyElement, getLangByType, insertEmptyBlock, jumpToParent,} from "../../block/util";
|
2022-06-28 10:19:15 +08:00
|
|
|
|
import {countBlockWord} from "../../layout/status";
|
2022-09-03 11:20:36 +08:00
|
|
|
|
import {Constants} from "../../constants";
|
2023-06-07 10:36:20 +08:00
|
|
|
|
import {mathRender} from "../render/mathRender";
|
2022-11-09 14:25:02 +08:00
|
|
|
|
import {duplicateBlock} from "../wysiwyg/commonHotkey";
|
2022-11-25 23:06:03 +08:00
|
|
|
|
import {movePathTo} from "../../util/pathName";
|
|
|
|
|
import {hintMoveBlock} from "../hint/extend";
|
2023-02-19 00:05:38 +08:00
|
|
|
|
import {makeCard, quickMakeCard} from "../../card/makeCard";
|
2023-02-06 18:40:31 +08:00
|
|
|
|
import {transferBlockRef} from "../../menus/block";
|
2023-03-06 11:05:38 +08:00
|
|
|
|
import {isMobile} from "../../util/functions";
|
2023-03-08 21:57:57 +08:00
|
|
|
|
import {AIActions} from "../../ai/actions";
|
2023-07-21 23:16:23 +08:00
|
|
|
|
import {activeBlur, renderTextMenu, showKeyboardToolbarUtil} from "../../mobile/util/keyboardToolbar";
|
2023-05-12 23:45:06 +08:00
|
|
|
|
import {hideTooltip} from "../../dialog/tooltip";
|
2023-05-20 20:47:35 +08:00
|
|
|
|
import {appearanceMenu} from "../toolbar/Font";
|
|
|
|
|
import {setPosition} from "../../util/setPosition";
|
2023-06-29 18:56:46 +08:00
|
|
|
|
import {emitOpenMenu} from "../../plugin/EventBus";
|
2024-12-24 21:01:58 +08:00
|
|
|
|
import {insertAttrViewBlockAnimation, updateHeader} from "../render/av/row";
|
2024-05-24 08:31:06 +08:00
|
|
|
|
import {avContextmenu, duplicateCompletely} from "../render/av/action";
|
2024-04-01 11:51:24 +08:00
|
|
|
|
import {getPlainText} from "../util/paste";
|
2024-04-30 11:49:44 +08:00
|
|
|
|
import {addEditorToDatabase} from "../render/av/addToDatabase";
|
2024-06-07 11:02:02 +08:00
|
|
|
|
import {processClonePHElement} from "../render/util";
|
2024-11-04 17:22:15 +08:00
|
|
|
|
/// #if !MOBILE
|
2024-11-02 15:16:53 +08:00
|
|
|
|
import {openFileById} from "../../editor/util";
|
2024-11-04 17:22:15 +08:00
|
|
|
|
/// #endif
|
|
|
|
|
import {checkFold} from "../../util/noRelyPCFunction";
|
2024-11-21 01:11:27 +08:00
|
|
|
|
import {copyTextByType} from "../toolbar/util";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
export class Gutter {
|
|
|
|
|
public element: HTMLElement;
|
2023-11-07 11:01:01 +08:00
|
|
|
|
private gutterTip: string;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
2023-06-01 20:50:49 +08:00
|
|
|
|
constructor(protyle: IProtyle) {
|
2024-05-08 09:08:43 +08:00
|
|
|
|
if (isMac()) {
|
2024-11-02 15:16:53 +08:00
|
|
|
|
this.gutterTip = window.siyuan.languages.gutterTip.replace("⌥→", updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom));
|
2024-05-04 15:43:20 +08:00
|
|
|
|
} else {
|
|
|
|
|
this.gutterTip = window.siyuan.languages.gutterTip.replace("⌥→", updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom))
|
|
|
|
|
.replace("⌘↑", updateHotkeyTip(window.siyuan.config.keymap.editor.general.collapse.custom))
|
2024-05-10 00:25:28 +08:00
|
|
|
|
.replace("⌥⌘A", updateHotkeyTip(window.siyuan.config.keymap.editor.general.attr.custom))
|
|
|
|
|
.replace(/⌘/g, "Ctrl+").replace(/⌥/g, "Alt+").replace(/⇧/g, "Shift+").replace(/⌃/g, "Ctrl+");
|
2024-05-04 15:43:20 +08:00
|
|
|
|
}
|
2024-11-02 15:16:53 +08:00
|
|
|
|
if (protyle.options.backlinkData) {
|
2024-11-03 11:48:07 +08:00
|
|
|
|
this.gutterTip = this.gutterTip.replace(window.siyuan.languages.enter, window.siyuan.languages.openBy);
|
2024-11-02 15:16:53 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.element = document.createElement("div");
|
|
|
|
|
this.element.className = "protyle-gutters";
|
|
|
|
|
this.element.addEventListener("dragstart", (event: DragEvent & { target: HTMLElement }) => {
|
2023-05-12 23:45:06 +08:00
|
|
|
|
hideTooltip();
|
2024-04-14 11:11:18 +08:00
|
|
|
|
window.siyuan.menus.menu.remove();
|
2023-10-24 10:42:04 +08:00
|
|
|
|
const buttonElement = event.target.parentElement;
|
2024-07-04 16:44:37 +08:00
|
|
|
|
let selectIds: string[] = [];
|
2023-12-21 09:07:53 +08:00
|
|
|
|
let selectElements: Element[] = [];
|
2023-12-21 00:33:48 +08:00
|
|
|
|
let avElement: Element;
|
2023-12-20 23:50:50 +08:00
|
|
|
|
if (buttonElement.dataset.rowId) {
|
2023-12-21 00:33:48 +08:00
|
|
|
|
avElement = Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-node-id="${buttonElement.dataset.nodeId}"]`)).find((item: HTMLElement) => {
|
2024-07-25 17:55:25 +08:00
|
|
|
|
if (!isInEmbedBlock(item)) {
|
2023-12-20 23:50:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
2024-12-24 21:01:58 +08:00
|
|
|
|
const rowElement = avElement.querySelector(`.av__row[data-id="${buttonElement.dataset.rowId}"]`);
|
|
|
|
|
rowElement.classList.add("av__row--select");
|
|
|
|
|
rowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconCheck");
|
|
|
|
|
updateHeader(rowElement as HTMLElement);
|
2023-12-20 23:50:50 +08:00
|
|
|
|
avElement.querySelectorAll(".av__row--select:not(.av__row--header)").forEach(item => {
|
|
|
|
|
selectIds.push(item.getAttribute("data-id"));
|
|
|
|
|
selectElements.push(item);
|
2023-12-21 09:07:53 +08:00
|
|
|
|
});
|
2023-11-10 11:51:06 +08:00
|
|
|
|
} else {
|
2024-07-06 09:57:00 +08:00
|
|
|
|
const gutterId = buttonElement.getAttribute("data-node-id");
|
2023-12-20 23:50:50 +08:00
|
|
|
|
selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
2024-07-04 16:44:37 +08:00
|
|
|
|
let selectedIncludeGutter = false;
|
|
|
|
|
selectElements.forEach((item => {
|
2024-07-06 09:57:00 +08:00
|
|
|
|
const itemId = item.getAttribute("data-node-id");
|
2024-07-04 16:44:37 +08:00
|
|
|
|
if (itemId === gutterId) {
|
2024-07-06 09:57:00 +08:00
|
|
|
|
selectedIncludeGutter = true;
|
2024-07-04 16:44:37 +08:00
|
|
|
|
}
|
|
|
|
|
selectIds.push(itemId);
|
2024-07-06 09:57:00 +08:00
|
|
|
|
}));
|
2024-07-04 16:44:37 +08:00
|
|
|
|
if (!selectedIncludeGutter) {
|
2025-02-02 17:26:33 +08:00
|
|
|
|
let gutterNodeElement: HTMLElement;
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${gutterId}"]`)).find((item: HTMLElement) => {
|
2025-02-02 17:21:40 +08:00
|
|
|
|
if (!isInEmbedBlock(item) && this.isMatchNode(item)) {
|
|
|
|
|
gutterNodeElement = item;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-07-04 16:44:37 +08:00
|
|
|
|
if (gutterNodeElement) {
|
|
|
|
|
selectElements.forEach((item => {
|
2024-07-06 09:57:00 +08:00
|
|
|
|
item.classList.remove("protyle-wysiwyg--select");
|
2024-07-04 16:44:37 +08:00
|
|
|
|
}));
|
2024-07-06 09:57:00 +08:00
|
|
|
|
gutterNodeElement.classList.add("protyle-wysiwyg--select");
|
|
|
|
|
selectElements = [gutterNodeElement];
|
2024-07-04 16:44:37 +08:00
|
|
|
|
selectIds = [gutterId];
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2023-11-10 11:51:06 +08:00
|
|
|
|
|
|
|
|
|
const ghostElement = document.createElement("div");
|
2025-01-29 23:43:58 +08:00
|
|
|
|
ghostElement.className = protyle.wysiwyg.element.className;
|
2023-11-10 11:51:06 +08:00
|
|
|
|
selectElements.forEach(item => {
|
2024-04-19 10:52:59 +08:00
|
|
|
|
if (item.querySelector("iframe")) {
|
2025-01-29 23:25:43 +08:00
|
|
|
|
const type = item.getAttribute("data-type");
|
2023-12-12 20:53:10 +08:00
|
|
|
|
const embedElement = genEmptyElement();
|
2023-12-12 20:53:42 +08:00
|
|
|
|
embedElement.classList.add("protyle-wysiwyg--select");
|
2024-04-20 22:43:25 +08:00
|
|
|
|
getContenteditableElement(embedElement).innerHTML = `<svg class="svg"><use xlink:href="${buttonElement.querySelector("use").getAttribute("xlink:href")}"></use></svg> ${getLangByType(type)}`;
|
2023-12-12 20:53:10 +08:00
|
|
|
|
ghostElement.append(embedElement);
|
|
|
|
|
} else {
|
2024-06-07 11:02:02 +08:00
|
|
|
|
ghostElement.append(processClonePHElement(item.cloneNode(true) as Element));
|
2023-12-12 20:53:10 +08:00
|
|
|
|
}
|
2023-11-10 20:02:03 +08:00
|
|
|
|
});
|
|
|
|
|
ghostElement.setAttribute("style", `position:fixed;opacity:.1;width:${selectElements[0].clientWidth}px;padding:0;`);
|
2023-11-10 11:51:06 +08:00
|
|
|
|
document.body.append(ghostElement);
|
2025-01-29 23:43:58 +08:00
|
|
|
|
event.dataTransfer.setDragImage(ghostElement, 0, 0);
|
2023-11-10 11:51:06 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
ghostElement.remove();
|
|
|
|
|
});
|
2023-10-22 23:17:56 +08:00
|
|
|
|
buttonElement.style.opacity = "0.1";
|
2023-12-21 00:33:48 +08:00
|
|
|
|
window.siyuan.dragElement = avElement as HTMLElement || protyle.wysiwyg.element;
|
2024-12-25 21:16:40 +08:00
|
|
|
|
event.dataTransfer.setData(`${Constants.SIYUAN_DROP_GUTTER}${buttonElement.getAttribute("data-type")}${Constants.ZWSP}${buttonElement.getAttribute("data-subtype")}${Constants.ZWSP}${selectIds}${Constants.ZWSP}${window.siyuan.config.system.workspaceDir}`,
|
2023-02-17 15:34:38 +08:00
|
|
|
|
protyle.wysiwyg.element.innerHTML);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
this.element.addEventListener("dragend", () => {
|
2023-02-20 09:16:54 +08:00
|
|
|
|
this.element.querySelectorAll("button").forEach((item) => {
|
|
|
|
|
item.style.opacity = "";
|
|
|
|
|
});
|
|
|
|
|
window.siyuan.dragElement = undefined;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
this.element.addEventListener("click", (event: MouseEvent & { target: HTMLInputElement }) => {
|
|
|
|
|
const buttonElement = hasClosestByTag(event.target, "BUTTON");
|
|
|
|
|
if (!buttonElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
2023-12-20 23:50:50 +08:00
|
|
|
|
hideTooltip();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const id = buttonElement.getAttribute("data-node-id");
|
|
|
|
|
if (!id) {
|
2022-11-11 23:09:18 +08:00
|
|
|
|
if (buttonElement.getAttribute("disabled")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
buttonElement.setAttribute("disabled", "disabled");
|
|
|
|
|
let foldElement: Element;
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${(buttonElement.previousElementSibling || buttonElement.nextElementSibling).getAttribute("data-node-id")}"]`)).find(item => {
|
2024-07-25 17:55:25 +08:00
|
|
|
|
if (!isInEmbedBlock(item) && this.isMatchNode(item)) {
|
2022-11-11 23:09:18 +08:00
|
|
|
|
foldElement = item;
|
|
|
|
|
return true;
|
2022-10-03 15:53:43 +08:00
|
|
|
|
}
|
2022-11-11 23:09:18 +08:00
|
|
|
|
});
|
|
|
|
|
if (!foldElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (event.altKey) {
|
|
|
|
|
// 折叠所有子集
|
|
|
|
|
let hasFold = true;
|
|
|
|
|
Array.from(foldElement.children).find((ulElement) => {
|
|
|
|
|
if (ulElement.classList.contains("list")) {
|
|
|
|
|
const foldElement = Array.from(ulElement.children).find((listItemElement) => {
|
|
|
|
|
if (listItemElement.classList.contains("li")) {
|
|
|
|
|
if (listItemElement.getAttribute("fold") !== "1" && listItemElement.childElementCount > 3) {
|
|
|
|
|
hasFold = false;
|
|
|
|
|
return true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-11 23:09:18 +08:00
|
|
|
|
});
|
|
|
|
|
if (foldElement) {
|
|
|
|
|
return true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-11-11 23:09:18 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2025-02-04 17:16:41 +08:00
|
|
|
|
buttonElement.parentElement.querySelector("[data-type='fold'] > svg")?.setAttribute("style", `width: 10px${hasFold ? ";transform:rotate(90deg)" : ""}`);
|
2022-11-12 00:55:13 +08:00
|
|
|
|
const doOperations: IOperation[] = [];
|
|
|
|
|
const undoOperations: IOperation[] = [];
|
2022-11-11 23:09:18 +08:00
|
|
|
|
Array.from(foldElement.children).forEach((ulElement) => {
|
|
|
|
|
if (ulElement.classList.contains("list")) {
|
|
|
|
|
Array.from(ulElement.children).forEach((listItemElement) => {
|
|
|
|
|
if (listItemElement.classList.contains("li")) {
|
|
|
|
|
if (hasFold) {
|
|
|
|
|
listItemElement.removeAttribute("fold");
|
|
|
|
|
} else if (listItemElement.childElementCount > 3) {
|
|
|
|
|
listItemElement.setAttribute("fold", "1");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-11-11 23:28:21 +08:00
|
|
|
|
const listId = listItemElement.getAttribute("data-node-id");
|
|
|
|
|
doOperations.push({
|
|
|
|
|
action: "setAttrs",
|
|
|
|
|
id: listId,
|
2024-03-24 22:16:49 +08:00
|
|
|
|
data: JSON.stringify({fold: hasFold ? "" : "1"})
|
2022-11-12 00:55:13 +08:00
|
|
|
|
});
|
2022-11-11 23:28:21 +08:00
|
|
|
|
undoOperations.push({
|
|
|
|
|
action: "setAttrs",
|
|
|
|
|
id: listId,
|
2024-03-24 22:16:49 +08:00
|
|
|
|
data: JSON.stringify({fold: hasFold ? "1" : ""})
|
2022-11-12 00:55:13 +08:00
|
|
|
|
});
|
2022-11-11 23:09:18 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-11-11 23:09:18 +08:00
|
|
|
|
});
|
2022-11-11 23:28:21 +08:00
|
|
|
|
transaction(protyle, doOperations, undoOperations);
|
2022-11-11 23:09:18 +08:00
|
|
|
|
buttonElement.removeAttribute("disabled");
|
|
|
|
|
} else {
|
|
|
|
|
const foldStatus = setFold(protyle, foldElement);
|
2024-03-24 22:16:49 +08:00
|
|
|
|
if (foldStatus === 1) {
|
2022-11-11 23:09:18 +08:00
|
|
|
|
(buttonElement.firstElementChild as HTMLElement).style.transform = "";
|
2024-03-24 22:16:49 +08:00
|
|
|
|
} else if (foldStatus === 0) {
|
2022-11-11 23:09:18 +08:00
|
|
|
|
(buttonElement.firstElementChild as HTMLElement).style.transform = "rotate(90deg)";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-17 20:56:43 +08:00
|
|
|
|
hideElements(["select"], protyle);
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-20 23:30:08 +08:00
|
|
|
|
const gutterRect = buttonElement.getBoundingClientRect();
|
2023-12-20 22:23:30 +08:00
|
|
|
|
if (buttonElement.dataset.type === "NodeAttributeViewRowMenu" || buttonElement.dataset.type === "NodeAttributeViewRow") {
|
2023-12-20 23:30:08 +08:00
|
|
|
|
const rowElement = Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-node-id="${buttonElement.dataset.nodeId}"] .av__row[data-id="${buttonElement.dataset.rowId}"]`)).find((item: HTMLElement) => {
|
2024-07-25 17:55:25 +08:00
|
|
|
|
if (!isInEmbedBlock(item)) {
|
2023-12-20 23:30:08 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-12-20 22:23:30 +08:00
|
|
|
|
if (!rowElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-21 09:07:53 +08:00
|
|
|
|
const blockElement = hasClosestBlock(rowElement);
|
2023-12-20 22:23:30 +08:00
|
|
|
|
if (!blockElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (buttonElement.dataset.type === "NodeAttributeViewRow") {
|
2024-01-13 22:34:46 +08:00
|
|
|
|
blockElement.querySelectorAll(".av__cell--select, .av__cell--active").forEach((cellElement: HTMLElement) => {
|
|
|
|
|
cellElement.classList.remove("av__cell--select", "av__cell--active");
|
|
|
|
|
cellElement.querySelector(".av__drag-fill")?.remove();
|
2024-01-10 11:33:49 +08:00
|
|
|
|
});
|
2023-12-20 22:23:30 +08:00
|
|
|
|
const avID = blockElement.getAttribute("data-av-id");
|
|
|
|
|
const srcIDs = [Lute.NewNodeID()];
|
2023-12-20 23:30:08 +08:00
|
|
|
|
const previousID = event.altKey ? (rowElement.previousElementSibling.getAttribute("data-id") || "") : buttonElement.dataset.rowId;
|
2024-03-08 21:37:42 +08:00
|
|
|
|
const newUpdated = dayjs().format("YYYYMMDDHHmmss");
|
2023-12-20 22:23:30 +08:00
|
|
|
|
transaction(protyle, [{
|
|
|
|
|
action: "insertAttrViewBlock",
|
|
|
|
|
avID,
|
|
|
|
|
previousID,
|
2024-04-20 22:43:25 +08:00
|
|
|
|
srcs: [{
|
|
|
|
|
id: srcIDs[0],
|
|
|
|
|
isDetached: true,
|
|
|
|
|
content: ""
|
|
|
|
|
}],
|
2024-03-04 17:42:54 +08:00
|
|
|
|
blockID: id,
|
2024-03-08 21:37:42 +08:00
|
|
|
|
}, {
|
|
|
|
|
action: "doUpdateUpdated",
|
|
|
|
|
id,
|
|
|
|
|
data: newUpdated,
|
2023-12-20 22:23:30 +08:00
|
|
|
|
}], [{
|
|
|
|
|
action: "removeAttrViewBlock",
|
|
|
|
|
srcIDs,
|
|
|
|
|
avID,
|
2024-03-08 21:37:42 +08:00
|
|
|
|
}, {
|
|
|
|
|
action: "doUpdateUpdated",
|
|
|
|
|
id,
|
|
|
|
|
data: blockElement.getAttribute("updated")
|
2023-12-20 22:23:30 +08:00
|
|
|
|
}]);
|
2024-01-07 22:32:41 +08:00
|
|
|
|
insertAttrViewBlockAnimation(protyle, blockElement, srcIDs, previousID, avID);
|
2024-05-10 16:11:10 +08:00
|
|
|
|
if (event.altKey) {
|
|
|
|
|
this.element.querySelectorAll("button").forEach(item => {
|
|
|
|
|
item.dataset.rowId = srcIDs[0];
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-03-08 21:37:42 +08:00
|
|
|
|
blockElement.setAttribute("updated", newUpdated);
|
2023-12-20 22:23:30 +08:00
|
|
|
|
} else {
|
2024-10-28 12:10:36 +08:00
|
|
|
|
if (!protyle.disabled && event.shiftKey) {
|
2024-10-29 23:01:31 +08:00
|
|
|
|
const blockId = rowElement.querySelector('[data-dtype="block"] .av__celltext--ref')?.getAttribute("data-id");
|
2024-10-28 12:10:36 +08:00
|
|
|
|
if (blockId) {
|
|
|
|
|
fetchPost("/api/attr/getBlockAttrs", {id: blockId}, (response) => {
|
|
|
|
|
openFileAttr(response.data, "av", protyle);
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-20 23:30:08 +08:00
|
|
|
|
avContextmenu(protyle, rowElement as HTMLElement, {
|
2023-12-20 22:23:30 +08:00
|
|
|
|
x: gutterRect.left,
|
|
|
|
|
y: gutterRect.bottom,
|
|
|
|
|
w: gutterRect.width,
|
2023-12-20 23:30:08 +08:00
|
|
|
|
h: gutterRect.height,
|
|
|
|
|
isLeft: true
|
2023-12-20 22:23:30 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-12 12:28:20 +08:00
|
|
|
|
if (isOnlyMeta(event)) {
|
2024-11-02 15:16:53 +08:00
|
|
|
|
if (protyle.options.backlinkData) {
|
2024-11-04 17:26:08 +08:00
|
|
|
|
checkFold(id, (zoomIn, action) => {
|
|
|
|
|
openFileById({
|
|
|
|
|
app: protyle.app,
|
|
|
|
|
id,
|
|
|
|
|
action,
|
|
|
|
|
zoomIn
|
|
|
|
|
});
|
2024-11-02 15:16:53 +08:00
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
zoomOut({protyle, id});
|
|
|
|
|
}
|
2024-05-10 17:58:40 +08:00
|
|
|
|
} else if (event.altKey) {
|
2022-10-03 16:22:18 +08:00
|
|
|
|
let foldElement: Element;
|
2022-10-03 15:53:43 +08:00
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => {
|
2024-07-25 17:55:25 +08:00
|
|
|
|
if (!isInEmbedBlock(item) && this.isMatchNode(item)) {
|
2022-10-03 15:53:43 +08:00
|
|
|
|
foldElement = item;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-10-03 16:22:18 +08:00
|
|
|
|
});
|
2022-10-03 15:53:43 +08:00
|
|
|
|
if (!foldElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (buttonElement.getAttribute("data-type") === "NodeListItem" && foldElement.parentElement.getAttribute("data-node-id")) {
|
|
|
|
|
// 折叠同级
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let hasFold = true;
|
|
|
|
|
Array.from(foldElement.parentElement.children).find((listItemElement) => {
|
|
|
|
|
if (listItemElement.classList.contains("li")) {
|
|
|
|
|
if (listItemElement.getAttribute("fold") !== "1" && listItemElement.childElementCount > 3) {
|
|
|
|
|
hasFold = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-02-04 17:16:41 +08:00
|
|
|
|
buttonElement.parentElement.querySelector("[data-type='fold'] > svg")?.setAttribute("style", `width: 10px${hasFold ? ";transform:rotate(90deg)" : ""}`);
|
2022-11-12 00:55:13 +08:00
|
|
|
|
const doOperations: IOperation[] = [];
|
|
|
|
|
const undoOperations: IOperation[] = [];
|
2022-05-26 15:18:53 +08:00
|
|
|
|
Array.from(foldElement.parentElement.children).find((listItemElement) => {
|
|
|
|
|
if (listItemElement.classList.contains("li")) {
|
|
|
|
|
if (hasFold) {
|
|
|
|
|
listItemElement.removeAttribute("fold");
|
|
|
|
|
} else if (listItemElement.childElementCount > 3) {
|
|
|
|
|
listItemElement.setAttribute("fold", "1");
|
|
|
|
|
}
|
2022-11-11 23:28:21 +08:00
|
|
|
|
const listId = listItemElement.getAttribute("data-node-id");
|
|
|
|
|
doOperations.push({
|
|
|
|
|
action: "setAttrs",
|
|
|
|
|
id: listId,
|
2024-03-24 22:16:49 +08:00
|
|
|
|
data: JSON.stringify({fold: hasFold ? "" : "1"})
|
2022-11-12 00:55:13 +08:00
|
|
|
|
});
|
2022-11-11 23:28:21 +08:00
|
|
|
|
undoOperations.push({
|
|
|
|
|
action: "setAttrs",
|
|
|
|
|
id: listId,
|
2024-03-24 22:16:49 +08:00
|
|
|
|
data: JSON.stringify({fold: hasFold ? "1" : ""})
|
2022-11-12 00:55:13 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2022-11-11 23:28:21 +08:00
|
|
|
|
transaction(protyle, doOperations, undoOperations);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
setFold(protyle, foldElement);
|
|
|
|
|
}
|
|
|
|
|
foldElement.classList.remove("protyle-wysiwyg--hl");
|
2022-10-13 21:34:43 +08:00
|
|
|
|
} else if (window.siyuan.shiftIsPressed && !protyle.disabled) {
|
2023-09-24 17:53:28 +08:00
|
|
|
|
openAttr(protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`), "bookmark", protyle);
|
2023-12-20 23:30:08 +08:00
|
|
|
|
} else if (!window.siyuan.ctrlIsPressed && !window.siyuan.altIsPressed && !window.siyuan.shiftIsPressed) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.renderMenu(protyle, buttonElement);
|
2023-03-17 11:35:08 +08:00
|
|
|
|
// https://ld246.com/article/1648433751993
|
|
|
|
|
if (!protyle.toolbar.range) {
|
2025-01-05 23:54:41 +08:00
|
|
|
|
protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`) || protyle.wysiwyg.element.firstElementChild);
|
2023-03-17 11:35:08 +08:00
|
|
|
|
}
|
2025-01-05 11:27:43 +08:00
|
|
|
|
/// #if MOBILE
|
|
|
|
|
window.siyuan.menus.menu.fullscreen();
|
|
|
|
|
/// #else
|
|
|
|
|
window.siyuan.menus.menu.popup({x: gutterRect.left, y: gutterRect.bottom, isLeft: true});
|
|
|
|
|
const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true);
|
|
|
|
|
window.siyuan.menus.menu.element.setAttribute("data-from", popoverElement ? popoverElement.dataset.level + "popover" : "app");
|
|
|
|
|
focusByRange(protyle.toolbar.range);
|
|
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.element.addEventListener("contextmenu", (event: MouseEvent & { target: HTMLInputElement }) => {
|
|
|
|
|
const buttonElement = hasClosestByTag(event.target, "BUTTON");
|
2023-12-20 23:30:08 +08:00
|
|
|
|
if (!buttonElement || buttonElement.getAttribute("data-type") === "fold") {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!window.siyuan.ctrlIsPressed && !window.siyuan.altIsPressed && !window.siyuan.shiftIsPressed) {
|
2023-12-20 23:50:50 +08:00
|
|
|
|
hideTooltip();
|
2023-12-20 23:30:08 +08:00
|
|
|
|
const gutterRect = buttonElement.getBoundingClientRect();
|
|
|
|
|
if (buttonElement.dataset.type === "NodeAttributeViewRowMenu") {
|
|
|
|
|
const rowElement = Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-node-id="${buttonElement.dataset.nodeId}"] .av__row[data-id="${buttonElement.dataset.rowId}"]`)).find((item: HTMLElement) => {
|
2024-07-25 17:55:25 +08:00
|
|
|
|
if (!isInEmbedBlock(item)) {
|
2023-12-20 23:30:08 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (rowElement) {
|
|
|
|
|
avContextmenu(protyle, rowElement as HTMLElement, {
|
|
|
|
|
x: gutterRect.left,
|
|
|
|
|
y: gutterRect.bottom,
|
|
|
|
|
w: gutterRect.width,
|
|
|
|
|
h: gutterRect.height,
|
|
|
|
|
isLeft: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (buttonElement.dataset.type !== "NodeAttributeViewRow") {
|
|
|
|
|
this.renderMenu(protyle, buttonElement);
|
2025-01-05 11:26:11 +08:00
|
|
|
|
if (!protyle.toolbar.range) {
|
2025-01-05 23:54:41 +08:00
|
|
|
|
protyle.toolbar.range = getEditorRange(
|
|
|
|
|
protyle.wysiwyg.element.querySelector(`[data-node-id="${buttonElement.getAttribute("data-node-id")}"]`) ||
|
|
|
|
|
protyle.wysiwyg.element.firstElementChild);
|
2025-01-05 11:26:11 +08:00
|
|
|
|
}
|
2025-01-05 11:27:43 +08:00
|
|
|
|
/// #if MOBILE
|
|
|
|
|
window.siyuan.menus.menu.fullscreen();
|
|
|
|
|
/// #else
|
|
|
|
|
window.siyuan.menus.menu.popup({x: gutterRect.left, y: gutterRect.bottom, isLeft: true});
|
|
|
|
|
const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true);
|
|
|
|
|
window.siyuan.menus.menu.element.setAttribute("data-from", popoverElement ? popoverElement.dataset.level + "popover" : "app");
|
|
|
|
|
focusByRange(protyle.toolbar.range);
|
|
|
|
|
/// #endif
|
2023-12-20 23:30:08 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
});
|
|
|
|
|
this.element.addEventListener("mouseover", (event: MouseEvent & { target: HTMLInputElement }) => {
|
|
|
|
|
const buttonElement = hasClosestByTag(event.target, "BUTTON");
|
2022-10-03 12:35:11 +08:00
|
|
|
|
if (!buttonElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-20 23:30:08 +08:00
|
|
|
|
const type = buttonElement.getAttribute("data-type");
|
|
|
|
|
if (type === "fold" || type === "NodeAttributeViewRow") {
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl, .av__row--hl")).forEach(item => {
|
|
|
|
|
item.classList.remove("protyle-wysiwyg--hl", "av__row--hl");
|
2022-10-03 12:35:11 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${buttonElement.getAttribute("data-node-id")}"]`)).find(item => {
|
2024-07-25 17:55:25 +08:00
|
|
|
|
if (!isInEmbedBlock(item) && this.isMatchNode(item)) {
|
2023-12-21 09:07:53 +08:00
|
|
|
|
const rowItem = item.querySelector(`.av__row[data-id="${buttonElement.dataset.rowId}"]`);
|
2024-12-24 21:01:58 +08:00
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl, .av__row--hl")).forEach(hlItem => {
|
2022-10-08 16:12:21 +08:00
|
|
|
|
if (!item.isSameNode(hlItem)) {
|
|
|
|
|
hlItem.classList.remove("protyle-wysiwyg--hl");
|
|
|
|
|
}
|
2023-12-20 23:30:08 +08:00
|
|
|
|
if (rowItem && !rowItem.isSameNode(hlItem)) {
|
|
|
|
|
rowItem.classList.remove("av__row--hl");
|
|
|
|
|
}
|
2022-10-08 16:12:21 +08:00
|
|
|
|
});
|
2023-12-20 23:30:08 +08:00
|
|
|
|
if (type === "NodeAttributeViewRowMenu") {
|
|
|
|
|
rowItem.classList.add("av__row--hl");
|
|
|
|
|
} else {
|
|
|
|
|
item.classList.add("protyle-wysiwyg--hl");
|
|
|
|
|
}
|
2022-10-08 16:12:21 +08:00
|
|
|
|
return true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
});
|
2022-10-03 12:35:11 +08:00
|
|
|
|
this.element.addEventListener("mouseleave", (event: MouseEvent & { target: HTMLInputElement }) => {
|
2023-12-20 23:30:08 +08:00
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl, .av__row--hl")).forEach(item => {
|
|
|
|
|
item.classList.remove("protyle-wysiwyg--hl", "av__row--hl");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
});
|
2024-10-12 10:29:28 +08:00
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/12751
|
|
|
|
|
this.element.addEventListener("mousewheel", (event) => {
|
|
|
|
|
hideElements(["gutter"], protyle);
|
|
|
|
|
event.stopPropagation();
|
2024-12-25 21:22:37 +08:00
|
|
|
|
}, {passive: true});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 16:12:21 +08:00
|
|
|
|
private isMatchNode(item: Element) {
|
|
|
|
|
const itemRect = item.getBoundingClientRect();
|
2024-09-05 19:34:34 +08:00
|
|
|
|
// 原本为4,由于 https://github.com/siyuan-note/siyuan/issues/12166 改为 6
|
|
|
|
|
let gutterTop = this.element.getBoundingClientRect().top + 6;
|
2022-10-08 16:12:21 +08:00
|
|
|
|
if (itemRect.height < Math.floor(window.siyuan.config.editor.fontSize * 1.625) + 8) {
|
2022-10-08 21:01:50 +08:00
|
|
|
|
gutterTop = gutterTop - (itemRect.height - this.element.clientHeight) / 2;
|
2022-10-08 16:12:21 +08:00
|
|
|
|
}
|
2022-10-08 21:01:50 +08:00
|
|
|
|
return itemRect.top <= gutterTop && itemRect.bottom >= gutterTop;
|
2022-10-08 16:12:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 20:57:33 +08:00
|
|
|
|
private turnsOneInto(options: {
|
2024-09-23 09:11:17 +08:00
|
|
|
|
menuId?: string,
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: string,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
icon: string,
|
|
|
|
|
label: string,
|
|
|
|
|
protyle: IProtyle,
|
|
|
|
|
nodeElement: Element,
|
|
|
|
|
accelerator?: string
|
|
|
|
|
type: string,
|
|
|
|
|
level?: number
|
|
|
|
|
}) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return {
|
2024-09-23 09:11:17 +08:00
|
|
|
|
id: options.menuId,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: options.icon,
|
|
|
|
|
label: options.label,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: options.accelerator,
|
2024-06-05 22:50:53 +08:00
|
|
|
|
click() {
|
|
|
|
|
turnsOneInto(options);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private turnsIntoOne(options: {
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId?: string,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
accelerator?: string,
|
|
|
|
|
icon?: string,
|
|
|
|
|
label: string,
|
|
|
|
|
protyle: IProtyle,
|
|
|
|
|
selectsElement: Element[],
|
2023-11-28 17:19:22 +08:00
|
|
|
|
type: TTurnIntoOne,
|
2024-09-23 09:11:17 +08:00
|
|
|
|
level?: TTurnIntoOneSub,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}) {
|
|
|
|
|
return {
|
2024-09-23 09:11:17 +08:00
|
|
|
|
id: options.menuId,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: options.icon,
|
|
|
|
|
label: options.label,
|
|
|
|
|
accelerator: options.accelerator,
|
|
|
|
|
click() {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnsIntoOneTransaction(options);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private turnsInto(options: {
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId?: string,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon?: string,
|
|
|
|
|
label: string,
|
|
|
|
|
protyle: IProtyle,
|
|
|
|
|
selectsElement: Element[],
|
2023-11-28 17:19:22 +08:00
|
|
|
|
type: TTurnInto,
|
|
|
|
|
level?: number,
|
2024-09-23 09:11:17 +08:00
|
|
|
|
isContinue?: boolean,
|
|
|
|
|
accelerator?: string,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}) {
|
|
|
|
|
return {
|
2024-09-23 09:11:17 +08:00
|
|
|
|
id: options.menuId,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: options.icon,
|
|
|
|
|
label: options.label,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: options.accelerator,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
click() {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnsIntoTransaction(options);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 23:27:31 +08:00
|
|
|
|
private showMobileAppearance(protyle: IProtyle) {
|
|
|
|
|
const toolbarElement = document.getElementById("keyboardToolbar");
|
|
|
|
|
const dynamicElements = toolbarElement.querySelectorAll("#keyboardToolbar .keyboard__dynamic");
|
|
|
|
|
dynamicElements[0].classList.add("fn__none");
|
|
|
|
|
dynamicElements[1].classList.remove("fn__none");
|
|
|
|
|
toolbarElement.querySelector('.keyboard__action[data-type="text"]').classList.add("protyle-toolbar__item--current");
|
|
|
|
|
toolbarElement.querySelector('.keyboard__action[data-type="done"] use').setAttribute("xlink:href", "#iconCloseRound");
|
2023-07-22 00:36:21 +08:00
|
|
|
|
toolbarElement.classList.remove("fn__none");
|
|
|
|
|
const oldScrollTop = protyle.contentElement.scrollTop + 333.5; // toolbarElement.clientHeight
|
2023-07-21 23:27:31 +08:00
|
|
|
|
renderTextMenu(protyle, toolbarElement);
|
|
|
|
|
showKeyboardToolbarUtil(oldScrollTop);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-21 11:28:01 +08:00
|
|
|
|
public renderMultipleMenu(protyle: IProtyle, selectsElement: Element[]) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let isList = false;
|
|
|
|
|
let isContinue = false;
|
|
|
|
|
let hasEmbedBlock = false;
|
|
|
|
|
selectsElement.find((item, index) => {
|
|
|
|
|
if (item.classList.contains("li")) {
|
|
|
|
|
isList = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-12-20 10:24:01 +08:00
|
|
|
|
if (item.classList.contains("sb") || item.classList.contains("p")) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hasEmbedBlock = true;
|
|
|
|
|
}
|
|
|
|
|
if (item.nextElementSibling && selectsElement[index + 1] &&
|
|
|
|
|
item.nextElementSibling.isSameNode(selectsElement[index + 1])) {
|
|
|
|
|
isContinue = true;
|
|
|
|
|
} else if (index !== selectsElement.length - 1) {
|
|
|
|
|
isContinue = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (!isList && !protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const turnIntoSubmenu: IMenu[] = [];
|
|
|
|
|
if (isContinue) {
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "list",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconList",
|
|
|
|
|
label: window.siyuan.languages.list,
|
|
|
|
|
protyle,
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.list.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
selectsElement,
|
|
|
|
|
type: "Blocks2ULs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "orderedList",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconOrderedList",
|
|
|
|
|
label: window.siyuan.languages["ordered-list"],
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert["ordered-list"].custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "Blocks2OLs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "check",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconCheck",
|
|
|
|
|
label: window.siyuan.languages.check,
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.check.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "Blocks2TLs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "quote",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconQuote",
|
|
|
|
|
label: window.siyuan.languages.quote,
|
2024-09-04 17:35:50 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.quote.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "Blocks2Blockquote"
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
// 多选引用转换为块的时候 id 不一致
|
|
|
|
|
if (!hasEmbedBlock) {
|
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "paragraph",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconParagraph",
|
|
|
|
|
label: window.siyuan.languages.paragraph,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.paragraph.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "Blocks2Ps",
|
|
|
|
|
isContinue
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading1",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH1",
|
|
|
|
|
label: window.siyuan.languages.heading1,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading1.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
level: 1,
|
|
|
|
|
type: "Blocks2Hs",
|
|
|
|
|
isContinue
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading2",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH2",
|
|
|
|
|
label: window.siyuan.languages.heading2,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading2.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
level: 2,
|
|
|
|
|
type: "Blocks2Hs",
|
|
|
|
|
isContinue
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading3",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH3",
|
|
|
|
|
label: window.siyuan.languages.heading3,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading3.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
level: 3,
|
|
|
|
|
type: "Blocks2Hs",
|
|
|
|
|
isContinue
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading4",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH4",
|
|
|
|
|
label: window.siyuan.languages.heading4,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading4.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
level: 4,
|
|
|
|
|
type: "Blocks2Hs",
|
|
|
|
|
isContinue
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading5",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH5",
|
|
|
|
|
label: window.siyuan.languages.heading5,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading5.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
level: 5,
|
|
|
|
|
type: "Blocks2Hs",
|
|
|
|
|
isContinue
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading6",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH6",
|
|
|
|
|
label: window.siyuan.languages.heading6,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading6.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
level: 6,
|
|
|
|
|
type: "Blocks2Hs",
|
|
|
|
|
isContinue
|
|
|
|
|
}));
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "turnInto",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconRefresh",
|
|
|
|
|
label: window.siyuan.languages.turnInto,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: turnIntoSubmenu
|
|
|
|
|
}).element);
|
2025-01-08 10:20:39 +08:00
|
|
|
|
if (isContinue && !(selectsElement[0].parentElement.classList.contains("sb") &&
|
|
|
|
|
selectsElement.length + 1 === selectsElement[0].parentElement.childElementCount)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "mergeSuperBlock",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconSuper",
|
|
|
|
|
label: window.siyuan.languages.merge + " " + window.siyuan.languages.superBlock,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: [this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "hLayout",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.hLayout,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.hLayout.custom,
|
|
|
|
|
icon: "iconSplitLR",
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "BlocksMergeSuperBlock",
|
|
|
|
|
level: "col"
|
|
|
|
|
}), this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "vLayout",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.vLayout,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.vLayout.custom,
|
|
|
|
|
icon: "iconSplitTB",
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "BlocksMergeSuperBlock",
|
|
|
|
|
level: "row"
|
|
|
|
|
})]
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-19 09:21:59 +08:00
|
|
|
|
if (!protyle.disabled) {
|
2024-03-08 12:36:36 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "ai",
|
2024-03-08 12:36:36 +08:00
|
|
|
|
icon: "iconSparkles",
|
|
|
|
|
label: window.siyuan.languages.ai,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.ai.custom,
|
|
|
|
|
click() {
|
|
|
|
|
AIActions(selectsElement, protyle);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2023-05-19 09:21:59 +08:00
|
|
|
|
}
|
2024-11-21 01:11:27 +08:00
|
|
|
|
const copyMenu: IMenu[] = (copySubMenu(Array.from(selectsElement).map(item => item.getAttribute("data-node-id")), true, selectsElement[0]) as IMenu[]).concat([{
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "copyPlainText",
|
2024-05-24 08:31:06 +08:00
|
|
|
|
iconHTML: "",
|
2023-02-04 15:40:54 +08:00
|
|
|
|
label: window.siyuan.languages.copyPlainText,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.copyPlainText.custom,
|
|
|
|
|
click() {
|
|
|
|
|
let html = "";
|
2024-04-01 11:51:24 +08:00
|
|
|
|
selectsElement.forEach((item: HTMLElement) => {
|
|
|
|
|
html += getPlainText(item) + "\n";
|
2023-02-04 15:40:54 +08:00
|
|
|
|
});
|
|
|
|
|
copyPlainText(html.trimEnd());
|
2024-03-22 10:03:52 +08:00
|
|
|
|
focusBlock(selectsElement[0]);
|
2023-02-04 15:40:54 +08:00
|
|
|
|
}
|
2024-11-21 01:11:27 +08:00
|
|
|
|
}, {
|
|
|
|
|
id: "copy",
|
|
|
|
|
iconHTML: "",
|
|
|
|
|
label: window.siyuan.languages.copy,
|
|
|
|
|
accelerator: "⌘C",
|
|
|
|
|
click() {
|
|
|
|
|
if (isNotEditBlock(selectsElement[0])) {
|
|
|
|
|
focusBlock(selectsElement[0]);
|
|
|
|
|
} else {
|
|
|
|
|
focusByRange(getEditorRange(selectsElement[0]));
|
|
|
|
|
}
|
|
|
|
|
document.execCommand("copy");
|
|
|
|
|
}
|
2023-02-04 15:40:54 +08:00
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "duplicate",
|
2024-05-24 08:31:06 +08:00
|
|
|
|
iconHTML: "",
|
2023-02-04 15:40:54 +08:00
|
|
|
|
label: window.siyuan.languages.duplicate,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.duplicate.custom,
|
|
|
|
|
disabled: protyle.disabled,
|
|
|
|
|
click() {
|
|
|
|
|
duplicateBlock(selectsElement, protyle);
|
|
|
|
|
}
|
2024-11-21 01:11:27 +08:00
|
|
|
|
}]);
|
|
|
|
|
copyMenu.splice(4, 1, {
|
|
|
|
|
id: "copyHPath",
|
|
|
|
|
iconHTML: "",
|
|
|
|
|
label: window.siyuan.languages.copyHPath,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.copyHPath.custom,
|
|
|
|
|
click: () => {
|
|
|
|
|
copyTextByType([selectsElement[0].getAttribute("data-node-id")], "hPath");
|
|
|
|
|
focusBlock(selectsElement[0]);
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-02-06 21:54:26 +08:00
|
|
|
|
const copyTextRefMenu = this.genCopyTextRef(selectsElement);
|
2023-02-04 15:40:54 +08:00
|
|
|
|
if (copyTextRefMenu) {
|
2024-11-21 01:11:27 +08:00
|
|
|
|
copyMenu.splice(7, 0, copyTextRefMenu);
|
2023-02-04 15:40:54 +08:00
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "copy",
|
2023-02-04 15:40:54 +08:00
|
|
|
|
label: window.siyuan.languages.copy,
|
|
|
|
|
icon: "iconCopy",
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: copyMenu,
|
2022-08-20 13:13:21 +08:00
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "cut",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.cut,
|
|
|
|
|
accelerator: "⌘X",
|
|
|
|
|
icon: "iconCut",
|
|
|
|
|
click: () => {
|
2024-07-02 11:36:49 +08:00
|
|
|
|
focusBlock(selectsElement[0]);
|
|
|
|
|
document.execCommand("cut");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "move",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.move,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.general.move.custom,
|
|
|
|
|
icon: "iconMove",
|
|
|
|
|
click: () => {
|
2022-11-29 22:04:19 +08:00
|
|
|
|
movePathTo((toPath) => {
|
2023-06-01 20:50:49 +08:00
|
|
|
|
hintMoveBlock(toPath[0], selectsElement, protyle);
|
2022-11-25 23:06:03 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2024-04-16 09:01:56 +08:00
|
|
|
|
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined;
|
2024-01-28 13:01:40 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "addToDatabase",
|
2024-01-28 13:01:40 +08:00
|
|
|
|
label: window.siyuan.languages.addToDatabase,
|
2024-03-08 22:57:41 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
|
2024-01-28 13:01:40 +08:00
|
|
|
|
icon: "iconDatabase",
|
|
|
|
|
click: () => {
|
2024-04-30 11:49:44 +08:00
|
|
|
|
addEditorToDatabase(protyle, range);
|
2024-01-28 13:01:40 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "delete",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.delete,
|
|
|
|
|
icon: "iconTrashcan",
|
|
|
|
|
accelerator: "⌫",
|
|
|
|
|
click: () => {
|
2022-08-31 01:14:45 +08:00
|
|
|
|
protyle.breadcrumb?.hide();
|
2024-02-26 11:34:19 +08:00
|
|
|
|
removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0]), "Backspace");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_appearance", type: "separator"}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const appearanceElement = new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "appearance",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.appearance,
|
2023-05-21 23:13:13 +08:00
|
|
|
|
icon: "iconFont",
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.appearance.custom,
|
2023-07-21 23:27:31 +08:00
|
|
|
|
click: () => {
|
2023-07-21 23:16:23 +08:00
|
|
|
|
/// #if MOBILE
|
2023-07-21 23:27:31 +08:00
|
|
|
|
this.showMobileAppearance(protyle);
|
2023-07-21 23:16:23 +08:00
|
|
|
|
/// #else
|
2023-05-20 20:47:35 +08:00
|
|
|
|
protyle.toolbar.element.classList.add("fn__none");
|
|
|
|
|
protyle.toolbar.subElement.innerHTML = "";
|
|
|
|
|
protyle.toolbar.subElement.style.width = "";
|
|
|
|
|
protyle.toolbar.subElement.style.padding = "";
|
|
|
|
|
protyle.toolbar.subElement.append(appearanceMenu(protyle, selectsElement));
|
2023-10-01 10:26:31 +08:00
|
|
|
|
protyle.toolbar.subElement.style.zIndex = (++window.siyuan.zIndex).toString();
|
2023-05-20 20:47:35 +08:00
|
|
|
|
protyle.toolbar.subElement.classList.remove("fn__none");
|
|
|
|
|
protyle.toolbar.subElementCloseCB = undefined;
|
|
|
|
|
const position = selectsElement[0].getBoundingClientRect();
|
|
|
|
|
setPosition(protyle.toolbar.subElement, position.left, position.top);
|
|
|
|
|
/// #endif
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}).element;
|
|
|
|
|
window.siyuan.menus.menu.append(appearanceElement);
|
2023-03-16 22:18:27 +08:00
|
|
|
|
if (!isMobile()) {
|
|
|
|
|
appearanceElement.lastElementChild.classList.add("b3-menu__submenu--row");
|
|
|
|
|
}
|
2023-10-14 10:49:35 +08:00
|
|
|
|
this.genAlign(selectsElement, protyle);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.genWidths(selectsElement, protyle);
|
2024-09-12 00:43:07 +08:00
|
|
|
|
// this.genHeights(selectsElement, protyle);
|
2024-07-05 21:00:21 +08:00
|
|
|
|
if (!window.siyuan.config.readonly) {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_quickMakeCard", type: "separator"}).element);
|
2024-07-05 21:00:21 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "quickMakeCard",
|
2024-07-05 21:00:21 +08:00
|
|
|
|
label: window.siyuan.languages.quickMakeCard,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.quickMakeCard.custom,
|
|
|
|
|
iconHTML: '<svg class="b3-menu__icon" style="color:var(--b3-theme-primary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
|
|
|
|
icon: "iconRiffCard",
|
|
|
|
|
click() {
|
|
|
|
|
quickMakeCard(protyle, selectsElement);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2023-03-25 09:31:32 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "addToDeck",
|
2023-03-25 09:31:32 +08:00
|
|
|
|
label: window.siyuan.languages.addToDeck,
|
|
|
|
|
icon: "iconRiffCard",
|
2024-07-05 21:00:21 +08:00
|
|
|
|
ignore: !window.siyuan.config.flashcard.deck,
|
2023-03-25 09:31:32 +08:00
|
|
|
|
click() {
|
|
|
|
|
const ids: string[] = [];
|
|
|
|
|
selectsElement.forEach(item => {
|
|
|
|
|
if (item.getAttribute("data-type") === "NodeThematicBreak") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ids.push(item.getAttribute("data-node-id"));
|
|
|
|
|
});
|
2023-06-01 20:50:49 +08:00
|
|
|
|
makeCard(protyle.app, ids);
|
2023-03-25 09:31:32 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2023-06-03 09:55:50 +08:00
|
|
|
|
|
2023-06-29 18:56:46 +08:00
|
|
|
|
if (protyle?.app?.plugins) {
|
|
|
|
|
emitOpenMenu({
|
2023-07-12 18:32:23 +08:00
|
|
|
|
plugins: protyle.app.plugins,
|
2023-06-29 18:56:46 +08:00
|
|
|
|
type: "click-blockicon",
|
|
|
|
|
detail: {
|
|
|
|
|
protyle,
|
|
|
|
|
blockElements: selectsElement,
|
|
|
|
|
},
|
|
|
|
|
separatorPosition: "top",
|
2023-05-18 20:49:24 +08:00
|
|
|
|
});
|
2023-05-31 20:06:19 +08:00
|
|
|
|
}
|
2023-06-03 09:55:50 +08:00
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return window.siyuan.menus.menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public renderMenu(protyle: IProtyle, buttonElement: Element) {
|
2023-07-19 13:00:46 +08:00
|
|
|
|
if (!buttonElement) {
|
2023-07-21 23:27:31 +08:00
|
|
|
|
return;
|
2023-07-19 13:00:46 +08:00
|
|
|
|
}
|
2023-02-04 10:50:01 +08:00
|
|
|
|
hideElements(["util", "toolbar", "hint"], protyle);
|
2024-09-22 11:19:37 +08:00
|
|
|
|
window.siyuan.menus.menu.remove();
|
2023-03-08 23:18:21 +08:00
|
|
|
|
if (isMobile()) {
|
|
|
|
|
activeBlur();
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const id = buttonElement.getAttribute("data-node-id");
|
|
|
|
|
const selectsElement = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
|
|
|
|
if (selectsElement.length > 1) {
|
|
|
|
|
const match = Array.from(selectsElement).find(item => {
|
|
|
|
|
if (id === item.getAttribute("data-node-id")) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (match) {
|
|
|
|
|
return this.renderMultipleMenu(protyle, Array.from(selectsElement));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let nodeElement: Element;
|
|
|
|
|
if (buttonElement.tagName === "BUTTON") {
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => {
|
2024-07-25 17:55:25 +08:00
|
|
|
|
if (!isInEmbedBlock(item) && this.isMatchNode(item)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
nodeElement = item;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
nodeElement = buttonElement;
|
|
|
|
|
}
|
|
|
|
|
if (!nodeElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const type = nodeElement.getAttribute("data-type");
|
|
|
|
|
const subType = nodeElement.getAttribute("data-subtype");
|
|
|
|
|
const turnIntoSubmenu: IMenu[] = [];
|
|
|
|
|
hideElements(["select"], protyle);
|
|
|
|
|
nodeElement.classList.add("protyle-wysiwyg--select");
|
2022-10-05 10:12:21 +08:00
|
|
|
|
countBlockWord([id], protyle.block.rootID);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
// "heading1-6", "list", "ordered-list", "check", "quote", "code", "table", "line", "math", "paragraph"
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (type === "NodeParagraph" && !protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "list",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconList",
|
|
|
|
|
label: window.siyuan.languages.list,
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.list.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2ULs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "orderedList",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconOrderedList",
|
|
|
|
|
label: window.siyuan.languages["ordered-list"],
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert["ordered-list"].custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2OLs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "check",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconCheck",
|
|
|
|
|
label: window.siyuan.languages.check,
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.check.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2TLs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "quote",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconQuote",
|
|
|
|
|
label: window.siyuan.languages.quote,
|
2024-09-22 09:16:22 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.quote.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2Blockquote"
|
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading1",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH1",
|
|
|
|
|
label: window.siyuan.languages.heading1,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading1.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 1,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading2",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH2",
|
|
|
|
|
label: window.siyuan.languages.heading2,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading2.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 2,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading3",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH3",
|
|
|
|
|
label: window.siyuan.languages.heading3,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading3.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 3,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading4",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH4",
|
|
|
|
|
label: window.siyuan.languages.heading4,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading4.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 4,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading5",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH5",
|
|
|
|
|
label: window.siyuan.languages.heading5,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading5.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 5,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading6",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH6",
|
|
|
|
|
label: window.siyuan.languages.heading6,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading6.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 6,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeHeading" && !protyle.disabled) {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "paragraph",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconParagraph",
|
|
|
|
|
label: window.siyuan.languages.paragraph,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.paragraph.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2Ps",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
2024-09-12 22:07:32 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "quote",
|
2024-09-12 22:07:32 +08:00
|
|
|
|
icon: "iconQuote",
|
|
|
|
|
label: window.siyuan.languages.quote,
|
2024-09-22 09:16:22 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.quote.custom,
|
2024-09-12 22:07:32 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2Blockquote"
|
|
|
|
|
}));
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (subType !== "h1") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading1",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH1",
|
|
|
|
|
label: window.siyuan.languages.heading1,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading1.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-09-02 10:16:15 +08:00
|
|
|
|
level: 1,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if (subType !== "h2") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading2",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH2",
|
|
|
|
|
label: window.siyuan.languages.heading2,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading2.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 2,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if (subType !== "h3") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading3",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH3",
|
|
|
|
|
label: window.siyuan.languages.heading3,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading3.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 3,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if (subType !== "h4") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading4",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH4",
|
|
|
|
|
label: window.siyuan.languages.heading4,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading4.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 4,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if (subType !== "h5") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading5",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH5",
|
|
|
|
|
label: window.siyuan.languages.heading5,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading5.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 5,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if (subType !== "h6") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "heading6",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconH6",
|
|
|
|
|
label: window.siyuan.languages.heading6,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.heading6.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
selectsElement: [nodeElement],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
level: 6,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
type: "Blocks2Hs",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
|
|
|
|
}
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeList" && !protyle.disabled) {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "paragraph",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconParagraph",
|
|
|
|
|
label: window.siyuan.languages.paragraph,
|
2024-07-02 22:49:08 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.paragraph.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
type: "CancelList"
|
|
|
|
|
}));
|
2024-09-12 22:07:32 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "quote",
|
2024-09-12 22:07:32 +08:00
|
|
|
|
icon: "iconQuote",
|
|
|
|
|
label: window.siyuan.languages.quote,
|
2024-09-22 09:16:22 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.quote.custom,
|
2024-09-12 22:07:32 +08:00
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2Blockquote"
|
|
|
|
|
}));
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (nodeElement.getAttribute("data-subtype") === "o") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "list",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconList",
|
|
|
|
|
label: window.siyuan.languages.list,
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.list.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
type: "OL2UL"
|
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "check",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconCheck",
|
|
|
|
|
label: window.siyuan.languages.check,
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.check.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
type: "UL2TL"
|
|
|
|
|
}));
|
|
|
|
|
} else if (nodeElement.getAttribute("data-subtype") === "t") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "list",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconList",
|
|
|
|
|
label: window.siyuan.languages.list,
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.list.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
type: "TL2UL"
|
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "orderedList",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconOrderedList",
|
|
|
|
|
label: window.siyuan.languages["ordered-list"],
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert["ordered-list"].custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
type: "TL2OL"
|
|
|
|
|
}));
|
|
|
|
|
} else {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "orderedList",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconOrderedList",
|
|
|
|
|
label: window.siyuan.languages["ordered-list"],
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert["ordered-list"].custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
type: "UL2OL"
|
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "check",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconCheck",
|
|
|
|
|
label: window.siyuan.languages.check,
|
2024-06-05 12:01:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.check.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
type: "OL2TL"
|
|
|
|
|
}));
|
|
|
|
|
}
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeBlockquote" && !protyle.disabled) {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2024-09-26 09:35:33 +08:00
|
|
|
|
menuId: "paragraph",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconParagraph",
|
|
|
|
|
label: window.siyuan.languages.paragraph,
|
2024-07-02 22:49:08 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.heading.paragraph.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
type: "CancelBlockquote"
|
|
|
|
|
}));
|
|
|
|
|
}
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (turnIntoSubmenu.length > 0 && !protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "turnInto",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconRefresh",
|
|
|
|
|
label: window.siyuan.languages.turnInto,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: turnIntoSubmenu
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2023-09-28 12:20:19 +08:00
|
|
|
|
if (!protyle.disabled && !nodeElement.classList.contains("hr")) {
|
2024-03-08 12:36:36 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "ai",
|
2024-03-08 12:36:36 +08:00
|
|
|
|
icon: "iconSparkles",
|
|
|
|
|
label: window.siyuan.languages.ai,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.ai.custom,
|
|
|
|
|
click() {
|
|
|
|
|
AIActions([nodeElement], protyle);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2023-05-19 09:21:59 +08:00
|
|
|
|
}
|
2024-05-23 23:00:02 +08:00
|
|
|
|
|
2024-11-20 16:55:34 +08:00
|
|
|
|
const copyMenu = (copySubMenu([id], true, nodeElement) as IMenu[]).concat([{
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "copyPlainText",
|
2024-05-24 08:31:06 +08:00
|
|
|
|
iconHTML: "",
|
2024-05-23 23:45:10 +08:00
|
|
|
|
label: window.siyuan.languages.copyPlainText,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.copyPlainText.custom,
|
|
|
|
|
click() {
|
|
|
|
|
copyPlainText(getPlainText(nodeElement as HTMLElement).trimEnd());
|
|
|
|
|
focusBlock(nodeElement);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: type === "NodeAttributeView" ? "copyMirror" : "copy",
|
2024-05-24 08:31:06 +08:00
|
|
|
|
iconHTML: "",
|
2024-05-23 23:00:02 +08:00
|
|
|
|
label: type === "NodeAttributeView" ? window.siyuan.languages.copyMirror : window.siyuan.languages.copy,
|
2023-02-04 15:40:54 +08:00
|
|
|
|
accelerator: "⌘C",
|
|
|
|
|
click() {
|
|
|
|
|
if (isNotEditBlock(nodeElement)) {
|
2024-01-12 21:28:37 +08:00
|
|
|
|
focusBlock(nodeElement);
|
2023-02-04 15:40:54 +08:00
|
|
|
|
} else {
|
|
|
|
|
focusByRange(getEditorRange(nodeElement));
|
|
|
|
|
}
|
2024-01-12 21:28:37 +08:00
|
|
|
|
document.execCommand("copy");
|
2023-02-04 15:40:54 +08:00
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: type === "NodeAttributeView" ? "duplicateMirror" : "duplicate",
|
2024-05-24 08:31:06 +08:00
|
|
|
|
iconHTML: "",
|
2024-05-23 23:00:02 +08:00
|
|
|
|
label: type === "NodeAttributeView" ? window.siyuan.languages.duplicateMirror : window.siyuan.languages.duplicate,
|
2023-02-04 15:40:54 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.duplicate.custom,
|
|
|
|
|
disabled: protyle.disabled,
|
|
|
|
|
click() {
|
|
|
|
|
duplicateBlock([nodeElement], protyle);
|
|
|
|
|
}
|
2023-02-06 21:54:26 +08:00
|
|
|
|
}]);
|
2024-05-23 23:00:02 +08:00
|
|
|
|
if (type === "NodeAttributeView") {
|
|
|
|
|
copyMenu.push({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "duplicateCompletely",
|
2024-05-24 08:31:06 +08:00
|
|
|
|
iconHTML: "",
|
2024-05-23 23:00:02 +08:00
|
|
|
|
label: window.siyuan.languages.duplicateCompletely,
|
2024-05-24 08:33:05 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.duplicateCompletely.custom,
|
|
|
|
|
disabled: protyle.disabled,
|
2024-05-23 23:00:02 +08:00
|
|
|
|
click() {
|
2024-05-24 08:31:06 +08:00
|
|
|
|
duplicateCompletely(protyle, nodeElement as HTMLElement);
|
2024-05-23 23:00:02 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-02-06 21:54:26 +08:00
|
|
|
|
const copyTextRefMenu = this.genCopyTextRef([nodeElement]);
|
2023-02-04 15:40:54 +08:00
|
|
|
|
if (copyTextRefMenu) {
|
2024-05-23 23:45:10 +08:00
|
|
|
|
copyMenu.splice(7, 0, copyTextRefMenu);
|
2023-02-04 15:40:54 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "copy",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconCopy",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.copy,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
type: "submenu",
|
2023-02-04 15:40:54 +08:00
|
|
|
|
submenu: copyMenu
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (!protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "cut",
|
|
|
|
|
icon: "iconCut",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.cut,
|
|
|
|
|
accelerator: "⌘X",
|
|
|
|
|
click: () => {
|
2024-07-02 11:36:49 +08:00
|
|
|
|
focusBlock(nodeElement);
|
|
|
|
|
document.execCommand("cut");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "move",
|
|
|
|
|
icon: "iconMove",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.move,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.general.move.custom,
|
|
|
|
|
click: () => {
|
2022-11-29 22:04:19 +08:00
|
|
|
|
movePathTo((toPath) => {
|
2023-06-01 20:50:49 +08:00
|
|
|
|
hintMoveBlock(toPath[0], [nodeElement], protyle);
|
2022-11-25 23:06:03 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2024-04-16 09:01:56 +08:00
|
|
|
|
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined;
|
2024-01-28 13:01:40 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "addToDatabase",
|
|
|
|
|
icon: "iconDatabase",
|
2024-01-28 13:01:40 +08:00
|
|
|
|
label: window.siyuan.languages.addToDatabase,
|
2024-03-08 22:57:41 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
|
2024-01-28 13:01:40 +08:00
|
|
|
|
click: () => {
|
2024-04-30 11:49:44 +08:00
|
|
|
|
addEditorToDatabase(protyle, range);
|
2024-01-28 13:01:40 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "delete",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconTrashcan",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.delete,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
accelerator: "⌫",
|
|
|
|
|
click: () => {
|
2022-08-31 01:14:45 +08:00
|
|
|
|
protyle.breadcrumb?.hide();
|
2024-02-26 11:34:19 +08:00
|
|
|
|
removeBlock(protyle, nodeElement, getEditorRange(nodeElement), "Backspace");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (type === "NodeSuperBlock" && !protyle.disabled) {
|
2024-09-23 09:11:17 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
id: "separator_cancelSuperBlock",
|
|
|
|
|
type: "separator"
|
|
|
|
|
}).element);
|
2025-01-05 23:54:41 +08:00
|
|
|
|
const isCol = nodeElement.getAttribute("data-sb-layout") === "col";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "cancelSuperBlock",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.cancel + " " + window.siyuan.languages.superBlock,
|
2025-01-05 23:54:41 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general[isCol ? "hLayout" : "vLayout"].custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
click() {
|
2022-06-15 23:05:14 +08:00
|
|
|
|
const sbData = cancelSB(protyle, nodeElement);
|
|
|
|
|
transaction(protyle, sbData.doOperations, sbData.undoOperations);
|
|
|
|
|
focusBlock(protyle.wysiwyg.element.querySelector(`[data-node-id="${sbData.previousId}"]`));
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hideElements(["gutter"], protyle);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2025-01-05 23:54:41 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general[isCol ? "vLayout" : "hLayout"].custom,
|
|
|
|
|
label: window.siyuan.languages.turnInto + " " + window.siyuan.languages[isCol ? "vLayout" : "hLayout"],
|
|
|
|
|
click() {
|
|
|
|
|
const oldHTML = nodeElement.outerHTML;
|
|
|
|
|
if (isCol) {
|
2025-01-07 08:38:14 +08:00
|
|
|
|
nodeElement.setAttribute("data-sb-layout", "row");
|
2025-01-05 23:54:41 +08:00
|
|
|
|
} else {
|
2025-01-07 08:38:14 +08:00
|
|
|
|
nodeElement.setAttribute("data-sb-layout", "col");
|
2025-01-05 23:54:41 +08:00
|
|
|
|
}
|
|
|
|
|
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
|
|
|
|
updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
|
|
|
|
|
focusByRange(protyle.toolbar.range);
|
|
|
|
|
hideElements(["gutter"], protyle);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeCodeBlock" && !protyle.disabled && !nodeElement.getAttribute("data-subtype")) {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_code", type: "separator"}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const linewrap = nodeElement.getAttribute("linewrap");
|
|
|
|
|
const ligatures = nodeElement.getAttribute("ligatures");
|
|
|
|
|
const linenumber = nodeElement.getAttribute("linenumber");
|
|
|
|
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "code",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconCode",
|
|
|
|
|
label: window.siyuan.languages.code,
|
|
|
|
|
submenu: [{
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "md31",
|
2023-06-15 11:24:27 +08:00
|
|
|
|
iconHTML: "",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: `<div class="fn__flex" style="margin-bottom: 4px"><span>${window.siyuan.languages.md31}</span><span class="fn__space fn__flex-1"></span>
|
|
|
|
|
<input type="checkbox" class="b3-switch fn__flex-center"${linewrap === "true" ? " checked" : ((window.siyuan.config.editor.codeLineWrap && linewrap !== "false") ? " checked" : "")}></div>`,
|
|
|
|
|
bind(element) {
|
|
|
|
|
element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
|
|
|
|
const inputElement = element.querySelector("input");
|
|
|
|
|
if (event.target.tagName !== "INPUT") {
|
|
|
|
|
inputElement.checked = !inputElement.checked;
|
|
|
|
|
}
|
|
|
|
|
nodeElement.setAttribute("linewrap", inputElement.checked.toString());
|
|
|
|
|
nodeElement.querySelector(".hljs").removeAttribute("data-render");
|
|
|
|
|
highlightRender(nodeElement);
|
|
|
|
|
fetchPost("/api/attr/setBlockAttrs", {
|
|
|
|
|
id,
|
|
|
|
|
attrs: {linewrap: inputElement.checked.toString()}
|
|
|
|
|
});
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "md2",
|
2023-06-15 11:24:27 +08:00
|
|
|
|
iconHTML: "",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: `<div class="fn__flex" style="margin-bottom: 4px"><span>${window.siyuan.languages.md2}</span><span class="fn__space fn__flex-1"></span>
|
|
|
|
|
<input type="checkbox" class="b3-switch fn__flex-center"${ligatures === "true" ? " checked" : ((window.siyuan.config.editor.codeLigatures && ligatures !== "false") ? " checked" : "")}></div>`,
|
|
|
|
|
bind(element) {
|
|
|
|
|
element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
|
|
|
|
const inputElement = element.querySelector("input");
|
|
|
|
|
if (event.target.tagName !== "INPUT") {
|
|
|
|
|
inputElement.checked = !inputElement.checked;
|
|
|
|
|
}
|
|
|
|
|
nodeElement.setAttribute("ligatures", inputElement.checked.toString());
|
|
|
|
|
nodeElement.querySelector(".hljs").removeAttribute("data-render");
|
|
|
|
|
highlightRender(nodeElement);
|
|
|
|
|
fetchPost("/api/attr/setBlockAttrs", {
|
|
|
|
|
id,
|
|
|
|
|
attrs: {ligatures: inputElement.checked.toString()}
|
|
|
|
|
});
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "md27",
|
2023-06-15 11:24:27 +08:00
|
|
|
|
iconHTML: "",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: `<div class="fn__flex" style="margin-bottom: 4px"><span>${window.siyuan.languages.md27}</span><span class="fn__space fn__flex-1"></span>
|
|
|
|
|
<input type="checkbox" class="b3-switch fn__flex-center"${linenumber === "true" ? " checked" : ((window.siyuan.config.editor.codeSyntaxHighlightLineNum && linenumber !== "false") ? " checked" : "")}></div>`,
|
|
|
|
|
bind(element) {
|
|
|
|
|
element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
|
|
|
|
const inputElement = element.querySelector("input");
|
|
|
|
|
if (event.target.tagName !== "INPUT") {
|
|
|
|
|
inputElement.checked = !inputElement.checked;
|
|
|
|
|
}
|
|
|
|
|
nodeElement.setAttribute("linenumber", inputElement.checked.toString());
|
|
|
|
|
nodeElement.querySelector(".hljs").removeAttribute("data-render");
|
|
|
|
|
highlightRender(nodeElement);
|
|
|
|
|
fetchPost("/api/attr/setBlockAttrs", {
|
|
|
|
|
id,
|
|
|
|
|
attrs: {linenumber: inputElement.checked.toString()}
|
|
|
|
|
});
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeCodeBlock" && !protyle.disabled && ["echarts", "mindmap"].includes(nodeElement.getAttribute("data-subtype"))) {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_chart", type: "separator"}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const height = (nodeElement as HTMLElement).style.height;
|
|
|
|
|
let html = nodeElement.outerHTML;
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "chart",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.chart,
|
|
|
|
|
icon: "iconCode",
|
|
|
|
|
submenu: [{
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "height",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: `${window.siyuan.languages.height}<span class="fn__space"></span>
|
|
|
|
|
<input style="margin: 4px 0;width: 84px" type="number" step="1" min="148" class="b3-text-field" value="${height ? parseInt(height) : "420"}">`,
|
|
|
|
|
bind: (element) => {
|
|
|
|
|
element.querySelector("input").addEventListener("change", (event) => {
|
|
|
|
|
const newHeight = ((event.target as HTMLInputElement).value || "420") + "px";
|
|
|
|
|
(nodeElement as HTMLElement).style.height = newHeight;
|
2022-07-19 00:48:53 +08:00
|
|
|
|
(nodeElement.firstElementChild.nextElementSibling as HTMLElement).style.height = newHeight;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
|
|
|
|
html = nodeElement.outerHTML;
|
|
|
|
|
event.stopPropagation();
|
2023-09-28 22:38:49 +08:00
|
|
|
|
const chartInstance = window.echarts.getInstanceById(nodeElement.firstElementChild.nextElementSibling.getAttribute("_echarts_instance_"));
|
2022-07-19 00:48:53 +08:00
|
|
|
|
if (chartInstance) {
|
|
|
|
|
chartInstance.resize();
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "update",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.update,
|
|
|
|
|
icon: "iconEdit",
|
|
|
|
|
click() {
|
|
|
|
|
protyle.toolbar.showRender(protyle, nodeElement);
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeTable" && !protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let range = getEditorRange(nodeElement);
|
|
|
|
|
const tableElement = nodeElement.querySelector("table");
|
|
|
|
|
if (!tableElement.contains(range.startContainer)) {
|
|
|
|
|
range = getEditorRange(tableElement.querySelector("th"));
|
|
|
|
|
}
|
|
|
|
|
const cellElement = hasClosestByMatchTag(range.startContainer, "TD") || hasClosestByMatchTag(range.startContainer, "TH");
|
|
|
|
|
if (cellElement) {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_table", type: "separator"}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "table",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconTable",
|
|
|
|
|
label: window.siyuan.languages.table,
|
2024-06-25 22:45:15 +08:00
|
|
|
|
submenu: tableMenu(protyle, nodeElement, cellElement as HTMLTableCellElement, range).menus as IMenu[]
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}).element);
|
|
|
|
|
}
|
2024-01-04 21:38:42 +08:00
|
|
|
|
} else if (type === "NodeAttributeView" && !protyle.disabled) {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_exportCSV", type: "separator"}).element);
|
2024-01-04 21:38:42 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "exportCSV",
|
2024-01-04 21:38:42 +08:00
|
|
|
|
icon: "iconDatabase",
|
|
|
|
|
label: window.siyuan.languages.export + " CSV",
|
|
|
|
|
click() {
|
|
|
|
|
fetchPost("/api/export/exportAttributeView", {
|
2024-03-04 17:42:54 +08:00
|
|
|
|
id: nodeElement.getAttribute("data-av-id"),
|
|
|
|
|
blockID: id,
|
2024-01-04 21:38:42 +08:00
|
|
|
|
}, response => {
|
|
|
|
|
openByMobile(response.data.zip);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if ((type === "NodeVideo" || type === "NodeAudio") && !protyle.disabled) {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_VideoOrAudio", type: "separator"}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: type === "NodeVideo" ? "assetVideo" : "assetAudio",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: type === "NodeVideo" ? "iconVideo" : "iconRecord",
|
|
|
|
|
label: window.siyuan.languages.assets,
|
2023-06-01 20:50:49 +08:00
|
|
|
|
submenu: videoMenu(protyle, nodeElement, type)
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeIFrame" && !protyle.disabled) {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_IFrame", type: "separator"}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "assetIFrame",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconLanguage",
|
|
|
|
|
label: window.siyuan.languages.assets,
|
2023-06-01 20:50:49 +08:00
|
|
|
|
submenu: iframeMenu(protyle, nodeElement)
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeHTMLBlock" && !protyle.disabled) {
|
2024-09-23 08:43:49 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_html", type: "separator"}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-23 08:43:49 +08:00
|
|
|
|
id: "html",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconHTML5",
|
|
|
|
|
label: "HTML",
|
|
|
|
|
click() {
|
|
|
|
|
protyle.toolbar.showRender(protyle, nodeElement);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeBlockQueryEmbed" && !protyle.disabled) {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_blockEmbed", type: "separator"}).element);
|
2022-10-18 10:11:59 +08:00
|
|
|
|
const breadcrumb = nodeElement.getAttribute("breadcrumb");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "blockEmbed",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconSQL",
|
|
|
|
|
label: window.siyuan.languages.blockEmbed,
|
|
|
|
|
submenu: [{
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "refresh",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconRefresh",
|
|
|
|
|
label: `${window.siyuan.languages.refresh} SQL`,
|
|
|
|
|
click() {
|
|
|
|
|
nodeElement.removeAttribute("data-render");
|
|
|
|
|
blockRender(protyle, nodeElement);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "update",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconEdit",
|
|
|
|
|
label: `${window.siyuan.languages.update} SQL`,
|
|
|
|
|
click() {
|
|
|
|
|
protyle.toolbar.showRender(protyle, nodeElement);
|
|
|
|
|
}
|
2022-10-18 11:23:06 +08:00
|
|
|
|
}, {
|
|
|
|
|
type: "separator"
|
2022-10-18 10:11:59 +08:00
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "embedBlockBreadcrumb",
|
2022-10-18 10:11:59 +08:00
|
|
|
|
label: `<div class="fn__flex" style="margin-bottom: 4px"><span>${window.siyuan.languages.embedBlockBreadcrumb}</span><span class="fn__space fn__flex-1"></span>
|
|
|
|
|
<input type="checkbox" class="b3-switch fn__flex-center"${breadcrumb === "true" ? " checked" : ((window.siyuan.config.editor.embedBlockBreadcrumb && breadcrumb !== "false") ? " checked" : "")}></div>`,
|
|
|
|
|
bind(element) {
|
|
|
|
|
element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
|
|
|
|
const inputElement = element.querySelector("input");
|
|
|
|
|
if (event.target.tagName !== "INPUT") {
|
|
|
|
|
inputElement.checked = !inputElement.checked;
|
|
|
|
|
}
|
|
|
|
|
nodeElement.setAttribute("breadcrumb", inputElement.checked.toString());
|
|
|
|
|
fetchPost("/api/attr/setBlockAttrs", {
|
|
|
|
|
id,
|
|
|
|
|
attrs: {breadcrumb: inputElement.checked.toString()}
|
|
|
|
|
});
|
2022-10-19 21:47:47 +08:00
|
|
|
|
nodeElement.removeAttribute("data-render");
|
2022-10-18 10:11:59 +08:00
|
|
|
|
blockRender(protyle, nodeElement);
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-10-18 11:23:06 +08:00
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "hideHeadingBelowBlocks",
|
2022-10-18 11:23:06 +08:00
|
|
|
|
label: `<div class="fn__flex" style="margin-bottom: 4px"><span>${window.siyuan.languages.hideHeadingBelowBlocks}</span><span class="fn__space fn__flex-1"></span>
|
|
|
|
|
<input type="checkbox" class="b3-switch fn__flex-center"${nodeElement.getAttribute("custom-heading-mode") === "1" ? " checked" : ""}></div>`,
|
|
|
|
|
bind(element) {
|
|
|
|
|
element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
|
|
|
|
const inputElement = element.querySelector("input");
|
|
|
|
|
if (event.target.tagName !== "INPUT") {
|
|
|
|
|
inputElement.checked = !inputElement.checked;
|
|
|
|
|
}
|
|
|
|
|
nodeElement.setAttribute("custom-heading-mode", inputElement.checked ? "1" : "0");
|
|
|
|
|
fetchPost("/api/attr/setBlockAttrs", {
|
|
|
|
|
id,
|
|
|
|
|
attrs: {"custom-heading-mode": inputElement.checked ? "1" : "0"}
|
|
|
|
|
});
|
|
|
|
|
nodeElement.removeAttribute("data-render");
|
|
|
|
|
blockRender(protyle, nodeElement);
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}]
|
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeHeading" && !protyle.disabled) {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_1", type: "separator"}).element);
|
2022-09-27 23:36:07 +08:00
|
|
|
|
const headingSubMenu = [];
|
|
|
|
|
if (subType !== "h1") {
|
2022-09-28 12:14:18 +08:00
|
|
|
|
headingSubMenu.push(this.genHeadingTransform(protyle, id, 1));
|
2022-09-28 00:02:29 +08:00
|
|
|
|
}
|
|
|
|
|
if (subType !== "h2") {
|
2022-09-28 12:14:18 +08:00
|
|
|
|
headingSubMenu.push(this.genHeadingTransform(protyle, id, 2));
|
2022-09-28 00:02:29 +08:00
|
|
|
|
}
|
|
|
|
|
if (subType !== "h3") {
|
2022-09-28 12:14:18 +08:00
|
|
|
|
headingSubMenu.push(this.genHeadingTransform(protyle, id, 3));
|
2022-09-28 00:02:29 +08:00
|
|
|
|
}
|
|
|
|
|
if (subType !== "h4") {
|
2022-09-28 12:14:18 +08:00
|
|
|
|
headingSubMenu.push(this.genHeadingTransform(protyle, id, 4));
|
2022-09-28 00:02:29 +08:00
|
|
|
|
}
|
|
|
|
|
if (subType !== "h5") {
|
2022-09-28 12:14:18 +08:00
|
|
|
|
headingSubMenu.push(this.genHeadingTransform(protyle, id, 5));
|
2022-09-28 00:02:29 +08:00
|
|
|
|
}
|
|
|
|
|
if (subType !== "h6") {
|
2022-09-28 12:14:18 +08:00
|
|
|
|
headingSubMenu.push(this.genHeadingTransform(protyle, id, 6));
|
2022-09-27 23:36:07 +08:00
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "tWithSubtitle",
|
2022-09-27 23:36:07 +08:00
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconRefresh",
|
|
|
|
|
label: window.siyuan.languages.tWithSubtitle,
|
|
|
|
|
submenu: headingSubMenu
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "copyHeadings1",
|
2022-09-27 23:36:07 +08:00
|
|
|
|
icon: "iconCopy",
|
2022-10-16 14:23:17 +08:00
|
|
|
|
label: `${window.siyuan.languages.copy} ${window.siyuan.languages.headings1}`,
|
2022-09-27 23:36:07 +08:00
|
|
|
|
click() {
|
2022-09-28 00:02:29 +08:00
|
|
|
|
fetchPost("/api/block/getHeadingChildrenDOM", {id}, (response) => {
|
2024-11-25 10:52:40 +08:00
|
|
|
|
if (isInAndroid()) {
|
2024-08-09 22:06:18 +08:00
|
|
|
|
window.JSAndroid.writeHTMLClipboard(protyle.lute.BlockDOM2StdMd(response.data).trimEnd(), response.data + Constants.ZWSP);
|
2024-11-25 10:52:40 +08:00
|
|
|
|
} else if (isInHarmony()) {
|
|
|
|
|
window.JSHarmony.writeHTMLClipboard(protyle.lute.BlockDOM2StdMd(response.data).trimEnd(), response.data + Constants.ZWSP);
|
2024-08-09 21:27:27 +08:00
|
|
|
|
} else {
|
|
|
|
|
writeText(response.data + Constants.ZWSP);
|
|
|
|
|
}
|
2022-09-28 12:14:18 +08:00
|
|
|
|
});
|
2022-09-27 23:36:07 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2022-10-10 20:18:08 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "cutHeadings1",
|
2022-10-10 20:18:08 +08:00
|
|
|
|
icon: "iconCut",
|
2022-10-16 14:23:17 +08:00
|
|
|
|
label: `${window.siyuan.languages.cut} ${window.siyuan.languages.headings1}`,
|
2022-10-10 20:18:08 +08:00
|
|
|
|
click() {
|
|
|
|
|
fetchPost("/api/block/getHeadingChildrenDOM", {id}, (response) => {
|
2024-11-25 10:52:40 +08:00
|
|
|
|
if (isInAndroid()) {
|
2024-08-09 22:06:18 +08:00
|
|
|
|
window.JSAndroid.writeHTMLClipboard(protyle.lute.BlockDOM2StdMd(response.data).trimEnd(), response.data + Constants.ZWSP);
|
2024-11-25 10:52:40 +08:00
|
|
|
|
} else if (isInHarmony()) {
|
|
|
|
|
window.JSHarmony.writeHTMLClipboard(protyle.lute.BlockDOM2StdMd(response.data).trimEnd(), response.data + Constants.ZWSP);
|
2024-08-09 21:27:27 +08:00
|
|
|
|
} else {
|
|
|
|
|
writeText(response.data + Constants.ZWSP);
|
|
|
|
|
}
|
2022-10-10 20:18:08 +08:00
|
|
|
|
fetchPost("/api/block/getHeadingDeleteTransaction", {
|
|
|
|
|
id,
|
|
|
|
|
}, (response) => {
|
2022-10-10 22:36:57 +08:00
|
|
|
|
response.data.doOperations.forEach((operation: IOperation) => {
|
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {
|
|
|
|
|
itemElement.remove();
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-10-10 20:18:08 +08:00
|
|
|
|
transaction(protyle, response.data.doOperations, response.data.undoOperations);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "deleteHeadings1",
|
2022-10-10 20:18:08 +08:00
|
|
|
|
icon: "iconTrashcan",
|
2022-10-16 14:23:17 +08:00
|
|
|
|
label: `${window.siyuan.languages.delete} ${window.siyuan.languages.headings1}`,
|
2022-10-10 20:18:08 +08:00
|
|
|
|
click() {
|
|
|
|
|
fetchPost("/api/block/getHeadingDeleteTransaction", {
|
|
|
|
|
id,
|
|
|
|
|
}, (response) => {
|
2022-10-10 22:36:57 +08:00
|
|
|
|
response.data.doOperations.forEach((operation: IOperation) => {
|
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {
|
|
|
|
|
itemElement.remove();
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-10-10 20:18:08 +08:00
|
|
|
|
transaction(protyle, response.data.doOperations, response.data.undoOperations);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_2", type: "separator"}).element);
|
2022-10-26 23:23:24 +08:00
|
|
|
|
if (!protyle.options.backlinkData) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "enter",
|
2024-05-10 00:25:28 +08:00
|
|
|
|
accelerator: `${updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom)}/${updateHotkeyTip("⌘" + window.siyuan.languages.click)}`,
|
2022-10-26 23:23:24 +08:00
|
|
|
|
label: window.siyuan.languages.enter,
|
2023-06-11 10:22:05 +08:00
|
|
|
|
click: () => {
|
2023-06-01 20:50:49 +08:00
|
|
|
|
zoomOut({protyle, id});
|
2022-10-26 23:23:24 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "enterBack",
|
2022-10-26 23:23:24 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.general.enterBack.custom,
|
|
|
|
|
label: window.siyuan.languages.enterBack,
|
2023-05-18 19:27:21 +08:00
|
|
|
|
click: () => {
|
2023-08-20 12:41:00 +08:00
|
|
|
|
enterBack(protyle, id);
|
2022-09-02 20:42:59 +08:00
|
|
|
|
}
|
2022-10-26 23:23:24 +08:00
|
|
|
|
}).element);
|
2024-11-02 15:16:53 +08:00
|
|
|
|
} else {
|
2024-11-04 17:22:15 +08:00
|
|
|
|
/// #if !MOBILE
|
2024-11-02 15:16:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
id: "enter",
|
|
|
|
|
accelerator: `${updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom)}/${updateHotkeyTip("⌘" + window.siyuan.languages.click)}`,
|
|
|
|
|
label: window.siyuan.languages.openBy,
|
|
|
|
|
click: () => {
|
2024-11-04 17:22:15 +08:00
|
|
|
|
checkFold(id, (zoomIn, action) => {
|
|
|
|
|
openFileById({
|
|
|
|
|
app: protyle.app,
|
|
|
|
|
id,
|
|
|
|
|
action,
|
|
|
|
|
zoomIn
|
|
|
|
|
});
|
2024-11-02 15:16:53 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2024-11-04 17:22:15 +08:00
|
|
|
|
/// #endif
|
2022-10-26 23:23:24 +08:00
|
|
|
|
}
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (!protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "insertBefore",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconBefore",
|
|
|
|
|
label: window.siyuan.languages["insert-before"],
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.insertBefore.custom,
|
|
|
|
|
click() {
|
2022-10-22 11:31:41 +08:00
|
|
|
|
hideElements(["select"], protyle);
|
2022-10-05 10:12:21 +08:00
|
|
|
|
countBlockWord([], protyle.block.rootID);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
insertEmptyBlock(protyle, "beforebegin", id);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "insertAfter",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconAfter",
|
|
|
|
|
label: window.siyuan.languages["insert-after"],
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.insertAfter.custom,
|
|
|
|
|
click() {
|
2022-10-22 11:31:41 +08:00
|
|
|
|
hideElements(["select"], protyle);
|
2022-10-05 10:12:21 +08:00
|
|
|
|
countBlockWord([], protyle.block.rootID);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
insertEmptyBlock(protyle, "afterend", id);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2023-02-06 21:54:26 +08:00
|
|
|
|
const countElement = nodeElement.lastElementChild.querySelector(".protyle-attr--refcount");
|
2023-02-06 17:47:32 +08:00
|
|
|
|
if (countElement && countElement.textContent) {
|
2023-02-06 21:54:26 +08:00
|
|
|
|
transferBlockRef(id);
|
2023-02-06 17:47:32 +08:00
|
|
|
|
}
|
2022-10-13 21:34:43 +08:00
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "jumpToParentNext",
|
2022-10-13 21:34:43 +08:00
|
|
|
|
label: window.siyuan.languages.jumpToParentNext,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.jumpToParentNext.custom,
|
|
|
|
|
click() {
|
2022-10-22 11:31:41 +08:00
|
|
|
|
hideElements(["select"], protyle);
|
2024-04-30 22:41:43 +08:00
|
|
|
|
jumpToParent(protyle, nodeElement, "next");
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "jumpToParentPrev",
|
2024-04-30 22:41:43 +08:00
|
|
|
|
label: window.siyuan.languages.jumpToParentPrev,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.jumpToParentPrev.custom,
|
|
|
|
|
click() {
|
|
|
|
|
hideElements(["select"], protyle);
|
|
|
|
|
jumpToParent(protyle, nodeElement, "previous");
|
2022-10-13 21:34:43 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2024-04-30 22:41:43 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "jumpToParent",
|
2024-04-30 22:41:43 +08:00
|
|
|
|
label: window.siyuan.languages.jumpToParent,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.jumpToParent.custom,
|
|
|
|
|
click() {
|
|
|
|
|
hideElements(["select"], protyle);
|
|
|
|
|
jumpToParent(protyle, nodeElement, "parent");
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_3", type: "separator"}).element);
|
2022-10-13 21:34:43 +08:00
|
|
|
|
|
|
|
|
|
if (type !== "NodeThematicBreak") {
|
2022-07-28 10:27:51 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "fold",
|
2022-10-13 21:34:43 +08:00
|
|
|
|
label: window.siyuan.languages.fold,
|
2024-05-10 00:25:28 +08:00
|
|
|
|
accelerator: `${updateHotkeyTip(window.siyuan.config.keymap.editor.general.collapse.custom)}/${updateHotkeyTip("⌥" + window.siyuan.languages.click)}`,
|
2022-07-28 10:27:51 +08:00
|
|
|
|
click() {
|
2022-10-13 21:34:43 +08:00
|
|
|
|
setFold(protyle, nodeElement);
|
|
|
|
|
focusBlock(nodeElement);
|
2022-07-28 10:27:51 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (!protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "attr",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.attr,
|
2023-09-09 17:00:51 +08:00
|
|
|
|
icon: "iconAttr",
|
2024-05-10 00:25:28 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧" + window.siyuan.languages.click),
|
2022-05-26 15:18:53 +08:00
|
|
|
|
click() {
|
2023-09-24 17:53:28 +08:00
|
|
|
|
openAttr(nodeElement, "bookmark", protyle);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2022-10-13 21:34:43 +08:00
|
|
|
|
}
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (!protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const appearanceElement = new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "appearance",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.appearance,
|
2023-05-21 23:13:13 +08:00
|
|
|
|
icon: "iconFont",
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.insert.appearance.custom,
|
2023-07-21 23:27:31 +08:00
|
|
|
|
click: () => {
|
2023-07-21 23:16:23 +08:00
|
|
|
|
/// #if MOBILE
|
2023-07-21 23:27:31 +08:00
|
|
|
|
this.showMobileAppearance(protyle);
|
2023-07-21 23:16:23 +08:00
|
|
|
|
/// #else
|
2023-05-20 20:47:35 +08:00
|
|
|
|
protyle.toolbar.element.classList.add("fn__none");
|
|
|
|
|
protyle.toolbar.subElement.innerHTML = "";
|
|
|
|
|
protyle.toolbar.subElement.style.width = "";
|
|
|
|
|
protyle.toolbar.subElement.style.padding = "";
|
|
|
|
|
protyle.toolbar.subElement.append(appearanceMenu(protyle, [nodeElement]));
|
2023-10-01 10:26:31 +08:00
|
|
|
|
protyle.toolbar.subElement.style.zIndex = (++window.siyuan.zIndex).toString();
|
2023-05-20 20:47:35 +08:00
|
|
|
|
protyle.toolbar.subElement.classList.remove("fn__none");
|
|
|
|
|
protyle.toolbar.subElementCloseCB = undefined;
|
|
|
|
|
const position = nodeElement.getBoundingClientRect();
|
|
|
|
|
setPosition(protyle.toolbar.subElement, position.left, position.top);
|
|
|
|
|
/// #endif
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}).element;
|
|
|
|
|
window.siyuan.menus.menu.append(appearanceElement);
|
2023-03-16 22:18:27 +08:00
|
|
|
|
if (!isMobile()) {
|
|
|
|
|
appearanceElement.lastElementChild.classList.add("b3-menu__submenu--row");
|
|
|
|
|
}
|
2023-10-14 10:49:35 +08:00
|
|
|
|
this.genAlign([nodeElement], protyle);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.genWidths([nodeElement], protyle);
|
2024-09-12 00:43:07 +08:00
|
|
|
|
// this.genHeights([nodeElement], protyle);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_4", type: "separator"}).element);
|
2025-01-09 11:14:07 +08:00
|
|
|
|
if (window.siyuan.config.cloudRegion === 0 &&
|
|
|
|
|
!["NodeThematicBreak", "NodeBlockQueryEmbed", "NodeIFrame", "NodeHTMLBlock", "NodeWidget", "NodeVideo", "NodeAudio"].includes(type) &&
|
2022-05-26 15:18:53 +08:00
|
|
|
|
getContenteditableElement(nodeElement)?.textContent.trim() !== "" &&
|
|
|
|
|
(type !== "NodeCodeBlock" || (type === "NodeCodeBlock" && !nodeElement.getAttribute("data-subtype")))) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "wechatReminder",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconMp",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.wechatReminder,
|
2024-07-05 21:00:21 +08:00
|
|
|
|
ignore: window.siyuan.config.readonly,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
click() {
|
|
|
|
|
openWechatNotify(nodeElement);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2024-07-05 21:00:21 +08:00
|
|
|
|
if (type !== "NodeThematicBreak" && !window.siyuan.config.readonly) {
|
2022-12-26 11:05:46 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "quickMakeCard",
|
|
|
|
|
icon: "iconRiffCard",
|
2023-02-19 00:05:38 +08:00
|
|
|
|
label: window.siyuan.languages.quickMakeCard,
|
2023-02-19 09:24:40 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.quickMakeCard.custom,
|
2023-02-23 18:33:04 +08:00
|
|
|
|
iconHTML: '<svg class="b3-menu__icon" style="color:var(--b3-theme-primary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
2023-02-19 00:05:38 +08:00
|
|
|
|
click() {
|
2023-04-09 23:04:30 +08:00
|
|
|
|
quickMakeCard(protyle, [nodeElement]);
|
2023-02-19 00:05:38 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2024-07-05 21:00:21 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "addToDeck",
|
2024-07-05 21:00:21 +08:00
|
|
|
|
label: window.siyuan.languages.addToDeck,
|
|
|
|
|
ignore: !window.siyuan.config.flashcard.deck,
|
|
|
|
|
icon: "iconRiffCard",
|
|
|
|
|
click() {
|
|
|
|
|
makeCard(protyle.app, [id]);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2024-09-22 09:16:22 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({id: "separator_5", type: "separator"}).element);
|
2022-12-26 11:05:46 +08:00
|
|
|
|
}
|
2023-06-29 18:56:46 +08:00
|
|
|
|
|
|
|
|
|
if (protyle?.app?.plugins) {
|
|
|
|
|
emitOpenMenu({
|
2023-07-12 18:32:23 +08:00
|
|
|
|
plugins: protyle.app.plugins,
|
2023-06-29 18:56:46 +08:00
|
|
|
|
type: "click-blockicon",
|
|
|
|
|
detail: {
|
|
|
|
|
protyle,
|
|
|
|
|
blockElements: [nodeElement]
|
|
|
|
|
},
|
|
|
|
|
separatorPosition: "bottom",
|
2023-05-31 20:06:19 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2023-06-29 18:56:46 +08:00
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let updateHTML = nodeElement.getAttribute("updated") || "";
|
|
|
|
|
if (updateHTML) {
|
|
|
|
|
updateHTML = `${window.siyuan.languages.modifiedAt} ${dayjs(updateHTML).format("YYYY-MM-DD HH:mm:ss")}<br>`;
|
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "updateAndCreatedAt",
|
2024-01-26 17:58:02 +08:00
|
|
|
|
iconHTML: "",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
type: "readonly",
|
2023-01-27 12:21:33 +08:00
|
|
|
|
label: `${updateHTML}${window.siyuan.languages.createdAt} ${dayjs(id.substr(0, 14)).format("YYYY-MM-DD HH:mm:ss")}`,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}).element);
|
|
|
|
|
return window.siyuan.menus.menu;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 00:02:29 +08:00
|
|
|
|
private genHeadingTransform(protyle: IProtyle, id: string, level: number) {
|
|
|
|
|
return {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "heading" + level,
|
2023-08-16 19:16:31 +08:00
|
|
|
|
iconHTML: "",
|
2022-09-28 00:02:29 +08:00
|
|
|
|
icon: "iconHeading" + level,
|
|
|
|
|
label: window.siyuan.languages["heading" + level],
|
|
|
|
|
click() {
|
|
|
|
|
fetchPost("/api/block/getHeadingLevelTransaction", {
|
|
|
|
|
id,
|
|
|
|
|
level
|
|
|
|
|
}, (response) => {
|
2023-09-28 22:31:33 +08:00
|
|
|
|
response.data.doOperations.forEach((operation: IOperation, index: number) => {
|
2022-09-28 00:02:29 +08:00
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {
|
|
|
|
|
itemElement.outerHTML = operation.data;
|
|
|
|
|
});
|
2023-09-28 22:31:33 +08:00
|
|
|
|
// 使用 outer 后元素需要重新查询
|
2022-09-28 00:02:29 +08:00
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {
|
|
|
|
|
mathRender(itemElement);
|
|
|
|
|
});
|
2023-09-28 22:31:33 +08:00
|
|
|
|
if (index === 0) {
|
|
|
|
|
focusBlock(protyle.wysiwyg.element.querySelector(`[data-node-id="${operation.id}"]`), protyle.wysiwyg.element, true);
|
|
|
|
|
}
|
2022-09-28 00:02:29 +08:00
|
|
|
|
});
|
2022-09-28 12:14:18 +08:00
|
|
|
|
transaction(protyle, response.data.doOperations, response.data.undoOperations);
|
2022-09-28 00:02:29 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2022-09-28 12:14:18 +08:00
|
|
|
|
};
|
2022-09-28 00:02:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
private genClick(nodeElements: Element[], protyle: IProtyle, cb: (e: HTMLElement) => void) {
|
2022-08-01 11:59:22 +08:00
|
|
|
|
updateBatchTransaction(nodeElements, protyle, cb);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
focusBlock(nodeElements[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private genAlign(nodeElements: Element[], protyle: IProtyle) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "layout",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.layout,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: [{
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "alignLeft",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconAlignLeft",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.alignLeft,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.alignLeft.custom,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
2023-10-14 10:49:35 +08:00
|
|
|
|
if (e.classList.contains("av")) {
|
2023-11-09 19:50:39 +08:00
|
|
|
|
e.style.justifyContent = "";
|
2023-10-14 10:49:35 +08:00
|
|
|
|
} else {
|
2023-10-14 10:01:42 +08:00
|
|
|
|
e.style.textAlign = "left";
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "alignCenter",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconAlignCenter",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.alignCenter,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.alignCenter.custom,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
2023-10-14 10:49:35 +08:00
|
|
|
|
if (e.classList.contains("av")) {
|
2023-11-09 19:50:39 +08:00
|
|
|
|
e.style.justifyContent = "center";
|
2023-10-14 10:49:35 +08:00
|
|
|
|
} else {
|
2023-10-14 10:01:42 +08:00
|
|
|
|
e.style.textAlign = "center";
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "alignRight",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconAlignRight",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.alignRight,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.alignRight.custom,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
2023-10-14 10:49:35 +08:00
|
|
|
|
if (e.classList.contains("av")) {
|
2023-11-09 19:50:39 +08:00
|
|
|
|
e.style.justifyContent = "flex-end";
|
2023-10-14 10:49:35 +08:00
|
|
|
|
} else {
|
2023-10-14 10:01:42 +08:00
|
|
|
|
e.style.textAlign = "right";
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "justify",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconMenu",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.justify,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
2023-11-09 17:00:55 +08:00
|
|
|
|
e.style.textAlign = "justify";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2022-11-01 10:51:06 +08:00
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "separator_1",
|
2022-11-01 10:51:06 +08:00
|
|
|
|
type: "separator"
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "ltr",
|
2022-12-07 14:49:24 +08:00
|
|
|
|
icon: "iconLtr",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.ltr,
|
2022-11-01 10:51:06 +08:00
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
2023-10-14 10:49:35 +08:00
|
|
|
|
e.style.direction = "ltr";
|
2022-11-01 10:51:06 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "rtl",
|
2022-11-01 10:51:06 +08:00
|
|
|
|
icon: "iconRtl",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.rtl,
|
2022-11-01 10:51:06 +08:00
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
2023-10-14 10:49:35 +08:00
|
|
|
|
if (!e.classList.contains("av")) {
|
2023-10-14 10:01:42 +08:00
|
|
|
|
e.style.direction = "rtl";
|
|
|
|
|
}
|
2022-11-01 10:51:06 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "separator_2",
|
2022-11-01 10:51:06 +08:00
|
|
|
|
type: "separator"
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "clearFontStyle",
|
2022-11-01 10:51:06 +08:00
|
|
|
|
icon: "iconTrashcan",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
label: window.siyuan.languages.clearFontStyle,
|
2022-11-01 10:51:06 +08:00
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
2023-10-14 10:49:35 +08:00
|
|
|
|
if (e.classList.contains("av")) {
|
2023-11-09 19:50:39 +08:00
|
|
|
|
e.style.justifyContent = "";
|
2023-10-14 10:49:35 +08:00
|
|
|
|
} else {
|
|
|
|
|
e.style.textAlign = "";
|
2023-11-09 17:00:55 +08:00
|
|
|
|
e.style.direction = "";
|
2023-10-14 10:49:35 +08:00
|
|
|
|
}
|
2022-11-01 10:51:06 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}]
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-12 00:43:07 +08:00
|
|
|
|
private updateNodeElements(nodeElements: Element[], protyle: IProtyle, inputElement: HTMLInputElement) {
|
|
|
|
|
const undoOperations: IOperation[] = [];
|
|
|
|
|
const operations: IOperation[] = [];
|
|
|
|
|
nodeElements.forEach((e) => {
|
|
|
|
|
undoOperations.push({
|
|
|
|
|
action: "update",
|
|
|
|
|
id: e.getAttribute("data-node-id"),
|
|
|
|
|
data: e.outerHTML
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
inputElement.addEventListener(inputElement.type === "number" ? "blur" : "change", () => {
|
|
|
|
|
nodeElements.forEach((e: HTMLElement) => {
|
|
|
|
|
operations.push({
|
|
|
|
|
action: "update",
|
|
|
|
|
id: e.getAttribute("data-node-id"),
|
|
|
|
|
data: e.outerHTML
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
transaction(protyle, operations, undoOperations);
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
focusBlock(nodeElements[0]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
private genWidths(nodeElements: Element[], protyle: IProtyle) {
|
2024-09-12 00:43:07 +08:00
|
|
|
|
let rangeElement: HTMLInputElement;
|
2024-09-13 21:32:11 +08:00
|
|
|
|
const firstElement = nodeElements[0] as HTMLElement;
|
2024-09-12 00:43:07 +08:00
|
|
|
|
const styles: IMenu[] = [{
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "widthInput",
|
2024-09-12 00:43:07 +08:00
|
|
|
|
iconHTML: "",
|
|
|
|
|
type: "readonly",
|
|
|
|
|
label: `<div class="fn__flex-center">
|
|
|
|
|
<input class="b3-text-field" value="${firstElement.style.width.endsWith("px") ? parseInt(firstElement.style.width) : ""}" type="number" style="margin: 4px" placeholder="${window.siyuan.languages.width}"> px
|
|
|
|
|
</div>`,
|
|
|
|
|
bind: (element) => {
|
|
|
|
|
const inputElement = element.querySelector("input");
|
|
|
|
|
inputElement.addEventListener("input", () => {
|
|
|
|
|
nodeElements.forEach((item: HTMLElement) => {
|
|
|
|
|
item.style.width = inputElement.value + "px";
|
|
|
|
|
item.style.flex = "none";
|
2024-09-13 21:32:11 +08:00
|
|
|
|
});
|
2024-09-12 00:43:07 +08:00
|
|
|
|
rangeElement.value = "0";
|
|
|
|
|
rangeElement.parentElement.setAttribute("aria-label", inputElement.value + "px");
|
|
|
|
|
});
|
|
|
|
|
this.updateNodeElements(nodeElements, protyle, inputElement);
|
|
|
|
|
}
|
|
|
|
|
}];
|
2024-09-11 18:11:34 +08:00
|
|
|
|
["25%", "33%", "50%", "67%", "75%", "100%"].forEach((item) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
styles.push({
|
2024-09-23 08:43:49 +08:00
|
|
|
|
id: "width_" + item,
|
2024-09-12 00:43:07 +08:00
|
|
|
|
iconHTML: "",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: item,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.width = item;
|
|
|
|
|
e.style.flex = "none";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
styles.push({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "separator_1",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
type: "separator"
|
|
|
|
|
});
|
2024-09-12 00:43:07 +08:00
|
|
|
|
const width = firstElement.style.width.endsWith("%") ? parseInt(firstElement.style.width) : 0;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "widthDrag",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.width,
|
|
|
|
|
submenu: styles.concat([{
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "widthDrag",
|
2024-09-12 00:43:07 +08:00
|
|
|
|
iconHTML: "",
|
|
|
|
|
type: "readonly",
|
|
|
|
|
label: `<div style="margin: 4px 0;" aria-label="${firstElement.style.width.endsWith("px") ? firstElement.style.width : (firstElement.style.width || window.siyuan.languages.default)}" class="b3-tooltips b3-tooltips__n${isMobile() ? "" : " fn__size200"}">
|
2022-05-26 15:18:53 +08:00
|
|
|
|
<input style="box-sizing: border-box" value="${width}" class="b3-slider fn__block" max="100" min="1" step="1" type="range">
|
|
|
|
|
</div>`,
|
2024-09-12 00:43:07 +08:00
|
|
|
|
bind: (element) => {
|
|
|
|
|
rangeElement = element.querySelector("input");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
rangeElement.addEventListener("input", () => {
|
2024-09-12 00:43:07 +08:00
|
|
|
|
nodeElements.forEach((e: HTMLElement) => {
|
|
|
|
|
e.style.width = rangeElement.value + "%";
|
|
|
|
|
e.style.flex = "none";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
rangeElement.parentElement.setAttribute("aria-label", `${rangeElement.value}%`);
|
|
|
|
|
});
|
2024-09-12 00:43:07 +08:00
|
|
|
|
this.updateNodeElements(nodeElements, protyle, rangeElement);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "separator_2",
|
2024-09-12 00:43:07 +08:00
|
|
|
|
type: "separator"
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "default",
|
2024-09-12 00:43:07 +08:00
|
|
|
|
iconHTML: "",
|
|
|
|
|
label: window.siyuan.languages.default,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
if (e.style.width) {
|
|
|
|
|
e.style.width = "";
|
|
|
|
|
e.style.flex = "";
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
2024-09-12 00:43:07 +08:00
|
|
|
|
}
|
|
|
|
|
}]),
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO https://github.com/siyuan-note/siyuan/issues/11055
|
|
|
|
|
private genHeights(nodeElements: Element[], protyle: IProtyle) {
|
|
|
|
|
const matchHeight = nodeElements.find(item => {
|
|
|
|
|
if (!item.classList.contains("p") && !item.classList.contains("code-block") && !item.classList.contains("render-node")) {
|
2024-09-13 21:32:11 +08:00
|
|
|
|
return true;
|
2024-09-12 00:43:07 +08:00
|
|
|
|
}
|
2024-09-13 21:32:11 +08:00
|
|
|
|
});
|
2024-09-12 00:43:07 +08:00
|
|
|
|
if (matchHeight) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let rangeElement: HTMLInputElement;
|
2024-09-13 21:32:11 +08:00
|
|
|
|
const firstElement = nodeElements[0] as HTMLElement;
|
2024-09-12 00:43:07 +08:00
|
|
|
|
const styles: IMenu[] = [{
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "heightInput",
|
2024-09-12 00:43:07 +08:00
|
|
|
|
iconHTML: "",
|
|
|
|
|
type: "readonly",
|
|
|
|
|
label: `<div class="fn__flex-center">
|
|
|
|
|
<input class="b3-text-field" value="${firstElement.style.height.endsWith("px") ? parseInt(firstElement.style.height) : ""}" type="number" style="margin: 4px" placeholder="${window.siyuan.languages.height}"> px
|
|
|
|
|
</div>`,
|
|
|
|
|
bind: (element) => {
|
|
|
|
|
const inputElement = element.querySelector("input");
|
|
|
|
|
inputElement.addEventListener("input", () => {
|
|
|
|
|
nodeElements.forEach((item: HTMLElement) => {
|
|
|
|
|
item.style.height = inputElement.value + "px";
|
|
|
|
|
item.style.flex = "none";
|
2024-09-13 21:32:11 +08:00
|
|
|
|
});
|
2024-09-12 00:43:07 +08:00
|
|
|
|
rangeElement.value = "0";
|
|
|
|
|
rangeElement.parentElement.setAttribute("aria-label", inputElement.value + "px");
|
|
|
|
|
});
|
|
|
|
|
this.updateNodeElements(nodeElements, protyle, inputElement);
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
["25%", "33%", "50%", "67%", "75%", "100%"].forEach((item) => {
|
|
|
|
|
styles.push({
|
2024-09-23 08:43:49 +08:00
|
|
|
|
id: "height_" + item,
|
2024-09-12 00:43:07 +08:00
|
|
|
|
iconHTML: "",
|
|
|
|
|
label: item,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.height = item;
|
|
|
|
|
e.style.flex = "none";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
styles.push({
|
|
|
|
|
type: "separator"
|
|
|
|
|
});
|
|
|
|
|
const height = firstElement.style.height.endsWith("%") ? parseInt(firstElement.style.height) : 0;
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "heightDrag",
|
2024-09-12 00:43:07 +08:00
|
|
|
|
label: window.siyuan.languages.height,
|
|
|
|
|
submenu: styles.concat([{
|
|
|
|
|
iconHTML: "",
|
2024-09-22 09:16:22 +08:00
|
|
|
|
type: "readonly",
|
2024-09-12 00:43:07 +08:00
|
|
|
|
label: `<div style="margin: 4px 0;" aria-label="${firstElement.style.height.endsWith("px") ? firstElement.style.height : (firstElement.style.height || window.siyuan.languages.default)}" class="b3-tooltips b3-tooltips__n${isMobile() ? "" : " fn__size200"}">
|
|
|
|
|
<input style="box-sizing: border-box" value="${height}" class="b3-slider fn__block" max="100" min="1" step="1" type="range">
|
|
|
|
|
</div>`,
|
|
|
|
|
bind: (element) => {
|
|
|
|
|
rangeElement = element.querySelector("input");
|
|
|
|
|
rangeElement.addEventListener("input", () => {
|
2023-10-14 10:49:35 +08:00
|
|
|
|
nodeElements.forEach((e: HTMLElement) => {
|
2024-09-12 00:43:07 +08:00
|
|
|
|
e.style.height = rangeElement.value + "%";
|
|
|
|
|
e.style.flex = "none";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
2024-09-12 00:43:07 +08:00
|
|
|
|
rangeElement.parentElement.setAttribute("aria-label", `${rangeElement.value}%`);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
2024-09-12 00:43:07 +08:00
|
|
|
|
this.updateNodeElements(nodeElements, protyle, rangeElement);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
type: "separator"
|
|
|
|
|
}, {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "default",
|
2024-09-12 00:43:07 +08:00
|
|
|
|
iconHTML: "",
|
|
|
|
|
label: window.siyuan.languages.default,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
2024-09-12 00:43:07 +08:00
|
|
|
|
if (e.style.height) {
|
|
|
|
|
e.style.height = "";
|
2024-09-13 21:32:11 +08:00
|
|
|
|
e.style.overflow = "";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}]),
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-04 15:40:54 +08:00
|
|
|
|
private genCopyTextRef(selectsElement: Element[]): false | IMenu {
|
|
|
|
|
if (isNotEditBlock(selectsElement[0])) {
|
2023-02-06 21:54:26 +08:00
|
|
|
|
return false;
|
2023-02-04 15:40:54 +08:00
|
|
|
|
}
|
|
|
|
|
return {
|
2024-09-22 09:16:22 +08:00
|
|
|
|
id: "copyText",
|
2024-05-24 08:31:06 +08:00
|
|
|
|
iconHTML: "",
|
2023-07-12 18:32:23 +08:00
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.copyText.custom,
|
|
|
|
|
label: window.siyuan.languages.copyText,
|
2023-02-04 15:40:54 +08:00
|
|
|
|
click() {
|
|
|
|
|
// 用于标识复制文本 *
|
2023-02-06 21:54:26 +08:00
|
|
|
|
selectsElement[0].setAttribute("data-reftext", "true");
|
2023-02-04 15:40:54 +08:00
|
|
|
|
focusByRange(getEditorRange(selectsElement[0]));
|
|
|
|
|
document.execCommand("copy");
|
|
|
|
|
}
|
2023-02-06 21:54:26 +08:00
|
|
|
|
};
|
2023-02-04 15:40:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-20 22:23:30 +08:00
|
|
|
|
public render(protyle: IProtyle, element: Element, wysiwyg: HTMLElement, target?: Element) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/4659
|
2024-05-29 22:19:21 +08:00
|
|
|
|
if (protyle.title && protyle.title.element.getAttribute("data-render") !== "true") {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 防止划选时触碰图标导致 hl 无法移除
|
|
|
|
|
const selectElement = wysiwyg.parentElement.parentElement.querySelector(".protyle-select");
|
|
|
|
|
if (selectElement && !selectElement.classList.contains("fn__none")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let html = "";
|
|
|
|
|
let nodeElement = element;
|
|
|
|
|
let space = 0;
|
|
|
|
|
let index = 0;
|
|
|
|
|
let listItem;
|
|
|
|
|
let hideParent = false;
|
|
|
|
|
while (nodeElement) {
|
|
|
|
|
const isShow = !hideParent || (hideParent && nodeElement.getAttribute("fold") === "1");
|
2024-07-25 17:55:25 +08:00
|
|
|
|
if (!isInEmbedBlock(nodeElement)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let type;
|
|
|
|
|
if (isShow) {
|
|
|
|
|
type = nodeElement.getAttribute("data-type");
|
|
|
|
|
}
|
2025-02-04 16:41:43 +08:00
|
|
|
|
let dataNodeId = nodeElement.getAttribute("data-node-id");
|
2023-12-20 22:23:30 +08:00
|
|
|
|
if (type === "NodeAttributeView" && target) {
|
|
|
|
|
const rowElement = hasClosestByClassName(target, "av__row");
|
|
|
|
|
if (rowElement && !rowElement.classList.contains("av__row--header")) {
|
|
|
|
|
element = rowElement;
|
2024-10-28 12:10:36 +08:00
|
|
|
|
let iconAriaLabel = isMac() ? window.siyuan.languages.rowTip : window.siyuan.languages.rowTip.replace("⇧", "Shift+");
|
|
|
|
|
if (protyle.disabled) {
|
2024-10-29 23:01:31 +08:00
|
|
|
|
iconAriaLabel = window.siyuan.languages.rowTip.substring(0, window.siyuan.languages.rowTip.indexOf("<br"));
|
2024-10-28 22:11:59 +08:00
|
|
|
|
} else if (rowElement.querySelector('[data-dtype="block"]')?.getAttribute("data-detached") === "true") {
|
2024-10-29 23:01:31 +08:00
|
|
|
|
iconAriaLabel = window.siyuan.languages.rowTip.substring(0, window.siyuan.languages.rowTip.lastIndexOf("<br"));
|
2024-10-28 12:10:36 +08:00
|
|
|
|
}
|
|
|
|
|
html = `<button data-type="NodeAttributeViewRowMenu" data-node-id="${dataNodeId}" data-row-id="${rowElement.dataset.id}" class="ariaLabel" data-position="right" aria-label="${iconAriaLabel}"><svg><use xlink:href="#iconDrag"></use></svg><span ${protyle.disabled ? "" : 'draggable="true" class="fn__grab"'}></span></button>`;
|
2023-12-21 00:33:48 +08:00
|
|
|
|
if (!protyle.disabled) {
|
2023-12-21 09:07:53 +08:00
|
|
|
|
html = `<button data-type="NodeAttributeViewRow" data-node-id="${dataNodeId}" data-row-id="${rowElement.dataset.id}" class="ariaLabel" data-position="right" aria-label="${isMac() ? window.siyuan.languages.addBelowAbove : window.siyuan.languages.addBelowAbove.replace("⌥", "Alt+")}"><svg><use xlink:href="#iconAdd"></use></svg></button>${html}`;
|
2023-12-21 00:33:48 +08:00
|
|
|
|
}
|
2023-12-20 22:23:30 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (index === 0) {
|
|
|
|
|
// 不单独显示,要不然在块的间隔中,gutter 会跳来跳去的
|
|
|
|
|
if (["NodeBlockquote", "NodeList", "NodeSuperBlock"].includes(type)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const topElement = getTopAloneElement(nodeElement);
|
|
|
|
|
listItem = topElement.querySelector(".li") || topElement.querySelector(".list");
|
2022-10-18 11:51:15 +08:00
|
|
|
|
// 嵌入块中有列表时块标显示位置错误 https://github.com/siyuan-note/siyuan/issues/6254
|
2024-07-25 17:55:25 +08:00
|
|
|
|
if (isInEmbedBlock(listItem)) {
|
2022-10-18 11:51:15 +08:00
|
|
|
|
listItem = undefined;
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
// 标题必须显示
|
|
|
|
|
if (!topElement.isSameNode(nodeElement) && type !== "NodeHeading") {
|
|
|
|
|
nodeElement = topElement;
|
|
|
|
|
type = nodeElement.getAttribute("data-type");
|
2025-02-04 16:41:43 +08:00
|
|
|
|
dataNodeId = nodeElement.getAttribute("data-node-id");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (type === "NodeListItem" && index === 1 && !isShow) {
|
|
|
|
|
// 列表项中第一层不显示
|
|
|
|
|
html = "";
|
|
|
|
|
}
|
|
|
|
|
index += 1;
|
2024-10-28 12:40:03 +08:00
|
|
|
|
let gutterTip = this.gutterTip;
|
|
|
|
|
if (protyle.disabled) {
|
2024-10-29 23:01:31 +08:00
|
|
|
|
gutterTip = this.gutterTip.split("<br>").splice(0, 2).join("<br>");
|
2024-10-28 12:40:03 +08:00
|
|
|
|
}
|
2025-02-04 16:41:43 +08:00
|
|
|
|
|
|
|
|
|
let popoverHTML = ""
|
|
|
|
|
if (protyle.options.backlinkData) {
|
|
|
|
|
popoverHTML = `class="popover__block" data-id="${dataNodeId}"`
|
|
|
|
|
}
|
2024-10-28 12:40:03 +08:00
|
|
|
|
const buttonHTML = `<button class="ariaLabel" data-position="right" aria-label="${gutterTip}"
|
2025-02-04 16:41:43 +08:00
|
|
|
|
data-type="${type}" data-subtype="${nodeElement.getAttribute("data-subtype")}" data-node-id="${dataNodeId}">
|
2023-10-22 23:17:56 +08:00
|
|
|
|
<svg><use xlink:href="#${getIconByType(type, nodeElement.getAttribute("data-subtype"))}"></use></svg>
|
2025-02-04 16:41:43 +08:00
|
|
|
|
<span ${popoverHTML} ${protyle.disabled ? "" : 'draggable="true"'}></span>
|
2023-10-24 10:42:04 +08:00
|
|
|
|
</button>`;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (isShow) {
|
2023-10-22 23:17:56 +08:00
|
|
|
|
html = buttonHTML + html;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
let foldHTML = "";
|
|
|
|
|
if (type === "NodeListItem" && nodeElement.childElementCount > 3 || type === "NodeHeading") {
|
|
|
|
|
const fold = nodeElement.getAttribute("fold");
|
2023-11-07 09:02:01 +08:00
|
|
|
|
foldHTML = `<button class="ariaLabel" data-position="right" aria-label="${window.siyuan.languages.fold}"
|
2024-10-26 17:28:23 +08:00
|
|
|
|
data-type="fold" style="cursor:inherit;"><svg style="width: 10px${fold && fold === "1" ? "" : ";transform:rotate(90deg)"}"><use xlink:href="#iconPlay"></use></svg></button>`;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
if (type === "NodeListItem" || type === "NodeList") {
|
|
|
|
|
listItem = nodeElement;
|
|
|
|
|
if (type === "NodeListItem" && nodeElement.childElementCount > 3) {
|
2023-10-22 23:17:56 +08:00
|
|
|
|
html = buttonHTML + foldHTML;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (type === "NodeHeading") {
|
|
|
|
|
html = html + foldHTML;
|
|
|
|
|
}
|
|
|
|
|
if (type === "NodeBlockquote") {
|
|
|
|
|
space += 8;
|
|
|
|
|
}
|
|
|
|
|
if (nodeElement.previousElementSibling && nodeElement.previousElementSibling.getAttribute("data-node-id")) {
|
|
|
|
|
// 前一个块存在时,只显示到当前层级,但需显示折叠块的块标
|
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/2562 https://github.com/siyuan-note/siyuan/issues/2809
|
|
|
|
|
hideParent = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const parentElement = hasClosestBlock(nodeElement.parentElement);
|
|
|
|
|
if (parentElement) {
|
|
|
|
|
nodeElement = parentElement;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let match = true;
|
|
|
|
|
const buttonsElement = this.element.querySelectorAll("button");
|
|
|
|
|
if (buttonsElement.length !== html.split("</button>").length - 1) {
|
|
|
|
|
match = false;
|
|
|
|
|
} else {
|
2023-12-20 23:30:08 +08:00
|
|
|
|
Array.from(buttonsElement).find(item => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const id = item.getAttribute("data-node-id");
|
|
|
|
|
if (id && html.indexOf(id) === -1) {
|
|
|
|
|
match = false;
|
2023-12-21 09:07:53 +08:00
|
|
|
|
return true;
|
2023-12-20 23:30:08 +08:00
|
|
|
|
}
|
|
|
|
|
const rowId = item.getAttribute("data-row-id");
|
2023-12-21 00:33:48 +08:00
|
|
|
|
if ((rowId && html.indexOf(rowId) === -1) || (!rowId && html.indexOf("NodeAttributeViewRowMenu") > -1)) {
|
2023-12-20 23:30:08 +08:00
|
|
|
|
match = false;
|
|
|
|
|
return true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// 防止抖动 https://github.com/siyuan-note/siyuan/issues/4166
|
|
|
|
|
if (match && this.element.childElementCount > 0) {
|
|
|
|
|
this.element.classList.remove("fn__none");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.element.innerHTML = html;
|
|
|
|
|
this.element.classList.remove("fn__none");
|
|
|
|
|
this.element.style.width = "";
|
2023-11-10 20:02:03 +08:00
|
|
|
|
const contentTop = wysiwyg.parentElement.getBoundingClientRect().top;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let rect = element.getBoundingClientRect();
|
|
|
|
|
let marginHeight = 0;
|
|
|
|
|
if (listItem) {
|
|
|
|
|
rect = listItem.firstElementChild.getBoundingClientRect();
|
|
|
|
|
space = 0;
|
|
|
|
|
} else if (nodeElement.getAttribute("data-type") === "NodeBlockQueryEmbed") {
|
|
|
|
|
rect = nodeElement.getBoundingClientRect();
|
|
|
|
|
space = 0;
|
2023-12-28 23:46:18 +08:00
|
|
|
|
} else if (!element.classList.contains("av__row")) {
|
|
|
|
|
if (rect.height < Math.floor(window.siyuan.config.editor.fontSize * 1.625) + 8 ||
|
|
|
|
|
(rect.height > Math.floor(window.siyuan.config.editor.fontSize * 1.625) + 8 && rect.height < Math.floor(window.siyuan.config.editor.fontSize * 1.625) * 2 + 8)) {
|
|
|
|
|
marginHeight = (rect.height - this.element.clientHeight) / 2;
|
|
|
|
|
} else if ((nodeElement.getAttribute("data-type") === "NodeAttributeView" || element.getAttribute("data-type") === "NodeAttributeView") &&
|
|
|
|
|
contentTop < rect.top) {
|
|
|
|
|
marginHeight = 8;
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2023-11-09 19:50:39 +08:00
|
|
|
|
this.element.style.top = `${Math.max(rect.top, contentTop) + marginHeight}px`;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let left = rect.left - this.element.clientWidth - space;
|
2024-03-28 11:08:42 +08:00
|
|
|
|
if ((nodeElement.getAttribute("data-type") === "NodeBlockQueryEmbed" && this.element.childElementCount === 1)) {
|
|
|
|
|
// 嵌入块为列表时
|
2022-05-26 15:18:53 +08:00
|
|
|
|
left = nodeElement.getBoundingClientRect().left - this.element.clientWidth - space;
|
2024-03-28 11:08:42 +08:00
|
|
|
|
} else if (element.classList.contains("av__row")) {
|
|
|
|
|
// 为数据库行
|
|
|
|
|
left = nodeElement.getBoundingClientRect().left - this.element.clientWidth - space + parseInt(getComputedStyle(nodeElement).paddingLeft);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
this.element.style.left = `${left}px`;
|
|
|
|
|
if (left < this.element.parentElement.getBoundingClientRect().left) {
|
|
|
|
|
this.element.style.width = "24px";
|
2022-12-07 18:27:24 +08:00
|
|
|
|
// 需加 2,否则和折叠标题无法对齐
|
|
|
|
|
this.element.style.left = `${rect.left - this.element.clientWidth - space / 2 + 3}px`;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
html = "";
|
|
|
|
|
Array.from(this.element.children).reverse().forEach((item, index) => {
|
|
|
|
|
if (index !== 0) {
|
|
|
|
|
(item.firstElementChild as HTMLElement).style.height = "14px";
|
|
|
|
|
}
|
|
|
|
|
html += item.outerHTML;
|
|
|
|
|
});
|
|
|
|
|
this.element.innerHTML = html;
|
|
|
|
|
} else {
|
|
|
|
|
this.element.querySelectorAll("svg").forEach(item => {
|
|
|
|
|
item.style.height = "";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|