This commit is contained in:
Vanessa 2022-10-03 16:22:18 +08:00
parent 436f439dd1
commit c8ab7693f1
11 changed files with 58 additions and 60 deletions

View File

@ -49,7 +49,8 @@ class App {
progressStatus(data); progressStatus(data);
break; break;
case"statusbarCounter": case"statusbarCounter":
handleStatusbarCounter(data) handleStatusbarCounter(data);
break;
case"downloadProgress": case"downloadProgress":
downloadProgress(data.data); downloadProgress(data.data);
break; break;

View File

@ -157,7 +157,7 @@ export class Backlink extends Model {
this.mTree = new Tree({ this.mTree = new Tree({
element: this.element.querySelector(".backlinkMList") as HTMLElement, element: this.element.querySelector(".backlinkMList") as HTMLElement,
data: null, data: null,
click: (element, event) => { click: (element) => {
this.toggleItem(element, true); this.toggleItem(element, true);
}, },
ctrlClick(element) { ctrlClick(element) {
@ -283,7 +283,7 @@ export class Backlink extends Model {
private toggleItem(liElement: HTMLElement, isMention: boolean) { private toggleItem(liElement: HTMLElement, isMention: boolean) {
const svgElement = liElement.firstElementChild.firstElementChild; const svgElement = liElement.firstElementChild.firstElementChild;
const docId = liElement.getAttribute("data-node-id") const docId = liElement.getAttribute("data-node-id");
if (svgElement.classList.contains("b3-list-item__arrow--open")) { if (svgElement.classList.contains("b3-list-item__arrow--open")) {
svgElement.classList.remove("b3-list-item__arrow--open"); svgElement.classList.remove("b3-list-item__arrow--open");
this.editors.find((item, index) => { this.editors.find((item, index) => {
@ -302,8 +302,8 @@ export class Backlink extends Model {
}, (response) => { }, (response) => {
const editorElement = document.createElement("div"); const editorElement = document.createElement("div");
editorElement.style.minHeight = "auto"; editorElement.style.minHeight = "auto";
editorElement.setAttribute("data-defid", this.blockId) editorElement.setAttribute("data-defid", this.blockId);
editorElement.setAttribute("data-ismention", isMention? "true" : "false") editorElement.setAttribute("data-ismention", isMention? "true" : "false");
liElement.after(editorElement); liElement.after(editorElement);
const editor = new Protyle(editorElement, { const editor = new Protyle(editorElement, {
blockId: "", blockId: "",
@ -316,7 +316,7 @@ export class Backlink extends Model {
breadcrumb: false, breadcrumb: false,
} }
}); });
editor.protyle.block.rootID = docId editor.protyle.block.rootID = docId;
this.editors.push(editor); this.editors.push(editor);
}); });
} }

View File

@ -162,15 +162,15 @@ export const countBlockWord = (ids: string[]) => {
export const renderStatusbarCounter = (stat: { runeCount: number, wordCount: number, linkCount: number, imageCount: number, refCount: number }) => { export const renderStatusbarCounter = (stat: { runeCount: number, wordCount: number, linkCount: number, imageCount: number, refCount: number }) => {
let html = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span>&nbsp;${stat.runeCount}<span class="fn__space"></span> let html = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span>&nbsp;${stat.runeCount}<span class="fn__space"></span>
<span class="ft__on-surface">${window.siyuan.languages.wordCount}</span>&nbsp;${stat.wordCount}<span class="fn__space"></span>` <span class="ft__on-surface">${window.siyuan.languages.wordCount}</span>&nbsp;${stat.wordCount}<span class="fn__space"></span>`;
if (0 < stat.linkCount) { if (0 < stat.linkCount) {
html += `<span class="ft__on-surface">${window.siyuan.languages.link}</span>&nbsp;${stat.linkCount}<span class="fn__space"></span>` html += `<span class="ft__on-surface">${window.siyuan.languages.link}</span>&nbsp;${stat.linkCount}<span class="fn__space"></span>`;
} }
if (0 < stat.imageCount) { if (0 < stat.imageCount) {
html += `<span class="ft__on-surface">${window.siyuan.languages.image}</span>&nbsp;${stat.imageCount}<span class="fn__space"></span>` html += `<span class="ft__on-surface">${window.siyuan.languages.image}</span>&nbsp;${stat.imageCount}<span class="fn__space"></span>`;
} }
if (0 < stat.refCount) { if (0 < stat.refCount) {
html += `<span class="ft__on-surface">${window.siyuan.languages.ref}</span>&nbsp;${stat.refCount}<span class="fn__space"></span>` html += `<span class="ft__on-surface">${window.siyuan.languages.ref}</span>&nbsp;${stat.refCount}<span class="fn__space"></span>`;
} }
document.querySelector("#status .status__counter").innerHTML = html; document.querySelector("#status .status__counter").innerHTML = html;
} };

View File

@ -226,7 +226,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
refID: id, refID: id,
defID: refBlockId, defID: refBlockId,
includeChildren: false includeChildren: false
}) });
} }
}); });
submenu.push({ submenu.push({
@ -236,7 +236,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
refID: id, refID: id,
defID: refBlockId, defID: refBlockId,
includeChildren: true includeChildren: true
}) });
} }
}); });
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({

View File

@ -77,16 +77,16 @@ export class Gutter {
if (!id) { if (!id) {
const gutterFold = () => { const gutterFold = () => {
buttonElement.setAttribute("disabled", "disabled"); buttonElement.setAttribute("disabled", "disabled");
let foldElement: Element let foldElement: Element;
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${(buttonElement.previousElementSibling || buttonElement.nextElementSibling).getAttribute("data-node-id")}"]`)).find(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${(buttonElement.previousElementSibling || buttonElement.nextElementSibling).getAttribute("data-node-id")}"]`)).find(item => {
const itemRect = item.getBoundingClientRect(); const itemRect = item.getBoundingClientRect();
const gutterTop = this.element.getBoundingClientRect().top const gutterTop = this.element.getBoundingClientRect().top;
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") && if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") &&
itemRect.top <= gutterTop && itemRect.bottom >= gutterTop) { itemRect.top <= gutterTop && itemRect.bottom >= gutterTop) {
foldElement = item; foldElement = item;
return true; return true;
} }
}) });
if (!foldElement) { if (!foldElement) {
return; return;
} }
@ -159,16 +159,16 @@ export class Gutter {
if (window.siyuan.ctrlIsPressed) { if (window.siyuan.ctrlIsPressed) {
zoomOut(protyle, id); zoomOut(protyle, id);
} else if (window.siyuan.altIsPressed) { } else if (window.siyuan.altIsPressed) {
let foldElement: Element let foldElement: Element;
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => {
const itemRect = item.getBoundingClientRect(); const itemRect = item.getBoundingClientRect();
const gutterTop = this.element.getBoundingClientRect().top const gutterTop = this.element.getBoundingClientRect().top;
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") && if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") &&
itemRect.top <= gutterTop && itemRect.bottom >= gutterTop) { itemRect.top <= gutterTop && itemRect.bottom >= gutterTop) {
foldElement = item; foldElement = item;
return true; return true;
} }
}) });
if (!foldElement) { if (!foldElement) {
return; return;
} }
@ -236,7 +236,7 @@ export class Gutter {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${buttonElement.getAttribute("data-node-id")}"]`)).find(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${buttonElement.getAttribute("data-node-id")}"]`)).find(item => {
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) { if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
const itemRect = item.getBoundingClientRect(); const itemRect = item.getBoundingClientRect();
const gutterTop = this.element.getBoundingClientRect().top const gutterTop = this.element.getBoundingClientRect().top;
if (itemRect.top <= gutterTop && itemRect.bottom >= gutterTop) { if (itemRect.top <= gutterTop && itemRect.bottom >= gutterTop) {
Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl")).forEach(hlItem => { Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl")).forEach(hlItem => {
if (!item.isSameNode(hlItem)) { if (!item.isSameNode(hlItem)) {
@ -671,7 +671,7 @@ export class Gutter {
if (buttonElement.tagName === "BUTTON") { if (buttonElement.tagName === "BUTTON") {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => {
const itemRect = item.getBoundingClientRect(); const itemRect = item.getBoundingClientRect();
const gutterTop = this.element.getBoundingClientRect().top const gutterTop = this.element.getBoundingClientRect().top;
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") && if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed") &&
itemRect.top <= gutterTop && itemRect.bottom >= gutterTop) { itemRect.top <= gutterTop && itemRect.bottom >= gutterTop) {
nodeElement = item; nodeElement = item;

View File

@ -529,7 +529,7 @@ export class Toolbar {
// 合并相同的 node // 合并相同的 node
if (currentNewNode.getAttribute("data-type").indexOf("inline-math") > -1) { if (currentNewNode.getAttribute("data-type").indexOf("inline-math") > -1) {
// 数学公式合并 data-content https://github.com/siyuan-note/siyuan/issues/6028 // 数学公式合并 data-content https://github.com/siyuan-note/siyuan/issues/6028
nextNewNode.setAttribute("data-content", currentNewNode.getAttribute("data-content") + nextNewNode.getAttribute("data-content")) nextNewNode.setAttribute("data-content", currentNewNode.getAttribute("data-content") + nextNewNode.getAttribute("data-content"));
} else if (currentNewNode.getAttribute("data-type").indexOf("block-ref") === -1) { } else if (currentNewNode.getAttribute("data-type").indexOf("block-ref") === -1) {
// 引用不虚合并内容 https://ld246.com/article/1664454663564 // 引用不虚合并内容 https://ld246.com/article/1664454663564
nextNewNode.innerHTML = currentNewNode.innerHTML + nextNewNode.innerHTML; nextNewNode.innerHTML = currentNewNode.innerHTML + nextNewNode.innerHTML;

View File

@ -13,12 +13,10 @@ import {onGet} from "./onGet";
/// #if !MOBILE /// #if !MOBILE
import {getInstanceById} from "../../layout/util"; import {getInstanceById} from "../../layout/util";
import {Tab} from "../../layout/Tab"; import {Tab} from "../../layout/Tab";
import {getAllModels} from "../../layout/getAll";
import {updatePanelByEditor} from "../../editor/util"; import {updatePanelByEditor} from "../../editor/util";
/// #endif /// #endif
import {Editor} from "../../editor"; import {Editor} from "../../editor";
import {blockRender} from "../markdown/blockRender"; import {blockRender} from "../markdown/blockRender";
import {processRender} from "./processCode";
import {highlightRender} from "../markdown/highlightRender"; import {highlightRender} from "../markdown/highlightRender";
import {uploadLocalFiles} from "../upload"; import {uploadLocalFiles} from "../upload";
import {insertHTML} from "./insertHTML"; import {insertHTML} from "./insertHTML";
@ -622,18 +620,18 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
}); });
if (event.altKey) { if (event.altKey) {
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY)); focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
let html = '' let html = "";
for (let i = 0; i < selectedIds.length; i++) { for (let i = 0; i < selectedIds.length; i++) {
const response = await fetchSyncPost("/api/block/getRefText", {id: selectedIds[i]}); const response = await fetchSyncPost("/api/block/getRefText", {id: selectedIds[i]});
html += `((${selectedIds[i]} '${response.data}')) ` html += `((${selectedIds[i]} '${response.data}')) `;
} }
insertHTML(html, protyle); insertHTML(html, protyle);
} else if (event.shiftKey) { } else if (event.shiftKey) {
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY)); focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
let html = '' let html = "";
selectedIds.forEach(item => { selectedIds.forEach(item => {
html += `{{select * from blocks where id='${item}'}}\n` html += `{{select * from blocks where id='${item}'}}\n`;
}) });
insertHTML(protyle.lute.SpinBlockDOM(html), protyle); insertHTML(protyle.lute.SpinBlockDOM(html), protyle);
blockRender(protyle, protyle.wysiwyg.element); blockRender(protyle, protyle.wysiwyg.element);
} else if (targetElement) { } else if (targetElement) {

View File

@ -107,7 +107,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false, spl
} }
const spinHTML = protyle.lute.SpinBlockDOM(removeEmbed(blockElement)); const spinHTML = protyle.lute.SpinBlockDOM(removeEmbed(blockElement));
const scrollLeft = blockElement.firstElementChild.scrollLeft; const scrollLeft = blockElement.firstElementChild.scrollLeft;
const blockPreviousElement = blockElement.previousElementSibling const blockPreviousElement = blockElement.previousElementSibling;
blockElement.outerHTML = spinHTML; blockElement.outerHTML = spinHTML;
render = true; render = true;
// spin 后变成多个块需后续处理 https://github.com/siyuan-note/insider/issues/451 // spin 后变成多个块需后续处理 https://github.com/siyuan-note/insider/issues/451

View File

@ -1022,7 +1022,7 @@ export class WYSIWYG {
} else if (range.startContainer.nodeType === 3 && range.startContainer.parentElement.tagName === "SPAN" && } else if (range.startContainer.nodeType === 3 && range.startContainer.parentElement.tagName === "SPAN" &&
range.startContainer.parentElement.isSameNode(range.endContainer.parentElement)) { range.startContainer.parentElement.isSameNode(range.endContainer.parentElement)) {
// 剪切粗体等字体中的一部分 // 剪切粗体等字体中的一部分
const spanElement = range.startContainer.parentElement const spanElement = range.startContainer.parentElement;
const attributes = spanElement.attributes; const attributes = spanElement.attributes;
const newSpanElement = document.createElement("span"); const newSpanElement = document.createElement("span");
for (let i = 0; i < attributes.length; i++) { for (let i = 0; i < attributes.length; i++) {
@ -1403,7 +1403,7 @@ export class WYSIWYG {
loadBreadcrumb(backlinkBreadcrumbItemElement); loadBreadcrumb(backlinkBreadcrumbItemElement);
} else { } else {
// 引用标题时的更多加载 // 引用标题时的更多加载
getBacklinkHeadingMore(backlinkBreadcrumbItemElement) getBacklinkHeadingMore(backlinkBreadcrumbItemElement);
} }
event.stopPropagation(); event.stopPropagation();
return; return;

View File

@ -22,25 +22,25 @@ const setBacklinkFold = (html: string, expand: boolean) => {
tempDom.innerHTML = html; tempDom.innerHTML = html;
if (tempDom.content.firstElementChild.classList.contains("li")) { if (tempDom.content.firstElementChild.classList.contains("li")) {
if (expand) { if (expand) {
const thirdLiElement = tempDom.content.querySelector(".li .li .li") const thirdLiElement = tempDom.content.querySelector(".li .li .li");
if (thirdLiElement) { if (thirdLiElement) {
thirdLiElement.setAttribute("fold", "1") thirdLiElement.setAttribute("fold", "1");
} }
} else { } else {
tempDom.content.firstElementChild.setAttribute("fold", "1") tempDom.content.firstElementChild.setAttribute("fold", "1");
} }
} else if (tempDom.content.firstElementChild.getAttribute("data-type") === "NodeHeading") { } else if (tempDom.content.firstElementChild.getAttribute("data-type") === "NodeHeading") {
Array.from(tempDom.content.children).forEach((item, index) => { Array.from(tempDom.content.children).forEach((item, index) => {
if ((expand && index > 2) || (!expand && index > 1)) { if ((expand && index > 2) || (!expand && index > 1)) {
if ((expand && index === 3) || (!expand && index === 2)) { if ((expand && index === 3) || (!expand && index === 2)) {
item.insertAdjacentHTML("beforebegin", `<div style="max-width: 100%;justify-content: center;" contenteditable="false" class="protyle-breadcrumb__item"><svg><use xlink:href="#iconMore"></use></svg></div>`); item.insertAdjacentHTML("beforebegin", "<div style=\"max-width: 100%;justify-content: center;\" contenteditable=\"false\" class=\"protyle-breadcrumb__item\"><svg><use xlink:href=\"#iconMore\"></use></svg></div>");
} }
item.classList.add("fn__none") item.classList.add("fn__none");
} }
}) });
} }
return tempDom.innerHTML; return tempDom.innerHTML;
} };
export const loadBreadcrumb = (element: HTMLElement) => { export const loadBreadcrumb = (element: HTMLElement) => {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
@ -66,7 +66,7 @@ export const getBacklinkHeadingMore = (moreElement: HTMLElement) => {
nextElement = nextElement.nextElementSibling; nextElement = nextElement.nextElementSibling;
} }
moreElement.remove(); moreElement.remove();
} };
const genBreadcrumb = (blockPaths: IBreadcrumb[]) => { const genBreadcrumb = (blockPaths: IBreadcrumb[]) => {
let html = ""; let html = "";

View File

@ -8,7 +8,6 @@ import {highlightRender} from "../markdown/highlightRender";
import {hasClosestBlock, hasClosestByAttribute} from "../util/hasClosest"; import {hasClosestBlock, hasClosestByAttribute} from "../util/hasClosest";
import {lockFile} from "../../dialog/processSystem"; import {lockFile} from "../../dialog/processSystem";
import {setFold} from "../../menus/protyle"; import {setFold} from "../../menus/protyle";
import {addLoading} from "../ui/initUI";
import {onGet} from "../util/onGet"; import {onGet} from "../util/onGet";
/// #if !MOBILE /// #if !MOBILE
import {getAllModels} from "../../layout/getAll"; import {getAllModels} from "../../layout/getAll";
@ -116,7 +115,7 @@ const promiseTransaction = () => {
return; return;
} }
let range: Range let range: Range;
if (getSelection().rangeCount > 0) { if (getSelection().rangeCount > 0) {
range = getSelection().getRangeAt(0); range = getSelection().getRangeAt(0);
} }
@ -169,14 +168,14 @@ const promiseTransaction = () => {
} }
if (operation.action === "move") { if (operation.action === "move") {
if (protyle.options.backlinkData) { if (protyle.options.backlinkData) {
const updateElements: Element[] = [] const updateElements: Element[] = [];
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => {
if (item.getAttribute("data-type") === "NodeBlockQueryEmbed" || !hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) { if (item.getAttribute("data-type") === "NodeBlockQueryEmbed" || !hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
updateElements.push(item) updateElements.push(item);
return; return;
} }
}); });
let hasFind = false let hasFind = false;
if (operation.previousID && updateElements.length > 0) { if (operation.previousID && updateElements.length > 0) {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).forEach(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).forEach(item => {
if (item.getAttribute("data-type") === "NodeBlockQueryEmbed" || !hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) { if (item.getAttribute("data-type") === "NodeBlockQueryEmbed" || !hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
@ -217,13 +216,13 @@ const promiseTransaction = () => {
if (operation.action === "insert") { if (operation.action === "insert") {
// insert // insert
if (protyle.options.backlinkData) { if (protyle.options.backlinkData) {
const cursorElements: Element[] = [] const cursorElements: Element[] = [];
if (operation.previousID) { if (operation.previousID) {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).forEach(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).forEach(item => {
if (item.nextElementSibling?.getAttribute("data-node-id") !== operation.id && if (item.nextElementSibling?.getAttribute("data-node-id") !== operation.id &&
(item.getAttribute("data-type") === "NodeBlockQueryEmbed" || !hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed"))) { (item.getAttribute("data-type") === "NodeBlockQueryEmbed" || !hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed"))) {
item.insertAdjacentHTML("afterend", operation.data); item.insertAdjacentHTML("afterend", operation.data);
cursorElements.push(item.nextElementSibling) cursorElements.push(item.nextElementSibling);
} }
}); });
} else { } else {
@ -233,10 +232,10 @@ const promiseTransaction = () => {
if (item.firstElementChild && item.firstElementChild.classList.contains("protyle-action") && if (item.firstElementChild && item.firstElementChild.classList.contains("protyle-action") &&
item.firstElementChild.nextElementSibling.getAttribute("data-node-id") !== operation.id) { item.firstElementChild.nextElementSibling.getAttribute("data-node-id") !== operation.id) {
item.firstElementChild.insertAdjacentHTML("afterend", operation.data); item.firstElementChild.insertAdjacentHTML("afterend", operation.data);
cursorElements.push(item.firstElementChild.nextElementSibling) cursorElements.push(item.firstElementChild.nextElementSibling);
} else if (item.firstElementChild && item.firstElementChild.getAttribute("data-node-id") !== operation.id) { } else if (item.firstElementChild && item.firstElementChild.getAttribute("data-node-id") !== operation.id) {
item.insertAdjacentHTML("afterbegin", operation.data); item.insertAdjacentHTML("afterbegin", operation.data);
cursorElements.push(item.firstElementChild) cursorElements.push(item.firstElementChild);
} }
} }
}); });
@ -304,10 +303,10 @@ export const promiseTransactions = () => {
// 用于推送和撤销 // 用于推送和撤销
export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: boolean) => { export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: boolean) => {
const updateElements: Element[] = [] const updateElements: Element[] = [];
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => {
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) { if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
updateElements.push(item) updateElements.push(item);
} }
}); });
if (operation.action === "setAttrs") { if (operation.action === "setAttrs") {
@ -385,7 +384,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
if (updateElements.length > 0) { if (updateElements.length > 0) {
updateElements.forEach(item => { updateElements.forEach(item => {
item.outerHTML = operation.data; item.outerHTML = operation.data;
}) });
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).find(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).find(item => {
if (item.getAttribute("data-type") === "NodeBlockQueryEmbed" // 引用转换为块嵌入undo、redo 后也需要更新 updateElement if (item.getAttribute("data-type") === "NodeBlockQueryEmbed" // 引用转换为块嵌入undo、redo 后也需要更新 updateElement
|| !hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) { || !hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
@ -479,18 +478,18 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
}); });
} }
/// #endif /// #endif
let hasFind = false let hasFind = false;
if (operation.previousID && updateElements.length > 0) { if (operation.previousID && updateElements.length > 0) {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).forEach(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).forEach(item => {
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) { if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
item.after(updateElements[0].cloneNode(true)); item.after(updateElements[0].cloneNode(true));
hasFind = true hasFind = true;
} }
}); });
} else if (updateElements.length > 0) { } else if (updateElements.length > 0) {
if (!protyle.options.backlinkData && operation.parentID === protyle.block.parentID) { if (!protyle.options.backlinkData && operation.parentID === protyle.block.parentID) {
protyle.wysiwyg.element.prepend(updateElements[0].cloneNode(true)); protyle.wysiwyg.element.prepend(updateElements[0].cloneNode(true));
hasFind = true hasFind = true;
} else { } else {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.parentID}"]`)).forEach(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.parentID}"]`)).forEach(item => {
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) { if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
@ -500,7 +499,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
} else { } else {
item.prepend(updateElements[0].cloneNode(true)); item.prepend(updateElements[0].cloneNode(true));
} }
hasFind = true hasFind = true;
} }
}); });
} }
@ -541,23 +540,23 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
blockRender(protyle, embedElement); blockRender(protyle, embedElement);
} else { } else {
item.insertAdjacentHTML("afterend", operation.data); item.insertAdjacentHTML("afterend", operation.data);
cursorElements.push(item.nextElementSibling) cursorElements.push(item.nextElementSibling);
} }
}); });
} else { } else {
if (!protyle.options.backlinkData && operation.parentID === protyle.block.parentID) { if (!protyle.options.backlinkData && operation.parentID === protyle.block.parentID) {
protyle.wysiwyg.element.insertAdjacentHTML("afterbegin", operation.data); protyle.wysiwyg.element.insertAdjacentHTML("afterbegin", operation.data);
cursorElements.push(protyle.wysiwyg.element.firstElementChild) cursorElements.push(protyle.wysiwyg.element.firstElementChild);
} else { } else {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.parentID}"]`)).forEach(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.parentID}"]`)).forEach(item => {
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) { if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
// 列表特殊处理 // 列表特殊处理
if (item.firstElementChild?.classList.contains("protyle-action")) { if (item.firstElementChild?.classList.contains("protyle-action")) {
item.firstElementChild.insertAdjacentHTML("afterend", operation.data); item.firstElementChild.insertAdjacentHTML("afterend", operation.data);
cursorElements.push(item.firstElementChild.nextElementSibling) cursorElements.push(item.firstElementChild.nextElementSibling);
} else { } else {
item.insertAdjacentHTML("afterbegin", operation.data); item.insertAdjacentHTML("afterbegin", operation.data);
cursorElements.push(item.firstElementChild) cursorElements.push(item.firstElementChild);
} }
} }
}); });