mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-02 10:50:15 +01:00
This commit is contained in:
parent
bb1314c66f
commit
bd264d7104
6 changed files with 179 additions and 123 deletions
|
|
@ -14,20 +14,19 @@ import {copyPlainText, isMac, isOnlyMeta, openByMobile, updateHotkeyTip, writeTe
|
|||
import {
|
||||
transaction,
|
||||
turnsIntoOneTransaction,
|
||||
turnsIntoTransaction,
|
||||
turnsIntoTransaction, turnsOneInto,
|
||||
updateBatchTransaction,
|
||||
updateTransaction
|
||||
} from "../wysiwyg/transaction";
|
||||
import {removeBlock} from "../wysiwyg/remove";
|
||||
import {focusBlock, focusByRange, focusByWbr, getEditorRange} from "../util/selection";
|
||||
import {focusBlock, focusByRange, getEditorRange} from "../util/selection";
|
||||
import {hideElements} from "../ui/hideElements";
|
||||
import {processRender} from "../util/processCode";
|
||||
import {highlightRender} from "../render/highlightRender";
|
||||
import {blockRender} from "../render/blockRender";
|
||||
import {removeEmbed} from "../wysiwyg/removeEmbed";
|
||||
import {getContenteditableElement, getTopAloneElement, isNotEditBlock} from "../wysiwyg/getBlock";
|
||||
import * as dayjs from "dayjs";
|
||||
import {fetchPost, fetchSyncPost} from "../../util/fetch";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {
|
||||
cancelSB,
|
||||
genEmptyElement,
|
||||
|
|
@ -449,91 +448,8 @@ export class Gutter {
|
|||
icon: options.icon,
|
||||
label: options.label,
|
||||
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
|
||||
}], options.protyle);
|
||||
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));
|
||||
options.protyle.wysiwyg.element.querySelectorAll('[data-type~="block-ref"]').forEach(item => {
|
||||
if (item.textContent === "") {
|
||||
fetchPost("/api/block/getRefText", {id: item.getAttribute("data-id")}, (response) => {
|
||||
item.innerHTML = response.data;
|
||||
});
|
||||
}
|
||||
});
|
||||
blockRender(options.protyle, options.protyle.wysiwyg.element);
|
||||
processRender(options.protyle.wysiwyg.element);
|
||||
highlightRender(options.protyle.wysiwyg.element);
|
||||
avRender(options.protyle.wysiwyg.element, options.protyle);
|
||||
click() {
|
||||
turnsOneInto(options);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue