|
@@ -890,6 +890,7 @@ export const turnsIntoTransaction = (options: {
|
|
|
let html = "";
|
|
|
const doOperations: IOperation[] = [];
|
|
|
const undoOperations: IOperation[] = [];
|
|
|
+ const tempElement = document.createElement("div");
|
|
|
selectsElement.forEach((item, index) => {
|
|
|
if ((options.type === "Blocks2Ps" || options.type === "Blocks2Hs") &&
|
|
|
item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") {
|
|
@@ -903,7 +904,9 @@ export const turnsIntoTransaction = (options: {
|
|
|
undoOperations.push({
|
|
|
action: "update",
|
|
|
id,
|
|
|
- data: item.outerHTML
|
|
|
+ data: item.outerHTML,
|
|
|
+ parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
|
|
|
+ previousID: undoOperations[undoOperations.length - 1]?.id || item.previousElementSibling?.getAttribute("data-node-id")
|
|
|
});
|
|
|
|
|
|
if (!options.isContinue) {
|
|
@@ -911,7 +914,6 @@ export const turnsIntoTransaction = (options: {
|
|
|
item.outerHTML = options.protyle.lute[options.type](item.outerHTML, options.level);
|
|
|
} else {
|
|
|
if (index === selectsElement.length - 1) {
|
|
|
- const tempElement = document.createElement("div");
|
|
|
// @ts-ignore
|
|
|
tempElement.innerHTML = options.protyle.lute[options.type](html, options.level);
|
|
|
item.outerHTML = tempElement.innerHTML;
|
|
@@ -922,12 +924,43 @@ export const turnsIntoTransaction = (options: {
|
|
|
});
|
|
|
undoOperations.forEach(item => {
|
|
|
const nodeElement = options.protyle.wysiwyg.element.querySelector(`[data-node-id="${item.id}"]`);
|
|
|
- doOperations.push({
|
|
|
- action: "update",
|
|
|
- id: item.id,
|
|
|
- data: nodeElement.outerHTML
|
|
|
- });
|
|
|
+ if (!nodeElement) {
|
|
|
+ item.action = "insert";
|
|
|
+ doOperations.push({
|
|
|
+ action: "delete",
|
|
|
+ id: item.id,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ doOperations.push({
|
|
|
+ action: "update",
|
|
|
+ id: item.id,
|
|
|
+ data: nodeElement.outerHTML
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
+ Array.from(tempElement.children).forEach(item => {
|
|
|
+ const itemId = item.getAttribute("data-node-id");
|
|
|
+ let find = false;
|
|
|
+ undoOperations.find(undoItem => {
|
|
|
+ if (itemId === undoItem.id) {
|
|
|
+ find = true
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (!find) {
|
|
|
+ doOperations.push({
|
|
|
+ action: "insert",
|
|
|
+ id: itemId,
|
|
|
+ previousID: item.previousElementSibling?.getAttribute("data-node-id") || undoOperations[0].previousID,
|
|
|
+ data: item.outerHTML,
|
|
|
+ parentID: item.parentElement?.getAttribute("data-node-id") || options.protyle.block.parentID || options.protyle.block.rootID,
|
|
|
+ });
|
|
|
+ undoOperations.splice(0, 0, {
|
|
|
+ action: "delete",
|
|
|
+ id: itemId,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
transaction(options.protyle, doOperations, undoOperations);
|
|
|
processRender(options.protyle.wysiwyg.element);
|
|
|
highlightRender(options.protyle.wysiwyg.element);
|