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);
break;
case"statusbarCounter":
handleStatusbarCounter(data)
handleStatusbarCounter(data);
break;
case"downloadProgress":
downloadProgress(data.data);
break;

View file

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

View file

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

View file

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

View file

@ -529,7 +529,7 @@ export class Toolbar {
// 合并相同的 node
if (currentNewNode.getAttribute("data-type").indexOf("inline-math") > -1) {
// 数学公式合并 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) {
// 引用不虚合并内容 https://ld246.com/article/1664454663564
nextNewNode.innerHTML = currentNewNode.innerHTML + nextNewNode.innerHTML;

View file

@ -13,12 +13,10 @@ import {onGet} from "./onGet";
/// #if !MOBILE
import {getInstanceById} from "../../layout/util";
import {Tab} from "../../layout/Tab";
import {getAllModels} from "../../layout/getAll";
import {updatePanelByEditor} from "../../editor/util";
/// #endif
import {Editor} from "../../editor";
import {blockRender} from "../markdown/blockRender";
import {processRender} from "./processCode";
import {highlightRender} from "../markdown/highlightRender";
import {uploadLocalFiles} from "../upload";
import {insertHTML} from "./insertHTML";
@ -622,18 +620,18 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
});
if (event.altKey) {
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
let html = ''
let html = "";
for (let i = 0; i < selectedIds.length; i++) {
const response = await fetchSyncPost("/api/block/getRefText", {id: selectedIds[i]});
html += `((${selectedIds[i]} '${response.data}')) `
html += `((${selectedIds[i]} '${response.data}')) `;
}
insertHTML(html, protyle);
} else if (event.shiftKey) {
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
let html = ''
let html = "";
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);
blockRender(protyle, protyle.wysiwyg.element);
} 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 scrollLeft = blockElement.firstElementChild.scrollLeft;
const blockPreviousElement = blockElement.previousElementSibling
const blockPreviousElement = blockElement.previousElementSibling;
blockElement.outerHTML = spinHTML;
render = true;
// 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" &&
range.startContainer.parentElement.isSameNode(range.endContainer.parentElement)) {
// 剪切粗体等字体中的一部分
const spanElement = range.startContainer.parentElement
const spanElement = range.startContainer.parentElement;
const attributes = spanElement.attributes;
const newSpanElement = document.createElement("span");
for (let i = 0; i < attributes.length; i++) {
@ -1403,7 +1403,7 @@ export class WYSIWYG {
loadBreadcrumb(backlinkBreadcrumbItemElement);
} else {
// 引用标题时的更多加载
getBacklinkHeadingMore(backlinkBreadcrumbItemElement)
getBacklinkHeadingMore(backlinkBreadcrumbItemElement);
}
event.stopPropagation();
return;

View file

@ -22,25 +22,25 @@ const setBacklinkFold = (html: string, expand: boolean) => {
tempDom.innerHTML = html;
if (tempDom.content.firstElementChild.classList.contains("li")) {
if (expand) {
const thirdLiElement = tempDom.content.querySelector(".li .li .li")
const thirdLiElement = tempDom.content.querySelector(".li .li .li");
if (thirdLiElement) {
thirdLiElement.setAttribute("fold", "1")
thirdLiElement.setAttribute("fold", "1");
}
} else {
tempDom.content.firstElementChild.setAttribute("fold", "1")
tempDom.content.firstElementChild.setAttribute("fold", "1");
}
} else if (tempDom.content.firstElementChild.getAttribute("data-type") === "NodeHeading") {
Array.from(tempDom.content.children).forEach((item, index) => {
if ((expand && index > 2) || (!expand && index > 1)) {
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;
}
};
export const loadBreadcrumb = (element: HTMLElement) => {
fetchPost("/api/filetree/getDoc", {
@ -66,7 +66,7 @@ export const getBacklinkHeadingMore = (moreElement: HTMLElement) => {
nextElement = nextElement.nextElementSibling;
}
moreElement.remove();
}
};
const genBreadcrumb = (blockPaths: IBreadcrumb[]) => {
let html = "";

View file

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