An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/17800
Vanessaed1f5a5e1463
diff --git a/app/src/block/util.ts b/app/src/block/util.tsindex 34157b0b69..e2f08d294a 100644--- a/app/src/block/util.ts+++ b/app/src/block/util.ts@@ -162,7 +162,7 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, idif (blockElement.getAttribute("data-type") === "NodeListItem" && blockElement.getAttribute("data-subtype") === "o" &&!newElement.parentElement.classList.contains("protyle-wysiwyg")) {updateListOrder(newElement.parentElement, orderIndex);- updateTransaction(protyle, newElement.parentElement.getAttribute("data-node-id"), newElement.parentElement.outerHTML, parentOldHTML);+ updateTransaction(protyle, newElement.parentElement, parentOldHTML);} else {let doOperations: IOperation[];if (position === "beforebegin") {diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.tsindex f2ec93811d..bc30c28c95 100644--- a/app/src/menus/protyle.ts+++ b/app/src/menus/protyle.ts@@ -270,7 +270,7 @@ export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElementclick() {nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));removeInlineType(refElement, "file-annotation-ref", protyle.toolbar.range);- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);oldHTML = nodeElement.outerHTML;}}, {@@ -281,7 +281,7 @@ export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElementrefElement.insertAdjacentHTML("beforebegin", refElement.innerHTML + " ");refElement.textContent = "*";nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);oldHTML = nodeElement.outerHTML;}}]@@ -294,7 +294,7 @@ export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElementrefElement.insertAdjacentHTML("afterend", "<wbr>");refElement.remove();nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, protyle.toolbar.range);oldHTML = nodeElement.outerHTML;}@@ -327,7 +327,7 @@ export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElementwindow.siyuan.menus.menu.removeCB = () => {if (nodeElement.outerHTML !== oldHTML) {nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);}const currentRange = getSelection().rangeCount === 0 ? undefined : getSelection().getRangeAt(0);@@ -340,7 +340,7 @@ export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElement};export const refMenu = (protyle: IProtyle, element: HTMLElement) => {- const nodeElement = hasClosestBlock(element);+ let nodeElement = hasClosestBlock(element) as HTMLElement;if (!nodeElement) {return;}@@ -513,7 +513,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {fetchPost("/api/block/getRefText", {id: refBlockId}, (response) => {element.innerHTML = response.data;nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);oldHTML = nodeElement.outerHTML;});focusByRange(protyle.toolbar.range);@@ -527,7 +527,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {click() {element.setAttribute("data-subtype", "s");nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByRange(protyle.toolbar.range);oldHTML = nodeElement.outerHTML;}@@ -540,7 +540,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {click() {nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));removeInlineType(element, "block-ref", protyle.toolbar.range);- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);oldHTML = nodeElement.outerHTML;}}, {@@ -551,7 +551,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {element.setAttribute("data-subtype", "s");element.textContent = "*";nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByRange(protyle.toolbar.range);oldHTML = nodeElement.outerHTML;}@@ -564,7 +564,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {element.setAttribute("data-subtype", "s");element.textContent = "*";nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByRange(protyle.toolbar.range);oldHTML = nodeElement.outerHTML;}@@ -575,7 +575,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {click() {element.outerHTML = `<span data-type="a" data-href="siyuan://blocks/${element.getAttribute("data-id")}">${element.innerHTML}</span><wbr>`;nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, protyle.toolbar.range);oldHTML = nodeElement.outerHTML;}@@ -586,9 +586,10 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {iconHTML: "",label: window.siyuan.languages.blockEmbed,click() {- const html = `<div data-content="select * from blocks where id='${refBlockId}'" data-node-id="${id}" data-type="NodeBlockQueryEmbed" class="render-node" updated="${dayjs().format("YYYYMMDDHHmmss")}">${nodeElement.querySelector(".protyle-attr").outerHTML}</div>`;- nodeElement.outerHTML = html;- updateTransaction(protyle, id, html, oldHTML);+ nodeElement.insertAdjacentHTML("afterend", `<div data-content="select * from blocks where id='${refBlockId}'" data-node-id="${id}" data-type="NodeBlockQueryEmbed" class="render-node" updated="${dayjs().format("YYYYMMDDHHmmss")}">${nodeElement.querySelector(".protyle-attr").outerHTML}</div>`);+ nodeElement = nodeElement.nextElementSibling as HTMLElement;+ nodeElement.previousElementSibling.remove();+ updateTransaction(protyle, nodeElement, oldHTML);blockRender(protyle, protyle.wysiwyg.element);oldHTML = nodeElement.outerHTML;}@@ -644,7 +645,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {element.insertAdjacentHTML("afterend", "<wbr>");element.remove();nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, protyle.toolbar.range);oldHTML = nodeElement.outerHTML;}@@ -657,7 +658,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {element.insertAdjacentHTML("afterend", "<wbr>");element.remove();nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, protyle.toolbar.range);oldHTML = nodeElement.outerHTML;}@@ -693,7 +694,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {window.siyuan.menus.menu.removeCB = () => {if (nodeElement.outerHTML !== oldHTML) {nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);}const currentRange = getSelection().rangeCount === 0 ? undefined : getSelection().getRangeAt(0);if (currentRange && !protyle.element.contains(currentRange.startContainer)) {@@ -760,7 +761,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {currentRange.extractContents();focusByWbr(nodeElement, currentRange);focusByRange(currentRange);- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);}}).element);} else {@@ -796,7 +797,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {inlineElement.insertAdjacentHTML("afterend", "<wbr>");inlineElement.remove();nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, protyle.toolbar.range);}}).element);@@ -808,7 +809,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {inlineElement.insertAdjacentHTML("afterend", "<wbr>");inlineElement.remove();nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, protyle.toolbar.range);}}).element);@@ -1194,7 +1195,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLElemewriteText(content);(assetElement as HTMLElement).outerHTML = "<wbr>";nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByWbr(protyle.wysiwyg.element, range);}}).element);@@ -1206,7 +1207,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLElemeclick: function () {(assetElement as HTMLElement).outerHTML = "<wbr>";nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByWbr(protyle.wysiwyg.element, range);}}).element);@@ -1296,7 +1297,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLElemereturn;}nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);window.siyuan.menus.menu.remove();focusBlock(nodeElement);});@@ -1325,7 +1326,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme});rangeElement.addEventListener("change", () => {nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);window.siyuan.menus.menu.remove();focusBlock(nodeElement);});@@ -1361,7 +1362,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLElemereturn;}nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);window.siyuan.menus.menu.remove();focusBlock(nodeElement);});@@ -1390,7 +1391,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme});rangeHeightElement.addEventListener("change", () => {nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);window.siyuan.menus.menu.remove();focusBlock(nodeElement);});@@ -1465,7 +1466,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme}imgElement.setAttribute("alt", textElements[2].value.replace(/\n|\r\n|\r|\u2028|\u2029/g, ""));nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);};}};@@ -1634,7 +1635,7 @@ style="margin:4px 0;width: ${isMobile() ? "100%" : "360px"}" class="b3-text-fiellinkElement.insertAdjacentHTML("afterend", "<wbr>");linkElement.remove();nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByWbr(nodeElement, protyle.toolbar.range);html = nodeElement.outerHTML;}@@ -1666,7 +1667,7 @@ style="margin:4px 0;width: ${isMobile() ? "100%" : "360px"}" class="b3-text-fiellinkElement.removeAttribute("data-href");linkElement.removeAttribute("data-title");nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);protyle.toolbar.range.selectNode(linkElement);protyle.toolbar.range.collapse(false);focusByRange(protyle.toolbar.range);@@ -1683,7 +1684,7 @@ style="margin:4px 0;width: ${isMobile() ? "100%" : "360px"}" class="b3-text-fielinputElements[2].value = "";nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));removeInlineType(linkElement, "a", protyle.toolbar.range);- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);html = nodeElement.outerHTML;}}).element);@@ -1755,7 +1756,7 @@ style="margin:4px 0;width: ${isMobile() ? "100%" : "360px"}" class="b3-text-fiel}if (html !== nodeElement.outerHTML) {nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);}};};@@ -1783,7 +1784,7 @@ export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => {}if (nodeElement.outerHTML !== oldHTML) {nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);}};window.siyuan.menus.menu.element.setAttribute("data-name", Constants.MENU_INLINE_TAG);@@ -1915,7 +1916,7 @@ export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => {tagElement.insertAdjacentHTML("afterend", "<wbr>");tagElement.remove();nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, protyle.toolbar.range);}}).element);@@ -1988,7 +1989,7 @@ export const inlineMathMenu = (protyle: IProtyle, element: Element) => {element.insertAdjacentHTML("afterend", "<wbr>");element.remove();nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByWbr(nodeElement, protyle.toolbar.range);}}).element);@@ -2011,7 +2012,7 @@ const genImageWidthMenu = (label: string, imgElement: HTMLElement, protyle: IProimg3115(imgElement.parentElement.parentElement);imgElement.parentElement.style.width = label === window.siyuan.languages.default ? "" : `calc(${label} - 8px)`;imgElement.style.height = "";- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusBlock(nodeElement);}};@@ -2027,7 +2028,7 @@ const genImageHeightMenu = (label: string, imgElement: HTMLElement, protyle: IPrimgElement.style.height = label === window.siyuan.languages.default ? "" : parseInt(label) + "vh";img3115(imgElement.parentElement.parentElement);imgElement.parentElement.style.width = "";- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusBlock(nodeElement);}};@@ -2088,7 +2089,7 @@ export const iframeMenu = (protyle: IProtyle, nodeElement: Element) => {iframeElement.setAttribute("src", value);}- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);html = nodeElement.outerHTML;event.stopPropagation();});@@ -2117,7 +2118,7 @@ export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string)element.style.maxWidth = "none";element.querySelector("textarea").addEventListener("change", (event) => {videoElement.setAttribute("src", (event.target as HTMLTextAreaElement).value.replace(/\n|\r\n|\r|\u2028|\u2029/g, "").trim());- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);html = nodeElement.outerHTML;event.stopPropagation();});@@ -2201,7 +2202,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:}}focusByRange(range);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);}});}@@ -2214,7 +2215,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:const html = nodeElement.outerHTML;thMatchElement.style.width = "";thMatchElement.style.minWidth = "60px";- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);}});}@@ -2230,7 +2231,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:} else {nodeElement.setAttribute("custom-pinthead", "true");}- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);}});otherMenus.push({diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex 4424d5c38e..acadb37fff 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -1492,7 +1492,7 @@ export class Gutter {nodeElement.setAttribute("data-sb-layout", "col");}nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByRange(protyle.toolbar.range);hideElements(["gutter"], protyle);}@@ -1604,7 +1604,7 @@ export class Gutter {element.querySelector("input").addEventListener("change", (event) => {const newHeight = ((event.target as HTMLInputElement).value || "420") + "px";(nodeElement as HTMLElement).style.height = newHeight;- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);html = nodeElement.outerHTML;event.stopPropagation();const renderElement = nodeElement.querySelector('[contenteditable="false"]') as HTMLElement;diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.tsindex 40cdb261d9..ad24fe0602 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -675,13 +675,13 @@ ${genHintItemHTML(item)}range.deleteContents();this.fixImageCursor(range);protyle.toolbar.showTpl(protyle, nodeElement, range);- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);return;} else if (value === Constants.ZWSP + 1) {range.deleteContents();this.fixImageCursor(range);protyle.toolbar.showWidget(protyle, nodeElement, range);- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);return;} else if (value === Constants.ZWSP + 2) {range.deleteContents();@@ -689,7 +689,7 @@ ${genHintItemHTML(item)}protyle.toolbar.range = range;const rangePosition = getSelectionPosition(nodeElement, range);assetMenu(protyle, {x: rangePosition.left, y: rangePosition.top + 26, w: 0, h: 26});- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);return;} else if (value === Constants.ZWSP + 3) {range.deleteContents();@@ -751,7 +751,7 @@ ${genHintItemHTML(item)}range.deleteContents();this.fixImageCursor(range);nodeElement.setAttribute("style", value.split(Constants.ZWSP)[1] || "");- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);return;} else if (value.startsWith("plugin")) {protyle.app.plugins.find((plugin) => {@@ -778,14 +778,13 @@ ${genHintItemHTML(item)}}const editableElement = getContenteditableElement(nodeElement);if (value === "![]()") { // https://github.com/siyuan-note/siyuan/issues/4586 1- let newHTML = "";range.insertNode(document.createElement("wbr"));range.insertNode(document.createTextNode(value));- newHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);- nodeElement.outerHTML = newHTML;- nodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`);+ nodeElement.insertAdjacentHTML("afterend", protyle.lute.SpinBlockDOM(nodeElement.outerHTML));+ nodeElement = nodeElement.nextElementSibling as HTMLElement;+ nodeElement.previousElementSibling.remove();focusByWbr(nodeElement, range);- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);let imgElement: HTMLElement = range.startContainer.childNodes[range.startOffset - 1] as HTMLElement || range.startContainer as HTMLElement;if (imgElement && imgElement.nodeType !== 3 && imgElement.classList.contains("img")) {// 已经找到图片@@ -814,16 +813,16 @@ ${genHintItemHTML(item)}editableElement.textContent = textContent;newHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);}- nodeElement.outerHTML = newHTML;- nodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`);+ nodeElement.insertAdjacentHTML("afterend", newHTML);+ nodeElement = nodeElement.nextElementSibling as HTMLElement;+ nodeElement.previousElementSibling.remove();// https://github.com/siyuan-note/siyuan/issues/6864if (nodeElement.getAttribute("data-type") === "NodeTable") {nodeElement.querySelectorAll("colgroup col").forEach((item: HTMLElement) => {item.style.minWidth = "60px";});- newHTML = nodeElement.outerHTML;}- updateTransaction(protyle, id, newHTML, html);+ updateTransaction(protyle, nodeElement, html);} else {let newHTML = protyle.lute.SpinBlockDOM(textContent);if (value === "<div>") {diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.tsindex 1aa2b88687..a0739f6aa5 100644--- a/app/src/protyle/index.ts+++ b/app/src/protyle/index.ts@@ -505,8 +505,17 @@ export class Protyle {});}+ /**+ * @deprecated 将在 3.7.1 版本中移除。请改用 {@link updateTransactionElement}。+ */public updateTransaction(id: string, newHTML: string, html: string) {- updateTransaction(this.protyle, id, newHTML, html);+ const element = document.createElement("template");+ element.innerHTML = newHTML;+ updateTransaction(this.protyle, element.content.firstElementChild, html);+ }++ public updateTransactionElement(element: Element, oldHTML: string) {+ updateTransaction(this.protyle, element, oldHTML);}public updateBatchTransaction(nodeElements: Element[], cb: (e: HTMLElement) => void) {diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.tsindex 332d0afec7..737f8ec2ab 100644--- a/app/src/protyle/toolbar/index.ts+++ b/app/src/protyle/toolbar/index.ts@@ -813,7 +813,7 @@ export class Toolbar {}}nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);nodeElement.querySelectorAll("wbr").forEach(item => {item.remove();});@@ -1210,7 +1210,7 @@ export class Toolbar {if (!noChange && nodeElement.outerHTML !== html) {nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);}};this.subElement.style.zIndex = (++window.siyuan.zIndex).toString();@@ -1740,7 +1740,7 @@ export class Toolbar {currentRange.extractContents();focusByWbr(nodeElement, currentRange);focusByRange(currentRange);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);this.subElement.classList.add("fn__none");} else if (action === "paste") {focusByRange(getEditorRange(nodeElement));diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex c313d12f5a..88a2399053 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -257,7 +257,7 @@ const processTable = (range: Range, html: string, protyle: IProtyle, blockElemen}});range.collapse(false);- updateTransaction(protyle, blockElement.getAttribute("data-node-id"), blockElement.outerHTML, oldHTML);+ updateTransaction(protyle, blockElement, oldHTML);return true;};@@ -335,7 +335,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,focusByWbr(blockElement, range);}blockElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, id, blockElement.outerHTML, oldHTML);+ updateTransaction(protyle, blockElement, oldHTML);setTimeout(() => {scrollCenter(protyle, undefined, "nearest", "smooth");}, Constants.TIMEOUT_LOAD);diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.tsindex 2292427baf..402fd104da 100644--- a/app/src/protyle/util/table.ts+++ b/app/src/protyle/util/table.ts@@ -88,7 +88,7 @@ export const setTableAlign = (protyle: IProtyle, cellElements: HTMLElement[], notableElement.rows[k].cells[item].setAttribute("align", type);});}- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByWbr(tableElement, range);};@@ -119,7 +119,7 @@ export const insertRow = (protyle: IProtyle, range: Range, cellElement: HTMLElemrange.selectNodeContents(newRowElement.cells[getColIndex(cellElement)]);range.collapse(true);focusByRange(range);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);scrollToView(nodeElement, newRowElement, protyle);};@@ -174,7 +174,7 @@ export const insertRowAbove = (protyle: IProtyle, range: Range, cellElement: HTMrange.selectNodeContents(newRowElement.cells[getColIndex(cellElement)]);range.collapse(true);focusByRange(range);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);scrollToView(nodeElement, newRowElement, protyle);};@@ -205,7 +205,7 @@ export const insertColumn = (protyle: IProtyle, nodeElement: Element, cellElemen}tableElement.querySelectorAll("col")[index].insertAdjacentHTML(type, "<col style='min-width: 60px;'>".repeat(count));focusByWbr(nodeElement, range);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);};export const deleteRow = (protyle: IProtyle, range: Range, cellElement: HTMLElement, nodeElement: Element) => {@@ -230,7 +230,7 @@ export const deleteRow = (protyle: IProtyle, range: Range, cellElement: HTMLElemrange.collapse(true);focusByRange(range);scrollToView(nodeElement, previousTrElement, protyle);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);}};@@ -263,7 +263,7 @@ export const deleteColumn = (protyle: IProtyle, range: Range, nodeElement: Elemecells[index].remove();}nodeElement.querySelectorAll("col")[index]?.remove();- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByRange(range);};@@ -291,7 +291,7 @@ export const moveRowToUp = (protyle: IProtyle, range: Range, cellElement: HTMLElrowElement.after(headElement);rowElement.parentElement.previousElementSibling.append(rowElement);}- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByWbr(nodeElement, range);scrollCenter(protyle, rowElement);};@@ -321,7 +321,7 @@ export const moveRowToDown = (protyle: IProtyle, range: Range, cellElement: HTMLrowElement.after(firstRowElement);rowElement.parentElement.nextElementSibling.insertAdjacentElement("afterbegin", rowElement);}- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByWbr(nodeElement, range);scrollCenter(protyle, rowElement);};@@ -349,7 +349,7 @@ export const moveColumnToLeft = (protyle: IProtyle, range: Range, cellElement: H}const colElements = nodeElement.querySelectorAll("col");colElements[cellIndex].after(colElements[cellIndex - 1]);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByWbr(nodeElement, range);};@@ -375,7 +375,7 @@ export const moveColumnToRight = (protyle: IProtyle, range: Range, cellElement:}const colElements = nodeElement.querySelectorAll("col");colElements[cellIndex].before(colElements[cellIndex + 1]);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);focusByWbr(nodeElement, range);};@@ -420,7 +420,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)}range.collapse(false);scrollCenter(protyle);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);event.preventDefault();return true;}@@ -799,7 +799,7 @@ export const clearTableCell = (protyle: IProtyle, tableBlockElement: HTMLElementselectCellElements.forEach(item => {item.innerHTML = "";});- updateTransaction(protyle, tableBlockElement.getAttribute("data-node-id"), tableBlockElement.outerHTML, oldHTML);+ updateTransaction(protyle, tableBlockElement, oldHTML);};export const updateTableTitle = (protyle: IProtyle, nodeElement: Element) => {@@ -856,7 +856,7 @@ export const updateTableTitle = (protyle: IProtyle, nodeElement: Element) => {}nodeElement.removeAttribute("caption");}- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);dialog.destroy();});inputElement.value = captionElement?.textContent || "";diff --git a/app/src/protyle/wysiwyg/codeBlock.ts b/app/src/protyle/wysiwyg/codeBlock.tsindex b148c75aa6..92e46f57df 100644--- a/app/src/protyle/wysiwyg/codeBlock.ts+++ b/app/src/protyle/wysiwyg/codeBlock.ts@@ -51,6 +51,6 @@ export const tabCodeBlock = (protyle: IProtyle, nodeElement: HTMLElement,const brElement = wbrElement.parentElement.querySelector("br");setLastNodeRange(brElement.previousSibling as Element, range, false);brElement.remove();- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);wbrElement.remove();};diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.tsindex 21ef7f7ddc..c6a9123232 100644--- a/app/src/protyle/wysiwyg/commonHotkey.ts+++ b/app/src/protyle/wysiwyg/commonHotkey.ts@@ -452,7 +452,7 @@ export const alignImgCenter = (protyle: IProtyle, nodeElement: Element, assetEleassetElements.forEach((item: HTMLElement) => {item.style.minWidth = "calc(100% - 0.1em)";});- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);};export const alignImgLeft = (protyle: IProtyle, nodeElement: Element, assetElements: Element[], id: string, html: string) => {@@ -460,5 +460,5 @@ export const alignImgLeft = (protyle: IProtyle, nodeElement: Element, assetElemeassetElements.forEach((item: HTMLElement) => {item.removeAttribute("style");});- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);};diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.tsindex 61360e0f19..20d1dfd753 100644--- a/app/src/protyle/wysiwyg/enter.ts+++ b/app/src/protyle/wysiwyg/enter.ts@@ -98,7 +98,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyleprotyle.toolbar.showRender(protyle, blockElement);processRender(blockElement);}- updateTransaction(protyle, blockElement.getAttribute("data-node-id"), blockElement.outerHTML, oldHTML);+ updateTransaction(protyle, blockElement, oldHTML);return true;}}@@ -117,7 +117,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtylerange.insertNode(wbrElement);editableElement.parentElement.removeAttribute("data-render");highlightRender(blockElement);- updateTransaction(protyle, blockElement.getAttribute("data-node-id"), blockElement.outerHTML, oldHTML);+ updateTransaction(protyle, blockElement, oldHTML);scrollCenter(protyle);return true;}@@ -340,15 +340,17 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtylecurrentElement = item;selectsElement.push(item);});- if (currentElement.parentElement.classList.contains("bq") && currentElement.parentElement.childElementCount > 2 &&+ let parentElement = currentElement.parentElement;+ if (parentElement.classList.contains("bq") && parentElement.childElementCount > 2 &¤tElement.previousElementSibling.classList.contains("p") && currentElement.classList.contains("p") &¤tElement.previousElementSibling.textContent.startsWith("[!") && parentHTML) {- const parentId = currentElement.parentElement.getAttribute("data-node-id");- const calloutHTML = protyle.lute.SpinBlockDOM(currentElement.parentElement.outerHTML);+ const calloutHTML = protyle.lute.SpinBlockDOM(parentElement.outerHTML);if (calloutHTML.indexOf('data-type="NodeCallout"') > -1) {- currentElement.parentElement.outerHTML = calloutHTML;+ parentElement.insertAdjacentHTML("afterend", calloutHTML);+ parentElement = parentElement.nextElementSibling as HTMLElement;+ parentElement.previousElementSibling.remove();mathRender(protyle.wysiwyg.element);- updateTransaction(protyle, parentId, calloutHTML, parentHTML);+ updateTransaction(protyle, parentElement, parentHTML);focusByWbr(protyle.wysiwyg.element, range);scrollCenter(protyle);return true;@@ -362,8 +364,8 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle}});transaction(protyle, doOperation, undoOperation);- if (currentElement.parentElement.classList.contains("sb") &&- currentElement.parentElement.getAttribute("data-sb-layout") === "col") {+ if (parentElement.classList.contains("sb") &&+ parentElement.getAttribute("data-sb-layout") === "col") {turnsIntoOneTransaction({protyle,selectsElement,@@ -425,7 +427,7 @@ const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) =if (listItemElement.getAttribute("data-subtype") === "o") {updateListOrder(listItemElement.parentElement);}- updateTransaction(protyle, listItemElement.parentElement.getAttribute("data-node-id"), listItemElement.parentElement.outerHTML, html);+ updateTransaction(protyle, listItemElement.parentElement, html);focusByWbr(newElement, range);scrollCenter(protyle);removeEmptyNode(newElement);@@ -450,7 +452,7 @@ const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) =if (subListElement.getAttribute("data-subtype") === "o") {updateListOrder(subListElement);}- updateTransaction(protyle, listItemElement.getAttribute("data-node-id"), listItemElement.outerHTML, html);+ updateTransaction(protyle, listItemElement, html);focusByWbr(listItemElement, range);scrollCenter(protyle);} else {@@ -505,7 +507,7 @@ const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) =id: listItemElement.getAttribute("data-node-id")}]);} else {- updateTransaction(protyle, listItemElement.parentElement.getAttribute("data-node-id"), listItemElement.parentElement.outerHTML, html);+ updateTransaction(protyle, listItemElement.parentElement, html);}focusByWbr(newElement, range);scrollCenter(protyle);@@ -594,7 +596,7 @@ const listEnter = (protyle: IProtyle, blockElement: HTMLElement, range: Range) =data: listItemHTML}]);} else {- updateTransaction(protyle, listItemElement.parentElement.getAttribute("data-node-id"), listItemElement.parentElement.outerHTML, oldHTML);+ updateTransaction(protyle, listItemElement.parentElement, oldHTML);}focusByWbr(newElement, range);scrollCenter(protyle);@@ -631,7 +633,7 @@ export const softEnter = (range: Range, nodeElement: HTMLElement, protyle: IProtstartElement.after(newlineNode);range.selectNode(newlineNode);range.collapse(false);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);return true;}}@@ -682,5 +684,5 @@ const addNewLineToEnd = (range: Range, nodeElement: HTMLElement, protyle: IProty}range.collapse(true);focusByRange(range);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);};diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 33ea7393a6..f06a115ced 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -1012,7 +1012,7 @@ export class WYSIWYG {documentSelf.onselectstart = null;documentSelf.onselect = null;if (target.classList.contains("protyle-action__drag") && nodeElement) {- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);}nodeElement.classList.remove("iframe--drag");target.parentElement.parentElement.classList.remove("img--drag");@@ -1087,7 +1087,7 @@ export class WYSIWYG {documentSelf.onselectstart = null;documentSelf.onselect = null;if (nodeElement) {- updateTransaction(protyle, id, nodeElement.outerHTML, html);+ updateTransaction(protyle, nodeElement, html);}};return;@@ -1530,7 +1530,7 @@ export class WYSIWYG {selectCellElements[0].rowSpan = rowSpan;focusByWbr(selectCellElements[0], document.createRange());document.execCommand("insertHTML", false, "");- updateTransaction(protyle, tableBlockElement.getAttribute("data-node-id"), tableBlockElement.outerHTML, oldHTML);+ updateTransaction(protyle, tableBlockElement, oldHTML);}});}@@ -1970,7 +1970,7 @@ export class WYSIWYG {});html += "</table>";textPlain = protyle.lute.HTML2Md(html);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);} else {const id = nodeElement.getAttribute("data-node-id");setInsertWbrHTML(nodeElement, range, protyle);@@ -2096,7 +2096,7 @@ export class WYSIWYG {if (nodeElement.parentElement.parentElement && !nodeElement.classList.contains("av")) {// 选中 heading 时,使用删除的 transactionsetInsertWbrHTML(nodeElement, range, protyle);- updateTransaction(protyle, id, protyle.wysiwyg.lastHTMLs[id] || nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);}}protyle.hint.render(protyle);@@ -2502,7 +2502,7 @@ export class WYSIWYG {} else {const id = blockElement.getAttribute("data-node-id");if (protyle.wysiwyg.lastHTMLs[id]) {- updateTransaction(protyle, id, blockElement.outerHTML, protyle.wysiwyg.lastHTMLs[id]);+ updateTransaction(protyle, blockElement, protyle.wysiwyg.lastHTMLs[id]);}}});@@ -3070,7 +3070,7 @@ export class WYSIWYG {}}});- updateTransaction(protyle, actionElement.parentElement.parentElement.getAttribute("data-node-id"), actionElement.parentElement.parentElement.outerHTML, oldHTML);+ updateTransaction(protyle, actionElement.parentElement.parentElement, oldHTML);}hideElements(["gutter"], protyle);} else if (event.shiftKey && !protyle.disabled) {@@ -3092,7 +3092,7 @@ export class WYSIWYG {}actionElement.parentElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));actionElement.parentElement.setAttribute(Constants.ATTRIBUTE_EDITING, "true");- updateTransaction(protyle, actionId, actionElement.parentElement.outerHTML, html);+ updateTransaction(protyle, actionElement.parentElement, html);}} else if (window.siyuan.config.editor.listItemDotNumberClickFocus) {if (protyle.block.showAll && protyle.block.id === actionId) {@@ -3178,7 +3178,7 @@ export class WYSIWYG {}}calloutIconElement.innerHTML = emojiHTML;- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusBlock(nodeElement);}, calloutIconElement.querySelector("img"));}@@ -3211,7 +3211,7 @@ export class WYSIWYG {}emojiElement.outerHTML = emojiHTML;hideElements(["dialog"]);- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, range);}, emojiElement);}diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.tsindex c7911cdd9f..81c899ee5d 100644--- a/app/src/protyle/wysiwyg/input.ts+++ b/app/src/protyle/wysiwyg/input.ts@@ -92,7 +92,7 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:if ((type !== "NodeCodeBlock" && type !== "NodeHeading") && // https://github.com/siyuan-note/siyuan/issues/11851(editElement.innerHTML.endsWith("\n<wbr>") || editElement.innerHTML.endsWith("\n<wbr>\n"))) {// 软换行- updateTransaction(protyle, id, blockElement.outerHTML, protyle.wysiwyg.lastHTMLs[id] || blockElement.outerHTML.replace("\n<wbr>", "<wbr>"));+ updateTransaction(protyle, blockElement, protyle.wysiwyg.lastHTMLs[id] || blockElement.outerHTML.replace("\n<wbr>", "<wbr>"));wbrElement.remove();return;}@@ -126,7 +126,7 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:} else if ((trimStartHTML.startsWith("```") || trimStartHTML.startsWith("···") || trimStartHTML.startsWith("~~~")) &&trimStartHTML.indexOf("\n") === -1 && trimStartHTML.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") === -1) {// ```test` 后续处理,```test 不处理- updateTransaction(protyle, id, blockElement.outerHTML, protyle.wysiwyg.lastHTMLs[id]);+ updateTransaction(protyle, blockElement, protyle.wysiwyg.lastHTMLs[id]);wbrElement.remove();return;}diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex 349ff71e8a..68031429af 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -822,7 +822,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const oldHTML = nodeElement.outerHTML;range.startContainer.textContent = "";previousSibling.remove();- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, range);event.stopPropagation();event.preventDefault();@@ -865,7 +865,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {range.insertNode(wbrElement);const oldHTML = nodeElement.outerHTML;wbrElement.nextSibling.textContent = Constants.ZWSP;- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, range);event.preventDefault();return;@@ -879,7 +879,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {range.insertNode(wbrElement);const oldHTML = nodeElement.outerHTML;wbrElement.nextSibling.textContent = Constants.ZWSP;- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, range);event.preventDefault();return;@@ -995,7 +995,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {range.insertNode(wbrElement);const oldHTML = nodeElement.outerHTML;wbrElement.previousSibling.textContent = Constants.ZWSP;- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, range);event.preventDefault();return;@@ -1009,7 +1009,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {range.insertNode(wbrElement);const oldHTML = nodeElement.outerHTML;wbrElement.previousSibling.textContent = Constants.ZWSP;- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, range);event.preventDefault();return;@@ -1070,7 +1070,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {range.deleteContents();range.insertNode(document.createTextNode(Constants.ZWSP));range.insertNode(document.createElement("wbr"));- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, range);event.preventDefault();return;@@ -1197,7 +1197,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {topElement.lastElementChild.insertAdjacentHTML("afterbegin", `<div class="protyle-attr--name"><svg><use xlink:href="#iconN"></use></svg>${content.trim()}</div>`);}topElement.setAttribute("name", content.trim());- updateTransaction(protyle, topElement.getAttribute("data-node-id"), topElement.outerHTML, oldHTML);+ updateTransaction(protyle, topElement, oldHTML);});}event.preventDefault();@@ -1502,10 +1502,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const html = nodeElement.outerHTML;// 需要 EscapeHTMLStr https://github.com/siyuan-note/siyuan/issues/11451editElement.innerHTML = "```" + window.siyuan.storage[Constants.LOCAL_CODELANG] + "\n" + Lute.EscapeHTMLStr(editElement.textContent) + "<wbr>\n```";- const newHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);- nodeElement.outerHTML = newHTML;- const newNodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`);- updateTransaction(protyle, id, newHTML, html);+ nodeElement.insertAdjacentHTML("afterend", protyle.lute.SpinBlockDOM(nodeElement.outerHTML));+ const newNodeElement = nodeElement.nextElementSibling;+ nodeElement.remove();+ updateTransaction(protyle, newNodeElement, html);highlightRender(newNodeElement);event.preventDefault();event.stopPropagation();@@ -1721,7 +1721,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {taskItemElement.classList.add("protyle-task--done");}taskItemElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, taskItemElement.getAttribute("data-node-id"), taskItemElement.outerHTML, html);+ updateTransaction(protyle, taskItemElement, html);event.preventDefault();event.stopPropagation();return;@@ -1784,7 +1784,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const oldHTML = selectsElement[0].outerHTML;selectsElement[0].setAttribute("data-sb-layout", "row");selectsElement[0].setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, selectsElement[0].getAttribute("data-node-id"), selectsElement[0].outerHTML, oldHTML);+ updateTransaction(protyle, selectsElement[0], oldHTML);} else {range.insertNode(document.createElement("wbr"));const sbData = await cancelSB(protyle, selectsElement[0]);@@ -1813,7 +1813,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const oldHTML = selectsElement[0].outerHTML;selectsElement[0].setAttribute("data-sb-layout", "col");selectsElement[0].setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, selectsElement[0].getAttribute("data-node-id"), selectsElement[0].outerHTML, oldHTML);+ updateTransaction(protyle, selectsElement[0], oldHTML);} else {range.insertNode(document.createElement("wbr"));const sbData = await cancelSB(protyle, selectsElement[0]);diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.tsindex 23cbd74eb9..c054af295f 100644--- a/app/src/protyle/wysiwyg/list.ts+++ b/app/src/protyle/wysiwyg/list.ts@@ -322,7 +322,7 @@ export const listIndent = (protyle: IProtyle, liItemElements: Element[], range:}}if (!previousElement.parentElement.classList.contains("protyle-wysiwyg")) {- updateTransaction(protyle, previousElement.parentElement.getAttribute("data-node-id"), previousElement.parentElement.outerHTML, html);+ updateTransaction(protyle, previousElement.parentElement, html);}focusByWbr(previousElement, range);};@@ -639,7 +639,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:liItemElements[0].firstElementChild.remove();liItemElements[0].lastElementChild.remove();liElement.outerHTML = liItemElements[0].innerHTML;- updateTransaction(protyle, parentLiItemElement.getAttribute("data-node-id"), parentLiItemElement.outerHTML, html);+ updateTransaction(protyle, parentLiItemElement, html);focusByWbr(parentLiItemElement, range);return;}@@ -883,7 +883,7 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:if (parentLiItemElement && parentLiItemElement.getAttribute("data-subtype") === "o") {updateListOrder(parentParentElement);}- updateTransaction(protyle, parentParentElement.getAttribute("data-node-id"), parentParentElement.outerHTML, html);+ updateTransaction(protyle, parentParentElement, html);}focusByWbr(parentParentElement, range);};diff --git a/app/src/protyle/wysiwyg/move.ts b/app/src/protyle/wysiwyg/move.tsindex 91aac9b7ab..19442cc58d 100644--- a/app/src/protyle/wysiwyg/move.ts+++ b/app/src/protyle/wysiwyg/move.ts@@ -77,7 +77,7 @@ export const moveToUp = (protyle: IProtyle, nodeElement: HTMLElement, range: Ranif (previousElement.getAttribute("data-subtype") === "o") {updateListOrder(previousElement.parentElement);}- updateTransaction(protyle, previousElement.parentElement.parentElement.parentElement.getAttribute("data-node-id"), previousElement.parentElement.parentElement.parentElement.outerHTML, oldListHTML);+ updateTransaction(protyle, previousElement.parentElement.parentElement.parentElement, oldListHTML);preventScroll(protyle);focusByWbr(previousElement.parentElement, range);scrollCenter(protyle);@@ -92,7 +92,7 @@ export const moveToUp = (protyle: IProtyle, nodeElement: HTMLElement, range: Ranconst orderIndex = parseInt(sourceElements[0].parentElement.firstElementChild.getAttribute("data-marker"));sourceElements[sourceElements.length - 1].after(previousElement);updateListOrder(sourceElements[0].parentElement, orderIndex);- updateTransaction(protyle, sourceElements[0].parentElement.getAttribute("data-node-id"), sourceElements[0].parentElement.outerHTML, html);+ updateTransaction(protyle, sourceElements[0].parentElement, html);} else {const id = previousElement.getAttribute("data-node-id");transaction(protyle, [{@@ -175,7 +175,7 @@ export const moveToDown = (protyle: IProtyle, nodeElement: HTMLElement, range: Rif (nextElement.getAttribute("data-subtype") === "o") {updateListOrder(nextElement.parentElement, orderIndex);}- updateTransaction(protyle, nextElement.parentElement.parentElement.parentElement.getAttribute("data-node-id"), nextElement.parentElement.parentElement.parentElement.outerHTML, oldListHTML);+ updateTransaction(protyle, nextElement.parentElement.parentElement.parentElement, oldListHTML);preventScroll(protyle);focusByWbr(nextElement.parentElement, range);scrollCenter(protyle);@@ -190,7 +190,7 @@ export const moveToDown = (protyle: IProtyle, nodeElement: HTMLElement, range: Rconst orderIndex = parseInt(sourceElements[0].parentElement.firstElementChild.getAttribute("data-marker"));sourceElements[0].before(nextElement);updateListOrder(nextElement.parentElement, orderIndex);- updateTransaction(protyle, nextElement.parentElement.getAttribute("data-node-id"), nextElement.parentElement.outerHTML, html);+ updateTransaction(protyle, nextElement.parentElement, html);} else {const id = nextElement.getAttribute("data-node-id");transaction(protyle, [{diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.tsindex f6244c75b3..41379a6a40 100644--- a/app/src/protyle/wysiwyg/remove.ts+++ b/app/src/protyle/wysiwyg/remove.ts@@ -623,7 +623,7 @@ export const removeImage = (imgSelectElement: Element, nodeElement: HTMLElement,}imgSelectElement.insertAdjacentHTML("afterend", "<wbr>");imgSelectElement.remove();- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);+ updateTransaction(protyle, nodeElement, oldHTML);focusByWbr(nodeElement, range);// 不太清楚为什么删除图片后无法上下键定位,但重绘后就好了 https://ld246.com/article/1714314625702const editElement = getContenteditableElement(nodeElement);@@ -846,7 +846,7 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDeleif (listElement.getAttribute("data-subtype") === "o") {updateListOrder(listElement);}- updateTransaction(protyle, listElement.getAttribute("data-node-id"), listElement.outerHTML, html);+ updateTransaction(protyle, listElement, html);}focusByWbr(previousLastElement.parentElement, range);};diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex 99f82c3ff5..e5230a43da 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -1290,7 +1290,9 @@ export const turnsOneInto = async (options: {const parentId = options.nodeElement.parentElement.getAttribute("data-node-id") || options.protyle.block.parentID;// @ts-ignoreconst newHTML = options.protyle.lute[options.type](options.nodeElement.outerHTML, options.level);- options.nodeElement.outerHTML = newHTML;+ options.nodeElement.insertAdjacentHTML("afterend", newHTML);+ options.nodeElement = options.nodeElement.nextElementSibling as HTMLElement;+ options.nodeElement.previousElementSibling.remove();if (["CancelBlockquote", "CancelList", "CancelCallout"].includes(options.type)) {const tempElement = document.createElement("template");tempElement.innerHTML = newHTML;@@ -1324,7 +1326,7 @@ export const turnsOneInto = async (options: {});transaction(options.protyle, doOperations, undoOperations);} else {- updateTransaction(options.protyle, options.id, newHTML, oldHTML);+ updateTransaction(options.protyle, options.nodeElement, oldHTML);}focusByWbr(options.protyle.wysiwyg.element, getEditorRange(options.protyle.wysiwyg.element));options.protyle.wysiwyg.element.querySelectorAll('[data-type~="block-ref"]').forEach(item => {@@ -1517,17 +1519,20 @@ const processFold = (operation: IOperation, protyle: IProtyle) => {}};-export const updateTransaction = (protyle: IProtyle, id: string, newHTML: string, html: string) => {- if (newHTML === html) {+export const updateTransaction = (protyle: IProtyle, element: Element, oldHTML: string) => {+ const id = element.getAttribute("data-node-id");+ const newHTML = element.outerHTML;+ if (newHTML === oldHTML) {return;}+ element.setAttribute(Constants.ATTRIBUTE_EDITING, "true");transaction(protyle, [{id,data: newHTML,action: "update"}], [{id,- data: html,+ data: oldHTML,action: "update"}]);};diff --git a/app/src/protyle/wysiwyg/turnIntoList.ts b/app/src/protyle/wysiwyg/turnIntoList.tsindex bdc61d756f..3c1f4e7497 100644--- a/app/src/protyle/wysiwyg/turnIntoList.ts+++ b/app/src/protyle/wysiwyg/turnIntoList.ts@@ -41,7 +41,7 @@ export const turnIntoTaskList = (protyle: IProtyle, type: string, blockElement:}blockElement.previousElementSibling.outerHTML = `<div class="protyle-action protyle-action--task" draggable="true"><svg><use xlink:href="#icon${isDone ? "C" : "Unc"}heck"></use></svg></div>`;editElement.innerHTML = html.substring(contextStartIndex);- updateTransaction(protyle, liElement.getAttribute("data-node-id"), liElement.outerHTML, oldHTML);+ updateTransaction(protyle, liElement, oldHTML);focusByWbr(protyle.wysiwyg.element, range);return true;}