mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-09 00:34:20 +01:00
This commit is contained in:
parent
c533dd49a8
commit
9084fe20b0
4 changed files with 97 additions and 59 deletions
|
|
@ -6,6 +6,50 @@ import {transaction, updateTransaction} from "../protyle/wysiwyg/transaction";
|
|||
import {scrollCenter} from "../util/highlightById";
|
||||
import {Constants} from "../constants";
|
||||
|
||||
export const cancelSB = (protyle: IProtyle, nodeElement: Element) => {
|
||||
const doOperations: IOperation[] = [];
|
||||
const undoOperations: IOperation[] = [];
|
||||
let previousId = nodeElement.previousElementSibling ? nodeElement.previousElementSibling.getAttribute("data-node-id") : undefined;
|
||||
nodeElement.classList.remove("protyle-wysiwyg--select");
|
||||
const id = nodeElement.getAttribute("data-node-id")
|
||||
const sbElement = genSBElement(nodeElement.getAttribute("data-sb-layout"), id, nodeElement.lastElementChild.outerHTML);
|
||||
undoOperations.push({
|
||||
action: "insert",
|
||||
id,
|
||||
data: sbElement.outerHTML,
|
||||
previousID: nodeElement.previousElementSibling ? nodeElement.previousElementSibling.getAttribute("data-node-id") : undefined,
|
||||
parentID: nodeElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID
|
||||
});
|
||||
Array.from(nodeElement.children).forEach((item, index) => {
|
||||
if (index === nodeElement.childElementCount - 1) {
|
||||
doOperations.push({
|
||||
action: "delete",
|
||||
id,
|
||||
});
|
||||
nodeElement.lastElementChild.remove();
|
||||
nodeElement.outerHTML = nodeElement.innerHTML;
|
||||
return;
|
||||
}
|
||||
doOperations.push({
|
||||
action: "move",
|
||||
id: item.getAttribute("data-node-id"),
|
||||
previousID: previousId,
|
||||
parentID: nodeElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID
|
||||
});
|
||||
undoOperations.push({
|
||||
action: "move",
|
||||
id: item.getAttribute("data-node-id"),
|
||||
previousID: item.previousElementSibling ? item.previousElementSibling.getAttribute("data-node-id") : undefined,
|
||||
parentID: id
|
||||
});
|
||||
previousId = item.getAttribute("data-node-id");
|
||||
});
|
||||
|
||||
return {
|
||||
doOperations, undoOperations, previousId
|
||||
}
|
||||
}
|
||||
|
||||
export const genSBElement = (layout: string, id?: string, attrHTML?: string) => {
|
||||
const sbElement = document.createElement("div");
|
||||
sbElement.setAttribute("data-node-id", id || Lute.NewNodeID());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue