This commit is contained in:
Vanessa 2024-09-08 11:03:47 +08:00
parent 9cff5cc235
commit 42ea06ce07
2 changed files with 20 additions and 37 deletions

View file

@ -157,8 +157,8 @@ export const setRefDynamicText = (data: {
item.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"] span[data-type="block-ref"][data-subtype="d"][data-id="${data.defBlockID}"]`).forEach(item => { item.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"] span[data-type="block-ref"][data-subtype="d"][data-id="${data.defBlockID}"]`).forEach(item => {
item.innerHTML = data.refText; item.innerHTML = data.refText;
}); });
}) });
} };
export const setDefRefCount = (data: { export const setDefRefCount = (data: {
"blockID": string, "blockID": string,
@ -169,59 +169,59 @@ export const setDefRefCount = (data: {
}) => { }) => {
getAllEditor().forEach(item => { getAllEditor().forEach(item => {
if (data.rootID === data.blockID && item.protyle.block.rootID === data.rootID) { if (data.rootID === data.blockID && item.protyle.block.rootID === data.rootID) {
const attrElement = item.protyle.title.element.querySelector(".protyle-attr") const attrElement = item.protyle.title.element.querySelector(".protyle-attr");
const countElement = attrElement.querySelector('.popover__block') const countElement = attrElement.querySelector(".popover__block");
if (countElement) { if (countElement) {
if (data.refCount === 0) { if (data.refCount === 0) {
countElement.remove() countElement.remove();
} else { } else {
countElement.textContent = data.refCount.toString(); countElement.textContent = data.refCount.toString();
countElement.setAttribute("data-id", data.refIDs.toString()) countElement.setAttribute("data-id", data.refIDs.toString());
} }
} else if (data.refCount > 0) { } else if (data.refCount > 0) {
attrElement.insertAdjacentHTML("beforeend", `<div class="protyle-attr--refcount popover__block" data-defids="[&quot;${data.blockID}&quot;]" data-id="${data.refIDs.toString()}" style="">${data.refCount}</div>`) attrElement.insertAdjacentHTML("beforeend", `<div class="protyle-attr--refcount popover__block" data-defids="[&quot;${data.blockID}&quot;]" data-id="${data.refIDs.toString()}" style="">${data.refCount}</div>`);
} }
return; return;
} }
// 不能对比 rootId否则潜入块中的锚文本无法更新 // 不能对比 rootId否则潜入块中的锚文本无法更新
item.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"]`).forEach(item => { item.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"]`).forEach(item => {
const countElement = item.querySelector('.protyle-attr--refcount') const countElement = item.querySelector(".protyle-attr--refcount");
if (countElement) { if (countElement) {
if (data.refCount === 0) { if (data.refCount === 0) {
countElement.remove() countElement.remove();
} else { } else {
countElement.textContent = data.refCount.toString(); countElement.textContent = data.refCount.toString();
} }
} else if (data.refCount > 0) { } else if (data.refCount > 0) {
const attrElement = item.querySelector('.protyle-attr') const attrElement = item.querySelector(".protyle-attr");
if (attrElement.childElementCount > 0) { if (attrElement.childElementCount > 0) {
attrElement.lastElementChild.insertAdjacentHTML("afterend", `<div class="protyle-attr--refcount popover__block">${data.refCount}</div>`) attrElement.lastElementChild.insertAdjacentHTML("afterend", `<div class="protyle-attr--refcount popover__block">${data.refCount}</div>`);
} else { } else {
attrElement.innerHTML = `<div class="protyle-attr--refcount popover__block">${data.refCount}</div>${Constants.ZWSP}` attrElement.innerHTML = `<div class="protyle-attr--refcount popover__block">${data.refCount}</div>${Constants.ZWSP}`;
} }
} }
}); });
}) });
let liElement; let liElement;
/// #if MOBILE /// #if MOBILE
liElement = window.siyuan.mobile.files.element.querySelector(`li[data-node-id="${data.rootID}"]`) liElement = window.siyuan.mobile.files.element.querySelector(`li[data-node-id="${data.rootID}"]`);
/// #else /// #else
liElement = (getDockByType("file").data.file as Files).element.querySelector(`li[data-node-id="${data.rootID}"]`) liElement = (getDockByType("file").data.file as Files).element.querySelector(`li[data-node-id="${data.rootID}"]`);
/// #endif /// #endif
if (liElement) { if (liElement) {
const counterElement = liElement.querySelector(".counter") const counterElement = liElement.querySelector(".counter");
if (counterElement) { if (counterElement) {
if (data.rootRefCount === 0) { if (data.rootRefCount === 0) {
counterElement.remove() counterElement.remove();
} else { } else {
counterElement.textContent = data.rootRefCount.toString() counterElement.textContent = data.rootRefCount.toString();
} }
} else if (data.rootRefCount > 0) { } else if (data.rootRefCount > 0) {
liElement.insertAdjacentHTML("beforeend", `<span class="popover__block counter b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.ref}">${data.rootRefCount}</span>`) liElement.insertAdjacentHTML("beforeend", `<span class="popover__block counter b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.ref}">${data.rootRefCount}</span>`);
} }
} }
} };
export const lockScreen = (app: App) => { export const lockScreen = (app: App) => {
if (window.siyuan.config.readonly) { if (window.siyuan.config.readonly) {

View file

@ -1050,23 +1050,6 @@ export const turnsOneInto = async (options: {
avRender(options.protyle.wysiwyg.element, options.protyle); avRender(options.protyle.wysiwyg.element, options.protyle);
}; };
const updateRef = (protyle: IProtyle, id: string, index = 0) => {
if (index > 6) {
return;
}
protyle.wysiwyg.element.querySelectorAll(`[data-type~="block-ref"][data-id="${id}"]`).forEach(item => {
if (item.getAttribute("data-subtype") === "d") {
fetchPost("/api/block/getRefText", {id: id}, (response) => {
item.innerHTML = response.data;
const blockElement = hasClosestBlock(item);
if (blockElement) {
updateRef(protyle, blockElement.getAttribute("data-node-id"), index + 1);
}
});
}
});
};
let transactionsTimeout: number; let transactionsTimeout: number;
export const transaction = (protyle: IProtyle, doOperations: IOperation[], undoOperations?: IOperation[]) => { export const transaction = (protyle: IProtyle, doOperations: IOperation[], undoOperations?: IOperation[]) => {
if (doOperations.length === 0) { if (doOperations.length === 0) {