2023-02-06 18:11:14 +08:00
|
|
|
|
import {hasClosestBlock, hasClosestByAttribute, hasClosestByMatchTag, hasClosestByTag} from "../util/hasClosest";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {getIconByType} from "../../editor/getIcon";
|
|
|
|
|
import {iframeMenu, setFold, tableMenu, videoMenu, zoomOut} from "../../menus/protyle";
|
2023-06-29 18:56:46 +08:00
|
|
|
|
import {MenuItem} from "../../menus/Menu";
|
2022-12-22 11:08:25 +08:00
|
|
|
|
import {copySubMenu, openAttr, openWechatNotify} from "../../menus/commonMenuItem";
|
2022-11-22 00:56:37 +08:00
|
|
|
|
import {copyPlainText, updateHotkeyTip, writeText} from "../util/compatibility";
|
2022-08-01 11:59:22 +08:00
|
|
|
|
import {
|
|
|
|
|
transaction,
|
2023-02-06 18:11:14 +08:00
|
|
|
|
turnsIntoOneTransaction,
|
|
|
|
|
turnsIntoTransaction,
|
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";
|
2022-08-29 20:57:33 +08:00
|
|
|
|
import {focusBlock, focusByRange, focusByWbr, getEditorRange} from "../util/selection";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {hideElements} from "../ui/hideElements";
|
|
|
|
|
import {processRender} from "../util/processCode";
|
2023-06-07 10:36:20 +08:00
|
|
|
|
import {highlightRender} from "../render/highlightRender";
|
|
|
|
|
import {blockRender} from "../render/blockRender";
|
2023-02-02 23:16:18 +08:00
|
|
|
|
import {removeEmbed} from "../wysiwyg/removeEmbed";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {getContenteditableElement, getTopAloneElement, isNotEditBlock} from "../wysiwyg/getBlock";
|
|
|
|
|
import * as dayjs from "dayjs";
|
2022-08-29 20:57:33 +08:00
|
|
|
|
import {fetchPost, fetchSyncPost} from "../../util/fetch";
|
2022-07-28 10:27:51 +08:00
|
|
|
|
import {cancelSB, insertEmptyBlock, jumpToParentNext} from "../../block/util";
|
2022-06-28 10:19:15 +08:00
|
|
|
|
import {countBlockWord} from "../../layout/status";
|
2022-09-03 11:20:36 +08:00
|
|
|
|
/// #if !MOBILE
|
2022-09-02 20:42:59 +08:00
|
|
|
|
import {openFileById} from "../../editor/util";
|
2022-09-03 11:20:36 +08:00
|
|
|
|
/// #endif
|
|
|
|
|
import {Constants} from "../../constants";
|
|
|
|
|
import {openMobileFileById} from "../../mobile/editor";
|
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-08 22:55:31 +08:00
|
|
|
|
import {avRender} from "../render/av/render";
|
2023-06-29 18:56:46 +08:00
|
|
|
|
import {emitOpenMenu} from "../../plugin/EventBus";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
export class Gutter {
|
|
|
|
|
public element: HTMLElement;
|
|
|
|
|
|
2023-06-01 20:50:49 +08:00
|
|
|
|
constructor(protyle: IProtyle) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.element = document.createElement("div");
|
|
|
|
|
this.element.className = "protyle-gutters";
|
2023-05-03 14:43:19 +08:00
|
|
|
|
if (/Mac/.test(navigator.platform) || navigator.platform === "iPhone") {
|
|
|
|
|
this.element.setAttribute("aria-label", window.siyuan.languages.gutterTip);
|
|
|
|
|
} else {
|
2023-07-19 12:34:06 +08:00
|
|
|
|
this.element.setAttribute("aria-label", window.siyuan.languages.gutterTip.replace("⌥⌘A", "Ctrl+Alt+A").replace(/⌘/g, "Ctrl+").replace(/⌥/g, "Alt+").replace(/⇧/g, "Shift+").replace(/⌃/g, "Ctrl+"));
|
2023-05-03 14:43:19 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.element.setAttribute("data-type", "a");
|
|
|
|
|
this.element.setAttribute("data-position", "right");
|
|
|
|
|
this.element.addEventListener("dragstart", (event: DragEvent & { target: HTMLElement }) => {
|
2023-05-12 23:45:06 +08:00
|
|
|
|
hideTooltip();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let selectIds: string[] = [event.target.getAttribute("data-node-id")];
|
|
|
|
|
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
|
|
|
|
if (selectElements.length > 0) {
|
|
|
|
|
selectIds = [];
|
|
|
|
|
selectElements.forEach(item => {
|
|
|
|
|
selectIds.push(item.getAttribute("data-node-id"));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (selectElements.length === 0) {
|
|
|
|
|
event.dataTransfer.setDragImage(protyle.wysiwyg.element.querySelector(`[data-node-id="${selectIds[0]}"]`), 0, 0);
|
|
|
|
|
}
|
|
|
|
|
event.target.style.opacity = "0.1";
|
2023-02-17 15:34:38 +08:00
|
|
|
|
window.siyuan.dragElement = protyle.wysiwyg.element;
|
|
|
|
|
event.dataTransfer.setData(`${Constants.SIYUAN_DROP_GUTTER}${event.target.getAttribute("data-type")}${Constants.ZWSP}${event.target.getAttribute("data-subtype")}${Constants.ZWSP}${selectIds}`,
|
|
|
|
|
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();
|
|
|
|
|
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 => {
|
|
|
|
|
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") &&
|
|
|
|
|
this.isMatchNode(item)) {
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
});
|
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,
|
|
|
|
|
data: JSON.stringify({fold: hasFold ? "0" : "1"})
|
2022-11-12 00:55:13 +08:00
|
|
|
|
});
|
2022-11-11 23:28:21 +08:00
|
|
|
|
undoOperations.push({
|
|
|
|
|
action: "setAttrs",
|
|
|
|
|
id: listId,
|
|
|
|
|
data: JSON.stringify({fold: hasFold ? "1" : "0"})
|
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);
|
|
|
|
|
if (foldStatus === "1") {
|
|
|
|
|
(buttonElement.firstElementChild as HTMLElement).style.transform = "";
|
|
|
|
|
} else if (foldStatus === "0") {
|
|
|
|
|
(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;
|
|
|
|
|
}
|
2022-11-16 22:20:15 +08:00
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
2023-06-01 20:50:49 +08:00
|
|
|
|
zoomOut({protyle, id});
|
2022-11-16 22:20:15 +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 => {
|
|
|
|
|
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") &&
|
2022-10-08 16:12:21 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
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,
|
|
|
|
|
data: JSON.stringify({fold: hasFold ? "0" : "1"})
|
2022-11-12 00:55:13 +08:00
|
|
|
|
});
|
2022-11-11 23:28:21 +08:00
|
|
|
|
undoOperations.push({
|
|
|
|
|
action: "setAttrs",
|
|
|
|
|
id: listId,
|
|
|
|
|
data: JSON.stringify({fold: hasFold ? "1" : "0"})
|
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-08-02 20:55:25 +08:00
|
|
|
|
openAttr(protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`));
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
this.renderMenu(protyle, buttonElement);
|
2023-03-17 11:35:08 +08:00
|
|
|
|
// https://ld246.com/article/1648433751993
|
|
|
|
|
if (!protyle.toolbar.range) {
|
|
|
|
|
protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element.firstElementChild);
|
|
|
|
|
}
|
2023-03-06 11:05:38 +08:00
|
|
|
|
if (isMobile()) {
|
|
|
|
|
window.siyuan.menus.menu.fullscreen();
|
|
|
|
|
} else {
|
|
|
|
|
window.siyuan.menus.menu.popup({x: event.clientX - 16, y: event.clientY - 16}, true);
|
2023-03-17 11:35:08 +08:00
|
|
|
|
focusByRange(protyle.toolbar.range);
|
2023-03-06 11:05:38 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.element.addEventListener("contextmenu", (event: MouseEvent & { target: HTMLInputElement }) => {
|
|
|
|
|
const buttonElement = hasClosestByTag(event.target, "BUTTON");
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (!buttonElement || protyle.disabled || buttonElement.getAttribute("data-type") === "fold") {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!window.siyuan.ctrlIsPressed && !window.siyuan.altIsPressed && !window.siyuan.shiftIsPressed) {
|
|
|
|
|
this.renderMenu(protyle, buttonElement);
|
2022-08-02 11:15:18 +08:00
|
|
|
|
window.siyuan.menus.menu.popup({x: event.clientX - 16, y: event.clientY - 16}, true);
|
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;
|
|
|
|
|
}
|
|
|
|
|
if (buttonElement.getAttribute("data-type") === "fold") {
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl")).forEach(hlItem => {
|
|
|
|
|
hlItem.classList.remove("protyle-wysiwyg--hl");
|
|
|
|
|
});
|
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 => {
|
2022-10-08 16:12:21 +08:00
|
|
|
|
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") && this.isMatchNode(item)) {
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl")).forEach(hlItem => {
|
|
|
|
|
if (!item.isSameNode(hlItem)) {
|
|
|
|
|
hlItem.classList.remove("protyle-wysiwyg--hl");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
item.classList.add("protyle-wysiwyg--hl");
|
|
|
|
|
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 }) => {
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl")).forEach(item => {
|
|
|
|
|
item.classList.remove("protyle-wysiwyg--hl");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 16:12:21 +08:00
|
|
|
|
private isMatchNode(item: Element) {
|
|
|
|
|
const itemRect = item.getBoundingClientRect();
|
|
|
|
|
let gutterTop = this.element.getBoundingClientRect().top + 4;
|
|
|
|
|
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: {
|
|
|
|
|
icon: string,
|
|
|
|
|
label: string,
|
|
|
|
|
protyle: IProtyle,
|
|
|
|
|
nodeElement: Element,
|
|
|
|
|
accelerator?: string
|
|
|
|
|
id: string,
|
|
|
|
|
type: string,
|
|
|
|
|
level?: number
|
|
|
|
|
}) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return {
|
|
|
|
|
icon: options.icon,
|
|
|
|
|
label: options.label,
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator: options.accelerator,
|
|
|
|
|
async click() {
|
|
|
|
|
if (!options.nodeElement.querySelector("wbr")) {
|
|
|
|
|
getContenteditableElement(options.nodeElement)?.insertAdjacentHTML("afterbegin", "<wbr>");
|
|
|
|
|
}
|
|
|
|
|
if (options.type === "CancelList" || options.type === "CancelBlockquote") {
|
|
|
|
|
for await(const item of options.nodeElement.querySelectorAll('[data-type="NodeHeading"][fold="1"]')) {
|
|
|
|
|
const itemId = item.getAttribute("data-node-id");
|
|
|
|
|
item.removeAttribute("fold");
|
|
|
|
|
const response = await fetchSyncPost("/api/transactions", {
|
|
|
|
|
session: options.protyle.id,
|
|
|
|
|
app: Constants.SIYUAN_APPID,
|
|
|
|
|
transactions: [{
|
|
|
|
|
doOperations: [{
|
|
|
|
|
action: "unfoldHeading",
|
|
|
|
|
id: itemId,
|
|
|
|
|
}],
|
|
|
|
|
undoOperations: [{
|
|
|
|
|
action: "foldHeading",
|
|
|
|
|
id: itemId
|
|
|
|
|
}],
|
|
|
|
|
}]
|
|
|
|
|
});
|
|
|
|
|
options.protyle.undo.add([{
|
|
|
|
|
action: "unfoldHeading",
|
|
|
|
|
id: itemId,
|
|
|
|
|
}], [{
|
|
|
|
|
action: "foldHeading",
|
|
|
|
|
id: itemId
|
|
|
|
|
}]);
|
|
|
|
|
item.insertAdjacentHTML("afterend", response.data[0].doOperations[0].retData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const oldHTML = options.nodeElement.outerHTML;
|
|
|
|
|
const previousId = options.nodeElement.previousElementSibling?.getAttribute("data-node-id");
|
|
|
|
|
const parentId = options.nodeElement.parentElement.getAttribute("data-node-id") || options.protyle.block.parentID;
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
const newHTML = options.protyle.lute[options.type](options.nodeElement.outerHTML, options.level);
|
|
|
|
|
options.nodeElement.outerHTML = newHTML;
|
|
|
|
|
if (options.type === "CancelList" || options.type === "CancelBlockquote") {
|
|
|
|
|
const tempElement = document.createElement("template");
|
|
|
|
|
tempElement.innerHTML = newHTML;
|
|
|
|
|
const doOperations: IOperation[] = [{
|
|
|
|
|
action: "delete",
|
|
|
|
|
id: options.id
|
|
|
|
|
}];
|
|
|
|
|
const undoOperations: IOperation[] = [];
|
|
|
|
|
let tempPreviousId = previousId;
|
|
|
|
|
Array.from(tempElement.content.children).forEach((item) => {
|
|
|
|
|
const tempId = item.getAttribute("data-node-id");
|
|
|
|
|
doOperations.push({
|
|
|
|
|
action: "insert",
|
|
|
|
|
data: item.outerHTML,
|
|
|
|
|
id: tempId,
|
|
|
|
|
previousID: tempPreviousId,
|
|
|
|
|
parentID: parentId
|
|
|
|
|
});
|
|
|
|
|
undoOperations.push({
|
|
|
|
|
action: "delete",
|
|
|
|
|
id: tempId
|
|
|
|
|
});
|
|
|
|
|
tempPreviousId = tempId;
|
|
|
|
|
});
|
|
|
|
|
undoOperations.push({
|
|
|
|
|
action: "insert",
|
|
|
|
|
data: oldHTML,
|
|
|
|
|
id: options.id,
|
|
|
|
|
previousID: previousId,
|
|
|
|
|
parentID: parentId
|
|
|
|
|
});
|
|
|
|
|
transaction(options.protyle, doOperations, undoOperations);
|
|
|
|
|
} else {
|
|
|
|
|
updateTransaction(options.protyle, options.id, newHTML, oldHTML);
|
|
|
|
|
}
|
|
|
|
|
focusByWbr(options.protyle.wysiwyg.element, getEditorRange(options.protyle.wysiwyg.element));
|
2022-09-14 23:26:02 +08:00
|
|
|
|
options.protyle.wysiwyg.element.querySelectorAll('[data-type~="block-ref"]').forEach(item => {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
if (item.textContent === "") {
|
|
|
|
|
fetchPost("/api/block/getRefText", {id: item.getAttribute("data-id")}, (response) => {
|
2022-08-31 18:17:43 +08:00
|
|
|
|
item.innerHTML = response.data;
|
2022-08-29 20:57:33 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
blockRender(options.protyle, options.protyle.wysiwyg.element);
|
|
|
|
|
processRender(options.protyle.wysiwyg.element);
|
|
|
|
|
highlightRender(options.protyle.wysiwyg.element);
|
2023-06-07 11:20:21 +08:00
|
|
|
|
avRender(options.protyle.wysiwyg.element);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private turnsIntoOne(options: {
|
|
|
|
|
accelerator?: string,
|
|
|
|
|
icon?: string,
|
|
|
|
|
label: string,
|
|
|
|
|
protyle: IProtyle,
|
|
|
|
|
selectsElement: Element[],
|
|
|
|
|
type: string,
|
|
|
|
|
level?: string
|
|
|
|
|
}) {
|
|
|
|
|
return {
|
|
|
|
|
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: {
|
|
|
|
|
icon?: string,
|
|
|
|
|
label: string,
|
|
|
|
|
protyle: IProtyle,
|
|
|
|
|
selectsElement: Element[],
|
|
|
|
|
type: string,
|
|
|
|
|
level?: number | string,
|
|
|
|
|
isContinue?: boolean
|
2022-08-29 20:57:33 +08:00
|
|
|
|
accelerator?: string
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}) {
|
|
|
|
|
return {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
if (item.classList.contains("bq") || item.classList.contains("sb") || item.classList.contains("p")) {
|
|
|
|
|
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({
|
|
|
|
|
icon: "iconList",
|
|
|
|
|
label: window.siyuan.languages.list,
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "Blocks2ULs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
|
|
|
|
icon: "iconOrderedList",
|
|
|
|
|
label: window.siyuan.languages["ordered-list"],
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "Blocks2OLs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
|
|
|
|
icon: "iconCheck",
|
|
|
|
|
label: window.siyuan.languages.check,
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "Blocks2TLs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
|
|
|
|
icon: "iconQuote",
|
|
|
|
|
label: window.siyuan.languages.quote,
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "Blocks2Blockquote"
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
// 多选引用转换为块的时候 id 不一致
|
|
|
|
|
if (!hasEmbedBlock) {
|
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
|
|
|
|
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({
|
|
|
|
|
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({
|
|
|
|
|
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({
|
|
|
|
|
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({
|
|
|
|
|
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({
|
|
|
|
|
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({
|
|
|
|
|
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({
|
|
|
|
|
icon: "iconRefresh",
|
|
|
|
|
label: window.siyuan.languages.turnInto,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: turnIntoSubmenu
|
|
|
|
|
}).element);
|
|
|
|
|
if (isContinue) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
icon: "iconSuper",
|
|
|
|
|
label: window.siyuan.languages.merge + " " + window.siyuan.languages.superBlock,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: [this.turnsIntoOne({
|
|
|
|
|
label: window.siyuan.languages.hLayout,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.hLayout.custom,
|
|
|
|
|
icon: "iconSplitLR",
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement,
|
|
|
|
|
type: "BlocksMergeSuperBlock",
|
|
|
|
|
level: "col"
|
|
|
|
|
}), this.turnsIntoOne({
|
|
|
|
|
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) {
|
|
|
|
|
AIActions(selectsElement, protyle);
|
|
|
|
|
}
|
2023-02-04 15:40:54 +08:00
|
|
|
|
const copyMenu: IMenu[] = [{
|
2022-05-26 15:18:53 +08:00
|
|
|
|
label: window.siyuan.languages.copy,
|
2023-02-04 15:40:54 +08:00
|
|
|
|
accelerator: "⌘C",
|
|
|
|
|
click() {
|
|
|
|
|
if (isNotEditBlock(selectsElement[0])) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let html = "";
|
|
|
|
|
selectsElement.forEach(item => {
|
2023-02-04 15:40:54 +08:00
|
|
|
|
html += removeEmbed(item);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
2023-02-04 15:40:54 +08:00
|
|
|
|
writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd());
|
|
|
|
|
} else {
|
|
|
|
|
focusByRange(getEditorRange(selectsElement[0]));
|
|
|
|
|
document.execCommand("copy");
|
2022-11-09 14:25:02 +08:00
|
|
|
|
}
|
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 = "";
|
|
|
|
|
selectsElement.forEach(item => {
|
|
|
|
|
item.querySelectorAll("[spellcheck]").forEach(editItem => {
|
|
|
|
|
const cloneNode = editItem.cloneNode(true) as HTMLElement;
|
|
|
|
|
cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
|
|
|
|
|
slashItem.firstElementChild.remove();
|
|
|
|
|
});
|
|
|
|
|
html += cloneNode.textContent + "\n";
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
copyPlainText(html.trimEnd());
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.duplicate,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.duplicate.custom,
|
|
|
|
|
disabled: protyle.disabled,
|
|
|
|
|
click() {
|
|
|
|
|
duplicateBlock(selectsElement, protyle);
|
|
|
|
|
}
|
2023-02-06 21:54:26 +08:00
|
|
|
|
}];
|
|
|
|
|
const copyTextRefMenu = this.genCopyTextRef(selectsElement);
|
2023-02-04 15:40:54 +08:00
|
|
|
|
if (copyTextRefMenu) {
|
|
|
|
|
copyMenu.splice(2, 0, copyTextRefMenu);
|
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
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({
|
|
|
|
|
label: window.siyuan.languages.cut,
|
|
|
|
|
accelerator: "⌘X",
|
|
|
|
|
icon: "iconCut",
|
|
|
|
|
click: () => {
|
|
|
|
|
if (isNotEditBlock(selectsElement[0])) {
|
|
|
|
|
let html = "";
|
|
|
|
|
selectsElement.forEach(item => {
|
|
|
|
|
html += removeEmbed(item);
|
|
|
|
|
});
|
|
|
|
|
writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd());
|
2022-08-31 01:14:45 +08:00
|
|
|
|
protyle.breadcrumb?.hide();
|
2023-06-01 20:50:49 +08:00
|
|
|
|
removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0]));
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
focusByRange(getEditorRange(selectsElement[0]));
|
|
|
|
|
document.execCommand("cut");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
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);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.delete,
|
|
|
|
|
icon: "iconTrashcan",
|
|
|
|
|
accelerator: "⌫",
|
|
|
|
|
click: () => {
|
2022-08-31 01:14:45 +08:00
|
|
|
|
protyle.breadcrumb?.hide();
|
2023-06-01 20:50:49 +08:00
|
|
|
|
removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0]));
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
const appearanceElement = new MenuItem({
|
|
|
|
|
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));
|
|
|
|
|
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");
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.genAlign(selectsElement, protyle);
|
|
|
|
|
this.genWidths(selectsElement, protyle);
|
2022-12-21 23:26:03 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
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
|
|
|
|
icon: "iconRiffCard",
|
|
|
|
|
click() {
|
2023-04-09 23:04:30 +08:00
|
|
|
|
quickMakeCard(protyle, selectsElement);
|
2023-02-19 00:05:38 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2023-03-25 09:31:32 +08:00
|
|
|
|
if (window.siyuan.config.flashcard.deck) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.addToDeck,
|
|
|
|
|
icon: "iconRiffCard",
|
|
|
|
|
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);
|
2022-05-26 15:18:53 +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 => {
|
2022-10-03 12:35:11 +08:00
|
|
|
|
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") &&
|
2022-10-08 16:12:21 +08:00
|
|
|
|
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({
|
|
|
|
|
icon: "iconList",
|
|
|
|
|
label: window.siyuan.languages.list,
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2ULs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
|
|
|
|
icon: "iconOrderedList",
|
|
|
|
|
label: window.siyuan.languages["ordered-list"],
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2OLs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
|
|
|
|
icon: "iconCheck",
|
|
|
|
|
label: window.siyuan.languages.check,
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2TLs"
|
|
|
|
|
}));
|
|
|
|
|
turnIntoSubmenu.push(this.turnsIntoOne({
|
|
|
|
|
icon: "iconQuote",
|
|
|
|
|
label: window.siyuan.languages.quote,
|
|
|
|
|
protyle,
|
|
|
|
|
selectsElement: [nodeElement],
|
|
|
|
|
type: "Blocks2Blockquote"
|
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
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({
|
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({
|
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({
|
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({
|
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({
|
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({
|
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],
|
|
|
|
|
level: 6,
|
|
|
|
|
type: "Blocks2Ps",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}));
|
|
|
|
|
if (subType !== "h1") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsInto({
|
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({
|
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({
|
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({
|
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({
|
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({
|
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({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconParagraph",
|
|
|
|
|
label: window.siyuan.languages.paragraph,
|
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
id,
|
|
|
|
|
type: "CancelList"
|
|
|
|
|
}));
|
|
|
|
|
if (nodeElement.getAttribute("data-subtype") === "o") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconList",
|
|
|
|
|
label: window.siyuan.languages.list,
|
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
id,
|
|
|
|
|
type: "OL2UL"
|
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconCheck",
|
|
|
|
|
label: window.siyuan.languages.check,
|
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
id,
|
|
|
|
|
type: "UL2TL"
|
|
|
|
|
}));
|
|
|
|
|
} else if (nodeElement.getAttribute("data-subtype") === "t") {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconList",
|
|
|
|
|
label: window.siyuan.languages.list,
|
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
id,
|
|
|
|
|
type: "TL2UL"
|
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconOrderedList",
|
|
|
|
|
label: window.siyuan.languages["ordered-list"],
|
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
id,
|
|
|
|
|
type: "TL2OL"
|
|
|
|
|
}));
|
|
|
|
|
} else {
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconOrderedList",
|
|
|
|
|
label: window.siyuan.languages["ordered-list"],
|
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
id,
|
|
|
|
|
type: "UL2OL"
|
|
|
|
|
}));
|
2022-08-29 20:57:33 +08:00
|
|
|
|
turnIntoSubmenu.push(this.turnsOneInto({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconCheck",
|
|
|
|
|
label: window.siyuan.languages.check,
|
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
id,
|
|
|
|
|
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({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconParagraph",
|
|
|
|
|
label: window.siyuan.languages.paragraph,
|
|
|
|
|
protyle,
|
|
|
|
|
nodeElement,
|
|
|
|
|
id,
|
|
|
|
|
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({
|
|
|
|
|
icon: "iconRefresh",
|
|
|
|
|
label: window.siyuan.languages.turnInto,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: turnIntoSubmenu
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2023-05-19 09:21:59 +08:00
|
|
|
|
if (!protyle.disabled) {
|
|
|
|
|
AIActions([nodeElement], protyle);
|
|
|
|
|
}
|
2023-02-04 15:40:54 +08:00
|
|
|
|
const copyMenu = (copySubMenu(id, true, nodeElement) as IMenu[]).concat([{
|
|
|
|
|
label: window.siyuan.languages.copy,
|
|
|
|
|
accelerator: "⌘C",
|
|
|
|
|
click() {
|
|
|
|
|
if (isNotEditBlock(nodeElement)) {
|
|
|
|
|
writeText(protyle.lute.BlockDOM2StdMd(removeEmbed(nodeElement)).trimEnd());
|
|
|
|
|
} else {
|
|
|
|
|
focusByRange(getEditorRange(nodeElement));
|
|
|
|
|
document.execCommand("copy");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.copyPlainText,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.copyPlainText.custom,
|
|
|
|
|
click() {
|
|
|
|
|
let text = "";
|
|
|
|
|
nodeElement.querySelectorAll("[spellcheck]").forEach(item => {
|
|
|
|
|
const cloneNode = item.cloneNode(true) as HTMLElement;
|
|
|
|
|
cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
|
|
|
|
|
slashItem.firstElementChild.remove();
|
|
|
|
|
});
|
|
|
|
|
text += cloneNode.textContent + "\n";
|
|
|
|
|
});
|
|
|
|
|
copyPlainText(text.trimEnd());
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.duplicate,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.duplicate.custom,
|
|
|
|
|
disabled: protyle.disabled,
|
|
|
|
|
click() {
|
|
|
|
|
duplicateBlock([nodeElement], protyle);
|
|
|
|
|
}
|
2023-02-06 21:54:26 +08:00
|
|
|
|
}]);
|
|
|
|
|
const copyTextRefMenu = this.genCopyTextRef([nodeElement]);
|
2023-02-04 15:40:54 +08:00
|
|
|
|
if (copyTextRefMenu) {
|
|
|
|
|
copyMenu.splice(copyMenu.length - 1, 0, copyTextRefMenu);
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.copy,
|
|
|
|
|
icon: "iconCopy",
|
|
|
|
|
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({
|
|
|
|
|
label: window.siyuan.languages.cut,
|
|
|
|
|
accelerator: "⌘X",
|
|
|
|
|
icon: "iconCut",
|
|
|
|
|
click: () => {
|
|
|
|
|
if (isNotEditBlock(nodeElement)) {
|
|
|
|
|
writeText(protyle.lute.BlockDOM2StdMd(removeEmbed(nodeElement)).trimEnd());
|
2023-06-01 20:50:49 +08:00
|
|
|
|
removeBlock(protyle, nodeElement, getEditorRange(nodeElement));
|
2022-08-31 01:14:45 +08:00
|
|
|
|
protyle.breadcrumb?.hide();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
focusByRange(getEditorRange(nodeElement));
|
|
|
|
|
document.execCommand("cut");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
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], [nodeElement], protyle);
|
2022-11-25 23:06:03 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.delete,
|
|
|
|
|
icon: "iconTrashcan",
|
|
|
|
|
accelerator: "⌫",
|
|
|
|
|
click: () => {
|
2022-08-31 01:14:45 +08:00
|
|
|
|
protyle.breadcrumb?.hide();
|
2023-06-01 20:50:49 +08:00
|
|
|
|
removeBlock(protyle, nodeElement, getEditorRange(nodeElement));
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2022-10-25 00:23:42 +08:00
|
|
|
|
if (type === "NodeSuperBlock" && !protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.cancel + " " + window.siyuan.languages.superBlock,
|
|
|
|
|
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);
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if (type === "NodeCodeBlock" && !protyle.disabled && !nodeElement.getAttribute("data-subtype")) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
const linewrap = nodeElement.getAttribute("linewrap");
|
|
|
|
|
const ligatures = nodeElement.getAttribute("ligatures");
|
|
|
|
|
const linenumber = nodeElement.getAttribute("linenumber");
|
|
|
|
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconCode",
|
|
|
|
|
label: window.siyuan.languages.code,
|
|
|
|
|
submenu: [{
|
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();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
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();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
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"))) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
const height = (nodeElement as HTMLElement).style.height;
|
|
|
|
|
let html = nodeElement.outerHTML;
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.chart,
|
|
|
|
|
icon: "iconCode",
|
|
|
|
|
submenu: [{
|
|
|
|
|
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();
|
2022-07-19 00:48:53 +08:00
|
|
|
|
const chartInstance = echarts.getInstanceById(nodeElement.firstElementChild.nextElementSibling.getAttribute("_echarts_instance_"));
|
|
|
|
|
if (chartInstance) {
|
|
|
|
|
chartInstance.resize();
|
|
|
|
|
}
|
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) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconTable",
|
|
|
|
|
label: window.siyuan.languages.table,
|
|
|
|
|
submenu: tableMenu(protyle, nodeElement, cellElement as HTMLTableCellElement, range) as IMenu[]
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2022-10-25 00:23:42 +08:00
|
|
|
|
} else if ((type === "NodeVideo" || type === "NodeAudio") && !protyle.disabled) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
id: "assetSubMenu",
|
|
|
|
|
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) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
id: "assetSubMenu",
|
|
|
|
|
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) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
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) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({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({
|
|
|
|
|
id: "assetSubMenu",
|
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconSQL",
|
|
|
|
|
label: window.siyuan.languages.blockEmbed,
|
|
|
|
|
submenu: [{
|
|
|
|
|
icon: "iconRefresh",
|
|
|
|
|
label: `${window.siyuan.languages.refresh} SQL`,
|
|
|
|
|
click() {
|
|
|
|
|
nodeElement.removeAttribute("data-render");
|
|
|
|
|
blockRender(protyle, nodeElement);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
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
|
|
|
|
}, {
|
|
|
|
|
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
|
|
|
|
}, {
|
|
|
|
|
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) {
|
2022-09-27 23:36:07 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
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({
|
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconRefresh",
|
|
|
|
|
label: window.siyuan.languages.tWithSubtitle,
|
|
|
|
|
submenu: headingSubMenu
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
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) => {
|
2022-09-27 23:36:07 +08:00
|
|
|
|
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({
|
|
|
|
|
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) => {
|
|
|
|
|
writeText(response.data + Constants.ZWSP);
|
|
|
|
|
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({
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
2022-10-26 23:23:24 +08:00
|
|
|
|
if (!protyle.options.backlinkData) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
accelerator: `${updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom)}/${updateHotkeyTip("⌘Click")}`,
|
|
|
|
|
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({
|
|
|
|
|
accelerator: window.siyuan.config.keymap.general.enterBack.custom,
|
|
|
|
|
label: window.siyuan.languages.enterBack,
|
2023-05-18 19:27:21 +08:00
|
|
|
|
click: () => {
|
2022-10-26 23:23:24 +08:00
|
|
|
|
if (!protyle.block.showAll) {
|
|
|
|
|
const ids = protyle.path.split("/");
|
|
|
|
|
if (ids.length > 2) {
|
|
|
|
|
/// #if MOBILE
|
2023-06-01 20:50:49 +08:00
|
|
|
|
openMobileFileById(protyle.app, ids[ids.length - 2], [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]);
|
2022-10-26 23:23:24 +08:00
|
|
|
|
/// #else
|
|
|
|
|
openFileById({
|
2023-06-01 20:50:49 +08:00
|
|
|
|
app: protyle.app,
|
2022-10-26 23:23:24 +08:00
|
|
|
|
id: ids[ids.length - 2],
|
|
|
|
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
|
|
|
|
});
|
|
|
|
|
/// #endif
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2023-06-11 10:22:05 +08:00
|
|
|
|
zoomOut({protyle, id: protyle.block.parent2ID, focusId: id});
|
2022-09-02 20:42:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-26 23:23:24 +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({
|
|
|
|
|
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({
|
|
|
|
|
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({
|
|
|
|
|
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);
|
2022-10-13 21:34:43 +08:00
|
|
|
|
jumpToParentNext(protyle, nodeElement);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
|
|
|
|
|
if (type !== "NodeThematicBreak") {
|
2022-07-28 10:27:51 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
2022-10-13 21:34:43 +08:00
|
|
|
|
label: window.siyuan.languages.fold,
|
|
|
|
|
accelerator: `${updateHotkeyTip(window.siyuan.config.keymap.editor.general.collapse.custom)}/${updateHotkeyTip("⌥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({
|
|
|
|
|
label: window.siyuan.languages.attr,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"),
|
|
|
|
|
click() {
|
2023-08-02 20:55:25 +08:00
|
|
|
|
openAttr(nodeElement);
|
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({
|
|
|
|
|
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]));
|
|
|
|
|
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");
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.genAlign([nodeElement], protyle);
|
|
|
|
|
this.genWidths([nodeElement], protyle);
|
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
if (!["NodeThematicBreak", "NodeBlockQueryEmbed", "NodeIFrame", "NodeHTMLBlock", "NodeWidget", "NodeVideo", "NodeAudio"].includes(type) &&
|
|
|
|
|
getContenteditableElement(nodeElement)?.textContent.trim() !== "" &&
|
|
|
|
|
(type !== "NodeCodeBlock" || (type === "NodeCodeBlock" && !nodeElement.getAttribute("data-subtype")))) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.wechatReminder,
|
|
|
|
|
icon: "iconMp",
|
|
|
|
|
click() {
|
|
|
|
|
openWechatNotify(nodeElement);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2022-12-26 11:05:46 +08:00
|
|
|
|
if (type !== "NodeThematicBreak") {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
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
|
|
|
|
icon: "iconRiffCard",
|
|
|
|
|
click() {
|
2023-04-09 23:04:30 +08:00
|
|
|
|
quickMakeCard(protyle, [nodeElement]);
|
2023-02-19 00:05:38 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
2023-03-25 09:31:32 +08:00
|
|
|
|
if (window.siyuan.config.flashcard.deck) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.addToDeck,
|
|
|
|
|
icon: "iconRiffCard",
|
|
|
|
|
click() {
|
2023-06-01 20:50:49 +08:00
|
|
|
|
makeCard(protyle.app, [nodeElement.getAttribute("data-node-id")]);
|
2023-03-25 09:31:32 +08:00
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
2022-12-26 11:05:46 +08:00
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
}
|
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({
|
2023-02-04 15:40:54 +08:00
|
|
|
|
iconHTML: Constants.ZWSP,
|
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 {
|
|
|
|
|
icon: "iconHeading" + level,
|
|
|
|
|
label: window.siyuan.languages["heading" + level],
|
|
|
|
|
click() {
|
|
|
|
|
fetchPost("/api/block/getHeadingLevelTransaction", {
|
|
|
|
|
id,
|
|
|
|
|
level
|
|
|
|
|
}, (response) => {
|
|
|
|
|
response.data.doOperations.forEach((operation: IOperation) => {
|
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {
|
|
|
|
|
itemElement.outerHTML = operation.data;
|
|
|
|
|
});
|
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {
|
|
|
|
|
mathRender(itemElement);
|
|
|
|
|
});
|
|
|
|
|
});
|
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({
|
|
|
|
|
label: window.siyuan.languages.layout,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu: [{
|
|
|
|
|
label: window.siyuan.languages.alignLeft,
|
|
|
|
|
icon: "iconAlignLeft",
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.alignLeft.custom,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.textAlign = "left";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.alignCenter,
|
|
|
|
|
icon: "iconAlignCenter",
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.alignCenter.custom,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.textAlign = "center";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.alignRight,
|
|
|
|
|
icon: "iconAlignRight",
|
|
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.alignRight.custom,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.textAlign = "right";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.justify,
|
|
|
|
|
icon: "iconMenu",
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.textAlign = "justify";
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-11-01 10:51:06 +08:00
|
|
|
|
}, {
|
|
|
|
|
type: "separator"
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.ltr,
|
2022-12-07 14:49:24 +08:00
|
|
|
|
icon: "iconLtr",
|
2022-11-01 10:51:06 +08:00
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.direction = "ltr";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.rtl,
|
|
|
|
|
icon: "iconRtl",
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.direction = "rtl";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
type: "separator"
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.clearFontStyle,
|
|
|
|
|
icon: "iconTrashcan",
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.textAlign = "";
|
|
|
|
|
e.style.direction = "";
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}]
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private genWidths(nodeElements: Element[], protyle: IProtyle) {
|
|
|
|
|
const styles: IMenu[] = [];
|
|
|
|
|
["25%", "33%", "50%", "67%", "75%"].forEach((item) => {
|
|
|
|
|
styles.push({
|
|
|
|
|
label: item,
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
e.style.width = item;
|
|
|
|
|
e.style.flex = "none";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
styles.push({
|
|
|
|
|
type: "separator"
|
|
|
|
|
});
|
|
|
|
|
let width = 100;
|
|
|
|
|
if (nodeElements.length === 1) {
|
|
|
|
|
const widthStyle = (nodeElements[0] as HTMLElement).style.width;
|
|
|
|
|
if (widthStyle.endsWith("%")) {
|
|
|
|
|
width = parseInt(widthStyle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.width,
|
|
|
|
|
submenu: styles.concat([{
|
2023-03-06 11:05:38 +08:00
|
|
|
|
label: `<div aria-label="${width}%" 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>`,
|
|
|
|
|
bind(element) {
|
|
|
|
|
const rangeElement = element.querySelector("input");
|
|
|
|
|
rangeElement.addEventListener("input", () => {
|
|
|
|
|
nodeElements.forEach((e) => {
|
|
|
|
|
(e as HTMLElement).style.width = rangeElement.value + "%";
|
|
|
|
|
(e as HTMLElement).style.flex = "none";
|
|
|
|
|
});
|
|
|
|
|
rangeElement.parentElement.setAttribute("aria-label", `${rangeElement.value}%`);
|
|
|
|
|
});
|
|
|
|
|
const undoOperations: IOperation[] = [];
|
|
|
|
|
const operations: IOperation[] = [];
|
|
|
|
|
nodeElements.forEach((e) => {
|
|
|
|
|
undoOperations.push({
|
|
|
|
|
action: "update",
|
|
|
|
|
id: e.getAttribute("data-node-id"),
|
|
|
|
|
data: e.outerHTML
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
rangeElement.addEventListener("change", () => {
|
|
|
|
|
nodeElements.forEach((e) => {
|
|
|
|
|
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]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
type: "separator"
|
|
|
|
|
}, {
|
|
|
|
|
label: window.siyuan.languages.clearFontStyle,
|
|
|
|
|
icon: "iconTrashcan",
|
|
|
|
|
click: () => {
|
|
|
|
|
this.genClick(nodeElements, protyle, (e: HTMLElement) => {
|
|
|
|
|
if (e.style.width) {
|
|
|
|
|
e.style.width = "";
|
|
|
|
|
e.style.flex = "";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}]),
|
|
|
|
|
}).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 {
|
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
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 10:51:06 +08:00
|
|
|
|
public render(protyle: IProtyle, element: Element, wysiwyg: HTMLElement) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/4659
|
|
|
|
|
const titleElement = wysiwyg.parentElement.querySelector(".protyle-title__input");
|
|
|
|
|
if (titleElement && titleElement.getAttribute("data-render") !== "true") {
|
|
|
|
|
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");
|
|
|
|
|
const embedElement = hasClosestByAttribute(nodeElement.parentElement, "data-type", "NodeBlockQueryEmbed");
|
|
|
|
|
if (!embedElement) {
|
|
|
|
|
let type;
|
|
|
|
|
if (isShow) {
|
|
|
|
|
type = nodeElement.getAttribute("data-type");
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
if (hasClosestByAttribute(listItem, "data-type", "NodeBlockQueryEmbed")) {
|
|
|
|
|
listItem = undefined;
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
// 标题必须显示
|
|
|
|
|
if (!topElement.isSameNode(nodeElement) && type !== "NodeHeading") {
|
|
|
|
|
nodeElement = topElement;
|
|
|
|
|
type = nodeElement.getAttribute("data-type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (type === "NodeListItem" && index === 1 && !isShow) {
|
|
|
|
|
// 列表项中第一层不显示
|
|
|
|
|
html = "";
|
|
|
|
|
}
|
|
|
|
|
index += 1;
|
|
|
|
|
if (isShow) {
|
2022-10-25 00:23:42 +08:00
|
|
|
|
html = `<button ${protyle.disabled ? "" : 'draggable="true"'} data-type="${type}" data-subtype="${nodeElement.getAttribute("data-subtype")}" data-node-id="${nodeElement.getAttribute("data-node-id")}"><svg><use xlink:href="#${getIconByType(type, nodeElement.getAttribute("data-subtype"))}"></use></svg></button>` + html;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
let foldHTML = "";
|
|
|
|
|
if (type === "NodeListItem" && nodeElement.childElementCount > 3 || type === "NodeHeading") {
|
|
|
|
|
const fold = nodeElement.getAttribute("fold");
|
|
|
|
|
foldHTML = `<button data-type="fold"><svg style="width:10px${fold && fold === "1" ? "" : ";transform:rotate(90deg)"}"><use xlink:href="#iconPlay"></use></svg></button>`;
|
|
|
|
|
}
|
|
|
|
|
if (type === "NodeListItem" || type === "NodeList") {
|
|
|
|
|
listItem = nodeElement;
|
|
|
|
|
if (type === "NodeListItem" && nodeElement.childElementCount > 3) {
|
2022-10-25 00:23:42 +08:00
|
|
|
|
html = `<button ${protyle.disabled ? "" : 'draggable="true"'} data-type="${type}" data-subtype="${nodeElement.getAttribute("data-subtype")}" data-node-id="${nodeElement.getAttribute("data-node-id")}"><svg><use xlink:href="#${getIconByType(type, nodeElement.getAttribute("data-subtype"))}"></use></svg></button>${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 {
|
|
|
|
|
buttonsElement.forEach(item => {
|
|
|
|
|
const id = item.getAttribute("data-node-id");
|
|
|
|
|
if (id && html.indexOf(id) === -1) {
|
|
|
|
|
match = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// 防止抖动 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 = "";
|
|
|
|
|
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;
|
|
|
|
|
} else 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;
|
|
|
|
|
}
|
2022-08-14 13:15:32 +08:00
|
|
|
|
this.element.style.top = `${Math.max(rect.top, wysiwyg.parentElement.getBoundingClientRect().top) + marginHeight}px`;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let left = rect.left - this.element.clientWidth - space;
|
|
|
|
|
if (nodeElement.getAttribute("data-type") === "NodeBlockQueryEmbed" && this.element.childElementCount === 1) {
|
|
|
|
|
// 嵌入块为列表时
|
|
|
|
|
left = nodeElement.getBoundingClientRect().left - this.element.clientWidth - space;
|
2023-06-11 10:22:05 +08:00
|
|
|
|
} else if (nodeElement.getAttribute("data-type") === "NodeAttributeView") {
|
|
|
|
|
left = left + (parseInt((nodeElement.firstElementChild.firstElementChild as HTMLElement)?.style.paddingLeft) || 0);
|
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 = "";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|